[glade3/project-tree-model] Fix selection handling in inspector and deleting of widgets
- From: Johannes Schmid <jhs src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade3/project-tree-model] Fix selection handling in inspector and deleting of widgets
- Date: Sun, 9 May 2010 19:20:43 +0000 (UTC)
commit 4a264ade01776ec3d4a2509a50e934cffbe9f2e5
Author: Johannes Schmid <jhs gnome org>
Date: Sun May 9 21:04:13 2010 +0200
Fix selection handling in inspector and deleting of widgets
gladeui/glade-inspector.c | 79 +++++++++++++++++++++++++++++++++++++++++++++
gladeui/glade-project.c | 38 +++++++++++++--------
gladeui/glade-utils.c | 8 +++--
3 files changed, 108 insertions(+), 17 deletions(-)
---
diff --git a/gladeui/glade-inspector.c b/gladeui/glade-inspector.c
index 5cff531..0c2e696 100644
--- a/gladeui/glade-inspector.c
+++ b/gladeui/glade-inspector.c
@@ -408,6 +408,68 @@ glade_inspector_finalize (GObject *object)
}
static void
+project_selection_changed_cb (GladeProject *project,
+ GladeInspector *inspector)
+{
+ GladeWidget *widget;
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GtkTreeIter *iter;
+ GtkTreePath *path, *ancestor_path;
+ GList *list;
+
+ g_return_if_fail (GLADE_IS_INSPECTOR (inspector));
+ g_return_if_fail (GLADE_IS_PROJECT (project));
+ g_return_if_fail (inspector->priv->project == project);
+
+ g_signal_handlers_block_by_func (gtk_tree_view_get_selection (GTK_TREE_VIEW (inspector->priv->view)),
+ G_CALLBACK (selection_changed_cb),
+ inspector);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (inspector->priv->view));
+ g_return_if_fail (selection != NULL);
+
+ model = inspector->priv->filter;
+
+ gtk_tree_selection_unselect_all (selection);
+
+ for (list = glade_project_selection_get (project);
+ list && list->data; list = list->next)
+ {
+ if ((widget = glade_widget_get_from_gobject (G_OBJECT (list->data))) != NULL)
+ {
+ if ((iter = glade_util_find_iter_by_widget (model, widget, GLADE_PROJECT_MODEL_COLUMN_OBJECT)) != NULL)
+ {
+ path = gtk_tree_model_get_path (model, iter);
+ ancestor_path = gtk_tree_path_copy (path);
+
+ /* expand parent node */
+ if (gtk_tree_path_up (ancestor_path))
+ gtk_tree_view_expand_to_path
+ (GTK_TREE_VIEW (inspector->priv->view), ancestor_path);
+
+ gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (inspector->priv->view),
+ path,
+ NULL,
+ TRUE,
+ 0.5,
+ 0);
+
+ gtk_tree_selection_select_iter (selection, iter);
+
+ gtk_tree_iter_free (iter);
+ gtk_tree_path_free (path);
+ gtk_tree_path_free (ancestor_path);
+ }
+ }
+ }
+
+ g_signal_handlers_unblock_by_func (gtk_tree_view_get_selection (GTK_TREE_VIEW (inspector->priv->view)),
+ G_CALLBACK (selection_changed_cb),
+ inspector);
+}
+
+static void
selection_foreach_func (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
@@ -425,6 +487,10 @@ static void
selection_changed_cb (GtkTreeSelection *selection,
GladeInspector *inspector)
{
+ g_signal_handlers_block_by_func (inspector->priv->project,
+ G_CALLBACK (project_selection_changed_cb),
+ inspector);
+
glade_app_selection_clear (FALSE);
gtk_tree_selection_selected_foreach (selection,
@@ -432,6 +498,10 @@ selection_changed_cb (GtkTreeSelection *selection,
inspector);
glade_app_selection_changed ();
+ g_signal_handlers_unblock_by_func (inspector->priv->project,
+ G_CALLBACK (project_selection_changed_cb),
+ inspector);
+
g_signal_emit (inspector, glade_inspector_signals[SELECTION_CHANGED], 0);
}
@@ -544,6 +614,9 @@ glade_inspector_set_project (GladeInspector *inspector,
if (inspector->priv->project)
{
+ g_signal_handlers_disconnect_by_func (G_OBJECT (project),
+ G_CALLBACK (project_selection_changed_cb),
+ inspector);
g_object_unref (inspector->priv->project);
inspector->priv->project = NULL;
}
@@ -560,6 +633,9 @@ glade_inspector_set_project (GladeInspector *inspector,
inspector, NULL);
gtk_tree_view_set_model (GTK_TREE_VIEW (priv->view), priv->filter);
+ g_signal_connect (G_OBJECT (project), "selection-changed",
+ G_CALLBACK (project_selection_changed_cb),
+ inspector);
}
gtk_tree_view_expand_all (GTK_TREE_VIEW (inspector->priv->view));
@@ -654,6 +730,9 @@ glade_inspector_new_with_project (GladeProject *project)
"project", project,
NULL);
+ /* Make sure we expended to the right path */
+ project_selection_changed_cb (project, inspector);
+
return GTK_WIDGET (inspector);
}
diff --git a/gladeui/glade-project.c b/gladeui/glade-project.c
index 7307cb6..2076e1b 100644
--- a/gladeui/glade-project.c
+++ b/gladeui/glade-project.c
@@ -2761,7 +2761,9 @@ void
glade_project_remove_object (GladeProject *project, GObject *object)
{
GladeWidget *gwidget;
- GList *link, *list, *children;
+ GList *list, *children;
+ GtkTreeIter* iter;
+ GtkTreePath* path;
g_return_if_fail (GLADE_IS_PROJECT (project));
g_return_if_fail (G_IS_OBJECT (object));
@@ -2783,17 +2785,14 @@ glade_project_remove_object (GladeProject *project, GObject *object)
glade_project_selection_remove (project, object, TRUE);
- if ((link = g_list_find (glade_project_get_objects (project), object)) != NULL)
+ iter = glade_util_find_iter_by_widget (GTK_TREE_MODEL (project), gwidget,
+ GLADE_PROJECT_MODEL_COLUMN_OBJECT);
+ if (iter)
{
- GtkTreeIter iter;
- GtkTreePath* path;
- if (glade_widget_get_parent (gwidget) == NULL)
- {
- project->priv->tree = g_list_delete_link (project->priv->tree, link);
- }
- glade_project_model_get_iter_for_object (project, object, &iter);
+ GList *link = g_list_find (project->priv->tree, object);
+
path = gtk_tree_model_get_path (GTK_TREE_MODEL (project),
- &iter);
+ iter);
gtk_tree_model_row_deleted (GTK_TREE_MODEL (project),
path);
g_object_unref (object);
@@ -2801,10 +2800,16 @@ glade_project_remove_object (GladeProject *project, GObject *object)
glade_widget_get_name (gwidget));
+ if (link)
+ {
+ project->priv->tree = g_list_delete_link (project->priv->tree, link);
+ }
+
g_signal_emit (G_OBJECT (project),
glade_project_signals [REMOVE_WIDGET],
0,
gwidget);
+ gtk_tree_iter_free (iter);
}
}
@@ -3516,8 +3521,10 @@ glade_project_create_object_list_foreach (GtkTreeModel* model,
gtk_tree_model_get (model, iter, GLADE_PROJECT_MODEL_COLUMN_OBJECT, &object, -1);
/* Get rid of the extra reference */
- g_object_unref (object);
- *list = g_list_append (*list, object);
+ g_object_unref (object);
+ *list = g_list_prepend (*list, object);
+
+ g_message ("Object: %p", object);
/* Continue iteration */
return FALSE;
@@ -4448,6 +4455,9 @@ glade_project_model_iter_next (GtkTreeModel* model,
}
if (children != project->priv->tree)
g_list_free (children);
+
+ if (retval)
+ g_message ("Next: %p", iter->user_data);
return retval;
}
@@ -4529,12 +4539,12 @@ glade_project_model_iter_children (GtkTreeModel* model,
GtkTreeIter* parent)
{
GladeProject* project = GLADE_PROJECT (model);
+
if (parent)
{
GladeWidget* widget = glade_widget_get_from_gobject (parent->user_data);
- if (widget)
- return FALSE;
GList* children = glade_widget_get_children (widget);
+
if (children)
{
glade_project_model_get_iter_for_object (project,
diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c
index 80b5bb2..f8a6954 100644
--- a/gladeui/glade-utils.c
+++ b/gladeui/glade-utils.c
@@ -1090,7 +1090,7 @@ glade_util_find_iter (GtkTreeModel *model,
gint column)
{
GtkTreeIter *retval = NULL;
- GladeWidget *widget;
+ GObject* object;
GtkTreeIter *next;
g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
@@ -1101,8 +1101,8 @@ glade_util_find_iter (GtkTreeModel *model,
while (retval == NULL)
{
- gtk_tree_model_get (model, next, column, &widget, -1);
- if (widget == findme)
+ gtk_tree_model_get (model, next, column, &object, -1);
+ if (object == glade_widget_get_object (findme))
{
retval = gtk_tree_iter_copy (next);
break;
@@ -1116,6 +1116,8 @@ glade_util_find_iter (GtkTreeModel *model,
break;
}
+ g_object_unref (object);
+
if (!gtk_tree_model_iter_next (model, next))
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]