[gtksourceview/wip/loader-saver] GtkSourceBuffer properties



commit 646e5610ee89ced39c484679519acce47ad08a07
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Mar 31 19:39:55 2014 +0200

    GtkSourceBuffer properties

 docs/reference/gtksourceview-3.0-sections.txt |    9 +
 gtksourceview/gtksourcebuffer.c               |  238 ++++++++++++++++++++++++-
 gtksourceview/gtksourcebuffer.h               |   13 ++
 3 files changed, 259 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index 527a39a..b4cd333 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -43,6 +43,13 @@ gtk_source_buffer_begin_not_undoable_action
 gtk_source_buffer_end_not_undoable_action
 gtk_source_buffer_get_undo_manager
 gtk_source_buffer_set_undo_manager
+<SUBSECTION>
+gtk_source_buffer_get_file
+gtk_source_buffer_get_encoding
+gtk_source_buffer_get_newline_type
+gtk_source_buffer_get_compression_type
+gtk_source_buffer_set_implicit_trailing_newline
+gtk_source_buffer_get_implicit_trailing_newline
 <SUBSECTION Standard>
 GtkSourceBufferClass
 GTK_SOURCE_IS_BUFFER
@@ -233,6 +240,7 @@ gtk_source_encoding_get_type
 <FILE>fileloader</FILE>
 <TITLE>GtkSourceFileLoader</TITLE>
 GtkSourceFileLoader
+GTK_SOURCE_FILE_LOADER_ERROR
 gtk_source_file_loader_new
 gtk_source_file_loader_new_from_stream
 gtk_source_file_loader_set_candidate_encodings
@@ -256,6 +264,7 @@ GTK_SOURCE_IS_FILE_LOADER_CLASS
 GTK_SOURCE_TYPE_FILE_LOADER
 GtkSourceFileLoaderPrivate
 gtk_source_file_loader_get_type
+gtk_source_file_loader_error_quark
 </SECTION>
 
 <SECTION>
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index b6adde5..c3200ed 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -42,6 +42,7 @@
 #include "gtksourcemark.h"
 #include "gtksourcemarkssequence.h"
 #include "gtksourcesearchcontext.h"
+#include "gtksourceencoding.h"
 #include "gtksourceview-i18n.h"
 #include "gtksourceview-marshal.h"
 #include "gtksourceview-typebuiltins.h"
@@ -140,7 +141,12 @@ enum {
        PROP_MAX_UNDO_LEVELS,
        PROP_LANGUAGE,
        PROP_STYLE_SCHEME,
-       PROP_UNDO_MANAGER
+       PROP_UNDO_MANAGER,
+       PROP_FILE,
+       PROP_ENCODING,
+       PROP_NEWLINE_TYPE,
+       PROP_COMPRESSION_TYPE,
+       PROP_IMPLICIT_TRAILING_NEWLINE
 };
 
 struct _GtkSourceBufferPrivate
@@ -166,10 +172,16 @@ struct _GtkSourceBufferPrivate
 
        GtkTextTag            *invalid_char_tag;
 
+       GFile                    *file;
+       const GtkSourceEncoding  *encoding;
+       GtkSourceNewlineType      newline_type;
+       GtkSourceCompressionType  compression_type;
+
        guint                  highlight_syntax : 1;
        guint                  highlight_brackets : 1;
        guint                  constructed : 1;
        guint                  allow_bracket_match : 1;
+       guint                  implicit_trailing_newline : 1;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceBuffer, gtk_source_buffer, GTK_TYPE_TEXT_BUFFER)
@@ -359,6 +371,85 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
                                                              GTK_SOURCE_TYPE_UNDO_MANAGER,
                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
