Warn for whitespace at beginning or end of new folder names
authorArc Riley <arcriley@gmail.com>
Wed, 1 Jul 2015 21:33:07 +0000 (14:33 -0700)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 4 Jul 2015 22:57:13 +0000 (18:57 -0400)
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

index e7bec0d6cad8731a1847901c72fee2946762885b..3c4b7b7788df59b5f90c08715a49afc6d56f6b66 100644 (file)
@@ -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);
     }