[gnome-builder/document-manager] GbDocumentManager: add find_with_type() helper
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/document-manager] GbDocumentManager: add find_with_type() helper
- Date: Wed, 10 Dec 2014 00:40:44 +0000 (UTC)
commit 80f4a72a3e4fa610aeca7338e2da05ac642dc2ff
Author: Christian Hergert <christian hergert me>
Date: Tue Dec 9 16:38:01 2014 -0800
GbDocumentManager: add find_with_type() helper
This will return the first document matching a given type. Convenient
if you have a singleton type document.
src/documents/gb-document-manager.c | 22 ++++++++++++++++++++++
src/documents/gb-document-manager.h | 2 ++
2 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/src/documents/gb-document-manager.c b/src/documents/gb-document-manager.c
index 09fb25d..0bf71ed 100644
--- a/src/documents/gb-document-manager.c
+++ b/src/documents/gb-document-manager.c
@@ -74,6 +74,28 @@ gb_document_manager_get_count (GbDocumentManager *manager)
}
GbDocument *
+gb_document_manager_find_with_type (GbDocumentManager *manager,
+ GType type)
+{
+ guint i;
+
+ g_return_val_if_fail (GB_IS_DOCUMENT_MANAGER (manager), NULL);
+ g_return_val_if_fail (g_type_is_a (type, GB_TYPE_DOCUMENT), NULL);
+
+ for (i = 0; i < manager->priv->documents->len; i++)
+ {
+ GbDocument *document;
+
+ document = g_ptr_array_index (manager->priv->documents, i);
+
+ if (g_type_is_a (G_TYPE_FROM_INSTANCE (document), type))
+ return document;
+ }
+
+ return NULL;
+}
+
+GbDocument *
gb_document_manager_find_with_file (GbDocumentManager *manager,
GFile *file)
{
diff --git a/src/documents/gb-document-manager.h b/src/documents/gb-document-manager.h
index 6c01fde..b31d506 100644
--- a/src/documents/gb-document-manager.h
+++ b/src/documents/gb-document-manager.h
@@ -68,6 +68,8 @@ GList *gb_document_manager_get_documents (GbDocumentManager *manage
guint gb_document_manager_get_count (GbDocumentManager *manager);
GbDocument *gb_document_manager_find_with_file (GbDocumentManager *manager,
GFile *file);
+GbDocument *gb_document_manager_find_with_type (GbDocumentManager *manager,
+ GType type);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]