[anjuta] dir-project: Merge root and top group node
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] dir-project: Merge root and top group node
- Date: Mon, 20 Feb 2012 19:57:55 +0000 (UTC)
commit 389d56ee424cec661283689d3ec72edb59b29423
Author: SÃbastien Granjoux <seb sfo free fr>
Date: Sat Feb 18 12:16:31 2012 +0100
dir-project: Merge root and top group node
plugins/dir-project/dir-node.c | 132 ++++++++++++++++--------------------
plugins/dir-project/dir-node.h | 14 ++++-
plugins/dir-project/dir-project.c | 71 +++++++-------------
plugins/dir-project/dir-project.h | 4 -
4 files changed, 94 insertions(+), 127 deletions(-)
---
diff --git a/plugins/dir-project/dir-node.c b/plugins/dir-project/dir-node.c
index 14f2f4d..48dcd4d 100644
--- a/plugins/dir-project/dir-node.c
+++ b/plugins/dir-project/dir-node.c
@@ -30,43 +30,18 @@
#include <libanjuta/anjuta-debug.h>
-
/* Root objects
*---------------------------------------------------------------------------*/
-struct _AnjutaDirRootNode {
- AnjutaProjectNode base;
-};
-
-AnjutaProjectNode*
-dir_root_node_new (GFile *file)
-{
- AnjutaDirRootNode *root = NULL;
-
- root = g_object_new (ANJUTA_TYPE_DIR_ROOT_NODE, NULL);
- root->base.type = ANJUTA_PROJECT_ROOT;
- root->base.properties = NULL;
- root->base.properties_info = NULL;
- root->base.file = g_file_dup (file);
- root->base.name = NULL;
-
- return ANJUTA_PROJECT_NODE (root);
-}
-
/* GObjet implementation
*---------------------------------------------------------------------------*/
-typedef struct _AnjutaDirRootNodeClass AnjutaDirRootNodeClass;
-
-struct _AnjutaDirRootNodeClass {
- AnjutaProjectNodeClass parent_class;
-};
-
-G_DEFINE_TYPE (AnjutaDirRootNode, anjuta_dir_root_node, ANJUTA_TYPE_PROJECT_NODE);
+G_DEFINE_TYPE (AnjutaDirRootNode, anjuta_dir_root_node, ANJUTA_TYPE_DIR_GROUP_NODE);
static void
anjuta_dir_root_node_init (AnjutaDirRootNode *node)
{
+ node->base.type = ANJUTA_PROJECT_ROOT;
}
static void
@@ -79,12 +54,6 @@ anjuta_dir_root_node_class_init (AnjutaDirRootNodeClass *klass)
/* Group node
*---------------------------------------------------------------------------*/
-struct _AnjutaDirGroupNode {
- AnjutaProjectNode base;
- GFileMonitor *monitor;
- GObject *emitter;
-};
-
static void
on_file_changed (GFileMonitor *monitor,
GFile *file,
@@ -103,34 +72,48 @@ on_file_changed (GFileMonitor *monitor,
}
}
+gboolean
+dir_group_node_set_file (AnjutaDirGroupNode *group, GFile *new_file, GObject *emitter)
+{
+ if (group->base.file != NULL)
+ {
+ g_object_unref (group->base.file);
+ group->base.file = NULL;
+ }
+ if (group->monitor != NULL)
+ {
+ g_file_monitor_cancel (group->monitor);
+ group->monitor = NULL;
+ }
+
+ if (new_file)
+ {
+ group->base.file = g_object_ref (new_file);
+
+ /* Connect monitor if file exist */
+ group->emitter = emitter;
+ if (g_file_query_exists (new_file, NULL))
+ {
+ group->monitor = g_file_monitor_directory (new_file, G_FILE_MONITOR_NONE, NULL, NULL);
+
+ g_signal_connect (G_OBJECT (group->monitor),
+ "changed",
+ G_CALLBACK (on_file_changed),
+ group);
+ }
+ }
+
+ return TRUE;
+}
+
+
AnjutaProjectNode*
dir_group_node_new (GFile *file, GObject *emitter)
{
AnjutaDirGroupNode *group = NULL;
group = g_object_new (ANJUTA_TYPE_DIR_GROUP_NODE, NULL);
- group->base.type = ANJUTA_PROJECT_GROUP;
- group->base.properties = NULL;
- group->base.properties_info = NULL;
- group->base.file = g_object_ref (file);
- group->base.name = NULL;
- group->base.state = ANJUTA_PROJECT_CAN_ADD_GROUP |
- ANJUTA_PROJECT_CAN_ADD_SOURCE |
- ANJUTA_PROJECT_CAN_REMOVE |
- ANJUTA_PROJECT_REMOVE_FILE;
-
- group->emitter = emitter;
-
- /* Connect monitor if file exist */
- if (g_file_query_exists (file, NULL))
- {
- group->monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
-
- g_signal_connect (G_OBJECT (group->monitor),
- "changed",
- G_CALLBACK (on_file_changed),
- group);
- }
+ dir_group_node_set_file (group, file, emitter);
return ANJUTA_PROJECT_NODE (group);
}
@@ -139,17 +122,19 @@ dir_group_node_new (GFile *file, GObject *emitter)
*---------------------------------------------------------------------------*/
-typedef struct _AnjutaDirGroupNodeClass AnjutaDirGroupNodeClass;
-
-struct _AnjutaDirGroupNodeClass {
- AnjutaProjectNodeClass parent_class;
-};
-
G_DEFINE_TYPE (AnjutaDirGroupNode, anjuta_dir_group_node, ANJUTA_TYPE_PROJECT_NODE);
static void
anjuta_dir_group_node_init (AnjutaDirGroupNode *node)
{
+ node->base.type = ANJUTA_PROJECT_GROUP;
+ node->base.properties = NULL;
+ node->base.properties_info = NULL;
+ node->base.name = NULL;
+ node->base.state = ANJUTA_PROJECT_CAN_ADD_GROUP |
+ ANJUTA_PROJECT_CAN_ADD_SOURCE |
+ ANJUTA_PROJECT_CAN_REMOVE |
+ ANJUTA_PROJECT_REMOVE_FILE;
node->monitor = NULL;
node->emitter = NULL;
}
@@ -172,6 +157,7 @@ anjuta_dir_group_node_class_init (AnjutaDirGroupNodeClass *klass)
object_class->finalize = anjuta_dir_group_node_finalize;
}
+
/* Object node
*---------------------------------------------------------------------------*/
@@ -186,13 +172,7 @@ dir_object_node_new (GFile *file)
AnjutaDirObjectNode *node = NULL;
node = g_object_new (ANJUTA_TYPE_DIR_OBJECT_NODE, NULL);
- node->base.type = ANJUTA_PROJECT_OBJECT;
- node->base.properties = NULL;
- node->base.properties_info = NULL;
- node->base.name = NULL;
node->base.file = g_file_dup (file);
- node->base.state = ANJUTA_PROJECT_CAN_REMOVE |
- ANJUTA_PROJECT_REMOVE_FILE;
return ANJUTA_PROJECT_NODE (node);
}
@@ -211,6 +191,12 @@ G_DEFINE_TYPE (AnjutaDirObjectNode, anjuta_dir_object_node, ANJUTA_TYPE_PROJECT_
static void
anjuta_dir_object_node_init (AnjutaDirObjectNode *node)
{
+ node->base.type = ANJUTA_PROJECT_OBJECT;
+ node->base.properties = NULL;
+ node->base.properties_info = NULL;
+ node->base.name = NULL;
+ node->base.state = ANJUTA_PROJECT_CAN_REMOVE |
+ ANJUTA_PROJECT_REMOVE_FILE;
}
static void
@@ -234,13 +220,7 @@ dir_source_node_new (GFile *file)
AnjutaDirSourceNode *source = NULL;
source = g_object_new (ANJUTA_TYPE_DIR_SOURCE_NODE, NULL);
- source->base.type = ANJUTA_PROJECT_SOURCE;
- source->base.properties = NULL;
- source->base.properties_info = NULL;
- source->base.name = NULL;
source->base.file = g_file_dup (file);
- source->base.state = ANJUTA_PROJECT_CAN_REMOVE |
- ANJUTA_PROJECT_REMOVE_FILE;
return ANJUTA_PROJECT_NODE (source);
}
@@ -259,6 +239,12 @@ G_DEFINE_TYPE (AnjutaDirSourceNode, anjuta_dir_source_node, ANJUTA_TYPE_PROJECT_
static void
anjuta_dir_source_node_init (AnjutaDirSourceNode *node)
{
+ node->base.type = ANJUTA_PROJECT_SOURCE;
+ node->base.properties = NULL;
+ node->base.properties_info = NULL;
+ node->base.name = NULL;
+ node->base.state = ANJUTA_PROJECT_CAN_REMOVE |
+ ANJUTA_PROJECT_REMOVE_FILE;
}
static void
diff --git a/plugins/dir-project/dir-node.h b/plugins/dir-project/dir-node.h
index 3765e1d..fc8beae 100644
--- a/plugins/dir-project/dir-node.h
+++ b/plugins/dir-project/dir-node.h
@@ -31,7 +31,8 @@ G_BEGIN_DECLS
#define ANJUTA_TYPE_DIR_ROOT_NODE (anjuta_dir_root_node_get_type ())
#define ANJUTA_DIR_ROOT_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ANJUTA_TYPE_DIR_ROOT_NODE, AnjutaDirRootNode))
-typedef struct _AnjutaDirRootNode AnjutaDirRootNode;
+typedef struct _AnjutaDirGroupNode AnjutaDirRootNode;
+typedef struct _AnjutaDirGroupNodeClass AnjutaDirRootNodeClass;
GType anjuta_dir_root_node_get_type (void) G_GNUC_CONST;
@@ -39,6 +40,7 @@ GType anjuta_dir_root_node_get_type (void) G_GNUC_CONST;
#define ANJUTA_DIR_GROUP_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ANJUTA_TYPE_DIR_GROUP_NODE, AnjutaDirGroupNode))
typedef struct _AnjutaDirGroupNode AnjutaDirGroupNode;
+typedef struct _AnjutaDirGroupNodeClass AnjutaDirGroupNodeClass;
GType anjuta_dir_group_node_get_type (void) G_GNUC_CONST;
@@ -56,10 +58,18 @@ typedef struct _AnjutaDirSourceNode AnjutaDirSourceNode;
GType anjuta_dir_source_node_get_type (void) G_GNUC_CONST;
+struct _AnjutaDirGroupNode {
+ AnjutaProjectNode base;
+ GFileMonitor *monitor;
+ GObject *emitter;
+};
-AnjutaProjectNode* dir_root_node_new (GFile *file);
+struct _AnjutaDirGroupNodeClass {
+ AnjutaProjectNodeClass parent_class;
+};
AnjutaProjectNode *dir_group_node_new (GFile *file, GObject *emitter);
+gboolean dir_group_node_set_file (AnjutaDirGroupNode *group, GFile *new_file, GObject *emitter);
AnjutaProjectNode *dir_object_node_new (GFile *file);
diff --git a/plugins/dir-project/dir-project.c b/plugins/dir-project/dir-project.c
index 608f160..5895e95 100644
--- a/plugins/dir-project/dir-project.c
+++ b/plugins/dir-project/dir-project.c
@@ -47,9 +47,7 @@
#define SOURCES_FILE PACKAGE_DATA_DIR "/sources.list"
struct _DirProject {
- GObject parent;
-
- AnjutaProjectNode *root;
+ AnjutaDirRootNode parent;
/* shortcut hash tables, mapping id -> GNode from the tree above */
GHashTable *groups;
@@ -61,6 +59,10 @@ struct _DirProject {
GList *sources;
};
+struct _DirProjectClass {
+ AnjutaDirRootNodeClass parent_class;
+};
+
/* A file or directory name part of a path */
typedef struct _DirMatchString DirMatchString;
@@ -192,9 +194,6 @@ project_node_new (DirProject *project, AnjutaProjectNode *parent, AnjutaProjectN
node = dir_source_node_new (file);
}
break;
- case ANJUTA_PROJECT_ROOT:
- node = dir_root_node_new (file);
- break;
default:
g_assert_not_reached ();
break;
@@ -582,15 +581,7 @@ dir_project_load_directory_callback (GObject *source_object,
g_object_unref (remove);
}
}
- if (anjuta_project_node_parent (data->parent) == data->proj->root)
- {
- /* Emit signal on root node instead of the first group */
- g_signal_emit_by_name (data->proj, "node-loaded", data->proj->root, NULL);
- }
- else
- {
- g_signal_emit_by_name (data->proj, "node-loaded", data->parent, NULL);
- }
+ g_signal_emit_by_name (data->proj, "node-loaded", data->parent, NULL);
}
g_object_unref (data->parent);
g_slice_free (DirData, data);
@@ -599,7 +590,7 @@ dir_project_load_directory_callback (GObject *source_object,
return;
}
- root = anjuta_project_node_get_file (data->proj->root);
+ root = anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (data->proj));
for (l = infos; l != NULL; l = g_list_next(l))
{
GFileInfo *info;
@@ -725,48 +716,40 @@ dir_project_load_root (DirProject *project, GError **error)
{
GFile *source_file;
GFile *root_file;
- AnjutaProjectNode *group;
- root_file = anjuta_project_node_get_file (project->root);
+ root_file = anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (project));
DEBUG_PRINT ("reload project %p root file %p", project, root_file);
- group = anjuta_project_node_first_child (project->root);
- if (group != NULL)
- {
- dir_project_load_directory (project, group, NULL);
- return project->root;
- }
-
- /* shortcut hash tables */
- project->groups = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-
if (g_file_query_file_type (root_file, G_FILE_QUERY_INFO_NONE, NULL) != G_FILE_TYPE_DIRECTORY)
{
g_set_error (error, IANJUTA_PROJECT_ERROR,
- IANJUTA_PROJECT_ERROR_DOESNT_EXIST,
- _("Project doesn't exist or invalid path"));
+ IANJUTA_PROJECT_ERROR_DOESNT_EXIST,
+ _("Project doesn't exist or invalid path"));
return NULL;
}
- group = project_node_new (project, NULL, ANJUTA_PROJECT_GROUP, root_file, NULL, NULL);
- anjuta_project_node_append (project->root, group);
- g_hash_table_insert (project->groups, g_file_get_uri (root_file), group);
+ /* shortcut hash tables */
+ if (project->groups == NULL)
+ {
+ project->groups = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ }
/* Load source pattern */
source_file = g_file_new_for_path (SOURCES_FILE);
project->sources = dir_push_pattern_list (NULL, g_object_ref (root_file), source_file, FALSE, NULL);
g_object_unref (source_file);
- dir_project_load_directory (project, group, NULL);
+ dir_group_node_set_file (ANJUTA_DIR_GROUP_NODE (project), root_file, G_OBJECT (project));
+ dir_project_load_directory (project, ANJUTA_PROJECT_NODE (project), NULL);
- return project->root;
+ return ANJUTA_PROJECT_NODE (project);
}
AnjutaProjectNode *
dir_project_load_node (DirProject *project, AnjutaProjectNode *node, GError **error)
{
- if (node == NULL) node = project->root;
+ if (node == NULL) node = ANJUTA_PROJECT_NODE (project);
switch (anjuta_project_node_get_node_type (node))
{
case ANJUTA_PROJECT_ROOT:
@@ -829,11 +812,7 @@ void
dir_project_unload (DirProject *project)
{
/* project data */
- /*project_node_destroy (project, project->root_node);
- project->root_node = NULL;*/
-
- if (project->root) project_node_destroy (project, project->root);
- project->root = NULL;
+ project_node_destroy (project, ANJUTA_PROJECT_NODE (project));
/* shortcut hash tables */
if (project->groups) g_hash_table_destroy (project->groups);
@@ -922,7 +901,7 @@ dir_project_new (GFile *directory, GError **error)
DirProject *project;
project = DIR_PROJECT (g_object_new (DIR_TYPE_PROJECT, NULL));
- project->root = dir_root_node_new (directory);
+ project->parent.base.file = g_object_ref (directory);
return project;
}
@@ -1008,7 +987,7 @@ iproject_remove_property (IAnjutaProject *obj, AnjutaProjectNode *node, const gc
static AnjutaProjectNode *
iproject_get_root (IAnjutaProject *obj, GError **error)
{
- return DIR_PROJECT (obj)->root;
+ return ANJUTA_PROJECT_NODE (obj);
}
static const GList*
@@ -1057,10 +1036,6 @@ dir_project_instance_init (DirProject *project)
g_return_if_fail (project != NULL);
g_return_if_fail (DIR_IS_PROJECT (project));
- /* project data */
- project->root = NULL;
- //project->root_node = NULL;
-
project->monitors = NULL;
project->groups = NULL;
@@ -1078,6 +1053,6 @@ dir_project_class_init (DirProjectClass *klass)
object_class->dispose = dir_project_dispose;
}
-ANJUTA_TYPE_BEGIN(DirProject, dir_project, G_TYPE_OBJECT);
+ANJUTA_TYPE_BEGIN(DirProject, dir_project, ANJUTA_TYPE_DIR_ROOT_NODE);
ANJUTA_TYPE_ADD_INTERFACE(iproject, IANJUTA_TYPE_PROJECT);
ANJUTA_TYPE_END;
diff --git a/plugins/dir-project/dir-project.h b/plugins/dir-project/dir-project.h
index d7e2100..0939b9d 100644
--- a/plugins/dir-project/dir-project.h
+++ b/plugins/dir-project/dir-project.h
@@ -42,10 +42,6 @@ G_BEGIN_DECLS
typedef struct _DirProject DirProject;
typedef struct _DirProjectClass DirProjectClass;
-struct _DirProjectClass {
- GObjectClass parent_class;
-};
-
GType dir_project_get_type (void);
DirProject *dir_project_new (GFile *directory, GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]