[nautilus] window-menus: move bookmark-related menu code where it belongs
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] window-menus: move bookmark-related menu code where it belongs
- Date: Thu, 17 Feb 2011 16:31:24 +0000 (UTC)
commit 8974c917ecb202a0dad4871c79dc8d7306e28feb
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue Feb 15 22:46:13 2011 -0500
window-menus: move bookmark-related menu code where it belongs
src/nautilus-window-bookmarks.c | 138 ++++++++++++++++++++++++++++++++++
src/nautilus-window-menus.c | 158 ---------------------------------------
2 files changed, 138 insertions(+), 158 deletions(-)
---
diff --git a/src/nautilus-window-bookmarks.c b/src/nautilus-window-bookmarks.c
index 4bae1b3..81e0187 100644
--- a/src/nautilus-window-bookmarks.c
+++ b/src/nautilus-window-bookmarks.c
@@ -34,6 +34,7 @@
#include "nautilus-window-bookmarks.h"
#include "nautilus-window-private.h"
#include <libnautilus-private/nautilus-undo-manager.h>
+#include <libnautilus-private/nautilus-ui-utilities.h>
#include <eel/eel-debug.h>
#include <eel/eel-stock-dialogs.h>
#include <eel/eel-vfs-extensions.h>
@@ -202,6 +203,143 @@ connect_proxy_cb (GtkActionGroup *action_group,
gtk_label_set_max_width_chars (label, MENU_ITEM_MAX_WIDTH_CHARS);
}
+/* Struct that stores all the info necessary to activate a bookmark. */
+typedef struct {
+ NautilusBookmark *bookmark;
+ NautilusWindow *window;
+ GCallback refresh_callback;
+ NautilusBookmarkFailedCallback failed_callback;
+} BookmarkHolder;
+
+static BookmarkHolder *
+bookmark_holder_new (NautilusBookmark *bookmark,
+ NautilusWindow *window,
+ GCallback refresh_callback,
+ NautilusBookmarkFailedCallback failed_callback)
+{
+ BookmarkHolder *new_bookmark_holder;
+
+ new_bookmark_holder = g_new (BookmarkHolder, 1);
+ new_bookmark_holder->window = window;
+ new_bookmark_holder->bookmark = bookmark;
+ new_bookmark_holder->failed_callback = failed_callback;
+ new_bookmark_holder->refresh_callback = refresh_callback;
+ /* Ref the bookmark because it might be unreffed away while
+ * we're holding onto it (not an issue for window).
+ */
+ g_object_ref (bookmark);
+ g_signal_connect_object (bookmark, "notify::icon",
+ refresh_callback,
+ window, G_CONNECT_SWAPPED);
+ g_signal_connect_object (bookmark, "notify::name",
+ refresh_callback,
+ window, G_CONNECT_SWAPPED);
+
+ return new_bookmark_holder;
+}
+
+static void
+bookmark_holder_free (BookmarkHolder *bookmark_holder)
+{
+ g_signal_handlers_disconnect_by_func (bookmark_holder->bookmark,
+ bookmark_holder->refresh_callback, bookmark_holder->window);
+ g_object_unref (bookmark_holder->bookmark);
+ g_free (bookmark_holder);
+}
+
+static void
+bookmark_holder_free_cover (gpointer callback_data, GClosure *closure)
+{
+ bookmark_holder_free (callback_data);
+}
+
+static void
+activate_bookmark_in_menu_item (GtkAction *action, gpointer user_data)
+{
+ NautilusWindowSlot *slot;
+ BookmarkHolder *holder;
+ GFile *location;
+
+ holder = (BookmarkHolder *)user_data;
+
+ if (nautilus_bookmark_uri_known_not_to_exist (holder->bookmark)) {
+ holder->failed_callback (holder->window, holder->bookmark);
+ } else {
+ location = nautilus_bookmark_get_location (holder->bookmark);
+ slot = nautilus_window_get_active_slot (holder->window);
+ nautilus_window_slot_go_to (slot,
+ location,
+ nautilus_event_should_open_in_new_tab ());
+ g_object_unref (location);
+ }
+}
+
+void
+nautilus_menus_append_bookmark_to_menu (NautilusWindow *window,
+ NautilusBookmark *bookmark,
+ const char *parent_path,
+ const char *parent_id,
+ guint index_in_parent,
+ GtkActionGroup *action_group,
+ guint merge_id,
+ GCallback refresh_callback,
+ NautilusBookmarkFailedCallback failed_callback)
+{
+ BookmarkHolder *bookmark_holder;
+ char action_name[128];
+ const char *name;
+ char *path;
+ GIcon *icon;
+ GtkAction *action;
+ GtkWidget *menuitem;
+
+ g_assert (NAUTILUS_IS_WINDOW (window));
+ g_assert (NAUTILUS_IS_BOOKMARK (bookmark));
+
+ bookmark_holder = bookmark_holder_new (bookmark, window, refresh_callback, failed_callback);
+ name = nautilus_bookmark_get_name (bookmark);
+
+ /* Create menu item with pixbuf */
+ icon = nautilus_bookmark_get_icon (bookmark);
+
+ g_snprintf (action_name, sizeof (action_name), "%s%d", parent_id, index_in_parent);
+
+ action = gtk_action_new (action_name,
+ name,
+ _("Go to the location specified by this bookmark"),
+ NULL);
+
+ g_object_set_data_full (G_OBJECT (action), "menu-icon",
+ icon,
+ g_object_unref);
+
+ g_signal_connect_data (action, "activate",
+ G_CALLBACK (activate_bookmark_in_menu_item),
+ bookmark_holder,
+ bookmark_holder_free_cover, 0);
+
+ gtk_action_group_add_action (action_group,
+ GTK_ACTION (action));
+
+ g_object_unref (action);
+
+ gtk_ui_manager_add_ui (window->details->ui_manager,
+ merge_id,
+ parent_path,
+ action_name,
+ action_name,
+ GTK_UI_MANAGER_MENUITEM,
+ FALSE);
+
+ path = g_strdup_printf ("%s/%s", parent_path, action_name);
+ menuitem = gtk_ui_manager_get_widget (window->details->ui_manager,
+ path);
+ gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem),
+ TRUE);
+
+ g_free (path);
+}
+
static void
update_bookmarks (NautilusWindow *window)
{
diff --git a/src/nautilus-window-menus.c b/src/nautilus-window-menus.c
index 967c566..4633d59 100644
--- a/src/nautilus-window-menus.c
+++ b/src/nautilus-window-menus.c
@@ -63,164 +63,6 @@
#define COMPUTER_URI "computer:"
#define BURN_CD_URI "burn:"
-/* Struct that stores all the info necessary to activate a bookmark. */
-typedef struct {
- NautilusBookmark *bookmark;
- NautilusWindow *window;
- GCallback refresh_callback;
- NautilusBookmarkFailedCallback failed_callback;
-} BookmarkHolder;
-
-static BookmarkHolder *
-bookmark_holder_new (NautilusBookmark *bookmark,
- NautilusWindow *window,
- GCallback refresh_callback,
- NautilusBookmarkFailedCallback failed_callback)
-{
- BookmarkHolder *new_bookmark_holder;
-
- new_bookmark_holder = g_new (BookmarkHolder, 1);
- new_bookmark_holder->window = window;
- new_bookmark_holder->bookmark = bookmark;
- new_bookmark_holder->failed_callback = failed_callback;
- new_bookmark_holder->refresh_callback = refresh_callback;
- /* Ref the bookmark because it might be unreffed away while
- * we're holding onto it (not an issue for window).
- */
- g_object_ref (bookmark);
- g_signal_connect_object (bookmark, "notify::icon",
- refresh_callback,
- window, G_CONNECT_SWAPPED);
- g_signal_connect_object (bookmark, "notify::name",
- refresh_callback,
- window, G_CONNECT_SWAPPED);
-
- return new_bookmark_holder;
-}
-
-static void
-bookmark_holder_free (BookmarkHolder *bookmark_holder)
-{
- g_signal_handlers_disconnect_by_func (bookmark_holder->bookmark,
- bookmark_holder->refresh_callback, bookmark_holder->window);
- g_object_unref (bookmark_holder->bookmark);
- g_free (bookmark_holder);
-}
-
-static void
-bookmark_holder_free_cover (gpointer callback_data, GClosure *closure)
-{
- bookmark_holder_free (callback_data);
-}
-
-static gboolean
-should_open_in_new_tab (void)
-{
- /* FIXME this is duplicated */
- GdkEvent *event;
-
- event = gtk_get_current_event ();
-
- if (event == NULL) {
- return FALSE;
- }
-
- if (event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) {
- return event->button.button == 2;
- }
-
- gdk_event_free (event);
-
- return FALSE;
-}
-
-static void
-activate_bookmark_in_menu_item (GtkAction *action, gpointer user_data)
-{
- NautilusWindowSlot *slot;
- BookmarkHolder *holder;
- GFile *location;
-
- holder = (BookmarkHolder *)user_data;
-
- if (nautilus_bookmark_uri_known_not_to_exist (holder->bookmark)) {
- holder->failed_callback (holder->window, holder->bookmark);
- } else {
- location = nautilus_bookmark_get_location (holder->bookmark);
- slot = nautilus_window_get_active_slot (holder->window);
- nautilus_window_slot_go_to (slot,
- location,
- should_open_in_new_tab ());
- g_object_unref (location);
- }
-}
-
-void
-nautilus_menus_append_bookmark_to_menu (NautilusWindow *window,
- NautilusBookmark *bookmark,
- const char *parent_path,
- const char *parent_id,
- guint index_in_parent,
- GtkActionGroup *action_group,
- guint merge_id,
- GCallback refresh_callback,
- NautilusBookmarkFailedCallback failed_callback)
-{
- BookmarkHolder *bookmark_holder;
- char action_name[128];
- const char *name;
- char *path;
- GIcon *icon;
- GtkAction *action;
- GtkWidget *menuitem;
-
- g_assert (NAUTILUS_IS_WINDOW (window));
- g_assert (NAUTILUS_IS_BOOKMARK (bookmark));
-
- bookmark_holder = bookmark_holder_new (bookmark, window, refresh_callback, failed_callback);
- name = nautilus_bookmark_get_name (bookmark);
-
- /* Create menu item with pixbuf */
- icon = nautilus_bookmark_get_icon (bookmark);
-
- g_snprintf (action_name, sizeof (action_name), "%s%d", parent_id, index_in_parent);
-
- action = gtk_action_new (action_name,
- name,
- _("Go to the location specified by this bookmark"),
- NULL);
-
- g_object_set_data_full (G_OBJECT (action), "menu-icon",
- icon,
- g_object_unref);
-
- g_signal_connect_data (action, "activate",
- G_CALLBACK (activate_bookmark_in_menu_item),
- bookmark_holder,
- bookmark_holder_free_cover, 0);
-
- gtk_action_group_add_action (action_group,
- GTK_ACTION (action));
-
- g_object_unref (action);
-
- gtk_ui_manager_add_ui (window->details->ui_manager,
- merge_id,
- parent_path,
- action_name,
- action_name,
- GTK_UI_MANAGER_MENUITEM,
- FALSE);
-
- path = g_strdup_printf ("%s/%s", parent_path, action_name);
- menuitem = gtk_ui_manager_get_widget (window->details->ui_manager,
- path);
- gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem),
- TRUE);
-
- g_free (path);
-}
-
static void
action_close_window_slot_callback (GtkAction *action,
gpointer user_data)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]