Exemple #1
0
        /// <summary>
        /// Shows a docking window for a given view.
        /// If is has been shown before, restore it position. Otherwise dock it to the right side.
        /// </summary>
        /// <param name="name">View to show.</param>
        /// <param name="dockingStyle">Docking style.</param>
        /// <param name="dockingAnchorStyle">Docking anchor style. Only usefull for DockingPaneStyle.Docked.</param>
        /// <returns></returns>
        public IDockableViewModel ShowWindow(string name, DockingPaneStyle dockingStyle, DockingPaneAnchorStyle dockingAnchorStyle)
        {
            IDockableViewModel d         = null;
            string             accessKey = this.SelectedShellViewModel.FullFileName;

            if (this.viewLookup.ContainsKey(accessKey))
            {
                if (this.viewLookup[accessKey].ContainsKey(name))
                {
                    d = this.viewLookup[accessKey][name].View;
                }
            }

            if (this.viewLookup.ContainsKey(TransientPanesKey))
            {
                if (this.viewLookup[TransientPanesKey].ContainsKey(name))
                {
                    d = this.viewLookup[TransientPanesKey][name].View;
                }
            }

            if (d != null)
            {
                ShowWindow(d, dockingStyle, dockingAnchorStyle);
                return(d);
            }

            return(null);
        }
Exemple #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;
                }
            }
        }
        public static IView Dock(this IDock dock, IDockableViewModel model, bool add = true)
        {
            IView currentTab = null;

            if (add)
            {
                if (model is IToolViewModel toolModel)
                {
                    currentTab = new AvalonStudioToolTab(toolModel);
                }
                else if (model is IDocumentTabViewModel documentModel)
                {
                    currentTab = new AvalonStudioDocumentTab(documentModel);
                }

                dock.Views.Add(currentTab);
                dock.Factory.Update(currentTab, dock);
            }
            else
            {
                currentTab = dock.Views.FirstOrDefault(v => v.Context == model);

                if (currentTab != null)
                {
                    dock.Factory.Update(currentTab, currentTab.Parent);
                }
            }

            return(currentTab);
        }
Exemple #4
0
        /// <summary>
        /// Saves the current configuration under the given name.
        /// </summary>
        /// <param name="name">Configuration name.</param>
        public void SaveConfiguration(string name)
        {
            if (this.configuration == null)
            {
                this.LoadConfigurations();
            }

            DockingLayoutContextConfiguration config;

            if (!this.configuration.Configurations.ContainsKey(name))
            {
                config = new DockingLayoutContextConfiguration(name);
                //config.LayoutPath = "Layout_" + config.ContextName + ".xml";

                this.configuration.AddConfiguration(config);
            }
            else
            {
                config = this.configuration.Configurations[name];
                //if (config.LayoutPath == null)
                //    config.LayoutPath = "Layout_" + config.ContextName + ".xml";
                config.Configurations.Clear();
            }

            string accessKey = this.SelectedShellViewModel.FullFileName;

            if (viewLookup.ContainsKey(accessKey))
            {
                foreach (string paneName in this.viewLookup[accessKey].Keys)
                {
                    IDockableViewModel       vm = this.viewLookup[accessKey][paneName].View;
                    DockingPaneConfiguration c  = new DockingPaneConfiguration(vm.DockingPaneName);
                    c.IsVisible = vm.IsDockingPaneVisible;
                    config.Configurations.Add(c.PaneName, c);

                    if (vm is IRestorableDockableViewModel)
                    {
                        IRestorableDockableViewModel rVm = vm as IRestorableDockableViewModel;

                        c.IsRestorable       = true;
                        c.RestoreInformation = rVm.GetInformationForRestore();
                        c.DockingPaneType    = rVm.GetDockingPaneType();
                    }
                }
            }

            if (viewLookup.ContainsKey(TransientPanesKey))
            {
                foreach (string paneName in this.viewLookup[TransientPanesKey].Keys)
                {
                    IDockableViewModel       vm = this.viewLookup[TransientPanesKey][paneName].View;
                    DockingPaneConfiguration c  = new DockingPaneConfiguration(vm.DockingPaneName);
                    c.IsVisible = vm.IsDockingPaneVisible;
                    config.Configurations.Add(c.PaneName, c);
                }
            }

            // save layout ...
        }
