From c620e48c96a4205e972e8b8cf46f163b721dbec4 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Fri, 10 Feb 2017 00:18:17 -0800 Subject: [PATCH] xed-view: Add some margin to the top and left of the text view --- xed/xed-view-gutter-renderer.c | 16 ++++++++++++++++ xed/xed-view-gutter-renderer.h | 35 ++++++++++++++++++++++++++++++++++ xed/xed-view.c | 13 +++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 xed/xed-view-gutter-renderer.c create mode 100644 xed/xed-view-gutter-renderer.h diff --git a/xed/xed-view-gutter-renderer.c b/xed/xed-view-gutter-renderer.c new file mode 100644 index 0000000..f516543 --- /dev/null +++ b/xed/xed-view-gutter-renderer.c @@ -0,0 +1,16 @@ +#include "xed-view-gutter-renderer.h" + +#define XED_VIEW_GUTTER_RENDERER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), XED_VIEW_GUTTER_RENDERER, XedViewGutterRendererPrivate)) + +G_DEFINE_TYPE (XedViewGutterRenderer, xed_view_gutter_renderer, GTK_SOURCE_TYPE_GUTTER_RENDERER) + +static void +xed_view_gutter_renderer_class_init (XedViewGutterRendererClass *klass) +{ + GtkSourceGutterRendererClass *renderer_class = GTK_SOURCE_GUTTER_RENDERER_CLASS (klass); +} + +static void +xed_view_gutter_renderer_init (XedViewGutterRenderer *self) +{ +} diff --git a/xed/xed-view-gutter-renderer.h b/xed/xed-view-gutter-renderer.h new file mode 100644 index 0000000..e863817 --- /dev/null +++ b/xed/xed-view-gutter-renderer.h @@ -0,0 +1,35 @@ +#ifndef __XED_VIEW_GUTTER_RENDERER_H__ +#define __XED_VIEW_GUTTER_RENDERER_H__ + +#include + +G_BEGIN_DECLS + +#define XED_TYPE_VIEW_GUTTER_RENDERER (xed_view_gutter_renderer_get_type ()) +#define XED_VIEW_GUTTER_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_VIEW_GUTTER_RENDERER, XedViewGutterRenderer)) +#define XED_VIEW_GUTTER_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_VIEW_GUTTER_RENDERER, XedViewGutterRendererClass)) +#define XED_IS_VIEW_GUTTER_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_VIEW_GUTTER_RENDERER)) +#define XED_IS_VIEW_GUTTER_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_VIEW_GUTTER_RENDERER)) +#define XED_VIEW_GUTTER_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_VIEW_GUTTER_RENDERER, XedViewGutterRendererClass)) + +typedef struct _XedViewGutterRenderer XedViewGutterRenderer; +typedef struct _XedViewGutterRendererClass XedViewGutterRendererClass; +typedef struct _XedViewGutterRendererPrivate XedViewGutterRendererPrivate; + +struct _XedViewGutterRenderer +{ + GtkSourceGutterRenderer parent; + + XedViewGutterRendererPrivate *priv; +}; + +struct _XedViewGutterRendererClass +{ + GtkSourceGutterRendererClass parent_instance; +}; + +GType xed_view_gutter_renderer_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* __XED_VIEW_GUTTER_RENDERER_H__ */ \ No newline at end of file diff --git a/xed/xed-view.c b/xed/xed-view.c index 01040cb..551e91a 100644 --- a/xed/xed-view.c +++ b/xed/xed-view.c @@ -10,6 +10,7 @@ #include #include "xed-view.h" +#include "xed-view-gutter-renderer.h" #include "xed-view-activatable.h" #include "xed-plugins-engine.h" #include "xed-debug.h" @@ -32,6 +33,7 @@ struct _XedViewPrivate GSettings *editor_settings; GtkTextBuffer *current_buffer; PeasExtensionSet *extensions; + GtkSourceGutterRenderer *renderer; guint view_realized : 1; }; @@ -143,6 +145,7 @@ xed_view_dispose (GObject *object) g_clear_object (&view->priv->extensions); g_clear_object (&view->priv->editor_settings); + g_clear_object (&view->priv->renderer); current_buffer_removed (view); @@ -163,6 +166,7 @@ xed_view_constructed (GObject *object) XedView *view; XedViewPrivate *priv; gboolean use_default_font; + GtkSourceGutter *gutter; view = XED_VIEW (object); priv = view->priv; @@ -246,6 +250,15 @@ xed_view_constructed (GObject *object) "indent_on_tab", TRUE, NULL); + gutter = gtk_source_view_get_gutter (GTK_SOURCE_VIEW (view), GTK_TEXT_WINDOW_LEFT); + priv->renderer = g_object_new (XED_TYPE_VIEW_GUTTER_RENDERER, + "size", 2, + NULL); + g_object_ref (priv->renderer); + gtk_source_gutter_insert (gutter, priv->renderer, 0); + + gtk_text_view_set_top_margin (GTK_TEXT_VIEW (view), 2); + G_OBJECT_CLASS (xed_view_parent_class)->constructed (object); }