Author: lluis
Date: 2006-12-17 07:46:05 -0500 (Sun, 17 Dec 2006)
New Revision: 69598

Modified:
   trunk/stetic/ChangeLog
   trunk/stetic/libstetic/editor/ActionMenu.cs
   trunk/stetic/libstetic/editor/ActionMenuBar.cs
   trunk/stetic/libstetic/editor/ActionMenuItem.cs
   trunk/stetic/libstetic/editor/ActionToolItem.cs
   trunk/stetic/libstetic/editor/ActionToolbar.cs
   trunk/stetic/libstetic/undo/ActionDiffAdaptor.cs
   trunk/stetic/libstetic/undo/DiffGenerator.cs
   trunk/stetic/libstetic/undo/UndoManager.cs
   trunk/stetic/libstetic/undo/XmlDiffAdaptor.cs
   trunk/stetic/libstetic/wrapper/Action.cs
   trunk/stetic/libstetic/wrapper/ActionGroup.cs
   trunk/stetic/libstetic/wrapper/ActionToolbarWrapper.cs
   trunk/stetic/libstetic/wrapper/ActionTree.cs
   trunk/stetic/libstetic/wrapper/Container.cs
   trunk/stetic/libstetic/wrapper/MenuBar.cs
   trunk/stetic/libstetic/wrapper/Widget.cs
   trunk/stetic/libstetic/wrapper/objects.xml
   trunk/stetic/libsteticui/PaletteBackend.cs
   trunk/stetic/libsteticui/Project.cs
   trunk/stetic/libsteticui/ProjectBackend.cs
   trunk/stetic/libsteticui/UndoQueue.cs
   trunk/stetic/libsteticui/WidgetDesigner.cs
   trunk/stetic/libsteticui/WidgetEditSession.cs
Log:
* libsteticui/ProjectBackend.cs, libsteticui/WidgetEditSession.cs,
  libsteticui/WidgetDesigner.cs, libsteticui/Project.cs: Added new
  Changed event.
* libsteticui/PaletteBackend.cs, libsteticui/UndoQueue.cs,
  libstetic/undo/DiffGenerator.cs,
  libstetic/undo/ActionDiffAdaptor.cs, libstetic/wrapper/Action.cs,
  libstetic/wrapper/Container.cs, libstetic/wrapper/Widget.cs,
  libstetic/wrapper/ActionGroup.cs, libstetic/wrapper/MenuBar.cs,
  libstetic/wrapper/ActionTree.cs,
  libstetic/editor/ActionMenuItem.cs,
  libstetic/editor/ActionMenuBar.cs, libstetic/editor/ActionMenu.cs,
  libstetic/editor/ActionToolItem.cs,
  libstetic/editor/ActionToolbar.cs: Improved support for Undo.
* libstetic/undo/UndoManager.cs: Removed debug code.
* libstetic/undo/XmlDiffAdaptor.cs: Fix support for name and id
  properties when diffing.
* libstetic/wrapper/objects.xml: HasFocus property doesn't need to be
  available at design time.
* libstetic/wrapper/ActionToolbarWrapper.cs: Implemented support for
  Undo.

Modified: trunk/stetic/ChangeLog
===================================================================
--- trunk/stetic/ChangeLog      2006-12-17 11:41:14 UTC (rev 69597)
+++ trunk/stetic/ChangeLog      2006-12-17 12:46:05 UTC (rev 69598)
@@ -1,3 +1,26 @@
+2006-12-17  Lluis Sanchez Gual <[EMAIL PROTECTED]> 
+
+       * libsteticui/ProjectBackend.cs, libsteticui/WidgetEditSession.cs,
+         libsteticui/WidgetDesigner.cs, libsteticui/Project.cs: Added new
+         Changed event.
+       * libsteticui/PaletteBackend.cs, libsteticui/UndoQueue.cs,
+         libstetic/undo/DiffGenerator.cs,
+         libstetic/undo/ActionDiffAdaptor.cs, libstetic/wrapper/Action.cs,
+         libstetic/wrapper/Container.cs, libstetic/wrapper/Widget.cs,
+         libstetic/wrapper/ActionGroup.cs, libstetic/wrapper/MenuBar.cs,
+         libstetic/wrapper/ActionTree.cs,
+         libstetic/editor/ActionMenuItem.cs,
+         libstetic/editor/ActionMenuBar.cs, libstetic/editor/ActionMenu.cs,
+         libstetic/editor/ActionToolItem.cs,
+         libstetic/editor/ActionToolbar.cs: Improved support for Undo.
+       * libstetic/undo/UndoManager.cs: Removed debug code.
+       * libstetic/undo/XmlDiffAdaptor.cs: Fix support for name and id
+         properties when diffing.
+       * libstetic/wrapper/objects.xml: HasFocus property doesn't need to be
+         available at design time.
+       * libstetic/wrapper/ActionToolbarWrapper.cs: Implemented support for
+         Undo.
+
 2006-12-05  Lluis Sanchez Gual <[EMAIL PROTECTED]> 
 
        * libsteticui/UndoQueue.cs: Added debug method.

Modified: trunk/stetic/libstetic/editor/ActionMenu.cs
===================================================================
--- trunk/stetic/libstetic/editor/ActionMenu.cs 2006-12-17 11:41:14 UTC (rev 
69597)
+++ trunk/stetic/libstetic/editor/ActionMenu.cs 2006-12-17 12:46:05 UTC (rev 
69598)
@@ -107,6 +107,7 @@
                        menuItems.Clear ();
 
                        uint n = 0;
+                       ActionMenuItem editItem = null;
                        
                        if (nodes.Count > 0) {
                                foreach (ActionTreeNode node in nodes) {
@@ -114,6 +115,9 @@
                                        item.KeyPressEvent += OnItemKeyPress;
                                        item.Attach (table, n++, 0);
                                        menuItems.Add (item);
+                                       // If adding an action with an empty 
name, select and start editing it
+//                                     if (node.Action != null && 
node.Action.Name.Length == 0)
+//                                             editItem = item;
                                }
                        }
                        
@@ -127,6 +131,17 @@
                        table.Attach (emptyLabel, 1, 2, n, n + 1);
                        
                        ShowAll ();
+                       
+                       if (editItem != null) {
+                               // If there is an item with an empty action, it 
means that it was an item that was
+                               // being edited. Restart the editing now.
+                               GLib.Timeout.Add (200, delegate {
+                                       editItem.Select ();
+                                       editItem.EditingDone += OnEditingDone;
+                                       editItem.StartEditing ();
+                                       return false;
+                               });
+                       }
                }
                
                void Refresh ()
