From 7340c91230ad9aeae5eb3ae9f20f14ce3eef4b44 Mon Sep 17 00:00:00 2001
From: Reuben Green <reubengreen73@gmail.com>
Date: Sat, 23 May 2020 13:04:50 +0100
Subject: [PATCH] Remove thunar-create-dialog module

remove the separate thunar-create-dialog module and replace it with a
single function in thunar-dialogs

(Merge request !9)
---
 po/POTFILES.in                   |   1 -
 thunar/Makefile.am               |   2 -
 thunar/thunar-application.c      |  11 +-
 thunar/thunar-create-dialog.c    | 467 -------------------------------
 thunar/thunar-create-dialog.h    |  47 ----
 thunar/thunar-dialogs.c          | 169 +++++++++++
 thunar/thunar-dialogs.h          |   4 +
 thunar/thunar-location-buttons.c |  10 +-
 thunar/thunar-standard-view.c    |  25 +-
 thunar/thunar-tree-view.c        |   9 +-
 10 files changed, 199 insertions(+), 546 deletions(-)
 delete mode 100644 thunar/thunar-create-dialog.c
 delete mode 100644 thunar/thunar-create-dialog.h

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 63cc7e660..f97790c1d 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -11,7 +11,6 @@ thunar/thunar-column-editor.c
 thunar/thunar-column-model.c
 thunar/thunar-compact-view.c
 thunar/thunar-component.c
-thunar/thunar-create-dialog.c
 thunar/thunar-dbus-service.c
 thunar/thunar-deep-count-job.c
 thunar/thunar-details-view.c
diff --git a/thunar/Makefile.am b/thunar/Makefile.am
index 3848ebe16..428cf4a43 100644
--- a/thunar/Makefile.am
+++ b/thunar/Makefile.am
@@ -72,8 +72,6 @@ thunar_SOURCES =							\
 	thunar-compact-view.h						\
 	thunar-component.c						\
 	thunar-component.h						\
-	thunar-create-dialog.c						\
-	thunar-create-dialog.h						\
 	thunar-dbus-service.c						\
 	thunar-dbus-service.h						\
 	thunar-deep-count-job.h						\
diff --git a/thunar/thunar-application.c b/thunar/thunar-application.c
index 8730107d0..866c3bdc3 100644
--- a/thunar/thunar-application.c
+++ b/thunar/thunar-application.c
@@ -47,7 +47,6 @@
 
 #include <thunar/thunar-application.h>
 #include <thunar/thunar-browser.h>
-#include <thunar/thunar-create-dialog.h>
 #include <thunar/thunar-dialogs.h>
 #include <thunar/thunar-gdk-extensions.h>
 #include <thunar/thunar-gobject-extensions.h>
@@ -1810,7 +1809,7 @@ thunar_application_create_file (ThunarApplication *application,
   /* TODO pass the startup ID to the rename dialog */
 
   /* ask the user to enter a name for the new folder */
-  name = thunar_show_create_dialog (screen, content_type, dialog_title, title);
+  name = thunar_dialogs_show_create (screen, content_type, dialog_title, title);
   if (G_LIKELY (name != NULL))
     {
       path_list.data = g_file_get_child (thunar_file_get_file (parent_directory), name);
@@ -1867,10 +1866,10 @@ thunar_application_create_file_from_template (ThunarApplication *application,
   /* TODO pass the startup ID to the rename dialog */
 
   /* ask the user to enter a name for the new document */
-  name = thunar_show_create_dialog (screen,
-                                    thunar_file_get_content_type (template_file),
-                                    thunar_file_get_display_name (template_file),
-                                    title);
+  name = thunar_dialogs_show_create (screen,
+                                     thunar_file_get_content_type (template_file),
+                                     thunar_file_get_display_name (template_file),
+                                     title);
   if (G_LIKELY (name != NULL))
     {
       /* fake the target path list */
diff --git a/thunar/thunar-create-dialog.c b/thunar/thunar-create-dialog.c
deleted file mode 100644
index b14d5bb0c..000000000
--- a/thunar/thunar-create-dialog.c
+++ /dev/null
@@ -1,467 +0,0 @@
-/* vi:set et ai sw=2 sts=2 ts=2: */
-/*-
- * Copyright (c) 2005-2006 Benedikt Meurer <benny@xfce.org>
- * Copyright (c) 2009-2010 Jannis Pohlmann <jannis@xfce.org>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program 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 General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <thunar/thunar-abstract-dialog.h>
-#include <thunar/thunar-create-dialog.h>
-#include <thunar/thunar-dialogs.h>
-#include <thunar/thunar-gobject-extensions.h>
-#include <thunar/thunar-gtk-extensions.h>
-#include <thunar/thunar-icon-factory.h>
-#include <thunar/thunar-private.h>
-#include <thunar/thunar-util.h>
-
-
-
-/* Property identifiers */
-enum
-{
-  PROP_0,
-  PROP_FILENAME,
-  PROP_CONTENT_TYPE,
-};
-
-
-
-static void         thunar_create_dialog_dispose          (GObject                 *object);
-static void         thunar_create_dialog_get_property     (GObject                 *object,
-                                                           guint                    prop_id,
-                                                           GValue                  *value,
-                                                           GParamSpec              *pspec);
-static void         thunar_create_dialog_set_property     (GObject                 *object,
-                                                           guint                    prop_id,
-                                                           const GValue            *value,
-                                                           GParamSpec              *pspec);
-static void         thunar_create_dialog_realize          (GtkWidget               *widget);
-static void         thunar_create_dialog_update_image     (ThunarCreateDialog      *dialog);
-static void         thunar_create_dialog_text_changed     (GtkWidget               *entry,
-                                                           ThunarCreateDialog      *dialog);
-static const gchar *thunar_create_dialog_get_filename     (const ThunarCreateDialog *dialog);
-static void         thunar_create_dialog_set_filename     (ThunarCreateDialog       *dialog,
-                                                           const gchar              *filename);
-static void         thunar_create_dialog_set_content_type (ThunarCreateDialog       *dialog,
-                                                           const gchar              *content_type);
-
-
-
-struct _ThunarCreateDialogClass
-{
-  ThunarAbstractDialogClass __parent__;
-};
-
-struct _ThunarCreateDialog
-{
-  ThunarAbstractDialog __parent__;
-
-  GtkWidget  *image;
-  GtkWidget  *entry;
-
-  gchar      *content_type;
-};
-
-
-
-G_DEFINE_TYPE (ThunarCreateDialog, thunar_create_dialog, THUNAR_TYPE_ABSTRACT_DIALOG)
-
-
-
-static void
-thunar_create_dialog_class_init (ThunarCreateDialogClass *klass)
-{
-  GtkWidgetClass *gtkwidget_class;
-  GObjectClass   *gobject_class;
-
-  gobject_class = G_OBJECT_CLASS (klass);
-  gobject_class->dispose = thunar_create_dialog_dispose;
-  gobject_class->get_property = thunar_create_dialog_get_property;
-  gobject_class->set_property = thunar_create_dialog_set_property;
-
-  gtkwidget_class = GTK_WIDGET_CLASS (klass);
-  gtkwidget_class->realize = thunar_create_dialog_realize;
-
-  /**
-   * ThunarCreateDialog::filename:
-   *
-   * The filename entered in the dialog's entry box.
-   **/
-  g_object_class_install_property (gobject_class,
-                                   PROP_FILENAME,
-                                   g_param_spec_string ("filename",
-                                                        "filename",
-                                                        "filename",
-                                                        NULL,
-                                                        EXO_PARAM_READWRITE));
-
-  /**
-   * ThunarCreateDialog::content-type:
-   *
-   * The content type of the file to create.
-   **/
-  g_object_class_install_property (gobject_class,
-                                   PROP_CONTENT_TYPE,
-                                   g_param_spec_string ("content-type",
-                                                        "content-type",
-                                                        "content-type",
-                                                       NULL,
-                                                       EXO_PARAM_READWRITE));
-}
-
-
-
-static void
-thunar_create_dialog_init (ThunarCreateDialog *dialog)
-{
-  GtkWidget *label;
-  GtkWidget *grid;
-
-  dialog->content_type = NULL;
-
-  /* configure the dialog itself */
-  gtk_dialog_add_buttons (GTK_DIALOG (dialog),
-                          _("_Cancel"), GTK_RESPONSE_CANCEL,
-                          _("C_reate"), GTK_RESPONSE_OK,
-                          NULL);
-  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
-  gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
-  gtk_window_set_default_size (GTK_WINDOW (dialog), 300, -1);
-
-  grid = gtk_grid_new ();
-  gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
-  gtk_grid_set_row_spacing (GTK_GRID (grid), 3);
-  gtk_container_set_border_width (GTK_CONTAINER (grid), 6);
-  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), grid, TRUE, TRUE, 0);
-  gtk_widget_show (grid);
-
-  dialog->image = g_object_new (GTK_TYPE_IMAGE, "xpad", 6, "ypad", 6, NULL);
-  gtk_grid_attach (GTK_GRID (grid), dialog->image, 0, 0, 1, 2);
-  gtk_widget_show (dialog->image);
-
-  label = g_object_new (GTK_TYPE_LABEL, "label", _("Enter the name:"), "xalign", 0.0f, "hexpand", TRUE, NULL);
-  gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 1, 1);
-  gtk_widget_show (label);
-
-  dialog->entry = g_object_new (GTK_TYPE_ENTRY, "activates-default", TRUE, "hexpand", TRUE, NULL);
-  g_signal_connect (G_OBJECT (dialog->entry), "changed", G_CALLBACK (thunar_create_dialog_text_changed), dialog);
-  gtk_widget_set_valign (dialog->entry, GTK_ALIGN_CENTER);
-  gtk_grid_attach (GTK_GRID (grid), dialog->entry, 1, 1, 1, 1);
-  thunar_gtk_label_set_a11y_relation (GTK_LABEL (label), dialog->entry);
-  gtk_widget_show (dialog->entry);
-}
-
-
-
-static void
-thunar_create_dialog_dispose (GObject *object)
-{
-  ThunarCreateDialog *dialog = THUNAR_CREATE_DIALOG (object);
-
-  /* release the content type */
-  thunar_create_dialog_set_content_type (dialog, NULL);
-
-  (*G_OBJECT_CLASS (thunar_create_dialog_parent_class)->dispose) (object);
-}
-
-
-
-static void
-thunar_create_dialog_get_property (GObject    *object,
-                                   guint       prop_id,
-                                   GValue     *value,
-                                   GParamSpec *pspec)
-{
-  ThunarCreateDialog *dialog = THUNAR_CREATE_DIALOG (object);
-
-  switch (prop_id)
-    {
-    case PROP_FILENAME:
-      g_value_set_string (value, thunar_create_dialog_get_filename (dialog));
-      break;
-
-    case PROP_CONTENT_TYPE:
-      g_value_set_string (value, dialog->content_type);
-      break;
-
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-    }
-}
-
-
-
-static void
-thunar_create_dialog_set_property (GObject      *object,
-                                   guint         prop_id,
-                                   const GValue *value,
-                                   GParamSpec   *pspec)
-{
-  ThunarCreateDialog *dialog = THUNAR_CREATE_DIALOG (object);
-
-  switch (prop_id)
-    {
-    case PROP_FILENAME:
-      thunar_create_dialog_set_filename (dialog, g_value_get_string (value));
-      break;
-
-    case PROP_CONTENT_TYPE:
-      thunar_create_dialog_set_content_type (dialog, g_value_get_string (value));
-      break;
-
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-    }
-}
-
-
-
-static void
-thunar_create_dialog_realize (GtkWidget *widget)
-{
-  ThunarCreateDialog *dialog = THUNAR_CREATE_DIALOG (widget);
-
-  /* let GtkWidget realize the widget */
-  (*GTK_WIDGET_CLASS (thunar_create_dialog_parent_class)->realize) (widget);
-
-  /* update the image */
-  thunar_create_dialog_update_image (dialog);
-}
-
-
-
-static void
-thunar_create_dialog_update_image (ThunarCreateDialog *dialog)
-{
-  GIcon *icon = NULL;
-
-  /* try to load the icon */
-  if (G_LIKELY (dialog->content_type != NULL))
-    icon = g_content_type_get_icon (dialog->content_type);
-
-  /* setup the image */
-  if (G_LIKELY (icon != NULL))
-    {
-      gtk_image_set_from_gicon (GTK_IMAGE (dialog->image), icon, GTK_ICON_SIZE_DIALOG);
-      g_object_unref (icon);
-      gtk_widget_show (dialog->image);
-    }
-  else
-    gtk_widget_hide (dialog->image);
-}
-
-
-
-static void
-thunar_create_dialog_text_changed (GtkWidget          *entry,
-                                   ThunarCreateDialog *dialog)
-{
-  const gchar *text;
-  const gchar *p;
-
-  _thunar_return_if_fail (GTK_IS_ENTRY (entry));
-  _thunar_return_if_fail (THUNAR_IS_CREATE_DIALOG (dialog));
-  _thunar_return_if_fail (dialog->entry == entry);
-
-  /* verify the new text */
-  text = gtk_entry_get_text (GTK_ENTRY (entry));
-  for (p = text; *p != '\0'; ++p)
-    if (G_UNLIKELY (G_IS_DIR_SEPARATOR (*p)))
-      break;
-
-  /* enable/disable the "OK" button appropriately */
-  gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, (*text != '\0' && *p == '\0'));
-}
-
-
-
-/**
- * thunar_create_dialog_get_filename:
- * @dialog : a #ThunarCreateDialog.
- *
- * Returns the filename currently selected in @dialog.
- *
- * Return value: the filename currently selected in @dialog.
- **/
-const gchar*
-thunar_create_dialog_get_filename (const ThunarCreateDialog *dialog)
-{
-  _thunar_return_val_if_fail (THUNAR_IS_CREATE_DIALOG (dialog), NULL);
-  return gtk_entry_get_text (GTK_ENTRY (dialog->entry));
-}
-
-
-
-/**
- * thunar_create_dialog_set_filename:
- * @dialog   : a #ThunarCreateDialog.
- * @filename : the new filename to set.
- *
- * Sets the filename currently selected in @dialog
- * to the specified @filename.
- **/
-void
-thunar_create_dialog_set_filename (ThunarCreateDialog *dialog,
-                                   const gchar        *filename)
-{
-  const gchar *dot;
-  glong        offset;
-
-  _thunar_return_if_fail (THUNAR_IS_CREATE_DIALOG (dialog));
-  _thunar_return_if_fail (filename != NULL);
-
-  /* setup the new filename */
-  gtk_entry_set_text (GTK_ENTRY (dialog->entry), filename);
-
-  /* check if filename contains a dot */
-  dot = thunar_util_str_get_extension (filename);
-  if (G_LIKELY (dot != NULL))
-    {
-      /* grab focus to the entry first, else
-       * the selection will be altered later
-       * when the focus is transferred.
-       */
-      gtk_widget_grab_focus (dialog->entry);
-
-      /* determine the UTF-8 char offset */
-      offset = g_utf8_pointer_to_offset (filename, dot);
-
-      /* select the text prior to the dot */
-      if (G_LIKELY (offset > 0))
-        gtk_editable_select_region (GTK_EDITABLE (dialog->entry), 0, offset);
-    }
-  else
-    {
-      /* select the whole file name */
-      gtk_editable_select_region (GTK_EDITABLE (dialog->entry), 0, -1);
-    }
-
-  /* notify listeners */
-  g_object_notify (G_OBJECT (dialog), "filename");
-}
-
-
-
-/**
- * thunar_create_dialog_set_content_type:
- * @dialog       : a #ThunarCreateDialog.
- * @content_type : the new content type.
- *
- * Set the content type for @dialog to @content_type.
- **/
-void
-thunar_create_dialog_set_content_type (ThunarCreateDialog *dialog,
-                                       const gchar        *content_type)
-{
-  _thunar_return_if_fail (THUNAR_IS_CREATE_DIALOG (dialog));
-
-  /* release the previous content type */
-  g_free (dialog->content_type);
-
-  /* set the new content type */
-  dialog->content_type = g_strdup (content_type);
-
-  /* update the image if we're already realized */
-  if (gtk_widget_get_realized (GTK_WIDGET (dialog)))
-    thunar_create_dialog_update_image (dialog);
-
-  /* notify listeners */
-  g_object_notify (G_OBJECT (dialog), "content-type");
-}
-
-
-
-/**
- * thunar_show_create_dialog:
- * @parent       : a #GdkScreen, a #GtkWidget or %NULL.
- * @content_type : the content type of the file or folder to create.
- * @filename     : the suggested filename or %NULL.
- * @title        : the dialog title.
- *
- * Constructs and display a #ThunarCreateDialog with the specified
- * parameters that asks the user to enter a name for a new file or
- * folder.
- *
- * The caller is responsible to free the returned filename using
- * g_free() when no longer needed.
- *
- * Return value: the filename entered by the user or %NULL if the user
- *               cancelled the dialog.
- **/
-gchar*
-thunar_show_create_dialog (gpointer     parent,
-                           const gchar *content_type,
-                           const gchar *filename,
-                           const gchar *title)
-{
-  GtkWidget *dialog;
-  GtkWindow *window;
-  GdkScreen *screen;
-  GError    *error = NULL;
-  gchar     *name = NULL;
-
-  _thunar_return_val_if_fail (parent == NULL || GDK_IS_SCREEN (parent) || GTK_IS_WIDGET (parent), NULL);
-
-  /* parse the parent window and screen */
-  screen = thunar_util_parse_parent (parent, &window);
-
-  /* display the create dialog */
-  dialog = g_object_new (THUNAR_TYPE_CREATE_DIALOG,
-                         "destroy-with-parent", TRUE,
-                         "filename", filename,
-                         "content-type", content_type,
-                         "modal", TRUE,
-                         "title", title,
-                         NULL);
-
-  if (screen != NULL)
-    gtk_window_set_screen (GTK_WINDOW (dialog), screen);
-
-  if (window != NULL)
-    gtk_window_set_transient_for (GTK_WINDOW (dialog), window);
-
-  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
-    {
-      /* determine the chosen filename */
-      filename = thunar_create_dialog_get_filename (THUNAR_CREATE_DIALOG (dialog));
-
-      /* convert the UTF-8 filename to the local file system encoding */
-      name = g_filename_from_utf8 (filename, -1, NULL, NULL, &error);
-      if (G_UNLIKELY (name == NULL))
-        {
-          /* display an error message */
-          thunar_dialogs_show_error (dialog, error, _("Cannot convert filename \"%s\" to the local encoding"), filename);
-
-          /* release the error */
-          g_error_free (error);
-        }
-    }
-
-  /* destroy the dialog */
-  gtk_widget_destroy (dialog);
-
-  return name;
-}
-
-
-
-
diff --git a/thunar/thunar-create-dialog.h b/thunar/thunar-create-dialog.h
deleted file mode 100644
index 6c5db7f69..000000000
--- a/thunar/thunar-create-dialog.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/* vi:set et ai sw=2 sts=2 ts=2: */
-/*-
- * Copyright (c) 2005-2006 Benedikt Meurer <benny@xfce.org>
- * Copyright (c) 2009-2010 Jannis Pohlmann <jannis@xfce.org>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program 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 General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#ifndef __THUNAR_CREATE_DIALOG_H__
-#define __THUNAR_CREATE_DIALOG_H__
-
-#include <gtk/gtk.h>
-
-G_BEGIN_DECLS;
-
-typedef struct _ThunarCreateDialogClass ThunarCreateDialogClass;
-typedef struct _ThunarCreateDialog      ThunarCreateDialog;
-
-#define THUNAR_TYPE_CREATE_DIALOG             (thunar_create_dialog_get_type ())
-#define THUNAR_CREATE_DIALOG(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), THUNAR_TYPE_CREATE_DIALOG, ThunarCreateDialog))
-#define THUNAR_CREATE_DIALOG_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), THUNAR_TYPE_CREATE_DIALOG, ThunarCreateDialogClass))
-#define THUNAR_IS_CREATE_DIALOG(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THUNAR_TYPE_CREATE_DIALOG))
-#define THUNAR_IS_CREATE_DIALOG_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_TYPE_CREATE_DIALOG))
-#define THUNAR_CREATE_DIALOG_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_CREATE_DIALOG, ThunarCreateDialogClass))
-
-GType  thunar_create_dialog_get_type (void) G_GNUC_CONST;
-
-gchar *thunar_show_create_dialog     (gpointer     parent,
-                                      const gchar *content_type,
-                                      const gchar *filename,
-                                      const gchar *title) G_GNUC_MALLOC;
-
-G_END_DECLS;
-
-#endif /* !__THUNAR_CREATE_DIALOG_H__ */
diff --git a/thunar/thunar-dialogs.c b/thunar/thunar-dialogs.c
index 947a4215e..c1949b09f 100644
--- a/thunar/thunar-dialogs.c
+++ b/thunar/thunar-dialogs.c
@@ -33,6 +33,7 @@
 #endif
 
 #include <thunar/thunar-dialogs.h>
+#include <thunar/thunar-gtk-extensions.h>
 #include <thunar/thunar-icon-factory.h>
 #include <thunar/thunar-io-jobs.h>
 #include <thunar/thunar-job.h>
@@ -51,6 +52,174 @@ static gboolean      thunar_dialogs_entry_undo           (GtkWidget  *widget,
 
 
 
+static void
+thunar_create_dialog_text_changed (GtkWidget *entry,
+                                   GtkWidget *dialog)
+{
+  const gchar *text;
+  const gchar *p;
+
+  _thunar_return_if_fail (GTK_IS_ENTRY (entry));
+  _thunar_return_if_fail (GTK_IS_DIALOG (dialog));
+
+  /* verify the new text */
+  text = gtk_entry_get_text (GTK_ENTRY (entry));
+  for (p = text; *p != '\0'; ++p)
+    if (G_UNLIKELY (G_IS_DIR_SEPARATOR (*p)))
+      break;
+
+  /* enable/disable the "OK" button appropriately */
+  gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, (*text != '\0' && *p == '\0'));
+}
+
+
+
+/**
+ * thunar_dialogs_show_create:
+ * @parent       : a #GdkScreen, a #GtkWidget or %NULL.
+ * @content_type : the content type of the file or folder to create.
+ * @filename     : the suggested filename or %NULL.
+ * @title        : the dialog title.
+ *
+ * Displays a Thunar create dialog  with the specified
+ * parameters that asks the user to enter a name for a new file or
+ * folder.
+ *
+ * The caller is responsible to free the returned filename using
+ * g_free() when no longer needed.
+ *
+ * Return value: the filename entered by the user or %NULL if the user
+ *               cancelled the dialog.
+ **/
+gchar*
+thunar_dialogs_show_create (gpointer     parent,
+                            const gchar *content_type,
+                            const gchar *filename,
+                            const gchar *title)
+{
+  GtkWidget   *dialog;
+  GtkWindow   *window;
+  GdkScreen   *screen;
+  GError      *error = NULL;
+  gchar       *name = NULL;
+  GtkWidget   *label;
+  GtkWidget   *grid;
+  GtkWidget   *image;
+  GtkWidget   *entry;
+  const gchar *dot;
+  glong        offset;
+  GIcon       *icon = NULL;
+
+  _thunar_return_val_if_fail (parent == NULL || GDK_IS_SCREEN (parent) || GTK_IS_WIDGET (parent), NULL);
+
+  /* parse the parent window and screen */
+  screen = thunar_util_parse_parent (parent, &window);
+
+  /* create a new dialog window */
+  dialog = gtk_dialog_new_with_buttons (title,
+                                        window,
+                                        GTK_DIALOG_MODAL
+                                        | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                        _("_Cancel"), GTK_RESPONSE_CANCEL,
+                                        _("C_reate"), GTK_RESPONSE_OK,
+                                        NULL);
+
+  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+  gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
+  gtk_window_set_default_size (GTK_WINDOW (dialog), 300, -1);
+
+  grid = gtk_grid_new ();
+  gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
+  gtk_grid_set_row_spacing (GTK_GRID (grid), 3);
+  gtk_container_set_border_width (GTK_CONTAINER (grid), 6);
+  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), grid, TRUE, TRUE, 0);
+  gtk_widget_show (grid);
+
+  /* try to load the icon */
+  if (G_LIKELY (content_type != NULL))
+    icon = g_content_type_get_icon (content_type);
+
+  /* setup the image */
+  if (G_LIKELY (icon != NULL))
+    {
+      image = g_object_new (GTK_TYPE_IMAGE, "xpad", 6, "ypad", 6, NULL);
+      gtk_image_set_from_gicon (GTK_IMAGE (image), icon, GTK_ICON_SIZE_DIALOG);
+      gtk_grid_attach (GTK_GRID (grid), image, 0, 0, 1, 2);
+      g_object_unref (icon);
+      gtk_widget_show (image);
+    }
+
+  label = g_object_new (GTK_TYPE_LABEL, "label", _("Enter the name:"), "xalign", 0.0f, "hexpand", TRUE, NULL);
+  gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 1, 1);
+  gtk_widget_show (label);
+
+  entry = g_object_new (GTK_TYPE_ENTRY, "activates-default", TRUE, "hexpand", TRUE, NULL);
+  g_signal_connect (G_OBJECT (entry), "changed", G_CALLBACK (thunar_create_dialog_text_changed), dialog);
+  gtk_widget_set_valign (entry, GTK_ALIGN_CENTER);
+  gtk_grid_attach (GTK_GRID (grid), entry, 1, 1, 1, 1);
+  thunar_gtk_label_set_a11y_relation (GTK_LABEL (label), entry);
+  gtk_widget_show (entry);
+
+  if (filename == NULL)
+    filename = "";
+
+  /* put the filename in the entry */
+  gtk_entry_set_text (GTK_ENTRY (entry), filename);
+
+  /* check if filename contains a dot */
+  dot = thunar_util_str_get_extension (filename);
+  if (G_LIKELY (dot != NULL))
+    {
+      /* grab focus to the entry first, else
+       * the selection will be altered later
+       * when the focus is transferred.
+       */
+      gtk_widget_grab_focus (entry);
+
+      /* determine the UTF-8 char offset */
+      offset = g_utf8_pointer_to_offset (filename, dot);
+
+      /* select the text prior to the dot */
+      if (G_LIKELY (offset > 0))
+        gtk_editable_select_region (GTK_EDITABLE (entry), 0, offset);
+    }
+  else
+    {
+      /* select the whole file name */
+      gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
+    }
+
+  if (screen != NULL)
+    gtk_window_set_screen (GTK_WINDOW (dialog), screen);
+
+  if (window != NULL)
+    gtk_window_set_transient_for (GTK_WINDOW (dialog), window);
+
+  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
+    {
+      /* determine the chosen filename */
+      filename = gtk_entry_get_text (GTK_ENTRY (entry));;
+
+      /* convert the UTF-8 filename to the local file system encoding */
+      name = g_filename_from_utf8 (filename, -1, NULL, NULL, &error);
+      if (G_UNLIKELY (name == NULL))
+        {
+          /* display an error message */
+          thunar_dialogs_show_error (dialog, error, _("Cannot convert filename \"%s\" to the local encoding"), filename);
+
+          /* release the error */
+          g_error_free (error);
+        }
+    }
+
+  /* destroy the dialog */
+  gtk_widget_destroy (dialog);
+
+  return name;
+}
+
+
+
 /**
  * thunar_dialogs_show_rename_file:
  * @parent : a #GtkWidget on which the error dialog should be shown, or a #GdkScreen
diff --git a/thunar/thunar-dialogs.h b/thunar/thunar-dialogs.h
index 1b29623a4..27dd73ec0 100644
--- a/thunar/thunar-dialogs.h
+++ b/thunar/thunar-dialogs.h
@@ -26,6 +26,10 @@
 
 G_BEGIN_DECLS;
 
+gchar             *thunar_dialogs_show_create           (gpointer              parent,
+                                                         const gchar          *content_type,
+                                                         const gchar          *filename,
+                                                         const gchar          *title);
 ThunarJob         *thunar_dialogs_show_rename_file      (gpointer              parent,
                                                          ThunarFile           *file);
 void               thunar_dialogs_show_about            (GtkWindow            *parent,
diff --git a/thunar/thunar-location-buttons.c b/thunar/thunar-location-buttons.c
index eed9dffac..8b44189cf 100644
--- a/thunar/thunar-location-buttons.c
+++ b/thunar/thunar-location-buttons.c
@@ -27,7 +27,7 @@
 
 #include <thunar/thunar-application.h>
 #include <thunar/thunar-clipboard-manager.h>
-#include <thunar/thunar-create-dialog.h>
+#include <thunar/thunar-dialogs.h>
 #include <thunar/thunar-gio-extensions.h>
 #include <thunar/thunar-gobject-extensions.h>
 #include <thunar/thunar-gtk-extensions.h>
@@ -1342,10 +1342,10 @@ G_GNUC_END_IGNORE_DEPRECATIONS
     return;
 
   /* ask the user to enter a name for the new folder */
-  name = thunar_show_create_dialog (GTK_WIDGET (buttons),
-                                    "inode/directory",
-                                    _("New Folder"),
-                                    _("Create New Folder"));
+  name = thunar_dialogs_show_create (GTK_WIDGET (buttons),
+                                     "inode/directory",
+                                     _("New Folder"),
+                                     _("Create New Folder"));
   if (G_LIKELY (name != NULL))
     {
       /* fake the path list */
diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c
index c9f0e1b33..a80ebd23e 100644
--- a/thunar/thunar-standard-view.c
+++ b/thunar/thunar-standard-view.c
@@ -33,7 +33,6 @@
 #include <gdk/gdkkeysyms.h>
 
 #include <thunar/thunar-application.h>
-#include <thunar/thunar-create-dialog.h>
 #include <thunar/thunar-dialogs.h>
 #include <thunar/thunar-dnd.h>
 #include <thunar/thunar-enum-types.h>
@@ -2355,10 +2354,10 @@ G_GNUC_END_IGNORE_DEPRECATIONS
   _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view));
 
   /* ask the user to enter a name for the new empty file */
-  name = thunar_show_create_dialog (GTK_WIDGET (standard_view),
-                                    "text/plain",
-                                    _("New Empty File"),
-                                    _("New Empty File..."));
+  name = thunar_dialogs_show_create (GTK_WIDGET (standard_view),
+                                     "text/plain",
+                                     _("New Empty File"),
+                                     _("New Empty File..."));
   if (G_LIKELY (name != NULL))
     {
       /* determine the ThunarFile for the current directory */
@@ -2401,10 +2400,10 @@ G_GNUC_END_IGNORE_DEPRECATIONS
   _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view));
 
   /* ask the user to enter a name for the new folder */
