[mapguide-commits] r4988 - in trunk/Tools/Maestro/Maestro/FusionEditor: . Strings

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Jul 1 23:23:13 EDT 2010


Author: jng
Date: 2010-07-02 03:23:12 +0000 (Fri, 02 Jul 2010)
New Revision: 4988

Modified:
   trunk/Tools/Maestro/Maestro/FusionEditor/ApplicationDefinitionEditor.cs
   trunk/Tools/Maestro/Maestro/FusionEditor/Strings/ApplicationDefinitionEditor.Designer.cs
   trunk/Tools/Maestro/Maestro/FusionEditor/Strings/ApplicationDefinitionEditor.resx
Log:
Fix #1389: Port web layout preview logic to fusion editor.

Modified: trunk/Tools/Maestro/Maestro/FusionEditor/ApplicationDefinitionEditor.cs
===================================================================
--- trunk/Tools/Maestro/Maestro/FusionEditor/ApplicationDefinitionEditor.cs	2010-07-02 02:31:42 UTC (rev 4987)
+++ trunk/Tools/Maestro/Maestro/FusionEditor/ApplicationDefinitionEditor.cs	2010-07-02 03:23:12 UTC (rev 4988)
@@ -131,6 +131,9 @@
 			UpdateDisplay();
 		}
 
+        private string sessionPreviewUrl;
+        private string libraryPreviewUrl;
+
 		public void UpdateDisplay()
 		{
 			try
@@ -741,10 +744,35 @@
 
 		public bool Preview()
 		{
-			ShowInBrowser_Click(null, null);
+			//ShowInBrowser_Click(null, null);
+            SaveSessionCopy();
+            DoPreview(sessionPreviewUrl);
 			return true;
 		}
 
+        private void SaveLibraryCopy()
+        {
+            m_editor.CurrentConnection.SaveResourceAs(m_appDef, m_editor.ResourceId);
+        }
+
+        private void SaveSessionCopy()
+        {
+            m_editor.CurrentConnection.SaveResourceAs(m_appDef, m_appDef.ResourceId);
+        }
+
+        private void DoPreview(string url)
+        {
+            try
+            {
+                m_editor.OpenUrl(url);
+            }
+            catch (Exception ex)
+            {
+                m_editor.SetLastException(ex); 
+                MessageBox.Show(this, String.Format(Strings.ApplicationDefinitionEditor.BrowserLaunchError, ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); 
+            }
+        }
+
 		private void ApplicationDefinitionEditor_Load(object sender, System.EventArgs e)
 		{
 		
@@ -1065,11 +1093,19 @@
 
 		private void TemplateURL_TextChanged(object sender, System.EventArgs e)
 		{
-			if (m_editor.Existing)
-				browserURL.Text = ((OSGeo.MapGuide.MaestroAPI.HttpServerConnection)m_editor.CurrentConnection).BaseURL + TemplateURL.Text + "?ApplicationDefinition=" + System.Web.HttpUtility.UrlEncode(m_appDef.ResourceId);
-			else
-				browserURL.Text = "";
+            if (m_editor.Existing)
+            {
+                //browserURL.Text = ((OSGeo.MapGuide.MaestroAPI.HttpServerConnection)m_editor.CurrentConnection).BaseURL + TemplateURL.Text + "?ApplicationDefinition=" + System.Web.HttpUtility.UrlEncode(m_appDef.ResourceId);
+                var htcon = (OSGeo.MapGuide.MaestroAPI.HttpServerConnection)m_editor.CurrentConnection;
 
+                sessionPreviewUrl = htcon.BaseURL + TemplateURL.Text + "?ApplicationDefinition=" + System.Web.HttpUtility.UrlEncode(m_appDef.ResourceId) + "&Session=" + htcon.SessionID;
+                libraryPreviewUrl = htcon.BaseURL + TemplateURL.Text + "?ApplicationDefinition=" + System.Web.HttpUtility.UrlEncode(m_editor.ResourceId);
+
+                browserURL.Text = libraryPreviewUrl;
+            }
+            else
+                browserURL.Text = "";
+
 			if (m_isUpdating)
 				return;
 
@@ -1160,6 +1196,33 @@
 
 		private void ShowInBrowser_Click(object sender, System.EventArgs e)
 		{
+            if (m_editor.IsModified)
+            {
+                var result = MessageBox.Show(Strings.ApplicationDefinitionEditor.UnsavedLayoutPreview, string.Empty, MessageBoxButtons.YesNoCancel);
+
+                //Yes = Save changes then preview
+                //No = Preview original (without unsaved changes)
+                //Cancel = Abort Preview
+                if (result == DialogResult.Cancel)
+                    return;
+
+                if (result == DialogResult.Yes)
+                {
+                    SaveSessionCopy();
+                    SaveLibraryCopy();
+
+                    //HACK: There is no formal interface to unset the editor's dirty state
+                    //Dirty state is simply indicated by the asterisk on the editor's tab
+                    //so remove the asterisk.
+                    var page = this.Parent as TabPage;
+                    if (page != null && page.Text.EndsWith(" *"))
+                        page.Text = page.Text.Substring(0, page.Text.Length - 2);
+
+                    m_editor.UpdateResourceStates();
+                }
+            }
+            DoPreview(libraryPreviewUrl);
+            /*
 			try
 			{
 				m_editor.CurrentConnection.SaveResourceAs(m_appDef, m_tempResource);
@@ -1189,7 +1252,7 @@
                 string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
 				MessageBox.Show(this, String.Format(Strings.ApplicationDefinitionEditor.BrowserLaunchError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
 			}
-		
+		    */
 		}
 
         private void AddMapButton_Click(object sender, EventArgs e)

Modified: trunk/Tools/Maestro/Maestro/FusionEditor/Strings/ApplicationDefinitionEditor.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro/FusionEditor/Strings/ApplicationDefinitionEditor.Designer.cs	2010-07-02 02:31:42 UTC (rev 4987)
+++ trunk/Tools/Maestro/Maestro/FusionEditor/Strings/ApplicationDefinitionEditor.Designer.cs	2010-07-02 03:23:12 UTC (rev 4988)
@@ -113,5 +113,14 @@
                 return ResourceManager.GetString("SeperatorMarker", resourceCulture);
             }
         }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to The Application Definition has unsaved changes. If you do not save, the original version of the Application Definition will be shown. Save first before viewing?.
+        /// </summary>
+        internal static string UnsavedLayoutPreview {
+            get {
+                return ResourceManager.GetString("UnsavedLayoutPreview", resourceCulture);
+            }
+        }
     }
 }

Modified: trunk/Tools/Maestro/Maestro/FusionEditor/Strings/ApplicationDefinitionEditor.resx
===================================================================
--- trunk/Tools/Maestro/Maestro/FusionEditor/Strings/ApplicationDefinitionEditor.resx	2010-07-02 02:31:42 UTC (rev 4987)
+++ trunk/Tools/Maestro/Maestro/FusionEditor/Strings/ApplicationDefinitionEditor.resx	2010-07-02 03:23:12 UTC (rev 4988)
@@ -141,4 +141,8 @@
     <value>- Seperator -</value>
     <comment>The text displayed in the tree when a seperator is inserted</comment>
   </data>
+  <data name="UnsavedLayoutPreview" xml:space="preserve">
+    <value>The Application Definition has unsaved changes. If you do not save, the original version of the Application Definition will be shown. Save first before viewing?</value>
+    <comment>en "View in browser" is clicked with unsaved changes</comment>
+  </data>
 </root>
\ No newline at end of file



More information about the mapguide-commits mailing list