widget factory: Redo the menubar with a model

No UI change intended, except for the fact that
actions don't do inconsistent states for checks
and radios.
This commit is contained in:
Matthias Clasen 2019-06-07 18:05:57 +00:00
parent f91cc6c473
commit 4d191aa0b5
2 changed files with 159 additions and 0 deletions

View File

@ -1932,6 +1932,12 @@ activate (GApplication *app)
model = (GMenuModel *)gtk_builder_get_object (builder, "new_style_context_menu_model");
set_up_context_popover (widget, model);
widget = gtk_bin_get_child (GTK_BIN (gtk_builder_get_object (builder, "page2frame2")));
model = (GMenuModel *)gtk_builder_get_object (builder, "menu_bar_model");
widget2 = gtk_popover_bar_new_from_model (model);
gtk_container_add (GTK_CONTAINER (widget), widget2);
gtk_box_reorder_child_after (GTK_BOX (widget), widget2, NULL);
gtk_widget_show (GTK_WIDGET (window));
g_object_unref (builder);
@ -2017,10 +2023,13 @@ main (int argc, char *argv[])
{ "print", activate_action, NULL, NULL, NULL },
{ "share", activate_action, NULL, NULL, NULL },
{ "labels", activate_action, NULL, NULL, NULL },
{ "new", activate_action, NULL, NULL, NULL },
{ "open", activate_action, NULL, NULL, NULL },
{ "open-in", activate_action, NULL, NULL, NULL },
{ "open-tab", activate_action, NULL, NULL, NULL },
{ "open-window", activate_action, NULL, NULL, NULL },
{ "save", activate_action, NULL, NULL, NULL },
{ "save-as", activate_action, NULL, NULL, NULL },
{ "cut", activate_action, NULL, NULL, NULL },
{ "copy", activate_action, NULL, NULL, NULL },
{ "paste", activate_action, NULL, NULL, NULL },
@ -2034,6 +2043,12 @@ main (int argc, char *argv[])
{ "option-b", activate_action, NULL, NULL, NULL },
{ "option-c", activate_action, NULL, NULL, NULL },
{ "option-d", activate_action, NULL, NULL, NULL },
{ "check-on", NULL, NULL, "true", NULL },
{ "check-off", NULL, NULL, "false", NULL },
{ "radio-x", NULL, "s", "'x'", NULL },
{ "check-on-disabled", NULL, NULL, "true", NULL },
{ "check-off-disabled", NULL, NULL, "false", NULL },
{ "radio-x-disabled", NULL, "s", "'x'", NULL },
};
gint status;
@ -2044,6 +2059,12 @@ main (int argc, char *argv[])
app);
action = g_action_map_lookup_action (G_ACTION_MAP (app), "wine");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
action = g_action_map_lookup_action (G_ACTION_MAP (app), "check-on-disabled");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
action = g_action_map_lookup_action (G_ACTION_MAP (app), "check-off-disabled");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
action = g_action_map_lookup_action (G_ACTION_MAP (app), "radio-x-disabled");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);

View File

@ -3887,4 +3887,142 @@ bad things might happen.</property>
</item>
</section>
</menu>
<menu id="menu_bar_model">
<submenu>
<attribute name="label" translatable="yes">File</attribute>
<section>
<item>
<attribute name="label" translatable="yes">_New</attribute>
<attribute name="action">app.new</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Open</attribute>
<attribute name="action">app.open</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Save</attribute>
<attribute name="action">app.save</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Save _As</attribute>
<attribute name="action">app.save-as</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">_Quit</attribute>
<attribute name="action">app.quit</attribute>
</item>
</section>
</submenu>
<submenu>
<attribute name="label" translatable="yes">Edit</attribute>
<section>
<item>
<attribute name="label" translatable="yes">Cu_t</attribute>
<attribute name="action">app.cut</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Copy</attribute>
<attribute name="action">app.copy</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Paste</attribute>
<attribute name="action">app.paste</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Delete</attribute>
<attribute name="action">win.delete</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Search</attribute>
<attribute name="action">win.search</attribute>
</item>
</section>
<section>
<submenu>
<attribute name="label" translatable="yes">Checks &amp; Radios</attribute>
<section>
<item>
<attribute name="label" translatable="yes">Check</attribute>
<attribute name="action">app.check-on</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Check</attribute>
<attribute name="action">app.check-off</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Check</attribute>
<attribute name="action">app.check-on-disabled</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Check</attribute>
<attribute name="action">app.check-off-disabled</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Check</attribute>
<attribute name="action">app.check-no-action</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">Radio</attribute>
<attribute name="action">app.radio-x</attribute>
<attribute name="target">x</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Radio</attribute>
<attribute name="action">app.radio-x</attribute>
<attribute name="target">y</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Radio</attribute>
<attribute name="action">app.radio-x-disabled</attribute>
<attribute name="target">x</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Radio</attribute>
<attribute name="action">app.radio-x-disabled</attribute>
<attribute name="target">y</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Radio</attribute>
<attribute name="action">app.radio-no-action</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
</section>
</submenu>
</section>
</submenu>
<submenu>
<attribute name="label" translatable="yes">View</attribute>
<section>
<item>
<attribute name="label" translatable="yes">Dark Theme</attribute>
<attribute name="action">win.dark</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Toolbar</attribute>
<attribute name="action">win.toolbar</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Statusbar</attribute>
<attribute name="action">win.statusbar</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Select Background</attribute>
<attribute name="action">win.background</attribute>
</item>
</section>
</submenu>
<submenu>
<attribute name="label" translatable="yes">Help</attribute>
<item>
<attribute name="label" translatable="yes">About</attribute>
<attribute name="action">app.about</attribute>
</item>
</submenu>
</menu>
</interface>