2008-05-05 Paolo Borelli <pborelli@katamail.com>
[nautilus.git] / src / nautilus-navigation-window.c
blobb441a7ebc0752a8ecb47fb0439a110248e166069
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 /*
4 * Nautilus
6 * Copyright (C) 1999, 2000 Red Hat, Inc.
7 * Copyright (C) 1999, 2000, 2001 Eazel, Inc.
8 * Copyright (C) 2003 Ximian, Inc.
10 * Nautilus is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * Nautilus is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the Free
22 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * Authors: Elliot Lee <sopwith@redhat.com>
25 * John Sullivan <sullivan@eazel.com>
29 /* nautilus-window.c: Implementation of the main window object */
31 #include <config.h>
32 #include "nautilus-window-private.h"
34 #include "nautilus-actions.h"
35 #include "nautilus-application.h"
36 #include "nautilus-bookmarks-window.h"
37 #include "nautilus-main.h"
38 #include "nautilus-location-bar.h"
39 #include "nautilus-pathbar.h"
40 #include "nautilus-query-editor.h"
41 #include "nautilus-search-bar.h"
42 #include "nautilus-window-manage-views.h"
43 #include "nautilus-zoom-control.h"
44 #include <eel/eel-gtk-extensions.h>
45 #include <eel/eel-gtk-macros.h>
46 #include <eel/eel-string.h>
47 #include <gdk-pixbuf/gdk-pixbuf.h>
48 #include <gdk/gdkx.h>
49 #include <gtk/gtkmain.h>
50 #include <gtk/gtkmenubar.h>
51 #include <gtk/gtkmenuitem.h>
52 #include <gtk/gtkcombobox.h>
53 #include <gtk/gtktoolbar.h>
54 #include <gtk/gtktogglebutton.h>
55 #include <gtk/gtkvbox.h>
56 #include <gtk/gtktreemodel.h>
57 #include <gtk/gtkliststore.h>
58 #include <glib/gi18n.h>
59 #ifdef HAVE_X11_XF86KEYSYM_H
60 #include <X11/XF86keysym.h>
61 #endif
62 #include <libgnomeui/gnome-uidefs.h>
63 #include <libnautilus-private/nautilus-file-utilities.h>
64 #include <libnautilus-private/nautilus-file-attributes.h>
65 #include <libnautilus-private/nautilus-global-preferences.h>
66 #include <libnautilus-private/nautilus-horizontal-splitter.h>
67 #include <libnautilus-private/nautilus-icon-info.h>
68 #include <libnautilus-private/nautilus-metadata.h>
69 #include <libnautilus-private/nautilus-mime-actions.h>
70 #include <libnautilus-private/nautilus-program-choosing.h>
71 #include <libnautilus-private/nautilus-sidebar.h>
72 #include <libnautilus-private/nautilus-view-factory.h>
73 #include <libnautilus-private/nautilus-clipboard.h>
74 #include <libnautilus-private/nautilus-undo.h>
75 #include <libnautilus-private/nautilus-module.h>
76 #include <libnautilus-private/nautilus-sidebar-provider.h>
77 #include <libnautilus-private/nautilus-search-directory.h>
78 #include <libnautilus-private/nautilus-signaller.h>
79 #include <math.h>
80 #include <sys/time.h>
83 /* FIXME bugzilla.gnome.org 41243:
84 * We should use inheritance instead of these special cases
85 * for the desktop window.
87 #include "nautilus-desktop-window.h"
89 #define MAX_TITLE_LENGTH 180
91 #define MENU_PATH_BOOKMARKS_PLACEHOLDER "/MenuBar/Other Menus/Bookmarks/Bookmarks Placeholder"
93 typedef enum {
94 NAUTILUS_BAR_PATH,
95 NAUTILUS_BAR_NAVIGATION,
96 NAUTILUS_BAR_SEARCH
97 } NautilusBarMode;
99 enum {
100 ARG_0,
101 ARG_APP_ID,
102 ARG_APP
105 static int side_pane_width_auto_value = 0;
107 static void add_sidebar_panels (NautilusNavigationWindow *window);
108 static void load_view_as_menu (NautilusWindow *window);
109 static void side_panel_image_changed_callback (NautilusSidebar *side_panel,
110 gpointer callback_data);
111 static void navigation_bar_location_changed_callback (GtkWidget *widget,
112 const char *uri,
113 NautilusNavigationWindow *window);
114 static void navigation_bar_cancel_callback (GtkWidget *widget,
115 NautilusNavigationWindow *window);
116 static void path_bar_location_changed_callback (GtkWidget *widget,
117 GFile *path,
118 NautilusNavigationWindow *window);
119 static void always_use_location_entry_changed (gpointer callback_data);
120 static void always_use_browser_changed (gpointer callback_data);
122 static void nautilus_navigation_window_set_bar_mode (NautilusNavigationWindow *window,
123 NautilusBarMode mode);
124 static void search_bar_activate_callback (NautilusSearchBar *bar,
125 NautilusWindow *window);
126 static void search_bar_cancel_callback (GtkWidget *widget,
127 NautilusNavigationWindow *window);
129 static void nautilus_navigation_window_show_location_bar_temporarily (NautilusNavigationWindow *window);
131 static void view_as_menu_switch_views_callback (GtkComboBox *combo_box,
132 NautilusWindow *window);
134 G_DEFINE_TYPE (NautilusNavigationWindow, nautilus_navigation_window, NAUTILUS_TYPE_WINDOW)
135 #define parent_class nautilus_navigation_window_parent_class
137 static const struct {
138 unsigned int keyval;
139 const char *action;
140 } extra_navigation_window_keybindings [] = {
141 #ifdef HAVE_X11_XF86KEYSYM_H
142 { XF86XK_Back, NAUTILUS_ACTION_BACK },
143 { XF86XK_Forward, NAUTILUS_ACTION_FORWARD }
144 #endif
147 static void
148 location_button_toggled_cb (GtkToggleButton *toggle,
149 NautilusNavigationWindow *window)
151 gboolean is_active;
153 is_active = gtk_toggle_button_get_active (toggle);
154 eel_preferences_set_boolean (NAUTILUS_PREFERENCES_ALWAYS_USE_LOCATION_ENTRY, is_active);
156 if (is_active) {
157 nautilus_navigation_bar_activate (NAUTILUS_NAVIGATION_BAR (window->navigation_bar));
161 static gboolean
162 location_button_should_be_active (NautilusNavigationWindow *window)
164 return eel_preferences_get_boolean (NAUTILUS_PREFERENCES_ALWAYS_USE_LOCATION_ENTRY);
167 static GtkWidget *
168 location_button_create (NautilusNavigationWindow *window)
170 GtkWidget *image;
171 GtkWidget *button;
173 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
174 gtk_widget_show (image);
176 button = g_object_new (GTK_TYPE_TOGGLE_BUTTON,
177 "image", image,
178 "focus-on-click", FALSE,
179 "active", location_button_should_be_active (window),
180 NULL);
182 gtk_widget_set_tooltip_text (button,
183 _("Toggle between button and text-based location bar"));
185 g_signal_connect (button, "toggled",
186 G_CALLBACK (location_button_toggled_cb), window);
187 return button;
190 static void
191 nautilus_navigation_window_init (NautilusNavigationWindow *window)
193 GtkUIManager *ui_manager;
194 GtkWidget *toolbar;
195 GtkWidget *location_bar;
196 GtkWidget *view_as_menu_vbox;
197 GtkToolItem *item;
198 GtkWidget *hbox, *vbox, *eventbox, *extras_vbox;
200 window->details = G_TYPE_INSTANCE_GET_PRIVATE (window, NAUTILUS_TYPE_NAVIGATION_WINDOW, NautilusNavigationWindowDetails);
202 window->details->content_paned = nautilus_horizontal_splitter_new ();
203 gtk_table_attach (GTK_TABLE (NAUTILUS_WINDOW (window)->details->table),
204 window->details->content_paned,
205 /* X direction */ /* Y direction */
206 0, 1, 3, 4,
207 GTK_EXPAND | GTK_FILL | GTK_SHRINK, GTK_EXPAND | GTK_FILL | GTK_SHRINK,
208 0, 0);
209 gtk_widget_show (window->details->content_paned);
211 vbox = gtk_vbox_new (FALSE, 0);
212 nautilus_horizontal_splitter_pack2 (
213 NAUTILUS_HORIZONTAL_SPLITTER (window->details->content_paned),
214 vbox);
215 gtk_widget_show (vbox);
217 eventbox = gtk_event_box_new ();
218 gtk_widget_set_name (eventbox, "nautilus-extra-view-widget");
219 gtk_box_pack_start (GTK_BOX (vbox), eventbox, FALSE, FALSE, 0);
220 gtk_widget_show (eventbox);
222 extras_vbox = gtk_vbox_new (FALSE, 0);
223 gtk_container_set_border_width (GTK_CONTAINER (extras_vbox), 6);
224 NAUTILUS_WINDOW (window)->details->extra_location_widgets = extras_vbox;
225 gtk_container_add (GTK_CONTAINER (eventbox), extras_vbox);
227 window->details->content_box = gtk_vbox_new (FALSE, 0);
228 gtk_box_pack_start (GTK_BOX (vbox), window->details->content_box, TRUE, TRUE, 0);
229 gtk_widget_show (window->details->content_box);
231 nautilus_navigation_window_initialize_actions (window);
232 nautilus_navigation_window_initialize_menus (window);
234 ui_manager = nautilus_window_get_ui_manager (NAUTILUS_WINDOW (window));
235 toolbar = gtk_ui_manager_get_widget (ui_manager, "/Toolbar");
236 window->details->toolbar = toolbar;
237 gtk_table_attach (GTK_TABLE (NAUTILUS_WINDOW (window)->details->table),
238 toolbar,
239 /* X direction */ /* Y direction */
240 0, 1, 1, 2,
241 GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0,
242 0, 0);
243 gtk_widget_show (toolbar);
245 nautilus_navigation_window_initialize_toolbars (window);
247 /* Set initial sensitivity of some buttons & menu items
248 * now that they're all created.
250 nautilus_navigation_window_allow_back (window, FALSE);
251 nautilus_navigation_window_allow_forward (window, FALSE);
253 /* set up location bar */
254 location_bar = gtk_toolbar_new ();
255 window->details->location_bar = location_bar;
257 hbox = gtk_hbox_new (FALSE, 12);
258 gtk_widget_show (hbox);
260 item = gtk_tool_item_new ();
261 gtk_container_set_border_width (GTK_CONTAINER (item), GNOME_PAD_SMALL);
262 gtk_widget_show (GTK_WIDGET (item));
263 gtk_tool_item_set_expand (item, TRUE);
264 gtk_container_add (GTK_CONTAINER (item), hbox);
265 gtk_toolbar_insert (GTK_TOOLBAR (location_bar),
266 item, -1);
268 window->details->location_button = location_button_create (window);
269 gtk_box_pack_start (GTK_BOX (hbox), window->details->location_button, FALSE, FALSE, 0);
270 gtk_widget_show (window->details->location_button);
272 window->path_bar = g_object_new (NAUTILUS_TYPE_PATH_BAR, NULL);
273 gtk_widget_show (window->path_bar);
275 g_signal_connect_object (window->path_bar, "path_clicked",
276 G_CALLBACK (path_bar_location_changed_callback), window, 0);
278 gtk_box_pack_start (GTK_BOX (hbox),
279 window->path_bar,
280 TRUE, TRUE, 0);
282 window->navigation_bar = nautilus_location_bar_new (window);
283 g_signal_connect_object (window->navigation_bar, "location_changed",
284 G_CALLBACK (navigation_bar_location_changed_callback), window, 0);
285 g_signal_connect_object (window->navigation_bar, "cancel",
286 G_CALLBACK (navigation_bar_cancel_callback), window, 0);
288 gtk_box_pack_start (GTK_BOX (hbox),
289 window->navigation_bar,
290 TRUE, TRUE, 0);
292 window->search_bar = nautilus_search_bar_new ();
293 g_signal_connect_object (window->search_bar, "activate",
294 G_CALLBACK (search_bar_activate_callback), window, 0);
295 g_signal_connect_object (window->search_bar, "cancel",
296 G_CALLBACK (search_bar_cancel_callback), window, 0);
297 gtk_box_pack_start (GTK_BOX (hbox),
298 window->search_bar,
299 TRUE, TRUE, 0);
301 /* Option menu for content view types; it's empty here, filled in when a uri is set.
302 * Pack it into vbox so it doesn't grow vertically when location bar does.
304 view_as_menu_vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL);
305 gtk_widget_show (view_as_menu_vbox);
307 item = gtk_tool_item_new ();
308 gtk_container_set_border_width (GTK_CONTAINER (item), GNOME_PAD_SMALL);
309 gtk_widget_show (GTK_WIDGET (item));
310 gtk_container_add (GTK_CONTAINER (item), view_as_menu_vbox);
311 gtk_toolbar_insert (GTK_TOOLBAR (location_bar),
312 item, -1);
314 window->view_as_combo_box = gtk_combo_box_new_text ();
315 gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (window->view_as_combo_box), FALSE);
316 gtk_box_pack_end (GTK_BOX (view_as_menu_vbox), window->view_as_combo_box, TRUE, FALSE, 0);
317 gtk_widget_show (window->view_as_combo_box);
318 g_signal_connect_object (window->view_as_combo_box, "changed",
319 G_CALLBACK (view_as_menu_switch_views_callback), window, 0);
321 /* Allocate the zoom control and place on the right next to the menu.
322 * It gets shown later, if the view-frame contains something zoomable.
324 window->zoom_control = nautilus_zoom_control_new ();
325 g_signal_connect_object (window->zoom_control, "zoom_in",
326 G_CALLBACK (nautilus_window_zoom_in),
327 window, G_CONNECT_SWAPPED);
328 g_signal_connect_object (window->zoom_control, "zoom_out",
329 G_CALLBACK (nautilus_window_zoom_out),
330 window, G_CONNECT_SWAPPED);
331 g_signal_connect_object (window->zoom_control, "zoom_to_level",
332 G_CALLBACK (nautilus_window_zoom_to_level),
333 window, G_CONNECT_SWAPPED);
334 g_signal_connect_object (window->zoom_control, "zoom_to_default",
335 G_CALLBACK (nautilus_window_zoom_to_default),
336 window, G_CONNECT_SWAPPED);
338 item = gtk_tool_item_new ();
339 gtk_container_set_border_width (GTK_CONTAINER (item), GNOME_PAD_SMALL);
340 gtk_widget_show (GTK_WIDGET (item));
341 gtk_container_add (GTK_CONTAINER (item), window->zoom_control);
342 gtk_toolbar_insert (GTK_TOOLBAR (location_bar),
343 item, 1);
345 gtk_widget_show (location_bar);
347 gtk_table_attach (GTK_TABLE (NAUTILUS_WINDOW (window)->details->table),
348 location_bar,
349 /* X direction */ /* Y direction */
350 0, 1, 2, 3,
351 GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0,
352 0, 0);
354 eel_preferences_add_callback_while_alive (NAUTILUS_PREFERENCES_ALWAYS_USE_LOCATION_ENTRY,
355 always_use_location_entry_changed,
356 window, G_OBJECT (window));
358 eel_preferences_add_callback_while_alive (NAUTILUS_PREFERENCES_ALWAYS_USE_BROWSER,
359 always_use_browser_changed,
360 window, G_OBJECT (window));
363 static void
364 always_use_location_entry_changed (gpointer callback_data)
366 NautilusNavigationWindow *window;
367 gboolean use_entry;
369 window = NAUTILUS_NAVIGATION_WINDOW (callback_data);
371 use_entry = eel_preferences_get_boolean (NAUTILUS_PREFERENCES_ALWAYS_USE_LOCATION_ENTRY);
373 if (use_entry) {
374 nautilus_navigation_window_set_bar_mode (window, NAUTILUS_BAR_NAVIGATION);
375 } else {
376 nautilus_navigation_window_set_bar_mode (window, NAUTILUS_BAR_PATH);
379 g_signal_handlers_block_by_func (window->details->location_button,
380 G_CALLBACK (location_button_toggled_cb),
381 window);
382 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (window->details->location_button), use_entry);
383 g_signal_handlers_unblock_by_func (window->details->location_button,
384 G_CALLBACK (location_button_toggled_cb),
385 window);
388 static void
389 always_use_browser_changed (gpointer callback_data)
391 NautilusNavigationWindow *window;
393 window = NAUTILUS_NAVIGATION_WINDOW (callback_data);
395 nautilus_navigation_window_update_spatial_menu_item (window);
398 static int
399 bookmark_list_get_uri_index (GList *list,
400 GFile *location)
402 NautilusBookmark *bookmark;
403 GList *l;
404 GFile *tmp;
405 int i;
407 g_return_val_if_fail (location != NULL, -1);
409 for (i = 0, l = list; l != NULL; i++, l = l->next) {
410 bookmark = NAUTILUS_BOOKMARK (l->data);
412 tmp = nautilus_bookmark_get_location (bookmark);
413 if (g_file_equal (location, tmp)) {
414 g_object_unref (tmp);
415 return i;
417 g_object_unref (tmp);
420 return -1;
423 static void
424 path_bar_location_changed_callback (GtkWidget *widget,
425 GFile *location,
426 NautilusNavigationWindow *window)
428 int i;
430 g_assert (NAUTILUS_IS_NAVIGATION_WINDOW (window));
432 /* check whether we already visited the target location */
433 i = bookmark_list_get_uri_index (window->back_list, location);
434 if (i >= 0) {
435 nautilus_navigation_window_back_or_forward (window, TRUE, i);
436 } else {
437 nautilus_window_go_to (NAUTILUS_WINDOW (window), location);
441 static void
442 hide_temporary_bars (NautilusNavigationWindow *window)
444 g_assert (NAUTILUS_IS_NAVIGATION_WINDOW (window));
446 if (window->details->temporary_location_bar) {
447 if (nautilus_navigation_window_location_bar_showing (window)) {
448 nautilus_navigation_window_hide_location_bar (window, FALSE);
450 window->details->temporary_location_bar = FALSE;
452 if (window->details->temporary_navigation_bar) {
453 if (NAUTILUS_WINDOW (window)->details->search_mode) {
454 nautilus_navigation_window_set_bar_mode (window, NAUTILUS_BAR_SEARCH);
455 } else {
456 if (!eel_preferences_get_boolean (NAUTILUS_PREFERENCES_ALWAYS_USE_LOCATION_ENTRY)) {
457 nautilus_navigation_window_set_bar_mode (window, NAUTILUS_BAR_PATH);
460 window->details->temporary_navigation_bar = FALSE;
462 if (window->details->temporary_search_bar) {
463 if (!eel_preferences_get_boolean (NAUTILUS_PREFERENCES_ALWAYS_USE_LOCATION_ENTRY)) {
464 nautilus_navigation_window_set_bar_mode (window, NAUTILUS_BAR_PATH);
465 } else {
466 nautilus_navigation_window_set_bar_mode (window, NAUTILUS_BAR_NAVIGATION);
468 window->details->temporary_search_bar = FALSE;
472 static void
473 navigation_bar_location_changed_callback (GtkWidget *widget,
474 const char *uri,
475 NautilusNavigationWindow *window)
477 GFile *location;
479 hide_temporary_bars (window);
480 location = g_file_new_for_uri (uri);
481 nautilus_window_go_to (NAUTILUS_WINDOW (window), location);
482 g_object_unref (location);
485 static void
486 navigation_bar_cancel_callback (GtkWidget *widget,
487 NautilusNavigationWindow *window)
489 hide_temporary_bars (window);
492 static void
493 side_pane_close_requested_callback (GtkWidget *widget,
494 gpointer user_data)
496 NautilusNavigationWindow *window;
498 window = NAUTILUS_NAVIGATION_WINDOW (user_data);
500 nautilus_navigation_window_hide_sidebar (window);
503 static void
504 side_pane_size_allocate_callback (GtkWidget *widget,
505 GtkAllocation *allocation,
506 gpointer user_data)
508 NautilusNavigationWindow *window;
510 window = NAUTILUS_NAVIGATION_WINDOW (user_data);
512 if (allocation->width != window->details->side_pane_width) {
513 window->details->side_pane_width = allocation->width;
514 if (eel_preferences_key_is_writable (NAUTILUS_PREFERENCES_SIDEBAR_WIDTH)) {
515 eel_preferences_set_integer
516 (NAUTILUS_PREFERENCES_SIDEBAR_WIDTH,
517 allocation->width <= 1 ? 0 : allocation->width);
522 static void
523 setup_side_pane_width (NautilusNavigationWindow *window)
525 static gboolean setup_auto_value= TRUE;
527 g_return_if_fail (window->sidebar != NULL);
529 if (setup_auto_value) {
530 setup_auto_value = FALSE;
531 eel_preferences_add_auto_integer
532 (NAUTILUS_PREFERENCES_SIDEBAR_WIDTH,
533 &side_pane_width_auto_value);
536 window->details->side_pane_width = side_pane_width_auto_value;
538 /* FIXME bugzilla.gnome.org 41245: Saved in pixels instead of in %? */
539 /* FIXME bugzilla.gnome.org 41245: No reality check on the value? */
541 gtk_paned_set_position (GTK_PANED (window->details->content_paned),
542 side_pane_width_auto_value);
545 static void
546 set_current_side_panel (NautilusNavigationWindow *window,
547 NautilusSidebar *panel)
549 if (window->details->current_side_panel) {
550 nautilus_sidebar_is_visible_changed (window->details->current_side_panel,
551 FALSE);
552 eel_remove_weak_pointer (&window->details->current_side_panel);
555 if (panel != NULL) {
556 nautilus_sidebar_is_visible_changed (panel, TRUE);
558 window->details->current_side_panel = panel;
559 eel_add_weak_pointer (&window->details->current_side_panel);
562 static void
563 side_pane_switch_page_callback (NautilusSidePane *side_pane,
564 GtkWidget *widget,
565 NautilusNavigationWindow *window)
567 const char *id;
568 NautilusSidebar *sidebar;
570 sidebar = NAUTILUS_SIDEBAR (widget);
572 if (sidebar == NULL) {
573 return;
576 set_current_side_panel (window, sidebar);
578 id = nautilus_sidebar_get_sidebar_id (sidebar);
579 if (eel_preferences_key_is_writable (NAUTILUS_PREFERENCES_SIDE_PANE_VIEW)) {
580 eel_preferences_set (NAUTILUS_PREFERENCES_SIDE_PANE_VIEW, id);
584 static void
585 nautilus_navigation_window_set_up_sidebar (NautilusNavigationWindow *window)
587 window->sidebar = nautilus_side_pane_new ();
589 gtk_paned_pack1 (GTK_PANED (window->details->content_paned),
590 GTK_WIDGET (window->sidebar),
591 FALSE, TRUE);
593 setup_side_pane_width (window);
594 g_signal_connect (window->sidebar,
595 "size_allocate",
596 G_CALLBACK (side_pane_size_allocate_callback),
597 window);
599 add_sidebar_panels (window);
601 g_signal_connect (window->sidebar,
602 "close_requested",
603 G_CALLBACK (side_pane_close_requested_callback),
604 window);
606 g_signal_connect (window->sidebar,
607 "switch_page",
608 G_CALLBACK (side_pane_switch_page_callback),
609 window);
611 gtk_widget_show (GTK_WIDGET (window->sidebar));
614 static void
615 nautilus_navigation_window_tear_down_sidebar (NautilusNavigationWindow *window)
617 GList *node, *next;
618 NautilusSidebar *sidebar_panel;
620 g_signal_handlers_disconnect_by_func (window->sidebar,
621 side_pane_switch_page_callback,
622 window);
624 for (node = window->sidebar_panels; node != NULL; node = next) {
625 next = node->next;
627 sidebar_panel = NAUTILUS_SIDEBAR (node->data);
629 nautilus_navigation_window_remove_sidebar_panel (window,
630 sidebar_panel);
633 gtk_widget_destroy (GTK_WIDGET (window->sidebar));
634 window->sidebar = NULL;
637 static void
638 nautilus_navigation_window_unrealize (GtkWidget *widget)
640 NautilusNavigationWindow *window;
642 window = NAUTILUS_NAVIGATION_WINDOW (widget);
644 GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
647 static gboolean
648 nautilus_navigation_window_state_event (GtkWidget *widget,
649 GdkEventWindowState *event)
651 if (event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED) {
652 eel_preferences_set_boolean (NAUTILUS_PREFERENCES_NAVIGATION_WINDOW_MAXIMIZED,
653 event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED);
656 if (GTK_WIDGET_CLASS (parent_class)->window_state_event != NULL) {
657 return GTK_WIDGET_CLASS (parent_class)->window_state_event (widget, event);
660 return FALSE;
663 static gboolean
664 nautilus_navigation_window_key_press_event (GtkWidget *widget,
665 GdkEventKey *event)
667 NautilusNavigationWindow *window;
668 int i;
670 window = NAUTILUS_NAVIGATION_WINDOW (widget);
672 for (i = 0; i < G_N_ELEMENTS (extra_navigation_window_keybindings); i++) {
673 if (extra_navigation_window_keybindings[i].keyval == event->keyval) {
674 GtkAction *action;
676 action = gtk_action_group_get_action (window->details->navigation_action_group,
677 extra_navigation_window_keybindings[i].action);
678 g_assert (action != NULL);
680 g_assert (action != NULL);
681 if (gtk_action_is_sensitive (action)) {
682 gtk_action_activate (action);
683 return TRUE;
686 break;
690 return GTK_WIDGET_CLASS (nautilus_navigation_window_parent_class)->key_press_event (widget, event);
693 static void
694 nautilus_navigation_window_destroy (GtkObject *object)
696 NautilusNavigationWindow *window;
698 window = NAUTILUS_NAVIGATION_WINDOW (object);
700 window->sidebar = NULL;
701 g_list_foreach (window->sidebar_panels, (GFunc)g_object_unref, NULL);
702 g_list_free (window->sidebar_panels);
703 window->sidebar_panels = NULL;
705 window->view_as_combo_box = NULL;
706 window->navigation_bar = NULL;
707 window->path_bar = NULL;
708 window->zoom_control = NULL;
710 window->details->content_paned = NULL;
712 GTK_OBJECT_CLASS (parent_class)->destroy (object);
715 static void
716 nautilus_navigation_window_finalize (GObject *object)
718 NautilusNavigationWindow *window;
720 window = NAUTILUS_NAVIGATION_WINDOW (object);
722 nautilus_navigation_window_remove_go_menu_callback (window);
723 nautilus_navigation_window_clear_back_list (window);
724 nautilus_navigation_window_clear_forward_list (window);
726 G_OBJECT_CLASS (parent_class)->finalize (object);
730 * Main API
733 void
734 nautilus_navigation_window_add_sidebar_panel (NautilusNavigationWindow *window,
735 NautilusSidebar *sidebar_panel)
737 const char *sidebar_id;
738 char *label;
739 char *tooltip;
740 char *default_id;
741 GdkPixbuf *icon;
743 g_return_if_fail (NAUTILUS_IS_NAVIGATION_WINDOW (window));
744 g_return_if_fail (NAUTILUS_IS_SIDEBAR (sidebar_panel));
745 g_return_if_fail (NAUTILUS_IS_SIDE_PANE (window->sidebar));
746 g_return_if_fail (g_list_find (window->sidebar_panels, sidebar_panel) == NULL);
748 label = nautilus_sidebar_get_tab_label (sidebar_panel);
749 tooltip = nautilus_sidebar_get_tab_tooltip (sidebar_panel);
750 nautilus_side_pane_add_panel (window->sidebar,
751 GTK_WIDGET (sidebar_panel),
752 label,
753 tooltip);
754 g_free (tooltip);
755 g_free (label);
757 icon = nautilus_sidebar_get_tab_icon (sidebar_panel);
758 nautilus_side_pane_set_panel_image (NAUTILUS_NAVIGATION_WINDOW (window)->sidebar,
759 GTK_WIDGET (sidebar_panel),
760 icon);
761 if (icon) {
762 g_object_unref (icon);
765 g_signal_connect (sidebar_panel, "tab_icon_changed",
766 (GCallback)side_panel_image_changed_callback, window);
768 window->sidebar_panels = g_list_prepend (window->sidebar_panels,
769 g_object_ref (sidebar_panel));
771 /* Show if default */
772 sidebar_id = nautilus_sidebar_get_sidebar_id (sidebar_panel);
773 default_id = eel_preferences_get (NAUTILUS_PREFERENCES_SIDE_PANE_VIEW);
774 if (sidebar_id && default_id && !strcmp (sidebar_id, default_id)) {
775 nautilus_side_pane_show_panel (window->sidebar,
776 GTK_WIDGET (sidebar_panel));
778 g_free (default_id);
781 void
782 nautilus_navigation_window_remove_sidebar_panel (NautilusNavigationWindow *window,
783 NautilusSidebar *sidebar_panel)
785 g_return_if_fail (NAUTILUS_IS_NAVIGATION_WINDOW (window));
786 g_return_if_fail (NAUTILUS_IS_SIDEBAR (sidebar_panel));
788 if (g_list_find (window->sidebar_panels, sidebar_panel) == NULL) {
789 return;
792 g_signal_handlers_disconnect_by_func (sidebar_panel, side_panel_image_changed_callback, window);
794 nautilus_side_pane_remove_panel (window->sidebar,
795 GTK_WIDGET (sidebar_panel));
796 window->sidebar_panels = g_list_remove (window->sidebar_panels, sidebar_panel);
797 g_object_unref (sidebar_panel);
800 void
801 nautilus_navigation_window_go_back (NautilusNavigationWindow *window)
803 nautilus_navigation_window_back_or_forward (window, TRUE, 0);
806 void
807 nautilus_navigation_window_go_forward (NautilusNavigationWindow *window)
809 nautilus_navigation_window_back_or_forward (window, FALSE, 0);
812 void
813 nautilus_navigation_window_allow_back (NautilusNavigationWindow *window, gboolean allow)
815 GtkAction *action;
817 action = gtk_action_group_get_action (window->details->navigation_action_group,
818 NAUTILUS_ACTION_BACK);
820 gtk_action_set_sensitive (action, allow);
823 void
824 nautilus_navigation_window_allow_forward (NautilusNavigationWindow *window, gboolean allow)
826 GtkAction *action;
828 action = gtk_action_group_get_action (window->details->navigation_action_group,
829 NAUTILUS_ACTION_FORWARD);
831 gtk_action_set_sensitive (action, allow);
834 static void
835 activate_nth_short_list_item (NautilusWindow *window, guint index)
837 g_assert (NAUTILUS_IS_WINDOW (window));
838 g_assert (index < g_list_length (window->details->short_list_viewers));
840 nautilus_window_set_content_view (window,
841 g_list_nth_data (window->details->short_list_viewers, index));
844 static void
845 activate_extra_viewer (NautilusWindow *window)
847 g_assert (NAUTILUS_IS_WINDOW (window));
848 g_assert (window->details->extra_viewer != NULL);
850 nautilus_window_set_content_view (window, window->details->extra_viewer);
853 static void
854 view_as_menu_switch_views_callback (GtkComboBox *combo_box, NautilusWindow *window)
856 int active;
857 g_assert (GTK_IS_COMBO_BOX (combo_box));
858 g_assert (NAUTILUS_IS_WINDOW (window));
860 active = gtk_combo_box_get_active (combo_box);
862 if (active < 0) {
863 return;
864 } else if (active < GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo_box), "num viewers"))) {
865 activate_nth_short_list_item (window, active);
866 } else {
867 activate_extra_viewer (window);
871 static void
872 load_view_as_menu (NautilusWindow *window)
874 GList *node;
875 int index;
876 int selected_index = -1;
877 GtkTreeModel *model;
878 GtkListStore *store;
879 const NautilusViewInfo *info;
880 GtkComboBox* combo_box;
882 combo_box = GTK_COMBO_BOX (NAUTILUS_NAVIGATION_WINDOW (window)->view_as_combo_box);
883 /* Clear the contents of ComboBox in a wacky way because there
884 * is no function to clear all items and also no function to obtain
885 * the number of items in a combobox.
887 model = gtk_combo_box_get_model (combo_box);
888 g_return_if_fail (GTK_IS_LIST_STORE (model));
889 store = GTK_LIST_STORE (model);
890 gtk_list_store_clear (store);
892 /* Add a menu item for each view in the preferred list for this location. */
893 for (node = window->details->short_list_viewers, index = 0;
894 node != NULL;
895 node = node->next, ++index) {
896 info = nautilus_view_factory_lookup (node->data);
897 gtk_combo_box_append_text (combo_box, _(info->view_combo_label));
899 if (nautilus_window_content_view_matches_iid (NAUTILUS_WINDOW (window), (char *)node->data)) {
900 selected_index = index;
903 g_object_set_data (G_OBJECT (combo_box), "num viewers", GINT_TO_POINTER (index));
904 if (selected_index == -1) {
905 const char *id;
906 /* We're using an extra viewer, add a menu item for it */
908 id = nautilus_window_get_content_view_id (window);
909 info = nautilus_view_factory_lookup (id);
910 gtk_combo_box_append_text (GTK_COMBO_BOX (NAUTILUS_NAVIGATION_WINDOW (window)->view_as_combo_box),
911 _(info->view_combo_label));
912 selected_index = index;
915 gtk_combo_box_set_active (GTK_COMBO_BOX (NAUTILUS_NAVIGATION_WINDOW (window)->view_as_combo_box), selected_index);
918 static void
919 real_load_view_as_menu (NautilusWindow *window)
921 EEL_CALL_PARENT (NAUTILUS_WINDOW_CLASS,
922 load_view_as_menu, (window));
924 load_view_as_menu (window);
927 static gboolean
928 real_set_title (NautilusWindow *window, const char *title)
930 char *full_title;
931 char *window_title;
932 gboolean changed;
934 changed = EEL_CALL_PARENT_WITH_RETURN_VALUE
935 (NAUTILUS_WINDOW_CLASS, set_title, (window, title));
937 if (changed) {
938 full_title = g_strdup_printf (_("%s - File Browser"), title);
940 window_title = eel_str_middle_truncate (full_title, MAX_TITLE_LENGTH);
941 gtk_window_set_title (GTK_WINDOW (window), window_title);
942 g_free (window_title);
943 g_free (full_title);
946 return changed;
949 static NautilusIconInfo *
950 real_get_icon (NautilusWindow *window)
952 return nautilus_icon_info_lookup_from_name ("file-manager", 48);
955 static void
956 zoom_level_changed_callback (NautilusView *view,
957 NautilusNavigationWindow *window)
959 g_assert (NAUTILUS_IS_WINDOW (window));
961 /* This is called each time the component successfully completed
962 * a zooming operation.
964 nautilus_zoom_control_set_zoom_level (NAUTILUS_ZOOM_CONTROL (window->zoom_control),
965 nautilus_view_get_zoom_level (view));
968 static void
969 connect_view (NautilusNavigationWindow *window, NautilusView *view)
971 g_signal_connect (view, "zoom_level_changed",
972 G_CALLBACK (zoom_level_changed_callback),
973 window);
976 static void
977 disconnect_view (NautilusNavigationWindow *window, NautilusView *view)
979 if (!view) {
980 return;
983 g_signal_handlers_disconnect_by_func
984 (view,
985 G_CALLBACK (zoom_level_changed_callback),
986 window);
989 static void
990 real_set_content_view_widget (NautilusWindow *nautilus_window,
991 NautilusView *new_view)
994 NautilusNavigationWindow *window;
996 window = NAUTILUS_NAVIGATION_WINDOW (nautilus_window);
998 disconnect_view (window, nautilus_window->content_view);
1000 EEL_CALL_PARENT (NAUTILUS_WINDOW_CLASS,
1001 set_content_view_widget,
1002 (nautilus_window, new_view));
1005 if (new_view == NULL) {
1006 return;
1009 connect_view (window, new_view);
1011 gtk_container_add (GTK_CONTAINER (window->details->content_box),
1012 GTK_WIDGET (new_view));
1014 if (new_view != NULL && nautilus_view_supports_zooming (new_view)) {
1015 gtk_widget_show (window->zoom_control);
1016 } else {
1017 gtk_widget_hide (window->zoom_control);
1020 /* Update displayed view in menu. Only do this if we're not switching
1021 * locations though, because if we are switching locations we'll
1022 * install a whole new set of views in the menu later (the current
1023 * views in the menu are for the old location).
1025 if (nautilus_window->details->pending_location == NULL) {
1026 load_view_as_menu (nautilus_window);
1030 static void
1031 real_set_throbber_active (NautilusWindow *window, gboolean active)
1033 nautilus_navigation_window_set_throbber_active
1034 (NAUTILUS_NAVIGATION_WINDOW (window), active);
1037 static void
1038 nautilus_navigation_window_show_location_bar_temporarily (NautilusNavigationWindow *window)
1040 if (!nautilus_navigation_window_location_bar_showing (window)) {
1041 nautilus_navigation_window_show_location_bar (window, FALSE);
1042 window->details->temporary_location_bar = TRUE;
1046 static void
1047 nautilus_navigation_window_show_navigation_bar_temporarily (NautilusNavigationWindow *window)
1049 if (nautilus_navigation_window_path_bar_showing (window)
1050 || nautilus_navigation_window_search_bar_showing (window)) {
1051 nautilus_navigation_window_set_bar_mode (window, NAUTILUS_BAR_NAVIGATION);
1052 window->details->temporary_navigation_bar = TRUE;
1054 nautilus_navigation_bar_activate
1055 (NAUTILUS_NAVIGATION_BAR (window->navigation_bar));
1058 static void
1059 real_prompt_for_location (NautilusWindow *window, const char *initial)
1061 nautilus_navigation_window_show_location_bar_temporarily (NAUTILUS_NAVIGATION_WINDOW (window));
1062 nautilus_navigation_window_show_navigation_bar_temporarily (NAUTILUS_NAVIGATION_WINDOW (window));
1064 if (initial) {
1065 nautilus_navigation_bar_set_location (NAUTILUS_NAVIGATION_BAR (NAUTILUS_NAVIGATION_WINDOW (window)->navigation_bar),
1066 initial);
1070 static void
1071 search_bar_activate_callback (NautilusSearchBar *bar,
1072 NautilusWindow *window)
1074 char *uri, *current_uri;
1075 NautilusDirectory *directory;
1076 NautilusSearchDirectory *search_directory;
1077 NautilusQuery *query;
1078 GFile *location;
1080 uri = nautilus_search_directory_generate_new_uri ();
1081 location = g_file_new_for_uri (uri);
1082 g_free (uri);
1084 directory = nautilus_directory_get (location);
1086 g_assert (NAUTILUS_IS_SEARCH_DIRECTORY (directory));
1088 search_directory = NAUTILUS_SEARCH_DIRECTORY (directory);
1090 query = nautilus_search_bar_get_query (NAUTILUS_SEARCH_BAR (NAUTILUS_NAVIGATION_WINDOW (window)->search_bar));
1091 if (query != NULL) {
1092 if (!nautilus_search_directory_is_indexed (search_directory)) {
1093 current_uri = nautilus_window_get_location_uri (window);
1094 nautilus_query_set_location (query, current_uri);
1095 g_free (current_uri);
1097 nautilus_search_directory_set_query (search_directory, query);
1098 g_object_unref (query);
1101 nautilus_window_go_to (window, location);
1103 nautilus_directory_unref (directory);
1104 g_object_unref (location);
1107 static void
1108 search_bar_cancel_callback (GtkWidget *widget,
1109 NautilusNavigationWindow *window)
1111 hide_temporary_bars (window);
1114 void
1115 nautilus_navigation_window_show_search (NautilusNavigationWindow *window)
1117 if (!nautilus_navigation_window_search_bar_showing (window)) {
1118 nautilus_navigation_window_show_location_bar_temporarily (window);
1119 nautilus_navigation_window_set_bar_mode (window, NAUTILUS_BAR_SEARCH);
1120 window->details->temporary_search_bar = TRUE;
1121 nautilus_search_bar_clear (NAUTILUS_SEARCH_BAR (window->search_bar));
1124 nautilus_search_bar_grab_focus (NAUTILUS_SEARCH_BAR (window->search_bar));
1127 static void
1128 query_editor_changed_callback (NautilusSearchBar *bar,
1129 NautilusQuery *query,
1130 gboolean reload,
1131 NautilusWindow *window)
1133 NautilusDirectory *directory;
1135 directory = nautilus_directory_get_for_file (window->details->viewed_file);
1136 g_assert (NAUTILUS_IS_SEARCH_DIRECTORY (directory));
1138 nautilus_search_directory_set_query (NAUTILUS_SEARCH_DIRECTORY (directory),
1139 query);
1140 if (reload) {
1141 nautilus_window_reload (window);
1144 nautilus_directory_unref (directory);
1147 static void
1148 real_set_search_mode (NautilusWindow *window, gboolean search_mode,
1149 NautilusSearchDirectory *search_directory)
1151 NautilusNavigationWindow *nav_window;
1152 GtkWidget *query_editor;
1153 NautilusQuery *query;
1155 nav_window = NAUTILUS_NAVIGATION_WINDOW (window);
1157 if (!search_mode) {
1158 nav_window->details->temporary_search_bar = TRUE;
1159 hide_temporary_bars (nav_window);
1160 return;
1163 if (nautilus_search_directory_is_saved_search (search_directory)) {
1164 query_editor = nautilus_query_editor_new (TRUE,
1165 nautilus_search_directory_is_indexed (search_directory));
1166 } else {
1167 nautilus_navigation_window_show_location_bar_temporarily (nav_window);
1168 nautilus_navigation_window_set_bar_mode (nav_window, NAUTILUS_BAR_SEARCH);
1169 nav_window->details->temporary_search_bar = FALSE;
1171 query_editor = nautilus_query_editor_new_with_bar (FALSE,
1172 nautilus_search_directory_is_indexed (search_directory),
1173 NAUTILUS_SEARCH_BAR (nav_window->search_bar));
1176 g_signal_connect_object (query_editor, "changed",
1177 G_CALLBACK (query_editor_changed_callback), window, 0);
1179 query = nautilus_search_directory_get_query (search_directory);
1180 if (query != NULL) {
1181 nautilus_query_editor_set_query (NAUTILUS_QUERY_EDITOR (query_editor),
1182 query);
1183 g_object_unref (query);
1184 }else {
1185 nautilus_query_editor_set_default_query (NAUTILUS_QUERY_EDITOR (query_editor));
1188 nautilus_window_add_extra_location_widget (window, query_editor);
1189 gtk_widget_show (query_editor);
1190 nautilus_query_editor_grab_focus (NAUTILUS_QUERY_EDITOR (query_editor));
1193 void
1194 nautilus_navigation_window_clear_forward_list (NautilusNavigationWindow *window)
1196 eel_g_object_list_free (window->forward_list);
1197 window->forward_list = NULL;
1200 void
1201 nautilus_navigation_window_clear_back_list (NautilusNavigationWindow *window)
1203 eel_g_object_list_free (window->back_list);
1204 window->back_list = NULL;
1207 static void
1208 side_panel_image_changed_callback (NautilusSidebar *side_panel,
1209 gpointer callback_data)
1211 NautilusWindow *window;
1212 GdkPixbuf *icon;
1214 window = NAUTILUS_WINDOW (callback_data);
1216 icon = nautilus_sidebar_get_tab_icon (side_panel);
1217 nautilus_side_pane_set_panel_image (NAUTILUS_NAVIGATION_WINDOW (window)->sidebar,
1218 GTK_WIDGET (side_panel),
1219 icon);
1220 if (icon != NULL) {
1221 g_object_unref (icon);
1226 * add_sidebar_panels:
1227 * @window: A NautilusNavigationWindow
1229 * Adds all sidebars available
1232 static void
1233 add_sidebar_panels (NautilusNavigationWindow *window)
1235 GtkWidget *current;
1236 GList *providers;
1237 GList *p;
1238 NautilusSidebar *sidebar_panel;
1240 g_assert (NAUTILUS_IS_NAVIGATION_WINDOW (window));
1242 if (window->sidebar == NULL) {
1243 return;
1246 providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_SIDEBAR_PROVIDER);
1248 for (p = providers; p != NULL; p = p->next) {
1249 NautilusSidebarProvider *provider;
1251 provider = NAUTILUS_SIDEBAR_PROVIDER (p->data);
1253 sidebar_panel = nautilus_sidebar_provider_create (provider,
1254 NAUTILUS_WINDOW_INFO (window));
1255 nautilus_navigation_window_add_sidebar_panel (window,
1256 sidebar_panel);
1258 g_object_unref (sidebar_panel);
1261 nautilus_module_extension_list_free (providers);
1263 current = nautilus_side_pane_get_current_panel (window->sidebar);
1264 set_current_side_panel
1265 (window,
1266 NAUTILUS_SIDEBAR (current));
1269 void
1270 nautilus_navigation_window_hide_location_bar (NautilusNavigationWindow *window, gboolean save_preference)
1272 window->details->temporary_location_bar = FALSE;
1273 gtk_widget_hide (window->details->location_bar);
1274 nautilus_navigation_window_update_show_hide_menu_items (window);
1275 if (save_preference &&
1276 eel_preferences_key_is_writable (NAUTILUS_PREFERENCES_START_WITH_LOCATION_BAR)) {
1277 eel_preferences_set_boolean (NAUTILUS_PREFERENCES_START_WITH_LOCATION_BAR, FALSE);
1281 void
1282 nautilus_navigation_window_show_location_bar (NautilusNavigationWindow *window, gboolean save_preference)
1284 gtk_widget_show (window->details->location_bar);
1285 nautilus_navigation_window_update_show_hide_menu_items (window);
1286 if (save_preference &&
1287 eel_preferences_key_is_writable (NAUTILUS_PREFERENCES_START_WITH_LOCATION_BAR)) {
1288 eel_preferences_set_boolean (NAUTILUS_PREFERENCES_START_WITH_LOCATION_BAR, TRUE);
1292 gboolean
1293 nautilus_navigation_window_location_bar_showing (NautilusNavigationWindow *window)
1295 if (window->details->location_bar != NULL) {
1296 return GTK_WIDGET_VISIBLE (window->details->location_bar);
1298 /* If we're not visible yet we haven't changed visibility, so its TRUE */
1299 return TRUE;
1302 gboolean
1303 nautilus_navigation_window_search_bar_showing (NautilusNavigationWindow *window)
1305 if (window->search_bar != NULL) {
1306 return GTK_WIDGET_VISIBLE (window->search_bar);
1308 /* If we're not visible yet we haven't changed visibility, so its TRUE */
1309 return TRUE;
1312 static void
1313 nautilus_navigation_window_set_bar_mode (NautilusNavigationWindow *window,
1314 NautilusBarMode mode)
1316 switch (mode) {
1318 case NAUTILUS_BAR_PATH:
1319 gtk_widget_show (window->path_bar);
1320 gtk_widget_hide (window->navigation_bar);
1321 gtk_widget_hide (window->search_bar);
1322 break;
1324 case NAUTILUS_BAR_NAVIGATION:
1325 gtk_widget_show (window->navigation_bar);
1326 gtk_widget_hide (window->path_bar);
1327 gtk_widget_hide (window->search_bar);
1328 break;
1330 case NAUTILUS_BAR_SEARCH:
1331 gtk_widget_show (window->search_bar);
1332 gtk_widget_hide (window->path_bar);
1333 gtk_widget_hide (window->navigation_bar);
1334 break;
1338 gboolean
1339 nautilus_navigation_window_path_bar_showing (NautilusNavigationWindow *window)
1341 if (window->path_bar != NULL) {
1342 return GTK_WIDGET_VISIBLE (window->path_bar);
1344 /* If we're not visible yet we haven't changed visibility, so its TRUE */
1345 return TRUE;
1348 gboolean
1349 nautilus_navigation_window_toolbar_showing (NautilusNavigationWindow *window)
1351 if (window->details->toolbar != NULL) {
1352 return GTK_WIDGET_VISIBLE (window->details->toolbar);
1354 /* If we're not visible yet we haven't changed visibility, so its TRUE */
1355 return TRUE;
1358 void
1359 nautilus_navigation_window_hide_status_bar (NautilusNavigationWindow *window)
1361 gtk_widget_hide (NAUTILUS_WINDOW (window)->details->statusbar);
1363 nautilus_navigation_window_update_show_hide_menu_items (window);
1364 if (eel_preferences_key_is_writable (NAUTILUS_PREFERENCES_START_WITH_STATUS_BAR) &&
1365 eel_preferences_get_boolean (NAUTILUS_PREFERENCES_START_WITH_STATUS_BAR)) {
1366 eel_preferences_set_boolean (NAUTILUS_PREFERENCES_START_WITH_STATUS_BAR, FALSE);
1370 void
1371 nautilus_navigation_window_show_status_bar (NautilusNavigationWindow *window)
1373 gtk_widget_show (NAUTILUS_WINDOW (window)->details->statusbar);
1375 nautilus_navigation_window_update_show_hide_menu_items (window);
1376 if (eel_preferences_key_is_writable (NAUTILUS_PREFERENCES_START_WITH_STATUS_BAR) &&
1377 !eel_preferences_get_boolean (NAUTILUS_PREFERENCES_START_WITH_STATUS_BAR)) {
1378 eel_preferences_set_boolean (NAUTILUS_PREFERENCES_START_WITH_STATUS_BAR, TRUE);
1382 gboolean
1383 nautilus_navigation_window_status_bar_showing (NautilusNavigationWindow *window)
1385 if (NAUTILUS_WINDOW (window)->details->statusbar != NULL) {
1386 return GTK_WIDGET_VISIBLE (NAUTILUS_WINDOW (window)->details->statusbar);
1388 /* If we're not visible yet we haven't changed visibility, so its TRUE */
1389 return TRUE;
1393 void
1394 nautilus_navigation_window_hide_toolbar (NautilusNavigationWindow *window)
1396 gtk_widget_hide (window->details->toolbar);
1397 nautilus_navigation_window_update_show_hide_menu_items (window);
1398 if (eel_preferences_key_is_writable (NAUTILUS_PREFERENCES_START_WITH_TOOLBAR) &&
1399 eel_preferences_get_boolean (NAUTILUS_PREFERENCES_START_WITH_TOOLBAR)) {
1400 eel_preferences_set_boolean (NAUTILUS_PREFERENCES_START_WITH_TOOLBAR, FALSE);
1404 void
1405 nautilus_navigation_window_show_toolbar (NautilusNavigationWindow *window)
1407 gtk_widget_show (window->details->toolbar);
1408 nautilus_navigation_window_update_show_hide_menu_items (window);
1409 if (eel_preferences_key_is_writable (NAUTILUS_PREFERENCES_START_WITH_TOOLBAR) &&
1410 !eel_preferences_get_boolean (NAUTILUS_PREFERENCES_START_WITH_TOOLBAR)) {
1411 eel_preferences_set_boolean (NAUTILUS_PREFERENCES_START_WITH_TOOLBAR, TRUE);
1415 void
1416 nautilus_navigation_window_hide_sidebar (NautilusNavigationWindow *window)
1418 if (window->sidebar == NULL) {
1419 return;
1422 nautilus_navigation_window_tear_down_sidebar (window);
1423 nautilus_navigation_window_update_show_hide_menu_items (window);
1425 if (eel_preferences_key_is_writable (NAUTILUS_PREFERENCES_START_WITH_SIDEBAR) &&
1426 eel_preferences_get_boolean (NAUTILUS_PREFERENCES_START_WITH_SIDEBAR)) {
1427 eel_preferences_set_boolean (NAUTILUS_PREFERENCES_START_WITH_SIDEBAR, FALSE);
1431 void
1432 nautilus_navigation_window_show_sidebar (NautilusNavigationWindow *window)
1434 if (window->sidebar != NULL) {
1435 return;
1438 nautilus_navigation_window_set_up_sidebar (window);
1439 nautilus_navigation_window_update_show_hide_menu_items (window);
1440 if (eel_preferences_key_is_writable (NAUTILUS_PREFERENCES_START_WITH_SIDEBAR) &&
1441 !eel_preferences_get_boolean (NAUTILUS_PREFERENCES_START_WITH_SIDEBAR)) {
1442 eel_preferences_set_boolean (NAUTILUS_PREFERENCES_START_WITH_SIDEBAR, TRUE);
1446 gboolean
1447 nautilus_navigation_window_sidebar_showing (NautilusNavigationWindow *window)
1449 g_return_val_if_fail (NAUTILUS_IS_NAVIGATION_WINDOW (window), FALSE);
1451 return (window->sidebar != NULL)
1452 && nautilus_horizontal_splitter_is_hidden (NAUTILUS_HORIZONTAL_SPLITTER (window->details->content_paned));
1456 * nautilus_navigation_window_get_base_page_index:
1457 * @window: Window to get index from
1459 * Returns the index of the base page in the history list.
1460 * Base page is not the currently displayed page, but the page
1461 * that acts as the base from which the back and forward commands
1462 * navigate from.
1464 gint
1465 nautilus_navigation_window_get_base_page_index (NautilusNavigationWindow *window)
1467 gint forward_count;
1469 forward_count = g_list_length (window->forward_list);
1471 /* If forward is empty, the base it at the top of the list */
1472 if (forward_count == 0) {
1473 return 0;
1476 /* The forward count indicate the relative postion of the base page
1477 * in the history list
1479 return forward_count;
1485 * nautilus_navigation_window_show:
1486 * @widget: GtkWidget
1488 * Call parent and then show/hide window items
1489 * base on user prefs.
1491 static void
1492 nautilus_navigation_window_show (GtkWidget *widget)
1494 NautilusNavigationWindow *window;
1496 window = NAUTILUS_NAVIGATION_WINDOW (widget);
1498 /* Initially show or hide views based on preferences; once the window is displayed
1499 * these can be controlled on a per-window basis from View menu items.
1502 if (eel_preferences_get_boolean (NAUTILUS_PREFERENCES_START_WITH_TOOLBAR)) {
1503 nautilus_navigation_window_show_toolbar (window);
1504 } else {
1505 nautilus_navigation_window_hide_toolbar (window);
1508 if (eel_preferences_get_boolean (NAUTILUS_PREFERENCES_START_WITH_LOCATION_BAR)) {
1509 nautilus_navigation_window_show_location_bar (window, FALSE);
1510 } else {
1511 nautilus_navigation_window_hide_location_bar (window, FALSE);
1514 if (eel_preferences_get_boolean (NAUTILUS_PREFERENCES_ALWAYS_USE_LOCATION_ENTRY)) {
1515 nautilus_navigation_window_set_bar_mode (window, NAUTILUS_BAR_NAVIGATION);
1516 } else {
1517 nautilus_navigation_window_set_bar_mode (window, NAUTILUS_BAR_PATH);
1520 if (eel_preferences_get_boolean (NAUTILUS_PREFERENCES_START_WITH_SIDEBAR)) {
1521 nautilus_navigation_window_show_sidebar (window);
1522 } else {
1523 nautilus_navigation_window_hide_sidebar (window);
1526 if (eel_preferences_get_boolean (NAUTILUS_PREFERENCES_START_WITH_STATUS_BAR)) {
1527 nautilus_navigation_window_show_status_bar (window);
1528 } else {
1529 nautilus_navigation_window_hide_status_bar (window);
1532 GTK_WIDGET_CLASS (parent_class)->show (widget);
1535 static void
1536 nautilus_navigation_window_save_geometry (NautilusNavigationWindow *window)
1538 char *geometry_string;
1539 gboolean is_maximized;
1541 g_assert (NAUTILUS_IS_WINDOW (window));
1543 if (GTK_WIDGET(window)->window) {
1544 geometry_string = eel_gtk_window_get_geometry_string (GTK_WINDOW (window));
1545 is_maximized = gdk_window_get_state (GTK_WIDGET (window)->window)
1546 & GDK_WINDOW_STATE_MAXIMIZED;
1548 if (eel_preferences_key_is_writable (NAUTILUS_PREFERENCES_NAVIGATION_WINDOW_SAVED_GEOMETRY) &&
1549 !is_maximized) {
1550 eel_preferences_set
1551 (NAUTILUS_PREFERENCES_NAVIGATION_WINDOW_SAVED_GEOMETRY,
1552 geometry_string);
1554 g_free (geometry_string);
1556 if (eel_preferences_key_is_writable (NAUTILUS_PREFERENCES_NAVIGATION_WINDOW_MAXIMIZED)) {
1557 eel_preferences_set_boolean
1558 (NAUTILUS_PREFERENCES_NAVIGATION_WINDOW_MAXIMIZED,
1559 is_maximized);
1566 static void
1567 real_window_close (NautilusWindow *window)
1569 nautilus_navigation_window_save_geometry (NAUTILUS_NAVIGATION_WINDOW (window));
1572 static void
1573 real_get_default_size (NautilusWindow *window,
1574 guint *default_width, guint *default_height)
1576 if (default_width) {
1577 *default_width = NAUTILUS_NAVIGATION_WINDOW_DEFAULT_WIDTH;
1580 if (default_height) {
1581 *default_height = NAUTILUS_NAVIGATION_WINDOW_DEFAULT_HEIGHT;
1585 static void
1586 nautilus_navigation_window_class_init (NautilusNavigationWindowClass *class)
1588 NAUTILUS_WINDOW_CLASS (class)->window_type = NAUTILUS_WINDOW_NAVIGATION;
1589 NAUTILUS_WINDOW_CLASS (class)->bookmarks_placeholder = MENU_PATH_BOOKMARKS_PLACEHOLDER;
1591 G_OBJECT_CLASS (class)->finalize = nautilus_navigation_window_finalize;
1592 GTK_OBJECT_CLASS (class)->destroy = nautilus_navigation_window_destroy;
1593 GTK_WIDGET_CLASS (class)->show = nautilus_navigation_window_show;
1594 GTK_WIDGET_CLASS (class)->unrealize = nautilus_navigation_window_unrealize;
1595 GTK_WIDGET_CLASS (class)->window_state_event = nautilus_navigation_window_state_event;
1596 GTK_WIDGET_CLASS (class)->key_press_event = nautilus_navigation_window_key_press_event;
1597 NAUTILUS_WINDOW_CLASS (class)->load_view_as_menu = real_load_view_as_menu;
1598 NAUTILUS_WINDOW_CLASS (class)->set_content_view_widget = real_set_content_view_widget;
1599 NAUTILUS_WINDOW_CLASS (class)->set_throbber_active = real_set_throbber_active;
1600 NAUTILUS_WINDOW_CLASS (class)->prompt_for_location = real_prompt_for_location;
1601 NAUTILUS_WINDOW_CLASS (class)->set_search_mode = real_set_search_mode;
1602 NAUTILUS_WINDOW_CLASS (class)->set_title = real_set_title;
1603 NAUTILUS_WINDOW_CLASS (class)->get_icon = real_get_icon;
1604 NAUTILUS_WINDOW_CLASS (class)->get_default_size = real_get_default_size;
1605 NAUTILUS_WINDOW_CLASS (class)->close = real_window_close;
1607 g_type_class_add_private (G_OBJECT_CLASS (class), sizeof (NautilusNavigationWindowDetails));