+       /**
+        * GtkSourceBuffer:file:
+        *
+        * The associated #GFile.
+        *
+        * Since: 3.14
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_FILE,
+                                        g_param_spec_object ("file",
+                                                             _("File"),
+                                                             _("The associated file"),
+                                                             G_TYPE_FILE,
+                                                             G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+       /**
+        * GtkSourceBuffer:encoding:
+        *
+        * The #GtkSourceBuffer:file's encoding. Note that the #GtkSourceBuffer
+        * always has a UTF-8 encoding.
+        *
+        * Since: 3.14
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_ENCODING,
+                                        g_param_spec_boxed ("encoding",
+                                                            _("Encoding"),
+                                                            _("The file's encoding"),
+                                                            GTK_SOURCE_TYPE_ENCODING,
+                                                            G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+       /**
+        * GtkSourceBuffer:newline-type:
+        *
+        * The type of line ending.
+        *
+        * Since: 3.14
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_NEWLINE_TYPE,
+                                        g_param_spec_enum ("newline-type",
+                                                           _("Newline type"),
+                                                           _("The type of line ending"),
+                                                           GTK_SOURCE_TYPE_NEWLINE_TYPE,
+                                                           GTK_SOURCE_NEWLINE_TYPE_LF,
+                                                           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+       /**
+        * GtkSourceBuffer:compression-type:
+        *
+        * The #GtkSourceBuffer:file's compression type.
+        *
+        * Since: 3.14
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_COMPRESSION_TYPE,
+                                        g_param_spec_enum ("compression-type",
+                                                           _("Compression type"),
+                                                           _("The file's compression type"),
+                                                           GTK_SOURCE_TYPE_COMPRESSION_TYPE,
+                                                           GTK_SOURCE_COMPRESSION_TYPE_NONE,
+                                                           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+       /**
+        * GtkSourceBuffer:implicit-trailing-newline:
+        *
+        * Whether the buffer has an implicit trailing newline.
+        *
+        * Since: 3.14
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_IMPLICIT_TRAILING_NEWLINE,
+                                        g_param_spec_boolean ("implicit-trailing-newline",
+                                                              _("Implicit trailing newline"),
+                                                              _("Whether the buffer has an implicit trailing 
newline"),
+                                                              TRUE,
+                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
+                                                              G_PARAM_STATIC_STRINGS));
+
        param_types[0] = GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE;
        param_types[1] = GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE;
 
@@ -629,6 +720,10 @@ gtk_source_buffer_set_property (GObject      *object,
                                                            g_value_get_object (value));
                        break;
 
+               case PROP_IMPLICIT_TRAILING_NEWLINE:
+                       source_buffer->priv->implicit_trailing_newline = g_value_get_boolean (value);
+                       break;
+
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
@@ -684,6 +779,26 @@ gtk_source_buffer_get_property (GObject    *object,
                        g_value_set_object (value, source_buffer->priv->undo_manager);
                        break;
 
+               case PROP_FILE:
+                       g_value_set_object (value, source_buffer->priv->file);
+                       break;
+
+               case PROP_ENCODING:
+                       g_value_set_boxed (value, source_buffer->priv->encoding);
+                       break;
+
+               case PROP_NEWLINE_TYPE:
+                       g_value_set_enum (value, source_buffer->priv->newline_type);
+                       break;
+
+               case PROP_COMPRESSION_TYPE:
+                       g_value_set_enum (value, source_buffer->priv->compression_type);
+                       break;
+
+               case PROP_IMPLICIT_TRAILING_NEWLINE:
+                       g_value_set_boolean (value, source_buffer->priv->implicit_trailing_newline);
+                       break;
+
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
@@ -2543,3 +2658,124 @@ _gtk_source_buffer_set_as_invalid_character (GtkSourceBuffer *buffer,
                                   start,
                                   end);
 }
+
+/**
+ * gtk_source_buffer_get_file:
+ * @buffer: a #GtkSourceBuffer.
+ *
+ * Returns: (transfer none): the associated #GFile.
+ * Since: 3.14
+ */
+GFile *
+gtk_source_buffer_get_file (GtkSourceBuffer *buffer)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
+
+       return buffer->priv->file;
+}
+
+/**
+ * gtk_source_buffer_get_encoding:
+ * @buffer: a #GtkSourceBuffer.
+ *
+ * Returns: the #GtkSourceBuffer:file's encoding. Note that the @buffer always
+ * has a UTF-8 encoding.
+ * Since: 3.14
+ */
+const GtkSourceEncoding *
+gtk_source_buffer_get_encoding (GtkSourceBuffer *buffer)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
+
+       return buffer->priv->encoding;
+}
+
+/**
+ * gtk_source_buffer_get_newline_type:
+ * @buffer: a #GtkSourceBuffer.
+ *
+ * Returns: the #GtkSourceBuffer:file's newline type.
+ * Since: 3.14
+ */
+GtkSourceNewlineType
+gtk_source_buffer_get_newline_type (GtkSourceBuffer *buffer)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), GTK_SOURCE_NEWLINE_TYPE_DEFAULT);
+
+       return buffer->priv->newline_type;
+}
+
+/**
+ * gtk_source_buffer_get_compression_type:
+ * @buffer: a #GtkSourceBuffer.
+ *
+ * Returns: the #GtkSourceBuffer:file's compression type.
+ * Since: 3.14
+ */
+GtkSourceCompressionType
+gtk_source_buffer_get_compression_type (GtkSourceBuffer *buffer)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), GTK_SOURCE_COMPRESSION_TYPE_NONE);
+
+       return buffer->priv->compression_type;
+}
+
+/**
+ * gtk_source_buffer_set_implicit_trailing_newline:
+ * @buffer: a #GtkSourceBuffer.
+ * @implicit_trailing_newline: the new value.
+ *
+ * Sets whether the @buffer has an implicit trailing newline.
+ *
+ * If a trailing newline is present in a #GtkTextBuffer, there will be one more
+ * visible line in a #GtkTextView. This is generally not what the user expects.
+ * So instead of having an explicit trailing newline in the @buffer, there can
+ * be an implicit trailing newline: the trailing newline is actually not in the
+ * @buffer, but when saving the file with a #GtkSourceFileSaver, there will be a
+ * trailing newline in the file.
+ *
+ * By default, both the #GtkSourceFileLoader:remove-trailing-newline property of
+ * #GtkSourceFileLoader and the #GtkSourceFileSaver:ensure-trailing-newline
+ * property of #GtkSourceFileSaver have the same value as
+ * #GtkSourceBuffer:implicit-trailing-newline.
+ *
+ * So by default, if @implicit_trailing_newline is %TRUE, the trailing newline
+ * (if present) is removed when the file is loaded into the @buffer. And when
+ * the buffer is saved into a file, a trailing newline is always added (by
+ * default).
+ *
+ * On the other hand, when @implicit_trailing_newline is %FALSE, the file's
+ * content is not modified when loaded into the @buffer (by default), and the
+ * buffer's content is not modified when saved into the file (by default).
+ *
+ * Since: 3.14
+ */
+void
+gtk_source_buffer_set_implicit_trailing_newline (GtkSourceBuffer *buffer,
+                                                gboolean         implicit_trailing_newline)
+{
+       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
+
+       implicit_trailing_newline = implicit_trailing_newline != FALSE;
+
+       if (buffer->priv->implicit_trailing_newline != implicit_trailing_newline)
+       {
+               buffer->priv->implicit_trailing_newline = implicit_trailing_newline;
+               g_object_notify (G_OBJECT (buffer), "implicit-trailing-newline");
+       }
+}
+
+/**
+ * gtk_source_buffer_get_implicit_trailing_newline:
+ * @buffer: a #GtkSourceBuffer.
+ *
+ * Returns: whether the @buffer has an implicit trailing newline.
+ * Since: 3.14
+ */
+gboolean
+gtk_source_buffer_get_implicit_trailing_newline (GtkSourceBuffer *buffer)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), TRUE);
+
+       return buffer->priv->implicit_trailing_newline;
+}
diff --git a/gtksourceview/gtksourcebuffer.h b/gtksourceview/gtksourcebuffer.h
index dad9348..c81acdd 100644
--- a/gtksourceview/gtksourcebuffer.h
+++ b/gtksourceview/gtksourcebuffer.h
@@ -255,6 +255,19 @@ GtkSourceUndoManager       *gtk_source_buffer_get_undo_manager                     
(GtkSourceBuffer        *buf
 void                    gtk_source_buffer_set_undo_manager                     (GtkSourceBuffer        
*buffer,
                                                                                 GtkSourceUndoManager   
*manager);
 
+GFile                  *gtk_source_buffer_get_file                             (GtkSourceBuffer        
*buffer);
+
+const GtkSourceEncoding *gtk_source_buffer_get_encoding                                (GtkSourceBuffer      
  *buffer);
+
+GtkSourceNewlineType    gtk_source_buffer_get_newline_type                     (GtkSourceBuffer        
*buffer);
+
+GtkSourceCompressionType gtk_source_buffer_get_compression_type                        (GtkSourceBuffer      
  *buffer);
+
+void                    gtk_source_buffer_set_implicit_trailing_newline        (GtkSourceBuffer        
*buffer,
+                                                                                gboolean                
implicit_trailing_newline);
+
+gboolean                gtk_source_buffer_get_implicit_trailing_newline        (GtkSourceBuffer        
*buffer);
+
 G_END_DECLS
 
 #endif /* __GTK_SOURCE_BUFFER_H__ */


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