[gnome-builder/wip/libide] libide: add IdeBuffer::cursor-moved
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/libide] libide: add IdeBuffer::cursor-moved
- Date: Wed, 18 Mar 2015 22:21:46 +0000 (UTC)
commit 0b78bcf998dcb62c7ded03697ac8ac1ce116533f
Author: Christian Hergert <christian hergert me>
Date: Wed Mar 18 15:16:14 2015 -0700
libide: add IdeBuffer::cursor-moved
This is useful if you want to track when the cursor has moved in the buffer
such as for showing the current line:column
libide/ide-buffer.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++
libide/ide-buffer.h | 3 ++
2 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-buffer.c b/libide/ide-buffer.c
index a506e83..5a0b722 100644
--- a/libide/ide-buffer.c
+++ b/libide/ide-buffer.c
@@ -78,6 +78,7 @@ enum {
};
enum {
+ CURSOR_MOVED,
LINE_FLAGS_CHANGED,
LOADED,
LAST_SIGNAL
@@ -89,6 +90,19 @@ static GParamSpec *gParamSpecs [LAST_PROP];
static guint gSignals [LAST_SIGNAL];
static void
+ide_buffer_emit_cursor_moved (IdeBuffer *self)
+{
+ GtkTextMark *mark;
+ GtkTextIter iter;
+
+ g_assert (IDE_IS_BUFFER (self));
+
+ mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (self));
+ gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (self), &iter, mark);
+ g_signal_emit (self, gSignals [CURSOR_MOVED], 0, &iter);
+}
+
+static void
ide_buffer_get_iter_at_location (IdeBuffer *self,
GtkTextIter *iter,
IdeSourceLocation *location)
@@ -515,6 +529,36 @@ ide_buffer_changed (GtkTextBuffer *buffer)
}
static void
+ide_buffer_delete_range (GtkTextBuffer *buffer,
+ GtkTextIter *start,
+ GtkTextIter *end)
+{
+ GTK_TEXT_BUFFER_CLASS (ide_buffer_parent_class)->delete_range (buffer, start, end);
+ ide_buffer_emit_cursor_moved (IDE_BUFFER (buffer));
+}
+
+static void
+ide_buffer_insert_text (GtkTextBuffer *buffer,
+ GtkTextIter *location,
+ const gchar *text,
+ gint len)
+{
+ GTK_TEXT_BUFFER_CLASS (ide_buffer_parent_class)->insert_text (buffer, location, text, len);
+ ide_buffer_emit_cursor_moved (IDE_BUFFER (buffer));
+}
+
+static void
+ide_buffer_mark_set (GtkTextBuffer *buffer,
+ const GtkTextIter *iter,
+ GtkTextMark *mark)
+{
+ GTK_TEXT_BUFFER_CLASS (ide_buffer_parent_class)->mark_set (buffer, iter, mark);
+
+ if ((G_UNLIKELY (mark == gtk_text_buffer_get_insert (buffer))))
+ ide_buffer_emit_cursor_moved (IDE_BUFFER (buffer));
+}
+
+static void
ide_buffer_constructed (GObject *object)
{
IdeBuffer *self = (IdeBuffer *)object;
@@ -657,6 +701,9 @@ ide_buffer_class_init (IdeBufferClass *klass)
object_class->set_property = ide_buffer_set_property;
text_buffer_class->changed = ide_buffer_changed;
+ text_buffer_class->delete_range = ide_buffer_delete_range;
+ text_buffer_class->insert_text = ide_buffer_insert_text;
+ text_buffer_class->mark_set = ide_buffer_mark_set;
gParamSpecs [PROP_CONTEXT] =
g_param_spec_object ("context",
@@ -704,6 +751,26 @@ ide_buffer_class_init (IdeBufferClass *klass)
g_object_class_install_property (object_class, PROP_TITLE, gParamSpecs [PROP_TITLE]);
/**
+ * IdeBuffer::cursor-moved:
+ * @self: An #IdeBuffer.
+ * @location: A #GtkTextIter.
+ *
+ * This signal is emitted when the insertion location has moved. You might
+ * want to attach to this signal to update the location of the insert mark in
+ * the display.
+ */
+ gSignals [CURSOR_MOVED] =
+ g_signal_new ("cursor-moved",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (IdeBufferClass, cursor_moved),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOXED,
+ G_TYPE_NONE,
+ 1,
+ GTK_TYPE_TEXT_ITER);
+
+ /**
* IdeBuffer::line-flags-changed:
*
* This signal is emitted when the calculated line flags have changed. This occurs when
diff --git a/libide/ide-buffer.h b/libide/ide-buffer.h
index bcf5e0c..b43ddc4 100644
--- a/libide/ide-buffer.h
+++ b/libide/ide-buffer.h
@@ -51,6 +51,9 @@ typedef enum
struct _IdeBufferClass
{
GtkSourceBufferClass parent_class;
+
+ void (*cursor_moved) (IdeBuffer *self,
+ const GtkTextIter *location);
};
struct _IdeBuffer
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]