[gedit/wip/loader-saver] Port GeditTab to GtkSourceFile (not finished)



commit 708f05c587dde9d2284634e00bd78afc51c48f88
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Jun 12 23:11:04 2014 +0200

    Port GeditTab to GtkSourceFile (not finished)

 gedit/gedit-tab.c |   72 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 62 insertions(+), 10 deletions(-)
---
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index fca1a0b..48728d2 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -58,9 +58,11 @@ struct _GeditTabPrivate
        GFile                  *tmp_save_location;
 
        /* tmp data for loading */
+       GtkSourceFileLoader    *loader;
+       GCancellable           *cancellable;
        gint                    tmp_line_pos;
        gint                    tmp_column_pos;
-       const GtkSourceEncoding *tmp_encoding;
+       const GtkSourceEncoding *tmp_encoding; /* TODO remove */
 
        GTimer                 *timer;
        guint                   times_called;
@@ -72,8 +74,10 @@ struct _GeditTabPrivate
 
        gint                    not_editable : 1;
        gint                    auto_save : 1;
-
        gint                    ask_if_externally_modified : 1;
+
+       /* tmp data for loading */
+       guint                   tmp_create : 1;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (GeditTab, gedit_tab, GTK_TYPE_BOX)
@@ -2039,6 +2043,30 @@ gedit_tab_get_from_document (GeditDocument *doc)
        return (res != NULL) ? GEDIT_TAB (res) : NULL;
 }
 
+static void
+progress_cb (goffset   current_num_bytes,
+            goffset   total_num_bytes,
+            GeditTab *tab)
+{
+}
+
+static void
+load_cb (GtkSourceFileLoader *loader,
+        GAsyncResult        *result,
+        GeditTab            *tab)
+{
+       GError *error = NULL;
+
+       gtk_source_file_loader_load_finish (loader, result, &error);
+
+       if (error != NULL)
+       {
+       }
+
+       /* Async operation finished. */
+       g_object_unref (tab);
+}
+
 void
 _gedit_tab_load (GeditTab                *tab,
                 GFile                   *location,
@@ -2048,28 +2076,52 @@ _gedit_tab_load (GeditTab                *tab,
                 gboolean                 create)
 {
        GeditDocument *doc;
+       GtkSourceFile *file;
 
        g_return_if_fail (GEDIT_IS_TAB (tab));
        g_return_if_fail (G_IS_FILE (location));
        g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_NORMAL);
+       g_return_if_fail (tab->priv->loader == NULL);
+       g_return_if_fail (tab->priv->cancellable == NULL);
+
+       gedit_tab_set_state (tab, GEDIT_TAB_STATE_LOADING);
 
        doc = gedit_view_frame_get_document (tab->priv->frame);
+       file = gedit_document_get_file (doc);
+       tab->priv->loader = gtk_source_file_loader_new (file, location);
+       tab->priv->cancellable = g_cancellable_new ();
 
-       gedit_tab_set_state (tab, GEDIT_TAB_STATE_LOADING);
+       if (encoding != NULL)
+       {
+               GSList *candidate_encodings = g_slist_append (NULL, (gpointer)encoding);
+               gtk_source_file_loader_set_candidate_encodings (loader, candidate_encodings);
+               g_slist_free (candidate_encodings);
+       }
+       else
+       {
+               /* TODO */
+       }
 
        tab->priv->tmp_line_pos = line_pos;
        tab->priv->tmp_column_pos = column_pos;
-       tab->priv->tmp_encoding = encoding;
+       tab->priv->tmp_create = create != FALSE;
 
        if (tab->priv->auto_save_timeout > 0)
+       {
                remove_auto_save_timeout (tab);
+       }
 
-       gedit_document_load (doc,
-                            location,
-                            encoding,
-                            line_pos,
-                            column_pos,
-                            create);
+       /* Keep tab alive during the async operation. */
+       g_object_ref (tab);
+
+       gtk_source_file_loader_load_async (tab->priv->loader,
+                                          G_PRIORITY_HIGH,
+                                          tab->priv->cancellable,
+                                          (GFileProgressCallback)progress_cb,
+                                          tab,
+                                          NULL,
+                                          (GAsyncReadyCallback)load_cb,
+                                          tab);
 }
 
 void


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