[gedit/wip/loader-saver: 12/19] Add gedit_document_get_file()



commit 9ad93f85233afa989ef9565e44d191d997b2ff0c
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Jun 11 19:09:43 2014 +0200

    Add gedit_document_get_file()
    
    The function returns the associated GtkSourceFile.

 docs/reference/gedit-sections.txt |    1 +
 gedit/gedit-document.c            |   27 +++++++++++++++++++++++++++
 gedit/gedit-document.h            |    2 ++
 3 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gedit-sections.txt b/docs/reference/gedit-sections.txt
index caa1935..898ded7 100644
--- a/docs/reference/gedit-sections.txt
+++ b/docs/reference/gedit-sections.txt
@@ -50,6 +50,7 @@ GeditDocumentCompressionType
 GEDIT_DOCUMENT_ERROR
 gedit_document_error_quark
 gedit_document_new
+gedit_document_get_file
 gedit_document_get_location
 gedit_document_set_location
 gedit_document_get_uri_for_display
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index ecba9c5..b14814a 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -62,6 +62,8 @@ static void   gedit_document_save_real        (GeditDocument                *doc,
 
 struct _GeditDocumentPrivate
 {
+       GtkSourceFile *file;
+
        GSettings   *editor_settings;
 
        GFile       *location;
@@ -280,6 +282,7 @@ gedit_document_dispose (GObject *object)
        g_clear_object (&doc->priv->editor_settings);
        g_clear_object (&doc->priv->metadata_info);
        g_clear_object (&doc->priv->search_context);
+       g_clear_object (&doc->priv->file);
 
        G_OBJECT_CLASS (gedit_document_parent_class)->dispose (object);
 }
@@ -917,6 +920,8 @@ gedit_document_init (GeditDocument *doc)
 
        priv->encoding = gedit_encoding_get_utf8 ();
 
+       priv->file = gtk_source_file_new (GTK_SOURCE_BUFFER (doc));
+
        g_settings_bind (priv->editor_settings,
                         GEDIT_SETTINGS_MAX_UNDO_ACTIONS,
                         doc,
@@ -2555,4 +2560,26 @@ _gedit_document_get_empty_search (GeditDocument *doc)
        return doc->priv->empty_search;
 }
 
+/**
+ * gedit_document_get_file:
+ * @doc: a #GeditDocument.
+ *
+ * Gets the associated #GtkSourceFile. You should use it only for reading
+ * purposes, not for creating a #GtkSourceFileLoader or #GtkSourceFileSaver. Use
+ * the higher-lever gedit API instead, since those functions do some extra work,
+ * like displaying progress and error information in an info bar.
+ *
+ * If you want to save the #GeditDocument to a secondary file, you can create a
+ * new #GtkSourceFile and use a #GtkSourceFileSaver.
+ *
+ * Returns: (transfer none): the associated #GtkSourceFile.
+ */
+GtkSourceFile *
+gedit_document_get_file (GeditDocument *doc)
+{
+       g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
+
+       return doc->priv->file;
+}
+
 /* ex:set ts=8 noet: */
diff --git a/gedit/gedit-document.h b/gedit/gedit-document.h
index 98290f3..63a84af 100644
--- a/gedit/gedit-document.h
+++ b/gedit/gedit-document.h
@@ -285,6 +285,8 @@ GMountOperation
 
 gboolean                _gedit_document_get_empty_search       (GeditDocument          *doc);
 
+GtkSourceFile          *gedit_document_get_file                (GeditDocument *doc);
+
 G_END_DECLS
 
 #endif /* __GEDIT_DOCUMENT_H__ */


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