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
This commit is contained in:
		
				
					committed by
					
						
						Matthias Clasen
					
				
			
			
				
	
			
			
			
						parent
						
							d2569a3860
						
					
				
				
					commit
					02b5ac9ee4
				
			@ -955,6 +955,7 @@ struct FileExistsData
 | 
			
		||||
  gboolean file_exists_and_is_not_folder;
 | 
			
		||||
  GFile *parent_file;
 | 
			
		||||
  GFile *file;
 | 
			
		||||
  gchar *name;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
@ -990,6 +991,17 @@ name_exists_get_info_cb (GCancellable *cancellable,
 | 
			
		||||
  else
 | 
			
		||||
    {
 | 
			
		||||
      gtk_widget_set_sensitive (priv->new_folder_create_button, TRUE);
 | 
			
		||||
 | 
			
		||||
      // 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), "");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -997,6 +1009,7 @@ 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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user