[gtk/inspector-controllers: 3/7] inspector: Redo the shortcuts page
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/inspector-controllers: 3/7] inspector: Redo the shortcuts page
- Date: Thu, 21 Jan 2021 15:25:45 +0000 (UTC)
commit e97d996fe4d2d43bbc938418bd82596acb99a5e3
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Jan 20 19:27:38 2021 -0500
inspector: Redo the shortcuts page
Use a column view here.
gtk/inspector/shortcuts.c | 178 +++++++++++++++++++++++-----------------------
1 file changed, 88 insertions(+), 90 deletions(-)
---
diff --git a/gtk/inspector/shortcuts.c b/gtk/inspector/shortcuts.c
index c5627ff892..08a1a419c2 100644
--- a/gtk/inspector/shortcuts.c
+++ b/gtk/inspector/shortcuts.c
@@ -20,135 +20,140 @@
#include "shortcuts.h"
#include "gtklabel.h"
-#include "gtklistbox.h"
#include "gtksizegroup.h"
#include "gtkstack.h"
#include "gtkshortcut.h"
#include "gtkshortcuttrigger.h"
#include "gtkshortcutcontroller.h"
+#include "gtksignallistitemfactory.h"
+#include "gtklistitem.h"
+#include "gtkcolumnview.h"
+#include "gtkcolumnviewcolumn.h"
+#include "gtkscrolledwindow.h"
+#include "gtknoselection.h"
+#include "gtkbinlayout.h"
+
struct _GtkInspectorShortcuts
{
GtkWidget parent;
- GtkWidget *box;
- GtkWidget *list;
-
- GtkSizeGroup *trigger;
- GtkSizeGroup *action;
+ GtkWidget *view;
};
G_DEFINE_TYPE (GtkInspectorShortcuts, gtk_inspector_shortcuts, GTK_TYPE_WIDGET)
static void
-gtk_inspector_shortcuts_init (GtkInspectorShortcuts *sl)
+setup_row (GtkSignalListItemFactory *factory,
+ GtkListItem *list_item,
+ gpointer data)
{
- gtk_widget_init_template (GTK_WIDGET (sl));
+ GtkWidget *label;
+
+ label = gtk_label_new ("");
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_list_item_set_child (list_item, label);
}
-static GtkWidget *
-create_row (gpointer item,
- gpointer user_data)
+static void
+bind_trigger (GtkSignalListItemFactory *factory,
+ GtkListItem *list_item,
+ gpointer data)
{
- GtkShortcut *shortcut = GTK_SHORTCUT (item);
- GtkInspectorShortcuts *sl = GTK_INSPECTOR_SHORTCUTS (user_data);
- GtkShortcutTrigger *trigger;
- GtkShortcutAction *action;
- char *s;
- GtkWidget *row;
GtkWidget *label;
+ GtkShortcut *shortcut;
+ GtkShortcutTrigger *trigger;
+ char *str;
+ label = gtk_list_item_get_child (list_item);
+ shortcut = gtk_list_item_get_item (list_item);
trigger = gtk_shortcut_get_trigger (shortcut);
+ str = gtk_shortcut_trigger_to_label (trigger, gtk_widget_get_display (label));
+ gtk_label_set_label (GTK_LABEL (label), str);
+ g_free (str);
+}
+
+static void
+bind_action (GtkSignalListItemFactory *factory,
+ GtkListItem *list_item,
+ gpointer data)
+{
+ GtkWidget *label;
+ GtkShortcut *shortcut;
+ GtkShortcutAction *action;
+ char *str;
+
+ label = gtk_list_item_get_child (list_item);
+ shortcut = gtk_list_item_get_item (list_item);
action = gtk_shortcut_get_action (shortcut);
+ str = gtk_shortcut_action_to_string (action);
+ gtk_label_set_label (GTK_LABEL (label), str);
+ g_free (str);
+}
+
+static void
+gtk_inspector_shortcuts_init (GtkInspectorShortcuts *self)
+{
+ GtkWidget *sw;
+ GtkListItemFactory *factory;
+ GtkColumnViewColumn *column;
+
+ sw = gtk_scrolled_window_new ();
+
+ self->view = gtk_column_view_new (NULL);
+
+ factory = gtk_signal_list_item_factory_new ();
+ g_signal_connect (factory, "setup", G_CALLBACK (setup_row), NULL);
+ g_signal_connect (factory, "bind", G_CALLBACK (bind_trigger), NULL);
- row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
+ column = gtk_column_view_column_new ("Trigger", factory);
+ gtk_column_view_append_column (GTK_COLUMN_VIEW (self->view), column);
+ g_object_unref (column);
- s = gtk_shortcut_trigger_to_string (trigger);
- label = gtk_label_new (s);
- gtk_label_set_xalign (GTK_LABEL (label), 0.0);
- g_free (s);
- gtk_box_append (GTK_BOX (row), label);
- gtk_size_group_add_widget (sl->trigger, label);
+ factory = gtk_signal_list_item_factory_new ();
+ g_signal_connect (factory, "setup", G_CALLBACK (setup_row), NULL);
+ g_signal_connect (factory, "bind", G_CALLBACK (bind_action), NULL);
- s = gtk_shortcut_action_to_string (action);
- label = gtk_label_new (s);
- gtk_label_set_xalign (GTK_LABEL (label), 0.0);
- g_free (s);
- gtk_box_append (GTK_BOX (row), label);
- gtk_size_group_add_widget (sl->action, label);
+ column = gtk_column_view_column_new ("Action", factory);
+ gtk_column_view_append_column (GTK_COLUMN_VIEW (self->view), column);
+ g_object_unref (column);
- return row;
+ gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), self->view);
+
+ gtk_widget_set_parent (sw, GTK_WIDGET (self));
}
void
-gtk_inspector_shortcuts_set_object (GtkInspectorShortcuts *sl,
+gtk_inspector_shortcuts_set_object (GtkInspectorShortcuts *self,
GObject *object)
{
GtkWidget *stack;
GtkStackPage *page;
+ GtkNoSelection *no_selection;
- stack = gtk_widget_get_parent (GTK_WIDGET (sl));
- page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (sl));
+ stack = gtk_widget_get_parent (GTK_WIDGET (self));
+ page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (self));
- if (GTK_IS_SHORTCUT_CONTROLLER (object))
- {
- g_object_set (page, "visible", TRUE, NULL);
- gtk_list_box_bind_model (GTK_LIST_BOX (sl->list),
- G_LIST_MODEL (object),
- create_row,
- sl,
- NULL);
- }
- else
+ if (!GTK_IS_SHORTCUT_CONTROLLER (object))
{
+ gtk_column_view_set_model (GTK_COLUMN_VIEW (self->view), NULL);
g_object_set (page, "visible", FALSE, NULL);
- gtk_list_box_bind_model (GTK_LIST_BOX (sl->list),
- NULL,
- NULL,
- NULL,
- NULL);
+ return;
}
-}
-static void
-gtk_inspector_shortcuts_measure (GtkWidget *widget,
- GtkOrientation orientation,
- int for_size,
- int *minimum,
- int *natural,
- int *minimum_baseline,
- int *natural_baseline)
-{
- GtkInspectorShortcuts *shortcuts = GTK_INSPECTOR_SHORTCUTS (widget);
-
- gtk_widget_measure (shortcuts->box,
- orientation,
- for_size,
- minimum, natural,
- minimum_baseline, natural_baseline);
-}
+ g_object_set (page, "visible", TRUE, NULL);
-static void
-gtk_inspector_shortcuts_size_allocate (GtkWidget *widget,
- int width,
- int height,
- int baseline)
-{
- GtkInspectorShortcuts *shortcuts = GTK_INSPECTOR_SHORTCUTS (widget);
-
- gtk_widget_size_allocate (shortcuts->box,
- &(GtkAllocation) { 0, 0, width, height },
- baseline);
+ no_selection = gtk_no_selection_new (g_object_ref (G_LIST_MODEL (object)));
+ gtk_column_view_set_model (GTK_COLUMN_VIEW (self->view), GTK_SELECTION_MODEL (no_selection));
+ g_object_unref (no_selection);
}
static void
dispose (GObject *object)
{
- GtkInspectorShortcuts *shortcuts = GTK_INSPECTOR_SHORTCUTS (object);
- GtkWidget *child;
+ GtkInspectorShortcuts *self = GTK_INSPECTOR_SHORTCUTS (object);
- while ((child = gtk_widget_get_first_child (GTK_WIDGET (shortcuts))))
- gtk_widget_unparent (child);
+ gtk_widget_unparent (gtk_widget_get_first_child (GTK_WIDGET (self)));
G_OBJECT_CLASS (gtk_inspector_shortcuts_parent_class)->dispose (object);
}
@@ -161,12 +166,5 @@ gtk_inspector_shortcuts_class_init (GtkInspectorShortcutsClass *klass)
object_class->dispose = dispose;
- widget_class->measure = gtk_inspector_shortcuts_measure;
- widget_class->size_allocate = gtk_inspector_shortcuts_size_allocate;
-
- gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/shortcuts.ui");
- gtk_widget_class_bind_template_child (widget_class, GtkInspectorShortcuts, box);
- gtk_widget_class_bind_template_child (widget_class, GtkInspectorShortcuts, list);
- gtk_widget_class_bind_template_child (widget_class, GtkInspectorShortcuts, trigger);
- gtk_widget_class_bind_template_child (widget_class, GtkInspectorShortcuts, action);
+ gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]