[gtk/prop-list: 56/83] gtk-demo: Add row reordering to the settings demo
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/prop-list: 56/83] gtk-demo: Add row reordering to the settings demo
- Date: Mon, 23 Dec 2019 05:45:28 +0000 (UTC)
commit ed35258bcb4b30f0bc35dafac09477d38fa53ada
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Dec 17 22:18:44 2019 -0500
gtk-demo: Add row reordering to the settings demo
demos/gtk-demo/listview_settings.c | 67 ++++++++++++++++++-
demos/gtk-demo/listview_settings.ui | 127 +++++++++++++++++++++++++++++++++++-
2 files changed, 192 insertions(+), 2 deletions(-)
---
diff --git a/demos/gtk-demo/listview_settings.c b/demos/gtk-demo/listview_settings.c
index 6a868b1a5b..7d4a65d280 100644
--- a/demos/gtk-demo/listview_settings.c
+++ b/demos/gtk-demo/listview_settings.c
@@ -249,6 +249,50 @@ stop_search (GtkSearchEntry *entry,
gtk_string_filter_set_search (GTK_STRING_FILTER (current_filter), "");
}
+static void
+move_column (GtkListView *columns_list, gboolean down)
+{
+ GListModel *columns;
+ guint position;
+ GtkColumnViewColumn *selected;
+ GtkColumnView *view;
+
+ columns = gtk_list_view_get_model (columns_list);
+ position = gtk_single_selection_get_selected (GTK_SINGLE_SELECTION (columns));
+ selected = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (columns));
+ view = gtk_column_view_column_get_column_view (selected);
+
+ if (down && position + 1 < g_list_model_get_n_items (columns))
+ position++;
+ else if (!down && position > 0)
+ position--;
+ else
+ return;
+
+ gtk_column_view_insert_column (view, position, selected);
+ gtk_single_selection_set_selected (GTK_SINGLE_SELECTION (columns), position);
+}
+
+static void
+move_column_down (GtkListView *columns_list)
+{
+ move_column (columns_list, TRUE);
+}
+
+static void
+move_column_up (GtkListView *columns_list)
+{
+ move_column (columns_list, FALSE);
+}
+
+static void
+column_visible_toggled (GtkListItem *item, GtkToggleButton *button)
+{
+ GtkColumnViewColumn *column = gtk_list_item_get_item (item);
+
+ gtk_column_view_column_set_visible (column, gtk_toggle_button_get_active (button));
+}
+
static GtkWidget *window = NULL;
GtkWidget *
@@ -264,6 +308,8 @@ do_listview_settings (GtkWidget *do_widget)
GtkBuilder *builder;
GtkColumnViewColumn *name_column;
GtkSorter *sorter;
+ GtkWidget *menubutton, *popover;
+ GtkWidget *columns_list;
g_type_ensure (SETTINGS_TYPE_KEY);
@@ -271,10 +317,18 @@ do_listview_settings (GtkWidget *do_widget)
gtk_builder_cscope_add_callback_symbol (GTK_BUILDER_CSCOPE (scope), "search_enabled",
(GCallback)search_enabled);
gtk_builder_cscope_add_callback_symbol (GTK_BUILDER_CSCOPE (scope), "search_changed",
(GCallback)search_changed);
gtk_builder_cscope_add_callback_symbol (GTK_BUILDER_CSCOPE (scope), "stop_search",
(GCallback)stop_search);
+ gtk_builder_cscope_add_callback_symbol (GTK_BUILDER_CSCOPE (scope), "move_column_down",
(GCallback)move_column_down);
+ gtk_builder_cscope_add_callback_symbol (GTK_BUILDER_CSCOPE (scope), "move_column_up",
(GCallback)move_column_up);
+ gtk_builder_cscope_add_callback_symbol (GTK_BUILDER_CSCOPE (scope), "column_visible_toggled",
(GCallback)column_visible_toggled);
builder = gtk_builder_new ();
gtk_builder_set_scope (builder, scope);
- gtk_builder_add_from_resource (builder, "/listview_settings/listview_settings.ui", NULL);
+ {
+ g_autoptr(GError) error = NULL;
+ gtk_builder_add_from_resource (builder, "/listview_settings/listview_settings.ui", &error);
+ if (error)
+ g_warning ("%s", error->message);
+ }
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
gtk_window_set_display (GTK_WINDOW (window),
@@ -307,6 +361,17 @@ do_listview_settings (GtkWidget *do_widget)
sorter = gtk_string_sorter_new (gtk_property_expression_new (SETTINGS_TYPE_KEY, NULL, "name"));
gtk_column_view_column_set_sorter (name_column, sorter);
g_object_unref (sorter);
+
+ menubutton = GTK_WIDGET (gtk_builder_get_object (builder, "menubutton"));
+ popover = GTK_WIDGET (gtk_builder_get_object (builder, "column_popover"));
+ gtk_menu_button_set_popover (GTK_MENU_BUTTON (menubutton), popover);
+
+ columns_list = GTK_WIDGET (gtk_builder_get_object (builder, "columns_list"));
+ model = G_LIST_MODEL (gtk_single_selection_new (gtk_column_view_get_columns (GTK_COLUMN_VIEW
(columnview))));
+ gtk_list_view_set_model (GTK_LIST_VIEW (columns_list), model);
+ g_object_unref (model);
+
+ g_object_unref (builder);
}
if (!gtk_widget_get_visible (window))
diff --git a/demos/gtk-demo/listview_settings.ui b/demos/gtk-demo/listview_settings.ui
index 8088ca9102..89317ff7c2 100644
--- a/demos/gtk-demo/listview_settings.ui
+++ b/demos/gtk-demo/listview_settings.ui
@@ -7,6 +7,11 @@
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="show-title-buttons">1</property>
+ <child type="end">
+ <object class="GtkMenuButton" id="menubutton">
+ <property name="icon-name">open-menu-symbolic</property>
+ </object>
+ </child>
<child type="end">
<object class="GtkToggleButton" id="search_button">
<property name="icon-name">system-search-symbolic</property>
@@ -100,7 +105,7 @@
</object>
</child>
<child>
- <object class="GtkColumnViewColumn">
+ <object class="GtkColumnViewColumn" id="value_column">
<property name="title">Value</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
@@ -119,6 +124,58 @@
</object>
</property>
</template>
+</interface>
+ ]]></property>
+ </object>
+ </property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkColumnViewColumn" id="summary_column">
+ <property name="title">Summary</property>
+ <property name="factory">
+ <object class="GtkBuilderListItemFactory">
+ <property name="bytes"><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="GtkListItem">
+ <property name="child">
+ <object class="GtkLabel">
+ <property name="xalign">0</property>
+ <binding name="label">
+ <lookup name="summary" type="SettingsKey">
+ <lookup name="item">GtkListItem</lookup>
+ </lookup>
+ </binding>
+ </object>
+ </property>
+ </template>
+</interface>
+ ]]></property>
+ </object>
+ </property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkColumnViewColumn" id="description_column">
+ <property name="title">Description</property>
+ <property name="factory">
+ <object class="GtkBuilderListItemFactory">
+ <property name="bytes"><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="GtkListItem">
+ <property name="child">
+ <object class="GtkLabel">
+ <property name="xalign">0</property>
+ <binding name="label">
+ <lookup name="description" type="SettingsKey">
+ <lookup name="item">GtkListItem</lookup>
+ </lookup>
+ </binding>
+ </object>
+ </property>
+ </template>
</interface>
]]></property>
</object>
@@ -134,4 +191,72 @@
</object>
</child>
</object>
+ <object class="GtkPopover" id="column_popover">
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkListView" id="columns_list">
+ <property name="factory">
+ <object class="GtkBuilderListItemFactory">
+ <property name="bytes"><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="GtkListItem">
+ <property name="child">
+ <object class="GtkBox">
+ <property name="spacing">10</property>
+ <child>
+ <object class="GtkCheckButton">
+ <signal name="toggled" handler="column_visible_toggled" object="GtkListItem"/>
+ <binding name="active">
+ <lookup name="visible" type="GtkColumnViewColumn">
+ <lookup name="item">GtkListItem</lookup>
+ </lookup>
+ </binding>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="xalign">0</property>
+ <property name="label">label</property>
+ <binding name="label">
+ <lookup name="title" type="GtkColumnViewColumn">
+ <lookup name="item">GtkListItem</lookup>
+ </lookup>
+ </binding>
+ </object>
+ </child>
+ </object>
+ </property>
+ </template>
+</interface>
+ ]]></property>
+ </object>
+ </property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="halign">center</property>
+ <style>
+ <class name="linked"/>
+ </style>
+ <child>
+ <object class="GtkButton">
+ <property name="icon-name">go-down-symbolic</property>
+ <signal name="clicked" handler="move_column_down" object="columns_list"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton">
+ <property name="icon-name">go-up-symbolic</property>
+ <signal name="clicked" handler="move_column_up" object="columns_list"/>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]