[nautilus] file-name-widgets: use a revealer to display errors



commit d0934dbe5364581b53b529e8d91917e8fabe2f9e
Author: Razvan Chitu <razvan ch95 gmail com>
Date:   Mon Aug 22 15:12:18 2016 +0300

    file-name-widgets: use a revealer to display errors
    
    Each file name widget has an error label for displaying error messages. However,
    when there is no error, the label just takes up space for no reason. In order to
    fix this, use a revealer to display error messages.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=770199

 src/nautilus-compress-dialog-controller.c         |    3 ++
 src/nautilus-file-name-widget-controller.c        |   22 ++++++++++++++++++++-
 src/nautilus-new-folder-dialog-controller.c       |    3 ++
 src/nautilus-rename-file-popover-controller.c     |    3 ++
 src/resources/ui/nautilus-compress-dialog.ui      |   18 +++++++++++-----
 src/resources/ui/nautilus-create-folder-dialog.ui |   15 ++++++++-----
 src/resources/ui/nautilus-rename-file-popover.ui  |   11 ++++++++-
 7 files changed, 60 insertions(+), 15 deletions(-)
---
diff --git a/src/nautilus-compress-dialog-controller.c b/src/nautilus-compress-dialog-controller.c
index 9a31e65..ea4a78a 100644
--- a/src/nautilus-compress-dialog-controller.c
+++ b/src/nautilus-compress-dialog-controller.c
@@ -191,6 +191,7 @@ nautilus_compress_dialog_controller_new (GtkWindow         *parent_window,
         NautilusCompressDialogController *self;
         g_autoptr (GtkBuilder) builder;
         GtkWidget *compress_dialog;
+        GtkWidget *error_revealer;
         GtkWidget *error_label;
         GtkWidget *name_entry;
         GtkWidget *activate_button;
@@ -202,6 +203,7 @@ nautilus_compress_dialog_controller_new (GtkWindow         *parent_window,
 
         builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-compress-dialog.ui");
         compress_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "compress_dialog"));
+        error_revealer = GTK_WIDGET (gtk_builder_get_object (builder, "error_revealer"));
         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, "activate_button"));
