diff options
author | Christian Neumair <cneumair@gnome.org> | 2008-03-21 15:51:19 +0000 |
---|---|---|
committer | Christian Neumair <cneumair@src.gnome.org> | 2008-03-21 15:51:19 +0000 |
commit | 2ab3f34ccaccb80d2bfa92c79d585c2605823123 (patch) | |
tree | 830f12a324be758a1a2dd6785bad3d7a4b526e9e | |
parent | ac6a2f48460f4ef46745aa88f07d95ceb076dcae (diff) | |
download | nautilus-2ab3f34ccaccb80d2bfa92c79d585c2605823123.tar.gz |
Add NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB to NautilusWindowOpenFlags.
2007-03-21 Christian Neumair <cneumair@gnome.org>
* libnautilus-private/nautilus-window-info.h:
Add NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB to NautilusWindowOpenFlags.
* src/nautilus-window-slot.[ch]:
* src/nautilus-navigation-window-slot.[ch]:
* src/*.[ch]:
Add code for handling back/forward lists, add get_close_successor()
API for determining which slot will follow the current one before
close.
Add nautilus_window_slot_go_to(_location) defines and use them in the
window "go to" code.
Properly destroy slots and views when closing slot.
Add "New Tab" menu item.
Beginnings of notebook tab handling.
Some more minor fixes and comments.
svn path=/branches/multiview/; revision=13963
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | libnautilus-private/nautilus-window-info.h | 3 | ||||
-rw-r--r-- | src/file-manager/fm-directory-view.c | 16 | ||||
-rw-r--r-- | src/nautilus-navigation-window-menus.c | 26 | ||||
-rw-r--r-- | src/nautilus-navigation-window-slot.c | 85 | ||||
-rw-r--r-- | src/nautilus-navigation-window-slot.h | 4 | ||||
-rw-r--r-- | src/nautilus-navigation-window-ui.xml | 1 | ||||
-rw-r--r-- | src/nautilus-navigation-window.c | 111 | ||||
-rw-r--r-- | src/nautilus-window-manage-views.c | 29 | ||||
-rw-r--r-- | src/nautilus-window-menus.c | 12 | ||||
-rw-r--r-- | src/nautilus-window-private.h | 2 | ||||
-rw-r--r-- | src/nautilus-window-slot.c | 42 | ||||
-rw-r--r-- | src/nautilus-window-slot.h | 16 | ||||
-rw-r--r-- | src/nautilus-window.c | 130 |
14 files changed, 398 insertions, 97 deletions
@@ -1,3 +1,21 @@ +2007-03-21 Christian Neumair <cneumair@gnome.org> + + * libnautilus-private/nautilus-window-info.h: + Add NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB to NautilusWindowOpenFlags. + + * src/nautilus-window-slot.[ch]: + * src/nautilus-navigation-window-slot.[ch]: + * src/*.[ch]: + Add code for handling back/forward lists, add get_close_successor() + API for determining which slot will follow the current one before + close. + Add nautilus_window_slot_go_to(_location) defines and use them in the + window "go to" code. + Properly destroy slots and views when closing slot. + Add "New Tab" menu item. + Beginnings of notebook tab handling. + Some more minor fixes and comments. + 2008-03-21 Christian Neumair <cneumair@gnome.org> * src/nautilus-places-sidebar.c: (update_places): diff --git a/libnautilus-private/nautilus-window-info.h b/libnautilus-private/nautilus-window-info.h index debc25d70..0c9fa771b 100644 --- a/libnautilus-private/nautilus-window-info.h +++ b/libnautilus-private/nautilus-window-info.h @@ -50,7 +50,8 @@ typedef enum { /* used in spatial mode */ NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND = 1<<0, /* used in navigation mode */ - NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW = 1<<1 + NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW = 1<<1, + NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB = 1<<2 } NautilusWindowOpenFlags; typedef enum { diff --git a/src/file-manager/fm-directory-view.c b/src/file-manager/fm-directory-view.c index 120d9532c..f9e5df8f6 100644 --- a/src/file-manager/fm-directory-view.c +++ b/src/file-manager/fm-directory-view.c @@ -1659,6 +1659,7 @@ slot_active (NautilusWindowSlot *slot, schedule_update_menus (view); /* initialise show hidden mode */ + /* multiview-TODO this always causes a reload for loaded views. */ fm_directory_view_init_show_hidden_files (view); } @@ -1902,6 +1903,7 @@ fm_directory_view_destroy (GtkObject *object) fm_directory_view_unmerge_menus (view); /* We don't own the window, so no unref */ + view->details->slot = NULL; view->details->window = NULL; fm_directory_view_stop (view); @@ -3684,8 +3686,11 @@ delayed_rename_file_hack_callback (RenameData *data) view = data->view; new_file = data->new_file; - EEL_CALL_METHOD (FM_DIRECTORY_VIEW_CLASS, view, start_renaming_file, (view, new_file, FALSE)); - fm_directory_view_reveal_selection (view); + if (view->details->window != NULL && + view->details->active) { + EEL_CALL_METHOD (FM_DIRECTORY_VIEW_CLASS, view, start_renaming_file, (view, new_file, FALSE)); + fm_directory_view_reveal_selection (view); + } g_object_unref (data->view); nautilus_file_unref (data->new_file); @@ -6628,8 +6633,9 @@ clipboard_targets_received (GtkClipboard *clipboard, view = FM_DIRECTORY_VIEW (user_data); can_paste = FALSE; - if (view->details->window == NULL) { - /* We've been destroyed since call */ + if (view->details->window == NULL || + !view->details->active) { + /* We've been destroyed or became inactive since call */ g_object_unref (view); return; } @@ -7726,6 +7732,7 @@ metadata_for_directory_as_file_ready_callback (NautilusFile *file, g_assert (view->details->directory_as_file == file); g_assert (view->details->metadata_for_directory_as_file_pending); + g_assert (view->details->metadata_for_directory_as_file_pending); view->details->metadata_for_directory_as_file_pending = FALSE; finish_loading_if_all_metadata_loaded (view); @@ -7744,6 +7751,7 @@ metadata_for_files_in_directory_ready_callback (NautilusDirectory *directory, g_assert (view->details->model == directory); g_assert (view->details->metadata_for_files_in_directory_pending); + g_assert (view->details->metadata_for_files_in_directory_pending); view->details->metadata_for_files_in_directory_pending = FALSE; finish_loading_if_all_metadata_loaded (view); diff --git a/src/nautilus-navigation-window-menus.c b/src/nautilus-navigation-window-menus.c index 174c23021..4b8907423 100644 --- a/src/nautilus-navigation-window-menus.c +++ b/src/nautilus-navigation-window-menus.c @@ -428,6 +428,29 @@ action_new_window_callback (GtkAction *action, } static void +action_new_tab_callback (GtkAction *action, + gpointer user_data) +{ + NautilusWindow *window; + NautilusWindowSlot *current_slot; + NautilusWindowSlot *new_slot; + GFile *current_location; + + window = NAUTILUS_WINDOW (user_data); + current_slot = window->details->active_slot; + current_location = nautilus_window_slot_get_location (current_slot); + + window = NAUTILUS_WINDOW (current_slot->window); + + if (current_location != NULL) { + new_slot = nautilus_window_open_slot (window); + nautilus_window_set_active_slot (window, new_slot); + nautilus_window_slot_go_to (new_slot, current_location); + g_object_unref (current_location); + } +} + +static void action_folder_window_callback (GtkAction *action, gpointer user_data) { @@ -477,6 +500,9 @@ static const GtkActionEntry navigation_entries[] = { /* name, stock id, label */ { "New Window", "window-new", N_("New _Window"), "<control>N", N_("Open another Nautilus window for the displayed location"), G_CALLBACK (action_new_window_callback) }, + /* name, stock id, label */ { "New Tab", "tab-new", N_("New _Tab"), + "<control>T", N_("Open another tab for the displayed location"), + G_CALLBACK (action_new_tab_callback) }, /* name, stock id, label */ { "Folder Window", "folder", N_("Open Folder W_indow"), NULL, N_("Open a folder window for the displayed location"), G_CALLBACK (action_folder_window_callback) }, diff --git a/src/nautilus-navigation-window-slot.c b/src/nautilus-navigation-window-slot.c index 398cb677c..e545fa7ef 100644 --- a/src/nautilus-navigation-window-slot.c +++ b/src/nautilus-navigation-window-slot.c @@ -34,16 +34,92 @@ static void nautilus_navigation_window_slot_class_init (NautilusNavigationWindow G_DEFINE_TYPE (NautilusNavigationWindowSlot, nautilus_navigation_window_slot, NAUTILUS_TYPE_WINDOW_SLOT) #define parent_class nautilus_navigation_window_slot_parent_class +void +nautilus_navigation_window_slot_clear_forward_list (NautilusNavigationWindowSlot *slot) +{ + g_assert (NAUTILUS_IS_NAVIGATION_WINDOW_SLOT (slot)); + + eel_g_object_list_free (slot->forward_list); + slot->forward_list = NULL; +} + +void +nautilus_navigation_window_slot_clear_back_list (NautilusNavigationWindowSlot *slot) +{ + g_assert (NAUTILUS_IS_NAVIGATION_WINDOW_SLOT (slot)); + + eel_g_object_list_free (slot->back_list); + slot->back_list = NULL; +} + static void nautilus_navigation_window_slot_active (NautilusWindowSlot *slot) { - NautilusWindow *window; + NautilusNavigationWindow *window; + NautilusNavigationWindowSlot *navigation_slot; + int page_num; + + navigation_slot = NAUTILUS_NAVIGATION_WINDOW_SLOT (slot); + window = NAUTILUS_NAVIGATION_WINDOW (slot->window); - window = slot->window; + page_num = gtk_notebook_page_num (GTK_NOTEBOOK (window->notebook), + slot->content_box); + g_assert (page_num >= 0); + + gtk_notebook_set_current_page (GTK_NOTEBOOK (window->notebook), page_num); EEL_CALL_PARENT (NAUTILUS_WINDOW_SLOT_CLASS, active, (slot)); - nautilus_navigation_window_load_extension_toolbar_items (NAUTILUS_NAVIGATION_WINDOW (window)); + nautilus_navigation_window_load_extension_toolbar_items (window); +} + +static NautilusWindowSlot * +nautilus_navigation_window_slot_get_close_successor (NautilusWindowSlot *slot) +{ + NautilusWindowSlot *successor; + NautilusNavigationWindow *window; + GtkNotebook *notebook; + GtkWidget *widget; + int page_num, n_pages; + + window = NAUTILUS_NAVIGATION_WINDOW (slot->window); + notebook = GTK_NOTEBOOK (window->notebook); + + n_pages = gtk_notebook_get_n_pages (notebook); + + page_num = gtk_notebook_page_num (notebook, slot->content_box); + g_assert (page_num >= 0); + + if (page_num == n_pages - 1) { + /* use previous page */ + page_num--; + } else { + /* use next page */ + page_num++; + } + + successor = NULL; + + widget = gtk_notebook_get_nth_page (notebook, page_num); + if (widget != NULL) { + successor = nautilus_window_get_slot_for_content_box (slot->window, widget); + if (successor == slot) { + successor = NULL; + } + } + + return successor; +} + +static void +nautilus_navigation_window_slot_finalize (GObject *object) +{ + NautilusNavigationWindowSlot *slot; + + slot = NAUTILUS_NAVIGATION_WINDOW_SLOT (object); + + nautilus_navigation_window_slot_clear_forward_list (slot); + nautilus_navigation_window_slot_clear_back_list (slot); } static void @@ -55,4 +131,7 @@ static void nautilus_navigation_window_slot_class_init (NautilusNavigationWindowSlotClass *class) { NAUTILUS_WINDOW_SLOT_CLASS (class)->active = nautilus_navigation_window_slot_active; + NAUTILUS_WINDOW_SLOT_CLASS (class)->get_close_successor = nautilus_navigation_window_slot_get_close_successor; + + G_OBJECT_CLASS (class)->finalize = nautilus_navigation_window_slot_finalize; } diff --git a/src/nautilus-navigation-window-slot.h b/src/nautilus-navigation-window-slot.h index 8bb5eb299..d7ac7576c 100644 --- a/src/nautilus-navigation-window-slot.h +++ b/src/nautilus-navigation-window-slot.h @@ -45,7 +45,6 @@ typedef enum { } NautilusBarMode; struct NautilusNavigationWindowSlot { - GtkWidget *content_box; NautilusWindowSlot parent; NautilusBarMode bar_mode; @@ -67,5 +66,8 @@ struct NautilusNavigationWindowSlotClass { GType nautilus_navigation_window_slot_get_type (void); +void nautilus_navigation_window_slot_clear_forward_list (NautilusNavigationWindowSlot *slot); +void nautilus_navigation_window_slot_clear_back_list (NautilusNavigationWindowSlot *slot); + #endif /* NAUTILUS_NAVIGATION_WINDOW_SLOT_H */ diff --git a/src/nautilus-navigation-window-ui.xml b/src/nautilus-navigation-window-ui.xml index 8f5c0997d..933f0aedb 100644 --- a/src/nautilus-navigation-window-ui.xml +++ b/src/nautilus-navigation-window-ui.xml @@ -3,6 +3,7 @@ <menu action="File"> <placeholder name="New Items Placeholder"> <menuitem name="New Window" action="New Window"/> + <menuitem name="New Tab" action="New Tab"/> <menuitem name="Folder Window" action="Folder Window"/> </placeholder> diff --git a/src/nautilus-navigation-window.c b/src/nautilus-navigation-window.c index 87d9a6c89..bc85e1510 100644 --- a/src/nautilus-navigation-window.c +++ b/src/nautilus-navigation-window.c @@ -184,6 +184,36 @@ location_button_create (NautilusNavigationWindow *window) return button; } +static gboolean +notebook_switch_page_cb (GtkNotebook *notebook, + GtkNotebookPage *page, + unsigned int page_num, + NautilusNavigationWindow *window) +{ + NautilusWindow *nautilus_window; + NautilusWindowSlot *slot; + GtkWidget *widget; + GList *l; + + nautilus_window = NAUTILUS_WINDOW (window); + + widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->notebook), page_num); + g_assert (widget != NULL); + + /* find slot corresponding to the target page */ + for (l = nautilus_window->details->slots; l != NULL; l = l->next) { + slot = NAUTILUS_WINDOW_SLOT (l->data); + if (slot->content_box == widget) { + break; + } + } + + g_assert (slot != NULL); + nautilus_window_set_active_slot (nautilus_window, slot); + + return FALSE; +} + static void nautilus_navigation_window_init (NautilusNavigationWindow *window) { @@ -209,6 +239,10 @@ nautilus_navigation_window_init (NautilusNavigationWindow *window) nautilus_horizontal_splitter_pack2 ( NAUTILUS_HORIZONTAL_SPLITTER (window->details->content_paned), window->notebook); + g_signal_connect (window->notebook, + "switch-page", + G_CALLBACK (notebook_switch_page_cb), + window); gtk_notebook_set_show_tabs (GTK_NOTEBOOK (window->notebook), FALSE); gtk_notebook_set_show_border (GTK_NOTEBOOK (window->notebook), FALSE); gtk_widget_show (window->notebook); @@ -712,8 +746,6 @@ nautilus_navigation_window_finalize (GObject *object) window = NAUTILUS_NAVIGATION_WINDOW (object); nautilus_navigation_window_remove_go_menu_callback (window); - nautilus_navigation_window_clear_back_list (window); - nautilus_navigation_window_clear_forward_list (window); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -1188,30 +1220,6 @@ real_set_search_mode (NautilusWindow *window, gboolean search_mode, nautilus_query_editor_grab_focus (NAUTILUS_QUERY_EDITOR (query_editor)); } -void -nautilus_navigation_window_clear_forward_list (NautilusNavigationWindow *window) -{ - NautilusNavigationWindowSlot *slot; - - slot = NAUTILUS_NAVIGATION_WINDOW_SLOT (NAUTILUS_WINDOW (window)->details->active_slot); - g_assert (slot != NULL); - - eel_g_object_list_free (slot->forward_list); - slot->forward_list = NULL; -} - -void -nautilus_navigation_window_clear_back_list (NautilusNavigationWindow *window) -{ - NautilusNavigationWindowSlot *slot; - - slot = NAUTILUS_NAVIGATION_WINDOW_SLOT (NAUTILUS_WINDOW (window)->details->active_slot); - g_assert (slot != NULL); - - eel_g_object_list_free (slot->back_list); - slot->back_list = NULL; -} - static void side_panel_image_changed_callback (NautilusSidebar *side_panel, gpointer callback_data) @@ -1592,17 +1600,34 @@ real_get_default_size (NautilusWindow *window, static NautilusWindowSlot * real_open_slot (NautilusWindow *window) { + NautilusNavigationWindow *navigation_window; NautilusWindowSlot *slot; + GtkNotebook *notebook; - /* these will be removed once we have real tab support */ - g_assert (window->details->active_slot == NULL); - g_assert (window->details->slots == NULL); + navigation_window = NAUTILUS_NAVIGATION_WINDOW (window); + notebook = GTK_NOTEBOOK (navigation_window->notebook); slot = (NautilusWindowSlot *) g_object_new (NAUTILUS_TYPE_NAVIGATION_WINDOW_SLOT, NULL); slot->window = window; - gtk_notebook_append_page (GTK_NOTEBOOK (NAUTILUS_NAVIGATION_WINDOW (window)->notebook), + + g_signal_handlers_block_by_func (navigation_window->notebook, + G_CALLBACK (notebook_switch_page_cb), + window); + /* multiview-TODO add some way to influence the position. + * We need + * + "behind active tab" [for views] + * + "at the end" [for loading sessions] + */ + gtk_notebook_append_page (notebook, slot->content_box, NULL); + g_signal_handlers_unblock_by_func (notebook, + G_CALLBACK (notebook_switch_page_cb), + window); + + gtk_notebook_set_show_tabs (notebook, + gtk_notebook_get_n_pages (notebook) > 1); + gtk_widget_show (slot->content_box); return slot; @@ -1612,11 +1637,29 @@ static void real_close_slot (NautilusWindow *window, NautilusWindowSlot *slot) { - /* multiview-TODO these will be removed once we have real tab support */ - g_assert (window->details->active_slot == slot); - g_assert (g_list_length (window->details->slots) == 1); + NautilusNavigationWindow *navigation_window; + GtkNotebook *notebook; + int page_num; + + navigation_window = NAUTILUS_NAVIGATION_WINDOW (window); + notebook = GTK_NOTEBOOK (navigation_window->notebook); + + page_num = gtk_notebook_page_num (notebook, slot->content_box); + g_assert (page_num >= 0); - /* multiview-TODO remove notebook tab */ + g_signal_handlers_block_by_func (notebook, + G_CALLBACK (notebook_switch_page_cb), + window); + gtk_notebook_remove_page (notebook, page_num); + g_signal_handlers_unblock_by_func (notebook, + G_CALLBACK (notebook_switch_page_cb), + window); + + gtk_notebook_set_show_tabs (notebook, + gtk_notebook_get_n_pages (notebook) > 1); + + EEL_CALL_PARENT (NAUTILUS_WINDOW_CLASS, + close_slot, (window, slot)); } static void diff --git a/src/nautilus-window-manage-views.c b/src/nautilus-window-manage-views.c index dfb3d5992..47cb8f140 100644 --- a/src/nautilus-window-manage-views.c +++ b/src/nautilus-window-manage-views.c @@ -274,6 +274,9 @@ handle_go_forward (NautilusNavigationWindow *window, GFile *location) g_list_free_1 (link); } +/* + * multiview-TODO: handle this on a per-slot basis + */ static void handle_go_elsewhere (NautilusWindow *window, GFile *location) { @@ -286,7 +289,7 @@ handle_go_elsewhere (NautilusWindow *window, GFile *location) navigation_slot = (NautilusNavigationWindowSlot *) slot; /* Clobber the entire forward list, and move displayed location to back list */ - nautilus_navigation_window_clear_forward_list (NAUTILUS_NAVIGATION_WINDOW (window)); + nautilus_navigation_window_slot_clear_forward_list (navigation_slot); if (slot->location != NULL) { /* If we're returning to the same uri somehow, don't put this uri on back list. @@ -340,7 +343,6 @@ viewed_file_changed_callback (NautilusFile *file, g_assert (NAUTILUS_IS_FILE (file)); g_assert (NAUTILUS_IS_WINDOW (window)); - slot = window->details->active_slot; g_assert (file == slot->viewed_file); if (!nautilus_file_is_not_yet_confirmed (file)) { @@ -499,6 +501,7 @@ nautilus_window_slot_open_location_full (NautilusWindowSlot *slot, { NautilusWindow *window; NautilusWindow *target_window; + NautilusWindowSlot *target_slot; gboolean do_load_location = TRUE; GFile *old_location; char *old_uri, *new_uri; @@ -506,6 +509,7 @@ nautilus_window_slot_open_location_full (NautilusWindowSlot *slot, window = slot->window; target_window = NULL; + target_slot = NULL; old_uri = nautilus_window_slot_get_location_uri (slot); if (old_uri == NULL) { @@ -586,6 +590,12 @@ nautilus_window_slot_open_location_full (NautilusWindowSlot *slot, g_assert (target_window != NULL); + if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0 && + NAUTILUS_IS_NAVIGATION_WINDOW (window)) { + g_assert (target_window == window); + target_slot = nautilus_window_open_slot (window); + } + if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND) != 0) { if (NAUTILUS_IS_SPATIAL_WINDOW (window) && !NAUTILUS_IS_DESKTOP_WINDOW (window)) { if (GTK_WIDGET_VISIBLE (target_window)) { @@ -611,7 +621,11 @@ nautilus_window_slot_open_location_full (NautilusWindowSlot *slot, g_object_unref (old_location); } - begin_location_change (target_window->details->active_slot, location, new_selection, + if (target_slot == NULL) { + target_slot = target_window->details->active_slot; + } + + begin_location_change (target_slot, location, new_selection, NAUTILUS_LOCATION_CHANGE_STANDARD, 0, NULL); } @@ -1115,6 +1129,11 @@ got_file_info_for_view_selection_callback (NautilusFile *file, /* Clean up state of already-showing window */ end_location_change (slot); + /* TODO? shouldn't we call + * cancel_viewed_file_changed_callback (slot); + * at this point, or in end_location_change() + */ + /* We disconnected this, so we need to re-connect it */ viewed_file = nautilus_file_get (slot->location); nautilus_window_slot_set_viewed_file (slot, viewed_file); @@ -1282,6 +1301,10 @@ nautilus_window_report_load_underway (NautilusWindow *window, slot = nautilus_window_get_slot_for_view (window, view); g_assert (slot != NULL); + if (slot == NULL) { + /* maybe the slot was immediately closed after opening it. */ + return; + } if (view == slot->new_content_view) { location_has_really_changed (slot); diff --git a/src/nautilus-window-menus.c b/src/nautilus-window-menus.c index 32371479c..9ad0b162b 100644 --- a/src/nautilus-window-menus.c +++ b/src/nautilus-window-menus.c @@ -191,7 +191,17 @@ static void action_close_window_callback (GtkAction *action, gpointer user_data) { - nautilus_window_close (NAUTILUS_WINDOW (user_data)); + NautilusWindow *window; + NautilusWindowSlot *slot; + + /* multiview-TODO rename this action, decide + * whether we need a "close all" action + */ + + window = NAUTILUS_WINDOW (user_data); + slot = window->details->active_slot; + + nautilus_window_slot_close (slot); } static void diff --git a/src/nautilus-window-private.h b/src/nautilus-window-private.h index 1515a5cbe..dc7607f4d 100644 --- a/src/nautilus-window-private.h +++ b/src/nautilus-window-private.h @@ -181,6 +181,8 @@ void nautilus_window_close_slot (Nautil NautilusWindowSlot *nautilus_window_get_slot_for_view (NautilusWindow *window, NautilusView *view); +NautilusWindowSlot *nautilus_window_get_slot_for_content_box (NautilusWindow *window, + GtkWidget *content_box); NautilusWindowSlot * nautilus_window_get_active_slot (NautilusWindow *window); void nautilus_window_set_active_slot (NautilusWindow *window, diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c index f37a759e9..7e527d1b6 100644 --- a/src/nautilus-window-slot.c +++ b/src/nautilus-window-slot.c @@ -71,6 +71,7 @@ nautilus_window_slot_active (NautilusWindowSlot *slot) g_assert (NAUTILUS_IS_WINDOW_SLOT (slot)); window = NAUTILUS_WINDOW (slot->window); + g_assert (g_list_find (window->details->slots, slot) != NULL); g_assert (slot == window->details->active_slot); EEL_CALL_METHOD (NAUTILUS_WINDOW_SLOT_CLASS, slot, @@ -94,6 +95,9 @@ nautilus_window_slot_inactive (NautilusWindowSlot *slot) NautilusWindow *window; g_assert (NAUTILUS_IS_WINDOW_SLOT (slot)); + + window = NAUTILUS_WINDOW (slot->window); + g_assert (g_list_find (window->details->slots, slot) != NULL); g_assert (slot == window->details->active_slot); EEL_CALL_METHOD (NAUTILUS_WINDOW_SLOT_CLASS, slot, @@ -125,11 +129,19 @@ nautilus_window_slot_init (NautilusWindowSlot *slot) gtk_widget_show (slot->view_box); } +static NautilusWindowSlot * +real_get_close_successor (NautilusWindowSlot *slot) +{ + return NULL; +} + static void nautilus_window_slot_class_init (NautilusWindowSlotClass *class) { class->active = real_active; class->inactive = real_inactive; + class->get_close_successor = real_get_close_successor; + G_OBJECT_CLASS (class)->finalize = nautilus_window_slot_finalize; } @@ -321,10 +333,24 @@ nautilus_window_slot_add_extra_location_widget (NautilusWindowSlot *slot, gtk_widget_show (slot->extra_location_widgets); } +/* gets the slot that is supposed to be displayed after closing + * the active slot. + */ +NautilusWindowSlot * +nautilus_window_slot_get_close_successor (NautilusWindowSlot *slot) +{ + return EEL_CALL_METHOD_WITH_RETURN_VALUE (NAUTILUS_WINDOW_SLOT_CLASS, slot, + get_close_successor, (slot)); +} + + static void nautilus_window_slot_finalize (GObject *object) { - NautilusWindowSlot *slot = NAUTILUS_WINDOW_SLOT (object); + NautilusWindowSlot *slot; + GtkWidget *widget; + + slot = NAUTILUS_WINDOW_SLOT (object); nautilus_window_slot_set_viewed_file (slot, NULL); /* TODO? why do we unref here? the file is NULL. @@ -350,6 +376,20 @@ nautilus_window_slot_finalize (GObject *object) slot->find_mount_cancellable = NULL; } + if (slot->content_view) { + widget = nautilus_view_get_widget (slot->content_view); + gtk_widget_destroy (widget); + g_object_unref (slot->content_view); + slot->content_view = NULL; + } + + if (slot->new_content_view) { + widget = nautilus_view_get_widget (slot->new_content_view); + gtk_widget_destroy (widget); + g_object_unref (slot->new_content_view); + slot->new_content_view = NULL; + } + g_free (slot->title); } diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h index 67e15e308..a4cb80292 100644 --- a/src/nautilus-window-slot.h +++ b/src/nautilus-window-slot.h @@ -46,8 +46,12 @@ typedef enum { struct NautilusWindowSlotClass { GObjectClass parent_class; + /* wrapped NautilusWindowInfo signals, for overloading */ void (* active) (NautilusWindowSlot *slot); void (* inactive) (NautilusWindowSlot *slot); + + /* gets the slot to make active after this slot has been closed. */ + NautilusWindowSlot * (* get_close_successor) (NautilusWindowSlot *slot); }; /* Each NautilusWindowSlot corresponds to @@ -113,9 +117,21 @@ void nautilus_window_slot_update_icon (NautilusWindowSlot *slot); GFile * nautilus_window_slot_get_location (NautilusWindowSlot *slot); char * nautilus_window_slot_get_location_uri (NautilusWindowSlot *slot); +NautilusWindowSlot * + nautilus_window_slot_get_close_successor (NautilusWindowSlot *slot); void nautilus_window_slot_close (NautilusWindowSlot *slot); void nautilus_window_slot_reload (NautilusWindowSlot *slot); +#define nautilus_window_slot_go_to(slot,location) \ + nautilus_window_slot_open_location(slot, location, FALSE) + +#define nautilus_window_slot_go_to_with_selection(slot,location,new_selection) \ + nautilus_window_slot_open_location_with_selection(slot, location, new_selection, FALSE) + +void nautilus_window_slot_go_home (NautilusWindow *window); +void nautilus_window_slot_go_up (NautilusWindow *window, + gboolean close_behind); + void nautilus_window_slot_set_content_view_widget (NautilusWindowSlot *slot, NautilusView *content_view); void nautilus_window_slot_set_viewed_file (NautilusWindowSlot *slot, diff --git a/src/nautilus-window.c b/src/nautilus-window.c index caa7d4f65..bb730653a 100644 --- a/src/nautilus-window.c +++ b/src/nautilus-window.c @@ -37,6 +37,8 @@ #include "nautilus-main.h" #include "nautilus-window-manage-views.h" #include "nautilus-window-bookmarks.h" +#include "nautilus-window-slot.h" +#include "nautilus-navigation-window-slot.h" #include "nautilus-zoom-control.h" #include "nautilus-search-bar.h" #include <eel/eel-debug.h> @@ -240,7 +242,7 @@ nautilus_window_go_to (NautilusWindow *window, GFile *location) { g_return_if_fail (NAUTILUS_IS_WINDOW (window)); - nautilus_window_slot_open_location (window->details->active_slot, location, FALSE); + nautilus_window_slot_go_to (window->details->active_slot, location); } @@ -249,7 +251,7 @@ nautilus_window_go_to_with_selection (NautilusWindow *window, GFile *location, G { g_return_if_fail (NAUTILUS_IS_WINDOW (window)); - nautilus_window_slot_open_location_with_selection (window->details->active_slot, location, new_selection, FALSE); + nautilus_window_slot_go_to_with_selection (window->details->active_slot, location, new_selection); } static gboolean @@ -645,7 +647,6 @@ nautilus_window_destroy (GtkObject *object) { NautilusWindow *window; NautilusWindowSlot *slot; - GtkWidget *widget; GList *l; window = NAUTILUS_WINDOW (object); @@ -657,18 +658,7 @@ nautilus_window_destroy (GtkObject *object) slot = l->data; cancel_view_as_callback (slot); - - if (slot->content_view) { - g_object_unref (slot->content_view); - slot->content_view = NULL; - } - - if (slot->new_content_view) { - widget = nautilus_view_get_widget (slot->new_content_view); - gtk_widget_destroy (widget); - g_object_unref (slot->new_content_view); - slot->new_content_view = NULL; - } + g_object_unref (slot); } GTK_OBJECT_CLASS (nautilus_window_parent_class)->destroy (object); @@ -707,6 +697,7 @@ nautilus_window_constructor (GType type, { GObject *object; NautilusWindow *window; + NautilusWindowSlot *slot; object = (* G_OBJECT_CLASS (nautilus_window_parent_class)->constructor) (type, n_construct_properties, @@ -714,7 +705,6 @@ nautilus_window_constructor (GType type, window = NAUTILUS_WINDOW (object); - NautilusWindowSlot *slot; slot = nautilus_window_open_slot (window); nautilus_window_set_active_slot (window, slot); @@ -755,8 +745,18 @@ nautilus_window_show_window (NautilusWindow *window) void nautilus_window_close (NautilusWindow *window) { + NautilusWindowSlot *slot; + GList *l; + g_return_if_fail (NAUTILUS_IS_WINDOW (window)); + nautilus_window_set_active_slot (window, NULL); + + for (l = window->details->slots; l != NULL; l = l->next) { + slot = NAUTILUS_WINDOW_SLOT (l->data); + nautilus_window_close_slot (window, slot); + } + EEL_CALL_METHOD (NAUTILUS_WINDOW_CLASS, window, close, (window)); @@ -781,6 +781,13 @@ nautilus_window_open_slot (NautilusWindow *window) return slot; } +static void +real_close_slot (NautilusWindow *window, + NautilusWindowSlot *slot) +{ + g_object_unref (slot); +} + void nautilus_window_close_slot (NautilusWindow *window, NautilusWindowSlot *slot) @@ -794,7 +801,6 @@ nautilus_window_close_slot (NautilusWindow *window, close_slot, (window, slot)); window->details->slots = g_list_remove (window->details->slots, slot); - nautilus_window_slot_set_allow_stop (slot, FALSE); } void @@ -804,10 +810,12 @@ nautilus_window_set_active_slot (NautilusWindow *window, NautilusWindowSlot *old_slot; g_assert (NAUTILUS_IS_WINDOW (window)); - g_assert (NAUTILUS_IS_WINDOW_SLOT (new_slot)); - g_assert (window == new_slot->window); - g_assert (g_list_find (window->details->slots, new_slot) != NULL); + if (new_slot != NULL) { + g_assert (NAUTILUS_IS_WINDOW_SLOT (new_slot)); + g_assert (window == new_slot->window); + g_assert (g_list_find (window->details->slots, new_slot) != NULL); + } old_slot = window->details->active_slot; @@ -827,17 +835,20 @@ nautilus_window_set_active_slot (NautilusWindow *window, window->details->active_slot = new_slot; - /* inform sidebar panels */ - nautilus_window_report_location_change (window, TRUE); - /* TODO decide whether "selection-changed" should be emitted */ - if (new_slot->content_view != NULL) { - /* inform window */ - nautilus_window_connect_content_view (window, new_slot->content_view); - } + if (new_slot != NULL) { + /* inform sidebar panels */ + nautilus_window_report_location_change (window, TRUE); + /* TODO decide whether "selection-changed" should be emitted */ + + if (new_slot->content_view != NULL) { + /* inform window */ + nautilus_window_connect_content_view (window, new_slot->content_view); + } - /* inform slot & view */ - g_signal_emit_by_name (new_slot, "active"); + /* inform slot & view */ + g_signal_emit_by_name (new_slot, "active"); + } } void @@ -847,18 +858,11 @@ nautilus_window_slot_close (NautilusWindowSlot *slot) window = slot->window; - if (g_list_length (window->details->slots) > 1) { - EEL_CALL_METHOD (NAUTILUS_WINDOW_CLASS, window, - close_slot, (window, slot)); - g_object_unref (slot); - } else { - /* no slot_closed will be emitted for the last slot. - * All the NautilusWindowInfo clients life inside the window, so they - * will be destroyed anyway. - * - * This is just for convenience, because otherwise we'd have to handle - * windows without any active slot. - */ + nautilus_window_set_active_slot (window, + nautilus_window_slot_get_close_successor (slot)); + nautilus_window_close_slot (window, slot); + + if (g_list_length (window->details->slots) == 0) { nautilus_window_close (window); } } @@ -1255,9 +1259,12 @@ load_view_as_menus_callback (NautilusFile *file, slot = callback_data; window = NAUTILUS_WINDOW (slot->window); - - EEL_CALL_METHOD (NAUTILUS_WINDOW_CLASS, window, - load_view_as_menu, (window)); + + if (slot == window->details->active_slot) { + /* slot may have changed in the meantime */ + EEL_CALL_METHOD (NAUTILUS_WINDOW_CLASS, window, + load_view_as_menu, (window)); + } } static void @@ -1347,7 +1354,7 @@ real_connect_content_view (NautilusWindow *window, * views in the menu are for the old location). */ if (slot->pending_location == NULL) { - nautilus_window_synch_view_as_menus (window); + nautilus_window_load_view_as_menus (window); } nautilus_view_grab_focus (view); @@ -1642,6 +1649,24 @@ nautilus_window_get_slot_for_view (NautilusWindow *window, return NULL; } +NautilusWindowSlot * +nautilus_window_get_slot_for_content_box (NautilusWindow *window, + GtkWidget *content_box) +{ + NautilusWindowSlot *slot; + GList *l; + + for (l = window->details->slots; l != NULL; l = l->next) { + slot = NAUTILUS_WINDOW_SLOT (l->data); + + if (slot->content_box == content_box) { + return slot; + } + } + + return NULL; +} + void nautilus_window_add_current_location_to_history_list (NautilusWindow *window) { @@ -1655,6 +1680,7 @@ void nautilus_forget_history (void) { NautilusWindowSlot *slot; + NautilusNavigationWindowSlot *navigation_slot; GList *window_node, *l; /* Clear out each window's back & forward lists. Also, remove @@ -1669,10 +1695,15 @@ nautilus_forget_history (void) NautilusNavigationWindow *window; window = NAUTILUS_NAVIGATION_WINDOW (window_node->data); - - nautilus_navigation_window_clear_back_list (window); - nautilus_navigation_window_clear_forward_list (window); - + + for (l = NAUTILUS_WINDOW (window_node->data)->details->slots; + l != NULL; l = l->next) { + navigation_slot = l->data; + + nautilus_navigation_window_slot_clear_back_list (navigation_slot); + nautilus_navigation_window_slot_clear_forward_list (navigation_slot); + } + nautilus_navigation_window_allow_back (window, FALSE); nautilus_navigation_window_allow_forward (window, FALSE); } @@ -1834,6 +1865,7 @@ nautilus_window_class_init (NautilusWindowClass *class) class->disconnect_content_view = real_disconnect_content_view; class->load_view_as_menu = real_load_view_as_menu; class->set_allow_up = real_set_allow_up; + class->close_slot = real_close_slot; g_object_class_install_property (G_OBJECT_CLASS (class), ARG_APP, |