@@ -135,8 +150,9 @@
                        ActionTreeNode selNode = null;
                        
                        foreach (Gtk.Widget w in table.Children) {
-                               if (area.IsSelected (w) && w is ActionMenuItem) 
{
-                                       selNode = ((ActionMenuItem)w).Node;
+                               ActionMenuItem ami = w as ActionMenuItem;
+                               if (area.IsSelected (w) && ami != null) {
+                                       selNode = ami.Node;
                                        area.ResetSelection (w);
                                }
                                table.Remove (w);
@@ -166,14 +182,20 @@
                
                void InsertAction (int pos)
                {
-                       Action ac = (Action) ObjectWrapper.Create 
(wrapper.Project, new Gtk.Action ("", "", null, null));
-                       ActionTreeNode newNode = new ActionTreeNode 
(Gtk.UIManagerItemType.Menuitem, null, ac);
-                       nodes.Insert (pos, newNode);
-                       ActionMenuItem item = FindMenuItem (newNode);
-                       item.EditingDone += OnEditingDone;
-                       item.Select ();
-                       item.StartEditing ();
-                       emptyLabel.Hide ();
+                       using (wrapper.UndoManager.AtomicChange) {
+                               Action ac = (Action) ObjectWrapper.Create 
(wrapper.Project, new Gtk.Action ("", "", null, null));
+                               ActionTreeNode newNode = new ActionTreeNode 
(Gtk.UIManagerItemType.Menuitem, null, ac);
+                               nodes.Insert (pos, newNode);
+                               ActionMenuItem item = FindMenuItem (newNode);
+                               item.EditingDone += OnEditingDone;
+                               item.Select ();
+                               item.StartEditing ();
+                               emptyLabel.Hide ();
+                               
+                               if (wrapper.LocalActionGroups.Count == 0)
+                                       wrapper.LocalActionGroups.Add (new 
ActionGroup ("Default"));
+                               wrapper.LocalActionGroups [0].Actions.Add (ac);
+                       }
                }
                
                void OnEditingDone (object ob, EventArgs args)
@@ -183,11 +205,10 @@
                        if (item.Node.Action.GtkAction.Label.Length == 0 && 
item.Node.Action.GtkAction.StockId == null) {
                                IDesignArea area = wrapper.GetDesignArea ();
                                area.ResetSelection (item);
-                               nodes.Remove (item.Node);
-                       } else {
-                               if (wrapper.LocalActionGroups.Count == 0)
-                                       wrapper.LocalActionGroups.Add (new 
ActionGroup ("Default"));
-                               wrapper.LocalActionGroups [0].Actions.Add 
(item.Node.Action);
+                               using (wrapper.UndoManager.AtomicChange) {
+                                       nodes.Remove (item.Node);
+                                       wrapper.LocalActionGroups 
[0].Actions.Remove (item.Node.Action);
+                               }
                        }
                }
                
@@ -308,32 +329,34 @@
                        
                        // Toolitems are copied, not moved
                        
-                       if (dropped.Node.ParentNode != null && 
dropped.Node.Type != Gtk.UIManagerItemType.Toolitem) {
-                               if (dropIndex < nodes.Count) {
-                                       // Do nothing if trying to drop the 
node over the same node
-                                       ActionTreeNode dropNode = nodes 
[dropIndex];
-                                       if (dropNode == dropped.Node)
-                                               return false;
-                                       dropped.Node.ParentNode.Children.Remove 
(dropped.Node);
-                                       
-                                       // The drop position may have changed 
after removing the dropped node,
-                                       // so get it again.
-                                       dropIndex = nodes.IndexOf (dropNode);
-                                       nodes.Insert (dropIndex, dropped.Node);
+                       using (wrapper.UndoManager.AtomicChange) {
+                               if (dropped.Node.ParentNode != null && 
dropped.Node.Type != Gtk.UIManagerItemType.Toolitem) {
+                                       if (dropIndex < nodes.Count) {
+                                               // Do nothing if trying to drop 
the node over the same node
+                                               ActionTreeNode dropNode = nodes 
[dropIndex];
+                                               if (dropNode == dropped.Node)
+                                                       return false;
+                                                       
+                                               
dropped.Node.ParentNode.Children.Remove (dropped.Node);
+                                               
+                                               // The drop position may have 
changed after removing the dropped node,
+                                               // so get it again.
+                                               dropIndex = nodes.IndexOf 
(dropNode);
+                                               nodes.Insert (dropIndex, 
dropped.Node);
+                                       } else {
+                                               
dropped.Node.ParentNode.Children.Remove (dropped.Node);
+                                               nodes.Add (dropped.Node);
+                                               dropIndex = nodes.Count - 1;
+                                       }
                                } else {
-                                       dropped.Node.ParentNode.Children.Remove 
(dropped.Node);
-                                       nodes.Add (dropped.Node);
-                                       dropIndex = nodes.Count - 1;
+                                       newNode = new ActionTreeNode 
(Gtk.UIManagerItemType.Menuitem, null, dropped.Node.Action);
+                                       nodes.Insert (dropIndex, newNode);
                                }
-                       } else {
-                               newNode = new ActionTreeNode 
(Gtk.UIManagerItemType.Menuitem, null, dropped.Node.Action);
-                               nodes.Insert (dropIndex, newNode);
+                               // Select the dropped node
+                               ActionMenuItem mi = (ActionMenuItem) menuItems 
[dropIndex];
+                               mi.Select ();
                        }
                        
-                       // Select the dropped node
-                       ActionMenuItem mi = (ActionMenuItem) menuItems 
[dropIndex];
-                       mi.Select ();
-                       
                        return base.OnDragDrop (context, x,     y, time);
                }
                
@@ -487,8 +510,17 @@
                                return;
                                
                        ActionMenuItem item = (ActionMenuItem)menuItems [pos];
-                       if (index == status.Count - 1)  // The last position in 
the status is the selected item
+                       if (index == status.Count - 1)  {
+                               // The last position in the status is the 
selected item
                                item.Select ();
+                               if (item.Node.Action != null && 
item.Node.Action.Name.Length == 0) {
+                                       // Then only case when there can have 
an action when an empty name
+                                       // is when the user clicked on the "add 
action" link. In this case,
+                                       // start editing the item again
+                                       item.EditingDone += OnEditingDone;
+                                       item.StartEditing ();
+                               }
+                       }
                        else {
                                item.ShowSubmenu ();
                                if (OpenSubmenu != null)

Modified: trunk/stetic/libstetic/editor/ActionMenuBar.cs
===================================================================
--- trunk/stetic/libstetic/editor/ActionMenuBar.cs      2006-12-17 11:41:14 UTC 
(rev 69597)
+++ trunk/stetic/libstetic/editor/ActionMenuBar.cs      2006-12-17 12:46:05 UTC 
(rev 69598)
@@ -91,9 +91,17 @@
                                return;
                                
                        ActionMenuItem item = (ActionMenuItem) menuItems [pos];
-                       if (status.Count == 1)  // The last position in the 
status is the selected item
+                       if (status.Count == 1)  {
+                               // The last position in the status is the 
selected item
                                item.Select ();
-                       else {
+                               if (item.Node.Action != null && 
item.Node.Action.Name.Length == 0) {
+                                       // Then only case when there can have 
an action when an empty name
+                                       // is when the user clicked on the "add 
action" link. In this case,
+                                       // start editing the item again
+                                       item.EditingDone += OnEditingDone;
+                                       item.StartEditing ();
+                               }
+                       } else {
                                item.ShowSubmenu ();
                                if (OpenSubmenu != null)
                                        OpenSubmenu.RestoreStatus (status, 1);
@@ -236,14 +244,20 @@
                void InsertAction (int pos)
                {
                        Widget wrapper = Widget.Lookup (this);
-                       Action ac = (Action) ObjectWrapper.Create 
(wrapper.Project, new Gtk.Action ("", "", null, null));
-                       ActionTreeNode node = new ActionTreeNode 
(Gtk.UIManagerItemType.Menu, "", ac);
-                       actionTree.Children.Insert (pos, node);
+                       using (wrapper.UndoManager.AtomicChange) {
+                               Action ac = (Action) ObjectWrapper.Create 
(wrapper.Project, new Gtk.Action ("", "", null, null));
+                               ActionTreeNode node = new ActionTreeNode 
(Gtk.UIManagerItemType.Menu, "", ac);
+                               actionTree.Children.Insert (pos, node);
 
-                       ActionMenuItem aitem = FindMenuItem (node);
-                       aitem.EditingDone += OnEditingDone;
-                       aitem.Select ();
-                       aitem.StartEditing ();
+                               ActionMenuItem aitem = FindMenuItem (node);
+                               aitem.EditingDone += OnEditingDone;
+                               aitem.Select ();
+                               aitem.StartEditing ();
+                               
+                               if (wrapper.LocalActionGroups.Count == 0)
+                                       wrapper.LocalActionGroups.Add (new 
ActionGroup ("Default"));
+                               wrapper.LocalActionGroups[0].Actions.Add (ac);
+                       }
                }
                
                void OnEditingDone (object ob, EventArgs args)
@@ -255,11 +269,10 @@
                        if (item.Node.Action.GtkAction.Label.Length == 0 && 
item.Node.Action.GtkAction.StockId == null) {
                                IDesignArea area = wrapper.GetDesignArea ();
                                area.ResetSelection (item);
-                               actionTree.Children.Remove (item.Node);
-                       } else {
-                               if (wrapper.LocalActionGroups.Count == 0)
-                                       wrapper.LocalActionGroups.Add (new 
ActionGroup ("Default"));
-                               wrapper.LocalActionGroups[0].Actions.Add 
(item.Node.Action);
+                               using (wrapper.UndoManager.AtomicChange) {
+                                       actionTree.Children.Remove (item.Node);
+                                       wrapper.LocalActionGroups 
[0].Actions.Remove (item.Node.Action);
+                               }
                        }
                }
                
@@ -372,30 +385,33 @@
                                newNode.Type = Gtk.UIManagerItemType.Menuitem;
                        }
 
-                       if (dropIndex < actionTree.Children.Count) {
-                               // Do nothing if trying to drop the node over 
the same node
-                               ActionTreeNode dropNode = actionTree.Children 
[dropIndex];
-                               if (dropNode == dropped.Node)
-                                       return false;
+                       Widget wrapper = Widget.Lookup (this);
+                       using (wrapper.UndoManager.AtomicChange) {
+                               if (dropIndex < actionTree.Children.Count) {
+                                       // Do nothing if trying to drop the 
node over the same node
+                                       ActionTreeNode dropNode = 
actionTree.Children [dropIndex];
+                                       if (dropNode == dropped.Node)
+                                               return false;
+                                               
+                                       if (newNode.ParentNode != null)
+                                               
newNode.ParentNode.Children.Remove (newNode);
                                        
-                               if (newNode.ParentNode != null)
-                                       newNode.ParentNode.Children.Remove 
(newNode);
+                                       // The drop position may have changed 
after removing the dropped node,
+                                       // so get it again.
+                                       dropIndex = actionTree.Children.IndexOf 
(dropNode);
+                                       actionTree.Children.Insert (dropIndex, 
newNode);
+                               } else {
+                                       if (newNode.ParentNode != null)
+                                               
newNode.ParentNode.Children.Remove (newNode);
+                                       actionTree.Children.Add (newNode);
+                                       dropIndex = actionTree.Children.Count - 
1;
+                               }
                                
-                               // The drop position may have changed after 
removing the dropped node,
-                               // so get it again.
-                               dropIndex = actionTree.Children.IndexOf 
(dropNode);
-                               actionTree.Children.Insert (dropIndex, newNode);
-                       } else {
-                               if (newNode.ParentNode != null)
-                                       newNode.ParentNode.Children.Remove 
(newNode);
-                               actionTree.Children.Add (newNode);
-                               dropIndex = actionTree.Children.Count - 1;
+                               // Select the dropped node
+                               ActionMenuItem mi = (ActionMenuItem) menuItems 
[dropIndex];
+                               mi.Select ();
                        }
                        
-                       // Select the dropped node
-                       ActionMenuItem mi = (ActionMenuItem) menuItems 
[dropIndex];
-                       mi.Select ();
-                       
                        return base.OnDragDrop (context, x,     y, time);
                }               
                protected override bool OnExposeEvent (Gdk.EventExpose ev)

Modified: trunk/stetic/libstetic/editor/ActionMenuItem.cs
===================================================================
--- trunk/stetic/libstetic/editor/ActionMenuItem.cs     2006-12-17 11:41:14 UTC 
(rev 69597)
+++ trunk/stetic/libstetic/editor/ActionMenuItem.cs     2006-12-17 12:46:05 UTC 
(rev 69598)
@@ -107,6 +107,18 @@
                public void EndEditing ()
                {
                        if (editing) {
+                               Gtk.Entry entry = label as Gtk.Entry;
+                               if (entry != null) {
+                                       localUpdate = true;
+                                       if (entry.Text.Length > 0 || 
node.Action.GtkAction.StockId != null) {
+                                               using 
(node.Action.UndoManager.AtomicChange) {
+                                                       
node.Action.GtkAction.Label = entry.Text;
+                                                       
node.Action.NotifyChanged ();
+                                               }
+                                       }
+                                       localUpdate = false;
+                               }
+                               
                                editing = false;
                                Refresh ();
                                while (Gtk.Application.EventsPending ())
@@ -271,7 +283,6 @@
                                
                                Gtk.Entry entry = new Gtk.Entry ();
                                entry.Text = text;
-                               entry.Changed += OnLabelChanged;
                                entry.Activated += OnLabelActivated;
                                entry.HasFrame = false;
                                this.label = entry;
@@ -335,20 +346,6 @@
                        table.Remove (this);
                }
                
-               void OnLabelChanged (object ob, EventArgs args)
-               {
-                       localUpdate = true;
-                       
-                       Gtk.Entry entry = ob as Gtk.Entry;
-                       if (entry.Text.Length > 0 || 
node.Action.GtkAction.StockId != null) {
-                               using (node.Action.UndoManager.AtomicChange) {
-                                       node.Action.GtkAction.Label = 
entry.Text;
-                                       node.Action.NotifyChanged ();
-                               }
-                       }
-                       localUpdate = false;
-               }
-               
                void OnCreateDeleteSubmenu (object ob, EventArgs args)
                {
                        using (node.Action.UndoManager.AtomicChange) {

Modified: trunk/stetic/libstetic/editor/ActionToolItem.cs
===================================================================
--- trunk/stetic/libstetic/editor/ActionToolItem.cs     2006-12-17 11:41:14 UTC 
(rev 69597)
+++ trunk/stetic/libstetic/editor/ActionToolItem.cs     2006-12-17 12:46:05 UTC 
(rev 69598)
@@ -98,6 +98,13 @@
                        GrabFocus ();
                }
                
+               public bool IsSelected {
+                       get {
+                               IDesignArea area = GetDesignArea ();
+                               return area.IsSelected (this);
+                       }
+               }
+               
                public void Copy ()
                {
                }
@@ -251,8 +258,10 @@
                        
                        Gtk.Entry entry = ob as Gtk.Entry;
                        if (entry.Text.Length > 0 || 
node.Action.GtkAction.StockId != null) {
-                               node.Action.GtkAction.Label = entry.Text;
-                               node.Action.NotifyChanged ();
+                               using (node.Action.UndoManager.AtomicChange) {
+                                       node.Action.GtkAction.Label = 
entry.Text;
+                                       node.Action.NotifyChanged ();
+                               }
                        }
                        localUpdate = false;
                }
@@ -323,32 +332,42 @@
                
                void OnSetToggleType (object ob, EventArgs args)
                {
-                       node.Action.Type = Action.ActionType.Toggle;
-                       node.Action.NotifyChanged ();
+                       using (node.Action.UndoManager.AtomicChange) {
+                               node.Action.Type = Action.ActionType.Toggle;
+                               node.Action.NotifyChanged ();
+                       }
                }
                
                void OnSetRadioType (object ob, EventArgs args)
                {
-                       node.Action.Type = Action.ActionType.Radio;
-                       node.Action.NotifyChanged ();
+                       using (node.Action.UndoManager.AtomicChange) {
+                               node.Action.Type = Action.ActionType.Radio;
+                               node.Action.NotifyChanged ();
+                       }
                }
                
                void OnSetActionType (object ob, EventArgs args)
                {
-                       node.Action.Type = Action.ActionType.Action;
-                       node.Action.NotifyChanged ();
+                       using (node.Action.UndoManager.AtomicChange) {
+                               node.Action.Type = Action.ActionType.Action;
+                               node.Action.NotifyChanged ();
+                       }
                }
                
                void OnStockSelected (object s, IconEventArgs args)
                {
-                       node.Action.GtkAction.StockId = args.IconId;
-                       node.Action.NotifyChanged ();
+                       using (node.Action.UndoManager.AtomicChange) {
+                               node.Action.GtkAction.StockId = args.IconId;
+                               node.Action.NotifyChanged ();
+                       }
                }
                
                void OnClearIcon (object on, EventArgs args)
                {
-                       node.Action.GtkAction.StockId = null;
-                       node.Action.NotifyChanged ();
+                       using (node.Action.UndoManager.AtomicChange) {
+                               node.Action.GtkAction.StockId = null;
+                               node.Action.NotifyChanged ();
+                       }
                }
                
                public void Refresh ()

Modified: trunk/stetic/libstetic/editor/ActionToolbar.cs
===================================================================
--- trunk/stetic/libstetic/editor/ActionToolbar.cs      2006-12-17 11:41:14 UTC 
(rev 69597)
+++ trunk/stetic/libstetic/editor/ActionToolbar.cs      2006-12-17 12:46:05 UTC 
(rev 69598)
@@ -212,15 +212,21 @@
                void InsertAction (int pos)
                {
                        Widget wrapper = Widget.Lookup (this);
-                       Action ac = (Action) ObjectWrapper.Create 
(wrapper.Project, new Gtk.Action ("", "", null, null));
-                       ActionTreeNode node = new ActionTreeNode 
(Gtk.UIManagerItemType.Toolitem, "", ac);
-                       actionTree.Children.Insert (pos, node);
+                       using (wrapper.UndoManager.AtomicChange) {
+                               Action ac = (Action) ObjectWrapper.Create 
(wrapper.Project, new Gtk.Action ("", "", null, null));
+                               ActionTreeNode node = new ActionTreeNode 
(Gtk.UIManagerItemType.Toolitem, "", ac);
+                               actionTree.Children.Insert (pos, node);
 
-                       ActionToolItem aitem = FindMenuItem (node);
-                       aitem.EditingDone += OnEditingDone;
-                       aitem.Select ();
-                       aitem.StartEditing (false);
-                       //ShowInsertPlaceholder = false;
+                               ActionToolItem aitem = FindMenuItem (node);
+                               aitem.EditingDone += OnEditingDone;
+                               aitem.Select ();
+                               aitem.StartEditing (false);
+                               //ShowInsertPlaceholder = false;
+
+                               if (wrapper.LocalActionGroups.Count == 0)
+                                       wrapper.LocalActionGroups.Add (new 
ActionGroup ("Default"));
+                               wrapper.LocalActionGroups[0].Actions.Add (ac);
+                       }
                }
                
                void OnEditingDone (object ob, EventArgs args)
@@ -235,11 +241,10 @@
                        
                        if (item.Node.Action.GtkAction.Label.Length == 0 && 
item.Node.Action.GtkAction.StockId == null) {
                                area.ResetSelection (item);
-                               actionTree.Children.Remove (item.Node);
-                       } else {
-                               if (wrapper.LocalActionGroups.Count == 0)
-                                       wrapper.LocalActionGroups.Add (new 
ActionGroup ("Default"));
-                               wrapper.LocalActionGroups[0].Actions.Add 
(item.Node.Action);
+                               using (wrapper.UndoManager.AtomicChange) {
+                                       actionTree.Children.Remove (item.Node);
+                                       wrapper.LocalActionGroups 
[0].Actions.Remove (item.Node.Action);
+                               }
                        }
                }
                
@@ -326,26 +331,28 @@
                                newNode.Type = Gtk.UIManagerItemType.Toolitem;
                        }
 
-                       if (dropIndex < actionTree.Children.Count) {
-                               // Do nothing if trying to drop the node over 
the same node
-                               ActionTreeNode dropNode = actionTree.Children 
[dropIndex];
-                               if (dropNode == newNode)
-                                       return false;
+                       Widget wrapper = Widget.Lookup (this);
+                       using (wrapper.UndoManager.AtomicChange) {
+                               if (dropIndex < actionTree.Children.Count) {
+                                       // Do nothing if trying to drop the 
node over the same node
+                                       ActionTreeNode dropNode = 
actionTree.Children [dropIndex];
+                                       if (dropNode == newNode)
+                                               return false;
+                                               
+                                       if (newNode.ParentNode != null)
+                                               
newNode.ParentNode.Children.Remove (newNode);
                                        
-                               if (newNode.ParentNode != null)
-                                       newNode.ParentNode.Children.Remove 
(newNode);
-                               
-                               // The drop position may have changed after 
removing the dropped node,
-                               // so get it again.
-                               dropIndex = actionTree.Children.IndexOf 
(dropNode);
-                               actionTree.Children.Insert (dropIndex, newNode);
-                       } else {
-                               if (newNode.ParentNode != null)
-                                       newNode.ParentNode.Children.Remove 
(newNode);
-                               actionTree.Children.Add (newNode);
-                               dropIndex = actionTree.Children.Count - 1;
+                                       // The drop position may have changed 
after removing the dropped node,
+                                       // so get it again.
+                                       dropIndex = actionTree.Children.IndexOf 
(dropNode);
+                                       actionTree.Children.Insert (dropIndex, 
newNode);
+                               } else {
+                                       if (newNode.ParentNode != null)
+                                               
newNode.ParentNode.Children.Remove (newNode);
+                                       actionTree.Children.Add (newNode);
+                                       dropIndex = actionTree.Children.Count - 
1;
+                               }
                        }
-                       
                        // Select the dropped node
                        ActionToolItem mi = (ActionToolItem) toolItems 
[dropIndex];
                        mi.Select ();
@@ -455,6 +462,23 @@
                        m.Popup ();
                }
                
+               public object SaveStatus ()
+               {
+                       for (int n=0; n<toolItems.Count; n++)
+                               if (((ActionToolItem)toolItems[n]).IsSelected)
+                                       return n;
+                       return null;
+               }
+               
+               public void RestoreStatus (object stat)
+               {
+                       if (stat == null)
+                               return;
+                       int n = (int) stat;
+                       if (n < toolItems.Count)
+                               ((ActionToolItem)toolItems[n]).Select ();
+               }
+               
                ActionToolItem LocateWidget (int x, int y)
                {
                        foreach (ActionToolItem mi in toolItems) {

Modified: trunk/stetic/libstetic/undo/ActionDiffAdaptor.cs
===================================================================
--- trunk/stetic/libstetic/undo/ActionDiffAdaptor.cs    2006-12-17 11:41:14 UTC 
(rev 69597)
+++ trunk/stetic/libstetic/undo/ActionDiffAdaptor.cs    2006-12-17 12:46:05 UTC 
(rev 69598)
@@ -18,13 +18,18 @@
                public IEnumerable GetChildren (object parent)
                {
                        if (parent is Action)
-                               return Type.EmptyTypes;
-                       if (parent is ActionGroup)
-                               return ((ActionGroup)parent).Actions;
-                       if (parent is ActionGroupCollection)
-                               return (ActionGroupCollection) parent;
-
-                       throw new NotImplementedException ();
+                               yield break;
+                       else if (parent is ActionGroup) {
+                               foreach (Action ac in 
((ActionGroup)parent).Actions)
+                                       if (ac.Name.Length > 0)
+                                               yield return ac;
+                       }
+                       else if (parent is ActionGroupCollection) {
+                               foreach (ActionGroup ag in 
(ActionGroupCollection) parent)
+                                       yield return ag;
+                       }
+                       else
+                               throw new NotImplementedException ();
                }
                
                public string GetUndoId (object childObject)
@@ -40,14 +45,19 @@
                public object FindChild (object parent, string undoId)
                {
                        foreach (object ob in GetChildren (parent))
-                               if (GetUndoId (ob) == undoId)
+                               if (GetUndoId (ob) == undoId) {
+                                       if ((ob is Action) && 
((Action)ob).Name.Length == 0)
+                                               continue;
                                        return ob;
+                               }
                        return null;
                }
                
                public void RemoveChild (object parent, string undoId)
                {
                        object child = FindChild (parent, undoId);
+                       if (child == null)
+                               return;
                        if (parent is ActionGroup) {
                                ((ActionGroup)parent).Actions.Remove 
((Action)child);
                        } else if (parent is ActionGroupCollection) {
@@ -97,7 +107,7 @@
                                        foreach (ItemDescriptor it in iset) {
                                                PropertyDescriptor prop = it as 
PropertyDescriptor;
                                                
-                                               if (!prop.VisibleFor 
(action.Wrapped) || !prop.CanWrite || prop.Name == "Name")
+                                               if (!prop.VisibleFor 
(action.Wrapped) || !prop.CanWrite)
                                                        continue;
 
                                                object value = prop.GetValue 
(action.Wrapped);
@@ -110,6 +120,8 @@
                                        }
                                }
                        }
+                       else if (obj is ActionGroup)
+                               yield return "name";    // ActionGroup only has 
one property, the name
                        else
                                yield break;
                }
@@ -148,33 +160,69 @@
                
                public object GetPropertyByName (object obj, string name)
                {
-                       return ((Action)obj).ClassDescriptor [name];
+                       if (obj is Action) {
+                               if (name == "id") name = "Name";
+                               return ((Action)obj).ClassDescriptor [name];
+                       }
+                       else if (obj is ActionGroup) {
+                               if (name == "name") return name;
+                       }
+                       throw new NotImplementedException ();
                }
                
                public string GetPropertyName (object property)
                {
-                       return ((PropertyDescriptor)property).Name;
+                       if (property is PropertyDescriptor) {
+                               PropertyDescriptor prop = (PropertyDescriptor) 
property;
+                               if (prop.Name == "Name") return "id";
+                               return prop.Name;
+                       }
+                       else if (property is string)
+                               return (string) property;
+
+                       throw new NotImplementedException ();
                }
                
                public string GetPropertyValue (object obj, object property)
                {
-                       PropertyDescriptor prop = (PropertyDescriptor) property;
-                       object val = prop.GetValue (((Action)obj).Wrapped);
-                       return prop.ValueToString (val);
+                       if (obj is Action) {
+                               PropertyDescriptor prop = (PropertyDescriptor) 
property;
+                               object val = prop.GetValue 
(((Action)obj).Wrapped);
+                               return prop.ValueToString (val);
+                       }
+                       else if (obj is ActionGroup) {
+                               if (((string)property) == "name")
+                                       return ((ActionGroup)obj).Name;
+                       }
+                       throw new NotImplementedException ();
                }
                
                public void SetPropertyValue (object obj, string name, string 
value)
                {
-                       PropertyDescriptor prop = (PropertyDescriptor) 
GetPropertyByName (obj, name);
-                       if (prop == null)
-                               throw new InvalidOperationException ("Property 
'" + name + "' not found in object of type: " + obj.GetType ());
-                       prop.SetValue (((Action)obj).Wrapped, 
prop.StringToValue (value));
+                       if (obj is Action) {
+                               if (name == "id") name = "Name";
+                               PropertyDescriptor prop = (PropertyDescriptor) 
GetPropertyByName (obj, name);
+                               if (prop == null)
+                                       throw new InvalidOperationException 
("Property '" + name + "' not found in object of type: " + obj.GetType ());
+                               prop.SetValue (((Action)obj).Wrapped, 
prop.StringToValue (value));
+                               return;
+                       }
+                       else if (obj is ActionGroup) {
+                               if (name == "name") {
+                                       ((ActionGroup)obj).Name = value;
+                                       return;
+                               }
+                       }
+                       throw new NotImplementedException ();
                }
 
                public void ResetPropertyValue (object obj, string name)
                {
-                       PropertyDescriptor prop = (PropertyDescriptor) 
GetPropertyByName (obj, name);
-                       prop.ResetValue (((Action)obj).Wrapped);
+                       if (obj is Action) {
+                               if (name == "id") name = "Name";
+                               PropertyDescriptor prop = (PropertyDescriptor) 
GetPropertyByName (obj, name);
+                               prop.ResetValue (((Action)obj).Wrapped);
+                       }
                }
                
                public IEnumerable GetSignals (object obj)

Modified: trunk/stetic/libstetic/undo/DiffGenerator.cs
===================================================================
--- trunk/stetic/libstetic/undo/DiffGenerator.cs        2006-12-17 11:41:14 UTC 
(rev 69597)
+++ trunk/stetic/libstetic/undo/DiffGenerator.cs        2006-12-17 12:46:05 UTC 
(rev 69598)
@@ -61,8 +61,9 @@
                                                cdiff.Operation = 
DiffOperation.Remove;
                                                changes.Add (cdiff);
                                        }
-                               } else
+                               } else {
                                        throw new InvalidOperationException 
("Found an element without ID");
+                               }
                        }
                        
                        // Register new elements
