[mapguide-commits] r5424 - in sandbox/maestro-3.0: Maestro.Editors/Properties Maestro.Editors/WebLayout OSGeo.MapGuide.MaestroAPI/ObjectModels

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Dec 1 05:26:47 EST 2010


Author: jng
Date: 2010-12-01 02:26:47 -0800 (Wed, 01 Dec 2010)
New Revision: 5424

Modified:
   sandbox/maestro-3.0/Maestro.Editors/Properties/Resources.Designer.cs
   sandbox/maestro-3.0/Maestro.Editors/Properties/Resources.resx
   sandbox/maestro-3.0/Maestro.Editors/WebLayout/WebLayoutCommandsCtrl.Designer.cs
   sandbox/maestro-3.0/Maestro.Editors/WebLayout/WebLayoutCommandsCtrl.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/WebLayout.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/WebLayoutInterfaces.cs
Log:
3.0 sandbox changes:
 - #1352: Implement import/export of custom web layout commands

Modified: sandbox/maestro-3.0/Maestro.Editors/Properties/Resources.Designer.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Editors/Properties/Resources.Designer.cs	2010-12-01 10:26:39 UTC (rev 5423)
+++ sandbox/maestro-3.0/Maestro.Editors/Properties/Resources.Designer.cs	2010-12-01 10:26:47 UTC (rev 5424)
@@ -362,6 +362,24 @@
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to Custom commands exported to {0}.
+        /// </summary>
+        internal static string CustomCommandsExported {
+            get {
+                return ResourceManager.GetString("CustomCommandsExported", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to {0} custom commands imported from {1}. The following commands had to be renamed to prevent clashes: {2}.
+        /// </summary>
+        internal static string CustomCommandsImported {
+            get {
+                return ResourceManager.GetString("CustomCommandsImported", resourceCulture);
+            }
+        }
+        
         internal static System.Drawing.Bitmap database__plus {
             get {
                 object obj = ResourceManager.GetObject("database--plus", resourceCulture);
@@ -478,6 +496,24 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to No commands selected. Nothing to export.
+        /// </summary>
+        internal static string ExportNoCommandsSelected {
+            get {
+                return ResourceManager.GetString("ExportNoCommandsSelected", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to No custom commands selected. Nothing to export.
+        /// </summary>
+        internal static string ExportNoCustomCommandsSelected {
+            get {
+                return ResourceManager.GetString("ExportNoCustomCommandsSelected", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to Expression....
         /// </summary>
         internal static string ExpressionItem {
@@ -604,6 +640,15 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to XML Files (.xml)|*.xml.
+        /// </summary>
+        internal static string FilterXml {
+            get {
+                return ResourceManager.GetString("FilterXml", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to Cannot Find an Empty String.
         /// </summary>
         internal static string FindEmptyString {

Modified: sandbox/maestro-3.0/Maestro.Editors/Properties/Resources.resx
===================================================================
--- sandbox/maestro-3.0/Maestro.Editors/Properties/Resources.resx	2010-12-01 10:26:39 UTC (rev 5423)
+++ sandbox/maestro-3.0/Maestro.Editors/Properties/Resources.resx	2010-12-01 10:26:47 UTC (rev 5424)
@@ -1046,4 +1046,19 @@
   <data name="Separator" xml:space="preserve">
     <value>Separator</value>
   </data>
+  <data name="CustomCommandsExported" xml:space="preserve">
+    <value>Custom commands exported to {0}</value>
+  </data>
+  <data name="CustomCommandsImported" xml:space="preserve">
+    <value>{0} custom commands imported from {1}. The following commands had to be renamed to prevent clashes: {2}</value>
+  </data>
+  <data name="ExportNoCommandsSelected" xml:space="preserve">
+    <value>No commands selected. Nothing to export</value>
+  </data>
+  <data name="ExportNoCustomCommandsSelected" xml:space="preserve">
+    <value>No custom commands selected. Nothing to export</value>
+  </data>
+  <data name="FilterXml" xml:space="preserve">
+    <value>XML Files (.xml)|*.xml</value>
+  </data>
 </root>
\ No newline at end of file

Modified: sandbox/maestro-3.0/Maestro.Editors/WebLayout/WebLayoutCommandsCtrl.Designer.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Editors/WebLayout/WebLayoutCommandsCtrl.Designer.cs	2010-12-01 10:26:39 UTC (rev 5423)
+++ sandbox/maestro-3.0/Maestro.Editors/WebLayout/WebLayoutCommandsCtrl.Designer.cs	2010-12-01 10:26:47 UTC (rev 5424)
@@ -97,6 +97,7 @@
             this.grdCommands.Size = new System.Drawing.Size(427, 228);
             this.grdCommands.TabIndex = 1;
             this.grdCommands.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.grdCommands_CellContentClick);
+            this.grdCommands.SelectionChanged += new System.EventHandler(this.grdCommands_SelectionChanged);
             this.grdCommands.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.grdCommands_CellContentClick);
             // 
             // toolStrip1
@@ -121,14 +122,14 @@
             this.btnAdd.Image = global::Maestro.Editors.Properties.Resources.application__plus;
             this.btnAdd.ImageTransparentColor = System.Drawing.Color.Magenta;
             this.btnAdd.Name = "btnAdd";
-            this.btnAdd.Size = new System.Drawing.Size(55, 22);
+            this.btnAdd.Size = new System.Drawing.Size(58, 22);
             this.btnAdd.Text = "Add";
             // 
             // invokeURLToolStripMenuItem
             // 
             this.invokeURLToolStripMenuItem.Image = global::Maestro.Editors.Properties.Resources.icon_invokeurl;
             this.invokeURLToolStripMenuItem.Name = "invokeURLToolStripMenuItem";
-            this.invokeURLToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
+            this.invokeURLToolStripMenuItem.Size = new System.Drawing.Size(142, 22);
             this.invokeURLToolStripMenuItem.Text = "Invoke URL";
             this.invokeURLToolStripMenuItem.Click += new System.EventHandler(this.invokeURLToolStripMenuItem_Click);
             // 
@@ -136,7 +137,7 @@
             // 
             this.invokeScriptToolStripMenuItem.Image = global::Maestro.Editors.Properties.Resources.icon_invokescript;
             this.invokeScriptToolStripMenuItem.Name = "invokeScriptToolStripMenuItem";
-            this.invokeScriptToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
+            this.invokeScriptToolStripMenuItem.Size = new System.Drawing.Size(142, 22);
             this.invokeScriptToolStripMenuItem.Text = "Invoke Script";
             this.invokeScriptToolStripMenuItem.Click += new System.EventHandler(this.invokeScriptToolStripMenuItem_Click);
             // 
@@ -144,7 +145,7 @@
             // 
             this.searchToolStripMenuItem.Image = global::Maestro.Editors.Properties.Resources.icon_search;
             this.searchToolStripMenuItem.Name = "searchToolStripMenuItem";
-            this.searchToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
+            this.searchToolStripMenuItem.Size = new System.Drawing.Size(142, 22);
             this.searchToolStripMenuItem.Text = "Search";
             this.searchToolStripMenuItem.Click += new System.EventHandler(this.searchToolStripMenuItem_Click);
             // 
@@ -154,7 +155,7 @@
             this.btnDelete.Image = global::Maestro.Editors.Properties.Resources.application__minus;
             this.btnDelete.ImageTransparentColor = System.Drawing.Color.Magenta;
             this.btnDelete.Name = "btnDelete";
-            this.btnDelete.Size = new System.Drawing.Size(58, 22);
+            this.btnDelete.Size = new System.Drawing.Size(60, 22);
             this.btnDelete.Text = "Delete";
             this.btnDelete.ToolTipText = "Delete selected command";
             this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
@@ -165,7 +166,7 @@
             this.btnExport.Image = global::Maestro.Editors.Properties.Resources.application_export;
             this.btnExport.ImageTransparentColor = System.Drawing.Color.Magenta;
             this.btnExport.Name = "btnExport";
-            this.btnExport.Size = new System.Drawing.Size(59, 22);
+            this.btnExport.Size = new System.Drawing.Size(60, 22);
             this.btnExport.Text = "Export";
             this.btnExport.ToolTipText = "Export commands to a XML file";
             this.btnExport.Click += new System.EventHandler(this.btnExport_Click);
@@ -175,7 +176,7 @@
             this.btnImport.Image = global::Maestro.Editors.Properties.Resources.application_import;
             this.btnImport.ImageTransparentColor = System.Drawing.Color.Magenta;
             this.btnImport.Name = "btnImport";
-            this.btnImport.Size = new System.Drawing.Size(59, 22);
+            this.btnImport.Size = new System.Drawing.Size(63, 22);
             this.btnImport.Text = "Import";
             this.btnImport.ToolTipText = "Import commands from an XML file";
             this.btnImport.Click += new System.EventHandler(this.btnImport_Click);
@@ -194,7 +195,6 @@
             // 
             // WebLayoutCommandsCtrl
             // 
-            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
             this.HeaderText = "Commands";
             this.Name = "WebLayoutCommandsCtrl";

Modified: sandbox/maestro-3.0/Maestro.Editors/WebLayout/WebLayoutCommandsCtrl.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Editors/WebLayout/WebLayoutCommandsCtrl.cs	2010-12-01 10:26:39 UTC (rev 5423)
+++ sandbox/maestro-3.0/Maestro.Editors/WebLayout/WebLayoutCommandsCtrl.cs	2010-12-01 10:26:47 UTC (rev 5424)
@@ -67,8 +67,13 @@
             base.UnsubscribeEventHandlers();
         }
 
+        private bool listChangedDisabled = false;
+
         void OnCommandSetListChanged(object sender, ListChangedEventArgs e)
         {
+            if (listChangedDisabled)
+                return;
+
             switch (e.ListChangedType)
             {
                 case ListChangedType.ItemAdded:
@@ -268,12 +273,82 @@
 
         private void btnExport_Click(object sender, EventArgs e)
         {
+            if (grdCommands.SelectedRows.Count == 0)
+            {
+                MessageBox.Show(Properties.Resources.ExportNoCommandsSelected);
+                return;
+            }
+            else
+            {
+                List<string> selectedCmds = new List<string>();
+                foreach (DataGridViewRow row in grdCommands.SelectedRows)
+                {
+                    var cmd = (ICommand)row.DataBoundItem;
+                    var cmdType = cmd.GetType();
+                    if (typeof(IInvokeScriptCommand).IsAssignableFrom(cmdType))
+                        selectedCmds.Add(cmd.Name);
+                    else if (typeof(IInvokeUrlCommand).IsAssignableFrom(cmdType))
+                        selectedCmds.Add(cmd.Name);
+                    else if (typeof(ISearchCommand).IsAssignableFrom(cmdType))
+                        selectedCmds.Add(cmd.Name);
+                }
 
+                if (selectedCmds.Count == 0)
+                {
+                    MessageBox.Show(Properties.Resources.ExportNoCustomCommandsSelected);
+                    return;
+                }
+
+                using (var save = DialogFactory.SaveFile())
+                {
+                    save.Filter = Properties.Resources.FilterXml;
+                    if (save.ShowDialog() == DialogResult.OK)
+                    {
+                        _wl.ExportCustomCommands(save.FileName, selectedCmds.ToArray());
+                        MessageBox.Show(string.Format(Properties.Resources.CustomCommandsExported, save.FileName));
+                    }
+                }
+            }
         }
 
         private void btnImport_Click(object sender, EventArgs e)
         {
+            using (var open = DialogFactory.OpenFile())
+            {
+                if (open.ShowDialog() == DialogResult.OK)
+                {
+                    listChangedDisabled = true;
+                    try
+                    {
+                        var cmds = _wl.ImportCustomCommands(open.FileName);
+                        StringBuilder sb = new StringBuilder();
 
+                        foreach (var imported in cmds)
+                        {
+                            ICommand cmd = _wl.GetCommandByName(imported.ImportedName);
+                            _commands.Add(cmd);
+
+                            if (imported.NameChanged)
+                                sb.AppendLine(imported.ToString());
+                        }
+
+                        MessageBox.Show(string.Format(Properties.Resources.CustomCommandsImported, cmds.Length, open.FileName, sb.ToString()));
+                    }
+                    catch (Exception ex)
+                    {
+                        MessageBox.Show(ex.Message, Properties.Resources.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
+                    }
+                    finally
+                    {
+                        listChangedDisabled = false;
+                    }
+                }
+            }
         }
+
+        private void grdCommands_SelectionChanged(object sender, EventArgs e)
+        {
+            EvaluateCommands();
+        }
     }
 }

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/WebLayout.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/WebLayout.cs	2010-12-01 10:26:39 UTC (rev 5423)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/WebLayout.cs	2010-12-01 10:26:47 UTC (rev 5424)
@@ -54,6 +54,13 @@
         }
     }
 
+    [Serializable]
+    public class WebLayoutCustomCommandList
+    {
+        [XmlArrayItem("CustomCommands")]
+        public CommandType[] Commands { get; set; }
+    }
+
     partial class WebLayoutType : IWebLayout, ICommandSet
     {
         internal WebLayoutType() { }
@@ -749,6 +756,57 @@
             return new SeparatorItemType() { Function = UIItemFunctionType.Separator };
         }
 
+        public void ExportCustomCommands(string file, string[] cmdNames)
+        {
+            WebLayoutCustomCommandList list = new WebLayoutCustomCommandList();
+
+            List<CommandType> commands = new List<CommandType>();
+
+            foreach (var name in cmdNames)
+            {
+                var cmd = (CommandType)GetCommandByName(name);
+                if (cmd != null)
+                    commands.Add(cmd);
+            }
+
+            list.Commands = commands.ToArray();
+
+            using (var fs = File.OpenWrite(file))
+            {
+                new XmlSerializer(typeof(WebLayoutCustomCommandList)).Serialize(fs, list);
+            }
+        }
+
+        public ImportedCommandResult[] ImportCustomCommands(string file)
+        {
+            List<ImportedCommandResult> clashes = new List<ImportedCommandResult>();
+
+            using (var fs = File.OpenRead(file))
+            {
+                var list = (WebLayoutCustomCommandList)(new XmlSerializer(typeof(WebLayoutCustomCommandList)).Deserialize(fs));
+                foreach (var importCmd in list.Commands)
+                {
+                    int counter = 0;
+                    string oldName = importCmd.Name;
+                    string newName = oldName;
+
+                    ICommand cmd = this.GetCommandByName(newName);
+                    while (cmd != null)
+                    {
+                        counter++;
+                        newName = oldName + counter;
+                        cmd = this.GetCommandByName(newName);
+                    }
+
+                    this.commandSetField.Add(importCmd);
+                    
+                    clashes.Add(new ImportedCommandResult() { OriginalName = oldName, ImportedName = newName });
+                }
+            }
+
+            return clashes.ToArray();
+        }
+
         [XmlIgnore]
         ICommandSet IWebLayout.CommandSet
         {

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/WebLayoutInterfaces.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/WebLayoutInterfaces.cs	2010-12-01 10:26:39 UTC (rev 5423)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/WebLayoutInterfaces.cs	2010-12-01 10:26:47 UTC (rev 5424)
@@ -266,11 +266,28 @@
         All,
     }
 
+    public class ImportedCommandResult
+    {
+        public string OriginalName { get; set; }
+
+        public string ImportedName { get; set; }
+
+        public bool NameChanged { get { return !this.ImportedName.Equals(this.OriginalName); } }
+
+        public override string ToString()
+        {
+            return string.Format("{0} => {1}", this.OriginalName, this.ImportedName);
+        }
+    }
+
     /// <summary>
     /// The Web Layout
     /// </summary>
     public interface IWebLayout : IResource, INotifyPropertyChanged
     {
+        void ExportCustomCommands(string file, string[] cmdNames);
+
+        ImportedCommandResult[] ImportCustomCommands(string file);
         /// <summary>
         /// Determines whether the specified command name is referenced in any regions
         /// </summary>



More information about the mapguide-commits mailing list