Commit 8208b426 authored by Sebastien Granjoux's avatar Sebastien Granjoux

am: Fix creating and deleting group with Anjuta interface

parent f35966dc
......@@ -236,12 +236,59 @@ amp_root_clear (AnjutaAmRootNode *node)
node->base.custom_properties = NULL;
}
static void
on_root_monitor_changed (GFileMonitor *monitor,
GFile *file,
GFile *other_file,
GFileMonitorEvent event_type,
gpointer data)
{
AnjutaAmRootNode *node = ANJUTA_AM_ROOT_NODE (data);
switch (event_type) {
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
case G_FILE_MONITOR_EVENT_CHANGED:
case G_FILE_MONITOR_EVENT_DELETED:
/* project can be NULL, if the node is dummy node because the
* original one is reloaded. */
if (node->project != NULL) g_signal_emit_by_name (G_OBJECT (node->project), "file-changed", data);
break;
default:
break;
}
}
AnjutaTokenFile*
amp_root_set_configure (AnjutaAmRootNode *root, GFile *configure)
amp_root_set_configure (AnjutaAmRootNode *root, GFile *configure, GObject* project)
{
if (root->configure != NULL) g_object_unref (root->configure);
if (root->configure_file != NULL) anjuta_token_file_free (root->configure_file);
root->configure_file = anjuta_token_file_new (configure);
if (configure != NULL)
{
root->configure_file = anjuta_token_file_new (configure);
root->configure = g_object_ref (configure);
root->monitor = g_file_monitor_file (configure,
G_FILE_MONITOR_NONE,
NULL,
NULL);
if (root->monitor != NULL)
{
root->project = project;
g_signal_connect (G_OBJECT (root->monitor),
"changed",
G_CALLBACK (on_root_monitor_changed),
root);
}
}
else
{
root->configure_file = NULL;
root->configure = NULL;
if (root->monitor) g_object_unref (root->monitor);
root->monitor = NULL;
}
return root->configure_file;
}
......@@ -257,6 +304,27 @@ amp_root_get_configure_token (AnjutaAmRootNode *root)
return root->configure_token;
}
void
amp_root_update_monitor (AnjutaAmRootNode *root)
{
if (root->monitor != NULL) g_object_unref (root->monitor);
if (root->configure != NULL)
{
root->monitor = g_file_monitor_file (root->configure,
G_FILE_MONITOR_NONE,
NULL,
NULL);
if (root->monitor != NULL)
{
g_signal_connect (G_OBJECT (root->monitor),
"changed",
G_CALLBACK (on_root_monitor_changed),
root);
}
}
}
/* GObjet implementation
*---------------------------------------------------------------------------*/
......@@ -275,6 +343,17 @@ anjuta_am_root_node_init (AnjutaAmRootNode *node)
node->configure_token = NULL;
}
static void
anjuta_am_root_node_dispose (GObject *object)
{
AnjutaAmRootNode *root = ANJUTA_AM_ROOT_NODE (object);
if (root->monitor) g_object_unref (root->monitor);
root->monitor = NULL;
G_OBJECT_CLASS (anjuta_am_root_node_parent_class)->dispose (object);
}
static void
anjuta_am_root_node_finalize (GObject *object)
{
......@@ -291,6 +370,7 @@ anjuta_am_root_node_class_init (AnjutaAmRootNodeClass *klass)
GObjectClass* object_class = G_OBJECT_CLASS (klass);
object_class->finalize = anjuta_am_root_node_finalize;
object_class->dispose = anjuta_am_root_node_dispose;
}
......@@ -509,7 +589,7 @@ on_group_monitor_changed (GFileMonitor *monitor,
case G_FILE_MONITOR_EVENT_DELETED:
/* project can be NULL, if the node is dummy node because the
* original one is reloaded. */
g_signal_emit_by_name (G_OBJECT (node->project), "file-changed", data);
if (node->project != NULL) g_signal_emit_by_name (G_OBJECT (node->project), "file-changed", data);
break;
default:
break;
......@@ -589,8 +669,10 @@ amp_group_get_makefile_name (AnjutaAmGroupNode *group)
void
amp_group_update_monitor (AnjutaAmGroupNode *group)
{
if (group->monitor != NULL) g_object_unref (group->monitor);
if (group->monitor != NULL) g_object_unref (group->monitor);
if (group->makefile != NULL)
{
group->monitor = g_file_monitor_file (group->makefile,
G_FILE_MONITOR_NONE,
NULL,
......@@ -602,7 +684,7 @@ amp_group_update_monitor (AnjutaAmGroupNode *group)
G_CALLBACK (on_group_monitor_changed),
group);
}
}
}
AnjutaAmGroupNode*
......
......@@ -47,9 +47,10 @@ AmpVariable* amp_variable_new (gchar *name, AnjutaTokenType assign, AnjutaToken
AnjutaAmRootNode* amp_root_new (GFile *file, GError **error);
void amp_root_free (AnjutaAmRootNode *node);
void amp_root_clear (AnjutaAmRootNode *node);
AnjutaTokenFile* amp_root_set_configure (AnjutaAmRootNode *node, GFile *configure);
AnjutaTokenFile* amp_root_set_configure (AnjutaAmRootNode *node, GFile *configure, GObject* project);
gboolean amp_root_update_configure (AnjutaAmRootNode *group, AnjutaToken *token);
AnjutaToken* amp_root_get_configure_token (AnjutaAmRootNode *root);
void amp_root_update_monitor (AnjutaAmRootNode *node);
AnjutaAmModuleNode* amp_module_new (const gchar *name, GError **error);
void amp_module_free (AnjutaAmModuleNode *node);
......
......@@ -89,8 +89,11 @@ GType anjuta_am_root_node_get_type (void) G_GNUC_CONST;
struct _AnjutaAmRootNode {
AnjutaProjectNode base;
GFile *configure; /* GFile corresponding to root configure */
AnjutaTokenFile *configure_file; /* Corresponding configure file */
AnjutaToken *configure_token;
GFileMonitor *monitor; /* File monitor */
GObject *project; /* Project used by file monitor */
};
......@@ -140,7 +143,7 @@ struct _AnjutaAmGroupNode {
AnjutaToken *make_token;
GHashTable *variables;
GFileMonitor *monitor; /* File monitor */
GObject *project; /* Project used by file monitor */
GObject *project; /* Project used by file monitor */
};
......
......@@ -845,7 +845,7 @@ amp_project_load_config (AmpProject *project, AnjutaToken *arg_list)
if (value == NULL) continue;
cfg = amp_config_file_new (value, anjuta_project_node_get_file (project->root), item);
g_hash_table_insert (project->configs, cfg->file, cfg);
g_hash_table_replace (project->configs, cfg->file, cfg);
g_free (value);
}
}
......@@ -1484,7 +1484,7 @@ amp_project_replace_node (AnjutaProjectNode *new_node, AnjutaProjectNode *old_no
if (old_node == NULL)
{
/* Delete old node */
g_object_unref (old_node);
g_object_unref (new_node);
}
else
{
......@@ -1502,17 +1502,21 @@ amp_project_replace_node (AnjutaProjectNode *new_node, AnjutaProjectNode *old_no
memcpy ((gchar *)new_node + sizeof (GInitiallyUnowned), data, type_info.instance_size - sizeof (GInitiallyUnowned));
g_free (data);
/* Update file monitor if it is a group */
if (anjuta_project_node_get_node_type (old_node) == ANJUTA_PROJECT_GROUP)
{
amp_group_update_monitor (ANJUTA_AM_GROUP_NODE (old_node));
}
/* Get old file */
if (old_node->file != NULL) g_object_unref (old_node->file);
old_node->file = new_node->file;
new_node->file = NULL;
/* Update file monitor if it is a group */
if (anjuta_project_node_get_node_type (old_node) == ANJUTA_PROJECT_GROUP)
{
amp_group_update_monitor (ANJUTA_AM_GROUP_NODE (old_node));
}
else if (anjuta_project_node_get_node_type (old_node) == ANJUTA_PROJECT_ROOT)
{
amp_root_update_monitor (ANJUTA_AM_ROOT_NODE (old_node));
}
/* Unlink old node and free it */
new_node->parent = NULL;
new_node->children = NULL;
......@@ -1546,8 +1550,8 @@ amp_project_duplicate_node (AnjutaProjectNode *old_node)
g_type_query (G_TYPE_FROM_INSTANCE (old_node), &type_info);
memcpy ((gchar *)new_node + sizeof (GInitiallyUnowned), (gchar *)old_node + sizeof (GInitiallyUnowned), type_info.instance_size - sizeof (GInitiallyUnowned));
new_node->custom_properties = NULL;
new_node->file = g_file_dup (new_node->file);
new_node->name = g_strdup (new_node->name);
if (new_node->file != NULL) new_node->file = g_file_dup (new_node->file);
if (new_node->name != NULL) new_node->name = g_strdup (new_node->name);
new_node->children = NULL;
/* Remove loaded node specific data */
......@@ -1573,7 +1577,7 @@ amp_project_get_type_info (AmpProject *project, AnjutaProjectNodeType type)
}
static AnjutaProjectNode *
amp_project_load_root (AmpProject *project, GError **error)
amp_project_load_root (AmpProject *project, AnjutaProjectNode *node, GError **error)
{
AmpAcScanner *scanner;
AnjutaToken *arg;
......@@ -1583,11 +1587,11 @@ amp_project_load_root (AmpProject *project, GError **error)
AnjutaTokenFile *configure_token_file;
GError *err = NULL;
root_file = anjuta_project_node_get_file (node);
DEBUG_PRINT ("reload project %p root file %p", project, root_file);
/* Unload current project */
amp_project_unload (project);
DEBUG_PRINT ("reload project %p root file %p", project, root_file);
root_file = anjuta_project_node_get_file (project->root);
/* shortcut hash tables */
project->groups = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
......@@ -1619,14 +1623,14 @@ amp_project_load_root (AmpProject *project, GError **error)
}
/* Parse configure */
configure_token_file = amp_root_set_configure (ANJUTA_AM_ROOT_NODE (project->root), configure_file);
configure_token_file = amp_root_set_configure (ANJUTA_AM_ROOT_NODE (node), configure_file, G_OBJECT (project));
g_hash_table_insert (project->files, configure_file, configure_token_file);
g_object_add_toggle_ref (G_OBJECT (configure_token_file), remove_config_file, project);
arg = anjuta_token_file_load (configure_token_file, NULL);
scanner = amp_ac_scanner_new (project);
AMP_ROOT_DATA (project->root)->configure_token = amp_ac_scanner_parse_token (scanner, arg, 0, &err);
AMP_ROOT_DATA (node)->configure_token = amp_ac_scanner_parse_token (scanner, arg, 0, &err);
amp_ac_scanner_free (scanner);
if (AMP_ROOT_DATA (project->root)->configure_token == NULL)
if (AMP_ROOT_DATA (node)->configure_token == NULL)
{
g_set_error (error, IANJUTA_PROJECT_ERROR,
IANJUTA_PROJECT_ERROR_PROJECT_MALFORMED,
......@@ -1638,7 +1642,7 @@ amp_project_load_root (AmpProject *project, GError **error)
/* Load all makefiles recursively */
group = amp_group_new (root_file, FALSE, NULL);
g_hash_table_insert (project->groups, g_file_get_uri (root_file), group);
anjuta_project_node_append (project->root, ANJUTA_PROJECT_NODE (group));
anjuta_project_node_append (node, ANJUTA_PROJECT_NODE (group));
if (project_load_makefile (project, group) == NULL)
{
......@@ -1649,7 +1653,7 @@ amp_project_load_root (AmpProject *project, GError **error)
return NULL;
}
return project->root;
return node;
}
static void
......@@ -1765,13 +1769,17 @@ AnjutaProjectNode *
amp_project_load_node (AmpProject *project, AnjutaProjectNode *node, GError **error)
{
AnjutaProjectNode *loaded = NULL;
AnjutaProjectNode *old_root;
//GTimer *timer;
//timer = g_timer_new ();
switch (anjuta_project_node_get_node_type (node))
{
case ANJUTA_PROJECT_ROOT:
loaded = amp_project_load_root (project, error);
old_root = project->root;
project->root = node;
loaded = amp_project_load_root (project, project->root, error);
project->root = old_root;
break;
case ANJUTA_PROJECT_PACKAGE:
loaded = amp_project_load_package (project, node, error);
......@@ -2334,7 +2342,7 @@ amp_add_work (PmJob *job)
static gboolean
amp_add_complete (PmJob *job)
{
g_signal_emit_by_name (AMP_PROJECT (job->user_data), "node-changed", job->node, job->error);
g_signal_emit_by_name (AMP_PROJECT (job->user_data), "node-changed", job->parent, job->error);
return TRUE;
}
......@@ -2381,7 +2389,9 @@ amp_remove_work (PmJob *job)
static gboolean
amp_remove_complete (PmJob *job)
{
g_signal_emit_by_name (AMP_PROJECT (job->user_data), "node-changed", job->node, job->error);
AnjutaProjectNode *parent = anjuta_project_node_parent (job->node);
g_signal_emit_by_name (AMP_PROJECT (job->user_data), "node-changed", parent != NULL ? parent : job->node, job->error);
return TRUE;
}
......
......@@ -131,13 +131,12 @@ amp_project_write_config_file (AmpProject *project, AnjutaToken *list, gboolean
gboolean
amp_group_create_token (AmpProject *project, AnjutaAmGroupNode *group, GError **error)
{
AnjutaProjectNode *last;
GFile *directory;
GFile *makefile;
AnjutaToken *list;
gchar *basename;
AnjutaTokenFile* tfile;
AnjutaAmGroupNode *sibling;
AnjutaProjectNode *sibling;
AnjutaAmGroupNode *parent;
gboolean after;
gchar *name;
......@@ -148,21 +147,20 @@ amp_group_create_token (AmpProject *project, AnjutaAmGroupNode *group, GError *
directory = g_file_get_child (anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (parent)), name);
/* Find a sibling if possible */
if (anjuta_project_node_prev_sibling (ANJUTA_PROJECT_NODE (group)) != NULL)
after = TRUE;
for (sibling = anjuta_project_node_prev_sibling (ANJUTA_PROJECT_NODE (group)); sibling != NULL; sibling = anjuta_project_node_prev_sibling (sibling))
{
sibling = ANJUTA_AM_GROUP_NODE (anjuta_project_node_prev_sibling (ANJUTA_PROJECT_NODE (group)));
after = TRUE;
if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_GROUP) break;
}
else if (anjuta_project_node_next_sibling (ANJUTA_PROJECT_NODE (group)) != NULL)
if (sibling == NULL)
{
sibling = ANJUTA_AM_GROUP_NODE (anjuta_project_node_next_sibling (ANJUTA_PROJECT_NODE (group)));
after = FALSE;
for (sibling = anjuta_project_node_next_sibling (ANJUTA_PROJECT_NODE (group)); sibling != NULL; sibling = anjuta_project_node_next_sibling (sibling))
{
if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_GROUP) break;
}
}
else
{
sibling = NULL;
after = TRUE;
}
if (sibling == NULL) after = TRUE;
/* Create directory */
g_file_make_directory (directory, NULL, NULL);
......@@ -179,33 +177,11 @@ amp_group_create_token (AmpProject *project, AnjutaAmGroupNode *group, GError *
makefile = g_file_get_child (directory, "Makefile.am");
}
g_file_replace_contents (makefile, "", 0, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL, NULL);
tfile = amp_group_set_makefile (group, makefile, G_OBJECT (project));
amp_project_add_file (project, makefile, tfile);
if (sibling == NULL)
{
/* Find a sibling before */
for (last = anjuta_project_node_prev_sibling (ANJUTA_PROJECT_NODE (group)); (last != NULL) && (anjuta_project_node_get_node_type (last) != ANJUTA_PROJECT_GROUP); last = anjuta_project_node_prev_sibling (last));
if (last != NULL)
{
sibling = ANJUTA_AM_GROUP_NODE (last);
after = TRUE;
}
else
{
/* Find a sibling after */
for (last = anjuta_project_node_next_sibling (ANJUTA_PROJECT_NODE (group)); (last != NULL) && (anjuta_project_node_get_node_type (last) != ANJUTA_PROJECT_GROUP); last = anjuta_project_node_next_sibling (last));
if (last != NULL)
{
sibling = ANJUTA_AM_GROUP_NODE (last);
after = FALSE;
}
}
}
/* Add in configure */
list = NULL;
if (sibling) list = amp_group_get_first_token (sibling, AM_GROUP_TOKEN_CONFIGURE);
if (sibling) list = amp_group_get_first_token (ANJUTA_AM_GROUP_NODE (sibling), AM_GROUP_TOKEN_CONFIGURE);
if (list == NULL) list= amp_group_get_first_token (parent, AM_GROUP_TOKEN_CONFIGURE);
if (list != NULL) list = anjuta_token_list (list);
if (list == NULL)
......@@ -222,7 +198,7 @@ amp_group_create_token (AmpProject *project, AnjutaAmGroupNode *group, GError *
if (sibling)
{
prev = amp_group_get_first_token (sibling, AM_GROUP_TOKEN_CONFIGURE);
prev = amp_group_get_first_token (ANJUTA_AM_GROUP_NODE (sibling), AM_GROUP_TOKEN_CONFIGURE);
/*if ((prev != NULL) && after)
{
prev = anjuta_token_next_word (prev);
......@@ -237,7 +213,7 @@ amp_group_create_token (AmpProject *project, AnjutaAmGroupNode *group, GError *
*ext = '\0';
}
token = amp_project_write_config_file (project, list, after, prev, relative_make);
amp_group_add_token (group, token, AM_GROUP_TOKEN_CONFIGURE);
amp_group_add_token (ANJUTA_AM_GROUP_NODE (group), token, AM_GROUP_TOKEN_CONFIGURE);
g_free (relative_make);
}
......@@ -248,17 +224,17 @@ amp_group_create_token (AmpProject *project, AnjutaAmGroupNode *group, GError *
AnjutaToken *makefile;
static gint eol_type[] = {ANJUTA_TOKEN_EOL, ANJUTA_TOKEN_SPACE, ANJUTA_TOKEN_COMMENT, 0};
makefile = amp_group_get_makefile_token (group);
makefile = amp_group_get_makefile_token (parent);
pos = anjuta_token_find_type (makefile, ANJUTA_TOKEN_SEARCH_NOT, eol_type);
if (pos == NULL)
{
pos = anjuta_token_prepend_child (makefile, anjuta_token_new_static (ANJUTA_TOKEN_SPACE, "\n"));
}
list = anjuta_token_insert_token_list (FALSE, pos,
ANJUTA_TOKEN_EOL, "\n",
NULL);
amp_group_update_makefile (parent, list);
list = anjuta_token_new_string (ANJUTA_TOKEN_EOL | ANJUTA_TOKEN_ADDED, "\n");
anjuta_token_insert_after (pos, list);
amp_group_update_makefile (parent, list);
list = anjuta_token_insert_token_list (FALSE, pos,
AM_TOKEN_SUBDIRS, "SUBDIRS",
ANJUTA_TOKEN_SPACE, " ",
......@@ -272,7 +248,7 @@ amp_group_create_token (AmpProject *project, AnjutaAmGroupNode *group, GError *
{
AnjutaToken *prev;
prev = amp_group_get_first_token (sibling, AM_GROUP_TOKEN_SUBDIRS);
prev = amp_group_get_first_token (ANJUTA_AM_GROUP_NODE (sibling), AM_GROUP_TOKEN_SUBDIRS);
list = anjuta_token_list (prev);
}
......@@ -287,7 +263,7 @@ amp_group_create_token (AmpProject *project, AnjutaAmGroupNode *group, GError *
if (sibling)
{
prev = amp_group_get_first_token (sibling, AM_GROUP_TOKEN_SUBDIRS);
prev = amp_group_get_first_token (ANJUTA_AM_GROUP_NODE (sibling), AM_GROUP_TOKEN_SUBDIRS);
}
token = anjuta_token_new_string (ANJUTA_TOKEN_NAME | ANJUTA_TOKEN_ADDED, name);
......@@ -305,11 +281,14 @@ amp_group_create_token (AmpProject *project, AnjutaAmGroupNode *group, GError *
anjuta_token_style_free (style);
amp_group_update_makefile (parent, token);
amp_group_add_token (group, token, AM_GROUP_TOKEN_SUBDIRS);
}
g_free (name);
tfile = amp_group_set_makefile (group, makefile, G_OBJECT (project));
amp_project_add_file (project, makefile, tfile);
return TRUE;
}
......
......@@ -14,9 +14,9 @@ AT_DATA([expect],
GROUP (0:0): group1
]])
AT_DATA([reference.am],
[[
SUBDIRS = \
[[SUBDIRS = \
group1
]])
AT_DATA([reference.ac],
[[AC_CONFIG_FILES(Makefile
......@@ -42,10 +42,10 @@ AT_DATA([expect],
GROUP (0:1): group2
]])
AT_DATA([reference.am],
[[
SUBDIRS = \
[[SUBDIRS = \
group1 \
group2
]])
AT_DATA([reference.ac],
[[AC_CONFIG_FILES(Makefile
......@@ -71,9 +71,9 @@ AT_DATA([expect],
GROUP (0:0): group2
]])
AT_DATA([reference.am],
[[
SUBDIRS = \
[[SUBDIRS = \
group2
]])
AT_DATA([reference.ac],
[[AC_CONFIG_FILES(Makefile
......@@ -97,8 +97,8 @@ AT_DATA([expect],
[[ GROUP (0): empty4
]])
AT_DATA([reference.am],
[[
SUBDIRS = \
[[SUBDIRS = \
]])
AT_DATA([reference.ac],
......@@ -123,9 +123,9 @@ AT_DATA([expect],
GROUP (0:0): group1
]])
AT_DATA([reference.am],
[[
SUBDIRS = \
[[SUBDIRS = \
group1
]])
AT_DATA([reference.ac],
[[AC_CONFIG_FILES(Makefile
......
......@@ -65,7 +65,7 @@ on_pm_project_load_incomplete (AnjutaProjectNode *node, AnjutaPmProject *project
static gboolean
pm_command_load_complete (AnjutaPmProject *project, AnjutaProjectNode *node, GError *error)
{
//g_message ("pm_command_load_complete");
// g_message ("pm_command_load_complete %p", node);
if (error != NULL)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment