コード例 #1
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 ...
        }
コード例 #2
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 ?
                // ..
            }
        }