Hi Juan,
I added the push/pop group stuff to glade-command,
it works like a charm; I also have a working prototype of
glade-gtk.c except for one problem:
The reordering stuff doesn't work, undoing and redoing reorders
reverses the order all the time.
The solution that comes to mind is using "child-set-property-function"
on GtkMenu in order to implement a custom "position" packing property
for menu items (similar to the GtkBox position property), this property
would not be saved to the glade file so the backend would have to
assign it at load time.
All the actual reordering would be handled by the set-child-property
function provided for the "position" property, and when reorders are
needed, we'll just glade_command_set_property to get that done.
Then it should all go fine (fingers crossed).
I've attached here a patch against current cvs which shows my
working implementation of undo/redo on menu actions (but ofcourse
with reordering broken)... It also includes an example of how to
declare virtual packing properties (i.e. the position property).
I probably won't get any more work in tonight or tomorrow, so feel
free to hack away on this reorder issue, otherwise I'll get that
ironed out next time I get the chance (sometime next week).
A short todo list:
o Signal editor & Remove button should be insensitive when
no menuitems are selected in the tree.
o Try to find a way to re-arange the UI to make space for
Undo/Redo buttons (I think we should avoid accelerators)
o Editor will have to handle the appropriate signals (see
glade-project-view for examples) to update the treeview
when the project is modified (i.e. added/removed/reordered
items as a result of undo/redo)
o We'll have to modify the glade-editor code (maybe some backend
from glade-widget-class) so that any remote child of a widget
who's class provides a "launch-editor-function" the "Edit..."
button will show up for them too.
We should also consider that a parent & child in a hierarchy may
both have editor support, we should probably get the backend to
provide a string for its "Edit..." button and let those buttons
stack.
Cheers,
-Tristan
? glade-3-2.91.0.tar.gz
? macros
? po/stamp-it
Index: po/POTFILES.in
===================================================================
RCS file: /cvs/gnome/glade3/po/POTFILES.in,v
retrieving revision 1.9
diff -u -p -r1.9 POTFILES.in
--- po/POTFILES.in 12 Dec 2005 00:33:25 -0000 1.9
+++ po/POTFILES.in 18 Dec 2005 00:40:49 -0000
@@ -1,12 +1,7 @@
# List of source files containing translatable strings.
-
-
-# Main application
glade-3.desktop.in
src/main.c
src/glade-project-window.c
-
-# libgladeui shared core library
src/glade-app.c
src/glade-builtins.c
src/glade-catalog.c
@@ -34,7 +29,5 @@ src/glade-widget-class.c
src/glade-widget.c
src/glade-xml-utils.c
src/glade-project-view.c
-
-# gladegtk plugin backend
src/glade-gtk.c
widgets/gtk+.xml.in
Index: src/glade-gtk.c
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-gtk.c,v
retrieving revision 1.90
diff -u -p -r1.90 glade-gtk.c
--- src/glade-gtk.c 15 Dec 2005 03:57:19 -0000 1.90
+++ src/glade-gtk.c 18 Dec 2005 00:40:50 -0000
@@ -2771,6 +2771,68 @@ glade_gtk_menu_editor_reorder_children (
}
static void
+glade_gtk_menu_editor_real_reorder (GtkTreeModel *model, GtkTreeIter *iter)
+{
+ GladeWidget *gitem, *gparent;
+ GtkTreeIter parent_iter, child;
+ GObject *parent;
+ GList list = {0, };
+
+ gtk_tree_model_get (model, iter, GLADEGTK_MENU_GWIDGET, &gitem, -1);
+
+
+ if (gtk_tree_model_iter_parent (model, &parent_iter, iter))
+ {
+ GtkWidget *submenu;
+ gtk_tree_model_get (model, &parent_iter,
+ GLADEGTK_MENU_OBJECT, &parent,
+ GLADEGTK_MENU_GWIDGET, &gparent, -1);
+
+ if ((submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent))))
+ gparent = glade_widget_get_from_gobject (submenu);
+ else
+ gparent = glade_command_create (glade_widget_class_get_by_type (GTK_TYPE_MENU),
+ gparent, NULL, glade_widget_get_project (gparent));
+ }
+ else
+ gparent = glade_widget_get_parent (gitem);
+
+ do
+ {
+ gtk_tree_model_get (model, iter, GLADEGTK_MENU_GWIDGET, &gitem, -1);
+ list.data = gitem;
+
+ glade_command_cut (&list);
+ glade_command_paste (&list, gparent, NULL);
+
+ } while (gtk_tree_model_iter_next (model, iter));
+
+ if (gtk_tree_model_iter_children (model, &child, iter))
+ glade_gtk_menu_editor_real_reorder (model, &child);
+}
+
+
+static void
+glade_gtk_menu_editor_reorder (GladeGtkMenuEditor *e, GtkTreeModel *model, GtkTreeIter *iter)
+{
+ gchar *desc;
+
+ g_return_if_fail (e != NULL);
+ g_return_if_fail (e->gmenubar != NULL);
+
+ desc = g_strdup_printf (_("Reorder children of %s"), e->gmenubar->name);
+
+ /* Start glade-command */
+ glade_command_push_group (desc);
+
+ glade_gtk_menu_editor_real_reorder (model, iter);
+
+ /* End glade-command */
+ glade_command_pop_group ();
+}
+
+
+static void
glade_gtk_menu_editor_item_change_type (GladeGtkMenuEditor *e,
GtkTreeIter *iter,
GladeWidgetClass *klass,
@@ -2778,7 +2840,7 @@ glade_gtk_menu_editor_item_change_type (
{
GladeWidget *parent, *gitem, *gitem_new;
GObject *item, *item_new;
- gchar *name, *label, *tooltip;
+ gchar *name, *label, *tooltip, *desc;
GtkWidget *submenu;
GList list = {0, };
@@ -2793,6 +2855,12 @@ glade_gtk_menu_editor_item_change_type (
name = g_strdup (glade_widget_get_name (gitem));
submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (item));
+ /* Start glade-command */
+ desc = g_strdup_printf (_("Setting menu item type on %s to %s"),
+ gitem->name, klass_name);
+ glade_command_push_group (desc);
+ g_free (desc);
+
/* Create new widget */
gitem_new = glade_command_create (klass, parent, NULL, e->project);
item_new = glade_widget_get_object (gitem_new);
@@ -2828,7 +2896,7 @@ glade_gtk_menu_editor_item_change_type (
/* Delete old widget */
list.data = gitem;
glade_command_delete (&list);
-
+
gtk_widget_show_all (GTK_WIDGET (item_new));
gtk_tree_store_set (e->store, iter,
@@ -2839,8 +2907,15 @@ glade_gtk_menu_editor_item_change_type (
glade_gtk_menu_editor_treeview_cursor_changed (GTK_TREE_VIEW (e->treeview), e);
+ /* XXX
glade_gtk_menu_editor_reorder_children (GTK_WIDGET (glade_widget_get_object (parent)),
GTK_TREE_MODEL (e->store), iter);
+ */
+ glade_gtk_menu_editor_reorder (e, GTK_TREE_MODEL (e->store), iter);
+
+ /* End glade-command */
+ glade_command_pop_group ();
+
g_free (name);
g_free (label);
@@ -2911,46 +2986,6 @@ glade_gtk_menu_editor_popup_handler (Gtk
return FALSE;
}
-static void
-glade_gtk_menu_editor_reorder (GtkTreeModel *model, GtkTreeIter *iter)
-{
- GladeWidget *gitem, *gparent;
- GtkTreeIter parent_iter, child;
- GObject *parent;
- GList list = {0, };
-
- gtk_tree_model_get (model, iter, GLADEGTK_MENU_GWIDGET, &gitem, -1);
-
- if (gtk_tree_model_iter_parent (model, &parent_iter, iter))
- {
- GtkWidget *submenu;
- gtk_tree_model_get (model, &parent_iter,
- GLADEGTK_MENU_OBJECT, &parent,
- GLADEGTK_MENU_GWIDGET, &gparent, -1);
-
- if ((submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent))))
- gparent = glade_widget_get_from_gobject (submenu);
- else
- gparent = glade_command_create (glade_widget_class_get_by_type (GTK_TYPE_MENU),
- gparent, NULL, glade_widget_get_project (gparent));
- }
- else
- gparent = glade_widget_get_parent (gitem);
-
- do
- {
- gtk_tree_model_get (model, iter, GLADEGTK_MENU_GWIDGET, &gitem, -1);
- list.data = gitem;
-
- glade_command_cut (&list);
- glade_command_paste (&list, gparent, NULL);
-
- } while (gtk_tree_model_iter_next (model, iter));
-
- if (gtk_tree_model_iter_children (model, &child, iter))
- glade_gtk_menu_editor_reorder (model, &child);
-}
-
static gboolean
glade_gtk_menu_editor_drag_and_drop_idle (gpointer data)
{
@@ -2962,7 +2997,7 @@ glade_gtk_menu_editor_drag_and_drop_idle
else
gtk_tree_model_get_iter_first (GTK_TREE_MODEL (e->store), &first_child);
- glade_gtk_menu_editor_reorder (GTK_TREE_MODEL (e->store), &first_child);
+ glade_gtk_menu_editor_reorder (e, GTK_TREE_MODEL (e->store), &first_child);
return FALSE;
}
@@ -2998,9 +3033,16 @@ glade_gtk_menu_editor_add_item (GladeGtk
GladeWidget *gparent, *gitem_new;
GValue val = {0, };
const gchar *name;
+ gchar *desc;
gparent = e->gmenubar;
+ /* Start glade-command */
+ desc = g_strdup_printf (_("Create a %s"),
+ glade_gtk_menu_editor_type_name (type));
+ glade_command_push_group (desc);
+ g_free (desc);
+
if (glade_gtk_menu_editor_get_item_selected (e, &iter))
{
GObject *parent;
@@ -3046,7 +3088,7 @@ glade_gtk_menu_editor_add_item (GladeGtk
g_value_set_string (&val, name);
glade_command_set_property (glade_widget_get_property (gitem_new, "label"), &val);
}
-
+
gtk_tree_store_set (GTK_TREE_STORE (e->store), &new_iter,
GLADEGTK_MENU_GWIDGET, gitem_new,
GLADEGTK_MENU_OBJECT, glade_widget_get_object (gitem_new),
@@ -3054,10 +3096,16 @@ glade_gtk_menu_editor_add_item (GladeGtk
GLADEGTK_MENU_LABEL, name,
GLADEGTK_MENU_TOOLTIP, NULL,
-1);
-
+ /* XXX
glade_gtk_menu_editor_reorder_children (GTK_WIDGET (glade_widget_get_object (gparent)),
GTK_TREE_MODEL (e->store),
&new_iter);
+ */
+ glade_gtk_menu_editor_reorder (e, GTK_TREE_MODEL (e->store), &new_iter);
+
+ /* End glade-command */
+ glade_command_pop_group ();
+
/* This flags is used to know if the row was inserted by drag and drop */
e->row_inserted = FALSE;
}
Index: widgets/gtk+.xml
===================================================================
RCS file: /cvs/gnome/glade3/widgets/gtk+.xml,v
retrieving revision 1.27
diff -u -p -r1.27 gtk+.xml
--- widgets/gtk+.xml 15 Dec 2005 03:57:20 -0000 1.27
+++ widgets/gtk+.xml 18 Dec 2005 00:40:51 -0000
@@ -679,6 +679,13 @@
<type>GtkMenuItem</type>
<add-child-function>glade_gtk_menu_add_item</add-child-function>
<remove-child-function>glade_gtk_menu_remove_item</remove-child-function>
+
+ <properties>
+ <property id="position" _name="Position" save="False">
+ <spec>glade_standard_int_spec</spec>
+ <_tooltip>The position of the menu item in the menu</_tooltip>
+ </property>
+ </properties>
</child>
</children>
</glade-widget-class>
_______________________________________________
Glade-devel maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/glade-devel