[mapguide-commits] r7077 - trunk/Tools/Maestro/Maestro.Editors/WebLayout

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Oct 4 07:27:02 PDT 2012


Author: jng
Date: 2012-10-04 07:27:01 -0700 (Thu, 04 Oct 2012)
New Revision: 7077

Modified:
   trunk/Tools/Maestro/Maestro.Editors/WebLayout/WebLayoutCommandsCtrl.cs
   trunk/Tools/Maestro/Maestro.Editors/WebLayout/WebLayoutMenusCtrl.cs
Log:
#2112: More Web Layout fixes

Modified: trunk/Tools/Maestro/Maestro.Editors/WebLayout/WebLayoutCommandsCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/WebLayout/WebLayoutCommandsCtrl.cs	2012-10-04 13:56:36 UTC (rev 7076)
+++ trunk/Tools/Maestro/Maestro.Editors/WebLayout/WebLayoutCommandsCtrl.cs	2012-10-04 14:27:01 UTC (rev 7077)
@@ -113,17 +113,19 @@
             var cmds = new List<ICommand>();
             foreach (DataGridViewRow row in grdCommands.SelectedRows)
             {
-                if (typeof(IInvokeScriptCommand).IsAssignableFrom(row.DataBoundItem.GetType()))
+                var dec = (CommandDecorator)row.DataBoundItem;
+                var cmd = dec.DecoratedInstance;
+                if (typeof(IInvokeScriptCommand).IsAssignableFrom(cmd.GetType()))
                 {
-                    cmds.Add((ICommand)row.DataBoundItem);
+                    cmds.Add(cmd);
                 }
-                else if (typeof(IInvokeUrlCommand).IsAssignableFrom(row.DataBoundItem.GetType()))
+                else if (typeof(IInvokeUrlCommand).IsAssignableFrom(cmd.GetType()))
                 {
-                    cmds.Add((ICommand)row.DataBoundItem);
+                    cmds.Add(cmd);
                 }
-                else if (typeof(ISearchCommand).IsAssignableFrom(row.DataBoundItem.GetType()))
+                else if (typeof(ISearchCommand).IsAssignableFrom(cmd.GetType()))
                 {
-                    cmds.Add((ICommand)row.DataBoundItem);
+                    cmds.Add(cmd);
                 }
             }
             return cmds.ToArray();
@@ -251,9 +253,9 @@
 
                         using (new WaitCursor(this))
                         {
+                            int deleted = _wl.RemoveAllReferences(iurl.Name);
                             _wl.CommandSet.RemoveCommand(iurl);
                             _commands.Remove(cmd);
-                            int deleted = _wl.RemoveAllReferences(iurl.Name);
                             ClearCommandUI();
                         }
                     }
@@ -267,9 +269,9 @@
 
                         using (new WaitCursor(this))
                         {
+                            _wl.RemoveAllReferences(iscr.Name);
                             _wl.CommandSet.RemoveCommand(iscr);
                             _commands.Remove(cmd);
-                            _wl.RemoveAllReferences(iscr.Name);
                             ClearCommandUI();
                         }
                     }
@@ -283,9 +285,9 @@
 
                         using (new WaitCursor(this))
                         {
+                            _wl.RemoveAllReferences(srch.Name);
                             _wl.CommandSet.RemoveCommand(srch);
                             _commands.Remove(cmd);
-                            _wl.RemoveAllReferences(srch.Name);
                             ClearCommandUI();
                         }
                     }

Modified: trunk/Tools/Maestro/Maestro.Editors/WebLayout/WebLayoutMenusCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/WebLayout/WebLayoutMenusCtrl.cs	2012-10-04 13:56:36 UTC (rev 7076)
+++ trunk/Tools/Maestro/Maestro.Editors/WebLayout/WebLayoutMenusCtrl.cs	2012-10-04 14:27:01 UTC (rev 7077)
@@ -42,7 +42,8 @@
         }
 
         private IWebLayout _wl;
-        private BindingList<ICommand> _cmds = new BindingList<ICommand>();
+        private BindingList<CommandDecorator> _cmds = new BindingList<CommandDecorator>();
+        private Dictionary<string, CommandDecorator> _cmdsByName = new Dictionary<string, CommandDecorator>();
 
         public override void Bind(IEditorService service)
         {
@@ -56,7 +57,9 @@
 
             foreach (var cmd in _wl.CommandSet.Commands)
             {
-                _cmds.Add(cmd);
+                var dec = new CommandDecorator(cmd);
+                _cmds.Add(dec);
+                _cmdsByName[dec.Name] = dec;
             }
             grdCommands.DataSource = _cmds;
         }
@@ -71,12 +74,19 @@
 
         void OnCommandRemoved(ICommand cmd)
         {
-            _cmds.Remove(cmd);
+            if (_cmdsByName.ContainsKey(cmd.Name))
+            {
+                var dec = _cmdsByName[cmd.Name];
+                _cmds.Remove(dec);
+                _cmdsByName.Remove(dec.Name);
+            }
         }
 
         void OnCommandAdded(ICommand cmd)
         {
-            _cmds.Add(cmd);
+            var dec = new CommandDecorator(cmd);
+            _cmds.Add(dec);
+            _cmdsByName[dec.Name] = dec;
         }
 
         private void grdCommands_DragLeave(object sender, EventArgs e)
@@ -89,12 +99,12 @@
 
         private ICommand GetSelectedCommand()
         {
-            ICommand cmd = null;
+            CommandDecorator cmd = null;
             if (grdCommands.SelectedRows.Count == 1)
-                cmd = grdCommands.SelectedRows[0].DataBoundItem as ICommand;
+                cmd = grdCommands.SelectedRows[0].DataBoundItem as CommandDecorator;
             else if (grdCommands.SelectedCells.Count == 1)
-                cmd = grdCommands.Rows[grdCommands.SelectedCells[0].RowIndex].DataBoundItem as ICommand;
-            return cmd;
+                cmd = grdCommands.Rows[grdCommands.SelectedCells[0].RowIndex].DataBoundItem as CommandDecorator;
+            return cmd.DecoratedInstance;
         }
 
         private void grdCommands_CellClick(object sender, DataGridViewCellEventArgs e)



More information about the mapguide-commits mailing list