diff options
author | António Fernandes <antoniof@gnome.org> | 2018-07-31 18:39:02 +0100 |
---|---|---|
committer | Ernestas Kulik <ernestas.kulik@gmail.com> | 2018-08-02 11:40:32 +0000 |
commit | 1dfc03550ebc0844bc471effe40382a56e87155c (patch) | |
tree | dd64cf0821d4afd811e908811376f4a05c061554 /src | |
parent | 5198b5e2104f7f7a538c6bd03a50f17561ec2ef7 (diff) | |
download | nautilus-1dfc03550ebc0844bc471effe40382a56e87155c.tar.gz |
file-name-widget: Warn when name exceeds size limit
An warning for names exceeding the size limit has been introduced in
122f201dcf356460a30a7b260730bcfc7246a614 for the rename popover.
This would be useful for the compress and new folder dialogs as well.
So, make all file name widget derivatives share this feature.
Diffstat (limited to 'src')
-rw-r--r-- | src/nautilus-compress-dialog-controller.c | 5 | ||||
-rw-r--r-- | src/nautilus-file-name-widget-controller.c | 28 | ||||
-rw-r--r-- | src/nautilus-file-name-widget-controller.h | 2 | ||||
-rw-r--r-- | src/nautilus-new-folder-dialog-controller.c | 5 | ||||
-rw-r--r-- | src/nautilus-rename-file-popover-controller.c | 10 |
5 files changed, 42 insertions, 8 deletions
diff --git a/src/nautilus-compress-dialog-controller.c b/src/nautilus-compress-dialog-controller.c index d551c37bc..34caaf013 100644 --- a/src/nautilus-compress-dialog-controller.c +++ b/src/nautilus-compress-dialog-controller.c @@ -71,6 +71,11 @@ nautilus_compress_dialog_controller_name_is_valid (NautilusFileNameWidgetControl is_valid = FALSE; *error_message = _("An archive cannot be called “..”."); } + else if (nautilus_file_name_widget_controller_is_name_too_long (self, name)) + { + is_valid = FALSE; + *error_message = _("Archive name is too long."); + } if (is_valid && g_str_has_prefix (name, ".")) { diff --git a/src/nautilus-file-name-widget-controller.c b/src/nautilus-file-name-widget-controller.c index eb1007613..30eb4687e 100644 --- a/src/nautilus-file-name-widget-controller.c +++ b/src/nautilus-file-name-widget-controller.c @@ -72,6 +72,29 @@ nautilus_file_name_widget_controller_set_containing_directory (NautilusFileNameW g_object_set (self, "containing-directory", directory, NULL); } +gboolean +nautilus_file_name_widget_controller_is_name_too_long (NautilusFileNameWidgetController *self, + gchar *name) +{ + NautilusFileNameWidgetControllerPrivate *priv; + size_t name_length; + glong max_name_length; + + priv = nautilus_file_name_widget_controller_get_instance_private (self); + name_length = strlen (name); + max_name_length = nautilus_directory_get_max_child_name_length (priv->containing_directory); + + if (max_name_length == -1) + { + /* We don't know, so let's give it a chance */ + return FALSE; + } + else + { + return name_length > max_name_length + 1; + } +} + static gboolean nautilus_file_name_widget_controller_name_is_valid (NautilusFileNameWidgetController *self, gchar *name, @@ -127,6 +150,11 @@ real_name_is_valid (NautilusFileNameWidgetController *self, is_valid = FALSE; *error_message = _("A file cannot be called “..”."); } + else if (nautilus_file_name_widget_controller_is_name_too_long (self, name)) + { + is_valid = FALSE; + *error_message = _("File name is too long."); + } if (is_valid && g_str_has_prefix (name, ".")) { diff --git a/src/nautilus-file-name-widget-controller.h b/src/nautilus-file-name-widget-controller.h index 1bd481c43..a492e2c4e 100644 --- a/src/nautilus-file-name-widget-controller.h +++ b/src/nautilus-file-name-widget-controller.h @@ -48,3 +48,5 @@ gchar * nautilus_file_name_widget_controller_get_new_name (NautilusFileNameWidge void nautilus_file_name_widget_controller_set_containing_directory (NautilusFileNameWidgetController *controller, NautilusDirectory *directory); +gboolean nautilus_file_name_widget_controller_is_name_too_long (NautilusFileNameWidgetController *self, + gchar *name); diff --git a/src/nautilus-new-folder-dialog-controller.c b/src/nautilus-new-folder-dialog-controller.c index 52b6e217b..99dcc2f23 100644 --- a/src/nautilus-new-folder-dialog-controller.c +++ b/src/nautilus-new-folder-dialog-controller.c @@ -64,6 +64,11 @@ nautilus_new_folder_dialog_controller_name_is_valid (NautilusFileNameWidgetContr is_valid = FALSE; *error_message = _("A folder cannot be called “..”."); } + else if (nautilus_file_name_widget_controller_is_name_too_long (self, name)) + { + is_valid = FALSE; + *error_message = _("Folder name is too long."); + } if (is_valid && g_str_has_prefix (name, ".")) { diff --git a/src/nautilus-rename-file-popover-controller.c b/src/nautilus-rename-file-popover-controller.c index e4fd9aa17..c1c049dab 100644 --- a/src/nautilus-rename-file-popover-controller.c +++ b/src/nautilus-rename-file-popover-controller.c @@ -103,18 +103,12 @@ nautilus_rename_file_popover_controller_name_is_valid (NautilusFileNameWidgetCon gchar **error_message) { NautilusRenameFilePopoverController *self; - NautilusDirectory *directory; - glong max_name_length; - size_t name_length; gboolean is_valid; self = NAUTILUS_RENAME_FILE_POPOVER_CONTROLLER (controller); - directory = nautilus_file_get_directory (self->target_file); - name_length = strlen (name); - max_name_length = nautilus_directory_get_max_child_name_length (directory); is_valid = TRUE; - if (name_length == 0) + if (strlen (name) == 0) { is_valid = FALSE; } @@ -154,7 +148,7 @@ nautilus_rename_file_popover_controller_name_is_valid (NautilusFileNameWidgetCon *error_message = _("A file cannot be called “..”."); } } - else if (name_length > max_name_length + 1 && max_name_length != -1) + else if (nautilus_file_name_widget_controller_is_name_too_long (controller, name)) { is_valid = FALSE; if (self->target_is_folder) |