[gnome-builder/wip/libide] libide: encapsulate GtkSourceFile inside of IdeFile



commit d208a96e3bcd6e51b6646019b868bf163d049e11
Author: Christian Hergert <christian hergert me>
Date:   Mon Feb 23 16:33:33 2015 -0800

    libide: encapsulate GtkSourceFile inside of IdeFile
    
    This allows us to track encoding during the load progress as well as
    newlines. We simply prime the defaults when saving later.

 libide/ide-file.c     |   22 +++++++++++++++++++++-
 libide/ide-internal.h |    3 +++
 2 files changed, 24 insertions(+), 1 deletions(-)
---
diff --git a/libide/ide-file.c b/libide/ide-file.c
index 4f93871..071e352 100644
--- a/libide/ide-file.c
+++ b/libide/ide-file.c
@@ -30,6 +30,7 @@ struct _IdeFile
   GFile         *file;
   IdeLanguage   *language;
   gchar         *path;
+  GtkSourceFile *source_file;
 };
 
 enum
@@ -141,7 +142,7 @@ ide_file_create_language (IdeFile *self)
                                  "id", lang_id,
                                  NULL);
 
-      g_once_init_leave (&priv->language, language);
+      g_once_init_leave (&self->language, language);
     }
 }
 
@@ -193,6 +194,24 @@ ide_file_set_file (IdeFile *self,
     }
 }
 
+GtkSourceFile *
+_ide_file_get_source_file (IdeFile *self)
+{
+  g_return_val_if_fail (IDE_IS_FILE (self), NULL);
+
+  if (g_once_init_enter (&self->source_file))
+    {
+      GtkSourceFile *source_file;
+
+      source_file = gtk_source_file_new ();
+      gtk_source_file_set_location (source_file, self->file);
+
+      g_once_init_leave (&self->source_file, source_file);
+    }
+
+  return self->source_file;
+}
+
 const gchar *
 ide_file_get_path (IdeFile *self)
 {
@@ -283,6 +302,7 @@ ide_file_finalize (GObject *object)
   IdeFile *self = (IdeFile *)object;
 
   g_clear_object (&self->file);
+  g_clear_object (&self->source_file);
   g_clear_object (&self->language);
   g_clear_pointer (&self->path, g_free);
 
diff --git a/libide/ide-internal.h b/libide/ide-internal.h
index bf5faa7..01a5432 100644
--- a/libide/ide-internal.h
+++ b/libide/ide-internal.h
@@ -20,6 +20,7 @@
 #define IDE_PRIVATE_H
 
 #include <clang-c/Index.h>
+#include <gtksourceview/gtksource.h>
 
 #include "ide-clang-translation-unit.h"
 #include "ide-diagnostic.h"
@@ -54,6 +55,8 @@ void           _ide_diagnostic_take_range (IdeDiagnostic         *self,
 void           _ide_diagnostic_add_range  (IdeDiagnostic         *self,
                                            IdeSourceRange        *range);
 
+GtkSourceFile *_ide_file_get_source_file (IdeFile *file);
+
 void _ide_search_context_add_provider (IdeSearchContext  *context,
                                        IdeSearchProvider *provider,
                                        gsize              max_results);


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