[gtksourceview/wip/gutter-renderer-folds: 10/10] Add gtk_source_view_{get, set}_show_code_folding()



commit 6f240c58580eda3af1d8013b98bf40d131249564
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Sep 7 16:27:38 2013 +0200

    Add gtk_source_view_{get,set}_show_code_folding()
    
    GutterRendererFolds is now private.

 docs/reference/Makefile.am                    |    1 +
 docs/reference/gtksourceview-3.0-sections.txt |    2 +
 gtksourceview/Makefile.am                     |    4 +-
 gtksourceview/gtksourcegutterrendererfolds.h  |    8 +-
 gtksourceview/gtksourcetypes-private.h        |    1 +
 gtksourceview/gtksourcetypes.h                |    1 -
 gtksourceview/gtksourceview.c                 |   85 +++++++++++++++++++++++++
 gtksourceview/gtksourceview.h                 |   16 ++++-
 tests/test-folding.c                          |   13 +----
 9 files changed, 108 insertions(+), 23 deletions(-)
---
diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am
index 1987d7f..6bfb0d4 100644
--- a/docs/reference/Makefile.am
+++ b/docs/reference/Makefile.am
@@ -32,6 +32,7 @@ IGNORE_HFILES =                                       \
        gtksourcecontextengine.h                \
        gtksourceengine.h                       \
        gtksourcegutter-private.h               \
+       gtksourcegutterrendererfolds.h          \
        gtksourcegutterrendererlines.h          \
        gtksourcegutterrenderermarks.h          \
        gtksourcegutterrenderer-private.h       \
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index 3b3bd10..e522aad 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -647,6 +647,8 @@ gtk_source_view_set_show_line_marks
 gtk_source_view_get_show_line_marks
 gtk_source_view_set_show_line_numbers
 gtk_source_view_get_show_line_numbers
+gtk_source_view_set_show_code_folding
+gtk_source_view_get_show_code_folding
 gtk_source_view_set_show_right_margin
 gtk_source_view_get_show_right_margin
 gtk_source_view_set_right_margin_position
diff --git a/gtksourceview/Makefile.am b/gtksourceview/Makefile.am
index d6a0162..324983c 100644
--- a/gtksourceview/Makefile.am
+++ b/gtksourceview/Makefile.am
@@ -32,7 +32,6 @@ libgtksourceview_headers =                    \
        gtksourcecompletionprovider.h           \
        gtksourcegutter.h                       \
        gtksourcegutterrenderer.h               \
-       gtksourcegutterrendererfolds.h          \
        gtksourcegutterrendererpixbuf.h         \
        gtksourcegutterrenderertext.h           \
        gtksourcelanguage.h                     \
@@ -58,6 +57,7 @@ libgtksourceview_private_headers = \
        gtksourcecontextengine.h                \
        gtksourceengine.h                       \
        gtksourcegutter-private.h               \
+       gtksourcegutterrendererfolds.h          \
        gtksourcegutterrendererlines.h          \
        gtksourcegutterrenderermarks.h          \
        gtksourcegutterrenderer-private.h       \
@@ -77,6 +77,7 @@ libgtksourceview_private_c_files = \
        gtksourcecompletionmodel.c      \
        gtksourcecontextengine.c        \
        gtksourceengine.c               \
+       gtksourcegutterrendererfolds.c  \
        gtksourcegutterrendererlines.c  \
        gtksourcegutterrenderermarks.c  \
        gtksourcelanguage-parser-1.c    \
@@ -100,7 +101,6 @@ libgtksourceview_c_files = \
        gtksourcecompletionprovider.c   \
        gtksourcegutter.c               \
        gtksourcegutterrenderer.c       \
-       gtksourcegutterrendererfolds.c  \
        gtksourcegutterrendererpixbuf.c \
        gtksourcegutterrenderertext.c   \
        gtksourcelanguage.c             \
diff --git a/gtksourceview/gtksourcegutterrendererfolds.h b/gtksourceview/gtksourcegutterrendererfolds.h
index 22d47c5..f210859 100644
--- a/gtksourceview/gtksourcegutterrendererfolds.h
+++ b/gtksourceview/gtksourcegutterrendererfolds.h
@@ -22,8 +22,8 @@
 #ifndef __GTK_SOURCE_GUTTER_RENDERER_FOLDS_H__
 #define __GTK_SOURCE_GUTTER_RENDERER_FOLDS_H__
 
-#include <gtksourceview/gtksourcetypes.h>
-#include <gtksourceview/gtksourcegutterrenderer.h>
+#include "gtksourcetypes-private.h"
+#include "gtksourcegutterrenderer.h"
 
 G_BEGIN_DECLS
 
@@ -47,12 +47,12 @@ struct _GtkSourceGutterRendererFolds
 struct _GtkSourceGutterRendererFoldsClass
 {
        GtkSourceGutterRendererClass parent_class;
-
-       gpointer padding[10];
 };
 
+G_GNUC_INTERNAL
 GType                   gtk_source_gutter_renderer_folds_get_type      (void) G_GNUC_CONST;
 
