[gnome-builder/wip/libide] libide: add some buffer helpers



commit f793aa2e35c10dc84491017adae543b048906756
Author: Christian Hergert <christian hergert me>
Date:   Fri Mar 13 02:48:22 2015 -0700

    libide: add some buffer helpers

 libide/ide-buffer-manager.c |   50 +++++++++++++++++++++++++++++++++++++++++++
 libide/ide-buffer-manager.h |    4 +++
 2 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-buffer-manager.c b/libide/ide-buffer-manager.c
index 74d8b54..dc8b58b 100644
--- a/libide/ide-buffer-manager.c
+++ b/libide/ide-buffer-manager.c
@@ -1111,3 +1111,53 @@ ide_buffer_manager_get_word_completion (IdeBufferManager *self)
 
   return self->word_completion;
 }
+
+/**
+ * ide_buffer_manager_find_buffer:
+ * @self: (in): An #IdeBufferManager.
+ * @file: (in): An #IdeFile.
+ *
+ * Gets the buffer for a given file. If it has not yet been loaded, %NULL is
+ * returned.
+ *
+ * Returns: (transfer none) (nullable): An #IdeBuffer or %NULL.
+ */
+IdeBuffer *
+ide_buffer_manager_find_buffer (IdeBufferManager *self,
+                                IdeFile          *file)
+{
+  gsize i;
+
+  g_return_val_if_fail (IDE_IS_BUFFER_MANAGER (self), NULL);
+  g_return_val_if_fail (IDE_IS_FILE (file), NULL);
+
+  for (i = 0; i < self->buffers->len; i++)
+    {
+      IdeBuffer *buffer;
+      IdeFile *buffer_file;
+
+      buffer = g_ptr_array_index (self->buffers, i);
+      buffer_file = ide_buffer_get_file (buffer);
+
+      if (ide_file_equal (buffer_file, file))
+        return buffer;
+    }
+
+  return NULL;
+}
+
+/**
+ * ide_buffer_manager_has_file:
+ * @self: (in): An #IdeBufferManager.
+ * @file: (in): An #IdeFile.
+ *
+ * Checks to see if the buffer manager has the file loaded.
+ *
+ * Returns: %TRUE if @file is loaded.
+ */
+gboolean
+ide_buffer_manager_has_file (IdeBufferManager *self,
+                             IdeFile          *file)
+{
+  return !!ide_buffer_manager_find_buffer (self, file);
+}
diff --git a/libide/ide-buffer-manager.h b/libide/ide-buffer-manager.h
index 5f944c4..d0ec766 100644
--- a/libide/ide-buffer-manager.h
+++ b/libide/ide-buffer-manager.h
@@ -55,6 +55,10 @@ void                      ide_buffer_manager_set_focus_buffer    (IdeBufferManag
                                                                   IdeBuffer            *buffer);
 GPtrArray                *ide_buffer_manager_get_buffers         (IdeBufferManager     *self);
 GtkSourceCompletionWords *ide_buffer_manager_get_word_completion (IdeBufferManager     *self);
+gboolean                  ide_buffer_manager_has_file            (IdeBufferManager     *self,
+                                                                  IdeFile              *file);
+IdeBuffer                *ide_buffer_manager_find_buffer         (IdeBufferManager     *self,
+                                                                  IdeFile              *file);
 
 G_END_DECLS
 


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