[gnome-builder/document-manager: 1/4] GbDocumentManager: start on document manager to manage live buffers



commit 366724ed822418e621bd826837165da46b0f76d4
Author: Christian Hergert <christian hergert me>
Date:   Tue Dec 2 18:20:06 2014 -0800

    GbDocumentManager: start on document manager to manage live buffers
    
    The long term idea here is that all the open GtkTextBuffer's will be
    managed by this. I think we may also add a generic document interface
    so that things like glade documents can also be managed here. Not sure
    yet though.
    
    Then, we can attach this buffer manager to the combobox in the
    GbTabStack. At that point, we can dynamically create GbEditorTab or
    GbEditorFrame instances to the documents as needed. You can then just
    display any document easily on any tab stack.

 src/documents/gb-document-manager.c |  170 +++++++++++++++++++++++++++++++++++
 src/documents/gb-document-manager.h |   63 +++++++++++++
 src/gnome-builder.mk                |    3 +
 3 files changed, 236 insertions(+), 0 deletions(-)
---
diff --git a/src/documents/gb-document-manager.c b/src/documents/gb-document-manager.c
new file mode 100644
index 0000000..48bd930
--- /dev/null
+++ b/src/documents/gb-document-manager.c
@@ -0,0 +1,170 @@
+/* gb-document-manager.c
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gb-document-manager.h"
+
+G_DEFINE_TYPE (GbDocumentManager, gb_document_manager, GTK_TYPE_LIST_STORE)
+
+enum {
+  COLUMN_DOCUMENT,
+  LAST_COLUMN
+};
+
+GbDocumentManager *
+gb_document_manager_new (void)
+{
+  return g_object_new (GB_TYPE_DOCUMENT_MANAGER, NULL);
+}
+
+gboolean
+gb_document_manager_find_document (GbDocumentManager *manager,
+                                   GbEditorDocument  *document,
+                                   GtkTreeIter       *iter)
+{
+  g_return_val_if_fail (GB_IS_DOCUMENT_MANAGER (manager), FALSE);
+  g_return_val_if_fail (GB_IS_EDITOR_DOCUMENT (document), FALSE);
+
+  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (manager), iter))
+    {
+      do
+        {
+          GValue value = { 0 };
+
+          gtk_tree_model_get_value (GTK_TREE_MODEL (manager), iter,
+                                    COLUMN_DOCUMENT, &value);
+
+          if (G_VALUE_HOLDS_OBJECT (&value) &&
+              (g_value_get_object (&value) == (void *)document))
+            {
+              g_value_unset (&value);
+              return TRUE;
+            }
+
+          g_value_unset (&value);
+        }
+      while (gtk_tree_model_iter_next (GTK_TREE_MODEL (manager), iter));
+    }
+
+  return FALSE;
+}
+
+void
+gb_document_manager_document_changed (GbDocumentManager *manager,
+                                      GbEditorDocument  *document)
+{
+  GtkTreeIter iter;
+
+  g_return_if_fail (GB_IS_DOCUMENT_MANAGER (manager));
+  g_return_if_fail (GB_IS_EDITOR_DOCUMENT (document));
+
+  if (gb_document_manager_find_document (manager, document, &iter))
+    {
+      GtkTreePath *tree_path;
+
+      tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (manager), &iter);
+      gtk_tree_model_row_changed (GTK_TREE_MODEL (manager), tree_path, &iter);
+      gtk_tree_path_free (tree_path);
+    }
+}
+
+static void
+gb_document_manager_on_notify_dirty (GbDocumentManager *manager,
+                                     GParamSpec        *pspec,
+                                     GbEditorDocument  *document)
+{
+  gb_document_manager_document_changed (manager, document);
+}
+
+static void
+gb_document_manager_on_notify_title (GbDocumentManager *manager,
+                                     GParamSpec        *pspec,
+                                     GbEditorDocument  *document)
+{
+  gb_document_manager_document_changed (manager, document);
+}
+
+/**
+ * gb_document_manager_add_document:
+ * @manager: A #GbDocumentManager.
+ * @document: A #GbEditorDocument.
+ *
+ * Adds A #GbEditorDocument to the collection of buffers managed by the
+ * #GbDocumentManager instance.
+ */
+void
+gb_document_manager_add_document (GbDocumentManager *manager,
+                                  GbEditorDocument  *document)
+{
+  GtkTreeIter iter;
+
+  g_return_if_fail (GB_IS_DOCUMENT_MANAGER (manager));
+  g_return_if_fail (GB_IS_EDITOR_DOCUMENT (document));
+
+  g_signal_connect_object (document,
+                           "notify::title",
+                           G_CALLBACK (gb_document_manager_on_notify_title),
+                           manager,
+                           G_CONNECT_SWAPPED);
+
+  g_signal_connect_object (document,
+                           "notify::dirty",
+                           G_CALLBACK (gb_document_manager_on_notify_dirty),
+                           manager,
+                           G_CONNECT_SWAPPED);
+
+  gtk_list_store_append (GTK_LIST_STORE (manager), &iter);
+  gtk_list_store_set (GTK_LIST_STORE (manager), &iter,
+                      COLUMN_DOCUMENT, document,
+                      -1);
+}
+
+/**
+ * gb_document_manager_remove_document:
+ *
+ * Removes the #GbEditorDocument instance @document from being managed by
+ * the #GbDocumentManager instance.
+ *
+ * Returns: %TRUE if the document was removed.
+ */
+gboolean
+gb_document_manager_remove_document (GbDocumentManager *manager,
+                                     GbEditorDocument  *document)
+{
+  GtkTreeIter iter;
+
+  g_return_val_if_fail (GB_IS_DOCUMENT_MANAGER (manager), FALSE);
+  g_return_val_if_fail (GB_IS_EDITOR_DOCUMENT (document), FALSE);
+
+  if (gb_document_manager_find_document (manager, document, &iter))
+    {
+      gtk_list_store_remove (GTK_LIST_STORE (manager), &iter);
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+static void
+gb_document_manager_class_init (GbDocumentManagerClass *klass)
+{
+}
+
+static void
+gb_document_manager_init (GbDocumentManager *self)
+{
+}
diff --git a/src/documents/gb-document-manager.h b/src/documents/gb-document-manager.h
new file mode 100644
index 0000000..2db9315
--- /dev/null
+++ b/src/documents/gb-document-manager.h
@@ -0,0 +1,63 @@
+/* gb-document-manager.h
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GB_DOCUMENT_MANAGER_H
+#define GB_DOCUMENT_MANAGER_H
+
+#include <gtk/gtk.h>
+
+#include "gb-editor-document.h"
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_DOCUMENT_MANAGER            (gb_document_manager_get_type())
+#define GB_DOCUMENT_MANAGER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GB_TYPE_DOCUMENT_MANAGER, 
GbDocumentManager))
+#define GB_DOCUMENT_MANAGER_CONST(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), GB_TYPE_DOCUMENT_MANAGER, 
GbDocumentManager const))
+#define GB_DOCUMENT_MANAGER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GB_TYPE_DOCUMENT_MANAGER, 
GbDocumentManagerClass))
+#define GB_IS_DOCUMENT_MANAGER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GB_TYPE_DOCUMENT_MANAGER))
+#define GB_IS_DOCUMENT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GB_TYPE_DOCUMENT_MANAGER))
+#define GB_DOCUMENT_MANAGER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GB_TYPE_DOCUMENT_MANAGER, 
GbDocumentManagerClass))
+
+typedef struct _GbDocumentManager        GbDocumentManager;
+typedef struct _GbDocumentManagerClass   GbDocumentManagerClass;
+typedef struct _GbDocumentManagerPrivate GbDocumentManagerPrivate;
+
+struct _GbDocumentManager
+{
+  GtkListStore parent;
+
+  /*< private >*/
+  GbDocumentManagerPrivate *priv;
+};
+
+struct _GbDocumentManagerClass
+{
+  GtkListStoreClass parent;
+};
+
+GType              gb_document_manager_get_type        (void);
+GbDocumentManager *gb_document_manager_new             (void);
+GbDocumentManager *gb_document_manager_get_default     (void);
+void               gb_document_manager_add_document    (GbDocumentManager *manager,
+                                                        GbEditorDocument  *document);
+gboolean           gb_document_manager_remove_document (GbDocumentManager *manager,
+                                                        GbEditorDocument  *document);
+
+G_END_DECLS
+
+#endif /* GB_DOCUMENT_MANAGER_H */
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index d4b9d55..62bbd45 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -43,6 +43,8 @@ libgnome_builder_la_SOURCES = \
        src/credits/gb-credits-widget.h \
        src/devhelp/gb-devhelp-tab.c \
        src/devhelp/gb-devhelp-tab.h \
+       src/documents/gb-document-manager.c \
+       src/documents/gb-document-manager.h \
        src/editor/c-parse-helper.c \
        src/editor/c-parse-helper.h \
        src/editor/gb-editor-document.c \
@@ -205,6 +207,7 @@ libgnome_builder_la_CFLAGS = \
        -I$(top_srcdir)/src/code-assistant \
        -I$(top_srcdir)/src/credits \
        -I$(top_srcdir)/src/devhelp \
+       -I$(top_srcdir)/src/documents \
        -I$(top_srcdir)/src/editor \
        -I$(top_srcdir)/src/gca \
        -I$(top_srcdir)/src/gd \


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