[Xfce4-commits] <thunar:master> Show trash and network in the go menu on-demand. Use a UI placeholder.

Jannis Pohlmann jannis at xfce.org
Thu Sep 3 16:58:02 CEST 2009


Updating branch refs/heads/master
         to e99cdb4cfae6392f15dc677c3e1c3b0e892a789a (commit)
       from 6125c281b73b0742ce2fc4c58b7423cd0a45e6ec (commit)

commit e99cdb4cfae6392f15dc677c3e1c3b0e892a789a
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Thu Sep 3 16:55:27 2009 +0200

    Show trash and network in the go menu on-demand. Use a UI placeholder.
    
    File system is also included in the placeholder as it is supposed to
    appear between trash and network for consistency reasons. However, the
    file system action is always added to the action group as it will of
    course always be displayed.

 thunar/thunar-window-ui.xml |    2 +-
 thunar/thunar-window.c      |  180 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 173 insertions(+), 9 deletions(-)

diff --git a/thunar/thunar-window-ui.xml b/thunar/thunar-window-ui.xml
index 997fbff..f88332e 100644
--- a/thunar/thunar-window-ui.xml
+++ b/thunar/thunar-window-ui.xml
@@ -73,8 +73,8 @@
       <menuitem action="forward" />
       <separator />
       <menuitem action="open-home" />
-      <menuitem action="open-trash" />
       <menuitem action="open-desktop" />
+      <placeholder name="placeholder-go-items-actions" />
       <menuitem action="open-documents" />
       <menuitem action="open-downloads" />
       <menuitem action="open-music" />
diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c
index 17a8e5c..4d17110 100644
--- a/thunar/thunar-window.c
+++ b/thunar/thunar-window.c
@@ -109,6 +109,7 @@ static void     thunar_window_unrealize                   (GtkWidget
 static gboolean thunar_window_configure_event             (GtkWidget              *widget,
                                                            GdkEventConfigure      *event);
 static void     thunar_window_merge_custom_preferences    (ThunarWindow           *window);
+static void     thunar_window_merge_go_actions            (ThunarWindow           *window);
 static void     thunar_window_install_location_bar        (ThunarWindow           *window,
                                                            GType                   type);
 static void     thunar_window_install_sidepane            (ThunarWindow           *window,
@@ -166,8 +167,12 @@ static void     thunar_window_action_open_templates       (GtkAction
                                                            ThunarWindow           *window);
 static void     thunar_window_action_open_videos          (GtkAction              *action,
                                                            ThunarWindow           *window);
+static void     thunar_window_action_open_file_system     (GtkAction              *action,
+                                                           ThunarWindow           *window);
 static void     thunar_window_action_open_trash           (GtkAction              *action,
                                                            ThunarWindow           *window);
+static void     thunar_window_action_open_network         (GtkAction              *action,
+                                                           ThunarWindow           *window);
 static void     thunar_window_action_open_location        (GtkAction              *action,
                                                            ThunarWindow           *window);
 static void     thunar_window_action_contents             (GtkAction              *action,
@@ -224,7 +229,10 @@ struct _ThunarWindow
 
   /* support for custom preferences actions */
   ThunarxProviderFactory *provider_factory;
-  gint                    custom_preferences_merge_id;
+  guint                   custom_preferences_merge_id;
+
+  /* UI manager merge ID for go menu actions */
+  guint                   go_items_actions_merge_id;
 
   ThunarClipboardManager *clipboard;
 
@@ -300,6 +308,7 @@ static GtkActionEntry action_entries[] =
   { "open-parent", GTK_STOCK_GO_UP, N_ ("Open _Parent"), "<alt>Up", N_ ("Open the parent folder"), G_CALLBACK (thunar_window_action_go_up), },
   { "open-home", THUNAR_STOCK_HOME, N_ ("_Home"), "<alt>Home", N_ ("Go to the home folder"), G_CALLBACK (thunar_window_action_open_home), },
   { "open-desktop", THUNAR_STOCK_DESKTOP, "Desktop", NULL, N_ ("Go to the desktop folder"), G_CALLBACK (thunar_window_action_open_desktop), },
+  { "open-file-system", GTK_STOCK_HARDDISK, N_ ("File System"), NULL, N_ ("Brwose the file system"), G_CALLBACK (thunar_window_action_open_file_system), },
   { "open-documents", THUNAR_STOCK_DOCUMENTS, "Documents", NULL, N_ ("Go to the documents folder"), G_CALLBACK (thunar_window_action_open_documents), },
   { "open-downloads", THUNAR_STOCK_DOWNLOADS, "Download", NULL, N_ ("Go to the downloads folder"), G_CALLBACK (thunar_window_action_open_downloads), },
   { "open-music", THUNAR_STOCK_MUSIC, "Music", NULL, N_ ("Go to the music folder"), G_CALLBACK (thunar_window_action_open_music), },
@@ -716,12 +725,6 @@ thunar_window_init (ThunarWindow *window)
   /* rename the user dir menu entries and hide the unexisting ones */
   thunar_window_setup_user_dir_menu_entries (window);
 
-  /* setup the "open-trash" action */
-  action = thunar_trash_action_new ();
-  g_signal_connect (G_OBJECT (action), "activate", G_CALLBACK (thunar_window_action_open_trash), window);
-  gtk_action_group_add_action (window->action_group, action);
-  g_object_unref (G_OBJECT (action));
-
   /*
    * add view options
    */
@@ -909,6 +912,13 @@ thunar_window_dispose (GObject *object)
       window->custom_preferences_merge_id = 0;
     }
 
+  /* un-merge the go menu actions */
+  if (G_LIKELY (window->go_items_actions_merge_id != 0))
+    {
+      gtk_ui_manager_remove_ui (window->ui_manager, window->go_items_actions_merge_id);
+      window->go_items_actions_merge_id = 0;
+    }
+
   /* disconnect from the current-directory */
   thunar_window_set_current_directory (window, NULL);
 
@@ -1377,6 +1387,72 @@ thunar_window_merge_custom_preferences (ThunarWindow *window)
 
 
 
+void
+thunar_window_merge_go_actions (ThunarWindow *window)
+{
+  GtkAction *action;
+
+  _thunar_return_if_fail (THUNAR_IS_WINDOW (window));
+  _thunar_return_if_fail (window->go_items_actions_merge_id == 0);
+
+  /* allocate a new merge id from the UI manager */
+  window->go_items_actions_merge_id = gtk_ui_manager_new_merge_id (window->ui_manager);
+
+  /* setup the "open-trash" action */
+  if (thunar_g_vfs_is_uri_scheme_supported ("trash"))
+    {
+      /* add the trash action to the action group */
+      action = thunar_trash_action_new ();
+      g_signal_connect (G_OBJECT (action), "activate", G_CALLBACK (thunar_window_action_open_trash), window);
+      gtk_action_group_add_action (window->action_group, action);
+
+      /* add the action to the UI manager */
+      gtk_ui_manager_add_ui (window->ui_manager,
+                             window->go_items_actions_merge_id,
+                             "/main-menu/go-menu/placeholder-go-items-actions",
+                             gtk_action_get_name (GTK_ACTION (action)),
+                             gtk_action_get_name (GTK_ACTION (action)),
+                             GTK_UI_MANAGER_MENUITEM, FALSE);
+
+      g_object_unref (action);
+    }
+
+  /* add the file system action to the UI manager */
+  {
+    action = gtk_action_group_get_action (window->action_group, "open-file-system");
+    gtk_ui_manager_add_ui (window->ui_manager,
+                           window->go_items_actions_merge_id,
+                           "/main-menu/go-menu/placeholder-go-items-actions",
+                           gtk_action_get_name (GTK_ACTION (action)),
+                           gtk_action_get_name (GTK_ACTION (action)),
+                           GTK_UI_MANAGER_MENUITEM, FALSE);
+  }
+
+  /* setup the "open-network" action */
+  if (thunar_g_vfs_is_uri_scheme_supported ("network"))
+    {
+      /* create the network action */
+      action = gtk_action_new ("open-network", _("Network"), _("Browse the network"), 
+                               GTK_STOCK_NETWORK);
+      g_signal_connect (action, "activate", G_CALLBACK (thunar_window_action_open_network), window);
+
+      /* add the network action to the action group */
+      gtk_action_group_add_action (window->action_group, action);
+
+      /* add the action to the UI manager */
+      gtk_ui_manager_add_ui (window->ui_manager,
+                             window->go_items_actions_merge_id,
+                             "/main-menu/go-menu/placeholder-go-items-actions",
+                             gtk_action_get_name (GTK_ACTION (action)),
+                             gtk_action_get_name (GTK_ACTION (action)),
+                             GTK_UI_MANAGER_MENUITEM, FALSE);
+
+      g_object_unref (action);
+    }
+}
+
+
+
 static void
 thunar_window_open_or_launch (ThunarWindow *window,
                               ThunarFile   *file)
@@ -1908,6 +1984,8 @@ thunar_window_action_open_home (GtkAction    *action,
   g_object_unref (home);
 }
 
+
+
 static gboolean
 thunar_window_open_user_folder (GtkAction           *action,
                                 ThunarWindow        *window,
@@ -1967,6 +2045,8 @@ thunar_window_open_user_folder (GtkAction           *action,
   return result;
 }
 
+
+
 static void
 thunar_window_action_open_desktop (GtkAction     *action,
                                    ThunarWindow  *window)
@@ -1979,6 +2059,8 @@ thunar_window_action_open_desktop (GtkAction     *action,
                                   "Desktop");
 }
 
+
+
 static void
 thunar_window_action_open_documents (GtkAction     *action,
                                      ThunarWindow  *window)
@@ -1991,6 +2073,8 @@ thunar_window_action_open_documents (GtkAction     *action,
                                   "Documents");
 }
 
+
+
 static void
 thunar_window_action_open_downloads (GtkAction     *action,
                                      ThunarWindow  *window)
@@ -2003,6 +2087,8 @@ thunar_window_action_open_downloads (GtkAction     *action,
                                   "Downloads");
 }
 
