[nautilus] view: show "New Folder" dialog



commit 6f4fc647917364e0b86e6f485efca9d70bbe21f2
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Apr 6 16:29:06 2015 -0300

    view: show "New Folder" dialog
    
    This commit introduces the "New Folder"
    dialog, which asks the folder name before
    actually creating it.
    
    With the introduced changes, the folder
    is created with the given name instead
    of creating it first with the generic
    "Unamed folder" and then renaming it.
    
    This dialog is part of the ongoing effort
    to modernize Nautilus to better fit GNOME
    standards, and the latest mockups can
    be found at [1].
    
    [1] 
https://raw.githubusercontent.com/gnome-design-team/gnome-mockups/master/nautilus/nautilus-next/new-folder.png
    
    https://bugzilla.gnome.org/show_bug.cgi?id=747381

 libnautilus-private/nautilus-file-operations.c     |    2 +
 libnautilus-private/nautilus-file-operations.h     |    1 +
 .../nautilus-file-undo-operations.c                |    2 +-
 src/nautilus-view.c                                |  167 ++++++++++++++------
 4 files changed, 123 insertions(+), 49 deletions(-)
---
diff --git a/libnautilus-private/nautilus-file-operations.c b/libnautilus-private/nautilus-file-operations.c
index 0315a46..acb4c7c 100644
--- a/libnautilus-private/nautilus-file-operations.c
+++ b/libnautilus-private/nautilus-file-operations.c
@@ -6256,6 +6256,7 @@ void
 nautilus_file_operations_new_folder (GtkWidget *parent_view, 
                                     GdkPoint *target_point,
                                     const char *parent_dir,
+                                    const char *folder_name,
                                     NautilusCreateCallback done_callback,
                                     gpointer done_callback_data)
 {
@@ -6271,6 +6272,7 @@ nautilus_file_operations_new_folder (GtkWidget *parent_view,
        job->done_callback = done_callback;
        job->done_callback_data = done_callback_data;
        job->dest_dir = g_file_new_for_uri (parent_dir);
+       job->filename = g_strdup (folder_name);
        job->make_dir = TRUE;
        if (target_point != NULL) {
                job->position = *target_point;
diff --git a/libnautilus-private/nautilus-file-operations.h b/libnautilus-private/nautilus-file-operations.h
index 87611b6..e65ba7d 100644
--- a/libnautilus-private/nautilus-file-operations.h
+++ b/libnautilus-private/nautilus-file-operations.h
@@ -64,6 +64,7 @@ void nautilus_file_operations_empty_trash (GtkWidget                 *parent_vie
 void nautilus_file_operations_new_folder  (GtkWidget                 *parent_view,
                                           GdkPoint                  *target_point,
                                           const char                *parent_dir_uri,
+                                          const char                *folder_name,
                                           NautilusCreateCallback     done_callback,
                                           gpointer                   done_callback_data);
 void nautilus_file_operations_new_file    (GtkWidget                 *parent_view,
diff --git a/libnautilus-private/nautilus-file-undo-operations.c 
b/libnautilus-private/nautilus-file-undo-operations.c
index 33a1426..3df7f6b 100644
--- a/libnautilus-private/nautilus-file-undo-operations.c
+++ b/libnautilus-private/nautilus-file-undo-operations.c
@@ -729,7 +729,7 @@ create_folder_redo_func (NautilusFileUndoInfoCreate *self,
 
        parent = g_file_get_parent (self->priv->target_file);
        parent_uri = g_file_get_uri (parent);
-       nautilus_file_operations_new_folder (NULL, NULL, parent_uri,
+       nautilus_file_operations_new_folder (NULL, NULL, parent_uri, NULL,
                                             create_callback, self);
 
        g_free (parent_uri);
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
index 1e28f16..7a0cb65 100644
--- a/src/nautilus-view.c
+++ b/src/nautilus-view.c
@@ -1404,22 +1404,6 @@ rename_file (NautilusView *view, NautilusFile *new_file)
        nautilus_view_reveal_selection (view);
 }
 
-static void
-reveal_newly_added_folder (NautilusView *view, NautilusFile *new_file,
-                          NautilusDirectory *directory, GFile *target_location)
-{
-       GFile *location;
-
-       location = nautilus_file_get_location (new_file);
-       if (g_file_equal (location, target_location)) {
-               g_signal_handlers_disconnect_by_func (view,
-                                                     G_CALLBACK (reveal_newly_added_folder),
-                                                     (void *) target_location);
-               rename_file (view, new_file);
-       }
-       g_object_unref (location);
-}
-
 typedef struct {
        NautilusView *directory_view;
        GHashTable *added_locations;
@@ -1553,22 +1537,6 @@ new_folder_done (GFile *new_folder,
                                               0, 0);
                g_list_free_full (uris, g_free);
                g_free (target_uri);
-       } else {
-               if (g_hash_table_lookup_extended (data->added_locations, new_folder, NULL, NULL)) {
-                       /* The file was already added */
-                       rename_file (directory_view, file);
-               } else {
-                       /* We need to run after the default handler adds the folder we want to
-                        * operate on. The ADD_FILE signal is registered as G_SIGNAL_RUN_LAST, so we
-                        * must use connect_after.
-                        */
-                       g_signal_connect_data (directory_view,
-                                              "add-file",
-                                              G_CALLBACK (reveal_newly_added_folder),
-                                              g_object_ref (new_folder),
-                                              (GClosureNotify)g_object_unref,
-                                              G_CONNECT_AFTER);
-               }
        }
 
        nautilus_file_unref (file);
@@ -1624,30 +1592,133 @@ context_menu_to_file_operation_position (NautilusView *view)
 }
 
 static void
+nautilus_view_add_file_dialog_validate_entry (GObject    *object,
+                                              GParamSpec *params,
+                                              gpointer    user_data)
+{
+       const gchar *text;
+
+       g_assert (object && GTK_IS_ENTRY (object));
+       g_assert (user_data && GTK_IS_DIALOG (user_data));
+
+       text = gtk_entry_get_text (GTK_ENTRY (object));
+
+       gtk_dialog_set_response_sensitive (GTK_DIALOG (user_data),
+                                           GTK_RESPONSE_OK,
+                                           g_utf8_strlen (text, -1) > 0);
+}
+
+static void
+nautilus_view_add_file_dialog_entry_activate (GtkWidget *entry,
+                                              gpointer   user_data)
+{
+       const gchar *text;
+
+       g_assert (entry && GTK_IS_ENTRY (entry));
+       g_assert (user_data && GTK_IS_DIALOG (user_data));
+
+       text = gtk_entry_get_text (GTK_ENTRY (entry));
+
+       if (g_utf8_strlen (text, -1) > 0) {
+               gtk_dialog_response (GTK_DIALOG (user_data),
+                                     GTK_RESPONSE_OK);
+       }
+}
+
+static void
 nautilus_view_new_folder (NautilusView *directory_view,
                          gboolean      with_selection)
 {
-       char *parent_uri;
-       NewFolderData *data;
-       GdkPoint *pos;
+       GtkWidget *dialog;
+       GtkWidget *label;
+       GtkWidget *entry;
+       GtkWidget *box;
+       GtkWidget *window;
+       GtkWidget *area;
+       gint response;
 
-       data = new_folder_data_new (directory_view, with_selection);
+       // Dialog label
+       label = gtk_label_new (_("Name"));
+       gtk_style_context_add_class (gtk_widget_get_style_context (label),
+                                     "dim-label");
 
-       g_signal_connect_data (directory_view,
-                              "add-file",
-                              G_CALLBACK (track_newly_added_locations),
-                              data,
-                              (GClosureNotify)NULL,
-                              G_CONNECT_AFTER);
+       // Folder name entry
+       entry = gtk_entry_new ();
+       gtk_widget_set_hexpand (entry, TRUE);
 
-       pos = context_menu_to_file_operation_position (directory_view);
+       // Dialog
+       window = gtk_widget_get_toplevel (GTK_WIDGET (directory_view));
+       dialog = gtk_dialog_new_with_buttons (_("New Folder"),
+                                              GTK_WINDOW (window),
+                                              GTK_DIALOG_MODAL | GTK_DIALOG_USE_HEADER_BAR | 
GTK_DIALOG_DESTROY_WITH_PARENT,
+                                              _("Cancel"),
+                                              GTK_RESPONSE_CANCEL,
+                                              _("Create"),
+                                              GTK_RESPONSE_OK,
+                                              NULL);
+
+       gtk_dialog_set_default_response (GTK_DIALOG (dialog),
+                                         GTK_RESPONSE_OK);
+
+       gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog   ),
+                                           GTK_RESPONSE_OK,
+                                           FALSE);
+
+       gtk_container_set_border_width (GTK_CONTAINER (dialog), 12);
+
+       // Main box
+       box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+       area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+
+       gtk_container_add (GTK_CONTAINER (box), label);
+       gtk_container_add (GTK_CONTAINER (box), entry);
+       gtk_container_add (GTK_CONTAINER (area), box);
+
+       gtk_widget_show_all (box);
+
+       // Only allow non-null names
+       g_signal_connect (entry,
+                          "notify::text",
+                          G_CALLBACK (nautilus_view_add_file_dialog_validate_entry),
+                          dialog);
+       g_signal_connect (entry,
+                          "activate",
+                          G_CALLBACK (nautilus_view_add_file_dialog_entry_activate),
+                          dialog);
+
+       // Show the dialog and wait for user interaction
+       response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+       // Perform the action on GTK_RESPONSE_OK response
+       if (response == GTK_RESPONSE_OK) {
+               char *parent_uri;
+               gchar *name;
+               NewFolderData *data;
+               GdkPoint *pos;
+
+               data = new_folder_data_new (directory_view, with_selection);
+               name = gtk_entry_get_text (GTK_ENTRY (entry));
+
+               g_signal_connect_data (directory_view,
+                                       "add-file",
+                                       G_CALLBACK (track_newly_added_locations),
+                                       data,
+                                       (GClosureNotify)NULL,
+                                       G_CONNECT_AFTER);
+
+               pos = context_menu_to_file_operation_position (directory_view);
+
+               parent_uri = nautilus_view_get_backing_uri (directory_view);
+               nautilus_file_operations_new_folder (GTK_WIDGET (directory_view),
+                                                     pos,
+                                                     parent_uri,
+                                                     name,
+                                                     new_folder_done, data);
 
-       parent_uri = nautilus_view_get_backing_uri (directory_view);
-       nautilus_file_operations_new_folder (GTK_WIDGET (directory_view),
-                                            pos, parent_uri,
-                                            new_folder_done, data);
+               g_free (parent_uri);
+         }
 
-       g_free (parent_uri);
+       gtk_widget_destroy (dialog);
 }
 
 static NewFolderData *


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