/// <summary>
        ///     Document we are tracking selection on is closing, ensure we clean everything up.
        /// </summary>
        private void OnDocumentClosing(object sender, EventArgs args)
        {
            Debug.Assert(_currentDocData != null, "null docData in DocumentClosing event");
            if (_currentDocData != null)
            {
                try
                {
                    // clear tree data, causes event handlers to be removed from our branches.
                    if (_treeProvider != null)
                    {
                        _treeProvider.Root = null;
                    }

                    // clear cached selection
                    _currentSelection    = null;
                    _currentBrowseObject = null;

                    // disable column event handlers
                    Debug.Assert(_currentDocData.Store != null, "unable to remove column event handlers");
                    if (_currentDocData.Store != null)
                    {
                        _treeControl.RemoveColumnEventHandlers();
                    }

                    // NOTE: It's important to cast here, otherwise a wrong overload would be called
                    // and selection container would not be cleared leading to strange problems - e.g.
                    // properties window might call refresh on disposed store etc.
                    DoSelectionChanged((object)null);
                }
                finally
                {
                    // Unsubscribe from document closing event
                    _currentDocData.DocumentClosing -= OnDocumentClosing;
                    _currentDocData = null;
                }
            }
        }