[Xfce4-commits] [xfce/libxfce4ui] 01/01: Add a widget for filename input (Bug #16542)

noreply at xfce.org noreply at xfce.org
Tue Mar 17 11:45:33 CET 2020


This is an automated email from the git hooks/post-receive script.

a   l   e   x       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/libxfce4ui.

commit 8f0ad0c23947545abf249aac56124cde74cdeb0a
Author: Reuben Green <reubengreen73 at gmail.com>
Date:   Thu Mar 12 17:28:34 2020 +0000

    Add a widget for filename input (Bug #16542)
    
    Adds a new widget, XfceFilenameInput, which essentially provides a smart
    version of the GtkEntry widget especially for entering filenames for
    creating
    or renaming files. In such situations it is necessary to check the
    filename
    the user has entered for validity (for example, it cannot be too long or
    contain directory separator characters). The new widget provides this,
    with
    as-you-type error messages to tell the user if the filename they have
    entered
    is not valid.
    
    Co-authored-by: Alexander Schwinn <alexxcons at xfce.org>
---
 libxfce4ui/Makefile.am           |   2 +
 libxfce4ui/libxfce4ui.h          |   1 +
 libxfce4ui/libxfce4ui.symbols    |  12 +
 libxfce4ui/xfce-filename-input.c | 482 +++++++++++++++++++++++++++++++++++++++
 libxfce4ui/xfce-filename-input.h |  56 +++++
 po/POTFILES.in                   |   1 +
 tests/test-ui.c                  |  40 +++-
 7 files changed, 593 insertions(+), 1 deletion(-)

diff --git a/libxfce4ui/Makefile.am b/libxfce4ui/Makefile.am
index 3daa0ab..49edf47 100644
--- a/libxfce4ui/Makefile.am
+++ b/libxfce4ui/Makefile.am
@@ -24,6 +24,7 @@ libxfce4ui_headers = \
 	xfce-gdk-extensions.h \
 	xfce-gtk-extensions.h \
 	xfce-spawn.h \
+	xfce-filename-input.h \
 	xfce-titled-dialog.h \
 	$(libxfce4ui_enum_headers)
 
@@ -47,6 +48,7 @@ libxfce4ui_sources = \
 	xfce-gtk-extensions.c \
 	xfce-sm-client.c \
 	xfce-spawn.c \
+	xfce-filename-input.c \
 	xfce-titled-dialog.c
 
 libxfce4ui_includedir = \
diff --git a/libxfce4ui/libxfce4ui.h b/libxfce4ui/libxfce4ui.h
index 3e0b536..6dc15f8 100644
--- a/libxfce4ui/libxfce4ui.h
+++ b/libxfce4ui/libxfce4ui.h
@@ -29,6 +29,7 @@
 #include <libxfce4ui/xfce-gdk-extensions.h>
 #include <libxfce4ui/xfce-gtk-extensions.h>
 #include <libxfce4ui/xfce-spawn.h>
+#include <libxfce4ui/xfce-filename-input.h>
 #include <libxfce4ui/xfce-sm-client.h>
 #include <libxfce4ui/xfce-titled-dialog.h>
 #include <libxfce4ui/libxfce4ui-enum-types.h>
diff --git a/libxfce4ui/libxfce4ui.symbols b/libxfce4ui/libxfce4ui.symbols
index f8b55d5..169362f 100644
--- a/libxfce4ui/libxfce4ui.symbols
+++ b/libxfce4ui/libxfce4ui.symbols
@@ -101,6 +101,18 @@ xfce_spawn_command_line_on_screen
 #endif
 #endif
 
+/* xfce-filename-input functions */
+#if IN_HEADER(__XFCE_FILENAME_INPUT_H__)
+#if IN_SOURCE(__XFCE_FILENAME_INPUT_C__)
+xfce_filename_input_get_type
+xfce_filename_input_get_text
+xfce_filename_input_check
+xfce_filename_input_get_entry
+xfce_filename_input_sensitise_widget
+xfce_filename_input_desensitise_widget
+#endif
+#endif
+
 /* xfce-sm-client functions */
 #if IN_HEADER(__XFCE_SM_CLIENT_H__)
 #if IN_SOURCE(__XFCE_SM_CLIENT_C__)
diff --git a/libxfce4ui/xfce-filename-input.c b/libxfce4ui/xfce-filename-input.c
new file mode 100644
index 0000000..9c4a705
--- /dev/null
+++ b/libxfce4ui/xfce-filename-input.c
@@ -0,0 +1,482 @@
+/*
+ * Copyright (c) 2020 The Xfce Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+
+/**
+ * SECTION:xfce-filename-input
+ * @title: XfceFilenameInput
+ * @short_description: widget for filename input
+ * @stability: Stable
+ * @include: libxfce4ui/libxfce4ui.h
+ *
+ * A widget to allow filename input for creating or renaming files,
+ * with as-you-type checking for invalid filenames.
+ **/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STDARG_H
+#include <stdarg.h>
+#endif
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <libxfce4util/libxfce4util.h>
+
+#include <libxfce4ui/xfce-filename-input.h>
+#include <libxfce4ui/libxfce4ui-private.h>
+#include <libxfce4ui/libxfce4ui-alias.h>
+
+/* Property identifiers */
+enum
+{
+  PROP_0,
+  PROP_ORIGINAL_FILENAME,
+  PROP_MAX_TEXT_LENGTH,
+  N_PROPERTIES
+};
+
+/* Signal identifiers */
+enum
+{
+  SIG_TEXT_VALID = 0,
+  SIG_TEXT_INVALID,
+  N_SIGS
+};
+
+
+
+static void     xfce_filename_input_set_property  (GObject      *object,
+                                                   guint         prop_id,
+                                                   const GValue *value,
+                                                   GParamSpec   *pspec);
+static void     xfce_filename_input_finalize      (GObject      *object);
+static void     xfce_filename_input_entry_changed (GtkEditable  *editable,
+                                                   gpointer      data);
+static gboolean xfce_filename_input_entry_undo    (GtkWidget    *widget,
+                                                   GdkEvent     *event,
+                                                   gpointer      data);
+
+
+
+struct _XfceFilenameInputClass
+{
+  GtkBoxClass parent;
+
+  /* signals */
+  void (*text_valid)   (XfceFilenameInput *filename_input);
+  void (*text_invalid) (XfceFilenameInput *filename_input);
+};
+
+struct _XfceFilenameInput
+{
+  GtkBox    parent;
+
+  GtkEntry *entry;
+  GtkLabel *label;
+
+  GRegex   *whitespace_regex;
+  GRegex   *dir_sep_regex;
+
+  gint     max_text_length;
+  gchar    *original_filename;
+};
+
+static guint signals[N_SIGS];
+
+G_DEFINE_TYPE (XfceFilenameInput, xfce_filename_input, GTK_TYPE_BOX)
+
+
+
+static void
+xfce_filename_input_class_init (XfceFilenameInputClass *klass)
+{
+  GObjectClass *gobject_class = (GObjectClass *)klass;
+
+  gobject_class->finalize = xfce_filename_input_finalize;
+  gobject_class->set_property = xfce_filename_input_set_property;
+
+  /**
+   * XfceFilenameInput:original-filename:
+   *
+   * The original name of the file, to be used as the initial text
+   * displayed in the GtkEntry. A NULL value indicates no original
+   * filename.
+   *
+   * Since: 4.16
+   *
+   **/
+  g_object_class_install_property (gobject_class,
+      PROP_ORIGINAL_FILENAME,
+      g_param_spec_string ("original-filename",
+                           "original-filename",
+                           "The original filename",
+                           NULL,
+                           G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  /**
+   * XfceFilenameInput:max-text-length:
+   *
+   * The maximum permitted length of a filename. A value of -1
+   * indicates no maximum length.
+   *
+   * Since: 4.16
+   *
+   **/
+  g_object_class_install_property (gobject_class,
+      PROP_MAX_TEXT_LENGTH,
+      g_param_spec_int ("max-text-length",
+                        "max-text-length",
+                        "Maximum permitted length of a filename",
+                        -1, G_MAXINT, -1,
+                        G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  /**
+   * XfceFilenameInput::text-valid:
+   * @filename_input: An #XfceFilenameInput
+   *
+   * Signals that the current text is a valid filename. This signal is
+   * emitted whenever the user changes the text and the result is a valid
+   * filename.
+   *
+   * Since: 4.16
+   *
+   **/
+  signals[SIG_TEXT_VALID] = g_signal_new  ("text-valid",
+                                           G_TYPE_FROM_CLASS (klass),
+                                           G_SIGNAL_RUN_LAST,
+                                           G_STRUCT_OFFSET (XfceFilenameInputClass,
+                                                            text_valid),
+                                           NULL, NULL, NULL,
+                                           G_TYPE_NONE, 0);
+
+  /**
+   * XfceFilenameInput::text-invalid:
+   * @filename_input: An #XfceFilenameInput
+   *
+   * Signals that the current text is not a valid filename. This signal is
+   * emitted whenever the user changes the text and the result is not a valid
+   * filename.
+   *
+   * Since: 4.16
+   *
+   **/
+  signals[SIG_TEXT_VALID] = g_signal_new  ("text-invalid",
+                                           G_TYPE_FROM_CLASS (klass),
+                                           G_SIGNAL_RUN_LAST,
+                                           G_STRUCT_OFFSET (XfceFilenameInputClass,
+                                                            text_invalid),
+                                           NULL, NULL, NULL,
+                                           G_TYPE_NONE, 0);
+}
+
+static void
+xfce_filename_input_init (XfceFilenameInput *filename_input)
+{
+  GError *err = NULL;
+
+  /* by default there is no maximum length for the filename and no original filename */
+  filename_input->max_text_length = -1;
+  filename_input->original_filename = NULL;
+
+  /* compile the regular expressions used to check the input */
+  /* the pattern for whitespace_regex matches if the text starts or ends with whitespace */
+  filename_input->whitespace_regex = g_regex_new ("^\\s|\\s$", 0, 0, &err);
+  filename_input->dir_sep_regex = g_regex_new (G_DIR_SEPARATOR_S, 0, 0, &err);
+
+  gtk_orientable_set_orientation (GTK_ORIENTABLE (filename_input), GTK_ORIENTATION_VERTICAL);
+  gtk_container_set_border_width (GTK_CONTAINER (filename_input), 2);
+
+  /* set up the GtkEntry for the input */
+  filename_input->entry = GTK_ENTRY (gtk_entry_new());
+  gtk_widget_set_hexpand (GTK_WIDGET (filename_input->entry), TRUE);
+  gtk_widget_set_valign (GTK_WIDGET (filename_input->entry), GTK_ALIGN_CENTER);
+  gtk_box_pack_start (GTK_BOX (filename_input), GTK_WIDGET (filename_input->entry), FALSE, FALSE, 0);
+
+  /* set up the GtkLabel to display any error or warning messages */
+  filename_input->label = GTK_LABEL (gtk_label_new(""));
+  gtk_label_set_xalign (filename_input->label, 0.0f);
+  gtk_widget_set_hexpand (GTK_WIDGET (filename_input->label), TRUE);
+  gtk_box_pack_start (GTK_BOX (filename_input), GTK_WIDGET (filename_input->label), FALSE, FALSE, 0);
+
+  /* allow reverting the filename with ctrl + z */
+  g_signal_connect (filename_input->entry, "key-press-event",
+                    G_CALLBACK (xfce_filename_input_entry_undo), filename_input);
+
+  /* set up a callback to check the input text whenever it is changed*/
+  g_signal_connect (filename_input->entry, "changed",
+                    G_CALLBACK (xfce_filename_input_entry_changed), filename_input);
+}
+
+static void
+xfce_filename_input_set_property (GObject      *object,
+                                  guint         prop_id,
+                                  const GValue *value,
+                                  GParamSpec   *pspec)
+{
+  XfceFilenameInput *filename_input = XFCE_FILENAME_INPUT (object);
+  const gchar       *filename;
+
+  switch (prop_id)
+    {
+    case PROP_ORIGINAL_FILENAME:
+      filename =  g_value_get_string (value);
+      if (filename == NULL)
+        return;
+
+      filename_input->original_filename = g_strdup (filename);
+      gtk_entry_set_text (filename_input->entry, filename_input->original_filename);
+
+      break;
+    case PROP_MAX_TEXT_LENGTH:
+      filename_input->max_text_length = g_value_get_int (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+xfce_filename_input_finalize (GObject *object)
+{
+  XfceFilenameInput *filename_input = XFCE_FILENAME_INPUT (object);
+
+  g_regex_unref (filename_input->whitespace_regex);
+  g_regex_unref (filename_input->dir_sep_regex);
+
+  g_free (filename_input->original_filename);
+
+  (*G_OBJECT_CLASS (xfce_filename_input_parent_class)->finalize) (object);
+}
+
+/**
+ * xfce_filename_input_get_text:
+ * @filename_input     : a #XfceFilenameInput instance.
+ *
+ * Gets the current text of the widget.
+ *
+ * Returns: (transfer none): the string representing the current text
+ *
+ * Since: 4.16
+ *
+ **/
+const gchar*
+xfce_filename_input_get_text (XfceFilenameInput *filename_input)
+{
+  g_return_val_if_fail (XFCE_IS_FILENAME_INPUT (filename_input), NULL);
+
+  /* NB the returned string must not be modified or freed,
+     as it belongs to the GtkEntry */
+  return gtk_entry_get_text (filename_input->entry);
+}
+
+/**
+ * xfce_filename_input_check:
+ * @filename_input     : a #XfceFilenameInput instance.
+ *
+ * Forces a check of the current input text even when it has not changed.
+ * This is useful to force the appropriate signal to be sent to indicate
+ * whether the text is a valid filename or not, so that for example any
+ * GtkWidgets whose sensitivity is controlled by this can be correctly updated
+ * when they are first created.
+ *
+ * Since: 4.16
+ *
+ **/
+void
+xfce_filename_input_check (XfceFilenameInput *filename_input)
+{
+  g_return_if_fail (XFCE_IS_FILENAME_INPUT (filename_input));
+
+  g_signal_emit_by_name (filename_input->entry, "changed", 0);
+}
+
+/**
+ * xfce_filename_input_get_entry:
+ * @filename_input     : a #XfceFilenameInput instance.
+ *
+ * Gets the #GtkEntry associated to filename_input
+ *
+ * Returns: (transfer none): A #GtkEntry
+ *
+ * Since: 4.16
+ *
+ **/
+GtkEntry*
+xfce_filename_input_get_entry (XfceFilenameInput *filename_input)
+{
+  g_return_val_if_fail (XFCE_IS_FILENAME_INPUT (filename_input), NULL);
+
+  return filename_input->entry;
+}
+
+/**
+ * xfce_filename_input_sensitise_widget:
+ * @widget     : a #GtkWidget
+ *
+ * A convenience function to be connected as a callback for the  "text-valid" signal
+ * (for example, using g_connect_swapped) for the simple case where the desired effect
+ * of this signal is to set the sensitivity of a single GtkWidget (for example, a GtkButton).
+ *
+ * Since: 4.16
+ *
+ **/
+void
+xfce_filename_input_sensitise_widget (GtkWidget *widget)
+{
+  gtk_widget_set_sensitive (widget, TRUE);
+}
+
+/**
+ * xfce_filename_input_desensitise_widget:
+ * @widget     : a #GtkWidget
+ *
+ * A convenience function to be connected as a callback for the  "text-invalid" signal
+ * (for example, using g_connect_swapped) for the simple case where the desired effect
+ * of this signal is to set the sensitivity of a single GtkWidget (for example, a GtkButton).
+ *
+ * Since: 4.16
+ *
+ **/
+void
+xfce_filename_input_desensitise_widget (GtkWidget *widget)
+{
+  gtk_widget_set_sensitive (widget, FALSE);
+}
+
+static void
+xfce_filename_input_entry_changed (GtkEditable *editable,
+                                   gpointer     data)
+{
+  XfceFilenameInput *filename_input;
+  GtkEntry          *entry;
+  GtkLabel          *label;
+
+  gint               text_length;
+  const gchar       *text;
+  const gchar       *label_text = "";
+  const gchar       *icon_name = NULL;
+  gboolean           new_text_valid = TRUE;
+  gboolean           match_ws, match_ds;
+
+  g_return_if_fail (GTK_IS_ENTRY (editable));
+  entry = GTK_ENTRY (editable);
+
+  g_return_if_fail (XFCE_IS_FILENAME_INPUT (data));
+  filename_input = XFCE_FILENAME_INPUT (data);
+  label = filename_input->label;
+
+  /* get the string representing the current text of the GtkEntry */
+  text_length = gtk_entry_get_text_length (entry);
+  text = gtk_entry_get_text (entry); /* NB this string must not be modified or freed,
+                                        as it belongs to the GtkEntry */
+
+  /*
+   * check whether the string starts or ends with whitespace, or contains the directory
+   * separator
+   */
+  match_ws = g_regex_match (filename_input->whitespace_regex, text, 0, NULL);
+  match_ds = g_regex_match (filename_input->dir_sep_regex, text, 0, NULL);
+
+  if (text_length == 0)
+    {
+      /* the string is empty */
+      icon_name = NULL;
+      label_text = "";
+      new_text_valid = FALSE;
+    }
+  else if (match_ds)
+    {
+      /* the string contains a directory separator */
+      label_text = _("Directory separator illegal in file name");
+      icon_name = "dialog-error";
+      new_text_valid = FALSE;
+    }
+  else if (filename_input->max_text_length != -1 && /* max_text_length = -1 means no maximum */
+          text_length > filename_input->max_text_length)
+    {
+      /* the string is too long */
+      label_text = _("Filename is too long");
+      icon_name = "dialog-error";
+      new_text_valid = FALSE;
+    }
+  else if (match_ws)
+    {
+      /* the string starts or ends with whitespace
+       * this does not make the filename invalid, but we warn the user about it */
+      label_text = _("Filenames should not start or end with a space");
+      icon_name = "dialog-warning";
+      new_text_valid = TRUE;
+    }
+
+  /* update the icon in the GtkEntry and the message in the GtkLabel */
+  gtk_entry_set_icon_from_icon_name (entry,
+                                     GTK_ENTRY_ICON_SECONDARY,
+                                     icon_name);
+  gtk_label_set_text (label, label_text);
+
+  /* send a signal to indicate whether the filename is valid */
+  gtk_entry_set_activates_default (entry, new_text_valid);
+  if (new_text_valid)
+    g_signal_emit_by_name (filename_input, "text-valid", 0);
+  else
+    g_signal_emit_by_name (filename_input, "text-invalid", 0);
+}
+
+static gboolean
+xfce_filename_input_entry_undo (GtkWidget  *widget,
+                                GdkEvent   *event,
+                                gpointer    data)
+{
+  guint              keyval;
+  GdkModifierType    state;
+  XfceFilenameInput *filename_input;
+
+  g_return_val_if_fail (XFCE_IS_FILENAME_INPUT (data), GDK_EVENT_PROPAGATE);
+  filename_input = XFCE_FILENAME_INPUT (data);
+
+  /* if there is no original filename to restore, we are done */
+  if (filename_input->original_filename == NULL)
+    return GDK_EVENT_PROPAGATE;
+
+  /* extract the keyval and state from the event */
+  if (G_UNLIKELY (!gdk_event_get_keyval (event, &keyval) ||
+                  !gdk_event_get_state (event, &state)))
+    return GDK_EVENT_PROPAGATE;
+
+  /* if the user pressed ctrl + z, reset the text to the original filename */
+  if ((state & GDK_CONTROL_MASK) != 0 && keyval == GDK_KEY_z)
+    {
+      gtk_entry_set_text (GTK_ENTRY (widget),
+                          filename_input->original_filename);
+      return GDK_EVENT_STOP;
+    }
+
+  return GDK_EVENT_PROPAGATE;
+}
+
+#define __XFCE_FILENAME_INPUT_C__
+#include <libxfce4ui/libxfce4ui-aliasdef.c>
diff --git a/libxfce4ui/xfce-filename-input.h b/libxfce4ui/xfce-filename-input.h
new file mode 100644
index 0000000..e8982c0
--- /dev/null
+++ b/libxfce4ui/xfce-filename-input.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2020 The Xfce Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+
+#if !defined (LIBXFCE4UI_INSIDE_LIBXFCE4UI_H) && !defined (LIBXFCE4UI_COMPILATION)
+#error "Only <libxfce4ui/libxfce4ui.h> can be included directly, this file is not part of the public API."
+#endif
+
+#ifndef __XFCE_FILENAME_INPUT_H__
+#define __XFCE_FILENAME_INPUT_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+typedef struct _XfceFilenameInputClass XfceFilenameInputClass;
+typedef struct _XfceFilenameInput      XfceFilenameInput;
+
+#define XFCE_TYPE_FILENAME_INPUT             (xfce_filename_input_get_type())
+#define XFCE_FILENAME_INPUT(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), XFCE_TYPE_FILENAME_INPUT, XfceFilenameInput))
+#define XFCE_IS_FILENAME_INPUT(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), XFCE_TYPE_FILENAME_INPUT))
+#define XFCE_FILENAME_INPUT_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),  XFCE_TYPE_FILENAME_INPUT, XfceFilenameInputClass))
+#define XFCE_IS_FILENAME_INPUT_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),  XFCE_TYPE_FILENAME_INPUT))
+#define XFCE_FILENAME_INPUT_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),  XFCE_TYPE_FILENAME_INPUT, XfceFilenameInputClass))
+
+GType        xfce_filename_input_get_type              (void) G_GNUC_CONST;
+
+const gchar *xfce_filename_input_get_text              (XfceFilenameInput *filename_input);
+
+void         xfce_filename_input_check                 (XfceFilenameInput *filename_input);
+
+GtkEntry    *xfce_filename_input_get_entry             (XfceFilenameInput *filename_input);
+
+void         xfce_filename_input_sensitise_widget      (GtkWidget         *widget);
+
+void         xfce_filename_input_desensitise_widget    (GtkWidget         *widget);
+
+
+G_END_DECLS
+
+#endif /* !__XFCE_FILENAME_INPUT_H__ */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ef6106c..0448939 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -7,6 +7,7 @@ libxfce4ui/xfce-gdk-extensions.c
 libxfce4ui/xfce-gtk-extensions.c
 libxfce4ui/xfce-sm-client.c
 libxfce4ui/xfce-spawn.c
+libxfce4ui/xfce-filename-input.c
 libxfce4ui/xfce-titled-dialog.c
 
 #
diff --git a/tests/test-ui.c b/tests/test-ui.c
index 2c6dd9f..8dd1740 100644
--- a/tests/test-ui.c
+++ b/tests/test-ui.c
@@ -216,6 +216,39 @@ show_xfce_gdk_screen_get_active (GtkButton *button,
                          monitor_num, gdk_screen_get_n_monitors (screen));
 }
 
+static void
+show_xfce_filename_input_dialog (GtkButton *button,
+                                 gpointer   unused)
+{
+  GtkWidget         *dialog;
+  XfceFilenameInput *filename_input;
+
+  dialog = gtk_dialog_new_with_buttons ("Enter file name",
+                                        NULL,
+                                        GTK_DIALOG_MODAL
+                                        | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                        "Cancel", GTK_RESPONSE_CANCEL,
+                                        "Submit", GTK_RESPONSE_OK,
+                                        NULL);
+  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+  gtk_window_set_default_size (GTK_WINDOW (dialog), 250, -1);
+
+  filename_input = g_object_new (XFCE_TYPE_FILENAME_INPUT,
+                                 "original-filename", "example.txt", "max-text-length", 30, NULL);
+  gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
+                     GTK_WIDGET (filename_input));
+  gtk_widget_show_all (GTK_WIDGET (filename_input));
+
+  g_signal_connect_swapped (filename_input, "text-invalid", G_CALLBACK (xfce_filename_input_desensitise_widget),
+                            gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK));
+  g_signal_connect_swapped (filename_input, "text-valid", G_CALLBACK (xfce_filename_input_sensitise_widget),
+                            gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK));
+  xfce_filename_input_check (filename_input); /* this call ensures that the "Submit" button has its
+                                                sensitivity set correctly */
+  gtk_dialog_run (GTK_DIALOG (dialog));
+  gtk_widget_destroy (dialog);
+}
+
 
 
 static void
@@ -316,7 +349,7 @@ create_main_window (void)
   g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_xfce_titled_dialog_new_with_mixed_buttons), NULL);
 
   /* Other Dialogs */
-  label = gtk_label_new ("Other Dialogs");
+  label = gtk_label_new ("Other Dialogs and Widgets");
   gtk_grid_attach (GTK_GRID (grid), label, 3, 0, 1, 1);
 
   /* xfce_gdk_screen_get_active */
@@ -324,6 +357,11 @@ create_main_window (void)
   gtk_grid_attach (GTK_GRID (grid), button, 3, 1, 1, 1);
   g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_xfce_gdk_screen_get_active), NULL);
 
+  /* xfce_filename_input */
+  button = gtk_button_new_with_label ("XfceFilenameInput");
+  gtk_grid_attach (GTK_GRID (grid), button, 3, 2, 1, 1);
+  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_xfce_filename_input_dialog), NULL);
+
   gtk_widget_show_all (window);
 }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list