[mapguide-commits] r4802 - in trunk/Tools/Maestro/Maestro: . MaestroEditorInterface ResourceEditors ResourceEditors/Strings

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Mon Apr 19 11:06:59 EDT 2010


Author: jng
Date: 2010-04-19 11:06:58 -0400 (Mon, 19 Apr 2010)
New Revision: 4802

Modified:
   trunk/Tools/Maestro/Maestro/EditorInterface.cs
   trunk/Tools/Maestro/Maestro/MaestroEditorInterface/EditorInterface.cs
   trunk/Tools/Maestro/Maestro/ResourceEditors/LayoutEditor.cs
   trunk/Tools/Maestro/Maestro/ResourceEditors/Strings/LayoutEditor.Designer.cs
   trunk/Tools/Maestro/Maestro/ResourceEditors/Strings/LayoutEditor.resx
Log:
Fix #1324: Use actual library resource id for previewing web layouts. This makes it functionally line up with how it works in Studio. That is:

1) The preview button in the toolbar previews the currently edited web layout that lives in the session repository (w/ any unsaved changes)
2) The "view in browser" button previews the (library based) web layout where this editor will save the changes to. Unlike studio, the user will be prompted to save any unsaved changes before previewing the library-based web layout, if the user doesn't save then they will be viewing the last-saved library version of the web layout.

This adds a new API to EditorInterface: UpdateResourceStates() which allows editor controls to force a refresh of the background colors of edited resource nodes.

Modified: trunk/Tools/Maestro/Maestro/EditorInterface.cs
===================================================================
--- trunk/Tools/Maestro/Maestro/EditorInterface.cs	2010-04-16 16:53:37 UTC (rev 4801)
+++ trunk/Tools/Maestro/Maestro/EditorInterface.cs	2010-04-19 15:06:58 UTC (rev 4802)
@@ -90,9 +90,14 @@
 				if (!m_page.Text.EndsWith("*"))
 					m_page.Text += " *";
 
-			m_editor.UpdateResourceTreeStatus();
+            m_editor.UpdateResourceTreeStatus();
 		}
 
+        public void UpdateResourceStates()
+        {
+            m_editor.UpdateResourceTreeStatus();
+        }
+
 		internal TabPage Page
 		{
 			get { return m_page; }

Modified: trunk/Tools/Maestro/Maestro/MaestroEditorInterface/EditorInterface.cs
===================================================================
--- trunk/Tools/Maestro/Maestro/MaestroEditorInterface/EditorInterface.cs	2010-04-16 16:53:37 UTC (rev 4801)
+++ trunk/Tools/Maestro/Maestro/MaestroEditorInterface/EditorInterface.cs	2010-04-19 15:06:58 UTC (rev 4802)
@@ -56,6 +56,11 @@
 		/// </summary>
 		void HasChanged();
 
+        /// <summary>
+        /// Forces a check of the state of all opened resources (to update colors in the Site Explorer)
+        /// </summary>
+        void UpdateResourceStates();
+
 		/// <summary>
 		/// Request a browse dialog for the specified resource type
 		/// </summary>

Modified: trunk/Tools/Maestro/Maestro/ResourceEditors/LayoutEditor.cs
===================================================================
--- trunk/Tools/Maestro/Maestro/ResourceEditors/LayoutEditor.cs	2010-04-16 16:53:37 UTC (rev 4801)
+++ trunk/Tools/Maestro/Maestro/ResourceEditors/LayoutEditor.cs	2010-04-19 15:06:58 UTC (rev 4802)
@@ -169,6 +169,9 @@
 			UpdateDisplay();
 		}
 
+        private string sessionPreviewUrl;
+        private string libraryPreviewUrl;
+
 		public void UpdateDisplay()
 		{
 			if (m_isUpdating)
@@ -250,10 +253,14 @@
                     ContextAddButton.DropDown =
                     TaskAddButton.DropDown = AddItemMenu;
 
-				if (m_editor.Existing)
-					browserURL.Text = ((OSGeo.MapGuide.MaestroAPI.HttpServerConnection)m_editor.CurrentConnection).BaseURL + "mapviewerajax/?WEBLAYOUT=" + System.Web.HttpUtility.UrlEncode(m_layout.ResourceId);
-				else
-					browserURL.Text = "";
+                if (m_editor.Existing)
+                {
+                    sessionPreviewUrl = ((OSGeo.MapGuide.MaestroAPI.HttpServerConnection)m_editor.CurrentConnection).BaseURL + "mapviewerajax/?WEBLAYOUT=" + System.Web.HttpUtility.UrlEncode(m_layout.ResourceId) + "&SESSION=" + m_editor.CurrentConnection.SessionID;
+                    libraryPreviewUrl = ((OSGeo.MapGuide.MaestroAPI.HttpServerConnection)m_editor.CurrentConnection).BaseURL + "mapviewerajax/?WEBLAYOUT=" + System.Web.HttpUtility.UrlEncode(m_editor.ResourceId);
+                    browserURL.Text = libraryPreviewUrl;
+                }
+                else
+                    browserURL.Text = "";
 
 			}
 			finally
