diff --git a/src/ui/tree.c b/src/ui/tree.c index c19a7a8..d423e28 100644 --- a/src/ui/tree.c +++ b/src/ui/tree.c @@ -56,17 +56,67 @@ static GtkWidget *my_tree_view; static GListModel *my_list_model = NULL; -// view = gtk_list_view_new (model, factory); <<<<<< +// erreur: un élément de l'initialisation n'est pas une constante +//model = create_application_list (); + + + +typedef struct _GtkModel GtkModel; +GtkModel my_model(); typedef struct _GtkSignalListItemFactory GtkSignalListItemFactory; +GtkSignalListItemFactory my_factory(int a); + GtkListItemFactory *gtk_signal_list_item_factory_new (void); +GtkListItemFactory *gtk_list_view_get_factory (GtkListView *self); +GtkWidget *gtk_list_view_new (GtkSelectionModel *my_model, GtkListItemFactory *my_factory); +static void setup_listitem_cb (GtkListItemFactory *factory, GtkListItem *list_item) +{ + GtkWidget *label = gtk_label_new (""); + gtk_list_item_set_child (list_item, label); + + GtkWidget *image = gtk_image_new (); + gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE); + gtk_list_item_set_child (list_item, image); +} + +static void bind_listitem_cb (GtkListItemFactory *factory, GtkListItem *list_item) +{ + GtkWidget *image; + GAppInfo *app_info; + + image = gtk_list_item_get_child (list_item); + app_info = gtk_list_item_get_item (list_item); + gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (app_info)); +} + +static void activate_cb (GtkListView *list, guint position, gpointer unused) +{ + GAppInfo *app_info; + + app_info = g_list_model_get_item (G_LIST_MODEL (gtk_list_view_get_model (list)), position); + g_app_info_launch (app_info, NULL, NULL, NULL); + g_object_unref (app_info); +} + + + + +// Parameters : self : the GtkSignalListItemFactory, +// listitem : the GtkListItem to bind, +// user_data : the user data set when the signal handler was connected. +// Flags: Run First +static void any_user_function (GtkSignalListItemFactory *self, GtkListItem *listitem, gpointer user_data) {} + +// user_function can be : setup, bind, unbind or teardown +// // The “setup” signal is emitted when the factory needs to create a new row widget. -// g_signal_connect (factory, "setup", setup_listitem_cb, NULL); <<<<<< +// g_signal_connect (factory, "setup", setup_listitem_cb, NULL); // // The “bind” signal is emitted when a row widget needs to be connected to an item from the model. -// g_signal_connect (factory, "bind", bind_listitem_cb, NULL); <<<<<< +// g_signal_connect (factory, "bind", bind_listitem_cb, NULL); // // Both of these signals take a GtkListItem as argument, // which is a wrapper object that lets you get at the model item (with gtk_list_item_get_item()) @@ -75,17 +125,6 @@ GtkListItemFactory *gtk_signal_list_item_factory_new (void); // If your “bind” handler connects to signals on the item or does other things that require cleanup, // you can use the “unbind” signal to do that cleanup. The “setup” signal has a similar counterpart called “teardown”. -static void setup_listitem_cb (GtkListItemFactory *factory, GtkListItem *list_item) -{ - GtkWidget *label = gtk_label_new (""); - gtk_list_item_set_child (list_item, label); -} - -// user_function can be : setup, bind, unbind or teardown -// Parameters : self, The GtkSignalListItemFactory, listitem, The GtkListItem to bind, -// user_data : user data set when the signal handler was connected. -// Flags: Run First -static void user_function (GtkSignalListItemFactory *self, GtkListItem *listitem, gpointer user_data) {} //------------------------------------------------------------------------------ @@ -96,8 +135,11 @@ static void user_function (GtkSignalListItemFactory *self, GtkListItem *listitem // https://gnome.pages.gitlab.gnome.org/libsoup/gio/GListModel.html // https://blog.gtk.org/2020/09/05/a-primer-on-gtklistview/ <<< Factory mechanism // https://docs.gtk.org/gtk4/class.ListItemFactory.html <<< +// https://www.typeerror.org/docs/gtk~4.0/gtksignallistitemfactory +// https://developer-old.gnome.org/gtk4/stable/GtkListView.html <<< copy that ! // https://docs.gtk.org/gtk4/class.ListItem.html // https://docs.gtk.org/gtk4/ctor.TreeListModel.new.html *** // https://blog.gtk.org/2020/06/08/more-on-lists-in-gtk-4/ *** // https://gitlab.gnome.org/GNOME/gtk/-/blob/main/demos/gtk-demo/listview_settings.c GtkBuilder *builder; (line 216) // https://discourse.gnome.org/t/how-can-i-get-the-expanded-collapsed-items-in-the-new-gtktreelistmodel-implementation/16824 +// https://developer-old.gnome.org/gtk4/stable/GtkSignalListItemFactory.html