[gtranslator] Add app menu
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator] Add app menu
- Date: Fri, 4 May 2012 17:52:35 +0000 (UTC)
commit fdb78bb7836748eb0b83b4a225989ff1a65ea3c9
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Wed May 2 19:34:17 2012 +0200
Add app menu
src/Makefile.am | 3 +-
src/{gtr-actions-help.c => gtr-actions-app.c} | 6 +-
src/gtr-actions-edit.c | 7 --
src/gtr-actions.h | 8 --
src/gtr-application.c | 89 +++++++++++++++++++++++--
src/gtr-window.c | 10 ---
src/gtranslator-menu.ui | 36 ++++++++++
src/gtranslator-ui.xml | 6 --
src/gtranslator.gresource.xml | 1 +
9 files changed, 126 insertions(+), 40 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 8c4883f..ab620cf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -77,6 +77,7 @@ INST_H_FILES = \
NOINST_H_FILES = \
gtr-actions.h \
+ gtr-actions-app.h \
gtr-assistant.h \
gtr-close-button.h \
gtr-close-confirmation-dialog.h \
@@ -111,11 +112,11 @@ libgtranslator_private_la_SOURCES = \
$(BUILT_SOURCES_PRIVATE)
libgtranslator_c_files = \
+ gtr-actions-app.c \
gtr-actions-documents.c \
gtr-actions-edit.c \
gtr-actions-file.c \
gtr-actions-go.c \
- gtr-actions-help.c \
gtr-actions-search.c \
gtr-actions-view.c \
gtr-application.c \
diff --git a/src/gtr-actions-help.c b/src/gtr-actions-app.c
similarity index 96%
rename from src/gtr-actions-help.c
rename to src/gtr-actions-app.c
index 304403d..88dbab0 100644
--- a/src/gtr-actions-help.c
+++ b/src/gtr-actions-app.c
@@ -23,7 +23,7 @@
#include <config.h>
#endif
-#include "gtr-actions.h"
+#include "gtr-actions-app.h"
#include "gtr-dirs.h"
#include "gtr-utils.h"
#include "gtr-window.h"
@@ -35,14 +35,14 @@
/* Show the user's guide for gtranslator */
void
-gtr_cmd_help_contents (GtkAction * action, GtrWindow * window)
+gtr_show_help (GtrWindow *window)
{
gtr_utils_help_display (GTK_WINDOW (window), "gtranslator", "gtranslator.xml");
}
/* Creates and shows the about box for gtranslator */
void
-gtr_about_dialog (GtkAction * action, GtrWindow * window)
+gtr_about_dialog (GtrWindow *window)
{
static const gchar *authors[] = {
N_("Current Maintainers"),
diff --git a/src/gtr-actions-edit.c b/src/gtr-actions-edit.c
index 3046b6f..bcc2303 100644
--- a/src/gtr-actions-edit.c
+++ b/src/gtr-actions-edit.c
@@ -25,7 +25,6 @@
#include <glib/gi18n.h>
#include "gtr-header-dialog.h"
-#include "gtr-preferences-dialog.h"
#include "gtr-actions.h"
#include "gtr-msg.h"
#include "gtr-po.h"
@@ -151,12 +150,6 @@ gtr_message_status_toggle_fuzzy (GtkAction * action, GtrWindow * window)
}
void
-gtr_actions_edit_preferences (GtkAction * action, GtrWindow * window)
-{
- gtr_show_preferences_dialog (window);
-}
-
-void
gtr_actions_edit_header (GtkAction * action, GtrWindow * window)
{
gtr_show_header_dialog (window);
diff --git a/src/gtr-actions.h b/src/gtr-actions.h
index a23eafc..7a635ef 100644
--- a/src/gtr-actions.h
+++ b/src/gtr-actions.h
@@ -64,8 +64,6 @@ void gtr_message_copy_to_translation (GtkAction * action, GtrWindow * window);
void gtr_message_status_toggle_fuzzy (GtkAction * action, GtrWindow * window);
-void gtr_actions_edit_preferences (GtkAction * action, GtrWindow * window);
-
void gtr_actions_edit_clear (GtkAction * action, GtrWindow * window);
/* View */
@@ -113,11 +111,5 @@ void gtr_actions_documents_previous_document
/*Help*/
void gtr_window_show_home_page (GtkAction * action, gpointer useless);
-void gtr_cmd_help_contents (GtkAction * action, GtrWindow * window);
-
-void gtr_about_dialog (GtkAction * action, GtrWindow * window);
-
-
-
G_END_DECLS
#endif
diff --git a/src/gtr-application.c b/src/gtr-application.c
index 41d581d..078d0d4 100644
--- a/src/gtr-application.c
+++ b/src/gtr-application.c
@@ -26,12 +26,14 @@
#include "gtr-assistant.h"
#include "gtr-actions.h"
+#include "gtr-actions-app.h"
#include "gtr-application.h"
#include "gtr-debug.h"
#include "gtr-dirs.h"
#include "gtr-settings.h"
#include "gtr-utils.h"
#include "gtr-window.h"
+#include "gtr-preferences-dialog.h"
#include "egg-toolbars-model.h"
#include <glib.h>
@@ -250,8 +252,77 @@ gtr_application_finalize (GObject *object)
}
static void
+new_window_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtrApplication *app = GTR_APPLICATION (user_data);
+ GtrWindow *window;
+
+ window = gtr_application_create_window (app);
+ gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (window));
+}
+
+static void
+preferences_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtrApplication *app = GTR_APPLICATION (user_data);
+ gtr_show_preferences_dialog (app->priv->active_window);
+}
+
+static void
+help_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtrApplication *app = GTR_APPLICATION (user_data);
+ gtr_show_help (app->priv->active_window);
+}
+
+static void
+about_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtrApplication *app = GTR_APPLICATION (user_data);
+ gtr_about_dialog (app->priv->active_window);
+}
+
+static void
+quit_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtkApplication *app = GTK_APPLICATION (user_data);
+ GList *windows, *l;
+
+ // FIXME: this sucks, we need a way to deal with this in a better way
+ windows = gtk_application_get_windows (app);
+
+ for (l = windows; l != NULL; l = g_list_next (l))
+ {
+ gtr_file_quit (NULL, l->data);
+ }
+
+ // FIXME: we may want to continue editing
+ g_application_quit (G_APPLICATION (app));
+}
+
+static GActionEntry app_entries[] = {
+ { "new_window", new_window_activated, NULL, NULL, NULL },
+ { "preferences", preferences_activated, NULL, NULL, NULL },
+ { "help", help_activated, NULL, NULL, NULL },
+ { "about", about_activated, NULL, NULL, NULL },
+ { "quit", quit_activated, NULL, NULL, NULL }
+};
+
+static void
gtr_application_startup (GApplication *application)
{
+ GtkBuilder *builder;
+
G_APPLICATION_CLASS (gtr_application_parent_class)->startup (application);
g_set_application_name (_("Gtranslator"));
@@ -260,6 +331,15 @@ gtr_application_startup (GApplication *application)
/* We set the default icon dir */
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
gtr_dirs_get_gtr_pixmaps_dir ());
+
+ g_action_map_add_action_entries (G_ACTION_MAP (application), app_entries,
+ G_N_ELEMENTS (app_entries), application);
+
+ builder = gtk_builder_new ();
+ gtk_builder_add_from_resource (builder, "/org/gnome/gtranslator/ui/gtranslator-menu.ui", NULL);
+ gtk_application_set_app_menu (GTK_APPLICATION (application),
+ G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu")));
+ g_object_unref (builder);
}
static void
@@ -314,12 +394,12 @@ gtr_application_activate (GApplication *application)
}
static void
-gtr_application_quit_mainloop (GApplication *application)
+gtr_application_shutdown (GApplication *application)
{
ensure_user_config_dir ();
save_accels ();
- G_APPLICATION_CLASS (gtr_application_parent_class)->quit_mainloop (application);
+ G_APPLICATION_CLASS (gtr_application_parent_class)->shutdown (application);
}
static void
@@ -336,7 +416,7 @@ gtr_application_class_init (GtrApplicationClass *klass)
application_class->startup = gtr_application_startup;
application_class->open = gtr_application_open;
application_class->activate = gtr_application_activate;
- application_class->quit_mainloop = gtr_application_quit_mainloop;
+ application_class->shutdown = gtr_application_shutdown;
}
GtrApplication *
@@ -447,8 +527,7 @@ gtr_application_get_views (GtrApplication * app,
g_return_val_if_fail (GTR_IS_APPLICATION (app), NULL);
res = g_list_concat (res,
- gtr_window_get_all_views (GTR_WINDOW
- (app->priv->active_window),
+ gtr_window_get_all_views (GTR_WINDOW (app->priv->active_window),
original, translated));
return res;
diff --git a/src/gtr-window.c b/src/gtr-window.c
index 5b26b39..508a123 100644
--- a/src/gtr-window.c
+++ b/src/gtr-window.c
@@ -120,7 +120,6 @@ static const GtkActionEntry always_sensitive_entries[] = {
{"Go", NULL, N_("_Go")},
{"Tools", NULL, N_("_Tools")},
{"Documents", NULL, N_("_Documents")},
- {"Help", NULL, N_("_Help")},
/* File menu */
{"FileOpen", GTK_STOCK_OPEN, NULL, "<control>O",
@@ -135,17 +134,8 @@ static const GtkActionEntry always_sensitive_entries[] = {
/* Edit menu */
{"EditToolbar", NULL, N_("T_oolbar"), NULL, NULL,
G_CALLBACK (gtr_window_cmd_edit_toolbar)},
- {"EditPreferences", GTK_STOCK_PREFERENCES, NULL, NULL,
- N_("Edit gtranslator preferences"),
- G_CALLBACK (gtr_actions_edit_preferences)},
{"EditHeader", GTK_STOCK_PROPERTIES, N_("_Header..."), NULL, NULL,
G_CALLBACK (gtr_actions_edit_header)},
-
- /* Help menu */
- {"HelpContents", GTK_STOCK_HELP, N_("_Contents"), "F1", NULL,
- G_CALLBACK (gtr_cmd_help_contents)},
- {"HelpAbout", GTK_STOCK_ABOUT, NULL, NULL, NULL,
- G_CALLBACK (gtr_about_dialog)},
};
/* Normal items */
diff --git a/src/gtranslator-menu.ui b/src/gtranslator-menu.ui
new file mode 100644
index 0000000..11da064
--- /dev/null
+++ b/src/gtranslator-menu.ui
@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <menu id="appmenu">
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_New Window</attribute>
+ <attribute name="action">app.new_window</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Preferences</attribute>
+ <attribute name="action">app.preferences</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">_Quit</attribute>
+ <attribute name="action">app.quit</attribute>
+ <attribute name="accel"><Primary>q</attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
diff --git a/src/gtranslator-ui.xml b/src/gtranslator-ui.xml
index 59899a2..ec8dcc2 100644
--- a/src/gtranslator-ui.xml
+++ b/src/gtranslator-ui.xml
@@ -31,7 +31,6 @@
<placeholder name="EditOps_2" />
<separator/>
<menuitem name="EditToolbarMenu" action="EditToolbar"/>
- <menuitem name="EditPreferencesMenu" action="EditPreferences"/>
</menu>
<menu name="ViewMenu" action="View">
@@ -94,10 +93,5 @@
<separator/>
</placeholder>
</menu>
-
- <menu name="HelpMenu" action="Help">
- <menuitem name="HelpContentsMenu" action="HelpContents"/>
- <menuitem name="HelpAboutMenu" action="HelpAbout"/>
- </menu>
</menubar>
</ui>
diff --git a/src/gtranslator.gresource.xml b/src/gtranslator.gresource.xml
index 3608c65..09a42c3 100644
--- a/src/gtranslator.gresource.xml
+++ b/src/gtranslator.gresource.xml
@@ -2,6 +2,7 @@
<gresources>
<gresource prefix="/org/gnome/gtranslator/ui">
<file preprocess="xml-stripblanks">gtranslator-ui.xml</file>
+ <file preprocess="xml-stripblanks">gtranslator-menu.ui</file>
<file preprocess="xml-stripblanks">gtr-header-dialog.ui</file>
<file preprocess="xml-stripblanks">gtr-jump-dialog.ui</file>
<file preprocess="xml-stripblanks">gtr-languages-fetcher.ui</file>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]