Commit 751b521c authored by Tristan Van Berkom's avatar Tristan Van Berkom
Browse files

* gladeui/glade-project.c: Fixed GladeProject to only ever report widgets that are

	  actually in the project from the GtkTreeModel interface.
parent adf891b4
2011-01-02 Tristan Van Berkom <tristanvb@openismus.com>
* gladeui/glade-project.c: Fixed GladeProject to only ever report widgets that are
actually in the project from the GtkTreeModel interface.
2011-01-01 Tristan Van Berkom <tristanvb@openismus.com>
* gladeui/glade-command.[ch], Added GladeProject member to base command structure, now
......
......@@ -2941,7 +2941,8 @@ glade_project_has_object (GladeProject * project, GObject * object)
g_return_val_if_fail (GLADE_IS_WIDGET (gwidget), FALSE);
return (glade_widget_get_project (gwidget) == project && glade_widget_in_project (gwidget));
return (glade_widget_get_project (gwidget) == project &&
glade_widget_in_project (gwidget));
}
/**
......@@ -4342,6 +4343,91 @@ glade_project_display_dependencies (GladeProject * project)
/* GtkTreeModel implementation */
static GObject *
glade_project_nth_child (GladeProject *project,
GladeWidget *parent,
gint nth)
{
GList *children, *list;
GObject *child = NULL;
gint i;
children = glade_widget_get_children (parent);
for (list = children, i = 0; list; list = list->next)
{
child = list->data;
if (!glade_project_has_object (project, child))
continue;
if (i == nth)
break;
child = NULL;
i++;
}
g_list_free (children);
return child;
}
static gint
glade_project_child_position (GladeProject *project,
GladeWidget *parent,
GObject *child)
{
GList *children, *list;
GObject *iter;
gint i, position = -1;
children = glade_widget_get_children (parent);
for (list = children, i = 0; list; list = list->next)
{
iter = list->data;
if (!glade_project_has_object (project, iter))
continue;
if (iter == child)
{
position = i;
break;
}
i++;
}
g_list_free (children);
return position;
}
static gint
glade_project_count_children (GladeProject *project,
GladeWidget *parent)
{
GList *children, *list;
GObject *iter;
gint i;
children = glade_widget_get_children (parent);
for (list = children, i = 0; list; list = list->next)
{
iter = list->data;
if (!glade_project_has_object (project, iter))
continue;
i++;
}
g_list_free (children);
return i;
}
static void
glade_project_model_get_iter_for_object (GladeProject * project,
GObject * object, GtkTreeIter * iter)
......@@ -4390,13 +4476,12 @@ glade_project_model_get_iter (GtkTreeModel * model,
GtkTreeIter * iter, GtkTreePath * path)
{
GladeProject *project = GLADE_PROJECT (model);
gint *indices = gtk_tree_path_get_indices (path);
gint depth = gtk_tree_path_get_depth (path);
GladeWidget *widget;
GObject *object;
gint i;
GList *parent;
gint *indices = gtk_tree_path_get_indices (path);
gint depth = gtk_tree_path_get_depth (path);
GladeWidget *widget;
GObject *object;
gint i;
GList *parent;
if ((parent = g_list_nth (project->priv->tree, indices[0])) != NULL)
{
......@@ -4412,24 +4497,9 @@ glade_project_model_get_iter (GtkTreeModel * model,
for (i = 1; i < depth; i++)
{
GList *children = glade_widget_get_children (widget);
GList *node;
if (!children)
{
iter->stamp = 0;
iter->user_data = NULL;
return FALSE;
}
object = glade_project_nth_child (project, widget, indices[i]);
node = g_list_nth (children, indices[i]);
if (node)
{
object = G_OBJECT (node->data);
}
g_list_free (children);
if (!node)
if (!object)
{
iter->stamp = 0;
iter->user_data = NULL;
......@@ -4456,33 +4526,33 @@ static GtkTreePath *
glade_project_model_get_path (GtkTreeModel * model, GtkTreeIter * iter)
{
GladeProject *project = GLADE_PROJECT (model);
GtkTreePath *path;
GObject *object;
GladeWidget *widget;
GladeWidget *toplevel;
GladeWidget *parent;
GList *top;
GtkTreePath *path;
GObject *object;
GladeWidget *widget;
GladeWidget *toplevel;
GladeWidget *parent;
GList *top;
g_return_val_if_fail (VALID_ITER (project, iter), NULL);
object = iter->user_data;
widget = glade_widget_get_from_gobject (object);
object = iter->user_data;
widget = glade_widget_get_from_gobject (object);
toplevel = glade_widget_get_toplevel (widget);
parent = widget;
parent = widget;
path = gtk_tree_path_new ();
while ((parent = glade_widget_get_parent (widget)) != NULL)
{
GList *children = glade_widget_get_children (parent);
GList *child = g_list_find (children, glade_widget_get_object (widget));
gint position;
if (!child)
if ((position =
glade_project_child_position (project, parent,
glade_widget_get_object (widget))) < 0)
gtk_tree_path_prepend_index (path, 0);
else
gtk_tree_path_prepend_index (path, g_list_position (children, child));
gtk_tree_path_prepend_index (path, position);
g_list_free (children);
widget = parent;
}
......@@ -4575,7 +4645,15 @@ glade_project_model_iter_next (GtkTreeModel * model, GtkTreeIter * iter)
child = g_list_find (children, object);
if (child)
{
next = g_list_next (child);
/* Get the next child that is actually in the project */
for (next = child->next; next; next = next->next)
{
GObject *object = next->data;
if (glade_project_has_object (project, object))
break;
}
if (next)
{
glade_project_model_get_iter_for_object (project, next->data, iter);
......@@ -4591,19 +4669,16 @@ glade_project_model_iter_next (GtkTreeModel * model, GtkTreeIter * iter)
static gboolean
glade_project_model_iter_has_child (GtkTreeModel * model, GtkTreeIter * iter)
{
GladeWidget *widget;
GList *children;
GladeProject *project = GLADE_PROJECT (model);
GladeWidget *widget;
g_return_val_if_fail (VALID_ITER (model, iter), FALSE);
widget = glade_widget_get_from_gobject (iter->user_data);
children = glade_widget_get_children (widget);
if (children != NULL)
{
g_list_free (children);
return TRUE;
}
if (glade_project_count_children (project, widget) > 0)
return TRUE;
return FALSE;
}
......@@ -4617,62 +4692,46 @@ glade_project_model_iter_n_children (GtkTreeModel * model, GtkTreeIter * iter)
if (iter)
{
GladeWidget *widget = glade_widget_get_from_gobject (iter->user_data);
GList *children = glade_widget_get_children (widget);
if (children)
{
gint n = g_list_length (children);
g_list_free (children);
return n;
}
return glade_project_count_children (project, widget);
}
else
return g_list_length (project->priv->tree);
return 0;
return g_list_length (project->priv->tree);
}
static gboolean
glade_project_model_iter_nth_child (GtkTreeModel * model,
GtkTreeIter * iter,
GtkTreeIter * parent, gint n)
GtkTreeIter * parent, gint nth)
{
GladeProject *project = GLADE_PROJECT (model);
GList *children;
GObject *object = NULL;
g_return_val_if_fail (parent == NULL || VALID_ITER (project, parent), FALSE);
if (parent != NULL)
{
GObject *object = parent->user_data;
GladeWidget *widget = glade_widget_get_from_gobject (object);
children = glade_widget_get_children (widget);
GObject *obj = parent->user_data;
GladeWidget *widget = glade_widget_get_from_gobject (obj);
object = glade_project_nth_child (project, widget, nth);
}
else
else if (project->priv->tree)
{
children = project->priv->tree;
}
GList *child =
g_list_nth (project->priv->tree, nth);
if (children)
{
gboolean retval = FALSE;
GList *child = g_list_nth (children, n);
if (child)
{
glade_project_model_get_iter_for_object (project, child->data, iter);
retval = TRUE;
}
else
{
iter->stamp = 0;
iter->user_data = NULL;
}
if (children != project->priv->tree)
g_list_free (children);
object = child->data;
}
return retval;
if (object)
{
glade_project_model_get_iter_for_object (project, object, iter);
return TRUE;
}
iter->stamp = 0;
iter->stamp = 0;
iter->user_data = NULL;
return FALSE;
......@@ -4683,32 +4742,23 @@ glade_project_model_iter_children (GtkTreeModel * model,
GtkTreeIter * iter, GtkTreeIter * parent)
{
GladeProject *project = GLADE_PROJECT (model);
GObject *object = NULL;
g_return_val_if_fail (parent == NULL || VALID_ITER (project, parent), FALSE);
if (parent)
{
GladeWidget *widget = glade_widget_get_from_gobject (parent->user_data);
GList *children = glade_widget_get_children (widget);
if (children)
{
glade_project_model_get_iter_for_object (project,
G_OBJECT (children->data),
iter);
g_list_free (children);
return TRUE;
}
object = glade_project_nth_child (project, widget, 0);
}
else
else if (project->priv->tree)
object = project->priv->tree->data;
if (object)
{
if (project->priv->tree)
{
glade_project_model_get_iter_for_object (project,
G_OBJECT (project->priv->
tree->data), iter);
return TRUE;
}
glade_project_model_get_iter_for_object (project, object, iter);
return TRUE;
}
iter->stamp = 0;
......@@ -4729,7 +4779,8 @@ glade_project_model_iter_parent (GtkTreeModel * model,
widget = glade_widget_get_from_gobject (child->user_data);
parent = glade_widget_get_parent (widget);
if (parent)
if (parent &&
glade_project_has_object (project, glade_widget_get_object (parent)))
{
glade_project_model_get_iter_for_object (project,
glade_widget_get_object (parent),
......
Supports Markdown
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