[gucharmap] charmap: Rearrange menus
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gucharmap] charmap: Rearrange menus
- Date: Mon, 25 Jun 2012 12:04:48 +0000 (UTC)
commit 9af5beb1554861d5e717ce5030b5341310dd26f3
Author: Christian Persch <chpe gnome org>
Date: Mon Jun 25 14:03:08 2012 +0200
charmap: Rearrange menus
Turns out the 2-word app menu in the window's menu bar when there's no
shell to show the app menu looks like crap. Re-arrange the menus so that
we go back to having the old menu order in the window, independently of
the app menu. Only create the app menu when there's a shell to actually
show it, so that it doesn't show in the window's menubar instead.
gucharmap/gucharmap-menus.ui | 91 ++++++++++++++++++++++--
gucharmap/gucharmap.gresource.xml.in | 2 +-
gucharmap/main.c | 128 +++++++--------------------------
3 files changed, 112 insertions(+), 109 deletions(-)
---
diff --git a/gucharmap/gucharmap-menus.ui b/gucharmap/gucharmap-menus.ui
index 170f8dc..9426d0d 100644
--- a/gucharmap/gucharmap-menus.ui
+++ b/gucharmap/gucharmap-menus.ui
@@ -23,17 +23,80 @@
<interface>
<menu id="app-menu">
- <item><link name="section" id="shell-view-by"/>
- <attribute name="label" translatable="yes">View By</attribute>
- </item>
- <item><link name="section" id="shell-view"></link></item>
- <item><link name="section" id="shell-zoom"></link></item>
- <item><link name="section" id="shell-find"></link></item>
- <item><link name="section" id="general"></link></item>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">By _Script</attribute>
+ <attribute name="action">app.group-by</attribute>
+ <attribute name="target">script</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">By _Unicode Block</attribute>
+ <attribute name="action">app.group-by</attribute>
+ <attribute name="target">block</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Sho_w only glyphs from this font</attribute>
+ <attribute name="action">app.show-only-glyphs-in-font</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Zoom _In</attribute>
+ <attribute name="action">app.zoom-in</attribute>
+ <attribute name="accel"><Primary>plus</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Zoom _Out</attribute>
+ <attribute name="action">app.zoom-out</attribute>
+ <attribute name="accel"><Primary>minus</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Normal Size</attribute>
+ <attribute name="action">app.normal-size</attribute>
+ <attribute name="accel"><Primary>0</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Find</attribute>
+ <attribute name="action">app.find</attribute>
+ <attribute name="accel"><Primary>f</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Help</attribute>
+ <attribute name="action">app.help</attribute>
+ <attribute name="accel">F1</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_About</attribute>
+ <attribute name="action">app.about</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Close Window</attribute>
+ <attribute name="action">app.close</attribute>
+ <attribute name="accel"><Primary>plus</attribute>
+ </item>
+ </section>
</menu>
<menu id="menubar">
<submenu>
+ <attribute name="label" translatable="yes">_File</attribute>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Close</attribute>
+ <attribute name="action">win.close</attribute>
+ <attribute name="accel"><Primary>plus</attribute>
+ </item>
+ </section>
+ </submenu>
+ <submenu>
<attribute name="label" translatable="yes">_View</attribute>
<section>
<item>
@@ -111,5 +174,19 @@
</section>
<item><link name="section" id="go-chapter"/></item>
</submenu>
+ <submenu>
+ <attribute name="label" translatable="yes">_Help</attribute>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Contents</attribute>
+ <attribute name="action">win.help</attribute>
+ <attribute name="accel">F1</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_About</attribute>
+ <attribute name="action">win.about</attribute>
+ </item>
+ </section>
+ </submenu>
</menu>
</interface>
diff --git a/gucharmap/gucharmap.gresource.xml.in b/gucharmap/gucharmap.gresource.xml.in
index e125ac6..8888a04 100644
--- a/gucharmap/gucharmap.gresource.xml.in
+++ b/gucharmap/gucharmap.gresource.xml.in
@@ -17,6 +17,6 @@
-->
<gresources>
<gresource prefix="/org/gnome/charmap">
- <file preprocess="xml-stripblanks" alias="gucharmap-menus.ui">@srcdir@/gucharmap-menus.ui</file>
+ <file alias="ui/menus.ui" preprocess="xml-stripblanks">gucharmap-menus.ui</file>
</gresource>
</gresources>
diff --git a/gucharmap/main.c b/gucharmap/main.c
index 25293f2..839b3dc 100644
--- a/gucharmap/main.c
+++ b/gucharmap/main.c
@@ -28,7 +28,7 @@
#include <gucharmap/gucharmap.h>
#include "gucharmap-window.h"
-#define UI_RESOURCE "/org/gnome/charmap/gucharmap-menus.ui"
+#define UI_RESOURCE "/org/gnome/charmap/ui/menus.ui"
static gboolean
option_version_cb (const gchar *option_name,
@@ -91,92 +91,33 @@ change_toggle_state (GSimpleAction *action,
}
static void
-activate_quit (GSimpleAction *action,
- GVariant *parameter,
- gpointer data)
+activate_close (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
- g_list_foreach (gtk_application_get_windows (GTK_APPLICATION (data)),
- (GFunc)gtk_widget_destroy, NULL);
-}
-
-static void
-update_shell_app_menu (GtkSettings *settings,
- GParamSpec *pspec,
- gpointer data)
-{
- GObject *app = G_OBJECT (data);
- GMenu *menu;
- gboolean show_app_menu;
-
- g_object_get (G_OBJECT (settings),
- "gtk-shell-shows-app-menu", &show_app_menu,
- NULL);
-
- menu = g_object_get_data (app, "shell-view-by-section");
+ GList *windows, *l;
- while (g_menu_model_get_n_items (G_MENU_MODEL (menu)) > 0)
- g_menu_remove (menu, 0);
-
- if (show_app_menu)
- {
- g_menu_append (menu, _("Script"), "app.group-by::script");
- g_menu_append (menu, _("Unicode Block"), "app.group-by::block");
- }
+ /* FIXME: use gtk_application_get_active_window() once it exists */
+ windows = gtk_application_get_windows (GTK_APPLICATION (user_data));
+ for (l = windows; l != NULL; l = l->next) {
+ GtkWidget *window = l->data;
+ if (!GTK_IS_APPLICATION_WINDOW (window))
+ continue;
- menu = g_object_get_data (app, "shell-view-section");
-
- while (g_menu_model_get_n_items (G_MENU_MODEL (menu)) > 0)
- g_menu_remove (menu, 0);
-
- if (show_app_menu)
- {
- g_menu_append (menu, _("Show only glyphs from this font"),
- "app.show-only-glyphs-in-font");
- }
-
-
- menu = g_object_get_data (app, "shell-zoom-section");
-
- while (g_menu_model_get_n_items (G_MENU_MODEL (menu)) > 0)
- g_menu_remove (menu, 0);
-
- if (show_app_menu)
- {
- g_menu_append (menu, _("Zoom In"), "app.zoom-in");
- g_menu_append (menu, _("Zoom Out"), "app.zoom-out");
- g_menu_append (menu, _("Normal Size"), "app.normal-size");
- }
-
-
- menu = g_object_get_data (app, "shell-find-section");
-
- while (g_menu_model_get_n_items (G_MENU_MODEL (menu)) > 0)
- g_menu_remove (menu, 0);
-
- if (show_app_menu)
- {
- g_menu_append (menu, _("Find\342\200\246"), "app.find");
- }
-
-
- menu = g_object_get_data (app, "general-section");
-
- while (g_menu_model_get_n_items (G_MENU_MODEL (menu)) > 0)
- g_menu_remove (menu, 0);
-
- g_menu_append (menu, _("_Help"), "app.help");
- g_menu_append (menu, _("_About Character Map"), "app.about");
- g_menu_append (menu, show_app_menu ? _("_Quit") : _("_Close"), "app.quit");
+ gtk_widget_destroy (window);
+ break;
+ }
}
-
static void
startup_cb (GApplication *application,
gpointer data)
{
GtkBuilder *builder = gtk_builder_new ();
GMenuModel *model;
+ gboolean show_app_menu;
+
const GActionEntry app_entries[] =
{
{ "group-by", activate_action, "s", "\"script\"", NULL },
@@ -192,34 +133,24 @@ startup_cb (GApplication *application,
{ "help", activate_action, NULL, NULL, NULL },
{ "about", activate_action, NULL, NULL, NULL },
- { "quit", activate_quit, NULL, NULL, NULL },
+ { "close", activate_close, NULL, NULL, NULL },
};
g_action_map_add_action_entries (G_ACTION_MAP (application),
app_entries, G_N_ELEMENTS (app_entries),
application);
+
gtk_builder_add_from_resource (builder, UI_RESOURCE, NULL);
/* app menu */
- model = G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu"));
- gtk_application_set_app_menu (GTK_APPLICATION (application), model);
-
- model = G_MENU_MODEL (gtk_builder_get_object (builder, "shell-view-by"));
- g_object_set_data (G_OBJECT (application), "shell-view-by-section", model);
-
- model = G_MENU_MODEL (gtk_builder_get_object (builder, "shell-view"));
- g_object_set_data (G_OBJECT (application), "shell-view-section", model);
-
- model = G_MENU_MODEL (gtk_builder_get_object (builder, "shell-zoom"));
- g_object_set_data (G_OBJECT (application), "shell-zoom-section", model);
-
- model = G_MENU_MODEL (gtk_builder_get_object (builder, "shell-find"));
- g_object_set_data (G_OBJECT (application), "shell-find-section", model);
-
- model = G_MENU_MODEL (gtk_builder_get_object (builder, "general"));
- g_object_set_data (G_OBJECT (application), "general-section", model);
-
+ g_object_get (gtk_settings_get_default (),
+ "gtk-shell-shows-app-menu", &show_app_menu,
+ NULL);
+ if (show_app_menu) {
+ model = G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu"));
+ gtk_application_set_app_menu (GTK_APPLICATION (application), model);
+ }
/* window menu */
@@ -246,9 +177,9 @@ startup_cb (GApplication *application,
gtk_application_add_accelerator (GTK_APPLICATION (application),
"F1", "app.help", NULL);
gtk_application_add_accelerator (GTK_APPLICATION (application),
- "<Primary>q", "app.quit", NULL);
+ "<Primary>q", "app.close", NULL);
gtk_application_add_accelerator (GTK_APPLICATION (application),
- "<Primary>w", "app.quit", NULL);
+ "<Primary>w", "app.close", NULL);
g_object_unref (builder);
@@ -315,11 +246,6 @@ main (int argc, char **argv)
window = gucharmap_window_new (application);
- g_signal_connect (gtk_widget_get_settings (window),
- "notify::gtk-shell-shows-app-menu",
- G_CALLBACK (update_shell_app_menu), application);
- update_shell_app_menu (gtk_widget_get_settings (window), NULL, application);
-
screen = gtk_window_get_screen (GTK_WINDOW (window));
monitor = gdk_screen_get_monitor_at_point (screen, 0, 0);
#if GTK_CHECK_VERSION (3, 3, 5)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]