[mapguide-commits] r5239 - in sandbox/maestro-3.0/Maestro.Base: .
Editor Properties Services
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Mon Oct 4 01:51:06 EDT 2010
Author: jng
Date: 2010-10-04 05:51:06 +0000 (Mon, 04 Oct 2010)
New Revision: 5239
Modified:
sandbox/maestro-3.0/Maestro.Base/Editor/DrawingSourceEditor.cs
sandbox/maestro-3.0/Maestro.Base/Editor/EditorContentBase.cs
sandbox/maestro-3.0/Maestro.Base/Editor/FeatureSourceEditor.cs
sandbox/maestro-3.0/Maestro.Base/Editor/LayerDefinitionEditor.cs
sandbox/maestro-3.0/Maestro.Base/Editor/MapDefinitionEditor.cs
sandbox/maestro-3.0/Maestro.Base/Editor/XmlEditor.cs
sandbox/maestro-3.0/Maestro.Base/IViewContent.cs
sandbox/maestro-3.0/Maestro.Base/Properties/Resources.Designer.cs
sandbox/maestro-3.0/Maestro.Base/Properties/Resources.resx
sandbox/maestro-3.0/Maestro.Base/Services/OpenResourceManager.cs
sandbox/maestro-3.0/Maestro.Base/TabFactory.cs
sandbox/maestro-3.0/Maestro.Base/ViewContentBase.cs
Log:
3.0 sandbox changes:
- Refactor root resource editors to use common pre-save logic.
- Add pre-save validation stub for subclasses of EditorContentBase to do resource-specific validation
Modified: sandbox/maestro-3.0/Maestro.Base/Editor/DrawingSourceEditor.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Editor/DrawingSourceEditor.cs 2010-10-04 04:39:35 UTC (rev 5238)
+++ sandbox/maestro-3.0/Maestro.Base/Editor/DrawingSourceEditor.cs 2010-10-04 05:51:06 UTC (rev 5239)
@@ -47,22 +47,5 @@
_edsvc.BeforeSave += new CancelEventHandler(OnBeforeSave);
dsEditorCtrl.Bind(service);
}
-
- void OnBeforeSave(object sender, CancelEventArgs e)
- {
- //We've been editing an in-memory model of the session copy
- //so we need to save this model back to the session copy before Save()
- //commits the changes back to the original resource
- try
- {
- _edsvc.UpdateResourceContent(_res.Serialize());
- e.Cancel = false;
- }
- catch (Exception ex)
- {
- MessageService.ShowError(ex);
- e.Cancel = true;
- }
- }
}
}
Modified: sandbox/maestro-3.0/Maestro.Base/Editor/EditorContentBase.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Editor/EditorContentBase.cs 2010-10-04 04:39:35 UTC (rev 5238)
+++ sandbox/maestro-3.0/Maestro.Base/Editor/EditorContentBase.cs 2010-10-04 05:51:06 UTC (rev 5239)
@@ -8,6 +8,7 @@
using OSGeo.MapGuide.MaestroAPI.Resource;
using OSGeo.MapGuide.MaestroAPI;
using Maestro.Editors;
+using ICSharpCode.Core;
namespace Maestro.Base.Editor
{
@@ -37,6 +38,7 @@
_svc = value;
_svc.DirtyStateChanged += new EventHandler(OnDirtyStateChanged);
_svc.Saved += new EventHandler(OnSaved);
+ _svc.BeforeSave += new CancelEventHandler(OnBeforeSave);
this.Resource = _svc.GetEditedResource();
UpdateTitle();
@@ -47,6 +49,34 @@
}
}
+ protected virtual string GetXmlContent()
+ {
+ return this.Resource.Serialize();
+ }
+
+ protected virtual void OnBeforeSave(object sender, CancelEventArgs e)
+ {
+ //We've been editing an in-memory model of the session copy
+ //so we need to save this model back to the session copy before Save()
+ //commits the changes back to the original resource
+ try
+ {
+ ValidateEditedResource();
+ _svc.UpdateResourceContent(GetXmlContent());
+ e.Cancel = false;
+ }
+ catch (Exception ex)
+ {
+ MessageService.ShowError(ex);
+ e.Cancel = true;
+ }
+ }
+
+ /// <summary>
+ /// Performs any pre-save validation on the currently edited resource
+ /// </summary>
+ protected virtual void ValidateEditedResource() { }
+
void OnSaved(object sender, EventArgs e)
{
UpdateTitle();
Modified: sandbox/maestro-3.0/Maestro.Base/Editor/FeatureSourceEditor.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Editor/FeatureSourceEditor.cs 2010-10-04 04:39:35 UTC (rev 5238)
+++ sandbox/maestro-3.0/Maestro.Base/Editor/FeatureSourceEditor.cs 2010-10-04 05:51:06 UTC (rev 5239)
@@ -44,27 +44,9 @@
{
_edsvc = service;
_res = _edsvc.GetEditedResource();
- _edsvc.BeforeSave += new CancelEventHandler(OnBeforeSave);
fsEditorCtrl.Bind(service);
}
- void OnBeforeSave(object sender, CancelEventArgs e)
- {
- //We've been editing an in-memory model of the session copy
- //so we need to save this model back to the session copy before Save()
- //commits the changes back to the original resource
- try
- {
- _edsvc.UpdateResourceContent(_res.Serialize());
- e.Cancel = false;
- }
- catch (Exception ex)
- {
- MessageService.ShowError(ex);
- e.Cancel = true;
- }
- }
-
public override string SetupPreviewUrl(string mapguideRootUrl)
{
string url = mapguideRootUrl;
Modified: sandbox/maestro-3.0/Maestro.Base/Editor/LayerDefinitionEditor.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Editor/LayerDefinitionEditor.cs 2010-10-04 04:39:35 UTC (rev 5238)
+++ sandbox/maestro-3.0/Maestro.Base/Editor/LayerDefinitionEditor.cs 2010-10-04 05:51:06 UTC (rev 5239)
@@ -75,22 +75,5 @@
throw new NotSupportedException("Could not determine the sub-layer type"); //LOCALIZE
}
}
-
- void OnBeforeSave(object sender, CancelEventArgs e)
- {
- //We've been editing an in-memory model of the session copy
- //so we need to save this model back to the session copy before Save()
- //commits the changes back to the original resource
- try
- {
- _edsvc.UpdateResourceContent(_res.Serialize());
- e.Cancel = false;
- }
- catch (Exception ex)
- {
- MessageService.ShowError(ex);
- e.Cancel = true;
- }
- }
}
}
Modified: sandbox/maestro-3.0/Maestro.Base/Editor/MapDefinitionEditor.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Editor/MapDefinitionEditor.cs 2010-10-04 04:39:35 UTC (rev 5238)
+++ sandbox/maestro-3.0/Maestro.Base/Editor/MapDefinitionEditor.cs 2010-10-04 05:51:06 UTC (rev 5239)
@@ -48,23 +48,6 @@
mapEditorCtrl.Bind(service);
}
- void OnBeforeSave(object sender, CancelEventArgs e)
- {
- //We've been editing an in-memory model of the session copy
- //so we need to save this model back to the session copy before Save()
- //commits the changes back to the original resource
- try
- {
- _edsvc.UpdateResourceContent(_res.Serialize());
- e.Cancel = false;
- }
- catch (Exception ex)
- {
- MessageService.ShowError(ex);
- e.Cancel = true;
- }
- }
-
public override bool CanProfile
{
get
Modified: sandbox/maestro-3.0/Maestro.Base/Editor/XmlEditor.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Editor/XmlEditor.cs 2010-10-04 04:39:35 UTC (rev 5238)
+++ sandbox/maestro-3.0/Maestro.Base/Editor/XmlEditor.cs 2010-10-04 05:51:06 UTC (rev 5239)
@@ -88,19 +88,14 @@
protected override void Bind(IEditorService service)
{
service.RegisterCustomNotifier(editor);
- service.BeforeSave += new CancelEventHandler(OnBeforeSave);
editor.Bind(service);
editor.ReadyForEditing(); //This turns on event broadcasting
this.Title = "XML Editor: " + ResourceIdentifier.GetName(this.EditorService.ResourceID); //LOCALIZE
}
- void OnBeforeSave(object sender, CancelEventArgs e)
+ protected override string GetXmlContent()
{
- //Because we're working with raw XML, we need to save the XML back to our session
- //copy first before the save operation starts
- this.EditorService.UpdateResourceContent(this.XmlContent);
-
- e.Cancel = false;
+ return this.XmlContent;
}
public string XmlContent
Modified: sandbox/maestro-3.0/Maestro.Base/IViewContent.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/IViewContent.cs 2010-10-04 04:39:35 UTC (rev 5238)
+++ sandbox/maestro-3.0/Maestro.Base/IViewContent.cs 2010-10-04 05:51:06 UTC (rev 5239)
@@ -21,6 +21,7 @@
using System.Collections.Generic;
using System.Text;
using System.Drawing;
+using System.ComponentModel;
namespace Maestro.Base
{
@@ -71,8 +72,12 @@
/// <summary>
/// Fired when the view has been closed internally
/// </summary>
- event EventHandler ViewContentClosing;
+ event CancelEventHandler ViewContentClosing;
/// <summary>
+ /// Fired when the view has been closed internally
+ /// </summary>
+ event EventHandler ViewContentClosed;
+ /// <summary>
/// Fired when the view is going to hide
/// </summary>
event EventHandler ViewContentHiding;
Modified: sandbox/maestro-3.0/Maestro.Base/Properties/Resources.Designer.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Properties/Resources.Designer.cs 2010-10-04 04:39:35 UTC (rev 5238)
+++ sandbox/maestro-3.0/Maestro.Base/Properties/Resources.Designer.cs 2010-10-04 05:51:06 UTC (rev 5239)
@@ -260,6 +260,15 @@
}
/// <summary>
+ /// Looks up a localized string similar to This resource has unsaved changes. Close and discard these changes?.
+ /// </summary>
+ internal static string CloseUnsavedResource {
+ get {
+ return ResourceManager.GetString("CloseUnsavedResource", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Are you sure you want to delete?.
/// </summary>
internal static string ConfirmDelete {
Modified: sandbox/maestro-3.0/Maestro.Base/Properties/Resources.resx
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Properties/Resources.resx 2010-10-04 04:39:35 UTC (rev 5238)
+++ sandbox/maestro-3.0/Maestro.Base/Properties/Resources.resx 2010-10-04 05:51:06 UTC (rev 5239)
@@ -673,4 +673,7 @@
<data name="NewResource" xml:space="preserve">
<value>New Resource</value>
</data>
+ <data name="CloseUnsavedResource" xml:space="preserve">
+ <value>This resource has unsaved changes. Close and discard these changes?</value>
+ </data>
</root>
\ No newline at end of file
Modified: sandbox/maestro-3.0/Maestro.Base/Services/OpenResourceManager.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Services/OpenResourceManager.cs 2010-10-04 04:39:35 UTC (rev 5238)
+++ sandbox/maestro-3.0/Maestro.Base/Services/OpenResourceManager.cs 2010-10-04 05:51:06 UTC (rev 5239)
@@ -101,6 +101,16 @@
_openItems[resourceId] = ed;
ed.ViewContentClosing += (sender, e) =>
{
+ if (ed.IsDirty)
+ {
+ if (!MessageService.AskQuestion(Properties.Resources.CloseUnsavedResource))
+ {
+ e.Cancel = true;
+ }
+ }
+ };
+ ed.ViewContentClosed += (sender, e) =>
+ {
_openItems.Remove(resourceId);
siteExp.FlagNode(resourceId, NodeFlagAction.None);
};
Modified: sandbox/maestro-3.0/Maestro.Base/TabFactory.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/TabFactory.cs 2010-10-04 04:39:35 UTC (rev 5238)
+++ sandbox/maestro-3.0/Maestro.Base/TabFactory.cs 2010-10-04 05:51:06 UTC (rev 5239)
@@ -89,7 +89,7 @@
};
- content.ViewContentClosing += (sender, e) =>
+ content.ViewContentClosed += (sender, e) =>
{
//Remove itself from the tab control
var tabs = page.Parent as TabControl;
Modified: sandbox/maestro-3.0/Maestro.Base/ViewContentBase.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/ViewContentBase.cs 2010-10-04 04:39:35 UTC (rev 5238)
+++ sandbox/maestro-3.0/Maestro.Base/ViewContentBase.cs 2010-10-04 05:51:06 UTC (rev 5239)
@@ -69,12 +69,20 @@
public virtual void Close()
{
- var handler = this.ViewContentClosing;
+ CancelEventArgs ce = new CancelEventArgs(false);
+ var ceHandler = this.ViewContentClosing;
+ if (ceHandler != null)
+ ceHandler(this, ce);
+
+ if (ce.Cancel)
+ return;
+
+ var handler = this.ViewContentClosed;
if (handler != null)
handler(this, EventArgs.Empty);
}
- public event EventHandler ViewContentClosing;
+ public event CancelEventHandler ViewContentClosing;
public void ShowError(Exception ex)
{
@@ -158,5 +166,7 @@
{
get { return ViewRegion.Document; }
}
+
+ public event EventHandler ViewContentClosed;
}
}
More information about the mapguide-commits
mailing list