[gnome-builder] buffer: add ide_buffer_get_iter_at_source_location()



commit fe97c19a9a1106636ff9fb56dd82ee43ce632610
Author: Christian Hergert <christian hergert me>
Date:   Wed Mar 25 01:40:31 2015 -0700

    buffer: add ide_buffer_get_iter_at_source_location()
    
    This helper will get a GtkTextIter for an IdeSourceLocation. The file
    field of the location is not checked and assumed to be within the buffer.

 libide/ide-buffer.c |   21 +++++++++++++++++++++
 libide/ide-buffer.h |    3 +++
 2 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-buffer.c b/libide/ide-buffer.c
index 0836353..8408ba8 100644
--- a/libide/ide-buffer.c
+++ b/libide/ide-buffer.c
@@ -1601,3 +1601,24 @@ _ide_buffer_set_mtime (IdeBuffer      *self,
 
   IDE_EXIT;
 }
+
+void
+ide_buffer_get_iter_at_source_location (IdeBuffer         *self,
+                                        GtkTextIter       *iter,
+                                        IdeSourceLocation *location)
+{
+  guint line;
+  guint line_offset;
+
+  g_return_if_fail (IDE_IS_BUFFER (self));
+  g_return_if_fail (iter != NULL);
+  g_return_if_fail (location != NULL);
+
+  line = ide_source_location_get_line (location);
+  line_offset = ide_source_location_get_line_offset (location);
+
+  gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (self), iter, line);
+  for (; line_offset; line_offset--)
+    if (gtk_text_iter_ends_line (iter) || !gtk_text_iter_forward_char (iter))
+      break;
+}
diff --git a/libide/ide-buffer.h b/libide/ide-buffer.h
index aa17d8b..1891133 100644
--- a/libide/ide-buffer.h
+++ b/libide/ide-buffer.h
@@ -84,6 +84,9 @@ void                ide_buffer_set_style_scheme_name     (IdeBuffer         *sel
                                                           const gchar       *style_scheme_name);
 void                ide_buffer_trim_trailing_whitespace  (IdeBuffer         *self);
 void                ide_buffer_check_for_volume_change   (IdeBuffer         *self);
+void                ide_buffer_get_iter_at_source_location(IdeBuffer        *self,
+                                                          GtkTextIter       *iter,
+                                                          IdeSourceLocation *location);
 
 G_END_DECLS
 


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