2008-05-05 Paolo Borelli <pborelli@katamail.com>
[nautilus.git] / src / nautilus-window-toolbars.c
blobd0e7bef75384b0dccd706fd717249bb6e73b6507
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
3 /*
4 * Nautilus
6 * Copyright (C) 2000, 2001 Eazel, Inc.
8 * Nautilus is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * Nautilus is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Author: John Sullivan <sullivan@eazel.com>
25 /* nautilus-window-toolbars.c - implementation of nautilus window toolbar operations,
26 * split into separate file just for convenience.
29 #include <config.h>
31 #include <unistd.h>
32 #include "nautilus-application.h"
33 #include "nautilus-window-manage-views.h"
34 #include "nautilus-window-private.h"
35 #include "nautilus-window.h"
36 #include "nautilus-throbber.h"
37 #include <eel/eel-gnome-extensions.h>
38 #include <eel/eel-gtk-extensions.h>
39 #include <eel/eel-string.h>
40 #include <gtk/gtklabel.h>
41 #include <gtk/gtktogglebutton.h>
42 #include <gdk/gdkkeysyms.h>
43 #include <glib/gi18n.h>
44 #include <libgnomeui/gnome-popup-menu.h>
45 #include <libnautilus-extension/nautilus-menu-provider.h>
46 #include <libnautilus-private/nautilus-bookmark.h>
47 #include <libnautilus-private/nautilus-file-utilities.h>
48 #include <libnautilus-private/nautilus-ui-utilities.h>
49 #include <libnautilus-private/nautilus-global-preferences.h>
50 #include <libnautilus-private/nautilus-module.h>
52 /* FIXME bugzilla.gnome.org 41243:
53 * We should use inheritance instead of these special cases
54 * for the desktop window.
56 #include "nautilus-desktop-window.h"
58 #define TOOLBAR_PATH_EXTENSION_ACTIONS "/Toolbar/Extra Buttons Placeholder/Extension Actions"
60 void
61 nautilus_navigation_window_set_throbber_active (NautilusNavigationWindow *window,
62 gboolean allow)
64 if (( window->details->throbber_active && allow) ||
65 (!window->details->throbber_active && !allow)) {
66 return;
69 window->details->throbber_active = allow;
70 if (allow) {
71 nautilus_throbber_start (NAUTILUS_THROBBER (window->details->throbber));
72 } else {
73 nautilus_throbber_stop (NAUTILUS_THROBBER (window->details->throbber));
77 static void
78 toolbar_reconfigured_cb (GtkToolItem *item,
79 NautilusThrobber *throbber)
81 GtkToolbarStyle style;
82 GtkIconSize size;
84 style = gtk_tool_item_get_toolbar_style (item);
86 if (style == GTK_TOOLBAR_BOTH)
88 size = GTK_ICON_SIZE_DIALOG;
90 else
92 size = GTK_ICON_SIZE_LARGE_TOOLBAR;
95 nautilus_throbber_set_size (throbber, size);
98 void
99 nautilus_navigation_window_activate_throbber (NautilusNavigationWindow *window)
101 GtkToolItem *item;
102 GtkWidget *throbber;
104 if (window->details->throbber != NULL) {
105 return;
108 item = gtk_tool_item_new ();
109 gtk_widget_show (GTK_WIDGET (item));
110 gtk_tool_item_set_expand (item, TRUE);
111 gtk_toolbar_insert (GTK_TOOLBAR (window->details->toolbar),
112 item, -1);
114 throbber = nautilus_throbber_new ();
115 gtk_widget_show (GTK_WIDGET (throbber));
117 item = gtk_tool_item_new ();
118 gtk_container_add (GTK_CONTAINER (item), throbber);
119 gtk_widget_show (GTK_WIDGET (item));
121 g_signal_connect (item, "toolbar-reconfigured",
122 G_CALLBACK (toolbar_reconfigured_cb), throbber);
124 gtk_toolbar_insert (GTK_TOOLBAR (window->details->toolbar),
125 item, -1);
127 window->details->throbber = throbber;
130 void
131 nautilus_navigation_window_initialize_toolbars (NautilusNavigationWindow *window)
133 nautilus_navigation_window_activate_throbber (window);
137 static GList *
138 get_extension_toolbar_items (NautilusNavigationWindow *window)
140 GList *items;
141 GList *providers;
142 GList *l;
144 providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_MENU_PROVIDER);
145 items = NULL;
147 for (l = providers; l != NULL; l = l->next) {
148 NautilusMenuProvider *provider;
149 GList *file_items;
151 provider = NAUTILUS_MENU_PROVIDER (l->data);
152 file_items = nautilus_menu_provider_get_toolbar_items
153 (provider,
154 GTK_WIDGET (window),
155 NAUTILUS_WINDOW (window)->details->viewed_file);
156 items = g_list_concat (items, file_items);
159 nautilus_module_extension_list_free (providers);
161 return items;
164 void
165 nautilus_navigation_window_load_extension_toolbar_items (NautilusNavigationWindow *window)
167 GtkActionGroup *action_group;
168 GtkAction *action;
169 GtkUIManager *ui_manager;
170 GList *items;
171 GList *l;
172 NautilusMenuItem *item;
173 guint merge_id;
175 ui_manager = nautilus_window_get_ui_manager (NAUTILUS_WINDOW (window));
176 if (window->details->extensions_toolbar_merge_id != 0) {
177 gtk_ui_manager_remove_ui (ui_manager,
178 window->details->extensions_toolbar_merge_id);
179 window->details->extensions_toolbar_merge_id = 0;
182 if (window->details->extensions_toolbar_action_group != NULL) {
183 gtk_ui_manager_remove_action_group (ui_manager,
184 window->details->extensions_toolbar_action_group);
185 window->details->extensions_toolbar_action_group = NULL;
188 merge_id = gtk_ui_manager_new_merge_id (ui_manager);
189 window->details->extensions_toolbar_merge_id = merge_id;
190 action_group = gtk_action_group_new ("ExtensionsToolbarGroup");
191 window->details->extensions_toolbar_action_group = action_group;
192 gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
193 gtk_ui_manager_insert_action_group (ui_manager, action_group, -1);
194 g_object_unref (action_group); /* owned by ui manager */
196 items = get_extension_toolbar_items (window);
198 for (l = items; l != NULL; l = l->next) {
199 item = NAUTILUS_MENU_ITEM (l->data);
201 action = nautilus_toolbar_action_from_menu_item (item);
203 gtk_action_group_add_action (action_group,
204 GTK_ACTION (action));
205 g_object_unref (action);
207 gtk_ui_manager_add_ui (ui_manager,
208 merge_id,
209 TOOLBAR_PATH_EXTENSION_ACTIONS,
210 gtk_action_get_name (action),
211 gtk_action_get_name (action),
212 GTK_UI_MANAGER_TOOLITEM,
213 FALSE);
215 g_object_unref (item);
218 g_list_free (items);