@@ -189,6 +190,7 @@
                                        object newProp = newObject != null ? 
newAdaptor.GetSignal (newObject, name, handler) : null;
                                        if (newProp == null)
                                                changes.Add (new PropertyDiff 
(DiffOperation.Remove, name, handler));
+                                       found [name + " " + handler] = found;
                                }
                        }
                        

Modified: trunk/stetic/libstetic/undo/UndoManager.cs
===================================================================
--- trunk/stetic/libstetic/undo/UndoManager.cs  2006-12-17 11:41:14 UTC (rev 
69597)
+++ trunk/stetic/libstetic/undo/UndoManager.cs  2006-12-17 12:46:05 UTC (rev 
69598)
@@ -265,7 +265,6 @@
                public void Delay ()
                {
                        delayed = true;
-                       Console.WriteLine ("Delay");
                }
 
                public void Dispose ()
@@ -287,8 +286,6 @@
                                ChangeEventPending.Clear ();
                                Count = 0;
                                
-                               Console.WriteLine ("Delayed: " + delayed);
-
                                if (!delayed)
                                        undoManager.NotifyUndoCheckpoint (obs);
                                delayed = false;

Modified: trunk/stetic/libstetic/undo/XmlDiffAdaptor.cs
===================================================================
--- trunk/stetic/libstetic/undo/XmlDiffAdaptor.cs       2006-12-17 11:41:14 UTC 
(rev 69597)
+++ trunk/stetic/libstetic/undo/XmlDiffAdaptor.cs       2006-12-17 12:46:05 UTC 
(rev 69598)
@@ -107,37 +107,58 @@
                public IEnumerable GetProperties (object obj)
                {
                        XmlElement elem = GetPropsElem (obj);
-                       if (elem != null && processProperties)
-                               return elem.SelectNodes ("property");
-                       else
-                               return Type.EmptyTypes;
+                       if (elem != null && processProperties) {
+                               XmlAttribute at = elem.Attributes ["name"];
+                               if (at != null)
+                                       yield return at;
+                               at = elem.Attributes ["id"];
+                               if (at != null)
+                                       yield return at;
+                               foreach (XmlElement e in elem.SelectNodes 
("property"))
+                                       yield return e;
+                       } else
+                               yield break;
                }
                
                public object GetPropertyByName (object obj, string name)
                {
-                       return GetPropsElem (obj).SelectSingleNode ("[EMAIL 
PROTECTED]'" + name + "']");
+                       XmlElement elem = GetPropsElem (obj);
+                       XmlElement prop = (XmlElement) elem.SelectSingleNode 
("[EMAIL PROTECTED]'" + name + "']");
+                       if (prop != null)
+                               return prop;
+                       return elem.Attributes [name];
                }
                
                public string GetPropertyName (object property)
                {
-                       return ((XmlElement)property).GetAttribute ("name");
+                       if (property is XmlElement)
+                               return ((XmlElement)property).GetAttribute 
("name");
+                       else
+                               return ((XmlAttribute)property).LocalName;
                }
                
                public string GetPropertyValue (object obj, object property)
                {
-                       return ((XmlElement)property).InnerText;
+                       if (property is XmlElement)
+                               return ((XmlElement)property).InnerText;
+                       else
+                               return ((XmlAttribute)property).Value;
                }
                
                public void SetPropertyValue (object obj, string name, string 
value)
                {
                        XmlElement elem = GetPropsElem (obj);
-                       XmlElement prop = (XmlElement) elem.SelectSingleNode 
("[EMAIL PROTECTED]'" + name + "']");
-                       if (prop == null) {
-                               prop = elem.OwnerDocument.CreateElement 
("property");
-                               prop.SetAttribute ("name", name);
-                               elem.AppendChild (prop);
+                       if (name == "id" || name == "name") {
+                               elem.SetAttribute (name, value);
+                       } else {
+                               XmlElement prop = (XmlElement) 
elem.SelectSingleNode ("[EMAIL PROTECTED]'" + name + "']");
+                               if (prop == null) {
+                                       prop = elem.OwnerDocument.CreateElement 
("property");
+                                       prop.SetAttribute ("name", name);
+                                       elem.AppendChild (prop);
+                               }
+                               prop.InnerText = value;
                        }
-                       prop.InnerText = value;
                }
                
                public void ResetPropertyValue (object obj, string name)
@@ -146,6 +167,11 @@
                        XmlElement prop = (XmlElement) elem.SelectSingleNode 
("[EMAIL PROTECTED]'" + name + "']");
                        if (prop != null)
                                elem.RemoveChild (prop);
+                       else {
+                               XmlAttribute at = elem.Attributes [name];
+                               if (at != null)
+                                       elem.Attributes.Remove (at);
+                       }
                }
                
                public IEnumerable GetSignals (object obj)
