Commit b2539378 authored by Sebastien Granjoux's avatar Sebastien Granjoux

pm: Fix adding and removing packages

parent ebe54f38
......@@ -212,7 +212,7 @@ amp_root_new (GFile *file, GError **error)
root->base.file = g_file_dup (file);
root->base.name = NULL;
root->base.state = ANJUTA_PROJECT_CAN_ADD_GROUP |
ANJUTA_PROJECT_CAN_ADD_MODULE,
ANJUTA_PROJECT_CAN_ADD_PACKAGE,
ANJUTA_PROJECT_CAN_SAVE;
......@@ -898,8 +898,7 @@ amp_target_new (const gchar *name, AnjutaProjectNodeType type, const gchar *inst
node->base.custom_properties = NULL;
node->base.name = g_strdup (name);
node->base.file = NULL;
node->base.state = ANJUTA_PROJECT_CAN_ADD_MODULE |
ANJUTA_PROJECT_CAN_ADD_SOURCE |
node->base.state = ANJUTA_PROJECT_CAN_ADD_SOURCE |
ANJUTA_PROJECT_CAN_REMOVE;
node->install = g_strdup (install);
node->flags = flags;
......
......@@ -2390,7 +2390,7 @@ static gboolean
amp_remove_complete (PmJob *job)
{
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;
......
......@@ -1504,10 +1504,11 @@ anjuta_pm_project_new_package (AnjutaPmProject *project,
gint response;
gboolean finished = FALSE;
GtkTreeSelection *package_selection;
GtkTreeIter root;
gboolean valid;
AnjutaProjectNode *root;
AnjutaProjectNode *node;
AnjutaProjectNode *module = NULL;
gint default_pos = -1;
GbfProjectModel *model;
gint pos;
g_return_val_if_fail (project != NULL, NULL);
......@@ -1520,50 +1521,44 @@ anjuta_pm_project_new_package (AnjutaPmProject *project,
packages_view = GTK_WIDGET (gtk_builder_get_object (gui, "packages_view"));
ok_button = GTK_WIDGET (gtk_builder_get_object (gui, "ok_package_button"));
/* Get default parent */
if (default_module != NULL)
{
GbfTreeData *data;
GbfProjectModel *model;
model = anjuta_pm_project_get_model(project);
gtk_tree_model_get (GTK_TREE_MODEL (model), default_module, GBF_PROJECT_MODEL_COLUMN_DATA, &data, -1);
if (data != NULL)
{
module = gbf_tree_data_get_node (data);
}
}
/* Fill combo box with modules */
store = gtk_list_store_new(1, G_TYPE_STRING);
gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (module_entry), 0);
model = anjuta_pm_project_get_model(project);
for (valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &root); valid != FALSE; valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &root))
{
GbfTreeData *data;
gtk_tree_model_get (GTK_TREE_MODEL (model), &root, GBF_PROJECT_MODEL_COLUMN_DATA, &data, -1);
if (data && (data->type == GBF_TREE_NODE_GROUP)) break;
}
if (valid)
{
GtkTreeIter iter;
gint pos = 0;
GbfTreeData *data;
GtkTreePath *default_path = default_module != NULL ? gtk_tree_model_get_path(GTK_TREE_MODEL (model), default_module) : NULL;
gtk_tree_model_get (GTK_TREE_MODEL (model), &root, GBF_PROJECT_MODEL_COLUMN_DATA, &data, -1);
for (valid = gtk_tree_model_iter_children (GTK_TREE_MODEL (model), &iter, &root); valid != FALSE; valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter))
{
GbfTreeData *data;
gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, GBF_PROJECT_MODEL_COLUMN_DATA, &data, -1);
root = ianjuta_project_get_root (project->project, NULL);
pos = 0;
for (node = anjuta_project_node_first_child (root); node != NULL; node = anjuta_project_node_next_sibling (node))
{
if (anjuta_project_node_get_node_type (node) == ANJUTA_PROJECT_MODULE)
{
GtkTreeIter list_iter;
gchar *name;
if (data && (data->type == GBF_TREE_NODE_MODULE))
{
GtkTreeIter list_iter;
GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL (model), &iter);
name = anjuta_project_node_get_name (node);
gtk_list_store_append (store, &list_iter);
gtk_list_store_set (store, &list_iter, 0, name, -1);
g_free (name);
gtk_list_store_append (store, &list_iter);
gtk_list_store_set (store, &list_iter, 0, data->name, -1);
if ((default_path != NULL) && (gtk_tree_path_compare (path, default_path) == 0))
{
default_pos = pos;
}
gtk_tree_path_free (path);
pos++;
}
}
if (default_path != NULL) gtk_tree_path_free (default_path);
if (node == module)
{
default_pos = pos;
}
pos ++;
}
}
gtk_combo_box_set_model (GTK_COMBO_BOX(module_entry), GTK_TREE_MODEL(store));
gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (module_entry), 0);
......@@ -1619,12 +1614,45 @@ anjuta_pm_project_new_package (AnjutaPmProject *project,
switch (response) {
case GTK_RESPONSE_OK:
{
gchar *module;
gchar *name;
AnjutaProjectNode *module;
GString *error_message = g_string_new (NULL);
name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (module_entry));
name = g_strstrip (name);
if (*name == '\0')
{
/* Missing module name */
g_string_append (error_message, _("Missing module name"));
}
else
{
/* Look for already existing module */
module = anjuta_pm_project_get_module (project, name);
if (module == NULL)
{
/* Create new module */
AnjutaProjectNode *root;
GError *error = NULL;
root = ianjuta_project_get_root (project->project, NULL);
module = gtk_combo_box_get_active_text (GTK_COMBO_BOX (module_entry));
if (module)
module = ianjuta_project_add_node_after (project->project, root, NULL, ANJUTA_PROJECT_MODULE, NULL, name, &error);
if (error != NULL)
{
gchar *str = g_strdup_printf ("%s: %s\n", name, error->message);
g_string_append (error_message, str);
g_error_free (error);
g_free (str);
}
}
}
g_free (name);
if (module != NULL)
{
GString *err_mesg = g_string_new (NULL);
GList *list;
GList *node;
GtkTreeModel *model;
......@@ -1637,51 +1665,42 @@ anjuta_pm_project_new_package (AnjutaPmProject *project,
{
gchar *name;
AnjutaProjectNode* new_package;
GError *err = NULL;
GError *error = NULL;
gtk_tree_model_get (model, &iter, COL_PKG_PACKAGE, &name, -1);
/*new_package = ianjuta_project_add_package (project,
module,
name,
&err);*/
new_package = NULL;
if (err)
new_package = ianjuta_project_add_node_after (project->project, module, NULL, ANJUTA_PROJECT_PACKAGE, NULL, name, &error);
if (error)
{
gchar *str = g_strdup_printf ("%s: %s\n",
name,
err->message);
g_string_append (err_mesg, str);
g_error_free (err);
error->message);
g_string_append (error_message, str);
g_error_free (error);
g_free (str);
}
else
{
packages = g_list_append (packages,
new_package);
packages = g_list_append (packages, new_package);
finished = TRUE;
}
g_free (name);
}
}
g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
g_list_free (list);
if (err_mesg->str && strlen (err_mesg->str) > 0)
{
error_dialog (parent, _("Cannot add packages"),
"%s", err_mesg->str);
}
else
{
finished = TRUE;
}
g_string_free (err_mesg, TRUE);
}
else
if (error_message->len != 0)
{
error_dialog (parent, _("Cannot add packages"),
"%s", _("No module has been selected"));
"%s",error_message->str);
}
else
{
finished = TRUE;
}
g_string_free (error_message, TRUE);
break;
}
default:
......
......@@ -651,6 +651,12 @@ confirm_removal (ProjectManagerPlugin *plugin, GList *selected)
case GBF_TREE_NODE_SOURCE:
mesg = g_string_new (_("Are you sure you want to remove the following source file from the project?\n\n"));
break;
case GBF_TREE_NODE_PACKAGE:
mesg = g_string_new (_("Are you sure you want to remove the following package from the project?\n\n"));
break;
case GBF_TREE_NODE_MODULE:
mesg = g_string_new (_("Are you sure you want to remove the following module from the project?\n\n"));
break;
case GBF_TREE_NODE_UNKNOWN:
mesg = g_string_new (_("Are you sure you want to remove the following elements from the project?\n\n"));
break;
......@@ -680,6 +686,12 @@ confirm_removal (ProjectManagerPlugin *plugin, GList *selected)
case GBF_TREE_NODE_SHORTCUT:
g_string_append_printf (mesg, _("Shortcut: %s\n"), data->name);
return TRUE;
case GBF_TREE_NODE_MODULE:
g_string_append_printf (mesg, _("Module: %s\n"), data->name);
break;
case GBF_TREE_NODE_PACKAGE:
g_string_append_printf (mesg, _("Package: %s\n"), data->name);
break;
default:
g_warn_if_reached ();
return FALSE;
......@@ -732,7 +744,9 @@ on_popup_remove (GtkAction *action, ProjectManagerPlugin *plugin)
case GBF_TREE_NODE_GROUP:
case GBF_TREE_NODE_TARGET:
case GBF_TREE_NODE_SOURCE:
node = anjuta_pm_project_get_node(plugin->project, data);
case GBF_TREE_NODE_MODULE:
case GBF_TREE_NODE_PACKAGE:
node = gbf_tree_data_get_node (data);
if (node != NULL)
{
if (!update) update_operation_begin (plugin);
......
......@@ -279,9 +279,6 @@ anjuta_pm_project_get_capabilities (AnjutaPmProject *project)
case ANJUTA_PROJECT_SOURCE:
caps |= ANJUTA_PROJECT_CAN_ADD_SOURCE;
break;
case ANJUTA_PROJECT_MODULE:
caps |= ANJUTA_PROJECT_CAN_ADD_MODULE;
break;
case ANJUTA_PROJECT_PACKAGE:
caps |= ANJUTA_PROJECT_CAN_ADD_PACKAGE;
break;
......@@ -485,6 +482,35 @@ anjuta_pm_project_get_node_from_file (AnjutaPmProject *project, AnjutaProjectNod
return NULL;
}
static gboolean
find_module (AnjutaProjectNode *node, gpointer data)
{
gboolean found = FALSE;
if (anjuta_project_node_get_node_type (node) == ANJUTA_PROJECT_MODULE)
{
gchar *name = anjuta_project_node_get_name (node);
found = g_strcmp0 (name, (const gchar *)data) == 0;
g_free (name);
}
return found;
}
AnjutaProjectNode *
anjuta_pm_project_get_module (AnjutaPmProject *project, const gchar *name)
{
AnjutaProjectNode *root;
AnjutaProjectNode *module;
root = ianjuta_project_get_root (project->project, NULL);
module = anjuta_project_node_children_traverse (root, find_module, (gpointer)name);
return module;
}
/* Display properties dialog. These dialogs are not modal, so a pointer on each
* dialog is kept with in node data to be able to destroy them if the node is
* removed. It is useful to put the dialog at the top if the same target is
......
......@@ -101,6 +101,7 @@ GbfProjectModel *anjuta_pm_project_get_model (AnjutaPmProject *project);
AnjutaProjectNode *anjuta_pm_project_get_node (AnjutaPmProject *project, GbfTreeData *data);
AnjutaProjectNode *anjuta_pm_project_get_node_from_file (AnjutaPmProject *project, AnjutaProjectNodeType type, GFile *file);
AnjutaProjectNode *anjuta_pm_project_get_module (AnjutaPmProject *project, const gchar *name);
gboolean anjuta_pm_project_show_properties_dialog (AnjutaPmProject *project, GbfTreeData *data);
......
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