[mapguide-commits] r7044 - in trunk/Tools/Maestro: Maestro.Base Maestro.Base/Commands Maestro.Base/Events Maestro.Base/UI Maestro.Shared.UI OSGeo.MapGuide.MaestroAPI/Resource
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Tue Sep 25 05:40:20 PDT 2012
Author: jng
Date: 2012-09-25 05:40:19 -0700 (Tue, 25 Sep 2012)
New Revision: 7044
Added:
trunk/Tools/Maestro/Maestro.Base/UI/ResourceIdNavigator.cs
Modified:
trunk/Tools/Maestro/Maestro.Base/Commands/StartupCommand.cs
trunk/Tools/Maestro/Maestro.Base/Events/EventWatcher.cs
trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
trunk/Tools/Maestro/Maestro.Base/Strings.Designer.cs
trunk/Tools/Maestro/Maestro.Base/Strings.resx
trunk/Tools/Maestro/Maestro.Base/UI/ISiteExplorer.cs
trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorer.cs
trunk/Tools/Maestro/Maestro.Shared.UI/ViewContentManagerBase.cs
trunk/Tools/Maestro/Maestro.Shared.UI/WorkbenchBase.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Resource/ResourceIdentifier.cs
Log:
#2130: This submission implements a Resource ID "address bar". Along the way, we added some extra support APIs needed for this feature to work, and also fixed the behaviour of ResourceIdentifier.Validate()
Modified: trunk/Tools/Maestro/Maestro.Base/Commands/StartupCommand.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/StartupCommand.cs 2012-09-25 08:08:42 UTC (rev 7043)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/StartupCommand.cs 2012-09-25 12:40:19 UTC (rev 7044)
@@ -51,7 +51,7 @@
wb.Text = "MapGuide Maestro"; //NOXLATE
var mgr = ServiceRegistry.GetService<ViewContentManager>();
-
+
if (Props.Get(ConfigProperties.ShowMessages, true))
mgr.OpenContent<MessageViewer>(ViewRegion.Bottom);
Modified: trunk/Tools/Maestro/Maestro.Base/Events/EventWatcher.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Events/EventWatcher.cs 2012-09-25 08:08:42 UTC (rev 7043)
+++ trunk/Tools/Maestro/Maestro.Base/Events/EventWatcher.cs 2012-09-25 12:40:19 UTC (rev 7044)
@@ -110,6 +110,13 @@
() => { return new SiteExplorer(); });
wb.ActiveSiteExplorer.ActiveConnectionChanged += new EventHandler(OnActiveConnectionChanged);
+
+ var connMgr = ServiceRegistry.GetService<ServerConnectionManager>();
+ var openMgr = ServiceRegistry.GetService<OpenResourceManager>();
+ var siteExp = wb.ActiveSiteExplorer;
+
+ var nav = new ResourceIdNavigator(connMgr, openMgr, viewMgr, siteExp);
+ wb.AddToolbar("Resource ID Bar", nav.NavigatorToolStrip, ToolbarRegion.Top, true);
}
wb.ActiveSiteExplorer.RefreshModel(name);
Modified: trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj 2012-09-25 08:08:42 UTC (rev 7043)
+++ trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj 2012-09-25 12:40:19 UTC (rev 7044)
@@ -396,6 +396,7 @@
<DependentUpon>ResourceHeaderXmlDialog.cs</DependentUpon>
</Compile>
<Compile Include="UI\ResourceIconCache.cs" />
+ <Compile Include="UI\ResourceIdNavigator.cs" />
<Compile Include="UI\ResourcePropertiesDialog.cs">
<SubType>Form</SubType>
</Compile>
Modified: trunk/Tools/Maestro/Maestro.Base/Strings.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Strings.Designer.cs 2012-09-25 08:08:42 UTC (rev 7043)
+++ trunk/Tools/Maestro/Maestro.Base/Strings.Designer.cs 2012-09-25 12:40:19 UTC (rev 7044)
@@ -560,6 +560,15 @@
}
/// <summary>
+ /// Looks up a localized string similar to No Active Connection.
+ /// </summary>
+ internal static string ErrorNoActiveConnection {
+ get {
+ return ResourceManager.GetString("ErrorNoActiveConnection", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Unknown executable specified: {0}.
/// </summary>
internal static string ErrorUnknownExecutable {
@@ -758,6 +767,33 @@
}
/// <summary>
+ /// Looks up a localized string similar to Go.
+ /// </summary>
+ internal static string Label_Go {
+ get {
+ return ResourceManager.GetString("Label_Go", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Open this resource.
+ /// </summary>
+ internal static string Label_OpenResource {
+ get {
+ return ResourceManager.GetString("Label_OpenResource", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Resource ID:.
+ /// </summary>
+ internal static string Label_ResourceID {
+ get {
+ return ResourceManager.GetString("Label_ResourceID", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Tools.
/// </summary>
internal static string Label_Tools {
Modified: trunk/Tools/Maestro/Maestro.Base/Strings.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Strings.resx 2012-09-25 08:08:42 UTC (rev 7043)
+++ trunk/Tools/Maestro/Maestro.Base/Strings.resx 2012-09-25 12:40:19 UTC (rev 7044)
@@ -971,4 +971,16 @@
<data name="XmlResHandlerAction" xml:space="preserve">
<value>Load this resource into the Site Repository</value>
</data>
+ <data name="ErrorNoActiveConnection" xml:space="preserve">
+ <value>No Active Connection</value>
+ </data>
+ <data name="Label_Go" xml:space="preserve">
+ <value>Go</value>
+ </data>
+ <data name="Label_ResourceID" xml:space="preserve">
+ <value>Resource ID:</value>
+ </data>
+ <data name="Label_OpenResource" xml:space="preserve">
+ <value>Open this resource</value>
+ </data>
</root>
\ No newline at end of file
Modified: trunk/Tools/Maestro/Maestro.Base/UI/ISiteExplorer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/UI/ISiteExplorer.cs 2012-09-25 08:08:42 UTC (rev 7043)
+++ trunk/Tools/Maestro/Maestro.Base/UI/ISiteExplorer.cs 2012-09-25 12:40:19 UTC (rev 7044)
@@ -82,8 +82,15 @@
/// Gets the items currently selected
/// </summary>
RepositoryItem[] SelectedItems { get; }
+
+ /// <summary>
+ /// Raised when the selected item(s) changes
+ /// </summary>
+ event RepositoryItemEventHandler ItemsSelected;
}
+ public delegate void RepositoryItemEventHandler(object sender, RepositoryItem[] items);
+
public enum NodeFlagAction
{
/*
Added: trunk/Tools/Maestro/Maestro.Base/UI/ResourceIdNavigator.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/UI/ResourceIdNavigator.cs (rev 0)
+++ trunk/Tools/Maestro/Maestro.Base/UI/ResourceIdNavigator.cs 2012-09-25 12:40:19 UTC (rev 7044)
@@ -0,0 +1,252 @@
+#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 ICSharpCode.Core;
+using Maestro.Base.Editor;
+using Maestro.Base.Services;
+using OSGeo.MapGuide.MaestroAPI;
+using OSGeo.MapGuide.MaestroAPI.Resource;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace Maestro.Base.UI
+{
+ public class ResourceIdNavigator
+ {
+ // How this tool strip is visually laid out
+ //
+ // [Resource ID: ][ComboBox: Resource ID][@][ComboBox: Active Connections][ Go =>]
+ //
+
+ private ToolStrip _strip;
+
+ private ToolStripLabel _resIdLabel;
+ private ToolStripComboBox _cmbResourceId;
+ private ToolStripLabel _atLabel;
+ private ToolStripComboBox _cmbActiveConnections;
+ private ToolStripButton _btnGo;
+
+ private ServerConnectionManager _connMgr;
+ private OpenResourceManager _omgr;
+ private ISiteExplorer _siteExp;
+ private ViewContentManager _viewMgr;
+
+ public ResourceIdNavigator(ServerConnectionManager connMgr,
+ OpenResourceManager omgr,
+ ViewContentManager viewMgr,
+ ISiteExplorer siteExp)
+ {
+ _connMgr = connMgr;
+ _connMgr.ConnectionAdded += OnConnectionAdded;
+ _connMgr.ConnectionRemoved += OnConnectionRemoved;
+
+ _omgr = omgr;
+ _viewMgr = viewMgr;
+ _viewMgr.ViewActivated += OnViewActivated;
+
+ _siteExp = siteExp;
+ _siteExp.ItemsSelected += OnSiteExplorerItemsSelected;
+
+ _strip = new ToolStrip();
+ _strip.Layout += OnToolStripLayout;
+ _strip.Stretch = true;
+
+ _resIdLabel = new ToolStripLabel(Strings.Label_ResourceID);
+ _cmbResourceId = new ToolStripComboBox();
+ _cmbResourceId.AutoSize = false;
+ _cmbResourceId.Width = 250;
+ _cmbResourceId.TextChanged += OnResourceIdChanged;
+ _cmbResourceId.KeyUp += OnResourceIdKeyUp;
+
+ _atLabel = new ToolStripLabel("@"); //NOXLATE
+ _cmbActiveConnections = new ToolStripComboBox();
+ _cmbActiveConnections.AutoSize = false;
+ _cmbActiveConnections.Width = 250;
+ _cmbActiveConnections.ComboBox.SelectedIndexChanged += OnActiveConnectionChanged;
+ _cmbActiveConnections.ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
+
+ _btnGo = new ToolStripButton(Strings.Label_Go);
+ _btnGo.Image = Properties.Resources.arrow;
+ _btnGo.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
+ _btnGo.TextImageRelation = TextImageRelation.TextBeforeImage;
+ _btnGo.ToolTipText = Strings.Label_OpenResource;
+ _btnGo.Click += btnGo_Click;
+
+ UpdateConnectionList();
+ UpdateNavigationState();
+
+ _strip.Items.AddRange(new ToolStripItem[]
+ {
+ _resIdLabel,
+ _cmbResourceId,
+ _atLabel,
+ _cmbActiveConnections,
+ _btnGo
+ });
+ }
+
+ void OnSiteExplorerItemsSelected(object sender, RepositoryItem[] items)
+ {
+ if (items == null)
+ return;
+
+ if (items.Length != 1)
+ return;
+
+ var idx = _cmbActiveConnections.Items.IndexOf(items[0].ConnectionName);
+ if (idx >= 0)
+ {
+ _cmbResourceId.Text = items[0].ResourceId;
+ _cmbActiveConnections.SelectedIndex = idx;
+ }
+ }
+
+ private bool bNoRaiseEvents = false;
+
+ void OnViewActivated(object sender, Shared.UI.IViewContent content)
+ {
+ var ed = content as IEditorViewContent;
+ if (ed != null && !ed.IsNew)
+ {
+ var conn = ed.Resource.CurrentConnection;
+ var idx = _cmbActiveConnections.Items.IndexOf(conn.DisplayName);
+ if (idx >= 0)
+ {
+ _cmbActiveConnections.SelectedIndex = idx;
+ _cmbResourceId.Text = ed.EditorService.ResourceID;
+ }
+ }
+ }
+
+ void OnResourceIdKeyUp(object sender, KeyEventArgs e)
+ {
+ if (_btnGo.Enabled && (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return))
+ {
+ DoNavigate();
+ }
+ }
+
+ void OnActiveConnectionChanged(object sender, EventArgs e)
+ {
+ _cmbActiveConnections.ToolTipText = (string)_cmbActiveConnections.SelectedItem ?? string.Empty;
+ }
+
+ void OnToolStripLayout(object sender, LayoutEventArgs e)
+ {
+ int width = _strip.DisplayRectangle.Width;
+ foreach (ToolStripItem tsi in _strip.Items)
+ {
+ if (!(tsi == _cmbResourceId))
+ {
+ width -= tsi.Width;
+ width -= tsi.Margin.Horizontal;
+ }
+ }
+ _cmbResourceId.Width = Math.Max(0, width - _cmbResourceId.Margin.Horizontal);
+ }
+
+ void OnResourceIdChanged(object sender, EventArgs e)
+ {
+ UpdateNavigationState();
+ }
+
+ private void UpdateNavigationState()
+ {
+ _btnGo.Enabled = ResourceIdentifier.Validate(_cmbResourceId.Text) && !ResourceIdentifier.IsFolderResource(_cmbResourceId.Text);
+ }
+
+ void OnConnectionRemoved(object sender, string name)
+ {
+ UpdateConnectionList();
+ }
+
+ void OnConnectionAdded(object sender, string name)
+ {
+ UpdateConnectionList();
+ }
+
+ void btnGo_Click(object sender, EventArgs e)
+ {
+ DoNavigate();
+ }
+
+ private void DoNavigate()
+ {
+ var conn = GetActiveConnection();
+ if (conn != null)
+ {
+ string resId = _cmbResourceId.Text;
+ if (!ResourceIdentifier.Validate(resId))
+ {
+ MessageService.ShowError(OSGeo.MapGuide.MaestroAPI.Strings.ErrorInvalidResourceIdentifier);
+ }
+ else
+ {
+ if (_omgr.IsOpen(resId, conn))
+ {
+ var ed = _omgr.GetOpenEditor(resId, conn);
+ ed.Activate();
+ }
+ else
+ {
+ _omgr.Open(resId, conn, false, _siteExp);
+ }
+ }
+ }
+ else
+ {
+ MessageService.ShowError(Strings.ErrorNoActiveConnection);
+ }
+ }
+
+ private IServerConnection GetActiveConnection()
+ {
+ if (_cmbActiveConnections.SelectedItem != null)
+ {
+ return _connMgr.GetConnection(_cmbActiveConnections.SelectedItem.ToString());
+ }
+ return null;
+ }
+
+ private void UpdateConnectionList()
+ {
+ var connNames = _connMgr.GetConnectionNames();
+ _btnGo.Enabled = connNames.Count > 0;
+ _cmbActiveConnections.ComboBox.Items.Clear();
+ if (connNames.Count > 0)
+ {
+ foreach (var name in connNames)
+ {
+ _cmbActiveConnections.ComboBox.Items.Add(name);
+ }
+ _cmbActiveConnections.ComboBox.SelectedIndex = 0;
+ }
+ else
+ {
+ _cmbActiveConnections.ToolTipText = Strings.ErrorNoActiveConnection; //Not a real "error" just re-using the same message
+ }
+ UpdateNavigationState();
+ }
+
+ public ToolStrip NavigatorToolStrip { get { return _strip; } }
+ }
+}
Modified: trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorer.cs 2012-09-25 08:08:42 UTC (rev 7043)
+++ trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorer.cs 2012-09-25 12:40:19 UTC (rev 7044)
@@ -96,8 +96,14 @@
_currentConnectionName = connName;
OnActiveConnectionChanged();
}
+
+ var h = this.ItemsSelected;
+ if (h != null)
+ h(this, this.SelectedItems);
}
+ public event RepositoryItemEventHandler ItemsSelected;
+
public string ConnectionName
{
get
Modified: trunk/Tools/Maestro/Maestro.Shared.UI/ViewContentManagerBase.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Shared.UI/ViewContentManagerBase.cs 2012-09-25 08:08:42 UTC (rev 7043)
+++ trunk/Tools/Maestro/Maestro.Shared.UI/ViewContentManagerBase.cs 2012-09-25 12:40:19 UTC (rev 7044)
@@ -30,6 +30,7 @@
protected List<IViewContent> _singletonInstances = new List<IViewContent>();
public event EventHandler ViewHidden;
+ public event ViewEventHandler ViewActivated;
protected abstract WorkbenchBase GetWorkbench();
@@ -102,6 +103,9 @@
if (!cnt.IsAttached)
wb.ShowContent(cnt);
cnt.Activate();
+ var h = this.ViewActivated;
+ if (h != null)
+ h(this, cnt);
//wb.CheckContainerStatus();
return;
}
@@ -141,6 +145,9 @@
if (!cnt.IsAttached)
wb.ShowContent(cnt);
cnt.Activate();
+ var h = this.ViewActivated;
+ if (h != null)
+ h(this, cnt);
//wb.CheckContainerStatus();
return (T)cnt;
}
@@ -158,4 +165,6 @@
return obj;
}
}
+
+ public delegate void ViewEventHandler(object sender, IViewContent content);
}
Modified: trunk/Tools/Maestro/Maestro.Shared.UI/WorkbenchBase.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Shared.UI/WorkbenchBase.cs 2012-09-25 08:08:42 UTC (rev 7043)
+++ trunk/Tools/Maestro/Maestro.Shared.UI/WorkbenchBase.cs 2012-09-25 12:40:19 UTC (rev 7044)
@@ -81,8 +81,9 @@
toolbar = _workbenchInitializer.GetMainToolStrip(this);
toolbar.Stretch = true;
+ toolbar.Tag = BASE_TOOLSTRIP;
- AddToolbar("Base", toolbar, ToolbarRegion.Top, true); //NOXLATE
+ AddToolbar(toolbar.Tag.ToString(), toolbar, ToolbarRegion.Top, true); //NOXLATE
status = new StatusStrip();
statusLabel = new ToolStripStatusLabel();
@@ -95,6 +96,8 @@
Application.Idle += OnApplicationIdle;
}
+ const string BASE_TOOLSTRIP = "Base"; //NOXLATE
+
protected virtual void OnViewActivated(object sender, IViewContent content) { }
private Dictionary<string, ToolStrip> _toolstrips;
@@ -129,7 +132,7 @@
switch (region)
{
case ToolbarRegion.Top:
- toolStripContainer.TopToolStripPanel.Controls.Add(toolbar);
+ AddTopToolStrip(toolbar);
break;
case ToolbarRegion.Bottom:
toolStripContainer.BottomToolStripPanel.Controls.Add(toolbar);
@@ -168,7 +171,7 @@
toolStripContainer.RightToolStripPanel.Controls.Add(strip);
break;
case ToolbarRegion.Top:
- toolStripContainer.TopToolStripPanel.Controls.Add(strip);
+ AddTopToolStrip(strip);
break;
}
}
@@ -193,6 +196,39 @@
}
}
+ //SUPER-DUPER HACK: ToolStrip objects are added in the most unintuitive manner when ordering is a concern
+ //
+ //You'd think first one added will be the top-most tool strip. Nope! Not at all!
+ //So we need this hacky method to ensure the base toolstrip will always be the top-most one
+
+ private void AddTopToolStrip(ToolStrip strip)
+ {
+ var panel = toolStripContainer.TopToolStripPanel;
+ if ((string)strip.Tag == BASE_TOOLSTRIP)
+ panel.Controls.Add(strip);
+ else
+ {
+ var controls = new List<Control>();
+ panel.SuspendLayout();
+ Control baseTs = null;
+ for (int i = 0; i < panel.Controls.Count; i++)
+ {
+ if ((string)panel.Controls[i].Tag == BASE_TOOLSTRIP)
+ baseTs = panel.Controls[i];
+ else
+ controls.Add(panel.Controls[i]);
+ }
+ panel.Controls.Clear();
+ foreach (var cnt in controls)
+ {
+ panel.Controls.Add(cnt);
+ }
+ panel.Controls.Add(baseTs);
+ panel.Controls.Add(strip);
+ panel.ResumeLayout();
+ }
+ }
+
/// <summary>
/// Gets the toolbar.
/// </summary>
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Resource/ResourceIdentifier.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Resource/ResourceIdentifier.cs 2012-09-25 08:08:42 UTC (rev 7043)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Resource/ResourceIdentifier.cs 2012-09-25 12:40:19 UTC (rev 7044)
@@ -457,6 +457,13 @@
if (identifier.IndexOf(".") < 0 && !identifier.EndsWith("/")) //NOXLATE
return false;
+ if (identifier == StringConstants.RootIdentifier)
+ return true;
+
+ if (IsFolderResource(identifier))
+ return true;
+
+ var rt = GetResourceType(identifier);
}
catch
{
More information about the mapguide-commits
mailing list