[mapguide-commits] r6501 - in trunk/Tools/Maestro/Maestro.Base: . Commands Properties Resources UI

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sun Feb 12 07:50:59 EST 2012


Author: jng
Date: 2012-02-12 04:50:59 -0800 (Sun, 12 Feb 2012)
New Revision: 6501

Added:
   trunk/Tools/Maestro/Maestro.Base/Commands/ViewXmlChangesCommand.cs
   trunk/Tools/Maestro/Maestro.Base/Resources/edit-diff.png
Modified:
   trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin
   trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
   trunk/Tools/Maestro/Maestro.Base/Properties/Resources.Designer.cs
   trunk/Tools/Maestro/Maestro.Base/Properties/Resources.resx
   trunk/Tools/Maestro/Maestro.Base/UI/DirtyStateConfirmationDialog.cs
Log:
#1950: Add a toolbar command to view XML diffs of the actively edited resource

Added: trunk/Tools/Maestro/Maestro.Base/Commands/ViewXmlChangesCommand.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/ViewXmlChangesCommand.cs	                        (rev 0)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/ViewXmlChangesCommand.cs	2012-02-12 12:50:59 UTC (rev 6501)
@@ -0,0 +1,96 @@
+#region Disclaimer / License
+// Copyright (C) 2012, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+using ICSharpCode.Core;
+using Maestro.Editors.Diff;
+using Maestro.Shared.UI;
+using OSGeo.MapGuide.MaestroAPI.Resource.Comparison;
+
+namespace Maestro.Base.Commands
+{
+    internal class ViewXmlChangesCommand : AbstractMenuCommand
+    {
+        public override void Run()
+        {
+            var wb = Workbench.Instance;
+            if (wb == null) return;
+            var ed = wb.ActiveEditor;
+            if (ed == null) return;
+            var edSvc = ed.EditorService;
+
+            TextFileDiffList sLF = null;
+            TextFileDiffList dLF = null;
+            string sourceFile = Path.GetTempFileName();
+            string targetFile = Path.GetTempFileName();
+            try
+            {
+                edSvc.SyncSessionCopy();
+                using (var source = new StreamReader(edSvc.ResourceService.GetResourceXmlData(edSvc.ResourceID)))
+                using (var target = new StreamReader(edSvc.ResourceService.GetResourceXmlData(edSvc.EditedResourceID)))
+                {
+                    File.WriteAllText(sourceFile, source.ReadToEnd());
+                    File.WriteAllText(targetFile, target.ReadToEnd());
+
+                    sLF = new TextFileDiffList(sourceFile);
+                    dLF = new TextFileDiffList(targetFile);
+                }
+            }
+            catch (Exception ex)
+            {
+                ErrorDialog.Show(ex);
+                return;
+            }
+            finally
+            {
+                try { File.Delete(sourceFile); }
+                catch { }
+                try { File.Delete(targetFile); }
+                catch { }
+            }
+
+            try
+            {
+                double time = 0;
+                DiffEngine de = new DiffEngine();
+                time = de.ProcessDiff(sLF, dLF, DiffEngineLevel.SlowPerfect);
+
+                var rep = de.DiffReport();
+                TextDiffView dlg = new TextDiffView(sLF, dLF, rep, time);
+                dlg.Text += " - " + edSvc.ResourceID;
+                dlg.ShowDialog();
+                dlg.Dispose();
+            }
+            catch (Exception ex)
+            {
+                string tmp = string.Format("{0}{1}{1}***STACK***{1}{2}",
+                    ex.Message,
+                    Environment.NewLine,
+                    ex.StackTrace);
+                MessageBox.Show(tmp, "Compare Error");
+                return;
+            }
+        }
+    }
+}

Modified: trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin	2012-02-12 11:04:04 UTC (rev 6500)
+++ trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin	2012-02-12 12:50:59 UTC (rev 6501)
@@ -354,6 +354,13 @@
                          tooltip="${res:Menu_Tools_Translate_Desc}"
                          class="Maestro.Base.Commands.TranslateLayoutCommand" />
         </Condition>