+G_GNUC_INTERNAL
 GtkSourceGutterRenderer        *gtk_source_gutter_renderer_folds_new           (void);
 
 G_END_DECLS
diff --git a/gtksourceview/gtksourcetypes-private.h b/gtksourceview/gtksourcetypes-private.h
index afb1c8a..0001fb7 100644
--- a/gtksourceview/gtksourcetypes-private.h
+++ b/gtksourceview/gtksourcetypes-private.h
@@ -30,6 +30,7 @@ typedef struct _GtkSourceCompletionContainer  GtkSourceCompletionContainer;
 typedef struct _GtkSourceCompletionModel       GtkSourceCompletionModel;
 typedef struct _GtkSourceContextEngine         GtkSourceContextEngine;
 typedef struct _GtkSourceEngine                        GtkSourceEngine;
+typedef struct _GtkSourceGutterRendererFolds   GtkSourceGutterRendererFolds;
 typedef struct _GtkSourceGutterRendererLines   GtkSourceGutterRendererLines;
 typedef struct _GtkSourceGutterRendererMarks   GtkSourceGutterRendererMarks;
 typedef struct _GtkSourceMarksSequence         GtkSourceMarksSequence;
diff --git a/gtksourceview/gtksourcetypes.h b/gtksourceview/gtksourcetypes.h
index 2f9ed21..6442ddd 100644
--- a/gtksourceview/gtksourcetypes.h
+++ b/gtksourceview/gtksourcetypes.h
@@ -35,7 +35,6 @@ typedef struct _GtkSourceCompletionProposal   GtkSourceCompletionProposal;
 typedef struct _GtkSourceCompletionProvider    GtkSourceCompletionProvider;
 typedef struct _GtkSourceGutter                        GtkSourceGutter;
 typedef struct _GtkSourceGutterRenderer                GtkSourceGutterRenderer;
-typedef struct _GtkSourceGutterRendererFolds   GtkSourceGutterRendererFolds;
 typedef struct _GtkSourceGutterRendererPixbuf  GtkSourceGutterRendererPixbuf;
 typedef struct _GtkSourceGutterRendererText    GtkSourceGutterRendererText;
 typedef struct _GtkSourceLanguage              GtkSourceLanguage;
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index c225ee1..f451c5d 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -47,6 +47,7 @@
 #include "gtksourcegutter-private.h"
 #include "gtksourcegutterrendererlines.h"
 #include "gtksourcegutterrenderermarks.h"
