On Fri, 2004-07-23 at 10:08 +0200, laurent belmonte wrote: > Hi all, > > I have extracted the pathbar part of the mega-patch from Jamie > McCracken. > > > laurentB. > http://home.gna.org/monkeybubble > A new version of the patch with a screenshot.
Attachment:
Screenshot.png
Description: PNG image
Index: nautilus-spatial-window-ui.xml =================================================================== RCS file: /cvs/gnome/nautilus/src/nautilus-spatial-window-ui.xml,v retrieving revision 1.11 diff -u -r1.11 nautilus-spatial-window-ui.xml --- nautilus-spatial-window-ui.xml 1 Jun 2004 09:21:35 -0000 1.11 +++ nautilus-spatial-window-ui.xml 23 Jul 2004 14:13:59 -0000 @@ -65,4 +65,9 @@ </submenu> </menu> +<dockitem name="Path Bar" behavior="exclusive,never vertical"> + <control name="Wrapper" behavior="expandable"/> +</dockitem> + + </Root> Index: nautilus-spatial-window.c =================================================================== RCS file: /cvs/gnome/nautilus/src/nautilus-spatial-window.c,v retrieving revision 1.433 diff -u -r1.433 nautilus-spatial-window.c --- nautilus-spatial-window.c 21 Jun 2004 18:33:43 -0000 1.433 +++ nautilus-spatial-window.c 23 Jul 2004 14:14:00 -0000 @@ -89,10 +89,9 @@ guint save_geometry_timeout_id; GtkWidget *content_box; - GtkWidget *location_button; - GtkWidget *location_label; GtkWidget *location_statusbar; + GtkWidget *pathbar_box; GnomeVFSURI *location; }; @@ -372,6 +371,20 @@ "/status/StatusButton", BONOBO_OBJREF (control), NULL); + + /* Wrap the location bar in a control and set it up. */ + control = bonobo_control_new (window->details->pathbar_box); + bonobo_ui_component_object_set (NAUTILUS_WINDOW (window)->details->shell_ui, + "/Path Bar/Wrapper", + BONOBO_OBJREF (control), + NULL); + + // bonobo_object_unref (control); + + nautilus_bonobo_add_menu_separator + (NAUTILUS_WINDOW (window)->details->shell_ui, "/menu/Places/Places Placeholder"); + + } static void @@ -430,161 +443,137 @@ } } - static void -location_menu_item_activated_callback (GtkWidget *menu_item, - NautilusSpatialWindow *window) +pathbar_button_clicked_callback (GtkWidget *button, + GdkEventButton *event, + NautilusSpatialWindow *window) { GnomeVFSURI *uri; char *location; - GdkEvent *event; - uri = g_object_get_data (G_OBJECT (menu_item), "uri"); - location = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE); - event = gtk_get_current_event(); + if (GTK_IS_TOGGLE_BUTTON (button)) { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button) , TRUE); + } + uri = g_object_get_data (G_OBJECT (button), "uri"); + location = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE); + if (!gnome_vfs_uri_equal (uri, window->details->location)) { - if (event != NULL && ((GdkEventAny *) event)->type == GDK_BUTTON_RELEASE && - (((GdkEventButton *) event)->button == 2 || - (((GdkEventButton *) event)->state & GDK_SHIFT_MASK) != 0)) + if (event != NULL && event->type == GDK_BUTTON_PRESS && + (event->button == 2 || + (event->state & GDK_SHIFT_MASK) != 0)) { nautilus_window_open_location (NAUTILUS_WINDOW (window), location, TRUE); } else { - nautilus_window_open_location (NAUTILUS_WINDOW (window), location, FALSE); + nautilus_window_open_location (NAUTILUS_WINDOW (window), location,FALSE); } - } - - if (event != NULL) { - gdk_event_free (event); - } - g_free (location); } static void -menu_deactivate_callback (GtkWidget *menu, - gpointer data) +nautilus_spatial_window_set_pathbar (NautilusSpatialWindow *window, const char *location) { - GMainLoop *loop; - - loop = data; - - if (g_main_loop_is_running (loop)) { - g_main_loop_quit (loop); + GnomeVFSURI *uri; + char *name, *uri_location; + GtkWidget *button, *hbox, *label, *image; + GtkRcStyle *rc_style; + gboolean use_toggle_button, use_home_shortcut; + + uri = NULL; + if (location != NULL) { + uri = gnome_vfs_uri_new (location); + } -} - -static void -menu_popup_pos (GtkMenu *menu, - gint *x, - gint *y, - gboolean *push_in, - gpointer user_data) -{ - GtkWidget *widget; - GtkRequisition menu_requisition, button_requisition; - widget = user_data; - gtk_widget_size_request (GTK_WIDGET (menu), &menu_requisition); - gtk_widget_size_request (widget, &button_requisition); + + /* deallocate existing pathbar */ + gtk_container_foreach (GTK_CONTAINER (window->details->pathbar_box), + (GtkCallback) gtk_widget_destroy, + NULL); - gdk_window_get_origin (widget->window, x, y); + /* use a toggle button for the current folder only */ + use_toggle_button = TRUE; + while (uri != NULL) { - *y -= menu_requisition.height - button_requisition.height; + + uri_location = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD); - *push_in = TRUE; -} - -static void -location_button_clicked_callback (GtkWidget *widget, NautilusSpatialWindow *window) -{ - GtkWidget *popup, *menu_item, *first_item; - GnomeVFSURI *uri; - char *name; - GMainLoop *loop; + use_home_shortcut = (strcmp (uri_location, g_get_home_dir ()) == 0); + g_free (uri_location); + if (use_home_shortcut) { + name = g_strdup("Home"); + } else { + name = g_strconcat (" ", nautilus_get_uri_shortname_for_display (uri), NULL); + } - g_return_if_fail (window->details->location != NULL); + if (use_toggle_button) { + button = gtk_toggle_button_new (); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button) , TRUE); + use_toggle_button = FALSE; + } else { + button = gtk_button_new (); + } - popup = gtk_menu_new (); - first_item = NULL; - uri = gnome_vfs_uri_ref (window->details->location); - while (uri != NULL) { - name = nautilus_get_uri_shortname_for_display (uri); - menu_item = gtk_image_menu_item_new_with_label (name); - if (first_item == NULL) { - first_item = menu_item; + rc_style = gtk_widget_get_modifier_style (button); + rc_style->xthickness = 0; + rc_style->ythickness = 0; + gtk_widget_modify_style (button, rc_style); + gtk_widget_show (button); + + hbox = gtk_hbox_new (FALSE, 1); + gtk_container_add (GTK_CONTAINER (button), hbox); + gtk_widget_show (hbox); + + if (use_home_shortcut) { + image = gtk_image_new_from_stock (GTK_STOCK_HOME, GTK_ICON_SIZE_MENU); + gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); + gtk_widget_show (image); } + + label = gtk_label_new (name); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + gtk_box_pack_end (GTK_BOX (window->details->pathbar_box), button, TRUE, TRUE, 0); + + g_free (name); - gtk_widget_show (menu_item); - g_signal_connect (menu_item, "activate", - G_CALLBACK (location_menu_item_activated_callback), + + g_object_set_data_full (G_OBJECT (button), "uri", uri, (GDestroyNotify)gnome_vfs_uri_unref); + g_signal_connect (button, + "button_press_event", + G_CALLBACK (pathbar_button_clicked_callback), window); - g_object_set_data_full (G_OBJECT (menu_item), "uri", uri, (GDestroyNotify)gnome_vfs_uri_unref); - - gtk_menu_shell_prepend (GTK_MENU_SHELL (popup), menu_item); + + /* don't create anymore buttons if we use the home shortcut */ + if (use_home_shortcut) { + return; + } uri = gnome_vfs_uri_get_parent (uri); - } - gtk_menu_set_screen (GTK_MENU (popup), gtk_widget_get_screen (widget)); - loop = g_main_loop_new (NULL, FALSE); - - g_signal_connect (popup, "deactivate", - G_CALLBACK (menu_deactivate_callback), - loop); - - gtk_grab_add (popup); - gtk_menu_popup (GTK_MENU (popup), NULL, NULL, menu_popup_pos, widget, 1, GDK_CURRENT_TIME); - gtk_menu_shell_select_item (GTK_MENU_SHELL (popup), first_item); - g_main_loop_run (loop); - gtk_grab_remove (popup); - g_main_loop_unref (loop); - gtk_object_sink (GTK_OBJECT (popup)); + } } void nautilus_spatial_window_set_location_button (NautilusSpatialWindow *window, const char *location) { - GnomeVFSURI *uri; - char *name; - uri = NULL; - if (location != NULL) { - uri = gnome_vfs_uri_new (location); - } - if (uri != NULL) { - name = nautilus_get_uri_shortname_for_display (uri); - gtk_label_set_label (GTK_LABEL (window->details->location_label), - name); - g_free (name); - gtk_widget_set_sensitive (window->details->location_button, TRUE); - } else { - gtk_label_set_label (GTK_LABEL (window->details->location_label), - ""); - gtk_widget_set_sensitive (window->details->location_button, FALSE); - } - - if (window->details->location != NULL) { - gnome_vfs_uri_unref (window->details->location); - } - window->details->location = uri; + nautilus_spatial_window_set_pathbar(window,location); } + static void nautilus_spatial_window_instance_init (NautilusSpatialWindow *window) { GtkShadowType shadow_type; GtkWidget *frame; - GtkRcStyle *rc_style; - GtkWidget *arrow; - GtkWidget *hbox; window->details = g_new0 (NautilusSpatialWindowDetails, 1); window->affect_spatial_window_on_next_location_change = TRUE; @@ -601,30 +590,6 @@ gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (window->details->location_statusbar), FALSE); - window->details->location_button = gtk_button_new (); - gtk_button_set_relief (GTK_BUTTON (window->details->location_button), - GTK_RELIEF_NONE); - rc_style = gtk_widget_get_modifier_style (window->details->location_button); - rc_style->xthickness = 0; - rc_style->ythickness = 0; - gtk_widget_modify_style (window->details->location_button, - rc_style); - - gtk_widget_show (window->details->location_button); - - hbox = gtk_hbox_new (FALSE, 3); - gtk_container_add (GTK_CONTAINER (window->details->location_button), - hbox); - gtk_widget_show (hbox); - - window->details->location_label = gtk_label_new (""); - gtk_box_pack_start (GTK_BOX (hbox), window->details->location_label, - FALSE, FALSE, 0); - gtk_widget_show (window->details->location_label); - - arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (hbox), arrow, FALSE, FALSE, 0); - gtk_widget_show (arrow); frame = gtk_frame_new (NULL); gtk_widget_style_get (GTK_WIDGET (window->details->location_statusbar), @@ -634,14 +599,17 @@ frame, TRUE, TRUE, 0); gtk_widget_show (frame); - gtk_container_add (GTK_CONTAINER (frame), - window->details->location_button); + window->details->pathbar_box = gtk_hbox_new (FALSE, 1); + gtk_widget_show (window->details->pathbar_box); + + /* gtk_container_add (GTK_CONTAINER (frame), + window->details->pathbar_box);*/ - gtk_widget_set_sensitive (window->details->location_button, FALSE); - g_signal_connect (window->details->location_button, - "clicked", - G_CALLBACK (location_button_clicked_callback), window); gtk_widget_show (window->details->location_statusbar); + + + + } static void