@@ -1651,7 +1658,8 @@
 
 		public bool Preview()
 		{
-			ShowInBrowser_Click(null, null);
+            SaveSessionCopy();
+            DoPreview(sessionPreviewUrl);
 			return true;
 		}
 
@@ -1987,22 +1995,60 @@
 		
 		}
 
+        private void DoPreview(string url)
+        {
+            try 
+            {
+                m_editor.OpenUrl(url);
+            }
+            catch (Exception ex)
+            {
+                m_editor.SetLastException(ex);
+                MessageBox.Show(this, String.Format(Strings.LayoutEditor.BrowserLaunchError, ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
+            }
+        }
+
 		private void ShowInBrowser_Click(object sender, System.EventArgs e)
 		{
-			try
-			{
-				m_editor.CurrentConnection.SaveResourceAs(m_layout, m_tempResource);
-				string url = ((OSGeo.MapGuide.MaestroAPI.HttpServerConnection)m_editor.CurrentConnection).BaseURL + "mapviewerajax/?WEBLAYOUT=" + System.Web.HttpUtility.UrlEncode(m_tempResource) + "&SESSION=" + System.Web.HttpUtility.UrlEncode(m_editor.CurrentConnection.SessionID);
+            if (m_editor.IsModified)
+            {
+                var result = MessageBox.Show(Strings.LayoutEditor.UnsavedLayoutPreview, string.Empty, MessageBoxButtons.YesNoCancel);
 
-                m_editor.OpenUrl(url);
-			}
-			catch (Exception ex)
-			{
-                m_editor.SetLastException(ex);
-                MessageBox.Show(this, String.Format(Strings.LayoutEditor.BrowserLaunchError, ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
-			}
+                //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);
 		}
 
+        private void SaveLibraryCopy()
+        {
+            m_editor.CurrentConnection.SaveResourceAs(m_layout, m_editor.ResourceId); //Library copy
+        }
+
+        private void SaveSessionCopy()
+        {
+            //m_editor.CurrentConnection.SaveResourceAs(m_layout, m_tempResource); //Session copy
+            m_editor.CurrentConnection.SaveResource(m_layout); //This is a session copy
+        }
+
         private void DeleteButton_Click(object sender, EventArgs e)
         {
             DeleteSelectedItem();            

Modified: trunk/Tools/Maestro/Maestro/ResourceEditors/Strings/LayoutEditor.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro/ResourceEditors/Strings/LayoutEditor.Designer.cs	2010-04-16 16:53:37 UTC (rev 4801)
+++ trunk/Tools/Maestro/Maestro/ResourceEditors/Strings/LayoutEditor.Designer.cs	2010-04-19 15:06:58 UTC (rev 4802)
@@ -1,7 +1,7 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     This code was generated by a tool.
-//     Runtime Version:2.0.50727.4927
+//     Runtime Version:2.0.50727.3053
 //
 //     Changes to this file may cause incorrect behavior and will be lost if
 //     the code is regenerated.
@@ -122,5 +122,14 @@
                 return ResourceManager.GetString("SubMenuInTaskBarError", resourceCulture);
             }
         }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to The Web Layout has unsaved changes. If you do not save, the original version of the Web Layout will be shown. Save first before viewing?.
+        /// </summary>
+        internal static string UnsavedLayoutPreview {
+            get {
+                return ResourceManager.GetString("UnsavedLayoutPreview", resourceCulture);
+            }
+        }
     }
 }

Modified: trunk/Tools/Maestro/Maestro/ResourceEditors/Strings/LayoutEditor.resx
===================================================================
--- trunk/Tools/Maestro/Maestro/ResourceEditors/Strings/LayoutEditor.resx	2010-04-16 16:53:37 UTC (rev 4801)
+++ trunk/Tools/Maestro/Maestro/ResourceEditors/Strings/LayoutEditor.resx	2010-04-19 15:06:58 UTC (rev 4802)
@@ -145,4 +145,8 @@
     <value>The Taskbar does not support sub menus</value>
     <comment>An error message that is displayed if the user attempts to insert a submenu in the taskbar</comment>
   </data>
-</root>
\ No newline at end of file
+  <data name="UnsavedLayoutPreview" xml:space="preserve">
+    <value>The Web Layout has unsaved changes. If you do not save, the original version of the Web Layout will be shown. Save first before viewing?</value>
+    <comment>en "View in browser" is clicked with unsaved changes</comment>
+  </data>
+</root>



More information about the mapguide-commits mailing list