-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GTK4 List API examples with filters and sort #157
Comments
Sort blocked by #144 |
FullVala example with Expressions and NumericSort https://github.com/aeldemery/gtk4_list_colors/blob/master/sources/ColorGridWidget.vala#L65 |
Problem with FileFilter was solved. |
I think this is very close, but FileInfo has no propertiess, so need to use Expression with GClosure https://developer.gnome.org/gtk4/stable/GtkExpression.html#gtk-closure-expression-new import gintro/[gtk4, gobject, gio]
import std/with
proc getFileName(info: gio.FileInfo): string =
return info.getName()
proc setup_cb(factory: gtk4.SignalListItemFactory, listitem: gtk4.ListItem) =
listitem.setChild(newLabel(""))
proc bind_cb(factory: gtk4.SignalListItemFactory, listitem: gtk4.ListItem) =
let
lb = listitem.getChild().Label
fileobj = cast[FileInfo](listitem.getItem())
lb.text = fileobj.getFileName()
proc unbind_cb(factory: gtk4.SignalListItemFactory, listitem: gtk4.ListItem) =
# There's nothing to do here.
# If you does something like setting a signal in bind_cb,
# then disconnecting the signal is necessary in unbind_cb.
echo "unbind"
proc teardown_cb(factory: gtk4.SignalListItemFactory, listitem: gtk4.ListItem) =
listitem.setChild (nil)
# When the child of listitem is set to NULL, the reference to GtkLabel will be released and lb will be destroyed.
# Therefore, g_object_unref () for the GtkLabel object doesn't need in the user code.
proc entryChanged(self: EntryBuffer, position: int, chars: string, nChars: int) =
echo self.text
proc activate(app: gtk4.Application) =
let
window = newApplicationWindow(app)
scr = newScrolledWindow()
file = gio.newGFileForPath(".")
dl = gtk4.newDirectoryList("standard::name", file)
ls = listModel(dl)
ss = newStringSorter()
fm = newSortListModel(ls, ss)
ns = gtk4.newNoSelection(listModel(fm))
factory = gtk4.newSignalListItemFactory()
lv = newListView(ns, factory)
mainBox = newBox(Orientation.vertical, 5)
patternEntry = newEntry()
patternEntry.placeholderText = "Enter pattern"
patternEntry.buffer.connect("inserted_text", entryChanged)
with mainBox:
append patternEntry
append scr
let gFileType = typeFromName("GFileInfo")
ss.expression = newPropertyExpression(gFileType, nil, "display_name" )
with scr:
vexpand = true
setChild lv
dl.setMonitored true
with factory:
connect("setup", setup_cb)
connect("bind", bind_cb)
connect("unbind", unbind_cb)
connect("teardown", teardown_cb)
with window:
defaultSize = (600, 400)
title = "Nim ListView"
setChild mainBox
show
proc main =
let app = newApplication("org.gtk.example")
app.connect("activate", activate)
discard run(app)
main()
|
https://docs.gtk.org/gtk4/class.FileFilter.html
https://docs.gtk.org/gtk4/class.Sorter.html
https://docs.gtk.org/gtk4/class.MultiSorter.html
https://docs.gtk.org/gtk4/class.Filter.html
https://docs.gtk.org/gtk4/class.MultiFilter.html
The text was updated successfully, but these errors were encountered: