[gnome-text-editor] document: be more resilient and check current suffix



commit a558ebf558b2168b5bf391806fd7614a1f9d74f1
Author: Christian Hergert <chergert redhat com>
Date:   Fri May 20 16:12:22 2022 -0700

    document: be more resilient and check current suffix

 src/editor-document.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/src/editor-document.c b/src/editor-document.c
index 6e9d4b9..edb5783 100644
--- a/src/editor-document.c
+++ b/src/editor-document.c
@@ -22,9 +22,10 @@
 
 #include "config.h"
 
-#include <glib/gi18n.h>
 #include <string.h>
 
+#include <glib/gi18n.h>
+
 #include "editor-application.h"
 #include "editor-buffer-monitor-private.h"
 #include "editor-document-private.h"
@@ -2204,6 +2205,7 @@ _editor_document_suggest_filename (EditorDocument *self)
   GtkSourceLanguage *lang;
   const char *suggested_name = NULL;
   const char *suggested_suffix = NULL;
+  const char *current_suffix;
 
   g_assert (EDITOR_IS_DOCUMENT (self));
 
@@ -2216,12 +2218,20 @@ _editor_document_suggest_filename (EditorDocument *self)
   if (suggested_name != NULL)
     return g_strdup (suggested_name);
 
+  if (suggested_suffix == NULL)
+    suggested_suffix = ".txt";
+
   title = editor_document_dup_title (self);
 
-  if (suggested_suffix == NULL)
-    return g_strdup_printf ("%s.txt", title);
+  if (title == NULL)
+    title = g_strdup (_("New Document"));
+
+  current_suffix = strrchr (title, '.');
+
+  if (g_strcmp0 (current_suffix, suggested_suffix) == 0)
+    return g_steal_pointer (&title);
 
-  return g_strdup_printf ("%s.%s", title, suggested_suffix);
+  return g_strdup_printf ("%s%s", title, suggested_suffix);
 }
 
 GFile *


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