[mapguide-commits] r5072 - in sandbox/maestro-3.0/Maestro.Base: .
Commands/SiteExplorer Properties Services
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Fri Aug 6 01:11:06 EDT 2010
Author: jng
Date: 2010-08-06 05:11:06 +0000 (Fri, 06 Aug 2010)
New Revision: 5072
Added:
sandbox/maestro-3.0/Maestro.Base/Commands/SiteExplorer/OpenWithXmlEditorCommand.cs
Modified:
sandbox/maestro-3.0/Maestro.Base/Commands/SiteExplorer/OpenResourceCommand.cs
sandbox/maestro-3.0/Maestro.Base/Maestro.Base.addin
sandbox/maestro-3.0/Maestro.Base/Maestro.Base.csproj
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
Log:
This submission implements the Open Resource context menu command and the Open Resource in XML editor context menu command
Modified: sandbox/maestro-3.0/Maestro.Base/Commands/SiteExplorer/OpenResourceCommand.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Commands/SiteExplorer/OpenResourceCommand.cs 2010-08-05 17:38:22 UTC (rev 5071)
+++ sandbox/maestro-3.0/Maestro.Base/Commands/SiteExplorer/OpenResourceCommand.cs 2010-08-06 05:11:06 UTC (rev 5072)
@@ -21,10 +21,38 @@
using System.Collections.Generic;
using System.Text;
using ICSharpCode.Core;
+using OSGeo.MapGuide.MaestroAPI;
+using Maestro.Base.Services;
namespace Maestro.Base.Commands.SiteExplorer
{
- internal class OpenResourceCommand : NotImplementedCommand
+ internal class OpenResourceCommand : AbstractMenuCommand
{
+ private IServerConnection _conn;
+
+ public override void Run()
+ {
+ var wb = Workbench.Instance;
+ var items = wb.ActiveSiteExplorer.SelectedItems;
+ var openMgr = ServiceRegistry.GetService<OpenResourceManager>();
+ var connMgr = ServiceRegistry.GetService<ServerConnectionManager>();
+ _conn = connMgr.GetConnection(wb.ActiveSiteExplorer.ConnectionName);
+
+ if (items.Length == 1)
+ {
+ var item = items[0];
+ if (!item.IsFolder)
+ {
+ if (openMgr.IsOpen(item.ResourceId))
+ {
+ openMgr.GetOpenEditor(item.ResourceId).Activate();
+ }
+ else
+ {
+ openMgr.Open(item.ResourceId, _conn, false);
+ }
+ }
+ }
+ }
}
}
Added: sandbox/maestro-3.0/Maestro.Base/Commands/SiteExplorer/OpenWithXmlEditorCommand.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Commands/SiteExplorer/OpenWithXmlEditorCommand.cs (rev 0)
+++ sandbox/maestro-3.0/Maestro.Base/Commands/SiteExplorer/OpenWithXmlEditorCommand.cs 2010-08-06 05:11:06 UTC (rev 5072)
@@ -0,0 +1,68 @@
+#region Disclaimer / License
+// Copyright (C) 2010, 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.Text;
+using ICSharpCode.Core;
+using OSGeo.MapGuide.MaestroAPI;
+using Maestro.Base.Services;
+using Maestro.Base.Editor;
+
+namespace Maestro.Base.Commands.SiteExplorer
+{
+ internal class OpenWithXmlEditorCommand : AbstractMenuCommand
+ {
+ private IServerConnection _conn;
+
+ public override void Run()
+ {
+ var wb = Workbench.Instance;
+ var items = wb.ActiveSiteExplorer.SelectedItems;
+ var openMgr = ServiceRegistry.GetService<OpenResourceManager>();
+ var connMgr = ServiceRegistry.GetService<ServerConnectionManager>();
+ _conn = connMgr.GetConnection(wb.ActiveSiteExplorer.ConnectionName);
+
+ if (items.Length == 1)
+ {
+ var item = items[0];
+ if (!item.IsFolder)
+ {
+ if (openMgr.IsOpen(item.ResourceId))
+ {
+ var ed = openMgr.GetOpenEditor(item.ResourceId);
+ if (!(ed is XmlEditor))
+ {
+ MessageService.ShowMessage(Properties.Resources.ResourceAlreadyOpened);
+ return;
+ }
+ else
+ {
+ ed.Activate();
+ }
+ }
+ else
+ {
+ openMgr.Open(item.ResourceId, _conn, true);
+ }
+ }
+ }
+ }
+ }
+}
Modified: sandbox/maestro-3.0/Maestro.Base/Maestro.Base.addin
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Maestro.Base.addin 2010-08-05 17:38:22 UTC (rev 5071)
+++ sandbox/maestro-3.0/Maestro.Base/Maestro.Base.addin 2010-08-06 05:11:06 UTC (rev 5072)
@@ -318,7 +318,10 @@
<Condition action="Disable" name="SelectedItem">
<MenuItem id="Open"
label="${res:SiteExplorer_SelectedItem_Open}"
- class="Maestro.Base.Commands.NotImplementedCommand" />
+ class="Maestro.Base.Commands.SiteExplorer.OpenResourceCommand" />
+ <MenuItem id="OpenXml"
+ label="${res:SiteExplorer_SelectedItem_OpenWithXmlEditor}"
+ class="Maestro.Base.Commands.SiteExplorer.OpenWithXmlEditorCommand" />
<MenuItem id="Rename"
label="${res:SiteExplorer_SelectedItem_Rename}"
class="Maestro.Base.Commands.NotImplementedCommand" />
Modified: sandbox/maestro-3.0/Maestro.Base/Maestro.Base.csproj
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Maestro.Base.csproj 2010-08-05 17:38:22 UTC (rev 5071)
+++ sandbox/maestro-3.0/Maestro.Base/Maestro.Base.csproj 2010-08-06 05:11:06 UTC (rev 5072)
@@ -64,6 +64,7 @@
<Compile Include="Commands\SaveResourceCommand.cs" />
<Compile Include="Commands\SiteExplorer\DisconnectCommand.cs" />
<Compile Include="Commands\SiteExplorer\OpenResourceCommand.cs" />
+ <Compile Include="Commands\SiteExplorer\OpenWithXmlEditorCommand.cs" />
<Compile Include="Commands\SiteExplorer\RefreshCommand.cs" />
<Compile Include="Commands\SiteExplorer\ResourcePropertiesCommand.cs" />
<Compile Include="Commands\SiteExplorer\ValidateCommand.cs" />
Modified: sandbox/maestro-3.0/Maestro.Base/Properties/Resources.Designer.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Properties/Resources.Designer.cs 2010-08-05 17:38:22 UTC (rev 5071)
+++ sandbox/maestro-3.0/Maestro.Base/Properties/Resources.Designer.cs 2010-08-06 05:11:06 UTC (rev 5072)
@@ -753,6 +753,15 @@
}
/// <summary>
+ /// Looks up a localized string similar to This resource is already opened in another editor.
+ /// </summary>
+ internal static string ResourceAlreadyOpened {
+ get {
+ return ResourceManager.GetString("ResourceAlreadyOpened", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Failed to decode the current bounds,
///you must re-enter the epsg code in the SRS tag manually.
///Error message: {0}..
@@ -1023,6 +1032,15 @@
}
/// <summary>
+ /// Looks up a localized string similar to Open Resource with XML Editor.
+ /// </summary>
+ internal static string SiteExplorer_SelectedItem_OpenWithXmlEditor {
+ get {
+ return ResourceManager.GetString("SiteExplorer_SelectedItem_OpenWithXmlEditor", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Properties.
/// </summary>
internal static string SiteExplorer_SelectedItem_Properties {
Modified: sandbox/maestro-3.0/Maestro.Base/Properties/Resources.resx
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Properties/Resources.resx 2010-08-05 17:38:22 UTC (rev 5071)
+++ sandbox/maestro-3.0/Maestro.Base/Properties/Resources.resx 2010-08-06 05:11:06 UTC (rev 5072)
@@ -613,4 +613,10 @@
<data name="ValidationNoIssues" xml:space="preserve">
<value>No issues found during validation</value>
</data>
+ <data name="ResourceAlreadyOpened" xml:space="preserve">
+ <value>This resource is already opened in another editor</value>
+ </data>
+ <data name="SiteExplorer_SelectedItem_OpenWithXmlEditor" xml:space="preserve">
+ <value>Open Resource with XML Editor</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-08-05 17:38:22 UTC (rev 5071)
+++ sandbox/maestro-3.0/Maestro.Base/Services/OpenResourceManager.cs 2010-08-06 05:11:06 UTC (rev 5072)
@@ -71,6 +71,15 @@
return GetRegisteredEditor(rtd);
}
+ /// <summary>
+ /// Opens the specified resource using its assigned editor. If the resource is already
+ /// open, the the existing editor view is activated instead. If the resource has no assigned
+ /// editor or <see cref="useXmlEditor"/> is true, the resource will be opened in the default
+ /// XML editor.
+ /// </summary>
+ /// <param name="res"></param>
+ /// <param name="conn"></param>
+ /// <param name="useXmlEditor"></param>
public void Open(IResource res, IServerConnection conn, bool useXmlEditor)
{
string resourceId = res.ResourceID;
@@ -143,5 +152,15 @@
return ed;
}
+
+ internal bool IsOpen(string resourceId)
+ {
+ return _openItems.ContainsKey(resourceId);
+ }
+
+ internal IEditorViewContent GetOpenEditor(string resourceId)
+ {
+ return _openItems[resourceId];
+ }
}
}
More information about the mapguide-commits
mailing list