[gedit] Window: *_default_location() -> *_file_chooser_folder_uri()



commit 45b65dfd785511e790d5c42586ffb6d890158696
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Jun 7 02:18:16 2020 +0200

    Window: *_default_location() -> *_file_chooser_folder_uri()

 gedit/gedit-commands-file.c | 41 +++++++++++++++++++----------------------
 gedit/gedit-window.c        | 23 ++++++-----------------
 gedit/gedit-window.h        |  8 +++++---
 3 files changed, 30 insertions(+), 42 deletions(-)
---
diff --git a/gedit/gedit-commands-file.c b/gedit/gedit-commands-file.c
index 443812fdf..50e6d6eea 100644
--- a/gedit/gedit-commands-file.c
+++ b/gedit/gedit-commands-file.c
@@ -370,7 +370,6 @@ file_chooser_open_done_cb (GeditFileChooserOpen *file_chooser,
        GSList *files;
        const GtkSourceEncoding *encoding;
        gchar *folder_uri;
-       GFile *folder = NULL;
        GSList *loaded_documents;
 
        gedit_debug (DEBUG_COMMANDS);
@@ -395,13 +394,8 @@ file_chooser_open_done_cb (GeditFileChooserOpen *file_chooser,
        }
 
        /* Remember the folder we navigated to. */
-       if (folder_uri != NULL)
-       {
-               folder = g_file_new_for_uri (folder_uri);
-               g_free (folder_uri);
-       }
-       _gedit_window_set_default_location (window, folder);
-       g_clear_object (&folder);
+       _gedit_window_set_file_chooser_folder_uri (window, folder_uri);
+       g_free (folder_uri);
 
        loaded_documents = gedit_commands_load_locations (window, files, encoding, 0, 0);
 
@@ -428,21 +422,14 @@ _gedit_cmd_file_open (GSimpleAction *action,
 
        if (window != NULL)
        {
-               GFile *default_folder = NULL;
+               const gchar *folder_uri;
 
                _gedit_file_chooser_open_set_transient_for (file_chooser, GTK_WINDOW (window));
 
-               /* Set the current folder */
-               default_folder = _gedit_window_get_default_location (window);
-               if (default_folder != NULL)
+               folder_uri = _gedit_window_get_file_chooser_folder_uri (window);
+               if (folder_uri != NULL)
                {
-                       gchar *default_folder_uri;
-
-                       default_folder_uri = g_file_get_uri (default_folder);
-                       _gedit_file_chooser_open_set_current_folder_uri (file_chooser, default_folder_uri);
-
-                       g_object_unref (default_folder);
-                       g_free (default_folder_uri);
+                       _gedit_file_chooser_open_set_current_folder_uri (file_chooser, folder_uri);
                }
        }
 
@@ -703,8 +690,13 @@ save_dialog_response_cb (GeditFileChooserDialog *dialog,
                folder = g_file_get_parent (location);
                if (folder != NULL)
                {
-                       _gedit_window_set_default_location (window, folder);
+                       gchar *folder_uri;
+
+                       folder_uri = g_file_get_uri (folder);
+                       _gedit_window_set_file_chooser_folder_uri (window, folder_uri);
+
                        g_object_unref (folder);
+                       g_free (folder_uri);
                }
        }
 
@@ -831,11 +823,16 @@ save_as_tab_async (GeditTab            *tab,
        }
        else
        {
+               const gchar *default_folder_uri;
                GFile *default_folder;
                gchar *docname;
 
-               default_folder = _gedit_window_get_default_location (window);
-               if (default_folder == NULL)
+               default_folder_uri = _gedit_window_get_file_chooser_folder_uri (window);
+               if (default_folder_uri != NULL)
+               {
+                       default_folder = g_file_new_for_uri (default_folder_uri);
+               }
+               else
                {
                        /* It's logical to take the home dir by default, and it fixes
                         * a problem on MS Windows (hang in C:\windows\system32).
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 5b30107fe..295563237 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -3380,33 +3380,22 @@ gedit_window_get_state (GeditWindow *window)
        return window->priv->state;
 }
 
-GFile *
-_gedit_window_get_default_location (GeditWindow *window)
+const gchar *
+_gedit_window_get_file_chooser_folder_uri (GeditWindow *window)
 {
        g_return_val_if_fail (GEDIT_IS_WINDOW (window), NULL);
 
-       if (window->priv->file_chooser_folder_uri == NULL)
-       {
-               return NULL;
-       }
-
-       return g_file_new_for_uri (window->priv->file_chooser_folder_uri);
+       return window->priv->file_chooser_folder_uri;
 }
 
 void
-_gedit_window_set_default_location (GeditWindow *window,
-                                   GFile       *folder)
+_gedit_window_set_file_chooser_folder_uri (GeditWindow *window,
+                                          const gchar *folder_uri)
 {
        g_return_if_fail (GEDIT_IS_WINDOW (window));
-       g_return_if_fail (folder == NULL || G_IS_FILE (folder));
 
        g_free (window->priv->file_chooser_folder_uri);
-       window->priv->file_chooser_folder_uri = NULL;
-
-       if (folder != NULL)
-       {
-               window->priv->file_chooser_folder_uri = g_file_get_uri (folder);
-       }
+       window->priv->file_chooser_folder_uri = g_strdup (folder_uri);
 }
 
 static void
diff --git a/gedit/gedit-window.h b/gedit/gedit-window.h
index b2eb53535..4a05992cf 100644
--- a/gedit/gedit-window.h
+++ b/gedit/gedit-window.h
@@ -152,10 +152,12 @@ void             _gedit_window_move_tab_to_new_tab_group(GeditWindow         *wi
                                                          GeditTab            *tab);
 gboolean        _gedit_window_is_removing_tabs         (GeditWindow         *window);
 
-GFile          *_gedit_window_get_default_location     (GeditWindow         *window);
+const gchar    *_gedit_window_get_file_chooser_folder_uri
+                                                       (GeditWindow         *window);
 
-void            _gedit_window_set_default_location     (GeditWindow         *window,
-                                                        GFile               *folder);
+void            _gedit_window_set_file_chooser_folder_uri
+                                                       (GeditWindow         *window,
+                                                        const gchar         *folder_uri);
 
 void            _gedit_window_fullscreen               (GeditWindow         *window);
 


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