@@ -159,7 +185,7 @@
                
                public object GetSignal (object obj, string name, string 
handler)
                {
-                       return GetPropsElem (obj).SelectSingleNode ("[EMAIL 
PROTECTED]'" + name + "' && @handler='" + handler + "']");
+                       return GetPropsElem (obj).SelectSingleNode ("[EMAIL 
PROTECTED]'" + name + "' and @handler='" + handler + "']");
                }
                
                public void GetSignalInfo (object signal, out string name, out 
string handler)

Modified: trunk/stetic/libstetic/wrapper/Action.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Action.cs    2006-12-17 11:41:14 UTC (rev 
69597)
+++ trunk/stetic/libstetic/wrapper/Action.cs    2006-12-17 12:46:05 UTC (rev 
69598)
@@ -81,7 +81,7 @@
                                string s = GtkAction.StockId.Replace ("gtk-", 
"");
                                return GetIdentifier (s.Replace 
("gnome-stock-", ""));
                        }
-                       return null;
+                       return "";
                }
                
                public ActionType Type {
@@ -187,7 +187,10 @@
                        
                        WidgetUtils.ReadMembers (klass, this, ac, elem);
                        name = nameRoot = oldDefaultName = elem.GetAttribute 
("id");
-                       undoId = elem.GetAttribute ("undoId");
+                       
+                       string uid = elem.GetAttribute ("undoId");
+                       if (uid.Length > 0)
+                               undoId = uid;
                }
                
                public Action Clone ()

