[gnome-flashback] desktop: revalidate name before creating new folder



commit d1f8d453486c68889565a84125e02cf6a994526d
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Wed Nov 13 22:07:38 2019 +0200

    desktop: revalidate name before creating new folder

 .../libdesktop/gf-create-folder-dialog.c           | 48 ++++++++++++++--------
 1 file changed, 30 insertions(+), 18 deletions(-)
---
diff --git a/gnome-flashback/libdesktop/gf-create-folder-dialog.c 
b/gnome-flashback/libdesktop/gf-create-folder-dialog.c
index 2057453..80c4fc3 100644
--- a/gnome-flashback/libdesktop/gf-create-folder-dialog.c
+++ b/gnome-flashback/libdesktop/gf-create-folder-dialog.c
@@ -43,23 +43,8 @@ static guint dialog_signals[LAST_SIGNAL] = { 0 };
 
 G_DEFINE_TYPE (GfCreateFolderDialog, gf_create_folder_dialog, GTK_TYPE_DIALOG)
 
-static void
-cancel_clicked_cb (GtkWidget            *widget,
-                   GfCreateFolderDialog *self)
-{
-  gtk_widget_destroy (GTK_WIDGET (self));
-}
-
-static void
-create_clicked_cb (GtkWidget            *widget,
-                   GfCreateFolderDialog *self)
-{
-  gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_ACCEPT);
-}
-
-static void
-name_changed_cb (GtkEditable          *editable,
-                 GfCreateFolderDialog *self)
+static gboolean
+is_valid (GfCreateFolderDialog *self)
 {
   GtkRevealer *revealer;
   const char *text;
@@ -125,13 +110,40 @@ name_changed_cb (GtkEditable          *editable,
 
   g_free (validate_error);
   g_free (folder_name);
+
+  return valid;
+}
+
+static void
+cancel_clicked_cb (GtkWidget            *widget,
+                   GfCreateFolderDialog *self)
+{
+  gtk_widget_destroy (GTK_WIDGET (self));
+}
+
+static void
+create_clicked_cb (GtkWidget            *widget,
+                   GfCreateFolderDialog *self)
+{
+  if (!is_valid (self))
+    return;
+
+  gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_ACCEPT);
+}
+
+static void
+name_changed_cb (GtkEditable          *editable,
+                 GfCreateFolderDialog *self)
+{
+  is_valid (self);
 }
 
 static void
 name_activate_cb (GtkWidget            *widget,
                   GfCreateFolderDialog *self)
 {
-  if (!gtk_widget_get_sensitive (self->create_button))
+  if (!gtk_widget_get_sensitive (self->create_button) ||
+      !is_valid (self))
     return;
 
   gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_ACCEPT);


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