From dad7d234170ef96f1d2552abdbe4cc44bff307e7 Mon Sep 17 00:00:00 2001 From: Yousuf Philips Date: Thu, 27 Feb 2020 05:29:05 +0400 Subject: [PATCH] Add computer:/// to Go menu (Bug #16472) --- thunar/thunar-gio-extensions.c | 7 +++++++ thunar/thunar-gio-extensions.h | 1 + thunar/thunar-window-ui.xml | 1 + thunar/thunar-window.c | 35 ++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/thunar/thunar-gio-extensions.c b/thunar/thunar-gio-extensions.c index a72bef40..2bed2d62 100644 --- a/thunar/thunar-gio-extensions.c +++ b/thunar/thunar-gio-extensions.c @@ -63,6 +63,13 @@ thunar_g_file_new_for_trash (void) } +GFile * +thunar_g_file_new_for_computer (void) +{ + return g_file_new_for_uri ("computer:///"); +} + + GFile * thunar_g_file_new_for_desktop (void) diff --git a/thunar/thunar-gio-extensions.h b/thunar/thunar-gio-extensions.h index 48cc8aca..28a63e4d 100644 --- a/thunar/thunar-gio-extensions.h +++ b/thunar/thunar-gio-extensions.h @@ -29,6 +29,7 @@ GFile *thunar_g_file_new_for_home (void); GFile *thunar_g_file_new_for_root (void); GFile *thunar_g_file_new_for_trash (void); GFile *thunar_g_file_new_for_desktop (void); +GFile *thunar_g_file_new_for_computer (void); GFile *thunar_g_file_new_for_bookmarks (void); gboolean thunar_g_file_is_root (GFile *file); diff --git a/thunar/thunar-window-ui.xml b/thunar/thunar-window-ui.xml index d251a706..457b82b2 100644 --- a/thunar/thunar-window-ui.xml +++ b/thunar/thunar-window-ui.xml @@ -80,6 +80,7 @@ + diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c index 81d528a5..4988609b 100644 --- a/thunar/thunar-window.c +++ b/thunar/thunar-window.c @@ -201,6 +201,8 @@ static void thunar_window_action_open_home (GtkAction ThunarWindow *window); static void thunar_window_action_open_desktop (GtkAction *action, ThunarWindow *window); +static void thunar_window_action_open_computer (GtkAction *action, + ThunarWindow *window); static void thunar_window_action_open_templates (GtkAction *action, ThunarWindow *window); static void thunar_window_action_open_file_system (GtkAction *action, @@ -376,6 +378,7 @@ static GtkActionEntry action_entries[] = { "open-parent", "go-up-symbolic", N_ ("Open _Parent"), "Up", N_ ("Open the parent folder"), G_CALLBACK (thunar_window_action_go_up), }, { "open-home", "go-home-symbolic", N_ ("_Home"), "Home", N_ ("Go to the home folder"), G_CALLBACK (thunar_window_action_open_home), }, { "open-desktop", "user-desktop", N_ ("Desktop"), NULL, N_ ("Go to the desktop folder"), G_CALLBACK (thunar_window_action_open_desktop), }, + { "open-computer", "computer-symbolic", N_ ("Computer"), NULL, N_ ("Go to the computer folder"), G_CALLBACK (thunar_window_action_open_computer), }, { "open-file-system", "drive-harddisk", N_ ("File System"), NULL, N_ ("Browse the file system"), G_CALLBACK (thunar_window_action_open_file_system), }, { "open-network", "network-workgroup", N_("B_rowse Network"), NULL, N_ ("Browse local network connections"), G_CALLBACK (thunar_window_action_open_network), }, { "open-templates", "text-x-generic-template", N_("T_emplates"), NULL, N_ ("Go to the templates folder"), G_CALLBACK (thunar_window_action_open_templates), }, @@ -3093,6 +3096,38 @@ G_GNUC_END_IGNORE_DEPRECATIONS } +static void +thunar_window_action_open_computer (GtkAction *action, + ThunarWindow *window) +{ + GFile *computer; + ThunarFile *computer_file; + GError *error = NULL; + + _thunar_return_if_fail (THUNAR_IS_WINDOW (window)); + + /* determine the path to the root directory */ + computer = thunar_g_file_new_for_computer (); + + /* determine the file for the root directory */ + computer_file = thunar_file_get (computer, &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 computer folder")); + g_error_free (error); + } + else + { + /* open the root folder */ + thunar_window_set_current_directory (window, computer_file); + g_object_unref (G_OBJECT (computer_file)); + } + + /* release our reference on the home path */ + g_object_unref (computer); +} + static void thunar_window_action_open_templates (GtkAction *action, -- 2.17.1