@@ -214,6 +216,7 @@ nautilus_compress_dialog_controller_new (GtkWindow         *parent_window,
                                       parent_window);
 
         self = g_object_new (NAUTILUS_TYPE_COMPRESS_DIALOG_CONTROLLER,
+                             "error-revealer", error_revealer,
                              "error-label", error_label,
                              "name-entry", name_entry,
                              "activate-button", activate_button,
diff --git a/src/nautilus-file-name-widget-controller.c b/src/nautilus-file-name-widget-controller.c
index 6f0e4c0..0eb4745 100644
--- a/src/nautilus-file-name-widget-controller.c
+++ b/src/nautilus-file-name-widget-controller.c
@@ -6,6 +6,7 @@
 #define FILE_NAME_DUPLICATED_LABEL_TIMEOUT 500
 
 typedef struct {
+        GtkWidget *error_revealer;
         GtkWidget *error_label;
         GtkWidget *name_entry;
         GtkWidget *activate_button;
@@ -22,7 +23,8 @@ enum {
 };
 
 enum {
-        PROP_ERROR_LABEL = 1,
+        PROP_ERROR_REVEALER = 1,
+        PROP_ERROR_LABEL,
         PROP_NAME_ENTRY,
         PROP_ACTION_BUTTON,
         PROP_CONTAINING_DIRECTORY,
@@ -108,6 +110,9 @@ duplicated_file_label_show (NautilusFileNameWidgetController *self)
                                      _("A file with that name already exists."));
         }
 
+        gtk_revealer_set_reveal_child (GTK_REVEALER (priv->error_revealer),
+                                       TRUE);
+
         priv->duplicated_label_timeout_id = 0;
 
         return G_SOURCE_REMOVE;
@@ -130,6 +135,8 @@ file_name_widget_controller_process_new_name (NautilusFileNameWidgetController *
                                                                           &error_message);
 
         gtk_label_set_label (GTK_LABEL (priv->error_label), error_message);
+        gtk_revealer_set_reveal_child (GTK_REVEALER (priv->error_revealer),
+                                       error_message != NULL);
 
         existing_file = nautilus_directory_get_file_by_name (priv->containing_directory, name);
         *duplicated_name = existing_file != NULL &&
@@ -259,6 +266,9 @@ nautilus_file_name_widget_controller_set_property (GObject      *object,
         priv = nautilus_file_name_widget_controller_get_instance_private (controller);
 
         switch (prop_id) {
+                case PROP_ERROR_REVEALER:
+                        priv->error_revealer = GTK_WIDGET (g_value_get_object (value));
+                        break;
                 case PROP_ERROR_LABEL:
                         priv->error_label = GTK_WIDGET (g_value_get_object (value));
                         break;
@@ -350,6 +360,16 @@ nautilus_file_name_widget_controller_class_init (NautilusFileNameWidgetControlle
 
         g_object_class_install_property (
                 object_class,
+                PROP_ERROR_REVEALER,
+                g_param_spec_object ("error-revealer",
+                                     "Error Revealer",
+                                     "The error label revealer",
+                                     GTK_TYPE_WIDGET,
+                                     G_PARAM_WRITABLE |
+                                     G_PARAM_CONSTRUCT_ONLY));
+
+        g_object_class_install_property (
+                object_class,
                 PROP_ERROR_LABEL,
                 g_param_spec_object ("error-label",
                                      "Error Label",
diff --git a/src/nautilus-new-folder-dialog-controller.c b/src/nautilus-new-folder-dialog-controller.c
index 51da961..667e82b 100644
--- a/src/nautilus-new-folder-dialog-controller.c
+++ b/src/nautilus-new-folder-dialog-controller.c
@@ -60,6 +60,7 @@ nautilus_new_folder_dialog_controller_new (GtkWindow         *parent_window,
         NautilusNewFolderDialogController *self;
         g_autoptr (GtkBuilder) builder;
         GtkWidget *new_folder_dialog;
+        GtkWidget *error_revealer;
         GtkWidget *error_label;
         GtkWidget *name_entry;
         GtkWidget *activate_button;
@@ -67,6 +68,7 @@ nautilus_new_folder_dialog_controller_new (GtkWindow         *parent_window,
 
         builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-create-folder-dialog.ui");
         new_folder_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "create_folder_dialog"));
+        error_revealer = GTK_WIDGET (gtk_builder_get_object (builder, "error_revealer"));
         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"));
@@ -76,6 +78,7 @@ nautilus_new_folder_dialog_controller_new (GtkWindow         *parent_window,
                                       parent_window);
 
         self = g_object_new (NAUTILUS_TYPE_NEW_FOLDER_DIALOG_CONTROLLER,
+                             "error-revealer", error_revealer,
                              "error-label", error_label,
                              "name-entry", name_entry,
                              "activate-button", activate_button,
diff --git a/src/nautilus-rename-file-popover-controller.c b/src/nautilus-rename-file-popover-controller.c
index 36a7c34..7dfaad6 100644
--- a/src/nautilus-rename-file-popover-controller.c
+++ b/src/nautilus-rename-file-popover-controller.c
@@ -101,6 +101,7 @@ nautilus_rename_file_popover_controller_new (NautilusFile *target_file,
         NautilusRenameFilePopoverController *self;
         g_autoptr (GtkBuilder) builder;
         GtkWidget *rename_file_popover;
+        GtkWidget *error_revealer;
         GtkWidget *error_label;
         GtkWidget *name_entry;
         GtkWidget *activate_button;
@@ -112,6 +113,7 @@ nautilus_rename_file_popover_controller_new (NautilusFile *target_file,
 
         builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-rename-file-popover.ui");
         rename_file_popover = GTK_WIDGET (gtk_builder_get_object (builder, "rename_file_popover"));
+        error_revealer = GTK_WIDGET (gtk_builder_get_object (builder, "error_revealer"));
         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"));
@@ -129,6 +131,7 @@ nautilus_rename_file_popover_controller_new (NautilusFile *target_file,
         }
 
         self = g_object_new (NAUTILUS_TYPE_RENAME_FILE_POPOVER_CONTROLLER,
+                             "error-revealer", error_revealer,
                              "error-label", error_label,
                              "name-entry", name_entry,
                              "activate-button", activate_button,
diff --git a/src/resources/ui/nautilus-compress-dialog.ui b/src/resources/ui/nautilus-compress-dialog.ui
index 0aa9f11..8ca0196 100644
--- a/src/resources/ui/nautilus-compress-dialog.ui
+++ b/src/resources/ui/nautilus-compress-dialog.ui
@@ -42,12 +42,15 @@
           </packing>
         </child>
         <child>
-          <object class="GtkLabel" id="error_label">
-            <property name="visible">True</property>
-            <property name="xalign">0</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
+          <object class="GtkRevealer" id="error_revealer">
+            <child>
+              <object class="GtkLabel" id="error_label">
+                <property name="margin_top">4</property>
+                <property name="margin_bottom">4</property>
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+              </object>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -109,6 +112,9 @@
           <object class="GtkLabel" id="description_label">
             <property name="visible">True</property>
             <property name="xalign">0</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
           </object>
           <packing>
             <property name="expand">False</property>
diff --git a/src/resources/ui/nautilus-create-folder-dialog.ui 
b/src/resources/ui/nautilus-create-folder-dialog.ui
index 1e044bf..818ae08 100644
--- a/src/resources/ui/nautilus-create-folder-dialog.ui
+++ b/src/resources/ui/nautilus-create-folder-dialog.ui
@@ -40,12 +40,15 @@
           </packing>
         </child>
         <child>
-          <object class="GtkLabel" id="error_label">
-            <property name="visible">True</property>
-            <property name="xalign">0</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
+          <object class="GtkRevealer" id="error_revealer">
+            <child>
+              <object class="GtkLabel" id="error_label">
+                <property name="margin_top">4</property>
+                <property name="margin_bottom">4</property>
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+              </object>
+            </child>
           </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 fb10559..f5ab036 100644
--- a/src/resources/ui/nautilus-rename-file-popover.ui
+++ b/src/resources/ui/nautilus-rename-file-popover.ui
@@ -48,9 +48,16 @@
           </packing>
         </child>
         <child>
-          <object class="GtkLabel" id="error_label">
+          <object class="GtkRevealer" id="error_revealer">
             <property name="visible">True</property>
-            <property name="halign">start</property>
+            <child>
+              <object class="GtkLabel" id="error_label">
+                <property name="margin_top">4</property>
+                <property name="margin_bottom">4</property>
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+              </object>
+            </child>
           </object>
           <packing>
             <property name="left-attach">0</property>


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