[gnome-builder] libide: track loading state of buffer



commit 4c9c569c628639453c25ac95b530522b585bd5ad
Author: Christian Hergert <christian hergert me>
Date:   Fri Mar 13 02:08:16 2015 -0700

    libide: track loading state of buffer

 libide/ide-buffer-manager.c |    5 +++
 libide/ide-buffer.c         |   66 +++++++++++++++++++++++++++++++++++++------
 libide/ide-internal.h       |    3 ++
 3 files changed, 65 insertions(+), 9 deletions(-)
---
diff --git a/libide/ide-buffer-manager.c b/libide/ide-buffer-manager.c
index 31fb931..74d8b54 100644
--- a/libide/ide-buffer-manager.c
+++ b/libide/ide-buffer-manager.c
@@ -405,6 +405,7 @@ ide_buffer_manager_load_file__load_cb (GObject      *object,
        */
       if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
         {
+          _ide_buffer_set_loading (state->buffer, FALSE);
           g_task_return_error (task, error);
           return;
         }
@@ -459,6 +460,8 @@ ide_buffer_manager_load_file__load_cb (GObject      *object,
   gtk_text_buffer_select_range (GTK_TEXT_BUFFER (state->buffer), &iter, &iter);
 
 emit_signal:
+  _ide_buffer_set_loading (state->buffer, FALSE);
+
   g_signal_emit (self, gSignals [BUFFER_LOADED], 0, state->buffer);
 
   g_task_return_pointer (task, g_object_ref (state->buffer), g_object_unref);
@@ -529,6 +532,8 @@ ide_buffer_manager_load_file_async  (IdeBufferManager     *self,
                                   "file", file,
                                   NULL);
 
+  _ide_buffer_set_loading (state->buffer, TRUE);
+
   g_task_set_task_data (task, state, load_state_free);
 
   if (progress)
diff --git a/libide/ide-buffer.c b/libide/ide-buffer.c
index 6a4fe48..f5d2876 100644
--- a/libide/ide-buffer.c
+++ b/libide/ide-buffer.c
@@ -67,8 +67,9 @@ struct _IdeBuffer
   guint                   diagnose_timeout;
 
   guint                   diagnostics_dirty : 1;
-  guint                   in_diagnose : 1;
   guint                   highlight_diagnostics : 1;
+  guint                   in_diagnose : 1;
+  guint                   loading : 1;
 };
 
 G_DEFINE_TYPE (IdeBuffer, ide_buffer, GTK_SOURCE_TYPE_BUFFER)
@@ -85,6 +86,7 @@ enum {
 
 enum {
   LINE_FLAGS_CHANGED,
+  LOADED,
   LAST_SIGNAL
 };
 
@@ -699,14 +701,30 @@ ide_buffer_class_init (IdeBufferClass *klass)
    * This signal is emitted when the calculated line flags have changed. This occurs when
    * diagnostics and line changes have been recalculated.
    */
-  gSignals [LINE_FLAGS_CHANGED] = g_signal_new ("line-flags-changed",
-                                                G_TYPE_FROM_CLASS (klass),
-                                                G_SIGNAL_RUN_LAST,
-                                                0,
-                                                NULL, NULL,
-                                                g_cclosure_marshal_VOID__VOID,
-                                                G_TYPE_NONE,
-                                                0);
+  gSignals [LINE_FLAGS_CHANGED] =
+    g_signal_new ("line-flags-changed",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__VOID,
+                  G_TYPE_NONE,
+                  0);
+
+  /**
+   * IdeBuffer::loaded:
+   *
+   * This signal is emitted when the buffer manager has completed loading the file.
+   */
+  gSignals [LOADED] =
+    g_signal_new ("loaded",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__VOID,
+                  G_TYPE_NONE,
+                  0);
 }
 
 static void
@@ -1102,3 +1120,33 @@ ide_buffer_set_style_scheme_name (IdeBuffer   *self,
   if (scheme)
     gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (self), scheme);
 }
+
+gboolean
+_ide_buffer_get_loading (IdeBuffer *self)
+{
+  g_return_val_if_fail (IDE_IS_BUFFER (self), FALSE);
+
+  return self->loading;
+}
+
+void
+_ide_buffer_set_loading (IdeBuffer *self,
+                         gboolean   loading)
+{
+  g_return_if_fail (IDE_IS_BUFFER (self));
+
+  loading = !!loading;
+
+  if (self->loading != loading)
+    {
+      self->loading = loading;
+
+      /*
+       * TODO: We probably want some sort of state rather than this boolean value.
+       *       But that can come later after we get plumbing hooked up.
+       */
+
+      if (!self->loading)
+        g_signal_emit (self, gSignals [LOADED], 0);
+    }
+}
diff --git a/libide/ide-internal.h b/libide/ide-internal.h
index af14c8f..d5333a5 100644
--- a/libide/ide-internal.h
+++ b/libide/ide-internal.h
@@ -50,6 +50,9 @@ gboolean            _ide_back_forward_list_save_finish (IdeBackForwardList    *s
                                                         GError               **error);
 IdeBackForwardItem *_ide_back_forward_list_find        (IdeBackForwardList    *self,
                                                         IdeFile               *file);
+gboolean            _ide_buffer_get_loading            (IdeBuffer             *self);
+void                _ide_buffer_set_loading            (IdeBuffer             *self,
+                                                        gboolean               loading);
 void                _ide_diagnostic_add_range          (IdeDiagnostic         *self,
                                                         IdeSourceRange        *range);
 IdeDiagnostic      *_ide_diagnostic_new                (IdeDiagnosticSeverity  severity,


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