Modified: trunk/stetic/libstetic/wrapper/ActionGroup.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/ActionGroup.cs       2006-12-17 11:41:14 UTC 
(rev 69597)
+++ trunk/stetic/libstetic/wrapper/ActionGroup.cs       2006-12-17 12:46:05 UTC 
(rev 69598)
@@ -104,15 +104,19 @@
                        group.SetAttribute ("name", name);
                        if (writer.CreateUndoInfo)
                                group.SetAttribute ("undoId", undoId);
-                       foreach (Action ac in actions)
-                               group.AppendChild (ac.Write (writer));
+                       foreach (Action ac in actions) {
+                               if (ac.Name.Length > 0)
+                                       group.AppendChild (ac.Write (writer));
+                       }
                        return group;
                }
                
                public void Read (IProject project, XmlElement elem)
                {
                        name = elem.GetAttribute ("name");
-                       undoId = elem.GetAttribute ("undoId");
+                       string uid = elem.GetAttribute ("undoId");
+                       if (uid.Length > 0)
+                               undoId = uid;
                        foreach (XmlElement child in elem.SelectNodes 
("action")) {
                                Action ac = new Action ();
                                ac.Read (project, child);

Modified: trunk/stetic/libstetic/wrapper/ActionToolbarWrapper.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/ActionToolbarWrapper.cs      2006-12-17 
11:41:14 UTC (rev 69597)
+++ trunk/stetic/libstetic/wrapper/ActionToolbarWrapper.cs      2006-12-17 
12:46:05 UTC (rev 69598)
@@ -12,6 +12,7 @@
                ActionTree actionTree;
                XmlElement toolbarInfo;
                ToolbarStyle toolbarStyle;
+               bool treeChanged;
                static Gtk.ToolbarStyle defaultStyle;
                static bool gotDefault;
                
@@ -189,6 +190,77 @@
                        toolbar.FillMenu (actionTree);
                }
                
+               public override object GetUndoDiff ()
+               {
+                       XmlElement oldElem = treeChanged ? 
UndoManager.GetObjectStatus (this) ["node"] : null;
+                       if (oldElem != null)
+                               oldElem = (XmlElement) oldElem.CloneNode (true);
+                               
+                       treeChanged = false;
+                       object baseDiff = base.GetUndoDiff ();
+                       
+                       if (oldElem != null) {
+                               XmlElement newElem = 
UndoManager.GetObjectStatus (this) ["node"];
+                               if (newElem != null && oldElem.OuterXml == 
newElem.OuterXml)
+                                       oldElem = null;
+                       }
+                       
+                       if (baseDiff == null && oldElem == null)
+                               return null;
+                       else {
+                               object stat = toolbar.SaveStatus ();
+                               return new object[] { baseDiff, oldElem, stat };
+                       }
+               }
+               
+               public override object ApplyUndoRedoDiff (object diff)
+               {
+                       object[] data = (object[]) diff;
+                       object retBaseDiff;
+                       XmlElement oldNode = null;
+                       
+                       if (actionTree != null) {
+                               XmlElement status = UndoManager.GetObjectStatus 
(this);
+                               oldNode = status ["node"];
+                               if (oldNode != null)
+                                       oldNode = (XmlElement) 
oldNode.CloneNode (true);
+                       }
+                       object oldStat = toolbar.SaveStatus ();
+                       
+                       if (data [0] != null)
+                               retBaseDiff = base.ApplyUndoRedoDiff (data [0]);
+                       else
+                               retBaseDiff = null;
+                               
+                       XmlElement xdiff = (XmlElement) data [1];
+
+                       if (xdiff != null) {
+                               XmlElement status = UndoManager.GetObjectStatus 
(this);
+                               XmlElement prevNode = status ["node"];
+                               if (prevNode != null)
+                                       status.RemoveChild (prevNode);
+                               status.AppendChild (xdiff);
+                               
+                               if (actionTree != null) {
+                                       Loading = true;
+                                       DisposeTree ();
+                                       CreateTree ();
+                                       actionTree.Read (this, xdiff);
+                                       toolbar.FillMenu (actionTree);
+                                       Loading = false;
+                               }
+                       }
+                       
+                       // Restore the status after all menu structure has been 
properly built
+                       GLib.Timeout.Add (50, delegate {
+                               toolbar.RestoreStatus (data[2]);
+                               return false;
+                       });
+                       
+                       return new object [] { retBaseDiff, oldNode, oldStat };
+               }
+               
+               
                void BuildTree ()
                {
                        if (toolbarInfo != null) {
@@ -218,6 +290,7 @@
                
                void OnTreeChanged (object s, EventArgs a)
                {
+                       treeChanged = true;
                        NotifyChanged ();
                }
        }

Modified: trunk/stetic/libstetic/wrapper/ActionTree.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/ActionTree.cs        2006-12-17 11:41:14 UTC 
(rev 69597)
+++ trunk/stetic/libstetic/wrapper/ActionTree.cs        2006-12-17 12:46:05 UTC 
(rev 69598)
@@ -53,6 +53,7 @@
                ActionTreeNodeCollection children;
                ActionTreeNode parentNode;
                bool loading;
+               string lastActionName;
                
                public ActionTreeNode ()
                {
@@ -68,14 +69,19 @@
                        this.type = type;
                        this.name = name;
                        this.action = action;
-                       if (this.action != null)
+                       if (this.action != null) {
+                               lastActionName = this.action.Name;
                                this.action.Deleted += OnActionDeleted;
+                               this.action.ObjectChanged += OnActionChanged;
+                       }
                }
                
                public virtual void Dispose ()
                {
-                       if (action != null)
+                       if (action != null) {
                                action.Deleted -= OnActionDeleted;
+                               action.ObjectChanged -= OnActionChanged;
+                       }
                }
                
                void OnActionDeleted (object s, EventArgs args)
@@ -83,7 +89,19 @@
                        if (parentNode != null)
                                parentNode.Children.Remove (this);
                }
+               
+               void OnActionChanged (object s, ObjectWrapperEventArgs args)
+               {
+                       // If the name of the action changes, consider it a 
change in
+                       // the node, since the generated xml will be different
 
+                       Action ac = (Action) args.Wrapper;
+                       if (ac.Name != lastActionName) {
+                               lastActionName = ac.Name;
+                               NotifyChanged ();
+                       }
+               }
+
                internal virtual void NotifyChanged ()
                {
                        if (parentNode != null)
@@ -100,8 +118,11 @@
                                elem.SetAttribute ("action", action.Name);
                        
                        if (children != null) {
-                               foreach (ActionTreeNode child in children)
+                               foreach (ActionTreeNode child in children) {
+                                       if (child.Action != null && 
child.Action.Name.Length == 0)
+                                               continue;
                                        elem.AppendChild (child.Write (doc, 
format));
+                               }
                        }
                        return elem;
                }
@@ -112,8 +133,10 @@
                        if (elem.HasAttribute ("type"))
                                type = (Gtk.UIManagerItemType) Enum.Parse 
(typeof(Gtk.UIManagerItemType), elem.GetAttribute ("type"));
                        
-                       string aname = elem.GetAttribute ("action");
-                       if (aname.Length > 0) {
+                       // The name of an action may be empty in some 
situations (e.g. when adding a new action but before entering the name)
+                       XmlAttribute actionAt = elem.Attributes ["action"];
+                       if (actionAt != null) {
+                               string aname = actionAt.Value;
                                foreach (ActionGroup grp in 
baseWidget.LocalActionGroups) {
                                        action = grp.GetAction (aname);
                                        if (action != null)
@@ -126,8 +149,11 @@
                                                        break;
                                        }
                                }
-                               if (action != null)
+                               if (action != null) {
+                                       lastActionName = action.Name;
                                        action.Deleted += OnActionDeleted;
+                                       action.ObjectChanged += OnActionChanged;
+                               }
                        }
                        
                        try {

Modified: trunk/stetic/libstetic/wrapper/Container.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Container.cs 2006-12-17 11:41:14 UTC (rev 
69597)
+++ trunk/stetic/libstetic/wrapper/Container.cs 2006-12-17 12:46:05 UTC (rev 
69598)
@@ -165,7 +165,7 @@
                        // If there are child changes there is no need to look 
for changes in the
                        // actions, since the whole widget will be read again
                        
-                       if (objectDiff == null || objectDiff.ChildChanges == 
null)
+                       if (IsTopLevel && (objectDiff == null || 
objectDiff.ChildChanges == null))
                                actionsDiff = LocalActionGroups.GetDiff 
(Project, oldElem);
                        
                        // The undo writer skips children which are already 
registered in the undo manager
@@ -595,6 +595,8 @@
 
                public static Container LookupParent (Gtk.Widget widget)
                {
+                       if (widget == null)
+                               return null;
                        Gtk.Widget parent = widget.Parent;
                        Container wrapper = null;
                        while ((wrapper == null || wrapper.Unselectable) && 
parent != null) {
@@ -1136,6 +1138,31 @@
                        return null;
                }
                
+               public Widget FindChildByUndoId (string id)
+               {
+                       if (UndoId == id)
+                               return this;
+                       else
+                               return Widget.Lookup (FindChildByUndoId 
((Gtk.Container)Wrapped, id));
+               }
+               
+               Gtk.Widget FindChildByUndoId (Gtk.Container parent, string id)
+               {
+                       foreach (Gtk.Widget w in parent.AllChildren) {
+                               Widget ww = Widget.Lookup (w);
+                               if (ww == null)
+                                       continue;
+                               if (ww.UndoId == id)
+                                       return w;
+                               if (w is Gtk.Container) {
+                                       Gtk.Widget res = FindChildByUndoId 
((Gtk.Container)w, id);
+                                       if (res != null)
+                                               return res;
+                               }
+                       }
+                       return null;
+               }
+               
                public class ContainerChild : Stetic.ObjectWrapper
                {
                        // This id is used by the undo methods to identify a 
child of a container.

Modified: trunk/stetic/libstetic/wrapper/MenuBar.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/MenuBar.cs   2006-12-17 11:41:14 UTC (rev 
69597)
+++ trunk/stetic/libstetic/wrapper/MenuBar.cs   2006-12-17 12:46:05 UTC (rev 
69598)
@@ -78,20 +78,39 @@
                public override object GetUndoDiff ()
                {
                        XmlElement oldElem = treeChanged ? 
UndoManager.GetObjectStatus (this) ["node"] : null;
+                       if (oldElem != null)
+                               oldElem = (XmlElement) oldElem.CloneNode (true);
+
                        treeChanged = false;
                        object baseDiff = base.GetUndoDiff ();
+                       
+                       if (oldElem != null) {
+                               XmlElement newElem = 
UndoManager.GetObjectStatus (this) ["node"];
+                               if (newElem != null && oldElem.OuterXml == 
newElem.OuterXml)
+                                       oldElem = null;
+                       }
+                       
                        if (baseDiff == null && oldElem == null)
                                return null;
-                       else
-                               return new object[] { baseDiff, oldElem };
+                       else {
+                               object stat = menu.SaveStatus ();
+                               return new object[] { baseDiff, oldElem, stat };
+                       }
                }
                
                public override object ApplyUndoRedoDiff (object diff)
                {
                        object[] data = (object[]) diff;
                        object retBaseDiff;
+                       XmlElement oldNode = null;
                        
-                       object stat = menu.SaveStatus ();
+                       if (actionTree != null) {
+                               XmlElement status = UndoManager.GetObjectStatus 
(this);
+                               oldNode = status ["node"];
+                               if (oldNode != null)
+                                       oldNode = (XmlElement) 
oldNode.CloneNode (true);
+                       }
+                       object oldStat = menu.SaveStatus ();
                        
                        if (data [0] != null)
                                retBaseDiff = base.ApplyUndoRedoDiff (data [0]);
@@ -99,27 +118,33 @@
                                retBaseDiff = null;
                                
                        XmlElement xdiff = (XmlElement) data [1];
-                       Console.WriteLine ("DD:" + xdiff.OuterXml);
-                       XmlElement status = UndoManager.GetObjectStatus (this);
-                       XmlElement oldNode = status ["node"];
-                       if (oldNode != null)
-                               status.RemoveChild (oldNode);
-                       status.AppendChild (xdiff);
+
+                       if (xdiff != null) {
+                               XmlElement status = UndoManager.GetObjectStatus 
(this);
+                               XmlElement prevNode = status ["node"];
+                               if (prevNode != null)
+                                       status.RemoveChild (prevNode);
+                               status.AppendChild (xdiff);
+                               
+                               if (actionTree != null) {
+                                       Loading = true;
+                                       menu.OpenSubmenu = null;
+                                       DisposeTree ();
+                                       CreateTree ();
+                                       actionTree.Read (this, xdiff);
+                                       menu.FillMenu (actionTree);
+                                       Loading = false;
+                               } else
+                                       menuInfo = xdiff;
+                       }
                        
-                       if (actionTree != null) {
-                               Loading = true;
-                               menu.OpenSubmenu = null;
-                               DisposeTree ();
-                               CreateTree ();
-                               actionTree.Read (this, xdiff);
-                               menu.FillMenu (actionTree);
-                               Loading = false;
-                       } else
-                               menuInfo = xdiff;
+                       // Restore the status after all menu structure has been 
properly built
+                       GLib.Timeout.Add (50, delegate {
+                               menu.RestoreStatus (data[2]);
+                               return false;
+                       });
                        
-                       menu.RestoreStatus (stat);
-                       
-                       return new object [] { retBaseDiff, oldNode };
+                       return new object [] { retBaseDiff, oldNode, oldStat };
                }
                
                protected override void OnNameChanged (WidgetNameChangedArgs 
args)

Modified: trunk/stetic/libstetic/wrapper/Widget.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Widget.cs    2006-12-17 11:41:14 UTC (rev 
69597)
+++ trunk/stetic/libstetic/wrapper/Widget.cs    2006-12-17 12:46:05 UTC (rev 
69598)
@@ -10,6 +10,9 @@
        {
                static DiffGenerator propDiffGenerator;
                
+               // This id is used by the undo methods to identify an object 
(even if it's name changes)
+               string undoId = WidgetUtils.GetUndoId ();
+               
                string oldName;
                string oldMemberName;
                internal bool settingFocus;
@@ -107,6 +110,11 @@
                        base.Dispose ();
                }
                
+               public string UndoId {
+                       get { return undoId; }
+                       internal set { undoId = value; }
+               }
+               
                void OnFocusIn (object s, Gtk.FocusInEventArgs a)
                {
                        if (settingFocus)
@@ -442,6 +450,7 @@
                                        actionGroup.Read (Project, groupElem);
                                        if (actionGroups == null) {
                                                actionGroups = new 
ActionGroupCollection ();
+                                               actionGroups.SetOwner (this);
                                                actionGroups.ActionGroupAdded 
+= OnGroupAdded;
                                                actionGroups.ActionGroupRemoved 
+= OnGroupRemoved;
                                                actionGroups.ActionGroupChanged 
+= OnGroupChanged;
@@ -463,6 +472,10 @@
                                WidgetUtils.Read (this, elem);
                        else
                                GladeUtils.ImportWidget (this, elem);
+                       
+                       string uid = elem.GetAttribute ("undoId");
+                       if (uid.Length > 0)
+                               undoId = uid;
                }
                
                public override XmlElement Write (ObjectWriter writer)
@@ -475,7 +488,10 @@
                protected virtual XmlElement WriteProperties (ObjectWriter 
writer)
                {
                        if (writer.Format == FileFormat.Native) {
-                               return WidgetUtils.Write (this, 
writer.XmlDocument);
+                               XmlElement elem = WidgetUtils.Write (this, 
writer.XmlDocument);
+                               if (writer.CreateUndoInfo)
+                                       elem.SetAttribute ("undoId", undoId);
+                               return elem;
                        }
                        else {
                                XmlElement elem = GladeUtils.ExportWidget 
(this, writer.XmlDocument);

Modified: trunk/stetic/libstetic/wrapper/objects.xml
===================================================================
--- trunk/stetic/libstetic/wrapper/objects.xml  2006-12-17 11:41:14 UTC (rev 
69597)
+++ trunk/stetic/libstetic/wrapper/objects.xml  2006-12-17 12:46:05 UTC (rev 
69598)
@@ -17,7 +17,7 @@
                <property name="CanDefault" />
                <property name="HasDefault" glade-override="true" />
                <property name="CanFocus" />
-               <property name="HasFocus" />
+<!--           <property name="HasFocus" /> -->
                <property name="Events" />
                <property name="ExtensionEvents" />
                <property name="Name" internal="true"

Modified: trunk/stetic/libsteticui/PaletteBackend.cs
===================================================================
--- trunk/stetic/libsteticui/PaletteBackend.cs  2006-12-17 11:41:14 UTC (rev 
69597)
+++ trunk/stetic/libsteticui/PaletteBackend.cs  2006-12-17 12:46:05 UTC (rev 
69598)
@@ -326,8 +326,10 @@
                                return false;
 
                        if (dropped.Node.Action.ActionGroup != group) {
-                               dropped.Node.Action.ActionGroup.Actions.Remove 
(dropped.Node.Action);
-                               group.Actions.Add (dropped.Node.Action);
+                               using 
(dropped.Node.Action.UndoManager.AtomicChange) {
+                                       
dropped.Node.Action.ActionGroup.Actions.Remove (dropped.Node.Action);
+                                       group.Actions.Add (dropped.Node.Action);
+                               }
                        }
 
                        return base.OnDragDrop (context, x,     y, time);

Modified: trunk/stetic/libsteticui/Project.cs
===================================================================
--- trunk/stetic/libsteticui/Project.cs 2006-12-17 11:41:14 UTC (rev 69597)
+++ trunk/stetic/libsteticui/Project.cs 2006-12-17 12:46:05 UTC (rev 69598)
@@ -28,6 +28,7 @@
                
                public event EventHandler ActionGroupsChanged;
                public event EventHandler ModifiedChanged;
+               public event EventHandler Changed;
                
                public event ComponentSignalEventHandler SignalAdded;
                public event ComponentSignalEventHandler SignalRemoved;
@@ -323,6 +324,16 @@
                        );
                }
                
+               internal void NotifyChanged ()
+               {
+                       Gtk.Application.Invoke (
+                               delegate {
+                                       if (Changed != null)
+                                               Changed (this, EventArgs.Empty);
+                               }
+                       );
+               }
+               
                internal void NotifyWidgetNameChanged (object obj, string 
oldName, string newName)
                {
                        Gtk.Application.Invoke (

Modified: trunk/stetic/libsteticui/ProjectBackend.cs
===================================================================
--- trunk/stetic/libsteticui/ProjectBackend.cs  2006-12-17 11:41:14 UTC (rev 
69597)
+++ trunk/stetic/libsteticui/ProjectBackend.cs  2006-12-17 12:46:05 UTC (rev 
69598)
@@ -39,6 +39,7 @@
                
                public event Wrapper.WidgetEventHandler SelectionChanged;
                public event EventHandler ModifiedChanged;
+               public event EventHandler Changed;
                
                // Fired when the project has been reloaded, due for example to
                // a change in the registry
@@ -536,7 +537,7 @@
                void OnObjectChanged (object sender, ObjectWrapperEventArgs 
args)
                {
                        if (!Syncing) {
-                               Modified = true;
+                               NotifyChanged ();
                                if (ObjectChanged != null)
                                        ObjectChanged (this, args);
                        }
@@ -545,7 +546,7 @@
                void OnWidgetNameChanged (object sender, 
Stetic.Wrapper.WidgetNameChangedArgs args)
                {
                        if (!Syncing) {
-                               Modified = true;
+                               NotifyChanged ();
                                OnWidgetNameChanged (args);
                        }
                }
@@ -561,7 +562,7 @@
                void OnWidgetMemberNameChanged (object sender, 
Stetic.Wrapper.WidgetNameChangedArgs args)
                {
                        if (!Syncing) {
-                               Modified = true;
+                               NotifyChanged ();
                                OnWidgetMemberNameChanged (args);
                        }
                }
@@ -647,7 +648,7 @@
                        while (i < children.Count)
                                AddWidget (children[i++] as Widget, node);
 
-                       Modified = true;
+                       NotifyChanged ();
                }
 
                public Gtk.Widget[] Toplevels {
@@ -769,6 +770,15 @@
                                frontend.NotifyActionGroupRemoved 
(args.ActionGroup.Name);
                }
                
+               void NotifyChanged ()
+               {
+                       Modified = true;
+                       if (frontend != null)
+                               frontend.NotifyChanged ();
+                       if (Changed != null)
+                               Changed (this, EventArgs.Empty);
+               }
+               
                protected virtual void OnModifiedChanged (EventArgs args)
                {
                        if (ModifiedChanged != null)
@@ -777,14 +787,14 @@
                
                protected virtual void OnWidgetRemoved 
(Stetic.Wrapper.WidgetEventArgs args)
                {
-                       Modified = true;
+                       NotifyChanged ();
                        if (WidgetRemoved != null)
                                WidgetRemoved (this, args);
                }
                
                protected virtual void OnWidgetAdded 
(Stetic.Wrapper.WidgetEventArgs args)
                {
-                       Modified = true;
+                       NotifyChanged ();
                        if (WidgetAdded != null)
                                WidgetAdded (this, args);
                }

Modified: trunk/stetic/libsteticui/UndoQueue.cs
===================================================================
--- trunk/stetic/libsteticui/UndoQueue.cs       2006-12-17 11:41:14 UTC (rev 
69597)
+++ trunk/stetic/libsteticui/UndoQueue.cs       2006-12-17 12:46:05 UTC (rev 
69598)
@@ -1,10 +1,11 @@
 
 using System;
+using System.Xml;
 using System.Collections;
 
 namespace Stetic
 {
-       public class UndoQueue
+       public class UndoQueue: MarshalByRefObject
        {
                ArrayList changeList = new ArrayList ();
                int undoListCount = 0;
@@ -176,10 +177,13 @@
                                if (diff == null)       // No differences
                                        continue;
                                
-//                             Console.WriteLine ("ADDCHANGE " + widget);
+//                             Console.WriteLine ("ADDCHANGE " + widget + " 
uid:" + widget.UndoId);
 //                             PrintPatch (diff);
                                
-                               ObjectWrapperUndoRedoChange change = new 
ObjectWrapperUndoRedoChange (this, widget.Wrapped.Name, diff);
+                               if (widget.UndoId == null || 
widget.UndoId.Length == 0)
+                                       throw new InvalidOperationException 
("Object of type '" + widget.GetType () + "' does not have an undo id.");
+
+                               ObjectWrapperUndoRedoChange change = new 
ObjectWrapperUndoRedoChange (this, widget.UndoId, diff);
                                if (lastChange == null)
                                        lastChange = firstChange = change;
                                else {
@@ -215,12 +219,12 @@
                        }
                }
                
-               ObjectWrapperUndoRedoChange ApplyDiff (string name, object diff)
+               ObjectWrapperUndoRedoChange ApplyDiff (string id, object diff)
                {
-//                     Console.WriteLine ("** APPLYING DIFF:");
+//                     Console.WriteLine ("** APPLYING DIFF: uid:" + id);
 //                     PrintPatch (diff);
                        
-                       Wrapper.Widget ww = rootObject.FindChild (name);
+                       Wrapper.Widget ww = rootObject.FindChildByUndoId (id);
                        
                        object reverseDiff = ww.ApplyUndoRedoDiff (diff);
                
@@ -228,7 +232,7 @@
 //                             Console.WriteLine ("** REVERSE DIFF:");
 //                             PrintPatch (reverseDiff);
                                
-                               ObjectWrapperUndoRedoChange change = new 
ObjectWrapperUndoRedoChange (this, name, reverseDiff);
+                               ObjectWrapperUndoRedoChange change = new 
ObjectWrapperUndoRedoChange (this, id, reverseDiff);
                                return change;
                        } else
                                return null;
@@ -251,7 +255,9 @@
                        if (diff is Array) {
                                foreach (object ob in (Array)diff)
                                        if (ob != null) PrintPatch (ob);
-                       } else
+                       } else if (diff is XmlElement)
+                               Console.WriteLine (((XmlElement)diff).OuterXml);
+                       else
                                Console.WriteLine (diff.ToString ());
                }
        }

Modified: trunk/stetic/libsteticui/WidgetDesigner.cs
===================================================================
--- trunk/stetic/libsteticui/WidgetDesigner.cs  2006-12-17 11:41:14 UTC (rev 
69597)
+++ trunk/stetic/libsteticui/WidgetDesigner.cs  2006-12-17 12:46:05 UTC (rev 
69598)
@@ -19,6 +19,7 @@
                
                public event EventHandler BindField;
                public event EventHandler ModifiedChanged;
+               public event EventHandler Changed;
                public event EventHandler SelectionChanged;
                public event EventHandler RootComponentChanged;
                public event ComponentSignalEventHandler SignalAdded;
@@ -256,6 +257,12 @@
                                ModifiedChanged (this, EventArgs.Empty);
                }
                
+               internal void NotifyChanged ()
+               {
+                       if (Changed != null)
+                               Changed (this, EventArgs.Empty);
+               }
+               
                internal void NotifySelectionChanged (object ob)
                {
                        if (ob != null)
@@ -291,6 +298,13 @@
                        );
                }
                
+               public void NotifyChanged ()
+               {
+                       Gtk.Application.Invoke (
+                               delegate { designer.NotifyChanged (); }
+                       );
+               }
+               
                internal void NotifySelectionChanged (object ob)
                {
                        Gtk.Application.Invoke (

Modified: trunk/stetic/libsteticui/WidgetEditSession.cs
===================================================================
--- trunk/stetic/libsteticui/WidgetEditSession.cs       2006-12-17 11:41:14 UTC 
(rev 69597)
+++ trunk/stetic/libsteticui/WidgetEditSession.cs       2006-12-17 12:46:05 UTC 
(rev 69598)
@@ -98,6 +98,7 @@
                        undoManager.RootObject = rootWidget;
                        
                        gproject.ModifiedChanged += new EventHandler 
(OnModifiedChanged);
+                       gproject.Changed += new EventHandler (OnChanged);
                        gproject.ProjectReloaded += new EventHandler 
(OnProjectReloaded);
 //                     gproject.WidgetMemberNameChanged += new 
Stetic.Wrapper.WidgetNameChangedHandler (OnWidgetNameChanged);
                }
@@ -239,6 +240,12 @@
                                frontend.NotifyModifiedChanged ();
                }
                
+               void OnChanged (object s, EventArgs a)
+               {
+                       if (frontend != null)
+                               frontend.NotifyChanged ();
+               }
+               
                void OnProjectReloaded (object s, EventArgs a)
                {
                        Gtk.Widget[] tops = gproject.Toplevels;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to