[gnome-builder] project-tree: use IdeProject::file-trashed to remove old files
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] project-tree: use IdeProject::file-trashed to remove old files
- Date: Tue, 26 Apr 2016 05:16:03 +0000 (UTC)
commit 4ceb7ffe641b3ac19a81f5e43c4db199c4cb07a8
Author: Christian Hergert <christian hergert me>
Date: Mon Apr 25 22:15:50 2016 -0700
project-tree: use IdeProject::file-trashed to remove old files
This allows us to more readily handle other plugins using IdeProject to
remove files without involving the project tree.
plugins/project-tree/gb-project-tree-actions.c | 10 +----
plugins/project-tree/gb-project-tree.c | 60 ++++++++++++++++++++++++
2 files changed, 61 insertions(+), 9 deletions(-)
---
diff --git a/plugins/project-tree/gb-project-tree-actions.c b/plugins/project-tree/gb-project-tree-actions.c
index b84fda6..dad4989 100644
--- a/plugins/project-tree/gb-project-tree-actions.c
+++ b/plugins/project-tree/gb-project-tree-actions.c
@@ -658,24 +658,16 @@ gb_project_tree_actions__trash_file_cb (GObject *object,
IdeProject *project = (IdeProject *)object;
g_autoptr(IdeTreeNode) node = user_data;
g_autoptr(GError) error = NULL;
- IdeTreeNode *parent;
g_assert (IDE_IS_PROJECT (project));
g_assert (IDE_IS_TREE_NODE (node));
if (!ide_project_trash_file_finish (project, result, &error))
{
- /* todo: warning dialog */
+ /* TODO: warning dialog */
g_warning ("%s", error->message);
return;
}
-
- if ((parent = ide_tree_node_get_parent (node)))
- {
- ide_tree_node_invalidate (parent);
- ide_tree_node_expand (parent, FALSE);
- ide_tree_node_select (parent);
- }
}
typedef struct
diff --git a/plugins/project-tree/gb-project-tree.c b/plugins/project-tree/gb-project-tree.c
index cf3ca7b..73784f0 100644
--- a/plugins/project-tree/gb-project-tree.c
+++ b/plugins/project-tree/gb-project-tree.c
@@ -19,6 +19,7 @@
#define G_LOG_DOMAIN "project-tree"
#include <glib/gi18n.h>
+#include <ide.h>
#include "gb-project-file.h"
#include "gb-project-tree.h"
@@ -64,6 +65,8 @@ gb_project_tree_project_file_renamed (GbProjectTree *self,
GFile *dst_file,
IdeProject *project)
{
+ IDE_ENTRY;
+
g_assert (GB_IS_PROJECT_TREE (self));
g_assert (G_IS_FILE (src_file));
g_assert (G_IS_FILE (dst_file));
@@ -71,6 +74,57 @@ gb_project_tree_project_file_renamed (GbProjectTree *self,
ide_tree_rebuild (IDE_TREE (self));
gb_project_tree_reveal (self, dst_file);
+
+ IDE_EXIT;
+}
+
+static gboolean
+compare_to_file (gconstpointer a,
+ gconstpointer b)
+{
+ GFile *file = (GFile *)a;
+ GObject *item = (GObject *)b;
+
+ /*
+ * Our key (the GFile) is always @a.
+ * The potential match (maybe a GbProjectFile) is @b.
+ * @b may also be NULL.
+ */
+
+ g_assert (G_IS_FILE (file));
+ g_assert (!item || G_IS_OBJECT (item));
+
+ if (GB_IS_PROJECT_FILE (item))
+ return g_file_equal (file, gb_project_file_get_file (GB_PROJECT_FILE (item)));
+
+ return FALSE;
+}
+
+static void
+gb_project_tree_project_file_trashed (GbProjectTree *self,
+ GFile *file,
+ IdeProject *project)
+{
+ IdeTreeNode *node;
+
+ IDE_ENTRY;
+
+ g_assert (GB_IS_PROJECT_TREE (self));
+ g_assert (G_IS_FILE (file));
+ g_assert (IDE_IS_PROJECT (project));
+
+ node = ide_tree_find_custom (IDE_TREE (self), compare_to_file, file);
+
+ if (node != NULL)
+ {
+ IdeTreeNode *parent = ide_tree_node_get_parent (node);
+
+ ide_tree_node_invalidate (parent);
+ ide_tree_node_expand (parent, TRUE);
+ ide_tree_node_select (parent);
+ }
+
+ IDE_EXIT;
}
void
@@ -93,6 +147,12 @@ gb_project_tree_set_context (GbProjectTree *self,
self,
G_CONNECT_SWAPPED);
+ g_signal_connect_object (project,
+ "file-trashed",
+ G_CALLBACK (gb_project_tree_project_file_trashed),
+ self,
+ G_CONNECT_SWAPPED);
+
model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
root = ide_tree_node_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]