[gnome-builder/wip/libide] editor: load file from project tree upon node activation
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/libide] editor: load file from project tree upon node activation
- Date: Sun, 8 Feb 2015 03:42:45 +0000 (UTC)
commit 24dc287bdf00b697b8642fa70cb64c0f9e018e59
Author: Christian Hergert <christian hergert me>
Date: Sat Feb 7 19:41:26 2015 -0800
editor: load file from project tree upon node activation
We still need to adjust the GFile loaded for git files, but it works if
you run gnome-builder from your git repository. All will be fixed in
good time :)
src/tree/gb-project-tree-builder.c | 50 ++++++++++++++++++++++++++++++++++++
1 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/src/tree/gb-project-tree-builder.c b/src/tree/gb-project-tree-builder.c
index 53e96c3..9b6aa01 100644
--- a/src/tree/gb-project-tree-builder.c
+++ b/src/tree/gb-project-tree-builder.c
@@ -18,8 +18,11 @@
#include <glib/gi18n.h>
+#include "gb-editor-workspace.h"
#include "gb-project-tree-builder.h"
#include "gb-tree.h"
+#include "gb-widget.h"
+#include "gb-workbench.h"
typedef struct
{
@@ -223,6 +226,52 @@ gb_project_tree_builder_build_node (GbTreeBuilder *builder,
build_files (self, node);
}
+static gboolean
+gb_project_tree_builder_node_activated (GbTreeBuilder *builder,
+ GbTreeNode *node)
+{
+ GbProjectTreeBuilder *self = (GbProjectTreeBuilder *)builder;
+ GObject *item;
+
+ g_return_val_if_fail (GB_IS_PROJECT_TREE_BUILDER (self), FALSE);
+
+ item = gb_tree_node_get_item (node);
+
+ if (IDE_IS_PROJECT_FILE (item))
+ {
+ GbWorkbench *workbench;
+ GbWorkspace *workspace;
+ GFileInfo *file_info;
+ GbTree *tree;
+ GFile *file;
+
+ file_info = ide_project_file_get_file_info (IDE_PROJECT_FILE (item));
+ if (!file_info)
+ goto failure;
+
+ if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY)
+ goto failure;
+
+ file = ide_project_file_get_file (IDE_PROJECT_FILE (item));
+ if (!file)
+ goto failure;
+
+ tree = gb_tree_node_get_tree (node);
+ if (!tree)
+ goto failure;
+
+ workbench = gb_widget_get_workbench (GTK_WIDGET (tree));
+ workspace = gb_workbench_get_workspace (workbench,
+ GB_TYPE_EDITOR_WORKSPACE);
+ gb_editor_workspace_open (GB_EDITOR_WORKSPACE (workspace), file);
+
+ return TRUE;
+ }
+
+failure:
+ return FALSE;
+}
+
static void
gb_project_tree_builder_finalize (GObject *object)
{
@@ -283,6 +332,7 @@ gb_project_tree_builder_class_init (GbProjectTreeBuilderClass *klass)
object_class->set_property = gb_project_tree_builder_set_property;
tree_builder_class->build_node = gb_project_tree_builder_build_node;
+ tree_builder_class->node_activated = gb_project_tree_builder_node_activated;
gParamSpecs [PROP_CONTEXT] =
g_param_spec_object ("context",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]