Exemple #5
0
 private void DeactivateCurrentPane()
 {
     // deactivate current pane
     if (this.activePane != null)
     {
         this.OnActivePaneChanged(this.activePane, false);
     }
     this.activePane = null;
 }
Exemple #6
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;
                }
            }
        }
Exemple #7
0
 /// <summary>
 /// Called whenever the active pane changes.
 /// </summary>
 /// <param name="dockableViewModel"></param>
 /// <param name="isActive"></param>
 protected void OnActivePaneChanged(IDockableViewModel dockableViewModel, bool isActive)
 {
     if (ActivePaneChanged != null)
     {
         ActivePaneChanged(this,
                           new ActivePaneChangedEventArgs()
         {
             DockableViewModel = dockableViewModel,
             IsActive          = isActive
         }
                           );
     }
 }
Exemple #8
0
 /// <summary>
 /// Invalidates the titles of all docking panes.
 /// </summary>
 public void InvalidatePaneTitles()
 {
     foreach (string key in viewLookup.Keys)
     {
         foreach (string name in viewLookup[key].Keys)
         {
             IDockableViewModel vm = viewLookup[key][name].View;
             if (viewLookup[key][name].Pane != null)
             {
                 viewLookup[key][name].Pane.Caption = vm.DockingPaneTitle;
             }
         }
     }
 }
Exemple #9
0
 /// <summary>
 /// Reacts on ShowViewModelRequestEvent.
 /// </summary>
 /// <param name="args">Event data.</param>
 public virtual void ShowViewModel(ShowViewModelRequestEventArgs args)
 {
     if (args.ViewName != null)
     {
         IDockableViewModel vm = this.LayoutManager.ShowWindow(args.ViewName, args.DockingPaneStyle, args.DockingPaneAnchorStyle);
         if (vm != null)
         {
             this.LayoutManager.BringToFrontWindow(vm);
             vm.IsDockingPaneVisible = true;
         }
     }
     else if (args.SourceViewModel is IDockableViewModel)
     {
         this.LayoutManager.ShowWindow(args.SourceViewModel as IDockableViewModel, args.DockingPaneStyle, args.DockingPaneAnchorStyle);
         this.LayoutManager.BringToFrontWindow(args.SourceViewModel as IDockableViewModel);
         (args.SourceViewModel as IDockableViewModel).IsDockingPaneVisible = true;
     }
 }
 /// <summary>
 /// Hides a dockable window.
 /// </summary>
 /// <param name="view">Dockable window to hide.</param>
 public void HideWindow(IDockableViewModel view)
 {
     if (viewLookup.ContainsKey(view.DockingPaneName))
     {
         viewLookup[view.DockingPaneName].Pane.Hide();
     }
 }
Exemple #11
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="v"></param>
 public ViewLookUp(IDockableViewModel v)
 {
     this.View = v;
     this.Pane = null;
 }
        /// <summary>
        /// Activates a view.
        /// </summary>
        /// <param name="view"></param>
        public void Activate(IDockableViewModel view)
        {
            if (view == null)
                return;

            if (viewLookup.ContainsKey(view.DockingPaneName))
            {
                DockableContent content = viewLookup[view.DockingPaneName].Pane;
                if (!content.IsFocused)
                {
                    System.Windows.Input.Keyboard.ClearFocus();
                    content.Focus();
                }
            }
        }
