[gnome-builder] project-tree: fix create-file/create-folder from Empty node
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] project-tree: fix create-file/create-folder from Empty node
- Date: Tue, 10 May 2016 20:03:31 +0000 (UTC)
commit 03f49d82d97f66f684187449f2bfe48c2f8db4fd
Author: Christian Hergert <chergert redhat com>
Date: Tue May 10 23:03:19 2016 +0300
project-tree: fix create-file/create-folder from Empty node
If we select the "empty" node in the file tree (a single child to denote
that the directory was empty), we should still be able to create folders
and files as if we are in the parent directory.
plugins/project-tree/gb-project-tree-actions.c | 36 ++++++++++++++++++++++--
1 files changed, 33 insertions(+), 3 deletions(-)
---
diff --git a/plugins/project-tree/gb-project-tree-actions.c b/plugins/project-tree/gb-project-tree-actions.c
index dad4989..548fcdf 100644
--- a/plugins/project-tree/gb-project-tree-actions.c
+++ b/plugins/project-tree/gb-project-tree-actions.c
@@ -482,6 +482,28 @@ gb_project_tree_actions_new (GbProjectTree *self,
g_assert ((file_type == G_FILE_TYPE_DIRECTORY) ||
(file_type == G_FILE_TYPE_REGULAR));
+ /*
+ * If the selected item is NULL, but the parent is a GbProjectFile, then
+ * this was the "empty file" in a directory. We want to instead jump to
+ * the parent.
+ */
+ if (NULL != (selected = ide_tree_get_selected (IDE_TREE (self))))
+ {
+ if (NULL == ide_tree_node_get_item (selected))
+ {
+ IdeTreeNode *parent;
+
+ if (NULL != (parent = ide_tree_node_get_parent (selected)))
+ {
+ if (NULL != (item = ide_tree_node_get_item (parent)))
+ {
+ if (GB_IS_PROJECT_FILE (item))
+ ide_tree_node_select (parent);
+ }
+ }
+ }
+ }
+
again:
if (!(selected = ide_tree_get_selected (IDE_TREE (self))) ||
!(item = ide_tree_node_get_item (selected)) ||
@@ -836,7 +858,9 @@ gb_project_tree_actions_update (GbProjectTree *self)
{
GActionGroup *group;
IdeTreeNode *selection;
+ IdeTreeNode *parent;
GObject *item = NULL;
+ GObject *parent_item = NULL;
IDE_ENTRY;
@@ -847,13 +871,19 @@ gb_project_tree_actions_update (GbProjectTree *self)
selection = ide_tree_get_selected (IDE_TREE (self));
if (selection != NULL)
- item = ide_tree_node_get_item (selection);
+ {
+ item = ide_tree_node_get_item (selection);
+
+ parent = ide_tree_node_get_parent (selection);
+ if (parent != NULL)
+ parent_item = ide_tree_node_get_item (parent);
+ }
action_set (group, "new-file",
- "enabled", GB_IS_PROJECT_FILE (item),
+ "enabled", GB_IS_PROJECT_FILE (item) || GB_IS_PROJECT_FILE (parent_item),
NULL);
action_set (group, "new-directory",
- "enabled", GB_IS_PROJECT_FILE (item),
+ "enabled", GB_IS_PROJECT_FILE (item) || GB_IS_PROJECT_FILE (parent_item),
NULL);
action_set (group, "open",
"enabled", (GB_IS_PROJECT_FILE (item) && !project_file_is_directory (item)),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]