+#include "gtksourcegutterrendererfolds.h"
 
 /**
  * SECTION:view
@@ -110,6 +111,7 @@ enum {
        PROP_COMPLETION,
        PROP_SHOW_LINE_NUMBERS,
        PROP_SHOW_LINE_MARKS,
+       PROP_SHOW_CODE_FOLDING,
        PROP_TAB_WIDTH,
        PROP_INDENT_WIDTH,
        PROP_AUTO_INDENT,
@@ -140,6 +142,7 @@ struct _GtkSourceViewPrivate
 
        GtkSourceGutterRenderer *line_renderer;
        GtkSourceGutterRenderer *marks_renderer;
+       GtkSourceGutterRenderer *folds_renderer;
 
        GdkRGBA          current_line_color;
 
@@ -156,6 +159,7 @@ struct _GtkSourceViewPrivate
        guint            tabs_set : 1;
        guint            show_line_numbers : 1;
        guint            show_line_marks : 1;
+       guint            show_code_folding : 1;
        guint            auto_indent : 1;
        guint            insert_spaces : 1;
        guint            highlight_current_line : 1;
@@ -336,6 +340,21 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
                                                               G_PARAM_READWRITE));
 
        /**
+        * GtkSourceView:show-code-folding:
+        *
+        * Whether to display code folding.
+        *
+        * Since: 3.12
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_SHOW_CODE_FOLDING,
+                                        g_param_spec_boolean ("show-code-folding",
+                                                              _("Show Code Folding"),
+                                                              _("Whether to display code folding"),
+                                                              FALSE,
+                                                              G_PARAM_READWRITE));
+
+       /**
         * GtkSourceView:tab-width:
         *
         * Width of an tab character expressed in number of spaces.
@@ -782,6 +801,11 @@ gtk_source_view_set_property (GObject      *object,
                                                             g_value_get_boolean (value));
                        break;
 
+               case PROP_SHOW_CODE_FOLDING:
+                       gtk_source_view_set_show_code_folding (view,
+                                                              g_value_get_boolean (value));
+                       break;
+
                case PROP_TAB_WIDTH:
                        gtk_source_view_set_tab_width (view,
                                                       g_value_get_uint (value));
@@ -867,6 +891,11 @@ gtk_source_view_get_property (GObject    *object,
                                             gtk_source_view_get_show_line_marks (view));
                        break;
 
+               case PROP_SHOW_CODE_FOLDING:
+                       g_value_set_boolean (value,
+                                            gtk_source_view_get_show_code_folding (view));
+                       break;
+
                case PROP_TAB_WIDTH:
                        g_value_set_uint (value,
                                          gtk_source_view_get_tab_width (view));
@@ -2656,6 +2685,62 @@ gtk_source_view_set_show_line_marks (GtkSourceView *view,
        g_object_notify (G_OBJECT (view), "show_line_marks");
 }
 
+/**
+ * gtk_source_view_get_show_code_folding:
+ * @view: a #GtkSourceView.
+ *
+ * Returns: whether to show code folding.
+ * Since: 3.12
+ */
+gboolean
+gtk_source_view_get_show_code_folding (GtkSourceView *view)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
+
+       return view->priv->show_code_folding;
+}
+
+/**
+ * gtk_source_view_set_show_code_folding:
+ * @view: a #GtkSourceView.
+ * @show: the setting.
+ *
+ * Sets whether to show code folding.
+ *
+ * Since: 3.12
+ */
+void
+gtk_source_view_set_show_code_folding (GtkSourceView *view,
+                                      gboolean       show)
+{
+       g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
+
+       show = show != FALSE;
+
+       if (show == view->priv->show_code_folding)
+       {
+               return;
+       }
+
+       if (view->priv->folds_renderer == NULL)
+       {
+               GtkSourceGutter *gutter;
+
+               gutter = gtk_source_view_get_gutter (view, GTK_TEXT_WINDOW_LEFT);
+
+               view->priv->folds_renderer = gtk_source_gutter_renderer_folds_new ();
+
+               gtk_source_gutter_insert (gutter,
+                                         view->priv->folds_renderer,
+                                         GTK_SOURCE_VIEW_GUTTER_POSITION_FOLDING);
+       }
+
+       gtk_source_gutter_renderer_set_visible (view->priv->folds_renderer, show);
+       view->priv->show_code_folding = show;
+
+       g_object_notify (G_OBJECT (view), "show-code-folding");
+}
+
 static gboolean
 set_tab_stops_internal (GtkSourceView *view)
 {
diff --git a/gtksourceview/gtksourceview.h b/gtksourceview/gtksourceview.h
index 4ca73cd..fd18767 100644
--- a/gtksourceview/gtksourceview.h
+++ b/gtksourceview/gtksourceview.h
@@ -39,14 +39,17 @@ G_BEGIN_DECLS
 /**
  * GtkSourceViewGutterPosition:
  * @GTK_SOURCE_VIEW_GUTTER_POSITION_LINES: the gutter position of the lines
- * renderer
+ * renderer.
  * @GTK_SOURCE_VIEW_GUTTER_POSITION_MARKS: the gutter position of the marks
- * renderer
- **/
+ * renderer.
+ * @GTK_SOURCE_VIEW_GUTTER_POSITION_FOLDING: the gutter position of the renderer
+ * used for the code folding.
+ */
 typedef enum
 {
        GTK_SOURCE_VIEW_GUTTER_POSITION_LINES = -30,
-       GTK_SOURCE_VIEW_GUTTER_POSITION_MARKS = -20
+       GTK_SOURCE_VIEW_GUTTER_POSITION_MARKS = -20,
+       GTK_SOURCE_VIEW_GUTTER_POSITION_FOLDING = -10
 } GtkSourceViewGutterPosition;
 
 typedef struct _GtkSourceViewClass GtkSourceViewClass;
@@ -209,5 +212,10 @@ GtkSourceCompletion *
 GtkSourceGutter *gtk_source_view_get_gutter            (GtkSourceView     *view,
                                                          GtkTextWindowType  window_type);
 
+gboolean        gtk_source_view_get_show_code_folding  (GtkSourceView     *view);
+
+void            gtk_source_view_set_show_code_folding  (GtkSourceView     *view,
+                                                        gboolean           show);
+
 G_END_DECLS
 #endif                         /* end of SOURCE_VIEW_H__ */
diff --git a/tests/test-folding.c b/tests/test-folding.c
index 13c6a09..86859a7 100644
--- a/tests/test-folding.c
+++ b/tests/test-folding.c
@@ -21,17 +21,6 @@
 
 #include <gtksourceview/gtksource.h>
 
-static void
-add_folds_gutter (GtkSourceView *view)
-{
-       GtkSourceGutter *gutter;
-       GtkSourceGutterRenderer *renderer;
-
-       gutter = gtk_source_view_get_gutter (view, GTK_TEXT_WINDOW_LEFT);
-       renderer = gtk_source_gutter_renderer_folds_new ();
-       gtk_source_gutter_insert (gutter, renderer, 0);
-}
-
 int
 main (int argc, char *argv[])
 {
@@ -51,7 +40,7 @@ main (int argc, char *argv[])
        source_view = gtk_source_view_new ();
        gtk_container_add (GTK_CONTAINER (sw), source_view);
 
-       add_folds_gutter (GTK_SOURCE_VIEW (source_view));
+       gtk_source_view_set_show_code_folding (GTK_SOURCE_VIEW (source_view), TRUE);
 
        gtk_widget_show_all (window);
 


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