Exemple #13
0
 /// <summary>
 /// Tries to close a specified window..
 /// </summary>
 /// <param name="view"></param>
 public void CloseWindow(IDockableViewModel view)
 {
     this.CloseWindow(view, false);
 }
        /// <summary>
        /// Shows a docking window for a given view.  
        /// If is has been shown before, restore it 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>
        public void ShowWindow(IDockableViewModel view, DockingPaneStyle dockingStyle, DockingPaneAnchorStyle dockingAnchorStyle)
        {
            // init resource dictionaries for plugin hosters
            if (view is IPluginHosterViewModel)
            {
                IPluginHosterViewModel pHost = (IPluginHosterViewModel)view;
                if (pHost.IsVMPlugin)
                {
                    if (!pHost.VMPluginDictionaryInitialized)
                        try
                        {
                            if (pHost.VMPlugin.GetViewModelRessourceDictionary() != null)
                                if (System.Windows.Application.Current != null)
                                {
                                    System.Windows.Application.Current.Resources.BeginInit();
                                    System.Windows.Application.Current.Resources.MergedDictionaries.Add(pHost.VMPlugin.GetViewModelRessourceDictionary());
                                    System.Windows.Application.Current.Resources.EndInit();
                                }
                            pHost.VMPluginDictionaryInitialized = true;
                        }
                        catch
                        {
                            pHost.VMPluginDictionaryInitialized = false;
                        }
                }
            }
            if (!this.isRestoringLayout)
            {
                if (!view.IsInitialized)
                    view.InitializeVM();

                if (view is IRibbonDockableViewModel && this.Ribbon != null)
                    if (!((IRibbonDockableViewModel)view).IsRibbonMenuInitialized)
                    {
                        ((IRibbonDockableViewModel)view).CreateRibbonMenu(this.Ribbon);
                    }
            }

            if (!viewLookup.ContainsKey(view.DockingPaneName))
            {
                DockableContent content = new DockableContent();
                content.Name = view.DockingPaneName;
                content.Title = view.DockingPaneTitle;
                content.Content = view;
                content.StateChanged += new System.Windows.RoutedEventHandler(content_StateChanged);
                if (view.ActivationMode == ActivationMode.Normal)
                    content.IsActiveContentChanged += new EventHandler(content_IsActiveContentChanged);
                content.ContextChangeKind = ConvertToContextChangeKind(view.DockingContextChangeKind);

                viewLookup.Add(view.DockingPaneName, new ViewLookUp(view, content));
                
                if (this.isRestoringLayout)
                {
                    this.MainDockingManager.AddPaneForLayoutRestore(content);
                }
                else
                {
                    if (dockingStyle == DockingPaneStyle.Floating)
                    {
                        content.FloatingWindowSize = new Size(view.FloatingWindowDesiredWidth, view.FloatingWindowDesiredHeight);
                        content.ShowAsFloatingWindow(this.MainDockingManager, true);
                    }
                    else if (dockingStyle == DockingPaneStyle.DockedInDocumentPane)
                        content.ShowAsDocument(this.MainDockingManager);
                    else
                    {
                        if (view.DockedWindowDesiredWidth > 0)
                            content.DesiredWidth = view.DockedWindowDesiredWidth;
                        if (view.DockedWindowDesiredHeight > 0)
                            content.DesiredHeight = view.DockedWindowDesiredHeight;

                        AnchorStyle style = ConvertToAnchorStyle(dockingAnchorStyle);
                        if (style != AnchorStyle.None)
                        {
                            content.Show(this.MainDockingManager, style);
                        }
                        else
                            content.Show(this.MainDockingManager);
                    }
                }
            }

            // show docking window
            if (!this.isRestoringLayout)
            if (!viewLookup[view.DockingPaneName].Pane.IsVisible)
            {
                if (dockingStyle == DockingPaneStyle.Floating)
                {
                    viewLookup[view.DockingPaneName].Pane.FloatingWindowSize = new Size(view.FloatingWindowDesiredWidth, view.FloatingWindowDesiredHeight);
                    viewLookup[view.DockingPaneName].Pane.ShowAsFloatingWindow(this.MainDockingManager, true);
                }
                else if (dockingStyle == DockingPaneStyle.DockedInDocumentPane)
                    viewLookup[view.DockingPaneName].Pane.ShowAsDocument(this.MainDockingManager);
                else
                    viewLookup[view.DockingPaneName].Pane.Show(this.MainDockingManager);

                view.IsDockingPaneVisible = true;
            }
        }
Exemple #15
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>
 public void ShowWindow(IDockableViewModel view, DockingPaneStyle dockingStyle, DockingPaneAnchorStyle dockingAnchorStyle, bool dockedInDocumentPane)
 {
     this.ShowWindow(view, dockingStyle, dockingAnchorStyle, dockedInDocumentPane, this.SelectedShellViewModel.FullFileName);
 }
