Exemplo n.º 1
0
        /// <summary>
        /// Tries to close a specified window..
        /// </summary>
        /// <param name="view"></param>
        /// <param name="bRemove"></param>
        public void CloseWindow(IDockableViewModel view, bool bRemove)
        {
            string accessKey = this.SelectedShellViewModel.FullFileName;

            if (this.IsTransientViewModel(view.GetType()))
            {
                accessKey = TransientPanesKey;
            }

            if (!viewLookup.ContainsKey(accessKey))
            {
                return;
            }

            if (viewLookup[accessKey].ContainsKey(view.DockingPaneName))
            {
                ViewLookUp v = viewLookup[view.DockingPaneName][accessKey];
                if (v.Pane != null)
                {
                    (v.Pane.Frame as IVsWindowFrame).CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave);
                }
                else
                {
                    view.IsDockingPaneVisible = false;

                    if (this.SelectedShellViewModel.VisibleDocumentPanes.Contains(view))
                    {
                        this.SelectedShellViewModel.HiddenDocumentPanes.Add(this.SelectedShellViewModel.SelectedDocumentPane);
                        this.SelectedShellViewModel.VisibleDocumentPanes.Remove(this.SelectedShellViewModel.SelectedDocumentPane);
                    }

                    if (this.SelectedShellViewModel.VisibleDocumentPanes.Count == 0)
                    {
                        this.SelectedShellViewModel.SelectedDocumentPane = null;
                    }
                }

                // TODO ?
                if (bRemove)
                {
                    // remove pane from lookup
                    //this.viewLookup.Remove(view.DockingPaneName);
                }
            }

            if (this.IsTransientViewModel(view.GetType()))
            {
                // update all IsDockingPaneVisible
                foreach (ShellMainViewModel v in this.packageController.AvailableShellVMs.Keys)
                {
                    BaseDockingViewModel foundVm = v.FindViewModel(view.GetType());
                    foundVm.IsDockingPaneVisible = false;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tries to bring the view displaying the given view model to the front.
        /// </summary>
        /// <param name="view"></param>
        public void BringToFrontWindow(IDockableViewModel view)
        {
            string accessKey = this.SelectedShellViewModel.FullFileName;

            if (this.IsTransientViewModel(view.GetType()))
            {
                accessKey = TransientPanesKey;
            }

            if (!viewLookup.ContainsKey(accessKey))
            {
                return;
            }

            if (viewLookup[accessKey].ContainsKey(view.DockingPaneName))
            {
                ViewLookUp v = viewLookup[accessKey][view.DockingPaneName];
                if (v.Pane != null)
                {
                    (v.Pane.Frame as IVsWindowFrame).Show();
                }
                else
                {
                    this.SelectedShellViewModel.SelectedDocumentPane = view;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads a specific window configuration.
        /// </summary>
        /// <param name="name">Name of the configuration.</param>
        /// <param name="dockableViews">Existing dockable views.</param>
        /// <param name="bAckForceRestore">Acknoledge the force restore parameter that is set whenever a document is loaded for the first time (no document loaded before).</param>
        /// /// <param name="fullFileName">Full file name fo the shell vm.</param>
        public void RestoreConfiguration(string name, IEnumerable dockableViews, bool bAckForceRestore, string fullFileName)
        {
            if (this.configuration == null)
            {
                this.LoadConfigurations();
            }

            if (bAckForceRestore)
            {
                if (!this.bForceLoadLayout)
                {
                    return;
                }
            }

            if (!this.configuration.Configurations.ContainsKey(name))
            {
                // restore default layout
                this.RestoreDefaultWindows(dockableViews, name, fullFileName);
            }
            else
            {
                // restore windows
                Dictionary <string, IDockableViewModel> existingPanes = new Dictionary <string, IDockableViewModel>();
                foreach (IDockableViewModel p in dockableViews)
                {
                    existingPanes.Add(p.DockingPaneName, p);
                }

                DockingLayoutContextConfiguration config = this.configuration.Configurations[name];
                foreach (string n in config.Configurations.Keys)
                {
                    if (!existingPanes.ContainsKey(n))
                    {
                        this.OnRestoreLayoutMissingVMEncountered(config.Configurations[n]);
                    }
                    else
                    {
                        if (config.Configurations[n].IsVisible)
                        {
                            IDockableViewModel p = existingPanes[n];
                            if (this.IsTransientViewModel(p.GetType()))
                            {
                                if (this.viewLookup.ContainsKey(TransientPanesKey))
                                {
                                    if (this.viewLookup[TransientPanesKey].ContainsKey(p.DockingPaneName))
                                    {
                                        continue;
                                    }
                                }
                                ShowWindow(p, p.DockingPaneStyle, p.DockingPaneAnchorStyle, TransientPanesKey);
                            }
                            else
                            {
                                if (this.viewLookup.ContainsKey(fullFileName))
                                {
                                    if (this.viewLookup[fullFileName].ContainsKey(p.DockingPaneName))
                                    {
                                        continue;
                                    }
                                }
                                ShowWindow(p, p.DockingPaneStyle, p.DockingPaneAnchorStyle, fullFileName);
                            }
                        }
                    }
                }

                // restore layout ?
                // ..
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Shows a docking window for a given view.
        /// If is has been shown before, restore its position. Otherwise dock it to the right side.
        /// </summary>
        /// <param name="view">View to dock.</param>
        /// <param name="dockingStyle">Docking style.</param>
        /// <param name="dockingAnchorStyle">Docking anchor style. Only usefull for DockingPaneStyle.Docked.</param>
        /// <param name="dockedInDocumentPane">True if this view should be shown in the document pane window. False otherwise.</param>
        /// <param name="fullFileName">File name.</param>
        public virtual void ShowWindow(IDockableViewModel view, DockingPaneStyle dockingStyle, DockingPaneAnchorStyle dockingAnchorStyle, bool dockedInDocumentPane, string fullFileName)
        {
            if (!view.IsInitialized)
            {
                view.InitializeVM();
            }

            string accessKey = fullFileName;

            if (this.IsTransientViewModel(view.GetType()))
            {
                accessKey = TransientPanesKey;
                if (viewLookup.ContainsKey(TransientPanesKey))
                {
                    if (viewLookup[TransientPanesKey].ContainsKey(view.DockingPaneName))
                    {
                        ModelToolWindowPane p = viewLookup[TransientPanesKey][view.DockingPaneName].Pane;
                        if (p != null)
                        {
                            if (((IVsWindowFrame)p.Frame).IsVisible() != VSConstants.S_OK)
                            {
                                return;
                            }
                        }
                    }
                }
            }
            if (!viewLookup.ContainsKey(accessKey))
            {
                viewLookup.Add(accessKey, new Dictionary <string, ViewLookUp>());
            }

            if (!viewLookup[accessKey].ContainsKey(view.DockingPaneName))
            {
                if (!dockedInDocumentPane)
                {
                    int key;
                    if (!this.viewTypeNameLookup.ContainsKey(view.DockingPaneType.FullName))
                    {
                        key = 0;
                    }
                    else
                    {
                        key = this.viewTypeNameLookup[view.DockingPaneType.FullName].Count;
                    }

                    ModelToolWindowPane window = this.package.FindToolWindow(this.package.GetToolWindowType(view.DockingPaneType), key, true) as ModelToolWindowPane;
                    if ((window == null) || (window.Frame == null))
                    {
                        throw new NotSupportedException("Can not show window!");
                    }
                    window.Content.DataContext = view;
                    window.Caption             = view.DockingPaneTitle;

                    // subscribe to events
                    window.PaneClosed += new EventHandler(Window_PaneClosed);

                    // get window frame
                    IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;

                    // add lookup information
                    viewLookup[accessKey][view.DockingPaneName] = new ViewLookUp(view, window);
                    view.IsDockingPaneVisible = true;
                    paneViewLookup.Add(ModelPackage.GetPersistenceSlot(windowFrame), view.DockingPaneName);

                    if (!this.viewTypeNameLookup.ContainsKey(view.DockingPaneType.FullName))
                    {
                        this.viewTypeNameLookup[view.DockingPaneType.FullName] = new List <string>();
                    }
                    this.viewTypeNameLookup[view.DockingPaneType.FullName].Add(view.DockingPaneName);

                    // show window
                    windowFrame.Show();
                }
                else
                {
                    viewLookup[accessKey][view.DockingPaneName] = new ViewLookUp(view);

                    if (accessKey != TransientPanesKey)
                    {
                        this.packageController.AvailableShellVMsReversed[accessKey].VisibleDocumentPanes.Add(view);
                        if (this.packageController.AvailableShellVMsReversed[accessKey].SelectedDocumentPane == null)
                        {
                            this.packageController.AvailableShellVMsReversed[accessKey].SelectedDocumentPane = view;
                        }
                    }
                    else
                    {
                        this.SelectedShellViewModel.VisibleDocumentPanes.Add(view);
                        if (this.SelectedShellViewModel.SelectedDocumentPane == null)
                        {
                            this.SelectedShellViewModel.SelectedDocumentPane = view;
                        }
                    }
                    view.IsDockingPaneVisible = true;
                }
            }

            // show docking window
            if (!dockedInDocumentPane)
            {
                if (viewLookup[accessKey][view.DockingPaneName].Pane != null)
                {
                    if (((IVsWindowFrame)viewLookup[accessKey][view.DockingPaneName].Pane.Frame).IsVisible() != VSConstants.S_OK)
                    {
                        ((IVsWindowFrame)viewLookup[accessKey][view.DockingPaneName].Pane.Frame).Show();
                        viewLookup[accessKey][view.DockingPaneName].View.IsDockingPaneVisible = true;
                    }
                }
            }
            else
            {
                if (this.SelectedShellViewModel.HiddenDocumentPanes.Contains(view))
                {
                    this.SelectedShellViewModel.HiddenDocumentPanes.Remove(view);
                    this.SelectedShellViewModel.VisibleDocumentPanes.Add(view);

                    if (this.SelectedShellViewModel.SelectedDocumentPane == null)
                    {
                        this.SelectedShellViewModel.SelectedDocumentPane = view;
                    }
                }
                view.IsDockingPaneVisible = true;
            }

            if (this.IsTransientViewModel(view.GetType()))
            {
                // update all IsDockingPaneVisible
                foreach (ShellMainViewModel v in this.packageController.AvailableShellVMs.Keys)
                {
                    BaseDockingViewModel foundVm = v.FindViewModel(view.GetType());
                    foundVm.IsDockingPaneVisible = true;
                }
            }
        }
        /// <summary>
        /// Tries to close a specified window..
        /// </summary>
        /// <param name="view"></param>
        /// <param name="bRemove"></param>
        public void CloseWindow(IDockableViewModel view, bool bRemove)
        {
            string accessKey = this.SelectedShellViewModel.FullFileName;
            if (this.IsTransientViewModel(view.GetType()))
                accessKey = TransientPanesKey;

            if (!viewLookup.ContainsKey(accessKey))
                return;

            if (viewLookup[accessKey].ContainsKey(view.DockingPaneName))
            {
                ViewLookUp v = viewLookup[view.DockingPaneName][accessKey];
                if (v.Pane != null)
                {
                    (v.Pane.Frame as IVsWindowFrame).CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave);
                }
                else
                {
                    view.IsDockingPaneVisible = false;

                    if (this.SelectedShellViewModel.VisibleDocumentPanes.Contains(view))
                    {
                        this.SelectedShellViewModel.HiddenDocumentPanes.Add(this.SelectedShellViewModel.SelectedDocumentPane);
                        this.SelectedShellViewModel.VisibleDocumentPanes.Remove(this.SelectedShellViewModel.SelectedDocumentPane);
                    }

                    if (this.SelectedShellViewModel.VisibleDocumentPanes.Count == 0)
                        this.SelectedShellViewModel.SelectedDocumentPane = null;
                }

                // TODO ?
                if( bRemove )
                {
                    // remove pane from lookup
                    //this.viewLookup.Remove(view.DockingPaneName);
                }
            }

            if (this.IsTransientViewModel(view.GetType()))
            {
                // update all IsDockingPaneVisible
                foreach (ShellMainViewModel v in this.packageController.AvailableShellVMs.Keys)
                {
                    BaseDockingViewModel foundVm = v.FindViewModel(view.GetType());
                    foundVm.IsDockingPaneVisible = false;
                }
            }
        }
        /// <summary>
        /// Tries to bring the view displaying the given view model to the front.
        /// </summary>
        /// <param name="view"></param>
        public void BringToFrontWindow(IDockableViewModel view)
        {
            string accessKey = this.SelectedShellViewModel.FullFileName;
            if (this.IsTransientViewModel(view.GetType()))
                accessKey = TransientPanesKey;

            if (!viewLookup.ContainsKey(accessKey))
                return;

            if (viewLookup[accessKey].ContainsKey(view.DockingPaneName))
            {
                ViewLookUp v = viewLookup[accessKey][view.DockingPaneName];
                if (v.Pane != null)
                {
                    (v.Pane.Frame as IVsWindowFrame).Show();
                }
                else
                {
                    this.SelectedShellViewModel.SelectedDocumentPane = view;
                }
            }
        }
        /// <summary>
        /// Shows a docking window for a given view.  
        /// If is has been shown before, restore its position. Otherwise dock it to the right side.
        /// </summary>
        /// <param name="view">View to dock.</param>
        /// <param name="dockingStyle">Docking style.</param>
        /// <param name="dockingAnchorStyle">Docking anchor style. Only usefull for DockingPaneStyle.Docked.</param>
        /// <param name="dockedInDocumentPane">True if this view should be shown in the document pane window. False otherwise.</param>
        /// <param name="fullFileName">File name.</param>
        public virtual void ShowWindow(IDockableViewModel view, DockingPaneStyle dockingStyle, DockingPaneAnchorStyle dockingAnchorStyle, bool dockedInDocumentPane, string fullFileName)
        {
            if (!view.IsInitialized)
                view.InitializeVM();

            string accessKey = fullFileName;
            if (this.IsTransientViewModel(view.GetType()))
            {
                accessKey = TransientPanesKey;
                if( viewLookup.ContainsKey(TransientPanesKey) )
                    if (viewLookup[TransientPanesKey].ContainsKey(view.DockingPaneName))
                    {
                        ModelToolWindowPane p = viewLookup[TransientPanesKey][view.DockingPaneName].Pane;
                        if (p != null)
                        {
                            if (((IVsWindowFrame)p.Frame).IsVisible() != VSConstants.S_OK)
                                return;
                        }
                    }
            }
            if (!viewLookup.ContainsKey(accessKey))
                viewLookup.Add(accessKey, new Dictionary<string, ViewLookUp>());

            if (!viewLookup[accessKey].ContainsKey(view.DockingPaneName))
            {
                if (!dockedInDocumentPane)
                {
                    int key;
                    if (!this.viewTypeNameLookup.ContainsKey(view.DockingPaneType.FullName))
                        key = 0;
                    else
                        key = this.viewTypeNameLookup[view.DockingPaneType.FullName].Count;

                    ModelToolWindowPane window = this.package.FindToolWindow(this.package.GetToolWindowType(view.DockingPaneType), key, true) as ModelToolWindowPane;
                    if ((window == null) || (window.Frame == null))
                    {
                        throw new NotSupportedException("Can not show window!");
                    }
                    window.Content.DataContext = view;
                    window.Caption = view.DockingPaneTitle;

                    // subscribe to events
                    window.PaneClosed += new EventHandler(Window_PaneClosed);

                    // get window frame
                    IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;

                    // add lookup information
                    viewLookup[accessKey][view.DockingPaneName] = new ViewLookUp(view, window);
                    view.IsDockingPaneVisible = true;
                    paneViewLookup.Add(ModelPackage.GetPersistenceSlot(windowFrame), view.DockingPaneName);

                    if (!this.viewTypeNameLookup.ContainsKey(view.DockingPaneType.FullName))
                        this.viewTypeNameLookup[view.DockingPaneType.FullName] = new List<string>();
                    this.viewTypeNameLookup[view.DockingPaneType.FullName].Add(view.DockingPaneName);

                    // show window
                    windowFrame.Show();

                }
                else
                {
                    viewLookup[accessKey][view.DockingPaneName] = new ViewLookUp(view);

                    if (accessKey != TransientPanesKey)
                    {
                        this.packageController.AvailableShellVMsReversed[accessKey].VisibleDocumentPanes.Add(view);
                        if (this.packageController.AvailableShellVMsReversed[accessKey].SelectedDocumentPane == null)
                            this.packageController.AvailableShellVMsReversed[accessKey].SelectedDocumentPane = view;
                    }
                    else
                    {
                        this.SelectedShellViewModel.VisibleDocumentPanes.Add(view);
                        if (this.SelectedShellViewModel.SelectedDocumentPane == null)
                            this.SelectedShellViewModel.SelectedDocumentPane = view;
                    }
                    view.IsDockingPaneVisible = true;                    
                }
            }

            // show docking window
            if (!dockedInDocumentPane)
            {
                if (viewLookup[accessKey][view.DockingPaneName].Pane != null)
                    if (((IVsWindowFrame)viewLookup[accessKey][view.DockingPaneName].Pane.Frame).IsVisible() != VSConstants.S_OK)
                    {
                        ((IVsWindowFrame)viewLookup[accessKey][view.DockingPaneName].Pane.Frame).Show();
                        viewLookup[accessKey][view.DockingPaneName].View.IsDockingPaneVisible = true;
                    }
            }
            else
            {
                if (this.SelectedShellViewModel.HiddenDocumentPanes.Contains(view))
                {
                    this.SelectedShellViewModel.HiddenDocumentPanes.Remove(view);
                    this.SelectedShellViewModel.VisibleDocumentPanes.Add(view);

                    if (this.SelectedShellViewModel.SelectedDocumentPane == null)
                        this.SelectedShellViewModel.SelectedDocumentPane = view;
                }
                view.IsDockingPaneVisible = true;
            }

            if (this.IsTransientViewModel(view.GetType()))
            {
                // update all IsDockingPaneVisible
                foreach (ShellMainViewModel v in this.packageController.AvailableShellVMs.Keys)
                {
                    BaseDockingViewModel foundVm = v.FindViewModel(view.GetType());
                    foundVm.IsDockingPaneVisible = true;
                }
            }
        }