[gnome-builder] add source change monitor to document, gutter to frame
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] add source change monitor to document, gutter to frame
- Date: Fri, 28 Nov 2014 21:18:46 +0000 (UTC)
commit 83ebc410f2c8196bf34477c2d0e9cce3dcbec6e7
Author: Christian Hergert <christian hergert me>
Date: Fri Nov 28 04:03:12 2014 -0800
add source change monitor to document, gutter to frame
src/app/gb-application.c | 26 ++++++++++++
src/editor/gb-editor-document.c | 50 +++++++++++++++++++++--
src/editor/gb-editor-document.h | 13 ++++--
src/editor/gb-editor-frame.c | 53 ++++++++++++++++++-------
src/editor/gb-source-change-gutter-renderer.c | 6 +-
src/editor/gb-source-change-monitor.c | 8 +++-
6 files changed, 127 insertions(+), 29 deletions(-)
---
diff --git a/src/app/gb-application.c b/src/app/gb-application.c
index f3a5fa3..543112e 100644
--- a/src/app/gb-application.c
+++ b/src/app/gb-application.c
@@ -27,6 +27,8 @@
#include "gb-application.h"
#include "gb-editor-file-marks.h"
+#include "gb-editor-document.h"
+#include "gb-editor-frame.h"
#include "gb-editor-workspace.h"
#include "gb-log.h"
#include "gb-keybindings.h"
@@ -347,6 +349,30 @@ gb_application_activate (GApplication *application)
GbWorkbench *workbench;
GList *list;
+ {
+ GbEditorDocument *document;
+ GtkSourceFile *file;
+ GFile *gfile;
+ GtkWindow *window;
+ GtkWidget *frame;
+
+ file = gtk_source_file_new ();
+ gfile = g_file_new_for_path ("src/app/gb-application.c");
+ gtk_source_file_set_location (file, gfile);
+ g_object_unref (gfile);
+
+ document = g_object_new (GB_TYPE_EDITOR_DOCUMENT, "file", file, NULL);
+ g_object_unref (file);
+
+ window = g_object_new (GTK_TYPE_WINDOW, NULL);
+ frame = g_object_new (GB_TYPE_EDITOR_FRAME,
+ "document", document,
+ "visible", TRUE,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (frame));
+ gtk_window_present (window);
+ }
+
g_return_if_fail (GB_IS_APPLICATION (application));
list = gtk_application_get_windows (GTK_APPLICATION (application));
diff --git a/src/editor/gb-editor-document.c b/src/editor/gb-editor-document.c
index 9d61dbb..0c7d7d8 100644
--- a/src/editor/gb-editor-document.c
+++ b/src/editor/gb-editor-document.c
@@ -25,11 +25,14 @@
struct _GbEditorDocumentPrivate
{
- GtkSourceFile *file;
+ GtkSourceFile *file;
+ GbSourceChangeMonitor *change_monitor;
+ GBinding *file_binding;
};
enum {
PROP_0,
+ PROP_CHANGE_MONITOR,
PROP_FILE,
PROP_STYLE_SCHEME_NAME,
LAST_PROP
@@ -51,6 +54,14 @@ gb_editor_document_new (void)
return g_object_new (GB_TYPE_EDITOR_DOCUMENT, NULL);
}
+GbSourceChangeMonitor *
+gb_editor_document_get_change_monitor (GbEditorDocument *document)
+{
+ g_return_val_if_fail (GB_IS_EDITOR_DOCUMENT (document), NULL);
+
+ return document->priv->change_monitor;
+}
+
GtkSourceFile *
gb_editor_document_get_file (GbEditorDocument *document)
{
@@ -63,13 +74,27 @@ void
gb_editor_document_set_file (GbEditorDocument *document,
GtkSourceFile *file)
{
+ GbEditorDocumentPrivate *priv;
+
g_return_if_fail (GB_IS_EDITOR_DOCUMENT (document));
g_return_if_fail (!file || GTK_SOURCE_IS_FILE (file));
- if (file != document->priv->file)
+ priv = document->priv;
+
+ if (file != priv->file)
{
- g_clear_object (&document->priv->file);
- document->priv->file = file ? g_object_ref (file) : NULL;
+ g_clear_object (&priv->file);
+ g_clear_object (&priv->file_binding);
+
+ if (file)
+ {
+ priv->file = g_object_ref (file);
+ priv->file_binding =
+ g_object_bind_property (priv->file, "location",
+ priv->change_monitor, "file",
+ G_BINDING_SYNC_CREATE);
+ }
+
g_object_notify_by_pspec (G_OBJECT (document), gParamSpecs [PROP_FILE]);
}
}
@@ -117,6 +142,8 @@ gb_editor_document_finalize (GObject *object)
GbEditorDocumentPrivate *priv = GB_EDITOR_DOCUMENT (object)->priv;
g_clear_object (&priv->file);
+ g_clear_object (&priv->file_binding);
+ g_clear_object (&priv->change_monitor);
G_OBJECT_CLASS(gb_editor_document_parent_class)->finalize (object);
}
@@ -131,6 +158,10 @@ gb_editor_document_get_property (GObject *object,
switch (prop_id)
{
+ case PROP_CHANGE_MONITOR:
+ g_value_set_object (value, gb_editor_document_get_change_monitor (self));
+ break;
+
case PROP_FILE:
g_value_set_object (value, gb_editor_document_get_file (self));
break;
@@ -178,6 +209,15 @@ gb_editor_document_class_init (GbEditorDocumentClass *klass)
text_buffer_class->mark_set = gb_editor_document_mark_set;
text_buffer_class->changed = gb_editor_document_changed;
+ gParamSpecs [PROP_CHANGE_MONITOR] =
+ g_param_spec_object ("change-monitor",
+ _("Change Monitor"),
+ _("The change monitor for the backing file."),
+ GB_TYPE_SOURCE_CHANGE_MONITOR,
+ (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_CHANGE_MONITOR,
+ gParamSpecs [PROP_CHANGE_MONITOR]);
+
gParamSpecs [PROP_FILE] =
g_param_spec_object ("file",
_("File"),
@@ -212,6 +252,6 @@ static void
gb_editor_document_init (GbEditorDocument *document)
{
document->priv = gb_editor_document_get_instance_private (document);
-
document->priv->file = gtk_source_file_new ();
+ document->priv->change_monitor = gb_source_change_monitor_new (GTK_TEXT_BUFFER (document));
}
diff --git a/src/editor/gb-editor-document.h b/src/editor/gb-editor-document.h
index a03ad1d..80d8eda 100644
--- a/src/editor/gb-editor-document.h
+++ b/src/editor/gb-editor-document.h
@@ -21,6 +21,8 @@
#include <gtksourceview/gtksourcebuffer.h>
+#include "gb-source-change-monitor.h"
+
G_BEGIN_DECLS
#define GB_TYPE_EDITOR_DOCUMENT (gb_editor_document_get_type())
@@ -50,11 +52,12 @@ struct _GbEditorDocumentClass
void (*cursor_moved) (GbEditorDocument *document);
};
-GbEditorDocument *gb_editor_document_new (void);
-GType gb_editor_document_get_type (void) G_GNUC_CONST;
-GtkSourceFile *gb_editor_document_get_file (GbEditorDocument *document);
-void gb_editor_document_set_file (GbEditorDocument *document,
- GtkSourceFile *file);
+GbEditorDocument *gb_editor_document_new (void);
+GType gb_editor_document_get_type (void) G_GNUC_CONST;
+GtkSourceFile *gb_editor_document_get_file (GbEditorDocument *document);
+void gb_editor_document_set_file (GbEditorDocument *document,
+ GtkSourceFile *file);
+GbSourceChangeMonitor *gb_editor_document_get_change_monitor (GbEditorDocument *document);
G_END_DECLS
diff --git a/src/editor/gb-editor-frame.c b/src/editor/gb-editor-frame.c
index 8a4c880..50da2bf 100644
--- a/src/editor/gb-editor-frame.c
+++ b/src/editor/gb-editor-frame.c
@@ -22,6 +22,7 @@
#include "gb-editor-frame.h"
#include "gb-log.h"
+#include "gb-source-change-gutter-renderer.h"
#include "gb-source-search-highlighter.h"
#include "gb-source-view.h"
#include "gd-tagged-entry.h"
@@ -30,24 +31,25 @@
struct _GbEditorFramePrivate
{
/* Widgets owned by GtkBuilder */
- GtkSpinner *busy_spinner;
- NautilusFloatingBar *floating_bar;
- GtkButton *forward_search;
- GtkButton *backward_search;
- GtkScrolledWindow *scrolled_window;
- GtkRevealer *search_revealer;
- GdTaggedEntry *search_entry;
- GdTaggedEntryTag *search_entry_tag;
- GbSourceView *source_view;
+ GtkSpinner *busy_spinner;
+ GbSourceChangeGutterRenderer *diff_renderer;
+ NautilusFloatingBar *floating_bar;
+ GtkButton *forward_search;
+ GtkButton *backward_search;
+ GtkScrolledWindow *scrolled_window;
+ GtkRevealer *search_revealer;
+ GdTaggedEntry *search_entry;
+ GdTaggedEntryTag *search_entry_tag;
+ GbSourceView *source_view;
/* Objects owned by GbEditorFrame */
- GbEditorDocument *document;
- GtkSourceSearchContext *search_context;
- GtkSourceSearchSettings *search_settings;
- GbSourceSearchHighlighter *search_highlighter;
+ GbEditorDocument *document;
+ GtkSourceSearchContext *search_context;
+ GtkSourceSearchSettings *search_settings;
+ GbSourceSearchHighlighter *search_highlighter;
/* Signal handler identifiers */
- gulong cursor_moved_handler;
+ gulong cursor_moved_handler;
};
G_DEFINE_TYPE_WITH_PRIVATE (GbEditorFrame, gb_editor_frame, GTK_TYPE_OVERLAY)
@@ -239,6 +241,7 @@ gb_editor_frame_connect (GbEditorFrame *frame,
GbEditorDocument *document)
{
GbEditorFramePrivate *priv;
+ GbSourceChangeMonitor *monitor;
ENTRY;
@@ -253,6 +256,11 @@ gb_editor_frame_connect (GbEditorFrame *frame,
gtk_text_view_set_buffer (GTK_TEXT_VIEW (priv->source_view),
GTK_TEXT_BUFFER (priv->document));
+ monitor = gb_editor_document_get_change_monitor (document);
+ g_object_set (priv->diff_renderer,
+ "change-monitor", monitor,
+ NULL);
+
priv->search_settings = g_object_new (GTK_SOURCE_TYPE_SEARCH_SETTINGS,
NULL);
@@ -474,11 +482,28 @@ gb_editor_frame_finalize (GObject *object)
static void
gb_editor_frame_constructed (GObject *object)
{
+ GbSourceChangeMonitor *monitor = NULL;
GbEditorFramePrivate *priv = GB_EDITOR_FRAME (object)->priv;
+ GtkSourceGutter *gutter;
GbEditorFrame *frame = GB_EDITOR_FRAME (object);
G_OBJECT_CLASS (gb_editor_frame_parent_class)->constructed (object);
+ if (priv->document)
+ monitor = gb_editor_document_get_change_monitor (priv->document);
+
+ gutter = gtk_source_view_get_gutter (GTK_SOURCE_VIEW (priv->source_view),
+ GTK_TEXT_WINDOW_LEFT);
+ priv->diff_renderer = g_object_new (GB_TYPE_SOURCE_CHANGE_GUTTER_RENDERER,
+ "change-monitor", monitor,
+ "size", 2,
+ "visible", TRUE,
+ "xpad", 1,
+ NULL);
+ gtk_source_gutter_insert (gutter,
+ GTK_SOURCE_GUTTER_RENDERER (priv->diff_renderer),
+ 0);
+
g_signal_connect_object (priv->source_view,
"focus-in-event",
G_CALLBACK (gb_editor_frame_on_focus_in_event),
diff --git a/src/editor/gb-source-change-gutter-renderer.c b/src/editor/gb-source-change-gutter-renderer.c
index b79f424..4f040b8 100644
--- a/src/editor/gb-source-change-gutter-renderer.c
+++ b/src/editor/gb-source-change-gutter-renderer.c
@@ -90,6 +90,8 @@ gb_source_change_gutter_renderer_set_change_monitor (GbSourceChangeGutterRendere
G_CALLBACK (on_changed),
renderer);
}
+
+ gtk_source_gutter_renderer_queue_draw (GTK_SOURCE_GUTTER_RENDERER (renderer));
}
static void
@@ -196,9 +198,7 @@ gb_source_change_gutter_renderer_class_init (GbSourceChangeGutterRendererClass *
_("Change Monitor"),
_("The change monitor for the gutter renderer."),
GB_TYPE_SOURCE_CHANGE_MONITOR,
- (G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_CHANGE_MONITOR,
gParamSpecs [PROP_CHANGE_MONITOR]);
}
diff --git a/src/editor/gb-source-change-monitor.c b/src/editor/gb-source-change-monitor.c
index cb27e79..0805bc2 100644
--- a/src/editor/gb-source-change-monitor.c
+++ b/src/editor/gb-source-change-monitor.c
@@ -484,12 +484,16 @@ gb_source_change_monitor_set_buffer (GbSourceChangeMonitor *monitor,
{
g_signal_handler_disconnect (priv->buffer, priv->changed_handler);
priv->changed_handler = 0;
- g_clear_object (&priv->buffer);
+ g_object_remove_weak_pointer (G_OBJECT (priv->buffer),
+ (gpointer *)&priv->buffer);
}
if (buffer)
{
- priv->buffer = g_object_ref (buffer);
+ priv->buffer = buffer;
+ g_object_add_weak_pointer (G_OBJECT (priv->buffer),
+ (gpointer *)&priv->buffer);
+
priv->changed_handler =
g_signal_connect_object (priv->buffer,
"changed",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]