[gnome-builder/wip/chergert/perspective] libide: add IdeLoader interface
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/perspective] libide: add IdeLoader interface
- Date: Fri, 13 Nov 2015 09:37:06 +0000 (UTC)
commit 1a1e38f4407d15269c39371065b9d9ef61866341
Author: Christian Hergert <chergert redhat com>
Date: Fri Nov 13 01:36:50 2015 -0800
libide: add IdeLoader interface
I'm not super fond of the name, but the purpose of this interface is
to allow plugins to register loaders for files. A glade loader might
load a file with the Glade designer instead of the code editor. However,
the code editor might also be able to open the file.
We can display this in the "Open With" menu, but also use the priorities
to automatically "do the right thing".
libide/ide-loader.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++
libide/ide-loader.h | 57 ++++++++++++++++++++++++++++++
libide/ide-workbench.h | 5 +++
3 files changed, 151 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-loader.c b/libide/ide-loader.c
new file mode 100644
index 0000000..59fdaf0
--- /dev/null
+++ b/libide/ide-loader.c
@@ -0,0 +1,89 @@
+/* ide-loader.c
+ *
+ * Copyright (C) 2015 Christian Hergert <chergert redhat com>
+ *
+ * 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 "ide-loader.h"
+
+G_DEFINE_INTERFACE (IdeLoader, ide_loader, G_TYPE_OBJECT)
+
+static gchar *
+ide_loader_real_get_title (IdeLoader *self)
+{
+ return NULL;
+}
+
+static gboolean
+ide_loader_real_can_load_uri (IdeLoader *self,
+ IdeUri *uri,
+ const gchar *content_type,
+ gint *priority)
+{
+ *priority = 0;
+ return FALSE;
+}
+
+static gboolean
+ide_loader_real_load_uri (IdeLoader *self,
+ IdeUri *uri,
+ const gchar *content_type)
+{
+ return FALSE;
+}
+
+static void
+ide_loader_default_init (IdeLoaderInterface *iface)
+{
+ iface->get_title = ide_loader_real_get_title;
+ iface->can_load_uri = ide_loader_real_can_load_uri;
+ iface->load_uri = ide_loader_real_load_uri;
+}
+
+gboolean
+ide_loader_can_load_uri (IdeLoader *self,
+ IdeUri *uri,
+ const gchar *content_type,
+ gint *priority)
+{
+ gint dummy_priority;
+
+ g_return_val_if_fail (IDE_IS_LOADER (self), FALSE);
+ g_return_val_if_fail (uri != NULL, FALSE);
+
+ if (priority == NULL)
+ priority = &dummy_priority;
+
+ return IDE_LOADER_GET_IFACE (self)->can_load_uri (self, uri, content_type, priority);
+}
+
+gchar *
+ide_loader_get_title (IdeLoader *self)
+{
+ g_return_val_if_fail (IDE_IS_LOADER (self), NULL);
+
+ return IDE_LOADER_GET_IFACE (self)->get_title (self);
+}
+
+gboolean
+ide_loader_load_uri (IdeLoader *self,
+ IdeUri *uri,
+ const gchar *content_type)
+{
+ g_return_val_if_fail (IDE_IS_LOADER (self), FALSE);
+ g_return_val_if_fail (uri != NULL, FALSE);
+
+ return IDE_LOADER_GET_IFACE (self)->load_uri (self, uri, content_type);
+}
diff --git a/libide/ide-loader.h b/libide/ide-loader.h
new file mode 100644
index 0000000..5ac734f
--- /dev/null
+++ b/libide/ide-loader.h
@@ -0,0 +1,57 @@
+/* ide-loader.h
+ *
+ * Copyright (C) 2015 Christian Hergert <chergert redhat com>
+ *
+ * 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 IDE_LOADER_H
+#define IDE_LOADER_H
+
+#include <gio/gio.h>
+
+#include "ide-uri.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_LOADER (ide_loader_get_type())
+
+G_DECLARE_INTERFACE (IdeLoader, ide_loader, IDE, LOADER, GObject)
+
+struct _IdeLoaderInterface
+{
+ GTypeInterface parent_interface;
+
+ gchar *(*get_title) (IdeLoader *self);
+ gboolean (*can_load_uri) (IdeLoader *self,
+ IdeUri *uri,
+ const gchar *content_type,
+ gint *priority);
+ gboolean (*load_uri) (IdeLoader *self,
+ IdeUri *uri,
+ const gchar *content_type);
+};
+
+gboolean ide_loader_can_load_uri (IdeLoader *self,
+ IdeUri *uri,
+ const gchar *content_type,
+ gint *priority);
+gchar *ide_loader_get_title (IdeLoader *self);
+gboolean ide_loader_load_uri (IdeLoader *self,
+ IdeUri *uri,
+ const gchar *content_type);
+
+G_END_DECLS
+
+#endif /* IDE_LOADER_H */
diff --git a/libide/ide-workbench.h b/libide/ide-workbench.h
index 007afe6..164d5c8 100644
--- a/libide/ide-workbench.h
+++ b/libide/ide-workbench.h
@@ -22,6 +22,7 @@
#include <gtk/gtk.h>
#include "ide-context.h"
+#include "ide-loader.h"
#include "ide-perspective.h"
G_BEGIN_DECLS
@@ -50,6 +51,10 @@ void ide_workbench_focus (IdeWorkbench
GtkWidget *widget);
void ide_workbench_close (IdeWorkbench *self);
IdeContext *ide_workbench_get_context (IdeWorkbench *self);
+void ide_workbench_add_loader (IdeWorkbench *self,
+ IdeLoader *loader);
+void ide_workbench_remove_loader (IdeWorkbench *self,
+ IdeLoader *loader);
void ide_workbench_add_perspective (IdeWorkbench *self,
IdePerspective *perspective);
void ide_workbench_remove_perspective (IdeWorkbench *self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]