[Xfce4-commits] <thunar:nick/user-dirs> Ask user to create directory if it does not exist.
Nick Schermer
noreply at xfce.org
Sat Nov 5 13:38:02 CET 2011
Updating branch refs/heads/nick/user-dirs
to b47355dbdd296ff0872b3b2699e9dbda10b41f92 (commit)
from 075081d13fadad1d04c62454b44e6ee4e2458191 (commit)
commit b47355dbdd296ff0872b3b2699e9dbda10b41f92
Author: Nick Schermer <nick at xfce.org>
Date: Sat Nov 5 12:46:28 2011 +0100
Ask user to create directory if it does not exist.
thunar/thunar-window.c | 29 +++++++++++++++++++++++++++--
1 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c
index a42d982..18d0ca2 100644
--- a/thunar/thunar-window.c
+++ b/thunar/thunar-window.c
@@ -2008,6 +2008,10 @@ thunar_window_open_user_folder (GtkAction *action,
GFile *home_dir;
GFile *user_dir;
gchar *path = NULL;
+ GtkWidget *dialog;
+ gint response;
+ gchar *error_msg;
+ gchar *parse_name;
path = g_strdup (g_get_user_special_dir (thunar_user_dir));
@@ -2027,6 +2031,24 @@ thunar_window_open_user_folder (GtkAction *action,
/* handle the case where the file does not exists */
if (G_UNLIKELY (user_file == NULL || !thunar_file_exists (user_file)))
{
+ /* ask the user whether to create the directory */
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+ GTK_DIALOG_DESTROY_WITH_PARENT
+ | GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE,
+ _("Do you want to create the user directory \"%s\"?"),
+ default_name);
+ parse_name = g_file_get_parse_name (user_dir);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ _("This will create the directory \"%s\"."), parse_name);
+ gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+ gtk_dialog_add_button (GTK_DIALOG (dialog), _("Create Directory"), GTK_RESPONSE_YES);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ g_free (parse_name);
+
/* release the instance if it does not exist */
if (user_file != NULL)
{
@@ -2034,6 +2056,10 @@ thunar_window_open_user_folder (GtkAction *action,
user_file = NULL;
}
+ /* leave silently without creation */
+ if (response == GTK_RESPONSE_CANCEL)
+ return FALSE;
+
/* try to create the folder, then reload the file */
if (G_LIKELY (xfce_mkdirhier (path, 0755, &error)))
user_file = thunar_file_get (user_dir, &error);
@@ -2048,8 +2074,7 @@ thunar_window_open_user_folder (GtkAction *action,
}
else
{
- gchar *error_msg = g_strdup_printf (_("Failed to open folder \"%s\""), default_name);
-
+ error_msg = g_strdup_printf (_("Failed to open folder \"%s\""), default_name);
thunar_dialogs_show_error (GTK_WIDGET (window), error, "%s", error_msg);
g_free (error_msg);
if (error)
More information about the Xfce4-commits
mailing list