Exemple #16
0
 /// <summary>
 /// Shows a docking window for a given view.
 /// If is has been shown before, restore it position. Otherwise dock it to the right side.
 /// </summary>
 /// <param name="view">View to dock.</param>
 /// <param name="dockingSyle">Docking style.</param>
 public void ShowWindow(IDockableViewModel view, DockingPaneStyle dockingSyle)
 {
     ShowWindow(view, dockingSyle, DockingPaneAnchorStyle.None);
 }
        /// <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;
                }
            }
        }
 /// <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>
 public void ShowWindow(IDockableViewModel view, DockingPaneStyle dockingStyle, DockingPaneAnchorStyle dockingAnchorStyle, bool dockedInDocumentPane)
 {
     this.ShowWindow(view, dockingStyle, dockingAnchorStyle, dockedInDocumentPane, this.SelectedShellViewModel.FullFileName);
 }
 /// <summary>
 /// Shows a docking window for a given view.  
 /// If is has been shown before, restore it 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="fullFileName">File name.</param>
 public void ShowWindow(IDockableViewModel view, DockingPaneStyle dockingStyle, DockingPaneAnchorStyle dockingAnchorStyle, string fullFileName)
 {
     this.ShowWindow(view, dockingStyle, dockingAnchorStyle, view.DockingPaneStyle == DockingPaneStyle.DockedInDocumentPane, fullFileName);
 }
 /// <summary>
 /// Shows a docking window for a given view.  
 /// If is has been shown before, restore it position. Otherwise dock it to the right side.
 /// </summary>
 /// <param name="view">View to dock.</param>
 /// <param name="dockingSyle">Docking style.</param>
 public void ShowWindow(IDockableViewModel view, DockingPaneStyle dockingSyle)
 {
     ShowWindow(view, dockingSyle, DockingPaneAnchorStyle.None);
 }
 /// <summary>
 /// Shows a docking window for a given view.  
 /// If is has been shown before, restore it position. Otherwise dock it to the right side.
 /// </summary>
 public void ShowWindow(IDockableViewModel view)
 {
     ShowWindow(view, DockingPaneStyle.Docked);
 }
Exemple #23
0
 /// <summary>
 /// Shows a docking window for a given view.
 /// If is has been shown before, restore it position. Otherwise dock it to the right side.
 /// </summary>
 public void ShowWindow(IDockableViewModel view)
 {
     ShowWindow(view, DockingPaneStyle.Docked);
 }
 /// <summary>
 /// Tries to close a specified window..
 /// </summary>
 /// <param name="view"></param>
 public void CloseWindow(IDockableViewModel view)
 {
     this.CloseWindow(view, false);
 }
Exemple #25
0
 /// <summary>
 /// Shows a docking window for a given view.
 /// If is has been shown before, restore it 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="fullFileName">File name.</param>
 public void ShowWindow(IDockableViewModel view, DockingPaneStyle dockingStyle, DockingPaneAnchorStyle dockingAnchorStyle, string fullFileName)
 {
     this.ShowWindow(view, dockingStyle, dockingAnchorStyle, view.DockingPaneStyle == DockingPaneStyle.DockedInDocumentPane, fullFileName);
 }
        /// <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;
                }
            }
        }
