From: <mcu...@us...> - 2008-12-20 03:37:08
|
Revision: 1345 http://orm.svn.sourceforge.net/orm/?rev=1345&view=rev Author: mcurland Date: 2008-12-20 03:37:05 +0000 (Sat, 20 Dec 2008) Log Message: ----------- Modify the toolbox handling in the ORM Diagram Spy window to handle dynamic toolbox contents introduced with the shape extensions in [1344]. refs #376 refs #380 Modified Paths: -------------- trunk/ORMModel/Framework/Design/PropertyProvider.cs trunk/ORMModel/Framework/FrameworkServices.cs trunk/ORMModel/Framework/Shell/MultiDiagramDocView.cs trunk/ORMModel/Framework/Shell/MultiDiagramDocViewControl.cs trunk/ORMModel/ShapeModel/ORMDiagram.cs trunk/ORMModel/Shell/ORMDesignerCommandManager.cs trunk/ORMModel/Shell/ORMDiagramSpy.cs trunk/ORMModel/Shell/ORMDocData.cs trunk/ORMModel/Shell/ORMDocDataServices.cs trunk/ORMModel/Shell/ORMDocView.cs Modified: trunk/ORMModel/Framework/Design/PropertyProvider.cs =================================================================== --- trunk/ORMModel/Framework/Design/PropertyProvider.cs 2008-12-17 02:27:45 UTC (rev 1344) +++ trunk/ORMModel/Framework/Design/PropertyProvider.cs 2008-12-20 03:37:05 UTC (rev 1345) @@ -88,6 +88,18 @@ this.myProviderDictionary = new Dictionary<RuntimeTypeHandle, PropertyProvider>(RuntimeTypeHandleComparer.Instance); } #endregion // Constructor + #region Accessor Properties + /// <summary> + /// Get the context <see cref="Store"/> + /// </summary> + public Store Store + { + get + { + return myStore; + } + } + #endregion // Access Properties #region IPropertyProviderService implementation void IPropertyProviderService.AddOrRemovePropertyProvider<TExtendableElement>(PropertyProvider provider, bool includeSubtypes, EventHandlerAction action) { Modified: trunk/ORMModel/Framework/FrameworkServices.cs =================================================================== --- trunk/ORMModel/Framework/FrameworkServices.cs 2008-12-17 02:27:45 UTC (rev 1344) +++ trunk/ORMModel/Framework/FrameworkServices.cs 2008-12-20 03:37:05 UTC (rev 1345) @@ -83,6 +83,16 @@ myStore = store; } /// <summary> + /// The current <see cref="Store"/> + /// </summary> + public Store Store + { + get + { + return myStore; + } + } + /// <summary> /// Get an array of providers of the requested type, or null if the interface is not implemented /// </summary> public T[] GetTypedDomainModelProviders<T>() where T : class Modified: trunk/ORMModel/Framework/Shell/MultiDiagramDocView.cs =================================================================== --- trunk/ORMModel/Framework/Shell/MultiDiagramDocView.cs 2008-12-17 02:27:45 UTC (rev 1344) +++ trunk/ORMModel/Framework/Shell/MultiDiagramDocView.cs 2008-12-20 03:37:05 UTC (rev 1345) @@ -55,7 +55,7 @@ /// <summary> /// Determine when the toolbox should be refreshed /// </summary> - private Type myLastDiagramType; + private Type myLastToolboxDiagramType; private MultiDiagramDocViewControl DocViewControl { get @@ -86,19 +86,49 @@ protected override void OnSelectionChanged(EventArgs e) { base.OnSelectionChanged(e); - Diagram diagram = CurrentDiagram; + if (UpdateToolboxDiagram(CurrentDiagram)) + { + RefreshDiagramToolboxItems(); + } + } + /// <summary> + /// Update the type of diagram that sources the toolbox items for this document. If this + /// returns <see langword="true"/>, then it is the responsibility of the caller to call + /// <see cref="IToolboxService.Refresh"/> after updating the current toolbox filters. + /// </summary> + /// <param name="diagram">The <see cref="Diagram"/> to activate</param> + /// <returns><see langword="true"/> if the diagram type is changed</returns> + /// <remarks>The toolbox service always requests toolbox items from the document window, even + /// when the active selection container in a tool window supports the <see cref="Microsoft.VisualStudio.Shell.Interop.IVsToolboxUser"/> + /// interface. Derived classes can reimplement <see cref="Microsoft.VisualStudio.Shell.Interop.IVsToolboxUser"/> to redirect to the + /// implementation on an active toolwindow, but the document window needs to know the type of the + /// last diagram for which items were requested by both the document and tool windows. This enables + /// the items to be refreshed when the selection container is switched back and forth between the + /// document window and the tool window toolbox users.</remarks> + public bool UpdateToolboxDiagram(Diagram diagram) + { Type diagramType; if (diagram != null && - (diagramType = diagram.GetType()) != myLastDiagramType) + (diagramType = diagram.GetType()) != myLastToolboxDiagramType) { - myLastDiagramType = diagramType; - IToolboxService toolboxService; - if (this.UpdateToolboxFilters(ToolboxItemFilterType.Diagram, true) && (null != (toolboxService = base.ToolboxService))) - { - toolboxService.Refresh(); - } + myLastToolboxDiagramType = diagramType; + return true; } + return false; } + /// <summary> + /// Helper method to perform toolbox filter refresh. Should only call if <see cref="UpdateToolboxDiagram"/> returns true. + /// </summary> + private void RefreshDiagramToolboxItems() + { + IToolboxService toolboxService; + if (null != (toolboxService = base.ToolboxService)) + { + // We refresh on this request regardless of the response from UpdateToolboxFilters + UpdateToolboxFilters(ToolboxItemFilterType.Diagram, true); + toolboxService.Refresh(); + } + } #endregion // Base Overrides #region Public Properties #region Context Menu support @@ -328,6 +358,33 @@ } } #endregion // ReorderDiagrams method + #region DeactivateMouseActions method + /// <summary> + /// Verify that all mouse actions for the specified <see cref="DiagramView"/> + /// are canceled. Mouse actions are also canceled for the active view on the + /// associated <see cref="Diagram"/>. + /// </summary> + public static void DeactivateMouseActions(DiagramView diagramView) + { + if (diagramView != null) + { + MouseAction mouseAction; + if (null != (mouseAction = diagramView.ActiveMouseAction)) + { + diagramView.ActiveMouseAction = null; + } + Diagram diagram; + DiagramView activeView; + if (null != (diagram = diagramView.Diagram) && + null != (activeView = diagram.ActiveDiagramView) && + activeView != diagramView && + null != (mouseAction = activeView.ActiveMouseAction)) + { + diagramView.ActiveMouseAction = null; + } + } + } + #endregion // DeactivateMouseActions method #region Add methods /// <summary> /// Adds the <see cref="Diagram"/> specified by <paramref name="diagram"/> to this <see cref="MultiDiagramDocView"/>. @@ -573,7 +630,7 @@ if (0 != (reasons & EventSubscriberReasons.DocumentLoaded)) { // Force toolbox refresh on next selection change - myLastDiagramType = null; + myLastToolboxDiagramType = null; // Attach extra properties and events if we're tracking diagram order and position Store store = this.Store; Modified: trunk/ORMModel/Framework/Shell/MultiDiagramDocViewControl.cs =================================================================== --- trunk/ORMModel/Framework/Shell/MultiDiagramDocViewControl.cs 2008-12-17 02:27:45 UTC (rev 1344) +++ trunk/ORMModel/Framework/Shell/MultiDiagramDocViewControl.cs 2008-12-20 03:37:05 UTC (rev 1345) @@ -298,6 +298,10 @@ if (tabPage != null) { tabPage.Focus(); + if (DocView.UpdateToolboxDiagram(((DiagramTabPage)tabPage).Diagram)) + { + DocView.RefreshDiagramToolboxItems(); + } } } #endregion // OnGotFocus method @@ -416,6 +420,26 @@ DocView.SetSelectedComponents(null); } } + protected override void OnSelecting(TabControlCancelEventArgs e) + { + DiagramTabPage tabPage; + if (e.Action == TabControlAction.Selecting && + null != (tabPage = e.TabPage as DiagramTabPage)) + { + DeactivateMouseActions(tabPage.Designer); + } + base.OnSelecting(e); + } + protected override void OnDeselecting(TabControlCancelEventArgs e) + { + DiagramTabPage tabPage; + if (e.Action == TabControlAction.Deselecting && + null != (tabPage = e.TabPage as DiagramTabPage)) + { + DeactivateMouseActions(tabPage.Designer); + } + base.OnDeselecting(e); + } #endregion // OnSelectedIndexChanged method #region IndexOf methods public int IndexOf(DiagramView designer, int startingIndex) Modified: trunk/ORMModel/ShapeModel/ORMDiagram.cs =================================================================== --- trunk/ORMModel/ShapeModel/ORMDiagram.cs 2008-12-17 02:27:45 UTC (rev 1344) +++ trunk/ORMModel/ShapeModel/ORMDiagram.cs 2008-12-20 03:37:05 UTC (rev 1345) @@ -1319,7 +1319,7 @@ // during a chained mouse action cancels the action. // See corresponding code in ExternalConstraintConnectAction.ChainMouseAction and // InternalUniquenessConstraintConnectAction.ChainMouseAction. - (action != null || activeView.Toolbox.GetSelectedToolboxItem() != null)) + (action != null || (activeView != null && activeView.Toolbox.GetSelectedToolboxItem() != null))) { clientView.ActiveMouseAction = action; } Modified: trunk/ORMModel/Shell/ORMDesignerCommandManager.cs =================================================================== --- trunk/ORMModel/Shell/ORMDesignerCommandManager.cs 2008-12-17 02:27:45 UTC (rev 1344) +++ trunk/ORMModel/Shell/ORMDesignerCommandManager.cs 2008-12-20 03:37:05 UTC (rev 1345) @@ -41,6 +41,7 @@ namespace Neumont.Tools.ORM.Shell { + #region IORMDesignerView interface /// <summary> /// An interface representing a container that displays an ORM diagram. /// Abstracting the view enables commands to be handled/ the same for @@ -89,7 +90,246 @@ /// </summary> object PrimarySelection { get;} } + #endregion // IORMDesignerView interface + #region ToolboxFilterSet enum /// <summary> + /// The type of selection filter type to check. Used by <see cref="ToolboxFilterCache.UpdateFilters"/> + /// </summary> + [Flags] + public enum ToolboxFilterSet + { + /// <summary> + /// Update the filters for the currently selected item + /// </summary> + Selection = 1, + /// <summary> + /// Update the filters for the current diagram + /// </summary> + Diagram = 2, + /// <summary> + /// Udpate all filters + /// </summary> + All = Selection | Diagram, + } + #endregion // ToolboxFilterSet enum + #region ToolboxFilterCache class + /// <summary> + /// A class to manage toolbox filters as the selection in a <see cref="IORMDesignerView"/> implementation is modified + /// </summary> + [CLSCompliant(false)] + public class ToolboxFilterCache + { + // Use positive values for diagram items, negative for selection + private Dictionary<object, int> myFilterCache = new Dictionary<object, int>(); + private int myDiagramCookie; + private int mySelectionCookie; + private int myDiagramFilterCount; + private int mySelectionFilterCount; + private object[] myFilterCollection; + /// <summary> + /// Update the current toolbox filters to correspond to the current selection in <paramref name="designerView"/> + /// </summary> + /// <param name="designerView">The current <see cref="IORMDesignerView"/> to populate settings for</param> + /// <param name="filterType">The <see cref="ToolboxFilterSet"/> indicating the set of toolbox items to update</param> + /// <returns><see langword="true"/> if the filter set is changed.</returns> + public bool UpdateFilters(IORMDesignerView designerView, ToolboxFilterSet filterType) + { + Dictionary<object, int> filterCache = myFilterCache; + int diagramCookie = myDiagramCookie; + int selectionCookie = mySelectionCookie; + bool repopulate = false; + + // Check for first pass + if (diagramCookie == 0) + { + diagramCookie = NewDiagramCookie(); + filterType = ToolboxFilterSet.All; + } + if (selectionCookie == 0) + { + selectionCookie = NewSelectionCookie(); + filterType = ToolboxFilterSet.All; + } + + // Update the diagram information + if (0 != (filterType & ToolboxFilterSet.Diagram)) + { + Diagram diagram; + ICollection filters; + if (null != (diagram = designerView.CurrentDiagram) && + null != (filters = diagram.TargetToolboxItemFilterAttributes)) + { + int oldCount = myDiagramFilterCount; + int newCount = 0; + if (oldCount != 0) + { + int oldCookie = diagramCookie; + diagramCookie = NewDiagramCookie(); + foreach (object filter in filters) + { + int testCookie; + if (filterCache.TryGetValue(filter, out testCookie)) + { + filterCache[filter] = diagramCookie; + if (oldCookie != testCookie) + { + // Filter was not included in previous count + repopulate = true; + } + ++newCount; + } + else + { + filterCache[filter] = diagramCookie; + ++newCount; + repopulate = true; + } + } + if (!repopulate && newCount != oldCount) + { + repopulate = true; + } + } + else + { + foreach (object filter in filters) + { + // We updated the cookie when the count was set to zero, no reason to repeat + filterCache[filter] = diagramCookie; + ++newCount; + } + if (newCount != 0) + { + repopulate = true; + } + } + myDiagramFilterCount = newCount; + } + else if (myDiagramFilterCount != 0) + { + diagramCookie = NewDiagramCookie(); + myDiagramFilterCount = 0; + repopulate = true; + } + } + if (0 != (filterType & ToolboxFilterSet.Selection)) + { + IList selectedElements; + ShapeElement selectedShape; + ICollection filters; + if (null != (selectedElements = designerView.SelectedElements) && + 1 == selectedElements.Count && + null != (selectedShape = selectedElements[0] as ShapeElement) && + selectedShape != designerView.CurrentDiagram && + null != (filters = selectedShape.TargetToolboxItemFilterAttributes)) + { + int oldCount = mySelectionFilterCount; + int newCount = 0; + if (oldCount != 0) + { + int oldCookie = selectionCookie; + selectionCookie = NewSelectionCookie(); + foreach (object filter in filters) + { + int testCookie; + if (filterCache.TryGetValue(filter, out testCookie)) + { + filterCache[filter] = selectionCookie; + if (oldCookie != testCookie) + { + // Filter was not included in previous count + repopulate = true; + } + ++newCount; + } + else + { + filterCache[filter] = selectionCookie; + ++newCount; + repopulate = true; + } + } + if (!repopulate && newCount != oldCount) + { + repopulate = true; + } + } + else + { + foreach (object filter in filters) + { + // We updated the cookie when the count was set to zero, no reason to repeat + filterCache[filter] = selectionCookie; + ++newCount; + } + if (newCount != 0) + { + repopulate = true; + } + } + mySelectionFilterCount = newCount; + } + else if (mySelectionFilterCount != 0) + { + selectionCookie = NewSelectionCookie(); + mySelectionFilterCount = 0; + repopulate = true; + } + } + if (repopulate) + { + myFilterCollection = null; + } + return repopulate; + } + /// <summary> + /// Get a collection of all current toolbox filters + /// </summary> + public ICollection ToolboxFilters + { + get + { + object[] filters = myFilterCollection; + if (filters == null) + { + int totalCount = myDiagramFilterCount + mySelectionFilterCount; + myFilterCollection = filters = new object[totalCount]; + if (totalCount != 0) + { + int index = -1; + int diagramCookie = myDiagramCookie; + int selectionCookie = mySelectionCookie; + foreach (KeyValuePair<object, int> pair in myFilterCache) + { + int testValue = pair.Value; + if (testValue == diagramCookie || testValue == selectionCookie) + { + filters[++index] = pair.Key; + } + } + } + } + return filters; + } + } + private int NewDiagramCookie() + { + // Diagram cookies are positive + int cookie = myDiagramCookie; + myDiagramCookie = cookie = (cookie == int.MaxValue) ? 1 : (cookie + 1); + return cookie; + } + private int NewSelectionCookie() + { + // Selection cookies are negative + int cookie = mySelectionCookie; + mySelectionCookie = cookie = (cookie == int.MinValue) ? -11 : (cookie - 1); + return cookie; + } + } + #endregion // ToolboxFilterCache class + #region ORMDesignerCommandManager class + /// <summary> /// Handle command routing for views on the ORM designer /// </summary> [CLSCompliant(false)] @@ -3024,4 +3264,5 @@ } #endregion // Command Handlers } + #endregion // ORMDesignerCommandManager class } Modified: trunk/ORMModel/Shell/ORMDiagramSpy.cs =================================================================== --- trunk/ORMModel/Shell/ORMDiagramSpy.cs 2008-12-17 02:27:45 UTC (rev 1344) +++ trunk/ORMModel/Shell/ORMDiagramSpy.cs 2008-12-20 03:37:05 UTC (rev 1345) @@ -32,6 +32,8 @@ using Microsoft.VisualStudio.Shell.Interop; using Neumont.Tools.Modeling.Shell; using Neumont.Tools.Modeling; +using OLE = Microsoft.VisualStudio.OLE.Interop; +using System.Drawing.Design; namespace Neumont.Tools.ORM.Shell { @@ -41,7 +43,7 @@ /// </summary> [Guid("19A5C15D-14D4-4A88-9891-A3294077BE56")] [CLSCompliant(false)] - public class ORMDiagramSpyWindow : ORMToolWindow, IORMSelectionContainer, IProvideFrameVisibility, IORMDesignerView + public class ORMDiagramSpyWindow : ORMToolWindow, IORMSelectionContainer, IProvideFrameVisibility, IORMDesignerView, IVsToolboxUser { #region Member Variables private ToolWindowDiagramView myDiagramView; @@ -49,6 +51,8 @@ private LinkLabel myWatermarkLabel; private bool myDiagramSetChanged; private bool myDisassociating; + private IToolboxService myToolboxService; + private ToolboxFilterCache myToolboxFilterCache; private Store myStore; #endregion // Member Variables #region Constructor @@ -117,11 +121,13 @@ } if (!reselectOldDiagram) { + MultiDiagramDocView.DeactivateMouseActions(diagram.ActiveDiagramView); diagram.Associate(diagramView); } AdjustVisibility(true, false); if (!calledShow) { + calledShow = true; Show(); } if (reselectOldDiagram && diagramView.Selection.PrimaryItem != null) @@ -133,6 +139,12 @@ { SetSelectedComponents(new object[] { diagram }); } + DiagramClientView clientView; + if (calledShow && + !(clientView = diagramView.DiagramClientView).Focused) + { + clientView.Focus(); + } return true; } } @@ -236,7 +248,7 @@ myDiagramSetChanged = true; if (element == myDiagramView.Diagram) { - // Note that this is unlikely, the diagram will be disassociatin firts + // Note that this is unlikely, the diagram will be disassociated first AdjustVisibility(false, true); } } @@ -250,6 +262,7 @@ myDisassociating = true; try { + MultiDiagramDocView.DeactivateMouseActions(diagramView); diagram.Disassociate(diagramView); } finally @@ -288,16 +301,17 @@ } private void AdjustVisibility(bool diagramVisible, bool deferRebuildWatermark) { + DiagramView diagramView = myDiagramView; if (!diagramVisible) { - DiagramView view = myDiagramView; - Diagram diagram = view.Diagram; + Diagram diagram = diagramView.Diagram; if (diagram != null) { myDisassociating = true; try { - diagram.Disassociate(view); + MultiDiagramDocView.DeactivateMouseActions(diagramView); + diagram.Disassociate(diagramView); } finally { @@ -311,7 +325,7 @@ RebuildWatermark(); } } - myDiagramView.Visible = diagramVisible; + diagramView.Visible = diagramVisible; myWatermarkLabel.Visible = !diagramVisible; } private void RebuildWatermark() @@ -453,7 +467,32 @@ protected override void OnSelectionChanged(EventArgs e) { CommandManager.UpdateCommandStatus(); + UpdateToolbox(); } + /// <summary> + /// Update the toolbox when this window is activated + /// </summary> + protected override void OnORMSelectionContainerChanged() + { + if (CurrentORMSelectionContainer == this) + { + UpdateToolbox(); + } + } + private void UpdateToolbox() + { + MultiDiagramDocView docView; + if (null != (docView = CurrentDocumentView as MultiDiagramDocView) && + docView.UpdateToolboxDiagram(CurrentDiagram)) + { + IToolboxService toolboxService; + if (null != (toolboxService = ToolboxService)) + { + ToolboxFilterManager.UpdateFilters(this, ToolboxFilterSet.Diagram); + toolboxService.Refresh(); + } + } + } #endregion //ORMToolWindow overrides #region IORMDesignerView Implementation /// <summary> @@ -668,5 +707,68 @@ this.MenuService.ShowContextMenu(contextMenuId, pt.X, pt.Y); } #endregion // ContextMenu + #region IVsToolboxUser Implementation + /// <summary> + /// Get the <see cref="IToolboxService"/> for this object + /// </summary> + protected IToolboxService ToolboxService + { + get + { + return myToolboxService ?? (myToolboxService = (IToolboxService)ExternalServiceProvider.GetService(typeof(IToolboxService))); + } + } + /// <summary> + /// Get the <see cref="ToolboxFilterManager"/> for this window + /// </summary> + protected ToolboxFilterCache ToolboxFilterManager + { + get + { + ToolboxFilterCache retVal = myToolboxFilterCache; + if (retVal == null) + { + myToolboxFilterCache = retVal = new ToolboxFilterCache(); + retVal.UpdateFilters(this, ToolboxFilterSet.All); + } + return retVal; + } + } + /// <summary> + /// Implements <see cref="IVsToolboxUser.IsSupported"/> + /// </summary> + protected int IsSupported(OLE.IDataObject pDO) + { + IDataObject data = pDO as IDataObject; + if (data == null) + { + data = new DataObject(pDO); + } + IToolboxService toolboxService; + if (null != (toolboxService = ToolboxService)) + { + if (toolboxService.IsSupported(data, ToolboxFilterManager.ToolboxFilters)) + { + return VSConstants.S_OK; + } + } + return VSConstants.E_FAIL; + } + int IVsToolboxUser.IsSupported(OLE.IDataObject pDO) + { + return IsSupported(pDO); + } + /// <summary> + /// Implements <see cref="IVsToolboxUser.ItemPicked"/> + /// </summary> + protected static int ItemPicked(OLE.IDataObject pDO) + { + return VSConstants.S_OK; + } + int IVsToolboxUser.ItemPicked(OLE.IDataObject pDO) + { + return ItemPicked(pDO); + } + #endregion // IVsToolboxUser Implementation } } Modified: trunk/ORMModel/Shell/ORMDocData.cs =================================================================== --- trunk/ORMModel/Shell/ORMDocData.cs 2008-12-17 02:27:45 UTC (rev 1344) +++ trunk/ORMModel/Shell/ORMDocData.cs 2008-12-20 03:37:05 UTC (rev 1345) @@ -202,13 +202,13 @@ if (isReload) { - this.RemoveModelingEventHandlers(isReload); - // Null out the myPropertyProviderService and myTypedDomainModelProviderCache fields // so that a new instance will be created with the new Store next time it is needed this.myPropertyProviderService = null; this.myTypedDomainModelProviderCache = null; + this.RemoveModelingEventHandlers(isReload); + foreach (ModelingDocView view in DocViews) { MultiDiagramDocView multiDiagramDocView = view as MultiDiagramDocView; Modified: trunk/ORMModel/Shell/ORMDocDataServices.cs =================================================================== --- trunk/ORMModel/Shell/ORMDocDataServices.cs 2008-12-17 02:27:45 UTC (rev 1344) +++ trunk/ORMModel/Shell/ORMDocDataServices.cs 2008-12-20 03:37:05 UTC (rev 1345) @@ -1065,7 +1065,19 @@ { get { - return myPropertyProviderService ?? (myPropertyProviderService = new PropertyProviderService(Store)); + // Defensively verify store state + PropertyProviderService providers = myPropertyProviderService as PropertyProviderService; + Store store = Store; + if (providers == null || providers.Store != store) + { + if (store.ShuttingDown || store.Disposed) + { + myPropertyProviderService = null; + return null; + } + myPropertyProviderService = providers = new PropertyProviderService(store); + } + return providers; } } IPropertyProviderService IFrameworkServices.PropertyProviderService @@ -1081,10 +1093,17 @@ /// </summary> protected T[] GetTypedDomainModelProviders<T>() where T : class { + // Defensively verify store state TypedDomainModelProviderCache cache = myTypedDomainModelProviderCache; - if (cache == null) + Store store = Store; + if (cache == null || cache.Store != store) { - myTypedDomainModelProviderCache = cache = new TypedDomainModelProviderCache(Store); + if (store.ShuttingDown || store.Disposed) + { + myTypedDomainModelProviderCache = null; + return null; + } + myTypedDomainModelProviderCache = cache = new TypedDomainModelProviderCache(store); } return cache.GetTypedDomainModelProviders<T>(); } Modified: trunk/ORMModel/Shell/ORMDocView.cs =================================================================== --- trunk/ORMModel/Shell/ORMDocView.cs 2008-12-17 02:27:45 UTC (rev 1344) +++ trunk/ORMModel/Shell/ORMDocView.cs 2008-12-20 03:37:05 UTC (rev 1345) @@ -31,6 +31,7 @@ using Neumont.Tools.ORM.ObjectModel; using Neumont.Tools.ORM.ShapeModel; using Neumont.Tools.Modeling; +using Microsoft.VisualStudio.Shell.Interop; namespace Neumont.Tools.ORM.Shell { @@ -266,10 +267,11 @@ /// <see cref="DiagramDocView"/> designed to contain multiple <see cref="ORMDiagram"/>s. /// </summary> [CLSCompliant(false)] - public partial class ORMDesignerDocView : MultiDiagramDocView, IORMSelectionContainer, IORMDesignerView, IModelingEventSubscriber + public partial class ORMDesignerDocView : MultiDiagramDocView, IORMSelectionContainer, IORMDesignerView, IModelingEventSubscriber, IVsToolboxUser { #region Member variables private IServiceProvider myCtorServiceProvider; + private IMonitorSelectionService myMonitorSelectionService; private ORMDesignerCommandManager myCommandManager; #endregion // Member variables #region Construction/destruction @@ -819,6 +821,16 @@ } }); } + /// <summary> + /// Get the selection service for this designer + /// </summary> + protected IMonitorSelectionService MonitorSelection + { + get + { + return myMonitorSelectionService ?? (myMonitorSelectionService = (IMonitorSelectionService)myCtorServiceProvider.GetService(typeof(IMonitorSelectionService))); + } + } #endregion // ORMDesignerDocView Specific #region IORMDesignerView Implementation /// <summary> @@ -860,5 +872,39 @@ } } #endregion // IORMDesignerView Implementation + #region IVsToolboxUser Toolwindow Redirection + int IVsToolboxUser.IsSupported(Microsoft.VisualStudio.OLE.Interop.IDataObject pDO) + { + // Redirect toolbox queries to supporting tool windows if the document is not the + // active selection container. + object selectionContainer = MonitorSelection.CurrentSelectionContainer; + IVsToolboxUser redirectUser; + IORMDesignerView designerView; + if (selectionContainer != this && + null != (redirectUser = selectionContainer as IVsToolboxUser) && + null != (designerView = selectionContainer as IORMDesignerView) && + null != designerView.CurrentDiagram) + { + return redirectUser.IsSupported(pDO); + } + return IsSupported(pDO); + } + int IVsToolboxUser.ItemPicked(Microsoft.VisualStudio.OLE.Interop.IDataObject pDO) + { + // Redirect toolbox queries to supporting tool windows if the document is not the + // active selection container. + object selectionContainer = MonitorSelection.CurrentSelectionContainer; + IVsToolboxUser redirectUser; + IORMDesignerView designerView; + if (selectionContainer != this && + null != (redirectUser = selectionContainer as IVsToolboxUser) && + null != (designerView = selectionContainer as IORMDesignerView) && + null != designerView.CurrentDiagram) + { + return redirectUser.ItemPicked(pDO); + } + return ItemPicked(pDO); + } + #endregion // IVsToolboxUser Toolwindow Redirection } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |