diff options
author | Alexander Larsson <alexl@redhat.com> | 2004-11-22 15:24:38 +0000 |
---|---|---|
committer | Alexander Larsson <alexl@src.gnome.org> | 2004-11-22 15:24:38 +0000 |
commit | 67e2a42fea65f2685580b119b98a058c8e81ac4e (patch) | |
tree | 19bc7c578c9f1a47f299d012ac4775010e06661e /src/nautilus-window-toolbars.c | |
parent | 8dc115c33951754d75b57c67e4d918900a795468 (diff) | |
download | nautilus-67e2a42fea65f2685580b119b98a058c8e81ac4e.tar.gz |
Merge bonobo-slay-branch
2004-11-22 Alexander Larsson <alexl@redhat.com>
* Merge bonobo-slay-branch
Diffstat (limited to 'src/nautilus-window-toolbars.c')
-rw-r--r-- | src/nautilus-window-toolbars.c | 371 |
1 files changed, 64 insertions, 307 deletions
diff --git a/src/nautilus-window-toolbars.c b/src/nautilus-window-toolbars.c index a86142b81..083e7068e 100644 --- a/src/nautilus-window-toolbars.c +++ b/src/nautilus-window-toolbars.c @@ -33,12 +33,7 @@ #include "nautilus-window-manage-views.h" #include "nautilus-window-private.h" #include "nautilus-window.h" -#include <bonobo/bonobo-control.h> -#include <bonobo/bonobo-property-bag.h> -#include <bonobo/bonobo-property-bag-client.h> -#include <bonobo/bonobo-exception.h> -#include <bonobo/bonobo-moniker-util.h> -#include <bonobo/bonobo-ui-util.h> +#include "nautilus-throbber.h" #include <eel/eel-gnome-extensions.h> #include <eel/eel-gtk-extensions.h> #include <eel/eel-string.h> @@ -48,9 +43,9 @@ #include <libgnome/gnome-i18n.h> #include <libgnomeui/gnome-popup-menu.h> #include <libnautilus-extension/nautilus-menu-provider.h> -#include <libnautilus-private/nautilus-bonobo-extensions.h> #include <libnautilus-private/nautilus-bookmark.h> #include <libnautilus-private/nautilus-file-utilities.h> +#include <libnautilus-private/nautilus-ui-utilities.h> #include <libnautilus-private/nautilus-global-preferences.h> #include <libnautilus-private/nautilus-module.h> #include <libnautilus-private/nautilus-theme.h> @@ -63,239 +58,6 @@ #define TOOLBAR_PATH_EXTENSION_ACTIONS "/Toolbar/Extra Buttons Placeholder/Extension Actions" -enum { - TOOLBAR_ITEM_STYLE_PROP, - TOOLBAR_ITEM_ORIENTATION_PROP -}; - -static void -activate_back_or_forward_menu_item (GtkMenuItem *menu_item, - NautilusNavigationWindow *window, - gboolean back) -{ - int index; - - g_assert (GTK_IS_MENU_ITEM (menu_item)); - g_assert (NAUTILUS_IS_NAVIGATION_WINDOW (window)); - - index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "user_data")); - - nautilus_navigation_window_back_or_forward (window, back, index); -} - -static void -activate_back_menu_item_callback (GtkMenuItem *menu_item, NautilusNavigationWindow *window) -{ - activate_back_or_forward_menu_item (menu_item, window, TRUE); -} - -static void -activate_forward_menu_item_callback (GtkMenuItem *menu_item, NautilusNavigationWindow *window) -{ - activate_back_or_forward_menu_item (menu_item, window, FALSE); -} - -static GtkMenu * -create_back_or_forward_menu (NautilusNavigationWindow *window, gboolean back) -{ - GtkMenu *menu; - GtkWidget *menu_item; - GList *list_link; - int index; - - g_assert (NAUTILUS_IS_NAVIGATION_WINDOW (window)); - - menu = GTK_MENU (gtk_menu_new ()); - - list_link = back ? window->back_list : window->forward_list; - index = 0; - while (list_link != NULL) - { - menu_item = nautilus_bookmark_menu_item_new (NAUTILUS_BOOKMARK (list_link->data)); - g_object_set_data (G_OBJECT (menu_item), "user_data", GINT_TO_POINTER (index)); - gtk_widget_show (GTK_WIDGET (menu_item)); - g_signal_connect_object (menu_item, "activate", - back - ? G_CALLBACK (activate_back_menu_item_callback) - : G_CALLBACK (activate_forward_menu_item_callback), - window, 0); - - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); - list_link = g_list_next (list_link); - ++index; - } - - return menu; -} - -static GtkWidget * -get_back_button (NautilusNavigationWindow *window) -{ - return window->details->back_button_item; -} - -static GtkWidget * -get_forward_button (NautilusNavigationWindow *window) -{ - return window->details->forward_button_item; -} - -static void -menu_position_under_widget (GtkMenu *menu, int *x, int *y, - gboolean *push_in, gpointer user_data) -{ - GtkWidget *w; - int screen_width, screen_height; - GtkRequisition requisition; - - w = GTK_WIDGET (user_data); - - gdk_window_get_origin (w->window, x, y); - *x += w->allocation.x; - *y += w->allocation.y + w->allocation.height; - - gtk_widget_size_request (GTK_WIDGET (menu), &requisition); - - screen_width = gdk_screen_width (); - screen_height = gdk_screen_height (); - - *x = CLAMP (*x, 0, MAX (0, screen_width - requisition.width)); - *y = CLAMP (*y, 0, MAX (0, screen_height - requisition.height)); -} - -static gboolean -back_or_forward_button_pressed_callback (GtkWidget *widget, - GdkEventButton *event, - gpointer *user_data) -{ - NautilusNavigationWindow *window; - gboolean back; - - g_return_val_if_fail (GTK_IS_BUTTON (widget), FALSE); - g_return_val_if_fail (NAUTILUS_IS_NAVIGATION_WINDOW (user_data), FALSE); - - window = NAUTILUS_NAVIGATION_WINDOW (user_data); - - back = widget == get_back_button (window); - g_assert (back || widget == get_forward_button (window)); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE); - - gnome_popup_menu_do_popup_modal (GTK_WIDGET (create_back_or_forward_menu (NAUTILUS_NAVIGATION_WINDOW (user_data), back)), - menu_position_under_widget, widget, event, widget, widget); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE); - - return TRUE; -} - -static gboolean -back_or_forward_key_pressed_callback (GtkWidget *widget, - GdkEventKey *event, - gpointer *user_data) -{ - if (event->keyval == GDK_space || - event->keyval == GDK_KP_Space || - event->keyval == GDK_Return || - event->keyval == GDK_KP_Enter) { - back_or_forward_button_pressed_callback (widget, NULL, user_data); - } - - return FALSE; -} - -static GtkWidget * -create_back_or_forward_toolbar_item (NautilusNavigationWindow *window, - const char *tooltip, - const char *control_path) -{ - GtkWidget *button; - - button = gtk_toggle_button_new (); - - gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); - - gtk_container_add (GTK_CONTAINER (button), - gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT)); - - gtk_widget_show_all (GTK_WIDGET (button)); - - gtk_tooltips_set_tip (window->details->tooltips, - GTK_WIDGET (button), - tooltip, NULL); - - g_signal_connect_object (button, "key_press_event", - G_CALLBACK (back_or_forward_key_pressed_callback), - window, 0); - g_signal_connect_object (button, "button_press_event", - G_CALLBACK (back_or_forward_button_pressed_callback), - window, 0); - - bonobo_ui_component_widget_set (NAUTILUS_WINDOW (window)->details->shell_ui, - control_path, - button, - NULL); - - return button; -} - -static void -throbber_set_throbbing (NautilusNavigationWindow *window, - gboolean throbbing) -{ - CORBA_boolean b; - CORBA_any val; - - val._type = TC_CORBA_boolean; - val._value = &b; - b = throbbing; - - bonobo_pbclient_set_value_async ( - window->details->throbber_property_bag, - "throbbing", &val, NULL); -} - -static void -throbber_created_callback (Bonobo_Unknown throbber, - CORBA_Environment *ev, - gpointer user_data) -{ - char *exception_as_text; - NautilusNavigationWindow *window; - - if (BONOBO_EX (ev)) { - exception_as_text = bonobo_exception_get_text (ev); - g_warning ("Throbber activation exception '%s'", exception_as_text); - g_free (exception_as_text); - return; - } - - g_return_if_fail (NAUTILUS_IS_NAVIGATION_WINDOW (user_data)); - - window = NAUTILUS_NAVIGATION_WINDOW (user_data); - - window->details->throbber_activating = FALSE; - - bonobo_ui_component_object_set (NAUTILUS_WINDOW (window)->details->shell_ui, - "/Toolbar/ThrobberWrapper", - throbber, ev); - CORBA_exception_free (ev); - - window->details->throbber_property_bag = - Bonobo_Control_getProperties (throbber, ev); - - if (BONOBO_EX (ev)) { - window->details->throbber_property_bag = CORBA_OBJECT_NIL; - CORBA_exception_free (ev); - } else { - throbber_set_throbbing (window, window->details->throbber_active); - } - - bonobo_object_release_unref (throbber, ev); - - g_object_unref (window); -} - void nautilus_navigation_window_set_throbber_active (NautilusNavigationWindow *window, gboolean allow) @@ -305,81 +67,50 @@ nautilus_navigation_window_set_throbber_active (NautilusNavigationWindow *window return; } - if (allow) - access ("nautilus-throbber: start", 0); - else - access ("nautilus-throbber: stop", 0); - - nautilus_bonobo_set_sensitive (NAUTILUS_WINDOW (window)->details->shell_ui, - NAUTILUS_COMMAND_STOP, allow); - window->details->throbber_active = allow; - if (window->details->throbber_property_bag != CORBA_OBJECT_NIL) { - throbber_set_throbbing (window, allow); + if (allow) { + nautilus_throbber_start (NAUTILUS_THROBBER (window->details->throbber)); + } else { + nautilus_throbber_stop (NAUTILUS_THROBBER (window->details->throbber)); } } void nautilus_navigation_window_activate_throbber (NautilusNavigationWindow *window) { - CORBA_Environment ev; - char *exception_as_text; + GtkToolItem *item; + GtkWidget *throbber; - if (window->details->throbber_activating || - window->details->throbber_property_bag != CORBA_OBJECT_NIL) { + if (window->details->throbber != NULL) { return; } - /* FIXME bugzilla.gnome.org 41243: - * We should use inheritance instead of these special cases - * for the desktop window. - */ - if (!NAUTILUS_IS_DESKTOP_WINDOW (window)) { - CORBA_exception_init (&ev); - - g_object_ref (window); - bonobo_get_object_async ("OAFIID:Nautilus_Throbber", - "IDL:Bonobo/Control:1.0", - &ev, - throbber_created_callback, - window); - - if (BONOBO_EX (&ev)) { - exception_as_text = bonobo_exception_get_text (&ev); - g_warning ("Throbber activation exception '%s'", exception_as_text); - g_free (exception_as_text); - } - CORBA_exception_free (&ev); - window->details->throbber_activating = TRUE; - } + item = gtk_tool_item_new (); + gtk_widget_show (GTK_WIDGET (item)); + gtk_tool_item_set_expand (item, TRUE); + gtk_toolbar_insert (GTK_TOOLBAR (window->details->toolbar), + item, -1); + + throbber = nautilus_throbber_new (); + gtk_widget_show (GTK_WIDGET (throbber)); + + item = gtk_tool_item_new (); + gtk_container_add (GTK_CONTAINER (item), throbber); + gtk_widget_show (GTK_WIDGET (item)); + + gtk_toolbar_insert (GTK_TOOLBAR (window->details->toolbar), + item, -1); + + window->details->throbber = throbber; } void nautilus_navigation_window_initialize_toolbars (NautilusNavigationWindow *window) { - GtkWidget *space; - - nautilus_window_ui_freeze (NAUTILUS_WINDOW (window)); - nautilus_navigation_window_activate_throbber (window); - - window->details->back_button_item = create_back_or_forward_toolbar_item - (window, _("Go back a few pages"), - "/Toolbar/BackMenu"); - window->details->forward_button_item = create_back_or_forward_toolbar_item - (window, _("Go forward a number of pages"), - "/Toolbar/ForwardMenu"); - - space = gtk_event_box_new (); - gtk_event_box_set_visible_window (GTK_EVENT_BOX (space), FALSE); - bonobo_ui_component_widget_set (NAUTILUS_WINDOW (window)->details->shell_ui, - "/Toolbar/SpaceWrapper", - space, - NULL); - - nautilus_window_ui_thaw (NAUTILUS_WINDOW (window)); } + static GList * get_extension_toolbar_items (NautilusNavigationWindow *window) { @@ -410,27 +141,53 @@ get_extension_toolbar_items (NautilusNavigationWindow *window) void nautilus_navigation_window_load_extension_toolbar_items (NautilusNavigationWindow *window) { + GtkActionGroup *action_group; + GtkAction *action; + GtkUIManager *ui_manager; GList *items; GList *l; + NautilusMenuItem *item; + guint merge_id; + + ui_manager = nautilus_window_get_ui_manager (NAUTILUS_WINDOW (window)); + if (window->details->extensions_toolbar_merge_id != 0) { + gtk_ui_manager_remove_ui (ui_manager, + window->details->extensions_toolbar_merge_id); + window->details->extensions_toolbar_merge_id = 0; + } + + if (window->details->extensions_toolbar_action_group != NULL) { + gtk_ui_manager_remove_action_group (ui_manager, + window->details->extensions_toolbar_action_group); + window->details->extensions_toolbar_action_group = NULL; + } - nautilus_bonobo_remove_menu_items_and_commands - (NAUTILUS_WINDOW (window)->details->shell_ui, - TOOLBAR_PATH_EXTENSION_ACTIONS); + merge_id = gtk_ui_manager_new_merge_id (ui_manager); + window->details->extensions_toolbar_merge_id = merge_id; + action_group = gtk_action_group_new ("ExtensionsMenuGroup"); + window->details->extensions_toolbar_action_group = action_group; + gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE); + gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); + g_object_unref (action_group); /* owned by ui manager */ items = get_extension_toolbar_items (window); for (l = items; l != NULL; l = l->next) { - NautilusMenuItem *item; - item = NAUTILUS_MENU_ITEM (l->data); - nautilus_bonobo_add_extension_item_command - (NAUTILUS_WINDOW (window)->details->shell_ui, item); + action = nautilus_toolbar_action_from_menu_item (item); + + gtk_action_group_add_action (action_group, + GTK_ACTION (action)); + g_object_unref (action); - nautilus_bonobo_add_extension_toolbar_item - (NAUTILUS_WINDOW (window)->details->shell_ui, - TOOLBAR_PATH_EXTENSION_ACTIONS, - item); + gtk_ui_manager_add_ui (ui_manager, + merge_id, + TOOLBAR_PATH_EXTENSION_ACTIONS, + gtk_action_get_name (action), + gtk_action_get_name (action), + GTK_UI_MANAGER_TOOLITEM, + FALSE); g_object_unref (item); } |