[anjuta/newproject] move all dialogs in dialogs.c
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta/newproject] move all dialogs in dialogs.c
- Date: Sat, 8 May 2010 20:37:58 +0000 (UTC)
commit 78550a3e37cd23ae27d01ec708c1639b88f9aaae
Author: Sébastien Granjoux <seb sfo free fr>
Date: Sat May 8 21:47:40 2010 +0200
move all dialogs in dialogs.c
plugins/project-manager/dialogs.c | 856 ++++++++++++++++++++++++++++---
plugins/project-manager/dialogs.h | 4 +
plugins/project-manager/plugin.c | 17 +-
plugins/project-manager/project-util.c | 846 -------------------------------
plugins/project-manager/project-util.h | 31 --
5 files changed, 784 insertions(+), 970 deletions(-)
---
diff --git a/plugins/project-manager/dialogs.c b/plugins/project-manager/dialogs.c
index 5600829..3145f3b 100644
--- a/plugins/project-manager/dialogs.c
+++ b/plugins/project-manager/dialogs.c
@@ -30,10 +30,13 @@
#include "project-model.h"
#include "project-view.h"
+#include "pkg-config.h"
#include <libanjuta/anjuta-debug.h>
#include <libanjuta/anjuta-utils.h>
+#define ICON_SIZE 16
+
#define GLADE_FILE PACKAGE_DATA_DIR "/glade/create_dialogs.ui"
/* Types
@@ -105,7 +108,7 @@ error_dialog (GtkWindow *parent, const gchar *summary, const gchar *msg, ...)
*---------------------------------------------------------------------------*/
static gboolean
-nodes_filter_fn (GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
+parent_filter_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
{
GbfTreeData *data = NULL;
gboolean visible = FALSE;
@@ -158,11 +161,32 @@ nodes_filter_fn (GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
return visible;
}
+static gboolean
+module_filter_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
+{
+ GbfTreeData *data = NULL;
+ gboolean visible = FALSE;
+ AnjutaProjectNode *node;
+
+ gtk_tree_model_get (model, iter,
+ GBF_PROJECT_MODEL_COLUMN_DATA, &data, -1);
+ node = gbf_tree_data_get_node (data);
+ if (node != NULL)
+ {
+ AnjutaProjectNodeType type = anjuta_project_node_get_type (node);
+
+ visible = (type == ANJUTA_PROJECT_MODULE) || (type == ANJUTA_PROJECT_PACKAGE);
+ }
+
+ return visible;
+}
+
static void
setup_nodes_treeview (GbfProjectModel *model,
- GtkWidget *view,
- AnjutaProjectNodeType type,
- GtkTreeIter *selected)
+ GtkWidget *view,
+ GtkTreeModelFilterVisibleFunc func,
+ gpointer data,
+ GtkTreeIter *selected)
{
GtkTreeModel *filter;
GtkTreeIter iter_filter;
@@ -173,7 +197,7 @@ setup_nodes_treeview (GbfProjectModel *model,
filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (model), NULL);
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
- nodes_filter_fn, GINT_TO_POINTER (type), NULL);
+ func, data, NULL);
gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (filter));
g_object_unref (filter);
@@ -530,7 +554,7 @@ on_properties_dialog_response (GtkDialog *win,
*dialog = NULL;
}
-/* Public functions
+/* Properties dialog
*---------------------------------------------------------------------------*/
gboolean
@@ -582,89 +606,108 @@ pm_project_create_properties_dialog (IAnjutaProject *project, GtkWidget **dialog
return *dialog != NULL;
}
+/* Group dialog
+ *---------------------------------------------------------------------------*/
+
AnjutaProjectNode*
anjuta_pm_project_new_group (AnjutaPmProject *project, GtkWindow *parent, GtkTreeIter *selected, const gchar *default_name)
{
- GtkBuilder *gui;
- GtkWidget *dialog, *group_name_entry, *ok_button;
- GtkWidget *groups_view;
- gint response;
- gboolean finished = FALSE;
- AnjutaProjectNode *new_group = NULL;
+ GtkBuilder *gui;
+ GtkWidget *dialog, *group_name_entry, *ok_button;
+ GtkWidget *groups_view;
+ gint response;
+ gboolean finished = FALSE;
+ AnjutaProjectNode *new_group = NULL;
- g_return_val_if_fail (project != NULL, NULL);
-
- gui = load_interface ("new_group_dialog");
- g_return_val_if_fail (gui != NULL, NULL);
-
- /* get all needed widgets */
- dialog = GTK_WIDGET (gtk_builder_get_object (gui, "new_group_dialog"));
- groups_view = GTK_WIDGET (gtk_builder_get_object (gui, "groups_view"));
- group_name_entry = GTK_WIDGET (gtk_builder_get_object (gui, "group_name_entry"));
- ok_button = GTK_WIDGET (gtk_builder_get_object (gui, "ok_group_button"));
-
- /* set up dialog */
- if (default_name)
- gtk_entry_set_text (GTK_ENTRY (group_name_entry),
- default_name);
- g_signal_connect (group_name_entry, "changed",
- (GCallback) entry_changed_cb, ok_button);
- if (default_name)
- gtk_widget_set_sensitive (ok_button, TRUE);
- else
- gtk_widget_set_sensitive (ok_button, FALSE);
-
- setup_nodes_treeview (anjuta_pm_project_get_model (project), groups_view, ANJUTA_PROJECT_GROUP, selected);
- gtk_widget_show (groups_view);
-
- if (parent) {
- gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
- }
-
- /* execute dialog */
- while (!finished) {
- response = gtk_dialog_run (GTK_DIALOG (dialog));
+ g_return_val_if_fail (project != NULL, NULL);
- switch (response) {
- case GTK_RESPONSE_OK:
- {
- GError *err = NULL;
- AnjutaProjectNode *group;
- gchar *name;
-
- name = gtk_editable_get_chars (
- GTK_EDITABLE (group_name_entry), 0, -1);
-
- group = gbf_project_view_find_selected (GBF_PROJECT_VIEW (groups_view),
- ANJUTA_PROJECT_GROUP);
- if (group) {
- new_group = anjuta_pm_project_add_group (project, group, NULL, name, &err);
- if (err) {
- error_dialog (parent, _("Cannot add group"), "%s",
- err->message);
- g_error_free (err);
- } else {
- finished = TRUE;
- }
- } else {
- error_dialog (parent, _("Cannot add group"),
- "%s", _("No parent group selected"));
- }
- g_free (name);
- break;
- }
- default:
- finished = TRUE;
- break;
- }
- }
-
- /* destroy stuff */
- gtk_widget_destroy (dialog);
- g_object_unref (gui);
- return new_group;
+ gui = load_interface ("new_group_dialog");
+ g_return_val_if_fail (gui != NULL, NULL);
+
+ /* get all needed widgets */
+ dialog = GTK_WIDGET (gtk_builder_get_object (gui, "new_group_dialog"));
+ groups_view = GTK_WIDGET (gtk_builder_get_object (gui, "groups_view"));
+ group_name_entry = GTK_WIDGET (gtk_builder_get_object (gui, "group_name_entry"));
+ ok_button = GTK_WIDGET (gtk_builder_get_object (gui, "ok_group_button"));
+
+ /* set up dialog */
+ if (default_name)
+ gtk_entry_set_text (GTK_ENTRY (group_name_entry),
+ default_name);
+ g_signal_connect (group_name_entry, "changed",
+ (GCallback) entry_changed_cb, ok_button);
+ if (default_name)
+ gtk_widget_set_sensitive (ok_button, TRUE);
+ else
+ gtk_widget_set_sensitive (ok_button, FALSE);
+
+ setup_nodes_treeview (anjuta_pm_project_get_model (project),
+ groups_view,
+ parent_filter_func,
+ GINT_TO_POINTER (ANJUTA_PROJECT_GROUP),
+ selected);
+ gtk_widget_show (groups_view);
+
+ if (parent)
+ {
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
+ }
+
+ /* execute dialog */
+ while (!finished)
+ {
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ switch (response) {
+ case GTK_RESPONSE_OK:
+ {
+ GError *err = NULL;
+ AnjutaProjectNode *group;
+ gchar *name;
+
+ name = gtk_editable_get_chars (
+ GTK_EDITABLE (group_name_entry), 0, -1);
+
+ group = gbf_project_view_find_selected (GBF_PROJECT_VIEW (groups_view),
+ ANJUTA_PROJECT_GROUP);
+ if (group)
+ {
+ new_group = anjuta_pm_project_add_group (project, group, NULL, name, &err);
+ if (err)
+ {
+ error_dialog (parent, _("Cannot add group"), "%s",
+ err->message);
+ g_error_free (err);
+ }
+ else
+ {
+ finished = TRUE;
+ }
+ }
+ else
+ {
+ error_dialog (parent, _("Cannot add group"),
+ "%s", _("No parent group selected"));
+ }
+ g_free (name);
+ break;
+ }
+ default:
+ finished = TRUE;
+ break;
+ }
+ }
+
+ /* destroy stuff */
+ gtk_widget_destroy (dialog);
+ g_object_unref (gui);
+
+ return new_group;
}
+/* Source dialog
+ *---------------------------------------------------------------------------*/
+
AnjutaProjectNode*
anjuta_pm_project_new_source (AnjutaPmProject *project,
GtkWindow *parent,
@@ -770,7 +813,11 @@ anjuta_pm_project_new_multiple_source (AnjutaPmProject *project,
/*project_root = g_file_get_uri (anjuta_project_node_get_file (anjuta_pm_project_get_root (project)));
g_object_set_data_full (G_OBJECT (browse_button), "root", project_root, g_free);*/
- setup_nodes_treeview (anjuta_pm_project_get_model (project), targets_view, ANJUTA_PROJECT_SOURCE, default_parent);
+ setup_nodes_treeview (anjuta_pm_project_get_model (project),
+ targets_view,
+ parent_filter_func,
+ GINT_TO_POINTER (ANJUTA_PROJECT_SOURCE),
+ default_parent);
gtk_widget_show (targets_view);
if (top_window) {
@@ -878,3 +925,646 @@ anjuta_pm_project_new_multiple_source (AnjutaPmProject *project,
return new_sources;
}
+
+/* Target dialog
+ *---------------------------------------------------------------------------*/
+
+enum {
+ TARGET_TYPE_TYPE = 0,
+ TARGET_TYPE_NAME,
+ TARGET_TYPE_PIXBUF,
+ TARGET_TYPE_N_COLUMNS
+};
+
+/* create a tree model with the target types */
+static GtkListStore *
+build_types_store (AnjutaPmProject *project)
+{
+ GtkListStore *store;
+ GtkTreeIter iter;
+ GList *types;
+ GList *node;
+
+ types = anjuta_pm_project_get_node_info (project);
+ store = gtk_list_store_new (TARGET_TYPE_N_COLUMNS,
+ G_TYPE_POINTER,
+ G_TYPE_STRING,
+ GDK_TYPE_PIXBUF);
+
+ for (node = g_list_first (types); node != NULL; node = g_list_next (node)) {
+ GdkPixbuf *pixbuf;
+ const gchar *name;
+ AnjutaProjectNodeType type;
+
+ type = anjuta_project_node_info_type ((AnjutaProjectNodeInfo *)node->data);
+ if (type & ANJUTA_PROJECT_TARGET)
+ {
+ name = anjuta_project_node_info_name ((AnjutaProjectNodeInfo *)node->data);
+ pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default(),
+ GTK_STOCK_CONVERT,
+ ICON_SIZE,
+ GTK_ICON_LOOKUP_GENERIC_FALLBACK,
+ NULL);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ TARGET_TYPE_TYPE, type,
+ TARGET_TYPE_NAME, name,
+ TARGET_TYPE_PIXBUF, pixbuf,
+ -1);
+
+ if (pixbuf)
+ g_object_unref (pixbuf);
+ }
+ }
+
+ g_list_free (types);
+
+ return store;
+}
+
+AnjutaProjectNode*
+anjuta_pm_project_new_target (AnjutaPmProject *project,
+ GtkWindow *parent,
+ GtkTreeIter *default_group,
+ const gchar *default_target_name_to_add)
+{
+ GtkBuilder *gui;
+ GtkWidget *dialog, *target_name_entry, *ok_button;
+ GtkWidget *target_type_combo, *groups_view;
+ GtkListStore *types_store;
+ GtkCellRenderer *renderer;
+ gint response;
+ gboolean finished = FALSE;
+ AnjutaProjectNode *new_target = NULL;
+
+ g_return_val_if_fail (project != NULL, NULL);
+
+ gui = load_interface ("new_target_dialog");
+ g_return_val_if_fail (gui != NULL, NULL);
+
+ /* get all needed widgets */
+ dialog = GTK_WIDGET (gtk_builder_get_object (gui, "new_target_dialog"));
+ groups_view = GTK_WIDGET (gtk_builder_get_object (gui, "target_groups_view"));
+ target_name_entry = GTK_WIDGET (gtk_builder_get_object (gui, "target_name_entry"));
+ target_type_combo = GTK_WIDGET (gtk_builder_get_object (gui, "target_type_combo"));
+ ok_button = GTK_WIDGET (gtk_builder_get_object (gui, "ok_target_button"));
+
+ /* set up dialog */
+ if (default_target_name_to_add)
+ gtk_entry_set_text (GTK_ENTRY (target_name_entry),
+ default_target_name_to_add);
+ g_signal_connect (target_name_entry, "changed",
+ (GCallback) entry_changed_cb, ok_button);
+ if (default_target_name_to_add)
+ gtk_widget_set_sensitive (ok_button, TRUE);
+ else
+ gtk_widget_set_sensitive (ok_button, FALSE);
+
+ setup_nodes_treeview (anjuta_pm_project_get_model (project),
+ groups_view,
+ parent_filter_func,
+ GINT_TO_POINTER (ANJUTA_PROJECT_TARGET),
+ default_group);
+ gtk_widget_show (groups_view);
+
+ /* setup target types combo box */
+ types_store = build_types_store (project);
+ gtk_combo_box_set_model (GTK_COMBO_BOX (target_type_combo),
+ GTK_TREE_MODEL (types_store));
+
+ /* create cell renderers */
+ renderer = gtk_cell_renderer_pixbuf_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (target_type_combo),
+ renderer, FALSE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (target_type_combo),
+ renderer,
+ "pixbuf", TARGET_TYPE_PIXBUF,
+ NULL);
+
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (target_type_combo),
+ renderer, TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (target_type_combo),
+ renderer,
+ "text", TARGET_TYPE_NAME,
+ NULL);
+ gtk_widget_show (target_type_combo);
+
+ /* preselect */
+ gtk_combo_box_set_active (GTK_COMBO_BOX (target_type_combo), 0);
+
+ if (parent)
+ {
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
+ }
+
+ /* execute dialog */
+ while (!finished)
+ {
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ switch (response)
+ {
+ case GTK_RESPONSE_OK:
+ {
+ GError *err = NULL;
+ AnjutaProjectNode *group;
+ GtkTreeIter iter;
+ gchar *name;
+ AnjutaProjectNodeType type;
+
+ name = gtk_editable_get_chars (
+ GTK_EDITABLE (target_name_entry), 0, -1);
+ group = gbf_project_view_find_selected (GBF_PROJECT_VIEW (groups_view),
+ ANJUTA_PROJECT_GROUP);
+
+ /* retrieve target type */
+ if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (target_type_combo), &iter))
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (types_store), &iter,
+ TARGET_TYPE_TYPE, &type,
+ -1);
+ }
+
+ if (group && type)
+ {
+ new_target = anjuta_pm_project_add_target (project, group, NULL, name, type, &err);
+ if (err)
+ {
+ error_dialog (parent, _("Cannot add target"), "%s",
+ err->message);
+ g_error_free (err);
+ }
+ else
+ {
+ finished = TRUE;
+ }
+ }
+ else
+ {
+ error_dialog (parent, _("Cannot add target"), "%s",
+ _("No group selected"));
+ }
+
+ g_free (name);
+
+ break;
+ }
+ default:
+ finished = TRUE;
+ break;
+ }
+ }
+
+ /* destroy stuff */
+ g_object_unref (types_store);
+ gtk_widget_destroy (dialog);
+ g_object_unref (gui);
+
+ return new_target;
+}
+
+
+/* Module dialog
+ *---------------------------------------------------------------------------*/
+
+static void
+on_cursor_changed(GtkTreeView* view, gpointer data)
+{
+ GtkWidget* button = GTK_WIDGET(data);
+ GtkTreeSelection *selection = gtk_tree_view_get_selection(view);
+
+ if (gtk_tree_selection_count_selected_rows (selection) > 0)
+ gtk_widget_set_sensitive(button, TRUE);
+ else
+ gtk_widget_set_sensitive(button, FALSE);
+}
+
+GList*
+anjuta_pm_project_new_module (AnjutaPmProject *project,
+ GtkWindow *parent,
+ GtkTreeIter *default_target,
+ const gchar *default_module)
+{
+ GtkBuilder *gui;
+ GtkWidget *dialog;
+ GtkWidget *ok_button, *new_button;
+ GtkWidget *targets_view;
+ GtkWidget *modules_view;
+ gint response;
+ gboolean finished = FALSE;
+ GList* new_modules = NULL;
+ GtkTreeSelection *module_selection;
+
+ g_return_val_if_fail (project != NULL, NULL);
+
+ gui = load_interface ("add_module_dialog");
+ g_return_val_if_fail (gui != NULL, NULL);
+
+ /* get all needed widgets */
+ dialog = GTK_WIDGET (gtk_builder_get_object (gui, "add_module_dialog"));
+ targets_view = GTK_WIDGET (gtk_builder_get_object (gui, "module_targets_view"));
+ modules_view = GTK_WIDGET (gtk_builder_get_object (gui, "modules_view"));
+ new_button = GTK_WIDGET (gtk_builder_get_object (gui, "new_package_button"));
+ ok_button = GTK_WIDGET (gtk_builder_get_object (gui, "ok_module_button"));
+
+ setup_nodes_treeview (anjuta_pm_project_get_model (project),
+ targets_view,
+ parent_filter_func,
+ GINT_TO_POINTER (ANJUTA_PROJECT_MODULE),
+ default_target);
+ gtk_widget_show (targets_view);
+ setup_nodes_treeview (anjuta_pm_project_get_model (project),
+ modules_view,
+ module_filter_func,
+ NULL,
+ NULL);
+ gtk_widget_show (modules_view);
+ module_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (modules_view));
+ gtk_tree_selection_set_mode (module_selection, GTK_SELECTION_MULTIPLE);
+
+ if (gbf_project_view_find_selected (GBF_PROJECT_VIEW (modules_view), ANJUTA_PROJECT_MODULE))
+ {
+ gtk_widget_set_sensitive (ok_button, TRUE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive (ok_button, FALSE);
+ }
+ g_signal_connect (G_OBJECT(modules_view), "cursor-changed",
+ G_CALLBACK(on_cursor_changed), ok_button);
+
+
+ if (parent)
+ {
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
+ }
+
+ if (default_module)
+ gtk_widget_grab_focus (modules_view);
+ else
+ gtk_widget_grab_focus (targets_view);
+
+ /* execute dialog */
+ while (!finished)
+ {
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ switch (response) {
+ case 1:
+ {
+ anjuta_pm_project_new_package (project, parent, NULL, NULL);
+
+ break;
+ }
+ case GTK_RESPONSE_OK:
+ {
+ AnjutaProjectNode *target;
+
+ target = gbf_project_view_find_selected (GBF_PROJECT_VIEW (targets_view),
+ ANJUTA_PROJECT_TARGET);
+ if (target)
+ {
+ GString *err_mesg = g_string_new (NULL);
+ GList *list;
+ GList *node;
+
+ list = gbf_project_view_get_all_selected (GBF_PROJECT_VIEW (modules_view));
+ for (node = g_list_first (list); node != NULL; node = g_list_next (node))
+ {
+ GError *err = NULL;
+ AnjutaProjectNode* selected_module = (AnjutaProjectNode *)node->data;
+ AnjutaProjectNode* new_module;
+ gchar* uri = NULL;
+ GFile* module_file;
+
+ /*module_file = gbf_tree_data_get_file (selected_module);
+ new_module = ianjuta_project_add_module (project,
+ target,
+ module_file,
+ &err);
+ g_object_unref (module_file);*/
+ new_module = NULL;
+ if (err) {
+ gchar *str = g_strdup_printf ("%s: %s\n",
+ uri,
+ err->message);
+ g_string_append (err_mesg, str);
+ g_error_free (err);
+ g_free (str);
+ }
+ else
+ new_modules = g_list_append (new_modules, new_module);
+
+ g_free (uri);
+ }
+ g_list_free (list);
+
+ if (err_mesg->str && strlen (err_mesg->str) > 0)
+ {
+ error_dialog (parent, _("Cannot add modules"),
+ "%s", err_mesg->str);
+ }
+ else
+ {
+ finished = TRUE;
+ }
+ g_string_free (err_mesg, TRUE);
+ }
+ else
+ {
+ error_dialog (parent, _("Cannot add modules"),
+ "%s", _("No target has been selected"));
+ }
+
+ break;
+ }
+ default:
+ finished = TRUE;
+ break;
+ }
+ }
+
+ /* destroy stuff */
+ gtk_widget_destroy (dialog);
+ g_object_unref (gui);
+
+ return new_modules;
+}
+
+/* Package dialog
+ *---------------------------------------------------------------------------*/
+
+static void on_changed_disconnect (GtkEditable* entry, gpointer data);
+
+static void
+on_cursor_changed_set_entry(GtkTreeView* view, gpointer data)
+{
+ GtkWidget* entry = GTK_WIDGET(data);
+ GtkTreeSelection *selection = gtk_tree_view_get_selection(view);
+
+ if (gtk_tree_selection_count_selected_rows (selection) == 1)
+ {
+ GtkTreeModel *model;
+ GList *list;
+ GtkTreeIter iter;
+
+ list = gtk_tree_selection_get_selected_rows (selection, &model);
+ if (gtk_tree_model_get_iter (model, &iter, (GtkTreePath *)(list->data)))
+ {
+ gchar *name;
+ gchar *ptr;
+
+ gtk_tree_model_get (model, &iter, COL_PKG_PACKAGE, &name, -1);
+
+ /* Remove numeric suffix */
+ ptr = name + strlen(name) - 1;
+ while (g_ascii_isdigit (*ptr))
+ {
+ while (g_ascii_isdigit (*ptr)) ptr--;
+ if ((*ptr != '_') && (*ptr != '-') && (*ptr != '.')) break;
+ *ptr = '\0';
+ ptr--;
+ }
+
+ /* Convert to upper case and remove invalid characters */
+ for (ptr = name; *ptr != '\0'; ptr++)
+ {
+ if (g_ascii_isalnum (*ptr))
+ {
+ *ptr = g_ascii_toupper (*ptr);
+ }
+ else
+ {
+ *ptr = '_';
+ }
+ }
+
+ g_signal_handlers_block_by_func (G_OBJECT (entry), on_changed_disconnect, view);
+ gtk_entry_set_text (GTK_ENTRY (entry), name);
+ g_signal_handlers_unblock_by_func (G_OBJECT (entry), on_changed_disconnect, view);
+ g_free (name);
+ }
+
+ g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
+ g_list_free (list);
+ }
+}
+
+static void
+on_changed_disconnect (GtkEditable* entry, gpointer data)
+{
+ g_signal_handlers_block_by_func (G_OBJECT (data), on_cursor_changed_set_entry, entry);
+}
+
+GList*
+anjuta_pm_project_new_package (AnjutaPmProject *project,
+ GtkWindow *parent,
+ GtkTreeIter *default_module,
+ GList *packages_to_add)
+{
+ GtkBuilder *gui;
+ GtkWidget *dialog;
+ GtkWidget *ok_button;
+ GtkWidget *module_entry;
+ GtkWidget *packages_view;
+ GtkCellRenderer* renderer;
+ GtkListStore *store;
+ GList *packages = NULL;
+ GtkTreeViewColumn *col;
+ gint response;
+ gboolean finished = FALSE;
+ GtkTreeSelection *package_selection;
+ GtkTreeIter root;
+ gboolean valid;
+ gint default_pos = -1;
+ GbfProjectModel *model;
+
+ g_return_val_if_fail (project != NULL, NULL);
+
+ gui = load_interface ("add_package_dialog");
+ g_return_val_if_fail (gui != NULL, NULL);
+
+ /* get all needed widgets */
+ dialog = GTK_WIDGET (gtk_builder_get_object (gui, "add_package_dialog"));
+ module_entry = GTK_WIDGET (gtk_builder_get_object (gui, "module_entry"));
+ packages_view = GTK_WIDGET (gtk_builder_get_object (gui, "packages_view"));
+ ok_button = GTK_WIDGET (gtk_builder_get_object (gui, "ok_package_button"));
+
+ /* 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);
+
+ if (data && (data->type == GBF_TREE_NODE_MODULE))
+ {
+ GtkTreeIter list_iter;
+ GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL (model), &iter);
+
+ 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);
+ }
+ 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);
+ g_object_unref (store);
+ if (default_pos >= 0)
+ {
+ gtk_combo_box_set_active (GTK_COMBO_BOX (module_entry), default_pos);
+ }
+ else
+ {
+ /* Create automatically a module name from the package name when missing */
+ GtkWidget *entry = gtk_bin_get_child (GTK_BIN (module_entry));
+
+ g_signal_connect (G_OBJECT(packages_view), "cursor-changed",
+ G_CALLBACK(on_cursor_changed_set_entry), entry);
+ g_signal_connect (G_OBJECT(entry), "changed",
+ G_CALLBACK(on_changed_disconnect), packages_view);
+ }
+
+ /* Fill package list */
+ renderer = gtk_cell_renderer_text_new ();
+ col = gtk_tree_view_column_new_with_attributes (_("Package"),
+ renderer,
+ "text", COL_PKG_PACKAGE,
+ NULL);
+ gtk_tree_view_column_set_sort_column_id (col, COL_PKG_PACKAGE);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (packages_view), col);
+ renderer = gtk_cell_renderer_text_new ();
+ col = gtk_tree_view_column_new_with_attributes (_("Description"),
+ renderer,
+ "text",
+ COL_PKG_DESCRIPTION,
+ NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (packages_view), col);
+ store = packages_get_pkgconfig_list ();
+ gtk_tree_view_set_model (GTK_TREE_VIEW (packages_view),
+ GTK_TREE_MODEL (store));
+
+ on_cursor_changed (GTK_TREE_VIEW (packages_view), ok_button);
+ g_signal_connect (G_OBJECT(packages_view), "cursor-changed",
+ G_CALLBACK(on_cursor_changed), ok_button);
+ package_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (packages_view));
+ gtk_tree_selection_set_mode (package_selection, GTK_SELECTION_MULTIPLE);
+
+ if (parent) {
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
+ }
+
+ /* execute dialog */
+ while (!finished) {
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ switch (response) {
+ case GTK_RESPONSE_OK:
+ {
+ gchar *module;
+
+ module = gtk_combo_box_get_active_text (GTK_COMBO_BOX (module_entry));
+ if (module)
+ {
+ GString *err_mesg = g_string_new (NULL);
+ GList *list;
+ GList *node;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ list = gtk_tree_selection_get_selected_rows (package_selection, &model);
+ for (node = list; node != NULL; node = g_list_next (node))
+ {
+ if (gtk_tree_model_get_iter (model, &iter, (GtkTreePath *)(node->data)))
+ {
+ gchar *name;
+ AnjutaProjectNode* new_package;
+ GError *err = 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)
+ {
+ gchar *str = g_strdup_printf ("%s: %s\n",
+ name,
+ err->message);
+ g_string_append (err_mesg, str);
+ g_error_free (err);
+ g_free (str);
+ }
+ else
+ {
+ packages = g_list_append (packages,
+ new_package);
+ }
+ 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
+ {
+ error_dialog (parent, _("Cannot add packages"),
+ "%s", _("No module has been selected"));
+ }
+ break;
+ }
+ default:
+ finished = TRUE;
+ break;
+ }
+ }
+
+ /* destroy stuff */
+ gtk_widget_destroy (dialog);
+ g_object_unref (gui);
+
+ return packages;
+}
diff --git a/plugins/project-manager/dialogs.h b/plugins/project-manager/dialogs.h
index a38a72d..dec27a3 100644
--- a/plugins/project-manager/dialogs.h
+++ b/plugins/project-manager/dialogs.h
@@ -29,8 +29,12 @@
G_BEGIN_DECLS
AnjutaProjectNode* anjuta_pm_project_new_group (AnjutaPmProject *project, GtkWindow *parent, GtkTreeIter *default_parent, const gchar *name);
+AnjutaProjectNode* anjuta_pm_project_new_target (AnjutaPmProject *project, GtkWindow *parent, GtkTreeIter *default_group, const gchar *name);
AnjutaProjectNode* anjuta_pm_project_new_source (AnjutaPmProject *project, GtkWindow *parent, GtkTreeIter *default_parent, const gchar *name);
GList* anjuta_pm_project_new_multiple_source (AnjutaPmProject *project, GtkWindow *parent, GtkTreeIter *default_parent, GList *name);
+GList* anjuta_pm_project_new_module (AnjutaPmProject *project, GtkWindow *parent, GtkTreeIter *default_target, const gchar *default_module);
+GList* anjuta_pm_project_new_package (AnjutaPmProject *project, GtkWindow *parent, GtkTreeIter *default_module, GList *packages_to_add);
+
gboolean pm_project_create_properties_dialog (IAnjutaProject *project, GtkWidget **dialog, GtkWindow *parent, AnjutaProjectNode *node);
diff --git a/plugins/project-manager/plugin.c b/plugins/project-manager/plugin.c
index 446482b..12a136b 100644
--- a/plugins/project-manager/plugin.c
+++ b/plugins/project-manager/plugin.c
@@ -440,7 +440,7 @@ on_add_package (GtkAction *action, ProjectManagerPlugin *plugin)
update_operation_begin (plugin);
gbf_project_view_get_first_selected (GBF_PROJECT_VIEW (plugin->view), &selected_module);
- new_module = gbf_project_util_add_package (plugin->project,
+ new_module = anjuta_pm_project_new_package (plugin->project,
get_plugin_parent_window (plugin),
&selected_module, NULL);
update_operation_end (plugin, TRUE);
@@ -455,7 +455,7 @@ on_add_module (GtkAction *action, ProjectManagerPlugin *plugin)
update_operation_begin (plugin);
gbf_project_view_get_first_selected (GBF_PROJECT_VIEW (plugin->view), &selected_target);
- new_modules = gbf_project_util_add_module (plugin->project,
+ new_modules = anjuta_pm_project_new_module (plugin->project,
get_plugin_parent_window (plugin),
&selected_target, NULL);
g_list_free (new_modules);
@@ -535,7 +535,7 @@ on_popup_add_package (GtkAction *action, ProjectManagerPlugin *plugin)
update_operation_begin (plugin);
gbf_project_view_get_first_selected (GBF_PROJECT_VIEW (plugin->view), &selected_module);
- packages = gbf_project_util_add_package (plugin->project,
+ packages = anjuta_pm_project_new_package (plugin->project,
get_plugin_parent_window (plugin),
&selected_module, NULL);
update_operation_end (plugin, TRUE);
@@ -550,7 +550,7 @@ on_popup_add_module (GtkAction *action, ProjectManagerPlugin *plugin)
update_operation_begin (plugin);
gbf_project_view_get_first_selected (GBF_PROJECT_VIEW (plugin->view), &selected_target);
- new_modules = gbf_project_util_add_module (plugin->project,
+ new_modules = anjuta_pm_project_new_module (plugin->project,
get_plugin_parent_window (plugin),
&selected_target, NULL);
g_list_free (new_modules);
@@ -581,7 +581,7 @@ on_popup_add_target (GtkAction *action, ProjectManagerPlugin *plugin)
update_operation_begin (plugin);
gbf_project_view_get_first_selected (GBF_PROJECT_VIEW (plugin->view), &selected_group);
- new_target = gbf_project_util_new_target (plugin->project,
+ new_target = anjuta_pm_project_new_target (plugin->project,
get_plugin_parent_window (plugin),
&selected_group, NULL);
@@ -2078,7 +2078,6 @@ iproject_manager_add_source_quiet (IAnjutaProjectManager *project_manager,
{
ProjectManagerPlugin *plugin;
AnjutaProjectNode *source_id;
- GFile *source_file;
AnjutaProjectNode *target = NULL;
g_return_val_if_fail (ANJUTA_IS_PLUGIN (project_manager), FALSE);
@@ -2086,15 +2085,13 @@ iproject_manager_add_source_quiet (IAnjutaProjectManager *project_manager,
plugin = ANJUTA_PLUGIN_PROJECT_MANAGER (G_OBJECT (project_manager));
target = anjuta_pm_project_get_node_from_file (plugin->project, ANJUTA_PROJECT_TARGET, location_file);
- source_file = g_file_new_for_uri (source_uri_to_add);
update_operation_begin (plugin);
source_id = anjuta_pm_project_add_source (plugin->project,
target,
NULL,
- source_file,
+ source_uri_to_add,
err);
update_operation_end (plugin, TRUE);
- g_object_unref (source_file);
return get_element_file_from_node (plugin, source_id, IANJUTA_PROJECT_MANAGER_PROJECT_ROOT_URI);
}
@@ -2161,7 +2158,7 @@ iproject_manager_add_target (IAnjutaProjectManager *project_manager,
}
update_operation_begin (plugin);
- target_id = gbf_project_util_new_target (plugin->project,
+ target_id = anjuta_pm_project_new_target (plugin->project,
get_plugin_parent_window (plugin),
iter,
target_name_to_add);
diff --git a/plugins/project-manager/project-util.c b/plugins/project-manager/project-util.c
index e096a08..fccc86b 100644
--- a/plugins/project-manager/project-util.c
+++ b/plugins/project-manager/project-util.c
@@ -30,432 +30,7 @@
#include <glib/gi18n.h>
#include <gio/gio.h>
-#include "tree-data.h"
-#include "project-view.h"
-#include "project-model.h"
#include "project-util.h"
-#include "pkg-config.h"
-
-#define ICON_SIZE 16
-
-#define GLADE_FILE PACKAGE_DATA_DIR "/glade/pm_dialogs.ui"
-
-enum {
- COLUMN_FILE,
- COLUMN_URI,
- N_COLUMNS
-};
-
-static GtkBuilder *
-load_interface (const gchar *top_widget)
-{
- GtkBuilder *xml = gtk_builder_new ();
- GError* error = NULL;
-
- if (!gtk_builder_add_from_file (xml, GLADE_FILE, &error))
- {
- g_warning ("Couldn't load builder file: %s", error->message);
- g_error_free (error);
- return NULL;
- }
-
- return xml;
-}
-
-static gboolean
-groups_filter_fn (GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
-{
- GbfTreeData *data = NULL;
- gboolean retval = FALSE;
-
- gtk_tree_model_get (model, iter,
- GBF_PROJECT_MODEL_COLUMN_DATA, &data, -1);
- retval = (data && data->type == GBF_TREE_NODE_GROUP);
-
- return retval;
-}
-
-static void
-setup_groups_treeview (AnjutaPmProject *project,
- GtkWidget *view,
- GtkTreeIter *select_group)
-{
- GtkTreeModel *filter;
- GtkTreePath *path;
- GbfProjectModel *model;
-
- g_return_if_fail (project != NULL);
- g_return_if_fail (view != NULL && GBF_IS_PROJECT_VIEW (view));
-
- model = anjuta_pm_project_get_model (project);
- filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (model), NULL);
- gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
- groups_filter_fn, NULL, NULL);
- gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (filter));
- g_object_unref (filter);
-
- /* select default group */
- if (select_group) {
- GtkTreeIter iter_filter;
-
- gtk_tree_model_filter_convert_child_iter_to_iter (
- GTK_TREE_MODEL_FILTER (filter), &iter_filter, select_group);
- path = gtk_tree_model_get_path (filter, &iter_filter);
- gtk_tree_view_expand_to_path (GTK_TREE_VIEW (view), path);
- } else {
- GtkTreePath *root_path;
-
- gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
- root_path = gbf_project_model_get_project_root (model);
- if (root_path) {
- path = gtk_tree_model_filter_convert_child_path_to_path (
- GTK_TREE_MODEL_FILTER (filter), root_path);
- gtk_tree_path_free (root_path);
- } else {
- path = gtk_tree_path_new_first ();
- }
- }
-
- gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path, NULL, FALSE);
- gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (view), path, NULL,
- TRUE, 0.5, 0.0);
- gtk_tree_path_free (path);
-}
-
-
-static void
-error_dialog (GtkWindow *parent, const gchar *summary, const gchar *msg, ...)
-{
- va_list ap;
- gchar *tmp;
- GtkWidget *dialog;
-
- va_start (ap, msg);
- tmp = g_strdup_vprintf (msg, ap);
- va_end (ap);
-
- dialog = gtk_message_dialog_new_with_markup (parent,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- "<b>%s</b>\n\n%s", summary, tmp);
- g_free (tmp);
-
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
-}
-
-static void
-entry_changed_cb (GtkEditable *editable, gpointer user_data)
-{
- GtkWidget *button = user_data;
- gchar *text;
-
- if (!button)
- return;
-
- text = gtk_editable_get_chars (editable, 0, -1);
- if (strlen (text) > 0) {
- gtk_widget_set_sensitive (button, TRUE);
- gtk_widget_grab_default (button);
- } else {
- gtk_widget_set_sensitive (button, FALSE);
- }
- g_free (text);
-}
-
-enum {
- TARGET_TYPE_TYPE = 0,
- TARGET_TYPE_NAME,
- TARGET_TYPE_PIXBUF,
- TARGET_TYPE_N_COLUMNS
-};
-
-/* create a tree model with the target types */
-static GtkListStore *
-build_types_store (AnjutaPmProject *project)
-{
- GtkListStore *store;
- GtkTreeIter iter;
- GList *types;
- GList *node;
-
- types = anjuta_pm_project_get_node_info (project);
- store = gtk_list_store_new (TARGET_TYPE_N_COLUMNS,
- G_TYPE_POINTER,
- G_TYPE_STRING,
- GDK_TYPE_PIXBUF);
-
- for (node = g_list_first (types); node != NULL; node = g_list_next (node)) {
- GdkPixbuf *pixbuf;
- const gchar *name;
- AnjutaProjectNodeType type;
-
- type = anjuta_project_node_info_type ((AnjutaProjectNodeInfo *)node->data);
- if (type & ANJUTA_PROJECT_TARGET)
- {
- name = anjuta_project_node_info_name ((AnjutaProjectNodeInfo *)node->data);
- pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default(),
- GTK_STOCK_CONVERT,
- ICON_SIZE,
- GTK_ICON_LOOKUP_GENERIC_FALLBACK,
- NULL);
-
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- TARGET_TYPE_TYPE, type,
- TARGET_TYPE_NAME, name,
- TARGET_TYPE_PIXBUF, pixbuf,
- -1);
-
- if (pixbuf)
- g_object_unref (pixbuf);
- }
- }
-
- g_list_free (types);
-
- return store;
-}
-
-AnjutaProjectNode*
-gbf_project_util_new_target (AnjutaPmProject *project,
- GtkWindow *parent,
- GtkTreeIter *default_group,
- const gchar *default_target_name_to_add)
-{
- GtkBuilder *gui;
- GtkWidget *dialog, *target_name_entry, *ok_button;
- GtkWidget *target_type_combo, *groups_view;
- GtkListStore *types_store;
- GtkCellRenderer *renderer;
- gint response;
- gboolean finished = FALSE;
- AnjutaProjectNode *new_target = NULL;
-
- g_return_val_if_fail (project != NULL, NULL);
-
- gui = load_interface ("new_target_dialog");
- g_return_val_if_fail (gui != NULL, NULL);
-
- /* get all needed widgets */
- dialog = GTK_WIDGET (gtk_builder_get_object (gui, "new_target_dialog"));
- groups_view = GTK_WIDGET (gtk_builder_get_object (gui, "target_groups_view"));
- target_name_entry = GTK_WIDGET (gtk_builder_get_object (gui, "target_name_entry"));
- target_type_combo = GTK_WIDGET (gtk_builder_get_object (gui, "target_type_combo"));
- ok_button = GTK_WIDGET (gtk_builder_get_object (gui, "ok_target_button"));
-
- /* set up dialog */
- if (default_target_name_to_add)
- gtk_entry_set_text (GTK_ENTRY (target_name_entry),
- default_target_name_to_add);
- g_signal_connect (target_name_entry, "changed",
- (GCallback) entry_changed_cb, ok_button);
- if (default_target_name_to_add)
- gtk_widget_set_sensitive (ok_button, TRUE);
- else
- gtk_widget_set_sensitive (ok_button, FALSE);
-
- setup_groups_treeview (project, groups_view, default_group);
- gtk_widget_show (groups_view);
-
- /* setup target types combo box */
- types_store = build_types_store (project);
- gtk_combo_box_set_model (GTK_COMBO_BOX (target_type_combo),
- GTK_TREE_MODEL (types_store));
-
- /* create cell renderers */
- renderer = gtk_cell_renderer_pixbuf_new ();
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (target_type_combo),
- renderer, FALSE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (target_type_combo),
- renderer,
- "pixbuf", TARGET_TYPE_PIXBUF,
- NULL);
-
- renderer = gtk_cell_renderer_text_new ();
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (target_type_combo),
- renderer, TRUE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (target_type_combo),
- renderer,
- "text", TARGET_TYPE_NAME,
- NULL);
- gtk_widget_show (target_type_combo);
-
- /* preselect */
- gtk_combo_box_set_active (GTK_COMBO_BOX (target_type_combo), 0);
-
- if (parent) {
- gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
- }
-
- /* execute dialog */
- while (!finished) {
- response = gtk_dialog_run (GTK_DIALOG (dialog));
-
- switch (response) {
- case GTK_RESPONSE_OK:
- {
- GError *err = NULL;
- AnjutaProjectNode *group;
- GtkTreeIter iter;
- gchar *name;
- AnjutaProjectNodeType type;
-
- name = gtk_editable_get_chars (
- GTK_EDITABLE (target_name_entry), 0, -1);
- group = gbf_project_view_find_selected (GBF_PROJECT_VIEW (groups_view),
- ANJUTA_PROJECT_GROUP);
-
- /* retrieve target type */
- if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (target_type_combo), &iter)) {
- gtk_tree_model_get (GTK_TREE_MODEL (types_store), &iter,
- TARGET_TYPE_TYPE, &type,
- -1);
- }
-
- if (group && type) {
- new_target = anjuta_pm_project_add_target (project, group, NULL, name, type, &err);
- if (err) {
- error_dialog (parent, _("Cannot add target"), "%s",
- err->message);
- g_error_free (err);
- } else {
- finished = TRUE;
- }
- } else {
- error_dialog (parent, _("Cannot add target"), "%s",
- _("No group selected"));
- }
-
- g_free (name);
-
- break;
- }
- default:
- finished = TRUE;
- break;
- }
- }
-
- /* destroy stuff */
- g_object_unref (types_store);
- gtk_widget_destroy (dialog);
- g_object_unref (gui);
- return new_target;
-}
-
-static gboolean
-targets_filter_fn (GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
-{
- GbfTreeData *data = NULL;
- gboolean retval = FALSE;
-
- gtk_tree_model_get (model, iter,
- GBF_PROJECT_MODEL_COLUMN_DATA, &data, -1);
- retval = (data && !data->is_shortcut &&
- (data->type == GBF_TREE_NODE_GROUP ||
- data->type == GBF_TREE_NODE_TARGET));
-
- return retval;
-}
-
-static void
-setup_targets_treeview (AnjutaPmProject *project,
- GtkWidget *view,
- GtkTreeIter *select_target)
-{
- GtkTreeModel *filter;
- GtkTreeIter iter_filter;
- GtkTreePath *path = NULL;
- GbfProjectModel *model;
-
- g_return_if_fail (project != NULL);
- g_return_if_fail (view != NULL && GBF_IS_PROJECT_VIEW (view));
-
- model = anjuta_pm_project_get_model (project);
- filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (model), NULL);
- gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
- targets_filter_fn, NULL, NULL);
- gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (filter));
- g_object_unref (filter);
-
- /* select default target */
- if (select_target) {
- if (gtk_tree_model_filter_convert_child_iter_to_iter (
- GTK_TREE_MODEL_FILTER (filter), &iter_filter, select_target))
- {
- path = gtk_tree_model_get_path (filter, &iter_filter);
- }
- }
- if (path)
- {
- gtk_tree_view_expand_to_path (GTK_TREE_VIEW (view), path);
- gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path, NULL, FALSE);
- gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (view), path, NULL,
- TRUE, 0.5, 0.0);
- gtk_tree_path_free (path);
- } else {
- gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
- }
-}
-
-static gboolean
-modules_filter_fn (GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
-{
- GbfTreeData *data = NULL;
- gboolean retval = FALSE;
- GtkTreeIter root;
-
- gtk_tree_model_get (model, iter,
- GBF_PROJECT_MODEL_COLUMN_DATA, &data, -1);
- retval = (data && !data->is_shortcut &&
- (!gtk_tree_model_iter_parent (model, &root, iter) ||
- data->type == GBF_TREE_NODE_MODULE ||
- data->type == GBF_TREE_NODE_PACKAGE));
-
- return retval;
-}
-
-static void
-setup_modules_treeview (AnjutaPmProject *project,
- GtkWidget *view,
- GtkTreeIter *select_module)
-{
- GtkTreeModel *filter;
- GtkTreeIter iter_filter;
- GtkTreePath *path = NULL;
- GbfProjectModel *model;
-
- g_return_if_fail (view != NULL && GBF_IS_PROJECT_VIEW (view));
-
- model = anjuta_pm_project_get_model (project);
- filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (model), NULL);
- gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
- modules_filter_fn, NULL, NULL);
- gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (filter));
- g_object_unref (filter);
-
- /* select default module */
- if (select_module) {
- if (gtk_tree_model_filter_convert_child_iter_to_iter (
- GTK_TREE_MODEL_FILTER (filter), &iter_filter, select_module))
- {
- path = gtk_tree_model_get_path (filter, &iter_filter);
- }
- }
- if (path)
- {
- gtk_tree_view_expand_to_path (GTK_TREE_VIEW (view), path);
- gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path, NULL, FALSE);
- gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (view), path, NULL,
- TRUE, 0.5, 0.0);
- } else {
- path = gtk_tree_path_new_first ();
- gtk_tree_view_expand_to_path (GTK_TREE_VIEW (view), path);
- }
- gtk_tree_path_free (path);
-}
GList *
gbf_project_util_all_child (AnjutaProjectNode *parent, AnjutaProjectNodeType type)
@@ -530,424 +105,3 @@ gbf_project_util_replace_by_file (GList* list)
return list;
}
-static void
-on_cursor_changed(GtkTreeView* view, gpointer data)
-{
- GtkWidget* button = GTK_WIDGET(data);
- GtkTreeSelection *selection = gtk_tree_view_get_selection(view);
-
- if (gtk_tree_selection_count_selected_rows (selection) > 0)
- gtk_widget_set_sensitive(button, TRUE);
- else
- gtk_widget_set_sensitive(button, FALSE);
-}
-
-GList*
-gbf_project_util_add_module (AnjutaPmProject *project,
- GtkWindow *parent,
- GtkTreeIter *default_target,
- const gchar *default_module)
-{
- GtkBuilder *gui;
- GtkWidget *dialog;
- GtkWidget *ok_button, *new_button;
- GtkWidget *targets_view;
- GtkWidget *modules_view;
- gint response;
- gboolean finished = FALSE;
- GList* new_modules = NULL;
- GtkTreeSelection *module_selection;
-
- g_return_val_if_fail (project != NULL, NULL);
-
- gui = load_interface ("add_module_dialog");
- g_return_val_if_fail (gui != NULL, NULL);
-
- /* get all needed widgets */
- dialog = GTK_WIDGET (gtk_builder_get_object (gui, "add_module_dialog"));
- targets_view = GTK_WIDGET (gtk_builder_get_object (gui, "module_targets_view"));
- modules_view = GTK_WIDGET (gtk_builder_get_object (gui, "modules_view"));
- new_button = GTK_WIDGET (gtk_builder_get_object (gui, "new_package_button"));
- ok_button = GTK_WIDGET (gtk_builder_get_object (gui, "ok_module_button"));
-
- setup_targets_treeview (project, targets_view, default_target);
- gtk_widget_show (targets_view);
- setup_modules_treeview (project, modules_view, NULL);
- gtk_widget_show (modules_view);
- module_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (modules_view));
- gtk_tree_selection_set_mode (module_selection, GTK_SELECTION_MULTIPLE);
-
- if (gbf_project_view_find_selected (GBF_PROJECT_VIEW (modules_view), ANJUTA_PROJECT_MODULE))
- {
- gtk_widget_set_sensitive (ok_button, TRUE);
- }
- else
- {
- gtk_widget_set_sensitive (ok_button, FALSE);
- }
- g_signal_connect (G_OBJECT(modules_view), "cursor-changed",
- G_CALLBACK(on_cursor_changed), ok_button);
-
-
- if (parent) {
- gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
- }
-
- if (default_module)
- gtk_widget_grab_focus (modules_view);
- else
- gtk_widget_grab_focus (targets_view);
-
- /* execute dialog */
- while (!finished) {
- response = gtk_dialog_run (GTK_DIALOG (dialog));
-
- switch (response) {
- case 1:
- {
- gbf_project_util_add_package (project, parent, NULL, NULL);
-
- break;
- }
- case GTK_RESPONSE_OK:
- {
- AnjutaProjectNode *target;
-
- target = gbf_project_view_find_selected (GBF_PROJECT_VIEW (targets_view),
- ANJUTA_PROJECT_TARGET);
- if (target) {
- GString *err_mesg = g_string_new (NULL);
- GList *list;
- GList *node;
-
- list = gbf_project_view_get_all_selected (GBF_PROJECT_VIEW (modules_view));
- for (node = g_list_first (list); node != NULL; node = g_list_next (node))
- {
- GError *err = NULL;
- AnjutaProjectNode* selected_module = (AnjutaProjectNode *)node->data;
- AnjutaProjectNode* new_module;
- gchar* uri = NULL;
- GFile* module_file;
-
- /*module_file = gbf_tree_data_get_file (selected_module);
- new_module = ianjuta_project_add_module (project,
- target,
- module_file,
- &err);
- g_object_unref (module_file);*/
- new_module = NULL;
- if (err) {
- gchar *str = g_strdup_printf ("%s: %s\n",
- uri,
- err->message);
- g_string_append (err_mesg, str);
- g_error_free (err);
- g_free (str);
- }
- else
- new_modules = g_list_append (new_modules,
- new_module);
-
- g_free (uri);
- }
- g_list_free (list);
-
- if (err_mesg->str && strlen (err_mesg->str) > 0) {
- error_dialog (parent, _("Cannot add modules"),
- "%s", err_mesg->str);
- } else {
- finished = TRUE;
- }
- g_string_free (err_mesg, TRUE);
- } else {
- error_dialog (parent, _("Cannot add modules"),
- "%s", _("No target has been selected"));
- }
-
- break;
- }
- default:
- finished = TRUE;
- break;
- }
- }
-
- /* destroy stuff */
- gtk_widget_destroy (dialog);
- g_object_unref (gui);
-
- return new_modules;
-}
-
-static void on_changed_disconnect (GtkEditable* entry, gpointer data);
-
-static void
-on_cursor_changed_set_entry(GtkTreeView* view, gpointer data)
-{
- GtkWidget* entry = GTK_WIDGET(data);
- GtkTreeSelection *selection = gtk_tree_view_get_selection(view);
-
- if (gtk_tree_selection_count_selected_rows (selection) == 1)
- {
- GtkTreeModel *model;
- GList *list;
- GtkTreeIter iter;
-
- list = gtk_tree_selection_get_selected_rows (selection, &model);
- if (gtk_tree_model_get_iter (model, &iter, (GtkTreePath *)(list->data)))
- {
- gchar *name;
- gchar *ptr;
-
- gtk_tree_model_get (model, &iter, COL_PKG_PACKAGE, &name, -1);
-
- /* Remove numeric suffix */
- ptr = name + strlen(name) - 1;
- while (g_ascii_isdigit (*ptr))
- {
- while (g_ascii_isdigit (*ptr)) ptr--;
- if ((*ptr != '_') && (*ptr != '-') && (*ptr != '.')) break;
- *ptr = '\0';
- ptr--;
- }
-
- /* Convert to upper case and remove invalid characters */
- for (ptr = name; *ptr != '\0'; ptr++)
- {
- if (g_ascii_isalnum (*ptr))
- {
- *ptr = g_ascii_toupper (*ptr);
- }
- else
- {
- *ptr = '_';
- }
- }
-
- g_signal_handlers_block_by_func (G_OBJECT (entry), on_changed_disconnect, view);
- gtk_entry_set_text (GTK_ENTRY (entry), name);
- g_signal_handlers_unblock_by_func (G_OBJECT (entry), on_changed_disconnect, view);
- g_free (name);
- }
-
- g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
- g_list_free (list);
- }
-}
-
-static void
-on_changed_disconnect (GtkEditable* entry, gpointer data)
-{
- g_signal_handlers_block_by_func (G_OBJECT (data), on_cursor_changed_set_entry, entry);
-}
-
-GList*
-gbf_project_util_add_package (AnjutaPmProject *project,
- GtkWindow *parent,
- GtkTreeIter *default_module,
- GList *packages_to_add)
-{
- GtkBuilder *gui;
- GtkWidget *dialog;
- GtkWidget *ok_button;
- GtkWidget *module_entry;
- GtkWidget *packages_view;
- GtkCellRenderer* renderer;
- GtkListStore *store;
- GList *packages = NULL;
- GtkTreeViewColumn *col;
- gint response;
- gboolean finished = FALSE;
- GtkTreeSelection *package_selection;
- GtkTreeIter root;
- gboolean valid;
- gint default_pos = -1;
- GbfProjectModel *model;
-
- g_return_val_if_fail (project != NULL, NULL);
-
- gui = load_interface ("add_package_dialog");
- g_return_val_if_fail (gui != NULL, NULL);
-
- /* get all needed widgets */
- dialog = GTK_WIDGET (gtk_builder_get_object (gui, "add_package_dialog"));
- module_entry = GTK_WIDGET (gtk_builder_get_object (gui, "module_entry"));
- packages_view = GTK_WIDGET (gtk_builder_get_object (gui, "packages_view"));
- ok_button = GTK_WIDGET (gtk_builder_get_object (gui, "ok_package_button"));
-
- /* 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);
-
- if (data && (data->type == GBF_TREE_NODE_MODULE))
- {
- GtkTreeIter list_iter;
- GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL (model), &iter);
-
- 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);
- }
- 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);
- g_object_unref (store);
- if (default_pos >= 0)
- {
- gtk_combo_box_set_active (GTK_COMBO_BOX (module_entry), default_pos);
- }
- else
- {
- /* Create automatically a module name from the package name when missing */
- GtkWidget *entry = gtk_bin_get_child (GTK_BIN (module_entry));
-
- g_signal_connect (G_OBJECT(packages_view), "cursor-changed",
- G_CALLBACK(on_cursor_changed_set_entry), entry);
- g_signal_connect (G_OBJECT(entry), "changed",
- G_CALLBACK(on_changed_disconnect), packages_view);
- }
-
- /* Fill package list */
- renderer = gtk_cell_renderer_text_new ();
- col = gtk_tree_view_column_new_with_attributes (_("Package"),
- renderer,
- "text", COL_PKG_PACKAGE,
- NULL);
- gtk_tree_view_column_set_sort_column_id (col, COL_PKG_PACKAGE);
- gtk_tree_view_append_column (GTK_TREE_VIEW (packages_view), col);
- renderer = gtk_cell_renderer_text_new ();
- col = gtk_tree_view_column_new_with_attributes (_("Description"),
- renderer,
- "text",
- COL_PKG_DESCRIPTION,
- NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (packages_view), col);
- store = packages_get_pkgconfig_list ();
- gtk_tree_view_set_model (GTK_TREE_VIEW (packages_view),
- GTK_TREE_MODEL (store));
-
- on_cursor_changed (GTK_TREE_VIEW (packages_view), ok_button);
- g_signal_connect (G_OBJECT(packages_view), "cursor-changed",
- G_CALLBACK(on_cursor_changed), ok_button);
- package_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (packages_view));
- gtk_tree_selection_set_mode (package_selection, GTK_SELECTION_MULTIPLE);
-
- if (parent) {
- gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
- }
-
- /* execute dialog */
- while (!finished) {
- response = gtk_dialog_run (GTK_DIALOG (dialog));
-
- switch (response) {
- case GTK_RESPONSE_OK:
- {
- gchar *module;
-
- module = gtk_combo_box_get_active_text (GTK_COMBO_BOX (module_entry));
- if (module)
- {
- GString *err_mesg = g_string_new (NULL);
- GList *list;
- GList *node;
- GtkTreeModel *model;
- GtkTreeIter iter;
-
- list = gtk_tree_selection_get_selected_rows (package_selection, &model);
- for (node = list; node != NULL; node = g_list_next (node))
- {
- if (gtk_tree_model_get_iter (model, &iter, (GtkTreePath *)(node->data)))
- {
- gchar *name;
- AnjutaProjectNode* new_package;
- GError *err = 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)
- {
- gchar *str = g_strdup_printf ("%s: %s\n",
- name,
- err->message);
- g_string_append (err_mesg, str);
- g_error_free (err);
- g_free (str);
- }
- else
- {
- packages = g_list_append (packages,
- new_package);
- }
- 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
- {
- error_dialog (parent, _("Cannot add packages"),
- "%s", _("No module has been selected"));
- }
- break;
- }
- default:
- finished = TRUE;
- break;
- }
- }
-
- /* destroy stuff */
- gtk_widget_destroy (dialog);
- g_object_unref (gui);
-
- return packages;
-}
diff --git a/plugins/project-manager/project-util.h b/plugins/project-manager/project-util.h
index 8f5f86e..090570e 100644
--- a/plugins/project-manager/project-util.h
+++ b/plugins/project-manager/project-util.h
@@ -30,37 +30,6 @@
G_BEGIN_DECLS
-AnjutaProjectNode* gbf_project_util_new_group (AnjutaPmProject *project,
- GtkWindow *parent,
- GtkTreeIter *default_group,
- const gchar *default_group_name_to_add);
-
-AnjutaProjectNode* gbf_project_util_new_target (AnjutaPmProject *project,
- GtkWindow *parent,
- GtkTreeIter *default_group,
- const gchar *default_target_name_to_add);
-
-AnjutaProjectNode* gbf_project_util_add_source (AnjutaPmProject *project,
- GtkWindow *parent,
- GtkTreeIter *default_target,
- const gchar *default_uri_to_add);
-
-GList* gbf_project_util_add_module (AnjutaPmProject *project,
- GtkWindow *parent,
- GtkTreeIter *default_target,
- const gchar *default_module_name_to_add);
-
-GList* gbf_project_util_add_package (AnjutaPmProject *project,
- GtkWindow *parent,
- GtkTreeIter *default_module,
- GList *packages_to_add);
-
-
-GList* gbf_project_util_add_source_multi (AnjutaPmProject *project,
- GtkWindow *parent,
- GtkTreeIter *default_target,
- GList *uris_to_add);
-
GList * gbf_project_util_all_child (AnjutaProjectNode *parent,
AnjutaProjectNodeType type);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]