[gedit/wip/fix-external-tools] commands-file: save next tab in async ready callback



commit 1c1bbbcfebacd6672f5719d18b914daa9631cd62
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Nov 19 18:42:31 2014 +0100

    commands-file: save next tab in async ready callback

 gedit/gedit-commands-file.c |  117 ++++++++++++++++++++----------------------
 1 files changed, 56 insertions(+), 61 deletions(-)
---
diff --git a/gedit/gedit-commands-file.c b/gedit/gedit-commands-file.c
index 45f2da6..9689f55 100644
--- a/gedit/gedit-commands-file.c
+++ b/gedit/gedit-commands-file.c
@@ -793,52 +793,6 @@ save_dialog_response_cb (GeditFileChooserDialog *dialog,
                                  task);
 
        g_object_unref (location);
-
-/* TODO refactor this */
-#if 0
-save_next_tab:
-
-       data = g_object_get_data (G_OBJECT (window),
-                                 GEDIT_LIST_OF_TABS_TO_SAVE_AS);
-       if (data == NULL)
-       {
-               return;
-       }
-
-       /* Save As the next tab of the list (we are Saving All files) */
-       tabs_to_save_as = (GSList *)data;
-       g_return_if_fail (tab == GEDIT_TAB (tabs_to_save_as->data));
-
-       /* Remove the first item of the list */
-       tabs_to_save_as = g_slist_delete_link (tabs_to_save_as,
-                                              tabs_to_save_as);
-
-       g_object_set_data (G_OBJECT (window),
-                          GEDIT_LIST_OF_TABS_TO_SAVE_AS,
-                          tabs_to_save_as);
-
-       if (tabs_to_save_as != NULL)
-       {
-               tab = GEDIT_TAB (tabs_to_save_as->data);
-
-               if (GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (tab),
-                                                           GEDIT_IS_CLOSING_TAB)))
-               {
-                       g_object_set_data (G_OBJECT (tab),
-                                          GEDIT_IS_CLOSING_TAB,
-                                          NULL);
-
-                       /* Trace tab state changes */
-                       g_signal_connect (tab,
-                                         "notify::state",
-                                         G_CALLBACK (tab_state_changed_while_saving),
-                                         window);
-               }
-
-               gedit_window_set_active_tab (window, tab);
-               save_as_tab (tab, window);
-       }
-#endif
 }
 
 static GtkFileChooserConfirmation
@@ -1093,6 +1047,47 @@ _gedit_cmd_file_save_as (GSimpleAction *action,
        }
 }
 
+typedef struct _SaveAsData SaveAsData;
+
+struct _SaveAsData
+{
+       GeditWindow *window;
+       GSList *tabs_to_save_as;
+};
+
+static void
+save_documents_list_cb (GeditTab     *tab,
+                       GAsyncResult *result,
+                       SaveAsData   *data)
+{
+       GeditTab *next_tab;
+
+       save_as_tab_finish (tab, result);
+
+       g_return_if_fail (tab == GEDIT_TAB (data->tabs_to_save_as->data));
+       g_object_unref (data->tabs_to_save_as->data);
+       data->tabs_to_save_as = g_slist_delete_link (data->tabs_to_save_as,
+                                                    data->tabs_to_save_as);
+
+       if (data->tabs_to_save_as == NULL)
+       {
+               g_object_unref (data->window);
+               g_slice_free (SaveAsData, data);
+               return;
+       }
+
+       /* Save As the next tab of the list. */
+       next_tab = GEDIT_TAB (data->tabs_to_save_as->data);
+
+       gedit_window_set_active_tab (data->window, next_tab);
+
+       save_as_tab_async (next_tab,
+                          data->window,
+                          NULL,
+                          (GAsyncReadyCallback) save_documents_list_cb,
+                          data);
+}
+
 /*
  * The docs in the list must belong to the same GeditWindow.
  */
@@ -1100,8 +1095,8 @@ static void
 save_documents_list (GeditWindow *window,
                     GList       *docs)
 {
+       SaveAsData *data = NULL;
        GList *l;
-       GSList *tabs_to_save_as = NULL;
 
        gedit_debug (DEBUG_COMMANDS);
 
@@ -1134,7 +1129,15 @@ save_documents_list (GeditWindow *window,
                                if (gedit_document_is_untitled (doc) ||
                                    gedit_document_get_readonly (doc))
                                {
-                                       tabs_to_save_as = g_slist_prepend (tabs_to_save_as, tab);
+                                       if (data == NULL)
+                                       {
+                                               data = g_slice_new (SaveAsData);
+                                               data->window = g_object_ref (window);
+                                               data->tabs_to_save_as = NULL;
+                                       }
+
+                                       data->tabs_to_save_as = g_slist_prepend (data->tabs_to_save_as,
+                                                                                g_object_ref (tab));
                                }
                                else
                                {
@@ -1176,29 +1179,21 @@ save_documents_list (GeditWindow *window,
                }
        }
 
-       if (tabs_to_save_as != NULL)
+       if (data != NULL)
        {
                GeditTab *tab;
 
-               tabs_to_save_as = g_slist_reverse (tabs_to_save_as);
-
-               g_return_if_fail (g_object_get_data (G_OBJECT (window),
-                                                    GEDIT_LIST_OF_TABS_TO_SAVE_AS) == NULL);
-
-               g_object_set_data (G_OBJECT (window),
-                                  GEDIT_LIST_OF_TABS_TO_SAVE_AS,
-                                  tabs_to_save_as);
+               data->tabs_to_save_as = g_slist_reverse (data->tabs_to_save_as);
 
-               tab = GEDIT_TAB (tabs_to_save_as->data);
+               tab = GEDIT_TAB (data->tabs_to_save_as->data);
 
                gedit_window_set_active_tab (window, tab);
 
-               /* TODO save next tab in the callback. */
                save_as_tab_async (tab,
                                   window,
                                   NULL,
-                                  (GAsyncReadyCallback) save_as_tab_ready_cb,
-                                  NULL);
+                                  (GAsyncReadyCallback) save_documents_list_cb,
+                                  data);
        }
 }
 


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