[gedit/wip/fix-external-tools: 2/2] commands-file: close_tab() in async ready callback



commit c825f32354107c88132b3a90b4370289b29b9744
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Nov 19 16:56:26 2014 +0100

    commands-file: close_tab() in async ready callback

 gedit/gedit-commands-file.c |   77 +++++++++++++++++++++++--------------------
 1 files changed, 41 insertions(+), 36 deletions(-)
---
diff --git a/gedit/gedit-commands-file.c b/gedit/gedit-commands-file.c
index bd2b410..45f2da6 100644
--- a/gedit/gedit-commands-file.c
+++ b/gedit/gedit-commands-file.c
@@ -1482,7 +1482,6 @@ quit_if_needed (GeditWindow *window)
        }
 }
 
-/* Close tab */
 static gboolean
 really_close_tab (GeditTab *tab)
 {
@@ -1510,6 +1509,32 @@ really_close_tab (GeditTab *tab)
 }
 
 static void
+close_tab (GeditTab *tab)
+{
+       GeditDocument *doc;
+
+       doc = gedit_tab_get_document (tab);
+       g_return_if_fail (doc != NULL);
+
+       /* If the user has modified again the document, do not close the tab. */
+       if (_gedit_document_needs_saving (doc))
+       {
+               return;
+       }
+
+       /* Close the document only if it has been succesfully saved.
+        * Tab state is set to CLOSING (it is a state without exiting
+        * transitions) and the tab is closed in an idle handler.
+        */
+       _gedit_tab_mark_for_closing (tab);
+
+       g_idle_add_full (G_PRIORITY_HIGH_IDLE,
+                        (GSourceFunc) really_close_tab,
+                        tab,
+                        NULL);
+}
+
+static void
 tab_state_changed_while_saving (GeditTab    *tab,
                                GParamSpec  *pspec,
                                GeditWindow *window)
@@ -1525,33 +1550,11 @@ tab_state_changed_while_saving (GeditTab    *tab,
         */
        if (state == GEDIT_TAB_STATE_NORMAL)
        {
-               GeditDocument *doc;
-
                g_signal_handlers_disconnect_by_func (tab,
                                                      G_CALLBACK (tab_state_changed_while_saving),
                                                      window);
 
-               doc = gedit_tab_get_document (tab);
-               g_return_if_fail (doc != NULL);
-
-               /* If the saving operation failed or was interrupted, then the
-                * document is still "modified" -> do not close the tab.
-                */
-               if (_gedit_document_needs_saving (doc))
-               {
-                       return;
-               }
-
-               /* Close the document only if it has been succesfully saved.
-                * Tab state is set to CLOSING (it is a state without exiting
-                * transitions) and the tab is closed in an idle handler.
-                */
-               _gedit_tab_mark_for_closing (tab);
-
-               g_idle_add_full (G_PRIORITY_HIGH_IDLE,
-                                (GSourceFunc)really_close_tab,
-                                tab,
-                                NULL);
+               close_tab (tab);
        }
 }
 
@@ -1571,28 +1574,30 @@ save_and_close (GeditTab    *tab,
 }
 
 static void
+save_as_and_close_cb (GeditTab     *tab,
+                     GAsyncResult *result,
+                     gpointer      user_data)
+{
+       gboolean saved = save_as_tab_finish (tab, result);
+
+       if (saved)
+       {
+               close_tab (tab);
+       }
+}
+
+static void
 save_as_and_close (GeditTab    *tab,
                   GeditWindow *window)
 {
        gedit_debug (DEBUG_COMMANDS);
 
-       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);
 
-       /* TODO close tab in the callback. */
        save_as_tab_async (tab,
                           window,
                           NULL,
-                          (GAsyncReadyCallback) save_as_tab_ready_cb,
+                          (GAsyncReadyCallback) save_as_and_close_cb,
                           NULL);
 }
 


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