Add a header menu to settings demo

Allow toggling column visibility from here.
This commit is contained in:
Matthias Clasen 2020-05-31 14:44:42 -04:00
parent cb2901ec40
commit c835214540
2 changed files with 38 additions and 2 deletions

View File

@ -300,7 +300,11 @@ do_listview_settings (GtkWidget *do_widget)
GtkBuilderScope *scope; GtkBuilderScope *scope;
GtkBuilder *builder; GtkBuilder *builder;
GtkColumnViewColumn *name_column; GtkColumnViewColumn *name_column;
GtkColumnViewColumn *type_column;
GtkColumnViewColumn *default_column;
GtkSorter *sorter; GtkSorter *sorter;
GActionGroup *actions;
GAction *action;
g_type_ensure (SETTINGS_TYPE_KEY); g_type_ensure (SETTINGS_TYPE_KEY);
@ -320,6 +324,22 @@ do_listview_settings (GtkWidget *do_widget)
listview = GTK_WIDGET (gtk_builder_get_object (builder, "listview")); listview = GTK_WIDGET (gtk_builder_get_object (builder, "listview"));
columnview = GTK_WIDGET (gtk_builder_get_object (builder, "columnview")); columnview = GTK_WIDGET (gtk_builder_get_object (builder, "columnview"));
type_column = GTK_COLUMN_VIEW_COLUMN (gtk_builder_get_object (builder, "type_column"));
default_column = GTK_COLUMN_VIEW_COLUMN (gtk_builder_get_object (builder, "default_column"));
actions = G_ACTION_GROUP (g_simple_action_group_new ());
action = G_ACTION (g_property_action_new ("show-type", type_column, "visible"));
g_action_map_add_action (G_ACTION_MAP (actions), action);
g_object_unref (action);
action = G_ACTION (g_property_action_new ("show-default", default_column, "visible"));
g_action_map_add_action (G_ACTION_MAP (actions), action);
g_object_unref (action);
gtk_widget_insert_action_group (columnview, "columnview", actions);
g_object_unref (actions);
model = create_settings_model (NULL, NULL); model = create_settings_model (NULL, NULL);
treemodel = gtk_tree_list_model_new (FALSE, treemodel = gtk_tree_list_model_new (FALSE,
model, model,

View File

@ -77,6 +77,7 @@
<child> <child>
<object class="GtkColumnViewColumn" id="name_column"> <object class="GtkColumnViewColumn" id="name_column">
<property name="title">Name</property> <property name="title">Name</property>
<property name="header-menu">header_menu</property>
<property name="factory"> <property name="factory">
<object class="GtkBuilderListItemFactory"> <object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[ <property name="bytes"><![CDATA[
@ -103,6 +104,7 @@
<child> <child>
<object class="GtkColumnViewColumn"> <object class="GtkColumnViewColumn">
<property name="title">Value</property> <property name="title">Value</property>
<property name="header-menu">header_menu</property>
<property name="factory"> <property name="factory">
<object class="GtkBuilderListItemFactory"> <object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[ <property name="bytes"><![CDATA[
@ -127,8 +129,9 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkColumnViewColumn"> <object class="GtkColumnViewColumn" id="type_column">
<property name="title">Type</property> <property name="title">Type</property>
<property name="header-menu">header_menu</property>
<property name="factory"> <property name="factory">
<object class="GtkBuilderListItemFactory"> <object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[ <property name="bytes"><![CDATA[
@ -153,8 +156,9 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkColumnViewColumn"> <object class="GtkColumnViewColumn" id="default_column">
<property name="title">Default</property> <property name="title">Default</property>
<property name="header-menu">header_menu</property>
<property name="factory"> <property name="factory">
<object class="GtkBuilderListItemFactory"> <object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[ <property name="bytes"><![CDATA[
@ -187,4 +191,16 @@
</object> </object>
</child> </child>
</object> </object>
<menu id="header_menu">
<section>
<item>
<attribute name="label" translatable="yes">Type</attribute>
<attribute name="action">columnview.show-type</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Default value</attribute>
<attribute name="action">columnview.show-default</attribute>
</item>
</section>
</menu>
</interface> </interface>