[nautilus/wip/razvan/automatic-decompression: 7/7] files-view: extract file name widget code to a different class
- From: Răzvan-Mihai Chițu <razvanchitu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/razvan/automatic-decompression: 7/7] files-view: extract file name widget code to a different class
- Date: Thu, 7 Jul 2016 13:40:31 +0000 (UTC)
commit 5e1b23892fa75c0a8945c93c2aa6f9674751ff25
Author: Razvan Chitu <razvan ch95 gmail com>
Date: Thu Jul 7 16:38:43 2016 +0300
files-view: extract file name widget code to a different class
src/Makefile.am | 4 +-
src/nautilus-file-name-widget-coordinator.c | 315 ++++++++++++++
src/nautilus-file-name-widget-coordinator.h | 27 ++
src/nautilus-files-view.c | 457 +++++++--------------
src/resources/ui/nautilus-create-folder-dialog.ui | 2 -
src/resources/ui/nautilus-rename-file-popover.ui | 2 -
6 files changed, 484 insertions(+), 323 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 3171e8d..9e2dde2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -271,9 +271,11 @@ nautilus_no_main_sources = \
nautilus-file-changes-queue.h \
nautilus-file-conflict-dialog.c \
nautilus-file-conflict-dialog.h \
+ nautilus-file-name-widget-coordinator.c \
+ nautilus-file-name-widget-coordinator.h \
nautilus-file-operations.c \
- nautilus-operations-manager.h \
nautilus-operations-manager.c \
+ nautilus-operations-manager.h \
nautilus-file-operations.h \
nautilus-file-private.h \
nautilus-file-queue.c \
diff --git a/src/nautilus-file-name-widget-coordinator.c b/src/nautilus-file-name-widget-coordinator.c
new file mode 100644
index 0000000..7e09235
--- /dev/null
+++ b/src/nautilus-file-name-widget-coordinator.c
@@ -0,0 +1,315 @@
+#include <glib/gi18n.h>
+
+#include "nautilus-file-name-widget-coordinator.h"
+
+
+/* Delay to show the duplicated label when creating a folder */
+#define FILE_NAME_DUPLICATED_LABEL_TIMEOUT 500
+
+struct _NautilusFileNameWidgetCoordinator {
+ GObject parent_instance;
+
+ GtkWidget *parent_widget;
+
+ GtkWidget *file_name_widget;
+ GtkWidget *error_label;
+ GtkWidget *name_entry;
+ GtkWidget *activate_button;
+
+ NautilusDirectory *containing_dir;
+
+ NautilusFile *target_file;
+
+ gboolean duplicated_is_folder;
+
+ gint duplicated_label_timeout_id;
+
+ gint changed_handler_id;
+ gint activate_handler_id;
+};
+
+G_DEFINE_TYPE (NautilusFileNameWidgetCoordinator, nautilus_file_name_widget_coordinator, G_TYPE_OBJECT);
+
+enum {
+ NAME_ACCEPTED,
+ LAST_SIGNAL,
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static gboolean
+duplicated_file_label_show (NautilusFileNameWidgetCoordinator *coordinator)
+{
+ if (coordinator->duplicated_is_folder)
+ gtk_label_set_label (GTK_LABEL (coordinator->error_label),
+ _("A folder with that name already exists."));
+ else
+ gtk_label_set_label (GTK_LABEL (coordinator->error_label),
+ _("A file with that name already exists."));
+
+ coordinator->duplicated_label_timeout_id = 0;
+
+ return G_SOURCE_REMOVE;
+}
+
+static gchar*
+validate_file_name (const gchar *name)
+{
+ gchar *error_message = NULL;
+
+ if (strstr (name, "/") != NULL) {
+ error_message = _("Names cannot contain “/”.");
+ } else if (strcmp (name, ".") == 0){
+ error_message = _("“.” is an invalid name.");
+ } else if (strcmp (name, "..") == 0){
+ error_message = _("“..” is an invalid name.");
+ }
+
+ return error_message;
+}
+
+static void
+file_name_widget_entry_on_directory_info_ready (NautilusDirectory *directory,
+ GList *files,
+ gpointer callback_data) {
+ NautilusFileNameWidgetCoordinator *coordinator = callback_data;
+ gchar *name;
+ gchar *error_message;
+ NautilusFile *existing_file;
+ gboolean valid_name;
+ gboolean duplicated;
+
+ if (coordinator->parent_widget == NULL) {
+ return;
+ }
+
+ g_object_remove_weak_pointer (G_OBJECT (coordinator->parent_widget),
+ (gpointer *) &coordinator->parent_widget);
+
+ name = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (coordinator->name_entry))));
+ error_message = validate_file_name (name);
+ gtk_label_set_label (GTK_LABEL (coordinator->error_label), error_message);
+
+ existing_file = nautilus_directory_get_file_by_name (directory, name);
+
+ valid_name = strlen (name) > 0 && error_message == NULL;
+ /* If there is a target file and the name is the same, we don't show it
+ * as duplicated. This is the case for renaming. */
+ duplicated = existing_file != NULL &&
+ (coordinator->target_file == NULL ||
+ nautilus_file_compare_display_name (coordinator->target_file, name) != 0);
+ gtk_widget_set_sensitive (coordinator->activate_button, valid_name && !duplicated);
+
+ if (coordinator->duplicated_label_timeout_id > 0) {
+ g_source_remove (coordinator->duplicated_label_timeout_id);
+ coordinator->duplicated_label_timeout_id = 0;
+ }
+
+ /* Report duplicated file only if not other message shown (for instance,
+ * folders like "." or ".." will always exists, but we consider it as an
+ * error, not as a duplicated file or if the name is the same as the file
+ * we are renaming also don't report as a duplicated */
+ if (duplicated && valid_name) {
+ coordinator->duplicated_is_folder = nautilus_file_is_directory (existing_file);
+ coordinator->duplicated_label_timeout_id =
+ g_timeout_add (FILE_NAME_DUPLICATED_LABEL_TIMEOUT,
+ (GSourceFunc)duplicated_file_label_show,
+ coordinator);
+ }
+
+ if (existing_file != NULL)
+ nautilus_file_unref (existing_file);
+
+ g_free (name);
+}
+
+static void
+file_name_widget_entry_on_changed (GtkEntry *entry,
+ gpointer user_data)
+{
+ NautilusFileNameWidgetCoordinator *coordinator = user_data;
+
+ g_object_add_weak_pointer (G_OBJECT (coordinator->parent_widget),
+ (gpointer *) &coordinator->parent_widget);
+
+ nautilus_directory_call_when_ready (coordinator->containing_dir,
+ NAUTILUS_FILE_ATTRIBUTE_INFO,
+ TRUE,
+ file_name_widget_entry_on_directory_info_ready,
+ coordinator);
+}
+
+static void
+file_name_widget_on_directory_info_ready (NautilusDirectory *directory,
+ GList *files,
+ gpointer callback_data)
+{
+ NautilusFileNameWidgetCoordinator *coordinator = callback_data;
+ NautilusFile *existing_file;
+ gchar *name;
+ gchar *error_message;
+ gboolean valid_name;
+ gboolean duplicated;
+
+ if (coordinator->parent_widget == NULL) {
+ return;
+ }
+
+ g_object_remove_weak_pointer (G_OBJECT (coordinator->parent_widget),
+ (gpointer *) &coordinator->parent_widget);
+
+ name = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (coordinator->name_entry))));
+
+ existing_file = nautilus_directory_get_file_by_name (directory, name);
+
+ error_message = validate_file_name (name);
+ valid_name = strlen (name) > 0 && error_message == NULL;
+ duplicated = existing_file != NULL &&
+ (coordinator->target_file == NULL ||
+ nautilus_file_compare_display_name (coordinator->target_file, name) != 0);
+
+ if (coordinator->duplicated_label_timeout_id > 0) {
+ g_source_remove (coordinator->duplicated_label_timeout_id);
+ coordinator->duplicated_label_timeout_id = 0;
+ }
+
+ if (valid_name && !duplicated) {
+ g_signal_handler_disconnect (coordinator->name_entry,
+ coordinator->changed_handler_id);
+ g_signal_handler_disconnect (coordinator->name_entry,
+ coordinator->activate_handler_id);
+
+ g_signal_emit (coordinator, signals[NAME_ACCEPTED], 0);
+ } else {
+ /* Report duplicated file only if not other message shown (for instance,
+ * folders like "." or ".." will always exists, but we consider it as an
+ * error, not as a duplicated file) */
+ if (existing_file != NULL && valid_name) {
+ coordinator->duplicated_is_folder = nautilus_file_is_directory (existing_file);
+ /* Show it inmediatily since the user tried to trigger the action */
+ duplicated_file_label_show (coordinator);
+ }
+ }
+
+ if (existing_file != NULL)
+ nautilus_file_unref (existing_file);
+}
+
+static void
+file_name_widget_on_activate (GtkEntry *entry,
+ gpointer user_data)
+{
+ NautilusFileNameWidgetCoordinator *coordinator = user_data;
+
+ g_object_add_weak_pointer (G_OBJECT (coordinator->parent_widget),
+ (gpointer *) &coordinator->parent_widget);
+
+ nautilus_directory_call_when_ready (coordinator->containing_dir,
+ NAUTILUS_FILE_ATTRIBUTE_INFO,
+ TRUE,
+ file_name_widget_on_directory_info_ready,
+ coordinator);
+}
+
+static void
+nautilus_file_name_widget_coordinator_init (NautilusFileNameWidgetCoordinator *self)
+{
+
+}
+
+static void
+nautilus_file_name_widget_coordinator_finalize (GObject *object)
+{
+ NautilusFileNameWidgetCoordinator *self = NAUTILUS_FILE_NAME_WIDGET_COORDINATOR (object);
+
+ if (self->duplicated_label_timeout_id > 0) {
+ g_source_remove (self->duplicated_label_timeout_id);
+ self->duplicated_label_timeout_id = 0;
+ }
+
+ nautilus_directory_unref (self->containing_dir);
+
+ if (self->target_file) {
+ nautilus_file_unref (self->target_file);
+ }
+
+ G_OBJECT_CLASS (nautilus_file_name_widget_coordinator_parent_class)->finalize (object);
+}
+
+static void
+nautilus_file_name_widget_coordinator_class_init (NautilusFileNameWidgetCoordinatorClass *klass)
+{
+ GObjectClass *gobject_class;
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->finalize = nautilus_file_name_widget_coordinator_finalize;
+
+ signals[NAME_ACCEPTED] = g_signal_new ("name-accepted",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE,
+ 0);
+}
+
+NautilusFileNameWidgetCoordinator *
+nautilus_file_name_widget_coordinator_new (GtkWidget *parent_widget,
+ GtkWidget *file_name_widget,
+ GtkWidget *error_label,
+ GtkWidget *name_entry,
+ GtkWidget *activate_button,
+ NautilusDirectory *containing_dir,
+ NautilusFile *target_file)
+{
+ NautilusFileNameWidgetCoordinator *self = g_object_new (NAUTILUS_TYPE_FILE_NAME_WIDGET_COORDINATOR,
+ NULL);
+
+ self->parent_widget = parent_widget;
+
+ self->file_name_widget = file_name_widget;
+ self->error_label = error_label;
+ self->name_entry = name_entry;
+ self->activate_button = activate_button;
+
+ self->containing_dir = nautilus_directory_ref (containing_dir);
+ if (target_file) {
+ self->target_file = nautilus_file_ref (target_file);
+ }
+
+ self->changed_handler_id = g_signal_connect (name_entry, "changed",
+ G_CALLBACK (file_name_widget_entry_on_changed),
+ self);
+ self->activate_handler_id = g_signal_connect (name_entry, "activate",
+ G_CALLBACK (file_name_widget_on_activate),
+ self);
+
+ file_name_widget_entry_on_changed (GTK_ENTRY (name_entry),
+ (gpointer) self);
+
+ return self;
+}
+
+GtkWidget *
+nautilus_file_name_widget_coordinator_get_parent_widget (NautilusFileNameWidgetCoordinator *self)
+{
+ return self->parent_widget;
+}
+
+GtkWidget *
+nautilus_file_name_widget_coordinator_get_file_name_widget (NautilusFileNameWidgetCoordinator *self)
+{
+ return self->file_name_widget;
+}
+
+GtkWidget *
+nautilus_file_name_widget_coordinator_get_name_entry (NautilusFileNameWidgetCoordinator *self)
+{
+ return self->name_entry;
+}
+
+NautilusFile *
+nautilus_file_name_widget_coordinator_get_target_file (NautilusFileNameWidgetCoordinator *self)
+{
+ return self->target_file;
+}
\ No newline at end of file
diff --git a/src/nautilus-file-name-widget-coordinator.h b/src/nautilus-file-name-widget-coordinator.h
new file mode 100644
index 0000000..af3fe6b
--- /dev/null
+++ b/src/nautilus-file-name-widget-coordinator.h
@@ -0,0 +1,27 @@
+
+#ifndef __NAUTILUS_FILE_NAME_WIDGET_COORDINATOR_H__
+#define __NAUTILUS_FILE_NAME_WIDGET_COORDINATOR_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "nautilus-file.h"
+#include "nautilus-directory.h"
+
+#define NAUTILUS_TYPE_FILE_NAME_WIDGET_COORDINATOR (nautilus_file_name_widget_coordinator_get_type ())
+G_DECLARE_FINAL_TYPE (NautilusFileNameWidgetCoordinator, nautilus_file_name_widget_coordinator, NAUTILUS,
FILE_NAME_WIDGET_COORDINATOR, GObject)
+
+NautilusFileNameWidgetCoordinator * nautilus_file_name_widget_coordinator_new (GtkWidget
*parent_widget,
+ GtkWidget
*file_name_widget,
+ GtkWidget
*error_label,
+ GtkWidget *name_entry,
+ GtkWidget
*activate_button,
+ NautilusDirectory
*containing_dir,
+ NautilusFile
*target_file);
+
+GtkWidget * nautilus_file_name_widget_coordinator_get_parent_widget (NautilusFileNameWidgetCoordinator
*self);
+GtkWidget * nautilus_file_name_widget_coordinator_get_file_name_widget (NautilusFileNameWidgetCoordinator
*self);
+GtkWidget * nautilus_file_name_widget_coordinator_get_name_entry (NautilusFileNameWidgetCoordinator *self);
+NautilusFile * nautilus_file_name_widget_coordinator_get_target_file (NautilusFileNameWidgetCoordinator
*self);
+
+#endif
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index d83f081..152c0b2 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -75,6 +75,7 @@
#include "nautilus-dnd.h"
#include "nautilus-file-attributes.h"
#include "nautilus-file-changes-queue.h"
+#include "nautilus-file-name-widget-coordinator.h"
#include "nautilus-file-operations.h"
#include "nautilus-file-utilities.h"
#include "nautilus-file-private.h"
@@ -177,6 +178,8 @@ struct NautilusFilesViewDetails
gint duplicated_label_timeout_id;
GtkWidget *rename_file_popover;
+ NautilusFileNameWidgetCoordinator *dialog_coordinator;
+ NautilusFileNameWidgetCoordinator *popover_coordinator;
gboolean supports_zooming;
@@ -1695,175 +1698,39 @@ context_menu_to_file_operation_position (NautilusFilesView *view)
typedef struct {
NautilusFilesView *view;
- GtkWidget *widget;
- GtkWidget *error_label;
- GtkWidget *name_entry;
- GtkWidget *activate_button;
- gboolean target_is_folder;
- NautilusFile *target_file;
- gboolean duplicated_is_folder;
- void (*on_name_accepted) (gpointer data);
- /* For create folder only */
gboolean with_selection;
-} FileNameWidgetData;
-
-static gboolean
-duplicated_file_label_show (FileNameWidgetData *data)
-{
- if (data->duplicated_is_folder)
- gtk_label_set_label (GTK_LABEL (data->error_label), _("A folder with that name already
exists."));
- else
- gtk_label_set_label (GTK_LABEL (data->error_label), _("A file with that name already
exists."));
-
- data->view->details->duplicated_label_timeout_id = 0;
-
- return G_SOURCE_REMOVE;
-}
-
-static gchar*
-validate_file_name (const gchar *name,
- gboolean is_folder)
-{
- gchar *error_message = NULL;
-
- if (strstr (name, "/") != NULL) {
- if (is_folder)
- error_message = _("Folder names cannot contain “/”.");
- else
- error_message = _("Files names cannot contain “/”.");
- } else if (strcmp (name, ".") == 0){
- if (is_folder)
- error_message = _("A folder can not be called “.”.");
- else
- error_message = _("A file can not be called “.”.");
- } else if (strcmp (name, "..") == 0){
- if (is_folder)
- error_message = _("A folder can not be called “..”.");
- else
- error_message = _("A file can not be called “..”.");
- }
-
- return error_message;
-}
-
-static void
-file_name_widget_entry_on_directory_info_ready (NautilusDirectory *directory,
- GList *files,
- gpointer callback_data) {
- FileNameWidgetData *data;
- gchar *name;
- gchar *error_message;
- NautilusFile *existing_file;
- gboolean valid_name;
- gboolean duplicated;
-
- data = (FileNameWidgetData *) callback_data;
-
- if (data->view == NULL) {
- nautilus_directory_unref (directory);
- return;
- }
-
- g_object_remove_weak_pointer (G_OBJECT (data->view),
- (gpointer *) &data->view);
-
- name = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (data->name_entry))));
- error_message = validate_file_name (name, data->target_is_folder);
- gtk_label_set_label (GTK_LABEL (data->error_label), error_message);
-
- existing_file = nautilus_directory_get_file_by_name (directory, name);
-
- valid_name = strlen (name) > 0 && error_message == NULL;
- /* If there is a target file and the name is the same, we don't show it
- * as duplicated. This is the case for renaming. */
- duplicated = existing_file != NULL &&
- (data->target_file == NULL ||
- nautilus_file_compare_display_name (data->target_file, name) != 0);
- gtk_widget_set_sensitive (data->activate_button, valid_name && !duplicated);
-
- if (data->view->details->duplicated_label_timeout_id > 0) {
- g_source_remove (data->view->details->duplicated_label_timeout_id);
- data->view->details->duplicated_label_timeout_id = 0;
- }
-
- /* Report duplicated file only if not other message shown (for instance,
- * folders like "." or ".." will always exists, but we consider it as an
- * error, not as a duplicated file or if the name is the same as the file
- * we are renaming also don't report as a duplicated */
- if (duplicated && valid_name) {
- data->duplicated_is_folder = nautilus_file_is_directory (existing_file);
- data->view->details->duplicated_label_timeout_id =
- g_timeout_add (FILE_NAME_DUPLICATED_LABEL_TIMEOUT,
- (GSourceFunc)duplicated_file_label_show,
- data);
- }
-
- if (existing_file != NULL)
- nautilus_file_unref (existing_file);
-
- g_free (name);
-
- nautilus_directory_unref (directory);
-}
-
-static void
-file_name_widget_entry_on_changed (gpointer user_data)
-{
- FileNameWidgetData *data;
- NautilusFile *parent_location;
- NautilusDirectory *containing_dir;
-
- data = (FileNameWidgetData *) user_data;
-
- if (data->target_file != NULL &&
- !nautilus_file_is_self_owned (data->target_file)) {
- parent_location = nautilus_file_get_parent (data->target_file);
- containing_dir = nautilus_directory_get_for_file (parent_location);
-
- nautilus_file_unref (parent_location);
- } else {
- containing_dir = nautilus_directory_get_by_uri (nautilus_files_view_get_backing_uri
(data->view));
- }
-
- g_object_add_weak_pointer (G_OBJECT (data->view),
- (gpointer *) &data->view);
-
- nautilus_directory_call_when_ready (containing_dir,
- NAUTILUS_FILE_ATTRIBUTE_INFO,
- TRUE,
- file_name_widget_entry_on_directory_info_ready,
- data);
-}
+} NewFolderDialogData;
static void
create_folder_dialog_on_response (GtkDialog *dialog,
gint response_id,
gpointer user_data)
{
- FileNameWidgetData *widget_data;
-
- widget_data = (FileNameWidgetData *) user_data;
+ NewFolderDialogData *dialog_data = user_data;
+ NautilusFilesView *view = dialog_data->view;
if (response_id == GTK_RESPONSE_OK) {
NewFolderData *data;
+ GtkWidget *name_entry;
GdkPoint *pos;
char *parent_uri;
gchar *name;
- data = new_folder_data_new (widget_data->view, widget_data->with_selection);
+ data = new_folder_data_new (view, dialog_data->with_selection);
- name = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (widget_data->name_entry))));
- g_signal_connect_data (widget_data->view,
+ name_entry = nautilus_file_name_widget_coordinator_get_name_entry
(view->details->dialog_coordinator);
+ name = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (name_entry))));
+ g_signal_connect_data (view,
"add-file",
G_CALLBACK (track_newly_added_locations),
data,
(GClosureNotify)NULL,
G_CONNECT_AFTER);
- pos = context_menu_to_file_operation_position (widget_data->view);
+ pos = context_menu_to_file_operation_position (view);
- parent_uri = nautilus_files_view_get_backing_uri (widget_data->view);
- nautilus_file_operations_new_folder (GTK_WIDGET (widget_data->view),
+ parent_uri = nautilus_files_view_get_backing_uri (view);
+ nautilus_file_operations_new_folder (GTK_WIDGET (view),
pos, parent_uri, name,
new_folder_done, data);
@@ -1872,139 +1739,66 @@ create_folder_dialog_on_response (GtkDialog *dialog,
}
gtk_widget_destroy (GTK_WIDGET (dialog));
- g_free (user_data);
+ g_clear_object (&view->details->dialog_coordinator);
+ g_free (dialog_data);
}
static void
-create_folder_on_name_accepted (gpointer user_data)
+create_folder_on_name_accepted (NautilusFileNameWidgetCoordinator *coordinator,
+ gpointer user_data)
{
- FileNameWidgetData *data;
+ GtkWidget *dialog;
+
+ dialog = nautilus_file_name_widget_coordinator_get_file_name_widget (coordinator);
- data = (FileNameWidgetData *) user_data;
- gtk_dialog_response (GTK_DIALOG (data->widget),
+ gtk_dialog_response (GTK_DIALOG (dialog),
GTK_RESPONSE_OK);
}
static void
-rename_file_on_name_accepted (gpointer user_data)
+rename_file_on_name_accepted (NautilusFileNameWidgetCoordinator *coordinator,
+ gpointer user_data)
{
- FileNameWidgetData *data;
+ NautilusFilesView *view = user_data;
+ GtkWidget *name_entry;
gchar *name;
- data = (FileNameWidgetData *) user_data;
+ name_entry = nautilus_file_name_widget_coordinator_get_name_entry
(view->details->popover_coordinator);
- name = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (data->name_entry))));
+ name = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (name_entry))));
/* Put it on the queue for reveal after the view acknowledges the change */
- g_hash_table_insert (data->view->details->pending_reveal,
- data->target_file,
+ g_hash_table_insert (view->details->pending_reveal,
+ nautilus_file_name_widget_coordinator_get_target_file
(view->details->popover_coordinator),
GUINT_TO_POINTER (FALSE));
- nautilus_rename_file (data->target_file, name, NULL, NULL);
+ nautilus_rename_file (nautilus_file_name_widget_coordinator_get_target_file
(view->details->popover_coordinator),
+ name, NULL, NULL);
- gtk_widget_hide (data->widget);
+ gtk_widget_hide (nautilus_file_name_widget_coordinator_get_file_name_widget
(view->details->popover_coordinator));
g_free (name);
}
static void
-file_name_widget_on_directory_info_ready (NautilusDirectory *directory,
- GList *files,
- gpointer callback_data) {
- FileNameWidgetData *data;
- NautilusFile *existing_file;
- gchar *name;
- gchar *error_message;
- gboolean valid_name;
- gboolean duplicated;
-
- data = (FileNameWidgetData *) callback_data;
-
- if (data->view == NULL) {
- nautilus_directory_unref (directory);
- return;
- }
-
- g_object_remove_weak_pointer (G_OBJECT (data->view),
- (gpointer *) &data->view);
-
- name = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (data->name_entry))));
-
- existing_file = nautilus_directory_get_file_by_name (directory, name);
-
- error_message = validate_file_name (name, data->target_is_folder);
- valid_name = strlen (name) > 0 && error_message == NULL;
- duplicated = existing_file != NULL &&
- (data->target_file == NULL ||
- nautilus_file_compare_display_name (data->target_file, name) != 0);
-
- if (data->view->details->duplicated_label_timeout_id > 0) {
- g_source_remove (data->view->details->duplicated_label_timeout_id);
- data->view->details->duplicated_label_timeout_id = 0;
- }
-
- if (valid_name && !duplicated) {
- data->on_name_accepted ((gpointer) data);
- } else {
- /* Report duplicated file only if not other message shown (for instance,
- * folders like "." or ".." will always exists, but we consider it as an
- * error, not as a duplicated file) */
- if (existing_file != NULL && valid_name) {
- data->duplicated_is_folder = nautilus_file_is_directory (existing_file);
- /* Show it inmediatily since the user tried to trigger the action */
- duplicated_file_label_show (data);
- }
- }
-
- if (existing_file != NULL)
- nautilus_file_unref (existing_file);
-
- nautilus_directory_unref (directory);
-}
-
-static void
-file_name_widget_on_activate (gpointer user_data)
+rename_file_popover_on_closed (GtkPopover *popover,
+ gpointer user_data)
{
- FileNameWidgetData *data;
- NautilusFile *parent_location;
- NautilusDirectory *containing_dir;
-
- data = (FileNameWidgetData *) user_data;
-
- if (data->target_file != NULL &&
- !nautilus_file_is_self_owned (data->target_file)) {
- parent_location = nautilus_file_get_parent (data->target_file);
- containing_dir = nautilus_directory_get_for_file (parent_location);
-
- nautilus_file_unref (parent_location);
- } else {
- containing_dir = nautilus_directory_get_by_uri (nautilus_files_view_get_backing_uri
(data->view));
- }
-
- g_object_add_weak_pointer (G_OBJECT (data->view),
- (gpointer *) &data->view);
+ NautilusFilesView *view = user_data;
- nautilus_directory_call_when_ready (containing_dir,
- NAUTILUS_FILE_ATTRIBUTE_INFO,
- TRUE,
- file_name_widget_on_directory_info_ready,
- data);
+ g_clear_object (&view->details->popover_coordinator);
}
static void
-rename_file_popover_on_closed (GtkPopover *popover,
- gpointer user_data)
+rename_file_popover_on_unmap (GtkWidget *popover,
+ gpointer user_data)
{
- FileNameWidgetData *widget_data;
+ NautilusFilesView *view = user_data;
- widget_data = (FileNameWidgetData *) user_data;
- widget_data->view->details->rename_file_popover = NULL;
- if (widget_data->view->details->duplicated_label_timeout_id > 0) {
- g_source_remove (widget_data->view->details->duplicated_label_timeout_id);
- widget_data->view->details->duplicated_label_timeout_id = 0;
- }
- g_free (widget_data);
+ g_clear_object (&view->details->popover_coordinator);
+
+ gtk_widget_destroy (popover);
}
static GdkRectangle*
@@ -2017,71 +1811,85 @@ static void
nautilus_files_view_rename_file_popover_new (NautilusFilesView *view,
NautilusFile *target_file)
{
- FileNameWidgetData *widget_data;
- GtkWidget *label_file_name;
+ NautilusDirectory *containing_dir;
GtkBuilder *builder;
+ GtkWidget *name_label;
+ GtkWidget *popover;
+ GtkWidget *error_label;
+ GtkWidget *name_entry;
+ GtkWidget *activate_button;
gint start_offset, end_offset;
GdkRectangle *relative_to;
gint n_chars;
- if (view->details->rename_file_popover != NULL)
- return;
+ if (view->details->popover_coordinator != NULL)
+ return;
- builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-rename-file-popover.ui");
- label_file_name = GTK_WIDGET (gtk_builder_get_object (builder, "name_label"));
- widget_data = g_new (FileNameWidgetData, 1);
- widget_data->view = view;
- widget_data->on_name_accepted = rename_file_on_name_accepted;
- widget_data->widget = GTK_WIDGET (gtk_builder_get_object (builder, "rename_file_popover"));
- widget_data->activate_button = GTK_WIDGET (gtk_builder_get_object (builder, "rename_button"));
- widget_data->error_label = GTK_WIDGET (gtk_builder_get_object (builder, "error_label"));
- widget_data->name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry"));
- widget_data->target_is_folder = nautilus_file_is_directory (target_file);
- widget_data->target_file = target_file;
+ if (!nautilus_file_is_self_owned (target_file)) {
+ NautilusFile *parent_location;
- view->details->rename_file_popover = widget_data->widget;
+ parent_location = nautilus_file_get_parent (target_file);
+ containing_dir = nautilus_directory_get_for_file (parent_location);
+
+ nautilus_file_unref (parent_location);
+ } else {
+ containing_dir = nautilus_directory_get_by_uri (nautilus_files_view_get_backing_uri (view));
+ }
+
+ builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-rename-file-popover.ui");
+
+ name_label = GTK_WIDGET (gtk_builder_get_object (builder, "name_label"));
+ popover = GTK_WIDGET (gtk_builder_get_object (builder, "rename_file_popover"));
+ error_label = GTK_WIDGET (gtk_builder_get_object (builder, "error_label"));
+ name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry"));
+ activate_button = GTK_WIDGET (gtk_builder_get_object (builder, "rename_button"));
/* Connect signals */
gtk_builder_add_callback_symbols (builder,
- "file_name_widget_entry_on_changed",
- G_CALLBACK (file_name_widget_entry_on_changed),
- "file_name_widget_on_activate",
- G_CALLBACK (file_name_widget_on_activate),
"rename_file_popover_on_closed",
G_CALLBACK (rename_file_popover_on_closed),
"rename_file_popover_on_unmap",
- G_CALLBACK (gtk_widget_destroy),
+ G_CALLBACK (rename_file_popover_on_unmap),
NULL);
- gtk_builder_connect_signals (builder, widget_data);
+ gtk_builder_connect_signals (builder, view);
- if (widget_data->target_is_folder)
- gtk_label_set_text (GTK_LABEL (label_file_name), _("Folder name"));
+ if (nautilus_file_is_directory (target_file))
+ gtk_label_set_text (GTK_LABEL (name_label), _("Folder name"));
else
- gtk_label_set_text (GTK_LABEL (label_file_name), _("File name"));
- gtk_entry_set_text (GTK_ENTRY (widget_data->name_entry), nautilus_file_get_display_name
(target_file));
+ gtk_label_set_text (GTK_LABEL (name_label), _("File name"));
+ gtk_entry_set_text (GTK_ENTRY (name_entry), nautilus_file_get_display_name (target_file));
relative_to = nautilus_files_view_compute_rename_popover_relative_to (view);
- gtk_popover_set_default_widget (GTK_POPOVER (widget_data->widget),
- widget_data->activate_button);
- gtk_popover_set_pointing_to (GTK_POPOVER (widget_data->widget), relative_to);
- gtk_popover_set_relative_to (GTK_POPOVER (widget_data->widget),
+ gtk_popover_set_default_widget (GTK_POPOVER (popover),
+ activate_button);
+ gtk_popover_set_pointing_to (GTK_POPOVER (popover), relative_to);
+ gtk_popover_set_relative_to (GTK_POPOVER (popover),
GTK_WIDGET (view));
- gtk_widget_show (widget_data->widget);
- gtk_widget_grab_focus (widget_data->name_entry);
+ gtk_widget_show (popover);
+ gtk_widget_grab_focus (name_entry);
/* Select the name part withouth the file extension */
eel_filename_get_rename_region (nautilus_file_get_display_name (target_file),
&start_offset, &end_offset);
n_chars = g_utf8_strlen (nautilus_file_get_display_name (target_file), -1);
- gtk_entry_set_width_chars (GTK_ENTRY (widget_data->name_entry),
+ gtk_entry_set_width_chars (GTK_ENTRY (name_entry),
MIN (MAX (n_chars, RENAME_ENTRY_MIN_CHARS), RENAME_ENTRY_MAX_CHARS));
- gtk_editable_select_region (GTK_EDITABLE (widget_data->name_entry),
+ gtk_editable_select_region (GTK_EDITABLE (name_entry),
start_offset, end_offset);
- /* Update the rename button status */
- file_name_widget_entry_on_changed (widget_data);
+ view->details->popover_coordinator =
+ nautilus_file_name_widget_coordinator_new (GTK_WIDGET (view),
+ popover,
+ error_label,
+ name_entry,
+ activate_button,
+ containing_dir,
+ target_file);
+ g_signal_connect (view->details->popover_coordinator, "name-accepted",
+ G_CALLBACK (rename_file_on_name_accepted),
+ view);
g_object_unref (builder);
@@ -2091,48 +1899,61 @@ static void
nautilus_files_view_new_folder_dialog_new (NautilusFilesView *view,
gboolean with_selection)
{
- FileNameWidgetData *widget_data;
- GtkWidget *label_file_name;
+ NautilusDirectory *containing_dir;
GtkBuilder *builder;
+ GtkWidget *name_label;
+ GtkWidget *dialog;
+ GtkWidget *error_label;
+ GtkWidget *name_entry;
+ GtkWidget *activate_button;
+ NewFolderDialogData *dialog_data;
+
+ if (view->details->dialog_coordinator != NULL) {
+ return;
+ }
+
+ containing_dir = nautilus_directory_get_by_uri (nautilus_files_view_get_backing_uri (view));
builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-create-folder-dialog.ui");
- label_file_name = GTK_WIDGET (gtk_builder_get_object (builder, "name_label"));
-
- widget_data = g_new (FileNameWidgetData, 1);
- widget_data->view = view;
- widget_data->on_name_accepted = create_folder_on_name_accepted;
- widget_data->widget = GTK_WIDGET (gtk_builder_get_object (builder, "create_folder_dialog"));
- widget_data->activate_button = GTK_WIDGET (gtk_builder_get_object (builder, "ok_button"));
- widget_data->error_label = GTK_WIDGET (gtk_builder_get_object (builder, "error_label"));
- widget_data->name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry"));
- widget_data->target_is_folder = TRUE;
- widget_data->target_file = NULL;
- widget_data->with_selection = with_selection;
-
- gtk_window_set_transient_for (GTK_WINDOW (widget_data->widget),
- GTK_WINDOW (nautilus_files_view_get_window (view)));
- /* Connect signals */
- gtk_builder_add_callback_symbols (builder,
- "file_name_widget_entry_on_changed",
- G_CALLBACK (file_name_widget_entry_on_changed),
- "file_name_widget_on_activate",
- G_CALLBACK (file_name_widget_on_activate),
- "create_folder_dialog_on_response",
- G_CALLBACK (create_folder_dialog_on_response),
- NULL);
+ name_label = GTK_WIDGET (gtk_builder_get_object (builder, "name_label"));
+ dialog = GTK_WIDGET (gtk_builder_get_object (builder, "create_folder_dialog"));
+ error_label = GTK_WIDGET (gtk_builder_get_object (builder, "error_label"));
+ name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry"));
+ activate_button = GTK_WIDGET (gtk_builder_get_object (builder, "ok_button"));
+
+ gtk_window_set_transient_for (GTK_WINDOW (dialog),
+ GTK_WINDOW (nautilus_files_view_get_window (view)));
- gtk_builder_connect_signals (builder, widget_data);
- gtk_button_set_label (GTK_BUTTON (widget_data->activate_button),
+ gtk_button_set_label (GTK_BUTTON (activate_button),
_("Create"));
- gtk_label_set_text (GTK_LABEL (label_file_name), _("Folder name"));
- gtk_window_set_title (GTK_WINDOW (widget_data->widget), _("New Folder"));
+ gtk_label_set_text (GTK_LABEL (name_label), _("Folder name"));
+ gtk_window_set_title (GTK_WINDOW (dialog), _("New Folder"));
+
+ gtk_widget_show_all (dialog);
+
+ view->details->dialog_coordinator =
+ nautilus_file_name_widget_coordinator_new (GTK_WIDGET (view),
+ dialog,
+ error_label,
+ name_entry,
+ activate_button,
+ containing_dir,
+ NULL);
- gtk_widget_show_all (widget_data->widget);
- /* Update the ok button status */
- file_name_widget_entry_on_changed (widget_data);
+ dialog_data = g_new (NewFolderDialogData, 1);
+ dialog_data->view = view;
+ dialog_data->with_selection = with_selection;
+
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (create_folder_dialog_on_response),
+ dialog_data);
+ g_signal_connect (view->details->dialog_coordinator, "name-accepted",
+ G_CALLBACK (create_folder_on_name_accepted),
+ NULL);
g_object_unref (builder);
+ nautilus_directory_unref (containing_dir);
}
static void
diff --git a/src/resources/ui/nautilus-create-folder-dialog.ui
b/src/resources/ui/nautilus-create-folder-dialog.ui
index e39f5e6..b88a11a 100644
--- a/src/resources/ui/nautilus-create-folder-dialog.ui
+++ b/src/resources/ui/nautilus-create-folder-dialog.ui
@@ -33,8 +33,6 @@
<object class="GtkEntry" id="name_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <signal name="changed" handler="file_name_widget_entry_on_changed" swapped="yes" />
- <signal name="activate" handler="file_name_widget_on_activate" swapped="yes" />
</object>
<packing>
<property name="expand">False</property>
diff --git a/src/resources/ui/nautilus-rename-file-popover.ui
b/src/resources/ui/nautilus-rename-file-popover.ui
index ff60a97..8575208 100644
--- a/src/resources/ui/nautilus-rename-file-popover.ui
+++ b/src/resources/ui/nautilus-rename-file-popover.ui
@@ -28,7 +28,6 @@
<object class="GtkEntry" id="name_entry">
<property name="visible">True</property>
<property name="activates-default">True</property>
- <signal name="changed" handler="file_name_widget_entry_on_changed" swapped="yes" />
</object>
<packing>
<property name="left-attach">0</property>
@@ -42,7 +41,6 @@
<property name="label" translatable="yes">_Rename</property>
<property name="use_underline">True</property>
<property name="can_default">True</property>
- <signal name="clicked" handler="file_name_widget_on_activate" swapped="yes" />
<style>
<class name="suggested-action"/>
</style>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]