+        <Condition action="Disable" name="EditorFunction" property="CANSAVE">
+            <ToolbarItem id="XmlChanges"
+                         icon="edit_diff"
+                         label="${res:Menu_Tools_XmlChanges}"
+                         tooltip="${res:Menu_Tools_XmlChanges_Desc}"
+                         class="Maestro.Base.Commands.ViewXmlChangesCommand" />
+        </Condition>
         <!-- 
         Only needed if our custom drawn close buttons don't appear on document
         tabs (I'm looking at you Mono). So far this isn't the case. 

Modified: trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj	2012-02-12 11:04:04 UTC (rev 6500)
+++ trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj	2012-02-12 12:50:59 UTC (rev 6501)
@@ -139,6 +139,7 @@
     <Compile Include="Commands\TranslateLayoutCommand.cs" />
     <Compile Include="Commands\UserGuideCommand.cs" />
     <Compile Include="Commands\ValidateEditedResourceCommand.cs" />
+    <Compile Include="Commands\ViewXmlChangesCommand.cs" />
     <Compile Include="Commands\XmlEditCommand.cs" />
     <Compile Include="Editor\DrawingSourceEditor.cs">
       <SubType>UserControl</SubType>
@@ -404,6 +405,7 @@
   </ItemGroup>
   <ItemGroup>
     <Content Include="Maestro.Base.addin" />
+    <None Include="Resources\edit-diff.png" />
     <None Include="Resources\edit-language.png" />
     <None Include="Resources\box--pencil.png" />
     <None Include="Resources\Contributors.txt" />

Modified: trunk/Tools/Maestro/Maestro.Base/Properties/Resources.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Properties/Resources.Designer.cs	2012-02-12 11:04:04 UTC (rev 6500)
+++ trunk/Tools/Maestro/Maestro.Base/Properties/Resources.Designer.cs	2012-02-12 12:50:59 UTC (rev 6501)
@@ -670,6 +670,13 @@
             }
         }
         
+        internal static System.Drawing.Bitmap edit_diff {
+            get {
+                object obj = ResourceManager.GetObject("edit_diff", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
         internal static System.Drawing.Bitmap edit_language {
             get {
                 object obj = ResourceManager.GetObject("edit_language", resourceCulture);
@@ -1283,6 +1290,24 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to View Changes.
+        /// </summary>
+        internal static string Menu_Tools_XmlChanges {
+            get {
+                return ResourceManager.GetString("Menu_Tools_XmlChanges", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to View XML content changes of current resource.
+        /// </summary>
+        internal static string Menu_Tools_XmlChanges_Desc {
+            get {
+                return ResourceManager.GetString("Menu_Tools_XmlChanges_Desc", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to View.
         /// </summary>
         internal static string Menu_View {

Modified: trunk/Tools/Maestro/Maestro.Base/Properties/Resources.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Properties/Resources.resx	2012-02-12 11:04:04 UTC (rev 6500)
+++ trunk/Tools/Maestro/Maestro.Base/Properties/Resources.resx	2012-02-12 12:50:59 UTC (rev 6501)
@@ -112,15 +112,15 @@
     <value>2.0</value>
   </resheader>
   <resheader name="reader">
-    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
   <resheader name="writer">
-    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
   <data name="Menu_Tools_Options" xml:space="preserve">
     <value>Options</value>
   </data>
-  <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+  <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
   <data name="cross-circle" type="System.Resources.ResXFileRef, System.Windows.Forms">
     <value>..\Resources\cross-circle.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
@@ -1085,4 +1085,13 @@
   <data name="RtMapInspector" xml:space="preserve">
     <value>Runtime Map Inspector</value>
   </data>
+  <data name="edit_diff" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\edit-diff.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="Menu_Tools_XmlChanges" xml:space="preserve">
+    <value>View Changes</value>
+  </data>
+  <data name="Menu_Tools_XmlChanges_Desc" xml:space="preserve">
+    <value>View XML content changes of current resource</value>
+  </data>
 </root>
\ No newline at end of file

Added: trunk/Tools/Maestro/Maestro.Base/Resources/edit-diff.png
===================================================================
(Binary files differ)


Property changes on: trunk/Tools/Maestro/Maestro.Base/Resources/edit-diff.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: trunk/Tools/Maestro/Maestro.Base/UI/DirtyStateConfirmationDialog.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/UI/DirtyStateConfirmationDialog.cs	2012-02-12 11:04:04 UTC (rev 6500)
+++ trunk/Tools/Maestro/Maestro.Base/UI/DirtyStateConfirmationDialog.cs	2012-02-12 12:50:59 UTC (rev 6501)
@@ -106,7 +106,6 @@
             }
             catch (Exception ex)
             {
-                this.Cursor = Cursors.Default;
                 string tmp = string.Format("{0}{1}{1}***STACK***{1}{2}",
                     ex.Message,
                     Environment.NewLine,



More information about the mapguide-commits mailing list