src/Misc/EFTools/DesignXmlCore/Base/Shell/TreeGridDesignerToolWindow.cs
/// <summary>
///     Fired when the current document changes.
/// </summary>
/// <param name="oldView">Previous DocData</param>
/// <param name="newView">Current DocData</param>
Fired when the current document changes.
Fired when the current document changes .
protected override void OnDocumentWindowChanged(ModelingDocView oldView, ModelingDocView newView)
        {
            var newModelingData = newView != null ? newView.DocData : null;
            if (newModelingData != null
                && IsDocumentSupported(newModelingData))
            {
                var store = newModelingData.Store;
                if (store != null)
                {
                    if (_currentDocData != null)
                    {
                        if (newModelingData.Store != _currentDocData.Store)
                        {
                            if (_treeProvider != null)
                            {
                                _treeProvider.Root = null;
                            }
                            _currentSelection = null;
                            _currentBrowseObject = null;
                        }
                        _treeControl.RemoveColumnEventHandlers();
                        _currentDocData.DocumentClosing -= OnDocumentClosing;
                    }
                    _treeControl.AddColumnEventHandlers();
                    newModelingData.DocumentClosing += OnDocumentClosing;
                    _currentDocData = newModelingData;
                }
            }
            else
            {
                var oldModelingData = oldView != null ? oldView.DocData : null;
                if (oldModelingData != null
                    && IsDocumentSupported(oldModelingData))
                {
                    _currentBrowseObject = PrimarySelection;
                    SetSelectedComponents(new object[] { });
                    if (_containerControl != null)
                    {
                        _containerControl.WatermarkVisible = true;
                    }
                }
            }
        }
protected override void OnDocumentWindowChanged ( ModelingDocView oldView , ModelingDocView newView ) { var newModelingData = newView != null ? newView . DocData : null ; if ( newModelingData != null && IsDocumentSupported ( newModelingData ) ) { var store = newModelingData . Store ; if ( store != null ) { if ( _currentDocData != null ) { if ( newModelingData . Store != _currentDocData . Store ) { if ( _treeProvider != null ) { _treeProvider . Root = null ; } _currentSelection = null ; _currentBrowseObject = null ; } _treeControl . RemoveColumnEventHandlers ( ) ; _currentDocData . DocumentClosing -= OnDocumentClosing ; } _treeControl . AddColumnEventHandlers ( ) ; newModelingData . DocumentClosing += OnDocumentClosing ; _currentDocData = newModelingData ; } } else { var oldModelingData = oldView != null ? oldView . DocData : null ; if ( oldModelingData != null && IsDocumentSupported ( oldModelingData ) ) { _currentBrowseObject = PrimarySelection ; SetSelectedComponents ( new object [ ] { } ) ; if ( _containerControl != null ) { _containerControl . WatermarkVisible = true ; } } } }
Fired when the current document changes.
Fired when the current document changes .
// if we're switching stores, make sure we clear the tree.  Prevents store disposed exceptions if // the currentDocData.Store is disposed before we switch back to it. // clear tree data, causes event handlers to be removed from our branches. // clear cached selection // disable column event handlers // unsubscribe from document closing event // enable column event handlers // subscribe to document closing event // cache the doc data, so we can unsubscribe properly.  We cannot // unsubscribe using oldView.DocData, because we may get an OnDocumentWindowChanged(oldModelingData, null)  // just prior to a document close.  In that case, we'd unsubscribe too early, and not clean up properly // in OnDocumentClosed.  Instead we wait until either we get a new supported document, or the old one closes. // it's possible that the oldView is not some docData we support, in that case, don't do anything // Null or unsupported view, clear our selection context.  Note that we leave the tree populated // here so that in the common case of switching back and forth between designer and code, we  // don't lose selection/expansion state in the tree.  We also clear/save the selection context, // because we don't want to push anything to the property browser while the watermark is showing.
oldView
ModelingDocView
None
newView
ModelingDocView
None