[gtk+] Warn for whitespace at beginning or end of new folder names



commit 02b5ac9ee487322ff458b21837582f6e257077a4
Author: Arc Riley <arcriley gmail com>
Date:   Wed Jul 1 14:33:07 2015 -0700

    Warn for whitespace at beginning or end of new folder names
    
    The warning is not intended to disable the Create button and must only be shown
    when the folder is not found, so this is implemented in the folder name exists
    callback.
    
    A "name" entry was added to FileExistsData to pass the filename to the callback
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751800

 gtk/gtkfilechooserwidget.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index e7bec0d..3c4b7b7 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -955,6 +955,7 @@ struct FileExistsData
   gboolean file_exists_and_is_not_folder;
   GFile *parent_file;
   GFile *file;
+  gchar *name;
 };
 
 static void
@@ -990,13 +991,25 @@ name_exists_get_info_cb (GCancellable *cancellable,
   else
     {
       gtk_widget_set_sensitive (priv->new_folder_create_button, TRUE);
-      gtk_label_set_text (GTK_LABEL (priv->new_folder_error_label), "");
+
+      // If file doesn't exist, warn if string begins or ends with whitespace
+      if (g_ascii_isspace (data->name[0]))
+        gtk_label_set_text (GTK_LABEL (priv->new_folder_error_label),
+                            "Folder names should not begin with a space");
+
+      else if (g_ascii_isspace (data->name[strlen (data->name) - 1]))
+        gtk_label_set_text (GTK_LABEL (priv->new_folder_error_label),
+                            "Folder names should not end with a space");
+
+      else
+        gtk_label_set_text (GTK_LABEL (priv->new_folder_error_label), "");
     }
 
 out:
   g_object_unref (impl);
   g_object_unref (data->file);
   g_object_unref (data->parent_file);
+  g_free (data->name);
   g_free (data);
   g_object_unref (cancellable);
 }
@@ -1041,6 +1054,7 @@ check_valid_folder_name (GtkFileChooserWidget *impl,
           data->impl = g_object_ref (impl);
           data->parent_file = g_object_ref (priv->current_folder);
           data->file = g_object_ref (file);
+          data->name = g_strdup(name);
 
           if (priv->file_exists_get_info_cancellable)
             g_cancellable_cancel (priv->file_exists_get_info_cancellable);
@@ -6038,6 +6052,7 @@ out:
   g_object_unref (data->impl);
   g_object_unref (data->file);
   g_object_unref (data->parent_file);
+  g_free (data->name);
   g_free (data);
 
   g_object_unref (cancellable);
@@ -6155,6 +6170,7 @@ out:
       g_object_unref (impl);
       g_object_unref (data->file);
       g_object_unref (data->parent_file);
+      g_free (data->name);
       g_free (data);
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]