[nautilus] application: implement app menu actions
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] application: implement app menu actions
- Date: Tue, 24 Apr 2012 16:01:29 +0000 (UTC)
commit 76a41d069b2c260f2b0cf9bc6bfe0f60ae574010
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Apr 23 21:16:22 2012 -0400
application: implement app menu actions
https://bugzilla.gnome.org/show_bug.cgi?id=674532
src/nautilus-application.c | 210 +++++++++++++++++++++++++++++-------------
src/nautilus-application.h | 2 -
src/nautilus-window-menus.c | 101 +--------------------
src/nautilus-window.c | 101 +++++++++++++++++++++
src/nautilus-window.h | 1 +
5 files changed, 251 insertions(+), 164 deletions(-)
---
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index 429e52a..32770d0 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -34,8 +34,10 @@
#include "nautilus-empty-view.h"
#endif /* ENABLE_EMPTY_VIEW */
+#include "nautilus-connect-server-dialog.h"
#include "nautilus-desktop-icon-view.h"
#include "nautilus-desktop-window.h"
+#include "nautilus-file-management-properties.h"
#include "nautilus-freedesktop-dbus.h"
#include "nautilus-icon-view.h"
#include "nautilus-image-properties-page.h"
@@ -746,23 +748,156 @@ nautilus_application_constructor (GType type,
return retval;
}
+static GtkWindow *
+get_focus_window (GtkApplication *application)
+{
+ GList *windows;
+ GtkWindow *window = NULL;
+
+ /* the windows are ordered with the last focused first */
+ windows = gtk_application_get_windows (application);
+
+ if (windows != NULL) {
+ window = g_list_nth_data (windows, 0);
+ }
+
+ return window;
+}
+
static void
-nautilus_application_init (NautilusApplication *application)
+action_new_window (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
- GSimpleAction *action;
+ GtkApplication *application = user_data;
+ NautilusWindow *window;
+ GtkWindow *cur_window;
- application->priv =
- G_TYPE_INSTANCE_GET_PRIVATE (application, NAUTILUS_TYPE_APPLICATION,
- NautilusApplicationPriv);
+ cur_window = get_focus_window (application);
+ window = nautilus_application_create_window (NAUTILUS_APPLICATION (application),
+ cur_window ?
+ gtk_window_get_screen (cur_window) :
+ gdk_screen_get_default ());
- action = g_simple_action_new ("quit", NULL);
+ nautilus_window_slot_go_home (nautilus_window_get_active_slot (window), 0);
+}
- g_action_map_add_action (G_ACTION_MAP (application), G_ACTION (action));
+static void
+action_connect_to_server (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtkApplication *application = user_data;
+ GtkWidget *dialog;
- g_signal_connect_swapped (action, "activate",
- G_CALLBACK (nautilus_application_quit), application);
+ dialog = nautilus_connect_server_dialog_new (NAUTILUS_WINDOW (get_focus_window (application)));
+ gtk_widget_show (dialog);
+}
- g_object_unref (action);
+static void
+action_preferences (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtkApplication *application = user_data;
+ nautilus_file_management_properties_dialog_show (get_focus_window (application));
+}
+
+static void
+action_about (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtkApplication *application = user_data;
+
+ nautilus_window_show_about_dialog (NAUTILUS_WINDOW (get_focus_window (application)));
+}
+
+static void
+action_help (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtkWindow *window;
+ GtkWidget *dialog;
+ GtkApplication *application = user_data;
+ GError *error = NULL;
+
+ window = get_focus_window (application);
+ gtk_show_uri (window ?
+ gtk_window_get_screen (GTK_WINDOW (window)) :
+ gdk_screen_get_default (),
+ "help:gnome-help/files",
+ gtk_get_current_event_time (), &error);
+
+ if (error) {
+ dialog = gtk_message_dialog_new (window ? GTK_WINDOW (window) : NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("There was an error displaying help: \n%s"),
+ error->message);
+ g_signal_connect (G_OBJECT (dialog), "response",
+ G_CALLBACK (gtk_widget_destroy),
+ NULL);
+
+ gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+ gtk_widget_show (dialog);
+ g_error_free (error);
+ }
+}
+
+static void
+action_quit (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtkApplication *application = user_data;
+ GList *windows;
+
+ windows = gtk_application_get_windows (application);
+ g_list_foreach (windows, (GFunc) gtk_widget_destroy, NULL);
+}
+
+static GActionEntry app_entries[] = {
+ { "new-window", action_new_window, NULL, NULL, NULL },
+ { "connect-to-server", action_connect_to_server, NULL, NULL, NULL },
+ { "preferences", action_preferences, NULL, NULL, NULL },
+ { "about", action_about, NULL, NULL, NULL },
+ { "help", action_help, NULL, NULL, NULL },
+ { "quit", action_quit, NULL, NULL, NULL },
+};
+
+static void
+nautilus_application_init_app_menu (NautilusApplication *self)
+{
+ GtkBuilder *builder;
+ GError *error = NULL;
+
+ g_action_map_add_action_entries (G_ACTION_MAP (self),
+ app_entries, G_N_ELEMENTS (app_entries),
+ self);
+
+ builder = gtk_builder_new ();
+ gtk_builder_add_from_resource (builder, "/org/gnome/nautilus/nautilus-app-menu.ui", &error);
+
+ if (error == NULL) {
+ gtk_application_set_app_menu (GTK_APPLICATION (self),
+ G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
+ } else {
+ g_critical ("Unable to add the application menu: %s\n", error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (builder);
+}
+
+static void
+nautilus_application_init (NautilusApplication *application)
+{
+ application->priv =
+ G_TYPE_INSTANCE_GET_PRIVATE (application, NAUTILUS_TYPE_APPLICATION,
+ NautilusApplicationPriv);
}
static void
@@ -839,16 +974,6 @@ do_perform_self_checks (gint *exit_status)
*exit_status = EXIT_SUCCESS;
}
-void
-nautilus_application_quit (NautilusApplication *self)
-{
- GApplication *app = G_APPLICATION (self);
- GList *windows;
-
- windows = gtk_application_get_windows (GTK_APPLICATION (app));
- g_list_foreach (windows, (GFunc) gtk_widget_destroy, NULL);
-}
-
static gboolean
nautilus_application_local_command_line (GApplication *application,
gchar ***arguments,
@@ -1067,51 +1192,6 @@ init_gtk_accels (void)
}
static void
-nautilus_application_init_app_menu (NautilusApplication *self)
-{
- GtkBuilder *builder;
- GError *error = NULL;
- GSimpleAction *action;
-
- action = g_simple_action_new ("new-window", NULL);
- g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
- g_object_unref (action);
-
- action = g_simple_action_new ("connect-to-server", NULL);
- g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
- g_object_unref (action);
-
- action = g_simple_action_new ("preferences", NULL);
- g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
- g_object_unref (action);
-
- action = g_simple_action_new ("about", NULL);
- g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
- g_object_unref (action);
-
- action = g_simple_action_new ("help", NULL);
- g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
- g_object_unref (action);
-
- action = g_simple_action_new ("quit", NULL);
- g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
- g_object_unref (action);
-
- builder = gtk_builder_new ();
- gtk_builder_add_from_resource (builder, "/org/gnome/nautilus/nautilus-app-menu.ui", &error);
-
- if (error == NULL) {
- gtk_application_set_app_menu (GTK_APPLICATION (self),
- G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
- } else {
- g_critical ("Unable to add the application menu: %s\n", error->message);
- g_error_free (error);
- }
-
- g_object_unref (builder);
-}
-
-static void
nautilus_application_startup (GApplication *app)
{
NautilusApplication *self = NAUTILUS_APPLICATION (app);
diff --git a/src/nautilus-application.h b/src/nautilus-application.h
index d44f7c1..fd1885b 100644
--- a/src/nautilus-application.h
+++ b/src/nautilus-application.h
@@ -69,8 +69,6 @@ GType nautilus_application_get_type (void);
NautilusApplication *nautilus_application_get_singleton (void);
-void nautilus_application_quit (NautilusApplication *self);
-
NautilusWindow * nautilus_application_create_window (NautilusApplication *application,
GdkScreen *screen);
diff --git a/src/nautilus-window-menus.c b/src/nautilus-window-menus.c
index 265bfbd..1d2de1b 100644
--- a/src/nautilus-window-menus.c
+++ b/src/nautilus-window-menus.c
@@ -303,102 +303,9 @@ static void
action_about_nautilus_callback (GtkAction *action,
gpointer user_data)
{
- const gchar *authors[] = {
- "Alexander Larsson",
- "Ali Abdin",
- "Anders Carlsson",
- "Andrew Walton",
- "Andy Hertzfeld",
- "Arlo Rose",
- "Christian Neumair",
- "Cosimo Cecchi",
- "Darin Adler",
- "David Camp",
- "Eli Goldberg",
- "Elliot Lee",
- "Eskil Heyn Olsen",
- "Ettore Perazzoli",
- "Gene Z. Ragan",
- "George Lebl",
- "Ian McKellar",
- "J Shane Culpepper",
- "James Willcox",
- "Jan Arne Petersen",
- "John Harper",
- "John Sullivan",
- "Josh Barrow",
- "Maciej Stachowiak",
- "Mark McLoughlin",
- "Mathieu Lacage",
- "Mike Engber",
- "Mike Fleming",
- "Pavel Cisler",
- "Ramiro Estrugo",
- "Raph Levien",
- "Rebecca Schulman",
- "Robey Pointer",
- "Robin * Slomkowski",
- "Seth Nickell",
- "Susan Kare",
- "Tomas Bzatek",
- NULL
- };
- const gchar *documenters[] = {
- "GNOME Documentation Team",
- "Sun Microsystems",
- NULL
- };
- const gchar *license[] = {
- N_("Nautilus 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 2 of the License, or "
- "(at your option) any later version."),
- N_("Nautilus is distributed in the hope that 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."),
- N_("You should have received a copy of the GNU General Public License "
- "along with Nautilus; if not, write to the Free Software Foundation, Inc., "
- "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA")
- };
- gchar *license_trans, *copyright_str;
- GDateTime *date;
-
- license_trans = g_strjoin ("\n\n", _(license[0]), _(license[1]),
- _(license[2]), NULL);
-
- date = g_date_time_new_now_local ();
-
- /* Translators: these two strings here indicate the copyright time span,
- * e.g. 1999-2011.
- */
- copyright_str = g_strdup_printf (_("Copyright \xC2\xA9 %Id\xE2\x80\x93%Id "
- "The Nautilus authors"), 1999, g_date_time_get_year (date));
-
- gtk_show_about_dialog (GTK_WINDOW (user_data),
- "program-name", _("Nautilus"),
- "version", VERSION,
- "comments", _("Nautilus lets you organize "
- "files and folders, both on "
- "your computer and online."),
- "copyright", copyright_str,
- "license", license_trans,
- "wrap-license", TRUE,
- "authors", authors,
- "documenters", documenters,
- /* Translators should localize the following string
- * which will be displayed at the bottom of the about
- * box to give credit to the translator(s).
- */
- "translator-credits", _("translator-credits"),
- "logo-icon-name", "nautilus",
- "website", "http://live.gnome.org/Nautilus",
- "website-label", _("Nautilus Web Site"),
- NULL);
-
- g_free (license_trans);
- g_free (copyright_str);
- g_date_time_unref (date);
+ NautilusWindow *window = user_data;
+
+ nautilus_window_show_about_dialog (window);
}
static void
@@ -797,7 +704,7 @@ action_new_window_callback (GtkAction *action,
new_window = nautilus_application_create_window (
application,
gtk_window_get_screen (GTK_WINDOW (current_window)));
- nautilus_window_slot_go_home (nautilus_window_get_active_slot (new_window), FALSE);
+ nautilus_window_slot_go_home (nautilus_window_get_active_slot (new_window), 0);
}
static void
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 33e0ecb..c1b71ab 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -2099,3 +2099,104 @@ nautilus_event_get_window_open_flags (void)
return flags;
}
+
+void
+nautilus_window_show_about_dialog (NautilusWindow *window)
+{
+ const gchar *authors[] = {
+ "Alexander Larsson",
+ "Ali Abdin",
+ "Anders Carlsson",
+ "Andrew Walton",
+ "Andy Hertzfeld",
+ "Arlo Rose",
+ "Christian Neumair",
+ "Cosimo Cecchi",
+ "Darin Adler",
+ "David Camp",
+ "Eli Goldberg",
+ "Elliot Lee",
+ "Eskil Heyn Olsen",
+ "Ettore Perazzoli",
+ "Gene Z. Ragan",
+ "George Lebl",
+ "Ian McKellar",
+ "J Shane Culpepper",
+ "James Willcox",
+ "Jan Arne Petersen",
+ "John Harper",
+ "John Sullivan",
+ "Josh Barrow",
+ "Maciej Stachowiak",
+ "Mark McLoughlin",
+ "Mathieu Lacage",
+ "Mike Engber",
+ "Mike Fleming",
+ "Pavel Cisler",
+ "Ramiro Estrugo",
+ "Raph Levien",
+ "Rebecca Schulman",
+ "Robey Pointer",
+ "Robin * Slomkowski",
+ "Seth Nickell",
+ "Susan Kare",
+ "Tomas Bzatek",
+ NULL
+ };
+ const gchar *documenters[] = {
+ "GNOME Documentation Team",
+ "Sun Microsystems",
+ NULL
+ };
+ const gchar *license[] = {
+ N_("Nautilus 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 2 of the License, or "
+ "(at your option) any later version."),
+ N_("Nautilus is distributed in the hope that 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."),
+ N_("You should have received a copy of the GNU General Public License "
+ "along with Nautilus; if not, write to the Free Software Foundation, Inc., "
+ "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA")
+ };
+ gchar *license_trans, *copyright_str;
+ GDateTime *date;
+
+ license_trans = g_strjoin ("\n\n", _(license[0]), _(license[1]),
+ _(license[2]), NULL);
+
+ date = g_date_time_new_now_local ();
+
+ /* Translators: these two strings here indicate the copyright time span,
+ * e.g. 1999-2011.
+ */
+ copyright_str = g_strdup_printf (_("Copyright \xC2\xA9 %Id\xE2\x80\x93%Id "
+ "The Nautilus authors"), 1999, g_date_time_get_year (date));
+
+ gtk_show_about_dialog (window ? GTK_WINDOW (window) : NULL,
+ "program-name", _("Nautilus"),
+ "version", VERSION,
+ "comments", _("Nautilus lets you organize "
+ "files and folders, both on "
+ "your computer and online."),
+ "copyright", copyright_str,
+ "license", license_trans,
+ "wrap-license", TRUE,
+ "authors", authors,
+ "documenters", documenters,
+ /* Translators should localize the following string
+ * which will be displayed at the bottom of the about
+ * box to give credit to the translator(s).
+ */
+ "translator-credits", _("translator-credits"),
+ "logo-icon-name", "nautilus",
+ "website", "http://live.gnome.org/Nautilus",
+ "website-label", _("Nautilus Web Site"),
+ NULL);
+
+ g_free (license_trans);
+ g_free (copyright_str);
+ g_date_time_unref (date);
+}
diff --git a/src/nautilus-window.h b/src/nautilus-window.h
index ce6023b..a65fdf0 100644
--- a/src/nautilus-window.h
+++ b/src/nautilus-window.h
@@ -150,5 +150,6 @@ gboolean nautilus_window_disable_chrome_mapping (GValue *value,
gpointer user_data);
NautilusWindowOpenFlags nautilus_event_get_window_open_flags (void);
+void nautilus_window_show_about_dialog (NautilusWindow *window);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]