Exemple #27
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;
                }
            }
        }
        private void Package_ActiveWindowChangedEvent(object sender, ModelPackage.WindowChangedEventArgs e)
        {
            // there is no need to deactivate a view as this is handled by the main vm

            // activate view
            if (this.SelectedShellViewModel == null)
                return;

            this.SelectedShellViewModel.IsDockingPaneActive = false;
            if (e.NewData != null)
                if (e.NewData.DoesBelongToPackage)
                {
                    if (e.NewData.IsDocumentFrame)
                    {
                        if (this.selectedShellVMName != e.NewData.FullFileName)
                        {
                            bool bLoadLayout = false;
                            if (this.selectedShellVMName == null)
                                bLoadLayout = true;
                            
                            this.selectedShellVMName = e.NewData.FullFileName;

                            // change current shell vm
                            this.packageController.SetCurrentShellViewModel(this.selectedShellVMName);

                            if (bLoadLayout)
                                this.bForceLoadLayout = true;
                            //else
                            //{
                                UpdateView();
                            //}
                        }
                        this.SelectedShellViewModel.IsDockingPaneActive = true;

                        /*
                        if (this.SelectedDocumentPane != null)
                        {
                            this.OnActivePaneChanged(this.SelectedDocumentPane, true);
                            this.activePane = this.SelectedDocumentPane;
                        }
                        else
                            DeactivateCurrentPane();
                        */
                    }
                    else
                    {
                        this.SelectedShellViewModel.TriggerDockingPaneActivated = true;
                        if (e.NewData.Key != Guid.Empty)
                        {
                            string accessKey = this.SelectedShellViewModel.FullFileName;
                            if (this.viewLookup.ContainsKey(accessKey))
                                if (this.viewLookup[accessKey].ContainsKey(this.paneViewLookup[e.NewData.Key]))
                                {
                                    this.activePane = this.viewLookup[accessKey][this.paneViewLookup[e.NewData.Key]].View;
                                }

                            if (this.viewLookup.ContainsKey(TransientPanesKey))
                                if (this.viewLookup[TransientPanesKey].ContainsKey(this.paneViewLookup[e.NewData.Key]))
                                {
                                    this.activePane = this.viewLookup[TransientPanesKey][this.paneViewLookup[e.NewData.Key]].Pane.Content.DataContext as IDockableViewModel;
                                    //this.activePane = this.viewLookup[TransientPanesKey][this.paneViewLookup[e.NewData.Key]].View;
                                }

                            this.OnActivePaneChanged(this.activePane, true);
                        }
                        else
                            DeactivateCurrentPane();
                    }
                }
                else
                {
                    if (e.NewData.IsDocumentFrame)
                    {
                        // close vms???
                    }

                    this.SelectedShellViewModel.TriggerDockingPaneActivated = true;

                    // deactivate current pane
                    DeactivateCurrentPane();
                }
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="v"></param>
 /// <param name="p"></param>
 public ViewLookUp(IDockableViewModel v, DockableContent p)
 {
     this.View = v;
     this.Pane = p;
 }
 /// <summary>
 /// Tries to bring the view displaying the given view model to the front.
 /// </summary>
 /// <param name="view"></param>
 public void BringToFrontWindow(IDockableViewModel view)
 {
     if (viewLookup.ContainsKey(view.DockingPaneName) && !isRestoringLayout)
     {
         DockableContent content = viewLookup[view.DockingPaneName].Pane;
         content.Activate();
     }
 }
 private void DeactivateCurrentPane()
 {
     // deactivate current pane
     if (this.activePane != null)
         this.OnActivePaneChanged(this.activePane, false);
     this.activePane = null;
 }
        /// <summary>
        /// Tries to close a specified window..
        /// </summary>
        /// <param name="view"></param>
        /// <param name="bRemove"></param>
        public void CloseWindow(IDockableViewModel view, bool bRemove)
        {
            this.isRemoveInProcess = true;
            if (viewLookup.ContainsKey(view.DockingPaneName) && !isRestoringLayout)
            {
                DockableContent content = viewLookup[view.DockingPaneName].Pane;
                content.Close();

                if (bRemove)
                {
                    // remove docking pane
                    this.MainDockingManager.RemovePane(content);

                    // notify of a pane beeing closed
                    this.OnPaneClosed(viewLookup[view.DockingPaneName].View);

                    // remove pane from lookup
                    this.viewLookup.Remove(view.DockingPaneName);
                }
            }
            this.isRemoveInProcess = false;
        }
Exemple #33
0
        private void Package_ActiveWindowChangedEvent(object sender, ModelPackage.WindowChangedEventArgs e)
        {
            // there is no need to deactivate a view as this is handled by the main vm

            // activate view
            if (this.SelectedShellViewModel == null)
            {
                return;
            }

            this.SelectedShellViewModel.IsDockingPaneActive = false;
            if (e.NewData != null)
            {
                if (e.NewData.DoesBelongToPackage)
                {
                    if (e.NewData.IsDocumentFrame)
                    {
                        if (this.selectedShellVMName != e.NewData.FullFileName)
                        {
                            bool bLoadLayout = false;
                            if (this.selectedShellVMName == null)
                            {
                                bLoadLayout = true;
                            }

                            this.selectedShellVMName = e.NewData.FullFileName;

                            // change current shell vm
                            this.packageController.SetCurrentShellViewModel(this.selectedShellVMName);

                            if (bLoadLayout)
                            {
                                this.bForceLoadLayout = true;
                            }
                            //else
                            //{
                            UpdateView();
                            //}
                        }
                        this.SelectedShellViewModel.IsDockingPaneActive = true;

                        /*
                         * if (this.SelectedDocumentPane != null)
                         * {
                         *  this.OnActivePaneChanged(this.SelectedDocumentPane, true);
                         *  this.activePane = this.SelectedDocumentPane;
                         * }
                         * else
                         *  DeactivateCurrentPane();
                         */
                    }
                    else
                    {
                        this.SelectedShellViewModel.TriggerDockingPaneActivated = true;
                        if (e.NewData.Key != Guid.Empty)
                        {
                            string accessKey = this.SelectedShellViewModel.FullFileName;
                            if (this.viewLookup.ContainsKey(accessKey))
                            {
                                if (this.viewLookup[accessKey].ContainsKey(this.paneViewLookup[e.NewData.Key]))
                                {
                                    this.activePane = this.viewLookup[accessKey][this.paneViewLookup[e.NewData.Key]].View;
                                }
                            }

                            if (this.viewLookup.ContainsKey(TransientPanesKey))
                            {
                                if (this.viewLookup[TransientPanesKey].ContainsKey(this.paneViewLookup[e.NewData.Key]))
                                {
                                    this.activePane = this.viewLookup[TransientPanesKey][this.paneViewLookup[e.NewData.Key]].Pane.Content.DataContext as IDockableViewModel;
                                    //this.activePane = this.viewLookup[TransientPanesKey][this.paneViewLookup[e.NewData.Key]].View;
                                }
                            }

                            this.OnActivePaneChanged(this.activePane, true);
                        }
                        else
                        {
                            DeactivateCurrentPane();
                        }
                    }
                }
                else
                {
                    if (e.NewData.IsDocumentFrame)
                    {
                        // close vms???
                    }

                    this.SelectedShellViewModel.TriggerDockingPaneActivated = true;

                    // deactivate current pane
                    DeactivateCurrentPane();
                }
            }
        }
Exemple #34
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 ?
                // ..
            }
        }
 /// <summary>
 /// Called whenever a pane has been closed (not hidden !).
 /// </summary>
 /// <param name="dockableViewModel"></param>
 protected void OnPaneClosed(IDockableViewModel dockableViewModel)
 {
     if (PaneClosedEvent != null)
     {
         PaneClosedEvent(this,
            new PaneClosedEventArgs()
            {
                DockableViewModel = dockableViewModel
            }
         );
     }
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="v"></param>
 /// <param name="p"></param>
 public ViewLookUp(IDockableViewModel v, ModelToolWindowPane p)
 {
     this.View = v;
     this.Pane = p;
 }
 /// <summary>
 /// Called whenever the active pane changes.
 /// </summary>
 /// <param name="dockableViewModel"></param>
 /// <param name="isActive"></param>
 protected void OnActivePaneChanged(IDockableViewModel dockableViewModel, bool isActive)
 {
     if (ActivePaneChanged != null)
     {
         ActivePaneChanged(this,
            new ActivePaneChangedEventArgs()
            {
                DockableViewModel = dockableViewModel,
                IsActive = isActive
            }
         );
     }
 }
 /// <summary>
 /// Shows a window if the current configuration contains it and if it is set as visible.
 /// </summary>
 /// <param name="view"></param>
 public void ShowWindowBasedOnConfiguraion(IDockableViewModel view)
 {
     if( this.CurrentConfiguration != null )
         if (this.CurrentConfiguration.Configurations.ContainsKey(view.DockingPaneName))
         {
             DockingPaneConfiguration p = this.CurrentConfiguration.Configurations[view.DockingPaneName];
             if (p.IsVisible)
             {
                 this.ShowWindow(view, view.DockingPaneStyle, view.DockingPaneAnchorStyle);
             }
         }
 }
Exemple #39
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="v"></param>
 /// <param name="p"></param>
 public ViewLookUp(IDockableViewModel v, ModelToolWindowPane p)
 {
     this.View = v;
     this.Pane = p;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="v"></param>
 public ViewLookUp(IDockableViewModel v)
 {
     this.View = v;
     this.Pane = null;
 }