[glade] * gladeui/glade-project.c: o Added notification of row-has-child-toggled when first child i
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade] * gladeui/glade-project.c: o Added notification of row-has-child-toggled when first child i
- Date: Fri, 4 Feb 2011 13:19:57 +0000 (UTC)
commit 65860ef2cfccd307cad9958a30a271ef565cbff1
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Fri Feb 4 22:27:54 2011 +0900
* gladeui/glade-project.c:
o Added notification of row-has-child-toggled when first
child is added to a parent or last child removed
o Added glade_project_check_reordered() to be called after setting
a child property on a widget since this may effect the order of children,
if the order changes, then emit the "rows-reordered" treemodel signal.
* gladeui/glade-widget.c: call glade_project_check_reordered() after applying
child properties.
* gladeui/glade-base-editor.c: Delete child first before adding a replacement
when changing a child's type (we cant assume the parent can hold more than
one child).
ChangeLog | 17 +++++++
gladeui/glade-base-editor.c | 12 +++--
gladeui/glade-project.c | 111 ++++++++++++++++++++++++++++++++++++++-----
gladeui/glade-project.h | 3 +
gladeui/glade-widget.c | 27 +++++++++--
5 files changed, 148 insertions(+), 22 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fd2b4bd..8d6fca9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2011-02-04 Tristan Van Berkom <tristanvb openismus com>
+
+ * gladeui/glade-project.c:
+ o Added notification of row-has-child-toggled when first
+ child is added to a parent or last child removed
+ o Added glade_project_check_reordered() to be called after setting
+ a child property on a widget since this may effect the order of children,
+ if the order changes, then emit the "rows-reordered" treemodel signal.
+
+ * gladeui/glade-widget.c: call glade_project_check_reordered() after applying
+ child properties.
+
+ * gladeui/glade-base-editor.c: Delete child first before adding a replacement
+ when changing a child's type (we cant assume the parent can hold more than
+ one child).
+
+
2011-02-03 Pablo Castellano <pablog gnome org>
Make libgladeui-2 library come with introspection data, patch based on original
diff --git a/gladeui/glade-base-editor.c b/gladeui/glade-base-editor.c
index defa411..bdbb3fb 100644
--- a/gladeui/glade-base-editor.c
+++ b/gladeui/glade-base-editor.c
@@ -796,7 +796,7 @@ glade_base_editor_popup (GladeBaseEditor * editor, GladeWidget * widget)
GLADE_BASE_EDITOR_GTYPE, &iter_type,
GLADE_BASE_EDITOR_CLASS_NAME, &class_name, -1);
- label = g_strdup_printf (_("Add %s item"), class_name);
+ label = g_strdup_printf (_("Add %s"), class_name);
item = gtk_menu_item_new_with_label (label);
gtk_widget_show (item);
@@ -828,7 +828,7 @@ glade_base_editor_popup (GladeBaseEditor * editor, GladeWidget * widget)
GLADE_BASE_EDITOR_GTYPE, &iter_type,
GLADE_BASE_EDITOR_CLASS_NAME, &class_name, -1);
- label = g_strdup_printf (_("Add child %s item"), class_name);
+ label = g_strdup_printf (_("Add child %s"), class_name);
item = gtk_menu_item_new_with_label (label);
gtk_widget_show (item);
@@ -1343,6 +1343,10 @@ glade_base_editor_change_type (GladeBaseEditor * editor,
name = g_strdup (glade_widget_get_name (gchild));
glade_base_editor_find_child (editor, gchild, &iter);
+ /* Delete old widget first, we cant assume the old and new widget can live in
+ * the same parent simultaniously */
+ glade_base_editor_delegate_delete_child (editor, parent, gchild);
+
/* Create new widget */
gchild_new = glade_base_editor_delegate_build_child (editor, parent, type);
@@ -1376,9 +1380,6 @@ glade_base_editor_change_type (GladeBaseEditor * editor,
/* Copy properties */
glade_widget_copy_properties (gchild_new, gchild, TRUE, TRUE);
- /* Delete old widget */
- glade_base_editor_delegate_delete_child (editor, parent, gchild);
-
/* Apply packing properties to the new object
*
* No need to use GladeCommand here on the newly created widget,
@@ -1400,6 +1401,7 @@ glade_base_editor_change_type (GladeBaseEditor * editor,
if (GTK_IS_WIDGET (child_new))
gtk_widget_show_all (GTK_WIDGET (child_new));
+ /* XXX We should update the widget name in the visible tree here too */
gtk_tree_store_set (GTK_TREE_STORE (editor->priv->model), &iter,
GLADE_BASE_EDITOR_GWIDGET, gchild_new,
GLADE_BASE_EDITOR_OBJECT, child_new,
diff --git a/gladeui/glade-project.c b/gladeui/glade-project.c
index a7c42d3..671e14e 100644
--- a/gladeui/glade-project.c
+++ b/gladeui/glade-project.c
@@ -221,16 +221,18 @@ static GtkWidget *glade_project_build_prefs_dialog (GladeProject * project);
static void target_button_clicked (GtkWidget * widget, GladeProject * project);
static void update_prefs_for_resource_path (GladeProject * project);
-static guint glade_project_signals[LAST_SIGNAL] = { 0 };
-
-static GladeIDAllocator *unsaved_number_allocator = NULL;
-
static void gtk_tree_model_iface_init (GtkTreeModelIface * iface);
static void glade_project_model_get_iter_for_object (GladeProject * project,
GObject * object,
GtkTreeIter * iter);
+static gint glade_project_count_children (GladeProject *project,
+ GladeWidget *parent);
+
+static guint glade_project_signals[LAST_SIGNAL] = { 0 };
+
+static GladeIDAllocator *unsaved_number_allocator = NULL;
#define GLADE_PROJECT_LARGE_PROJECT 40
@@ -2640,15 +2642,33 @@ glade_project_set_widget_name (GladeProject * project,
static void
glade_project_notify_row_has_child (GladeProject *project,
- GladeWidget *gwidget,
- gboolean adding)
+ GladeWidget *gwidget)
{
-}
+ GladeWidget *parent;
+ gint siblings;
+
+ parent = glade_widget_get_parent (gwidget);
+
+ if (parent)
+ {
+ siblings = glade_project_count_children (project, parent);
+
+ if (siblings == 1)
+ {
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ glade_project_model_get_iter_for_object (project, glade_widget_get_object (parent), &iter);
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (project), &iter);
+ gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (project), path, &iter);
+ gtk_tree_path_free (path);
+ }
+ }
+}
static void
-glade_project_notify_row_inserted (GladeProject * project,
- GladeWidget * gwidget)
+glade_project_notify_row_inserted (GladeProject *project,
+ GladeWidget *gwidget)
{
GtkTreeIter iter;
GtkTreePath *path;
@@ -2662,11 +2682,12 @@ glade_project_notify_row_inserted (GladeProject * project,
gtk_tree_model_row_inserted (GTK_TREE_MODEL (project), path, &iter);
gtk_tree_path_free (path);
- glade_project_notify_row_has_child (project, gwidget, TRUE);
+ glade_project_notify_row_has_child (project, gwidget);
}
static void
-glade_project_notify_row_deleted (GladeProject * project, GladeWidget * gwidget)
+glade_project_notify_row_deleted (GladeProject *project,
+ GladeWidget *gwidget)
{
GtkTreeIter iter;
GtkTreePath *path;
@@ -2676,11 +2697,71 @@ glade_project_notify_row_deleted (GladeProject * project, GladeWidget * gwidget)
gtk_tree_model_row_deleted (GTK_TREE_MODEL (project), path);
gtk_tree_path_free (path);
- glade_project_notify_row_has_child (project, gwidget, FALSE);
+ glade_project_notify_row_has_child (project, gwidget);
project->priv->stamp++;
}
+void
+glade_project_check_reordered (GladeProject *project,
+ GladeWidget *parent,
+ GList *old_order)
+{
+ GList *new_order, *l, *ll;
+ gint *order, n_children, i;
+ GtkTreeIter iter;
+ GtkTreePath *path;
+
+ g_return_if_fail (GLADE_IS_PROJECT (project));
+ g_return_if_fail (GLADE_IS_WIDGET (parent));
+ g_return_if_fail (glade_project_has_object (project,
+ glade_widget_get_object (parent)));
+
+ new_order = glade_widget_get_children (parent);
+
+ /* Check if the list changed */
+ for (l = old_order, ll = new_order;
+ l && ll;
+ l = l->next, ll = ll->next)
+ {
+ if (l->data != ll->data)
+ break;
+ }
+
+ if (l || ll)
+ {
+ n_children = glade_project_count_children (project, parent);
+ order = g_new (gint, n_children);
+
+ for (i = 0, l = new_order; l; l = l->next)
+ {
+ GObject *obj = l->data;
+
+ if (glade_project_has_object (project, obj))
+ {
+ GList *node = g_list_find (old_order, obj);
+
+ g_assert (node);
+
+ order[i] = g_list_position (old_order, node);
+
+ i++;
+ }
+ }
+
+ /* Signal that the rows were reordered */
+ glade_project_model_get_iter_for_object (project, glade_widget_get_object (parent), &iter);
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (project), &iter);
+ gtk_tree_model_rows_reordered (GTK_TREE_MODEL (project), path, &iter, order);
+ gtk_tree_path_free (path);
+
+ g_free (order);
+ }
+
+ g_list_free (new_order);
+}
+
+
/**
* glade_project_add_object:
* @project: the #GladeProject the widget is added to
@@ -4170,6 +4251,8 @@ glade_project_model_get_column_type (GtkTreeModel * model, gint column)
}
}
+GladeWidget *debug_widget;
+
static gboolean
glade_project_model_get_iter (GtkTreeModel * model,
GtkTreeIter * iter, GtkTreePath * path)
@@ -4194,6 +4277,7 @@ glade_project_model_get_iter (GtkTreeModel * model,
return FALSE;
}
+ debug_widget = widget;
for (i = 1; i < depth; i++)
{
object = glade_project_nth_child (project, widget, indices[i]);
@@ -4206,6 +4290,7 @@ glade_project_model_get_iter (GtkTreeModel * model,
}
widget = glade_widget_get_from_gobject (object);
+ debug_widget = widget;
}
if (object)
@@ -4464,7 +4549,7 @@ glade_project_model_iter_children (GtkTreeModel * model,
object = glade_project_nth_child (project, widget, 0);
}
else if (project->priv->tree)
- object = project->priv->tree->data;
+ object = project->priv->tree->data;
if (object)
{
diff --git a/gladeui/glade-project.h b/gladeui/glade-project.h
index 5edb1c9..d18e3ca 100644
--- a/gladeui/glade-project.h
+++ b/gladeui/glade-project.h
@@ -134,6 +134,9 @@ gchar *glade_project_resource_fullpath (GladeProject *proj
void glade_project_widget_visibility_changed (GladeProject *project,
GladeWidget *widget,
gboolean visible);
+void glade_project_check_reordered (GladeProject *project,
+ GladeWidget *parent,
+ GList *old_order);
/* Commands */
void glade_project_undo (GladeProject *project);
diff --git a/gladeui/glade-widget.c b/gladeui/glade-widget.c
index d84418f..7cc141c 100644
--- a/gladeui/glade-widget.c
+++ b/gladeui/glade-widget.c
@@ -3251,18 +3251,37 @@ glade_widget_object_get_property (GladeWidget * widget,
* Sets @child's packing property identified by @property_name to @value.
*/
void
-glade_widget_child_set_property (GladeWidget * widget,
- GladeWidget * child,
- const gchar * property_name,
- const GValue * value)
+glade_widget_child_set_property (GladeWidget *widget,
+ GladeWidget *child,
+ const gchar *property_name,
+ const GValue *value)
{
+ GList *old_order = NULL;
+
g_return_if_fail (GLADE_IS_WIDGET (widget));
g_return_if_fail (GLADE_IS_WIDGET (child));
g_return_if_fail (property_name != NULL && value != NULL);
+ if (widget->priv->project &&
+ widget->priv->in_project)
+ old_order = glade_widget_get_children (widget);
+
glade_widget_adaptor_child_set_property (widget->priv->adaptor,
widget->priv->object,
child->priv->object, property_name, value);
+
+ /* After setting a child property... it's possible the order of children
+ * in the parent has been effected.
+ *
+ * If this is the case then we need to signal the GladeProject that
+ * it's rows have been reordered so that any connected views update
+ * themselves properly.
+ */
+ if (widget->priv->project &&
+ widget->priv->in_project)
+ glade_project_check_reordered (widget->priv->project, widget, old_order);
+
+ g_list_free (old_order);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]