From 3036a6ed5cb388b399e4e73c26abbb5b2fdcdd1c Mon Sep 17 00:00:00 2001 From: Christian Neumair Date: Tue, 13 May 2008 11:05:17 +0000 Subject: Add "Tabs" menu, for now it just contains actions for moving/switching 2008-05-13 Christian Neumair * libnautilus-private/nautilus-icon-container.c (keyboard_space): * src/file-manager/fm-icon-view.c (icon_container_activate_alternate_callback): * src/nautilus-navigation-window-menus.c (update_tab_action_sensitivity), (update_tab_menu), (nautilus_navigation_window_initialize_tabs_menu), (action_tabs_previous_callback), (action_tabs_next_callback), (action_tabs_move_left_callback), (action_tabs_move_right_callback), (nautilus_navigation_window_initialize_menus): * src/nautilus-navigation-window-ui.xml: * src/nautilus-notebook.c (nautilus_notebook_reorder_current_child_relative), (nautilus_notebook_set_current_page_relative), (nautilus_notebook_is_valid_relative_position), (nautilus_notebook_can_reorder_current_child_relative), (nautilus_notebook_can_set_current_page_relative): * src/nautilus-notebook.h: * src/nautilus-window-manage-views.c (nautilus_window_slot_open_location_full): Add "Tabs" menu, for now it just contains actions for moving/switching tabs. Refine view keybindings for opening in new window/tab. svn path=/branches/multiview/; revision=14158 --- ChangeLog | 25 ++++++ libnautilus-private/nautilus-icon-container.c | 3 +- src/file-manager/fm-icon-view.c | 39 ++++++++- src/nautilus-navigation-window-menus.c | 112 +++++++++++++++++++++++++- src/nautilus-navigation-window-ui.xml | 12 +++ src/nautilus-notebook.c | 81 +++++++++++++++++++ src/nautilus-notebook.h | 10 +++ src/nautilus-window-manage-views.c | 5 +- 8 files changed, 282 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4daaee6d6..0eb5145dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2008-05-13 Christian Neumair + + * libnautilus-private/nautilus-icon-container.c (keyboard_space): + * src/file-manager/fm-icon-view.c + (icon_container_activate_alternate_callback): + * src/nautilus-navigation-window-menus.c + (update_tab_action_sensitivity), (update_tab_menu), + (nautilus_navigation_window_initialize_tabs_menu), + (action_tabs_previous_callback), (action_tabs_next_callback), + (action_tabs_move_left_callback), + (action_tabs_move_right_callback), + (nautilus_navigation_window_initialize_menus): + * src/nautilus-navigation-window-ui.xml: + * src/nautilus-notebook.c + (nautilus_notebook_reorder_current_child_relative), + (nautilus_notebook_set_current_page_relative), + (nautilus_notebook_is_valid_relative_position), + (nautilus_notebook_can_reorder_current_child_relative), + (nautilus_notebook_can_set_current_page_relative): + * src/nautilus-notebook.h: + * src/nautilus-window-manage-views.c + (nautilus_window_slot_open_location_full): + Add "Tabs" menu, for now it just contains actions for moving/switching + tabs. Refine view keybindings for opening in new window/tab. + 2008-05-07 Christian Neumair * libnautilus-private/nautilus-mime-actions.c (activate_files): diff --git a/libnautilus-private/nautilus-icon-container.c b/libnautilus-private/nautilus-icon-container.c index 9c6821706..84a1dca58 100644 --- a/libnautilus-private/nautilus-icon-container.c +++ b/libnautilus-private/nautilus-icon-container.c @@ -2973,7 +2973,8 @@ keyboard_space (NautilusIconContainer *container, NautilusIcon *icon; /* Control-space toggles the selection state of the current icon. */ - if ((event->state & GDK_CONTROL_MASK) != 0) { + if ((event->state & GDK_CONTROL_MASK) != 0 && + (event->state & GDK_SHIFT_MASK) == 0) { if (container->details->keyboard_focus != NULL) { icon_toggle_selected (container, container->details->keyboard_focus); g_signal_emit (container, signals[SELECTION_CHANGED], 0); diff --git a/src/file-manager/fm-icon-view.c b/src/file-manager/fm-icon-view.c index ae24d7016..0cb8b3cce 100644 --- a/src/file-manager/fm-icon-view.c +++ b/src/file-manager/fm-icon-view.c @@ -1722,14 +1722,49 @@ icon_container_activate_alternate_callback (NautilusIconContainer *container, GList *file_list, FMIconView *icon_view) { + GdkEvent *event; + GdkEventButton *button_event; + GdkEventKey *key_event; + gboolean open_in_tab; + NautilusWindowInfo *window_info; + NautilusWindowOpenFlags flags; + g_assert (FM_IS_ICON_VIEW (icon_view)); g_assert (container == get_icon_container (icon_view)); + open_in_tab = FALSE; + + window_info = fm_directory_view_get_nautilus_window (FM_DIRECTORY_VIEW (icon_view)); + + if (nautilus_window_info_get_window_type (window_info) == NAUTILUS_WINDOW_NAVIGATION) { + event = gtk_get_current_event (); + if (event->type == GDK_BUTTON_PRESS || + event->type == GDK_BUTTON_RELEASE || + event->type == GDK_2BUTTON_PRESS || + event->type == GDK_3BUTTON_PRESS) { + button_event = (GdkEventButton *) event; + open_in_tab = (button_event->state & GDK_SHIFT_MASK) == 0; + } else if (event->type == GDK_KEY_PRESS || + event->type == GDK_KEY_RELEASE) { + key_event = (GdkEventKey *) event; + open_in_tab = !((key_event->state & GDK_SHIFT_MASK) != 0 && + (key_event->state & GDK_CONTROL_MASK) != 0); + } else { + open_in_tab = TRUE; + } + } + + flags = NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND; + if (open_in_tab) { + flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB; + } else { + flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW; + } + fm_directory_view_activate_files (FM_DIRECTORY_VIEW (icon_view), file_list, NAUTILUS_WINDOW_OPEN_ACCORDING_TO_MODE, - NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND | - NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW); + flags); } static void diff --git a/src/nautilus-navigation-window-menus.c b/src/nautilus-navigation-window-menus.c index 886431683..0fc0af49c 100644 --- a/src/nautilus-navigation-window-menus.c +++ b/src/nautilus-navigation-window-menus.c @@ -30,6 +30,7 @@ #include #include "nautilus-actions.h" +#include "nautilus-notebook.h" #include "nautilus-navigation-action.h" #include "nautilus-application.h" #include "nautilus-bookmark-list.h" @@ -412,6 +413,60 @@ nautilus_navigation_window_initialize_go_menu (NautilusNavigationWindow *window) G_CALLBACK (schedule_refresh_go_menu), window, G_CONNECT_SWAPPED); } +static void +update_tab_action_sensitivity (NautilusNavigationWindow *window) +{ + GtkActionGroup *action_group; + GtkAction *action; + NautilusNotebook *notebook; + gboolean sensitive; + + g_assert (NAUTILUS_IS_NAVIGATION_WINDOW (window)); + + notebook = NAUTILUS_NOTEBOOK (window->notebook); + action_group = window->details->navigation_action_group; + + action = gtk_action_group_get_action (action_group, "TabsPrevious"); + sensitive = nautilus_notebook_can_set_current_page_relative (notebook, -1); + g_object_set (action, "sensitive", sensitive, NULL); + + action = gtk_action_group_get_action (action_group, "TabsNext"); + sensitive = nautilus_notebook_can_set_current_page_relative (notebook, 1); + g_object_set (action, "sensitive", sensitive, NULL); + + action = gtk_action_group_get_action (action_group, "TabsMoveLeft"); + sensitive = nautilus_notebook_can_reorder_current_child_relative (notebook, -1); + g_object_set (action, "sensitive", sensitive, NULL); + + action = gtk_action_group_get_action (action_group, "TabsMoveRight"); + sensitive = nautilus_notebook_can_reorder_current_child_relative (notebook, 1); + g_object_set (action, "sensitive", sensitive, NULL); +} + +static void +update_tab_menu (NautilusNavigationWindow *window) +{ + g_assert (NAUTILUS_IS_NAVIGATION_WINDOW (window)); + + update_tab_action_sensitivity (window); +} + +static void +nautilus_navigation_window_initialize_tabs_menu (NautilusNavigationWindow *window) +{ + g_signal_connect_object (window->notebook, "page-added", + G_CALLBACK (refresh_tab_actions), window, G_CONNECT_SWAPPED); + g_signal_connect_object (window->notebook, "page-removed", + G_CALLBACK (refresh_tab_actions), window, G_CONNECT_SWAPPED); + g_signal_connect_object (window->notebook, "page-reordered", + G_CALLBACK (refresh_tab_actions), window, G_CONNECT_SWAPPED); + g_signal_connect_object (window->notebook, "switch-page", + G_CALLBACK (refresh_tab_action_sensitivity), window, + G_CONNECT_SWAPPED | G_CONNECT_AFTER); + + refresh_tab_actions (window); +} + static void action_new_window_callback (GtkAction *action, gpointer user_data) @@ -494,9 +549,50 @@ action_search_callback (GtkAction *action, nautilus_navigation_window_show_search (window); } +static void +action_tabs_previous_callback (GtkAction *action, + gpointer user_data) +{ + NautilusNavigationWindow *window; + + window = NAUTILUS_NAVIGATION_WINDOW (user_data); + nautilus_notebook_set_current_page_relative (NAUTILUS_NOTEBOOK (window->notebook), -1); +} + +static void +action_tabs_next_callback (GtkAction *action, + gpointer user_data) +{ + NautilusNavigationWindow *window; + + window = NAUTILUS_NAVIGATION_WINDOW (user_data); + nautilus_notebook_set_current_page_relative (NAUTILUS_NOTEBOOK (window->notebook), 1); +} + +static void +action_tabs_move_left_callback (GtkAction *action, + gpointer user_data) +{ + NautilusNavigationWindow *window; + + window = NAUTILUS_NAVIGATION_WINDOW (user_data); + nautilus_notebook_reorder_current_child_relative (NAUTILUS_NOTEBOOK (window->notebook), -1); +} + +static void +action_tabs_move_right_callback (GtkAction *action, + gpointer user_data) +{ + NautilusNavigationWindow *window; + + window = NAUTILUS_NAVIGATION_WINDOW (user_data); + nautilus_notebook_reorder_current_child_relative (NAUTILUS_NOTEBOOK (window->notebook), 1); +} + static const GtkActionEntry navigation_entries[] = { /* name, stock id, label */ { "Go", NULL, N_("_Go") }, /* name, stock id, label */ { "Bookmarks", NULL, N_("_Bookmarks") }, + /* name, stock id, label */ { "Tabs", NULL, N_("_Tabs") }, /* name, stock id, label */ { "New Window", "window-new", N_("New _Window"), "N", N_("Open another Nautilus window for the displayed location"), G_CALLBACK (action_new_window_callback) }, @@ -524,7 +620,20 @@ static const GtkActionEntry navigation_entries[] = { /* name, stock id, label */ { "Search", "gtk-find", N_("_Search for Files..."), "F", N_("Locate documents and folders on this computer by name or content"), G_CALLBACK (action_search_callback) }, - + + { "TabsPrevious", NULL, N_("_Previous Tab"), "Page_Up", + N_("Activate previous tab"), + G_CALLBACK (action_tabs_previous_callback) }, + { "TabsNext", NULL, N_("_Next Tab"), "Page_Down", + N_("Activate next tab"), + G_CALLBACK (action_tabs_next_callback) }, + { "TabsMoveLeft", NULL, N_("Move Tab _Left"), "Page_Up", + N_("Move current tab to left"), + G_CALLBACK (action_tabs_move_left_callback) }, + { "TabsMoveRight", NULL, N_("Move Tab _Right"), "Page_Down", + N_("Move current tab to right"), + G_CALLBACK (action_tabs_move_right_callback) }, + }; static const GtkToggleActionEntry navigation_toggle_entries[] = { @@ -633,5 +742,6 @@ nautilus_navigation_window_initialize_menus (NautilusNavigationWindow *window) nautilus_navigation_window_update_spatial_menu_item (window); nautilus_navigation_window_initialize_go_menu (window); + nautilus_navigation_window_initialize_tabs_menu (window); } diff --git a/src/nautilus-navigation-window-ui.xml b/src/nautilus-navigation-window-ui.xml index 3efa6afbe..5e504c9d9 100644 --- a/src/nautilus-navigation-window-ui.xml +++ b/src/nautilus-navigation-window-ui.xml @@ -47,6 +47,18 @@ + + + + + + + + + + + + diff --git a/src/nautilus-notebook.c b/src/nautilus-notebook.c index 3bd34b559..227b6e277 100644 --- a/src/nautilus-notebook.c +++ b/src/nautilus-notebook.c @@ -650,3 +650,84 @@ nautilus_notebook_remove (GtkContainer *container, gtk_notebook_get_n_pages (gnotebook) > 1); } + +void +nautilus_notebook_reorder_current_child_relative (NautilusNotebook *notebook, + int offset) +{ + GtkNotebook *gnotebook; + GtkWidget *child; + int page; + + g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook)); + + if (!nautilus_notebook_can_reorder_current_child_relative (notebook, offset)) { + return; + } + + gnotebook = GTK_NOTEBOOK (notebook); + + page = gtk_notebook_get_current_page (gnotebook); + child = gtk_notebook_get_nth_page (gnotebook, page); + gtk_notebook_reorder_child (gnotebook, child, page + offset); +} + +void +nautilus_notebook_set_current_page_relative (NautilusNotebook *notebook, + int offset) +{ + GtkNotebook *gnotebook; + int page; + + g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook)); + + if (!nautilus_notebook_can_set_current_page_relative (notebook, offset)) { + return; + } + + gnotebook = GTK_NOTEBOOK (notebook); + + page = gtk_notebook_get_current_page (gnotebook); + gtk_notebook_set_current_page (gnotebook, page + offset); + +} + +static gboolean +nautilus_notebook_is_valid_relative_position (NautilusNotebook *notebook, + int offset) +{ + GtkNotebook *gnotebook; + int page; + int n_pages; + + gnotebook = GTK_NOTEBOOK (notebook); + + page = gtk_notebook_get_current_page (gnotebook); + n_pages = gtk_notebook_get_n_pages (gnotebook) - 1; + if (page < 0 || + (offset < 0 && page < -offset) || + (offset > 0 && page > n_pages - offset)) { + return FALSE; + } + + return TRUE; +} + +gboolean +nautilus_notebook_can_reorder_current_child_relative (NautilusNotebook *notebook, + int offset) +{ + g_return_val_if_fail (NAUTILUS_IS_NOTEBOOK (notebook), FALSE); + + return nautilus_notebook_is_valid_relative_position (notebook, offset); +} + +gboolean +nautilus_notebook_can_set_current_page_relative (NautilusNotebook *notebook, + int offset) +{ + g_return_val_if_fail (NAUTILUS_IS_NOTEBOOK (notebook), FALSE); + + return nautilus_notebook_is_valid_relative_position (notebook, offset); +} + diff --git a/src/nautilus-notebook.h b/src/nautilus-notebook.h index 36af91736..a69fd179d 100644 --- a/src/nautilus-notebook.h +++ b/src/nautilus-notebook.h @@ -78,6 +78,16 @@ void nautilus_notebook_sync_tab_label (NautilusNotebook *nb, void nautilus_notebook_sync_loading (NautilusNotebook *nb, NautilusWindowSlot *slot); +void nautilus_notebook_reorder_current_child_relative (NautilusNotebook *notebook, + int offset); +void nautilus_notebook_set_current_page_relative (NautilusNotebook *notebook, + int offset); + +gboolean nautilus_notebook_can_reorder_current_child_relative (NautilusNotebook *notebook, + int offset); +gboolean nautilus_notebook_can_set_current_page_relative (NautilusNotebook *notebook, + int offset); + G_END_DECLS #endif /* NAUTILUS_NOTEBOOK_H */ diff --git a/src/nautilus-window-manage-views.c b/src/nautilus-window-manage-views.c index 79d607833..cbfdde669 100644 --- a/src/nautilus-window-manage-views.c +++ b/src/nautilus-window-manage-views.c @@ -497,7 +497,7 @@ nautilus_window_slot_open_location_full (NautilusWindowSlot *slot, char *old_uri, *new_uri; window = slot->window; - + target_window = NULL; target_slot = NULL; @@ -514,6 +514,9 @@ nautilus_window_slot_open_location_full (NautilusWindowSlot *slot, g_free (old_uri); g_free (new_uri); + g_assert (!((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) != 0 && + (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0)); + old_location = nautilus_window_slot_get_location (slot); switch (mode) { -- cgit v1.2.1