[gnome-builder] buffer: add helper to get IdeSourceLocation for an iter
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] buffer: add helper to get IdeSourceLocation for an iter
- Date: Wed, 26 Oct 2016 06:05:04 +0000 (UTC)
commit b7cd7c20289981643970d149c4fc56d77d417dde
Author: Christian Hergert <chergert redhat com>
Date: Tue Oct 25 23:01:45 2016 -0700
buffer: add helper to get IdeSourceLocation for an iter
libide/buffers/ide-buffer.c | 44 +++++++++++++++++++++++++++++++++++++++++++
libide/buffers/ide-buffer.h | 3 ++
2 files changed, 47 insertions(+), 0 deletions(-)
---
diff --git a/libide/buffers/ide-buffer.c b/libide/buffers/ide-buffer.c
index 79c73a2..c8835ae 100644
--- a/libide/buffers/ide-buffer.c
+++ b/libide/buffers/ide-buffer.c
@@ -2745,3 +2745,47 @@ ide_buffer_get_uri (IdeBuffer *self)
return g_file_get_uri (gfile);
}
+
+/**
+ * ide_buffer_get_iter_location:
+ *
+ * Gets the location of the iter as an #IdeSourceLocation.
+ *
+ * Returns: (transfer full): An #IdeSourceLocation
+ */
+IdeSourceLocation *
+ide_buffer_get_iter_location (IdeBuffer *self,
+ const GtkTextIter *iter)
+{
+ IdeBufferPrivate *priv = ide_buffer_get_instance_private (self);
+
+ g_return_val_if_fail (IDE_IS_BUFFER (self), NULL);
+ g_return_val_if_fail (iter != NULL, NULL);
+ g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == GTK_TEXT_BUFFER (self), NULL);
+
+ return ide_source_location_new (priv->file,
+ gtk_text_iter_get_line (iter),
+ gtk_text_iter_get_line_offset (iter),
+ gtk_text_iter_get_offset (iter));
+}
+
+/**
+ * ide_buffer_get_insert_location:
+ *
+ * Gets the location of the insert mark as an #IdeSourceLocation.
+ *
+ * Returns: (transfer full): An #IdeSourceLocation
+ */
+IdeSourceLocation *
+ide_buffer_get_insert_location (IdeBuffer *self)
+{
+ GtkTextMark *mark;
+ GtkTextIter iter;
+
+ g_return_val_if_fail (IDE_IS_BUFFER (self), NULL);
+
+ mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (self));
+ gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (self), &iter, mark);
+
+ return ide_buffer_get_iter_location (self, &iter);
+}
diff --git a/libide/buffers/ide-buffer.h b/libide/buffers/ide-buffer.h
index 5a6c49f..d2c6e07 100644
--- a/libide/buffers/ide-buffer.h
+++ b/libide/buffers/ide-buffer.h
@@ -83,6 +83,9 @@ void ide_buffer_set_style_scheme_name (IdeBuffer
const gchar *style_scheme_name);
void ide_buffer_trim_trailing_whitespace (IdeBuffer *self);
void ide_buffer_check_for_volume_change (IdeBuffer *self);
+IdeSourceLocation *ide_buffer_get_insert_location (IdeBuffer *self);
+IdeSourceLocation *ide_buffer_get_iter_location (IdeBuffer *self,
+ const GtkTextIter *iter);
void ide_buffer_get_iter_at_source_location (IdeBuffer *self,
GtkTextIter *iter,
IdeSourceLocation *location);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]