-  name = thunar_show_create_dialog (GTK_WIDGET (standard_view),
-                                    "inode/directory",
-                                    _("New Folder"),
-                                    _("Create New Folder"));
+  name = thunar_dialogs_show_create (GTK_WIDGET (standard_view),
+                                     "inode/directory",
+                                     _("New Folder"),
+                                     _("Create New Folder"));
   if (G_LIKELY (name != NULL))
     {
       /* determine the ThunarFile for the current directory */
@@ -2454,10 +2453,10 @@ G_GNUC_END_IGNORE_DEPRECATIONS
                            thunar_file_get_display_name (file));
 
   /* ask the user to enter a name for the new document */
-  name = thunar_show_create_dialog (GTK_WIDGET (standard_view),
-                                    thunar_file_get_content_type (THUNAR_FILE (file)),
-                                    thunar_file_get_display_name (file),
-                                    title);
+  name = thunar_dialogs_show_create (GTK_WIDGET (standard_view),
+                                     thunar_file_get_content_type (THUNAR_FILE (file)),
+                                     thunar_file_get_display_name (file),
+                                     title);
   if (G_LIKELY (name != NULL))
     {
       /* determine the ThunarFile for the current directory */
diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c
index 337775900..ff572dc25 100644
--- a/thunar/thunar-tree-view.c
+++ b/thunar/thunar-tree-view.c
@@ -27,7 +27,6 @@
 
 #include <thunar/thunar-application.h>
 #include <thunar/thunar-clipboard-manager.h>
-#include <thunar/thunar-create-dialog.h>
 #include <thunar/thunar-device.h>
 #include <thunar/thunar-dialogs.h>
 #include <thunar/thunar-dnd.h>
@@ -1771,10 +1770,10 @@ thunar_tree_view_action_create_folder (ThunarTreeView *view)
     return;
 
   /* ask the user to enter a name for the new folder */
-  name = thunar_show_create_dialog (GTK_WIDGET (view),
-                                    "inode/directory",
-                                    _("New Folder"),
-                                    _("Create New Folder"));
+  name = thunar_dialogs_show_create (GTK_WIDGET (view),
+                                     "inode/directory",
+                                     _("New Folder"),
+                                     _("Create New Folder"));
   if (G_LIKELY (name != NULL))
     {
       /* fake the path list */
-- 
GitLab