+
+
 static void
 thunar_window_action_open_music (GtkAction     *action,
                                  ThunarWindow  *window)
@@ -2015,6 +2101,8 @@ thunar_window_action_open_music (GtkAction     *action,
                                   "Music");
 }
 
+
+
 static void
 thunar_window_action_open_pictures (GtkAction     *action,
                                     ThunarWindow  *window)
@@ -2027,6 +2115,8 @@ thunar_window_action_open_pictures (GtkAction     *action,
                                   "Pictures");
 }
 
+
+
 static void
 thunar_window_action_open_public (GtkAction     *action,
                                   ThunarWindow  *window)
@@ -2039,6 +2129,8 @@ thunar_window_action_open_public (GtkAction     *action,
                                   "Public");
 }
 
+
+
 static void
 thunar_window_action_open_templates (GtkAction    *action,
                                      ThunarWindow *window)
@@ -2119,6 +2211,7 @@ thunar_window_action_open_templates (GtkAction    *action,
 }
 
 
+
 static void
 thunar_window_action_open_videos (GtkAction     *action,
                                   ThunarWindow  *window)
@@ -2132,6 +2225,41 @@ thunar_window_action_open_videos (GtkAction     *action,
 }
 
 
+
+static void
+thunar_window_action_open_file_system (GtkAction    *action,
+                                       ThunarWindow *window)
+{
+  GFile         *root;
+  ThunarFile    *root_file;
+  GError        *error = NULL;
+
+  _thunar_return_if_fail (THUNAR_IS_WINDOW (window));
+
+  /* determine the path to the root directory */
+  root = thunar_g_file_new_for_root ();
+
+  /* determine the file for the root directory */
+  root_file = thunar_file_get (root, &error);
+  if (G_UNLIKELY (root_file == NULL))
+    {
+      /* display an error to the user */
+      thunar_dialogs_show_error (GTK_WIDGET (window), error, _("Failed to open the file system root folder"));
+      g_error_free (error);
+    }
+  else
+    {
+      /* open the root folder */
+      thunar_window_set_current_directory (window, root_file);
+      g_object_unref (G_OBJECT (root_file));
+    }
+
+  /* release our reference on the home path */
+  g_object_unref (root);
+}
+
+
+
 static void
 thunar_window_action_open_trash (GtkAction    *action,
                                  ThunarWindow *window)
@@ -2158,7 +2286,7 @@ thunar_window_action_open_trash (GtkAction    *action,
     {
       /* open the trash folder */
       thunar_window_set_current_directory (window, trash_bin_file);
-      g_object_unref (G_OBJECT (trash_bin));
+      g_object_unref (G_OBJECT (trash_bin_file));
     }
 
   /* release our reference on the trash bin path */
@@ -2168,6 +2296,41 @@ thunar_window_action_open_trash (GtkAction    *action,
 
 
 static void
+thunar_window_action_open_network (GtkAction    *action,
+                                   ThunarWindow *window)
+{
+  ThunarFile *network_file;
+  GError     *error = NULL;
+  GFile      *network;
+
+  _thunar_return_if_fail (GTK_IS_ACTION (action));
+  _thunar_return_if_fail (THUNAR_IS_WINDOW (window));
+
+  /* determine the network root location */
+  network = g_file_new_for_uri ("network://");
+
+  /* determine the file for this location */
+  network_file = thunar_file_get (network, &error);
+  if (G_UNLIKELY (network_file == NULL))
+    {
+      /* display an error to the user */
+      thunar_dialogs_show_error (GTK_WIDGET (window), error, _("Failed to browse the network"));
+      g_error_free (error);
+    }
+  else
+    {
+      /* open the network root location */
+      thunar_window_set_current_directory (window, network_file);
+      g_object_unref (G_OBJECT (network_file));
+    }
+
+  /* release our reference on the location itself */
+  g_object_unref (network);
+}
+
+
+
+static void
 thunar_window_action_open_location (GtkAction    *action,
                                     ThunarWindow *window)
 {
@@ -2463,6 +2626,7 @@ thunar_window_merge_idle (gpointer user_data)
   /* merge custom preferences from the providers */
   GDK_THREADS_ENTER ();
   thunar_window_merge_custom_preferences (window);
+  thunar_window_merge_go_actions (window);
   GDK_THREADS_LEAVE ();
 
   return FALSE;



More information about the Xfce4-commits mailing list