Beispiel #1
0
        void OnNodeSelected(object sender, SelectionChangedEventArgs e)
        {
            UpdateHistoryButtons();

            IView[] newViews;
            if (e.Selection == null)
            {
                newViews = new IView[0];
            }
            else if (!e.Selection.ShowViews)
            {
                return;
            }
            else
            {
                newViews = Views.LocateViews(e.Selection).ToArray();
            }

            var newActualViews = new Dictionary <IView, DockContent>();

            foreach (var view in newViews)
            {
                DockContent content;
                if (!currentViews.TryGetValue(view, out content))
                {
                    content = new DockContent {
                        HideOnClose        = true,
                        CloseButtonVisible = false,
                        CloseButton        = false
                    };
                    content.DockHandler.ActivateOnShow = false;
                    view.ViewControl.Dock = DockStyle.Fill;
                    UpdateViewContainer(e.Selection.Node, view, content);

                    content.Controls.Add(view.ViewControl);
                    Modules.Activate();
                }
                newActualViews.Add(view, content);
            }

            DockArea.SuspendLayout(true);

            IDockContent activeView = null;

            if (currentViews.Count > 0)
            {
                activeView = currentViews.Values.First().PanelPane.ActiveContent;
            }
            if (!newActualViews.Values.Contains(activeView))
            {
                activeView = null;
            }

            foreach (var view in newActualViews)
            {
                view.Key.Model = e.Selection;
                view.Value.Show(DockArea, DockState.Document);
                if (activeView == null)
                {
                    activeView = view.Value;
                }
            }

            foreach (var prevView in currentViews)
            {
                if (!newActualViews.ContainsKey(prevView.Key))
                {
                    prevView.Value.Hide();
                    prevView.Key.Model = null;
                }
                else
                {
                    UpdateViewContainer(e.Selection.Node, prevView.Key, prevView.Value);
                }
            }
            currentViews = newActualViews;

            if (activeView != null)
            {
                activeView.DockHandler.PanelPane.ActiveContent = activeView;
            }
            Modules.Activate();
            DockArea.ResumeLayout(true, true);
        }