[gnome-terminal] application: Add skeleton application menu



commit 040fcff03b586253934c283224dc8a9b6dab6757
Author: Christian Persch <chpe gnome org>
Date:   Sat Apr 14 22:33:19 2012 +0200

    application: Add skeleton application menu
    
    Part of https://bugzilla.gnome.org/show_bug.cgi?id=672433

 src/Makefile.am            |    1 +
 src/terminal-app.c         |   68 +++++++++++++++++++++++++-
 src/terminal-appmenu.ui    |   40 +++++++++++++++
 src/terminal-util.c        |  115 +++++++++++++++++++++++++++++++------------
 src/terminal-util.h        |    2 +
 src/terminal-window.c      |   74 +----------------------------
 src/terminal.gresource.xml |    1 +
 7 files changed, 195 insertions(+), 106 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index bcc557a..1fb6190 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -291,6 +291,7 @@ CLEANFILES = \
 
 EXTRA_DIST = \
 	terminal.xml \
+	terminal-appmenu.ui \
 	terminal.gresource.xml \
 	terminal-marshal.list \
 	terminal-type-builtins.c.template \
diff --git a/src/terminal-app.c b/src/terminal-app.c
index f395aef..b60bc6c 100644
--- a/src/terminal-app.c
+++ b/src/terminal-app.c
@@ -1105,6 +1105,37 @@ terminal_app_manage_profiles (TerminalApp     *app,
 #endif
 }
 
+/* App menu callbacks */
+
+static void
+app_menu_preferences_cb (GSimpleAction *action,
+                         GVariant      *parameter,
+                         gpointer       user_data)
+{
+  TerminalApp *app = user_data;
+
+  terminal_app_edit_profile (app,
+                             terminal_app_get_profile_by_name (app, TERMINAL_DEFAULT_PROFILE_ID) /* FIXME */,
+                             NULL /* FIXME use last active window? */,
+                             NULL);
+}
+
+static void
+app_menu_help_cb (GSimpleAction *action,
+                  GVariant      *parameter,
+                  gpointer       user_data)
+{
+  terminal_util_show_help (NULL, NULL /* FIXME use last active window? */);
+}
+
+static void
+app_menu_about_cb (GSimpleAction *action,
+                   GVariant      *parameter,
+                   gpointer       user_data)
+{
+  terminal_util_show_about (NULL /* FIXME use last active window? */);
+}
+
 /* Class implementation */
 
 G_DEFINE_TYPE (TerminalApp, terminal_app, GTK_TYPE_APPLICATION)
@@ -1112,11 +1143,45 @@ G_DEFINE_TYPE (TerminalApp, terminal_app, GTK_TYPE_APPLICATION)
 /* GApplicationClass impl */
 
 static void
-terminal_app_activate (GApplication *gapp)
+terminal_app_activate (GApplication *application)
 {
   /* No-op required because GApplication is stupid */
 }
 
+static void
+terminal_app_startup (GApplication *application)
+{
+  const GActionEntry app_menu_actions[] = {
+    { "preferences", app_menu_preferences_cb,   NULL, NULL, NULL },
+    { "help",        app_menu_help_cb,          NULL, NULL, NULL },
+    { "about",       app_menu_about_cb,         NULL, NULL, NULL }
+  };
+
+  TerminalApp *app = TERMINAL_APP (application);
+  GtkBuilder *builder;
+  GError *error = NULL;
+
+  G_APPLICATION_CLASS (terminal_app_parent_class)->startup (application);
+
+  /* FIXME: Is this the right place to do prefs migration from gconf->dconf? */
+
+  g_action_map_add_action_entries (G_ACTION_MAP (application),
+                                   app_menu_actions, G_N_ELEMENTS (app_menu_actions),
+                                   application);
+
+  builder = gtk_builder_new ();
+  gtk_builder_add_from_resource (builder,
+                                 TERMINAL_RESOURCES_PATH_PREFIX "ui/terminal-appmenu.ui",
+                                 &error);
+  g_assert_no_error (error);
+
+  gtk_application_set_app_menu (GTK_APPLICATION (application),
+                                G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu")));
+  g_object_unref (builder);
+
+  g_print ("Done startup!\n");
+}
+
 /* GObjectClass impl */
 
 static void
@@ -1228,6 +1293,7 @@ terminal_app_class_init (TerminalAppClass *klass)
   object_class->finalize = terminal_app_finalize;
 
   g_application_class->activate = terminal_app_activate;
+  g_application_class->startup = terminal_app_startup;
 
   klass->quit = terminal_app_real_quit;
 
diff --git a/src/terminal-appmenu.ui b/src/terminal-appmenu.ui
new file mode 100644
index 0000000..d20d7d2
--- /dev/null
+++ b/src/terminal-appmenu.ui
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright  2012 Christian Persch
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3, or (at your option)
+  any later version.
+
+  This program is distributed in the hope conf it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+-->
+<interface>
+  <menu id="appmenu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Preferences</attribute>
+        <attribute name="action">app.preferences</attribute>
+        <attribute name="accel">&lt;Primary&gt;e</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>
+  </menu>
+</interface>
diff --git a/src/terminal-util.c b/src/terminal-util.c
index 95cd26d..5ee2339 100644
--- a/src/terminal-util.c
+++ b/src/terminal-util.c
@@ -147,42 +147,16 @@ void
 terminal_util_show_help (const char *topic, 
                          GtkWindow  *parent)
 {
+  char *uri;
   GError *error = NULL;
-  const char *lang;
-  char *uri = NULL, *url;
-  guint i;
- 
-  const char * const * langs = g_get_language_names ();
-  for (i = 0; langs[i]; i++) {
-    lang = langs[i];
-    if (strchr (lang, '.')) {
-      continue;
-    }
- 
-    uri = g_build_filename (TERM_HELPDIR,
-                            "gnome-terminal", /* DOC_MODULE */
-                            lang,
-                            "gnome-terminal.xml",
-                            NULL);
-					
-    if (g_file_test (uri, G_FILE_TEST_EXISTS)) {
-      break;
-    }
-
-    g_free (uri);
-    uri = NULL;
-  }
-
-  if (!uri)
-    return;
 
   if (topic) {
-    url = g_strdup_printf ("ghelp://%s?%s", uri, topic);
+    uri = g_strdup_printf ("help:gnome-terminal/%s", topic);
   } else {
-    url = g_strdup_printf ("ghelp://%s", uri);
+    uri = g_strdup ("help:gnome-terminal");
   }
 
-  if (!open_url (GTK_WINDOW (parent), url, gtk_get_current_event_time (), &error))
+  if (!open_url (GTK_WINDOW (parent), uri, gtk_get_current_event_time (), &error))
     {
       terminal_util_show_error_dialog (GTK_WINDOW (parent), NULL, error,
                                        _("There was an error displaying help"));
@@ -190,9 +164,86 @@ terminal_util_show_help (const char *topic,
     }
 
   g_free (uri);
-  g_free (url);
 }
- 
+
+#define ABOUT_GROUP "About"
+#define EMAILIFY(string) (g_strdelimit ((string), "%", '@'))
+
+void
+terminal_util_show_about (GtkWindow *transient_parent)
+{
+  static const char copyright[] =
+    "Copyright  2002â2004 Havoc Pennington\n"
+    "Copyright  2003â2004, 2007 Mariano SuÃrez-Alvarez\n"
+    "Copyright  2006 Guilherme de S. Pastore\n"
+    "Copyright  2007â2012 Christian Persch";
+  char *licence_text;
+  GKeyFile *key_file;
+  GError *error = NULL;
+  char **authors, **contributors, **artists, **documenters, **array_strv;
+  gsize n_authors = 0, n_contributors = 0, n_artists = 0, n_documenters = 0 , i;
+  GPtrArray *array;
+
+  key_file = g_key_file_new ();
+  if (!g_key_file_load_from_file (key_file, TERM_PKGDATADIR G_DIR_SEPARATOR_S "terminal.about", 0, &error))
+    {
+      g_warning ("Couldn't load about data: %s\n", error->message);
+      g_error_free (error);
+      g_key_file_free (key_file);
+      return;
+    }
+
+  authors = g_key_file_get_string_list (key_file, ABOUT_GROUP, "Authors", &n_authors, NULL);
+  contributors = g_key_file_get_string_list (key_file, ABOUT_GROUP, "Contributors", &n_contributors, NULL);
+  artists = g_key_file_get_string_list (key_file, ABOUT_GROUP, "Artists", &n_artists, NULL);
+  documenters = g_key_file_get_string_list (key_file, ABOUT_GROUP, "Documenters", &n_documenters, NULL);
+  g_key_file_free (key_file);
+
+  array = g_ptr_array_new ();
+
+  for (i = 0; i < n_authors; ++i)
+    g_ptr_array_add (array, EMAILIFY (authors[i]));
+  g_free (authors); /* strings are now owned by the array */
+
+  if (n_contributors > 0)
+  {
+    g_ptr_array_add (array, g_strdup (""));
+    g_ptr_array_add (array, g_strdup (_("Contributors:")));
+    for (i = 0; i < n_contributors; ++i)
+      g_ptr_array_add (array, EMAILIFY (contributors[i]));
+  }
+  g_free (contributors); /* strings are now owned by the array */
+  
+  g_ptr_array_add (array, NULL);
+  array_strv = (char **) g_ptr_array_free (array, FALSE);
+
+  for (i = 0; i < n_artists; ++i)
+    artists[i] = EMAILIFY (artists[i]);
+  for (i = 0; i < n_documenters; ++i)
+    documenters[i] = EMAILIFY (documenters[i]);
+
+  licence_text = terminal_util_get_licence_text ();
+
+  gtk_show_about_dialog (transient_parent,
+                         "program-name", _("GNOME Terminal"),
+                         "copyright", copyright,
+                         "comments", _("A terminal emulator for the GNOME desktop"),
+                         "version", VERSION,
+                         "authors", array_strv,
+                         "artists", artists,
+                         "documenters", documenters,
+                         "license", licence_text,
+                         "wrap-license", TRUE,
+                         "translator-credits", _("translator-credits"),
+                         "logo-icon-name", GNOME_TERMINAL_ICON_NAME,
+                         NULL);
+
+  g_strfreev (array_strv);
+  g_strfreev (artists);
+  g_strfreev (documenters);
+  g_free (licence_text);
+}
+
 /* sets accessible name and description for the widget */
 
 void
diff --git a/src/terminal-util.h b/src/terminal-util.h
index e9c3c36..3e4e1c5 100644
--- a/src/terminal-util.h
+++ b/src/terminal-util.h
@@ -37,6 +37,8 @@ void terminal_util_show_error_dialog (GtkWindow *transient_parent,
 
 void terminal_util_show_help (const char *topic, GtkWindow  *transient_parent);
 
+void terminal_util_show_about (GtkWindow *transient_parent);
+
 void terminal_util_set_labelled_by          (GtkWidget  *widget,
                                              GtkLabel   *label);
 void terminal_util_set_atk_name_description (GtkWidget  *widget,
diff --git a/src/terminal-window.c b/src/terminal-window.c
index d2ea463..2a77c53 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -3509,83 +3509,11 @@ help_contents_callback (GtkAction *action,
   terminal_util_show_help (NULL, GTK_WINDOW (window));
 }
 
-#define ABOUT_GROUP "About"
-#define EMAILIFY(string) (g_strdelimit ((string), "%", '@'))
-
 static void
 help_about_callback (GtkAction *action,
                      TerminalWindow *window)
 {
-  static const char copyright[] =
-    "Copyright  2002â2004 Havoc Pennington\n"
-    "Copyright  2003â2004, 2007 Mariano SuÃrez-Alvarez\n"
-    "Copyright  2006 Guilherme de S. Pastore\n"
-    "Copyright  2007â2011 Christian Persch";
-  char *licence_text;
-  GKeyFile *key_file;
-  GError *error = NULL;
-  char **authors, **contributors, **artists, **documenters, **array_strv;
-  gsize n_authors = 0, n_contributors = 0, n_artists = 0, n_documenters = 0 , i;
-  GPtrArray *array;
-
-  key_file = g_key_file_new ();
-  if (!g_key_file_load_from_file (key_file, TERM_PKGDATADIR G_DIR_SEPARATOR_S "terminal.about", 0, &error))
-    {
-      g_warning ("Couldn't load about data: %s\n", error->message);
-      g_error_free (error);
-      g_key_file_free (key_file);
-      return;
-    }
-
-  authors = g_key_file_get_string_list (key_file, ABOUT_GROUP, "Authors", &n_authors, NULL);
-  contributors = g_key_file_get_string_list (key_file, ABOUT_GROUP, "Contributors", &n_contributors, NULL);
-  artists = g_key_file_get_string_list (key_file, ABOUT_GROUP, "Artists", &n_artists, NULL);
-  documenters = g_key_file_get_string_list (key_file, ABOUT_GROUP, "Documenters", &n_documenters, NULL);
-  g_key_file_free (key_file);
-
-  array = g_ptr_array_new ();
-
-  for (i = 0; i < n_authors; ++i)
-    g_ptr_array_add (array, EMAILIFY (authors[i]));
-  g_free (authors); /* strings are now owned by the array */
-
-  if (n_contributors > 0)
-  {
-    g_ptr_array_add (array, g_strdup (""));
-    g_ptr_array_add (array, g_strdup (_("Contributors:")));
-    for (i = 0; i < n_contributors; ++i)
-      g_ptr_array_add (array, EMAILIFY (contributors[i]));
-  }
-  g_free (contributors); /* strings are now owned by the array */
-  
-  g_ptr_array_add (array, NULL);
-  array_strv = (char **) g_ptr_array_free (array, FALSE);
-
-  for (i = 0; i < n_artists; ++i)
-    artists[i] = EMAILIFY (artists[i]);
-  for (i = 0; i < n_documenters; ++i)
-    documenters[i] = EMAILIFY (documenters[i]);
-
-  licence_text = terminal_util_get_licence_text ();
-
-  gtk_show_about_dialog (GTK_WINDOW (window),
-			 "program-name", _("GNOME Terminal"),
-			 "copyright", copyright,
-			 "comments", _("A terminal emulator for the GNOME desktop"),
-			 "version", VERSION,
-			 "authors", array_strv,
-                         "artists", artists,
-                         "documenters", documenters,
-			 "license", licence_text,
-			 "wrap-license", TRUE,
-			 "translator-credits", _("translator-credits"),
-			 "logo-icon-name", GNOME_TERMINAL_ICON_NAME,
-			 NULL);
-
-  g_strfreev (array_strv);
-  g_strfreev (artists);
-  g_strfreev (documenters);
-  g_free (licence_text);
+  terminal_util_show_about (GTK_WINDOW (window));
 }
 
 GtkUIManager *
diff --git a/src/terminal.gresource.xml b/src/terminal.gresource.xml
index c094708..ed3bf1a 100644
--- a/src/terminal.gresource.xml
+++ b/src/terminal.gresource.xml
@@ -18,5 +18,6 @@
 <gresources>
   <gresource prefix="/org/gnome/terminal">
     <file alias="ui/terminal.xml" compressed="true" preprocess="xml-stripblanks">terminal.xml</file>
+    <file alias="ui/terminal-appmenu.ui" compressed="true" preprocess="xml-stripblanks">terminal-appmenu.ui</file>
   </gresource>
 </gresources>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]