Author: benny Date: 2006-08-29 15:53:32 +0000 (Tue, 29 Aug 2006) New Revision: 22936
Modified: thunar/trunk/ChangeLog thunar/trunk/thunar/thunar-chooser-button.c thunar/trunk/thunar/thunar-chooser-dialog.c thunar/trunk/thunar/thunar-file.c thunar/trunk/thunar/thunar-file.h thunar/trunk/thunar/thunar-gtk-extensions.c thunar/trunk/thunar/thunar-gtk-extensions.h thunar/trunk/thunar/thunar-location-button.c thunar/trunk/thunar/thunar-location-buttons.c thunar/trunk/thunar/thunar-renamer-dialog.c thunar/trunk/thunar/thunar-shortcuts-model.c thunar/trunk/thunar/thunar-shortcuts-view.c thunar/trunk/thunar/thunar-standard-view.c thunar/trunk/thunar/thunar-tree-view.c Log: 2006-08-29 Benedikt Meurer <[EMAIL PROTECTED]> * thunar/thunar-file.{c,h}, thunar/thunar-location-button.c, thunar/thunar-shortcuts-model.c: Add desktop shortcut to the shortcuts pane, and use a special icon for the desktop folder. Bug #2235. * thunar/thunar-chooser-button.c, thunar/thunar-chooser-dialog.c, thunar/thunar-gtk-extensions.{c,h}, thunar/thunar-location-buttons.c, thunar/thunar-renamer-dialog.c, thunar/thunar-shortcuts-view.c, thunar/thunar-standard-view.c, thunar/thunar-tree-view.c: Add helper method thunar_gtk_menu_run(), which takes care of running a GtkMenu in a separate main loop, placing the menu on the appropriate screen first. Modified: thunar/trunk/ChangeLog =================================================================== --- thunar/trunk/ChangeLog 2006-08-29 15:26:59 UTC (rev 22935) +++ thunar/trunk/ChangeLog 2006-08-29 15:53:32 UTC (rev 22936) @@ -1,5 +1,19 @@ 2006-08-29 Benedikt Meurer <[EMAIL PROTECTED]> + * thunar/thunar-file.{c,h}, thunar/thunar-location-button.c, + thunar/thunar-shortcuts-model.c: Add desktop shortcut to the + shortcuts pane, and use a special icon for the desktop folder. + Bug #2235. + * thunar/thunar-chooser-button.c, thunar/thunar-chooser-dialog.c, + thunar/thunar-gtk-extensions.{c,h}, thunar/thunar-location-buttons.c, + thunar/thunar-renamer-dialog.c, thunar/thunar-shortcuts-view.c, + thunar/thunar-standard-view.c, thunar/thunar-tree-view.c: Add helper + method thunar_gtk_menu_run(), which takes care of running a GtkMenu + in a separate main loop, placing the menu on the appropriate screen + first. + +2006-08-29 Benedikt Meurer <[EMAIL PROTECTED]> + * docs/README.gtkrc, docs/README.thunarrc, thunar/: Revert location bar related changes to the previous user interface, because the new user interface wastes too much space, and makes the file manager look busy. Modified: thunar/trunk/thunar/thunar-chooser-button.c =================================================================== --- thunar/trunk/thunar/thunar-chooser-button.c 2006-08-29 15:26:59 UTC (rev 22935) +++ thunar/trunk/thunar/thunar-chooser-button.c 2006-08-29 15:53:32 UTC (rev 22936) @@ -421,7 +421,6 @@ GtkIconTheme *icon_theme; const gchar *icon_name; GdkPixbuf *icon; - GMainLoop *loop; GtkWidget *image; GtkWidget *item; GtkWidget *menu; @@ -463,8 +462,6 @@ /* allocate a new popup menu */ menu = gtk_menu_new (); - exo_gtk_object_ref_sink (GTK_OBJECT (menu)); - gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (button)); /* determine the icon size for menus */ gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_size, &icon_size); @@ -492,6 +489,9 @@ g_object_unref (icon); } + /* cleanup */ + g_object_unref (G_OBJECT (icon_factory)); + /* append a separator */ item = gtk_separator_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); @@ -506,25 +506,13 @@ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); - /* allocate a new loop and connect it to the menu */ - loop = g_main_loop_new (NULL, FALSE); - g_signal_connect_swapped (G_OBJECT (menu), "deactivate", G_CALLBACK (g_main_loop_quit), loop); - /* make sure the menu has atleast the same width as the chooser */ if (menu->allocation.width < button->allocation.width) gtk_widget_set_size_request (menu, button->allocation.width, -1); - /* run the menu */ - gtk_grab_add (menu); - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, menu_position, button, 0, gtk_get_current_event_time ()); - g_main_loop_run (loop); - gtk_grab_remove (menu); - g_main_loop_unref (loop); + /* run the menu on the button's screen (takes over the floating reference of menu) */ + thunar_gtk_menu_run (GTK_MENU (menu), button, menu_position, button, 0, gtk_get_current_event_time ()); - /* cleanup */ - g_object_unref (G_OBJECT (icon_factory)); - g_object_unref (G_OBJECT (menu)); - /* yeppa, that's a requirement */ gtk_button_released (GTK_BUTTON (button)); } Modified: thunar/trunk/thunar/thunar-chooser-dialog.c =================================================================== --- thunar/trunk/thunar/thunar-chooser-dialog.c 2006-08-29 15:26:59 UTC (rev 22935) +++ thunar/trunk/thunar/thunar-chooser-dialog.c 2006-08-29 15:53:32 UTC (rev 22936) @@ -577,7 +577,6 @@ GtkWidget *image; GtkWidget *item; GtkWidget *menu; - GMainLoop *loop; _thunar_return_val_if_fail (THUNAR_IS_CHOOSER_DIALOG (dialog), FALSE); @@ -591,14 +590,8 @@ if (G_UNLIKELY (mime_application == NULL)) return FALSE; - /* prepare the internal loop */ - loop = g_main_loop_new (NULL, FALSE); - /* prepare the popup menu */ menu = gtk_menu_new (); - gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (GTK_WIDGET (dialog))); - g_signal_connect_swapped (G_OBJECT (menu), "deactivate", G_CALLBACK (g_main_loop_quit), loop); - exo_gtk_object_ref_sink (GTK_OBJECT (menu)); /* append the "Remove Launcher" item */ item = gtk_image_menu_item_new_with_mnemonic (_("_Remove Launcher")); @@ -611,16 +604,11 @@ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); gtk_widget_show (image); - /* run the internal loop */ - gtk_grab_add (menu); - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, button, time); - g_main_loop_run (loop); - gtk_grab_remove (menu); + /* run the menu on the dialog's screen (takes over the floating of menu) */ + thunar_gtk_menu_run (GTK_MENU (menu), GTK_WIDGET (dialog), NULL, NULL, button, time); /* clean up */ g_object_unref (G_OBJECT (mime_application)); - g_object_unref (G_OBJECT (menu)); - g_main_loop_unref (loop); return TRUE; } Modified: thunar/trunk/thunar/thunar-file.c =================================================================== --- thunar/trunk/thunar/thunar-file.c 2006-08-29 15:26:59 UTC (rev 22935) +++ thunar/trunk/thunar/thunar-file.c 2006-08-29 15:53:32 UTC (rev 22936) @@ -1482,7 +1482,6 @@ thunar_file_get_emblem_names (ThunarFile *file) { const ThunarVfsInfo *info = file->info; - const ThunarVfsPath *parent; const gchar *emblem_string; gchar **emblem_names; GList *emblems = NULL; @@ -1510,13 +1509,6 @@ emblems = g_list_append (emblems, *emblem_names); } - if (G_UNLIKELY (strcmp (info->display_name, "Desktop") == 0)) - { - parent = thunar_vfs_path_get_parent (info->path); - if (G_LIKELY (parent != NULL) && thunar_vfs_path_is_home (parent)) - emblems = g_list_prepend (emblems, THUNAR_FILE_EMBLEM_NAME_DESKTOP); - } - if ((info->flags & THUNAR_VFS_FILE_FLAGS_SYMLINK) != 0) emblems = g_list_prepend (emblems, THUNAR_FILE_EMBLEM_NAME_SYMBOLIC_LINK); @@ -1624,6 +1616,13 @@ return "gnome-fs-home"; } + /* special icon for the desktop node */ + if (G_UNLIKELY (thunar_file_is_desktop (file)) + && gtk_icon_theme_has_icon (icon_theme, "gnome-fs-desktop")) + { + return "gnome-fs-desktop"; + } + /* try to be smart when determining icons for executable files * in that we use the name of the file as icon name (which will * work for quite a lot of binaries, e.g. 'Terminal', 'mousepad', Modified: thunar/trunk/thunar/thunar-file.h =================================================================== --- thunar/trunk/thunar/thunar-file.h 2006-08-29 15:26:59 UTC (rev 22935) +++ thunar/trunk/thunar/thunar-file.h 2006-08-29 15:53:32 UTC (rev 22936) @@ -443,6 +443,18 @@ #define thunar_file_is_home(file) (thunar_vfs_path_is_home (THUNAR_FILE ((file))->info->path)) /** + * thunar_file_is_desktop: + * @file : a #ThunarFile. + * + * Checks whether @file refers to the users desktop directory. + * + * Return value: %TRUE if @file is the users desktop directory. + **/ +#define thunar_file_is_desktop(file) (!thunar_vfs_path_is_root (thunar_file_get_path (file)) \ + && thunar_vfs_path_is_home (thunar_vfs_path_get_parent (thunar_file_get_path (file))) \ + && exo_str_is_equal (thunar_file_get_display_name (file), "Desktop")) + +/** * thunar_file_is_regular: * @file : a #ThunarFile. * Modified: thunar/trunk/thunar/thunar-gtk-extensions.c =================================================================== --- thunar/trunk/thunar/thunar-gtk-extensions.c 2006-08-29 15:26:59 UTC (rev 22935) +++ thunar/trunk/thunar/thunar-gtk-extensions.c 2006-08-29 15:53:32 UTC (rev 22936) @@ -25,6 +25,8 @@ #include <stdarg.h> #endif +#include <exo/exo.h> + #include <thunar/thunar-gtk-extensions.h> #include <thunar/thunar-private.h> @@ -134,6 +136,63 @@ /** + * thunar_gtk_menu_run: + * @menu : a #GtkMenu. + * @parent : either a #GtkWidget or a #GdkScreen which determines the screen + * on which to run the @menu. May also be %NULL, which means that + * the screen of @menu will not be altered. + * @func : a user supplied function used to position the menu, or %NULL. + * @data : user supplied data to be passed to @func. + * @button : the mouse button which was pressed to initiate the event. + * @activate_time : the time at which the activation event occurred. + * + * A simple wrapper around gtk_menu_popup(), which runs the @menu in a separate + * main loop and returns only after the @menu was deactivated. + * + * This method automatically takes over the floating reference of @menu if any and + * releases it on return. That means if you created the menu via gtk_menu_new() you'll + * not need to take care of destroying the menu later. + **/ +void +thunar_gtk_menu_run (GtkMenu *menu, + gpointer parent, + GtkMenuPositionFunc func, + gpointer data, + guint button, + guint32 activate_time) +{ + GMainLoop *loop; + guint signal_id; + + _thunar_return_if_fail (parent == NULL || GDK_IS_SCREEN (parent) || GTK_IS_WIDGET (parent)); + _thunar_return_if_fail (GTK_IS_MENU (menu)); + + /* take over the floating reference on the menu */ + exo_gtk_object_ref_sink (GTK_OBJECT (menu)); + + /* place the menu on the same screen as the parent */ + if (G_UNLIKELY (parent != NULL && GDK_IS_SCREEN (parent))) + gtk_menu_set_screen (menu, GDK_SCREEN (parent)); + else if (G_LIKELY (parent != NULL && GTK_IS_WIDGET (parent))) + gtk_menu_set_screen (menu, gtk_widget_get_screen (GTK_WIDGET (parent))); + + /* run an internal main loop */ + gtk_grab_add (GTK_WIDGET (menu)); + loop = g_main_loop_new (NULL, FALSE); + signal_id = g_signal_connect_swapped (G_OBJECT (menu), "deactivate", G_CALLBACK (g_main_loop_quit), loop); + gtk_menu_popup (menu, NULL, NULL, func, data, button, activate_time); + g_main_loop_run (loop); + g_signal_handler_disconnect (G_OBJECT (menu), signal_id); + g_main_loop_unref (loop); + gtk_grab_remove (GTK_WIDGET (menu)); + + /* release the menu reference */ + g_object_unref (G_OBJECT (menu)); +} + + + +/** * thunar_gtk_ui_manager_get_action_by_name: * @ui_manager : a #GtkUIManager. * @action_name : the name of a #GtkAction in @ui_manager. Modified: thunar/trunk/thunar/thunar-gtk-extensions.h =================================================================== --- thunar/trunk/thunar/thunar-gtk-extensions.h 2006-08-29 15:26:59 UTC (rev 22935) +++ thunar/trunk/thunar/thunar-gtk-extensions.h 2006-08-29 15:53:32 UTC (rev 22936) @@ -24,23 +24,30 @@ G_BEGIN_DECLS; -void thunar_gtk_action_set_tooltip (GtkAction *action, - const gchar *format, +void thunar_gtk_action_set_tooltip (GtkAction *action, + const gchar *format, ...) G_GNUC_INTERNAL G_GNUC_PRINTF (2, 3); -void thunar_gtk_action_group_set_action_sensitive (GtkActionGroup *action_group, - const gchar *action_name, - gboolean sensitive) G_GNUC_INTERNAL; +void thunar_gtk_action_group_set_action_sensitive (GtkActionGroup *action_group, + const gchar *action_name, + gboolean sensitive) G_GNUC_INTERNAL; -void thunar_gtk_icon_factory_insert_icon (GtkIconFactory *icon_factory, - const gchar *stock_id, - const gchar *icon_name) G_GNUC_INTERNAL; +void thunar_gtk_icon_factory_insert_icon (GtkIconFactory *icon_factory, + const gchar *stock_id, + const gchar *icon_name) G_GNUC_INTERNAL; -GtkAction *thunar_gtk_ui_manager_get_action_by_name (GtkUIManager *ui_manager, - const gchar *action_name) G_GNUC_INTERNAL; +void thunar_gtk_menu_run (GtkMenu *menu, + gpointer parent, + GtkMenuPositionFunc func, + gpointer data, + guint button, + guint32 activate_time) G_GNUC_INTERNAL; -void thunar_gtk_widget_set_tooltip (GtkWidget *widget, - const gchar *format, +GtkAction *thunar_gtk_ui_manager_get_action_by_name (GtkUIManager *ui_manager, + const gchar *action_name) G_GNUC_INTERNAL; + +void thunar_gtk_widget_set_tooltip (GtkWidget *widget, + const gchar *format, ...) G_GNUC_INTERNAL G_GNUC_PRINTF (2, 3); G_END_DECLS; Modified: thunar/trunk/thunar/thunar-location-button.c =================================================================== --- thunar/trunk/thunar/thunar-location-button.c 2006-08-29 15:26:59 UTC (rev 22935) +++ thunar/trunk/thunar/thunar-location-button.c 2006-08-29 15:53:32 UTC (rev 22936) @@ -465,7 +465,7 @@ } /* the image is only visible for certain special paths */ - if (thunar_file_is_home (file) || thunar_file_is_root (file)) + if (thunar_file_is_home (file) || thunar_file_is_desktop (file) || thunar_file_is_root (file)) { /* determine the icon size for menus (to be compatible with GtkPathBar) */ settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (location_button))); Modified: thunar/trunk/thunar/thunar-location-buttons.c =================================================================== --- thunar/trunk/thunar/thunar-location-buttons.c 2006-08-29 15:26:59 UTC (rev 22935) +++ thunar/trunk/thunar/thunar-location-buttons.c 2006-08-29 15:53:32 UTC (rev 22936) @@ -1224,9 +1224,7 @@ const gchar *display_name; ThunarFile *file; GtkAction *action; - GMainLoop *loop; GtkWidget *menu; - guint signal_id; _thunar_return_if_fail (THUNAR_IS_LOCATION_BUTTONS (buttons)); _thunar_return_if_fail (THUNAR_IS_LOCATION_BUTTON (button)); @@ -1281,25 +1279,13 @@ thunar_gtk_action_set_tooltip (action, _("View the properties of the folder \"%s\""), display_name); g_object_set_data_full (G_OBJECT (action), I_("thunar-file"), g_object_ref (G_OBJECT (file)), (GDestroyNotify) g_object_unref); - /* determine the menu widget */ + /* run the menu on the screen on the buttons' screen */ menu = gtk_ui_manager_get_widget (buttons->ui_manager, "/location-buttons-context-menu"); - gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (GTK_WIDGET (buttons))); - exo_gtk_object_ref_sink (GTK_OBJECT (menu)); + thunar_gtk_menu_run (GTK_MENU (menu), GTK_WIDGET (buttons), NULL, NULL, event->button, event->time); - /* run an internal main loop */ - gtk_grab_add (menu); - loop = g_main_loop_new (NULL, FALSE); - signal_id = g_signal_connect_swapped (G_OBJECT (menu), "deactivate", G_CALLBACK (g_main_loop_quit), loop); - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, event->button, event->time); - g_main_loop_run (loop); - g_signal_handler_disconnect (G_OBJECT (menu), signal_id); - g_main_loop_unref (loop); - gtk_grab_remove (menu); - /* cleanup */ g_object_unref (G_OBJECT (buttons)); g_object_unref (G_OBJECT (clipboard)); - g_object_unref (G_OBJECT (menu)); } } } Modified: thunar/trunk/thunar/thunar-renamer-dialog.c =================================================================== --- thunar/trunk/thunar/thunar-renamer-dialog.c 2006-08-29 15:26:59 UTC (rev 22935) +++ thunar/trunk/thunar/thunar-renamer-dialog.c 2006-08-29 15:53:32 UTC (rev 22936) @@ -852,11 +852,9 @@ { GtkActionGroup *renamer_actions = NULL; ThunarxRenamer *renamer; - GMainLoop *loop; GtkWidget *menu; GList *actions = NULL; GList *lp; - guint id; gint renamer_merge_id = 0; _thunar_return_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog)); @@ -904,27 +902,10 @@ g_list_free (actions); } - /* determine the menu and take a reference */ + /* run the menu on the dialog's screen */ menu = gtk_ui_manager_get_widget (renamer_dialog->ui_manager, "/file-context-menu"); - exo_gtk_object_ref_sink (GTK_OBJECT (menu)); + thunar_gtk_menu_run (GTK_MENU (menu), GTK_WIDGET (renamer_dialog), NULL, NULL, button, time); - /* setup the main loop and connect it to the menu */ - loop = g_main_loop_new (NULL, FALSE); - id = g_signal_connect_swapped (G_OBJECT (menu), "deactivate", G_CALLBACK (g_main_loop_quit), loop); - - /* make sure the menu is on the proper screen */ - gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (GTK_WIDGET (renamer_dialog))); - - /* run our custom main loop */ - gtk_grab_add (menu); - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, button, time); - g_main_loop_run (loop); - g_main_loop_unref (loop); - gtk_grab_remove (menu); - - /* unlink the deactivate callback */ - g_signal_handler_disconnect (G_OBJECT (menu), id); - /* remove the previously merge items from the UI manager */ if (G_UNLIKELY (renamer_merge_id != 0)) { @@ -941,9 +922,6 @@ /* release the additional reference on the dialog */ g_object_unref (G_OBJECT (renamer_dialog)); - - /* decrease the reference count on the menu */ - g_object_unref (G_OBJECT (menu)); } Modified: thunar/trunk/thunar/thunar-shortcuts-model.c =================================================================== --- thunar/trunk/thunar/thunar-shortcuts-model.c 2006-08-29 15:26:59 UTC (rev 22935) +++ thunar/trunk/thunar/thunar-shortcuts-model.c 2006-08-29 15:53:32 UTC (rev 22936) @@ -248,7 +248,7 @@ { ThunarVfsVolume *volume; ThunarShortcut *shortcut; - ThunarVfsPath *system_path_list[3] = { thunar_vfs_path_get_for_home (), thunar_vfs_path_get_for_trash (), thunar_vfs_path_get_for_root () }; + ThunarVfsPath *system_path_list[4]; ThunarVfsPath *fhome; ThunarVfsPath *fpath; GtkTreePath *path; @@ -264,6 +264,12 @@ g_signal_connect (G_OBJECT (model->volume_manager), "volumes-added", G_CALLBACK (thunar_shortcuts_model_volumes_added), model); g_signal_connect (G_OBJECT (model->volume_manager), "volumes-removed", G_CALLBACK (thunar_shortcuts_model_volumes_removed), model); + /* determine the system-defined paths */ + system_path_list[0] = thunar_vfs_path_get_for_home (); + system_path_list[1] = thunar_vfs_path_get_for_trash (); + system_path_list[2] = thunar_vfs_path_relative (system_path_list[0], "Desktop"); + system_path_list[3] = thunar_vfs_path_get_for_root (); + /* will be used to append the shortcuts to the list */ path = gtk_tree_path_new_from_indices (0, -1); Modified: thunar/trunk/thunar/thunar-shortcuts-view.c =================================================================== --- thunar/trunk/thunar/thunar-shortcuts-view.c 2006-08-29 15:26:59 UTC (rev 22935) +++ thunar/trunk/thunar/thunar-shortcuts-view.c 2006-08-29 15:53:32 UTC (rev 22936) @@ -27,6 +27,7 @@ #include <thunar/thunar-application.h> #include <thunar/thunar-dialogs.h> #include <thunar/thunar-dnd.h> +#include <thunar/thunar-gtk-extensions.h> #include <thunar/thunar-preferences.h> #include <thunar/thunar-private.h> #include <thunar/thunar-shortcuts-icon-renderer.h> @@ -768,7 +769,6 @@ GtkWidget *image; GtkWidget *menu; GtkWidget *item; - GMainLoop *loop; gboolean mutable; /* determine the tree path for the given iter */ @@ -783,14 +783,8 @@ THUNAR_SHORTCUTS_MODEL_COLUMN_MUTABLE, &mutable, -1); - /* prepare the internal loop */ - loop = g_main_loop_new (NULL, FALSE); - /* prepare the popup menu */ menu = gtk_menu_new (); - gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (GTK_WIDGET (view))); - g_signal_connect_swapped (G_OBJECT (menu), "deactivate", G_CALLBACK (g_main_loop_quit), loop); - exo_gtk_object_ref_sink (GTK_OBJECT (menu)); /* append the "Open" menu action */ item = gtk_image_menu_item_new_with_mnemonic (_("_Open")); @@ -889,21 +883,16 @@ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); - /* run the internal loop */ - gtk_grab_add (menu); - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, (event != NULL) ? event->button : 0, - (event != NULL) ? event->time : gtk_get_current_event_time ()); - g_main_loop_run (loop); - gtk_grab_remove (menu); + /* run the menu on the view's screen (taking over the floating reference on menu) */ + thunar_gtk_menu_run (GTK_MENU (menu), GTK_WIDGET (view), NULL, NULL, (event != NULL) ? event->button : 0, + (event != NULL) ? event->time : gtk_get_current_event_time ()); /* clean up */ if (G_LIKELY (file != NULL)) g_object_unref (G_OBJECT (file)); if (G_UNLIKELY (volume != NULL)) g_object_unref (G_OBJECT (volume)); - g_object_unref (G_OBJECT (menu)); gtk_tree_path_free (path); - g_main_loop_unref (loop); } Modified: thunar/trunk/thunar/thunar-standard-view.c =================================================================== --- thunar/trunk/thunar/thunar-standard-view.c 2006-08-29 15:26:59 UTC (rev 22935) +++ thunar/trunk/thunar/thunar-standard-view.c 2006-08-29 15:53:32 UTC (rev 22936) @@ -36,6 +36,7 @@ #include <thunar/thunar-dnd.h> #include <thunar/thunar-enum-types.h> #include <thunar/thunar-gobject-extensions.h> +#include <thunar/thunar-gtk-extensions.h> #include <thunar/thunar-icon-renderer.h> #include <thunar/thunar-marshal.h> #include <thunar/thunar-private.h> @@ -3136,55 +3137,26 @@ guint button, guint32 time) { - GMainLoop *loop; - GtkWidget *menu; - GList *selected_items; - guint id; + GtkWidget *menu; + GList *selected_items; _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view)); - /* determine the selected items */ - selected_items = (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->get_selected_items) (standard_view); - /* merge the custom menu actions for the selected items */ + selected_items = (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->get_selected_items) (standard_view); thunar_standard_view_merge_custom_actions (standard_view, selected_items); - - /* check if we need to popup the file or the folder context menu */ - menu = gtk_ui_manager_get_widget (standard_view->ui_manager, (selected_items != NULL) ? "/file-context-menu" : "/folder-context-menu"); - - /* release the selected items */ g_list_foreach (selected_items, (GFunc) gtk_tree_path_free, NULL); g_list_free (selected_items); - /* take a reference on the context menu */ - exo_gtk_object_ref_sink (GTK_OBJECT (menu)); - /* grab an additional reference on the view */ g_object_ref (G_OBJECT (standard_view)); - loop = g_main_loop_new (NULL, FALSE); + /* run the menu on the view's screen (figuring out whether to use the file or the folder context menu) */ + menu = gtk_ui_manager_get_widget (standard_view->ui_manager, (selected_items != NULL) ? "/file-context-menu" : "/folder-context-menu"); + thunar_gtk_menu_run (GTK_MENU (menu), GTK_WIDGET (standard_view), NULL, NULL, button, time); - /* connect the deactivate handler */ - id = g_signal_connect_swapped (G_OBJECT (menu), "deactivate", G_CALLBACK (g_main_loop_quit), loop); - - /* make sure the menu is on the proper screen */ - gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (GTK_WIDGET (standard_view))); - - /* run our custom main loop */ - gtk_grab_add (menu); - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, button, time); - g_main_loop_run (loop); - g_main_loop_unref (loop); - gtk_grab_remove (menu); - - /* unlink the deactivate callback */ - g_signal_handler_disconnect (G_OBJECT (menu), id); - /* release the additional reference on the view */ g_object_unref (G_OBJECT (standard_view)); - - /* decrease the reference count on the menu */ - g_object_unref (G_OBJECT (menu)); } Modified: thunar/trunk/thunar/thunar-tree-view.c =================================================================== --- thunar/trunk/thunar/thunar-tree-view.c 2006-08-29 15:26:59 UTC (rev 22935) +++ thunar/trunk/thunar/thunar-tree-view.c 2006-08-29 15:53:32 UTC (rev 22936) @@ -28,6 +28,7 @@ #include <thunar/thunar-create-dialog.h> #include <thunar/thunar-dialogs.h> #include <thunar/thunar-dnd.h> +#include <thunar/thunar-gtk-extensions.h> #include <thunar/thunar-marshal.h> #include <thunar/thunar-preferences.h> #include <thunar/thunar-private.h> @@ -991,7 +992,6 @@ GtkWidget *image; GtkWidget *menu; GtkWidget *item; - GMainLoop *loop; /* verify that we're connected to the clipboard manager */ if (G_UNLIKELY (view->clipboard == NULL)) @@ -1003,14 +1003,8 @@ THUNAR_TREE_MODEL_COLUMN_VOLUME, &volume, -1); - /* prepare the internal loop */ - loop = g_main_loop_new (NULL, FALSE); - /* prepare the popup menu */ menu = gtk_menu_new (); - gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (GTK_WIDGET (view))); - g_signal_connect_swapped (G_OBJECT (menu), "deactivate", G_CALLBACK (g_main_loop_quit), loop); - exo_gtk_object_ref_sink (GTK_OBJECT (menu)); /* append the "Open" menu action */ item = gtk_image_menu_item_new_with_mnemonic (_("_Open")); @@ -1191,20 +1185,15 @@ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); gtk_widget_show (image); - /* run the internal main loop */ - gtk_grab_add (menu); - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, (event != NULL) ? event->button : 0, - (event != NULL) ? event->time : gtk_get_current_event_time ()); - g_main_loop_run (loop); - gtk_grab_remove (menu); + /* run the menu on the view's screen (taking over the floating reference on the menu) */ + thunar_gtk_menu_run (GTK_MENU (menu), GTK_WIDGET (view), NULL, NULL, (event != NULL) ? event->button : 0, + (event != NULL) ? event->time : gtk_get_current_event_time ()); /* cleanup */ if (G_UNLIKELY (volume != NULL)) g_object_unref (G_OBJECT (volume)); if (G_LIKELY (file != NULL)) g_object_unref (G_OBJECT (file)); - g_object_unref (G_OBJECT (menu)); - g_main_loop_unref (loop); } _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits