コード例 #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 the configuration.
        /// </summary>
        /// <param name="fileName">File name.</param>
        public void Load(string fileName)
        {
            if (!File.Exists(fileName))
                return;

            try
            {
                XDocument doc = XDocument.Load(fileName);
                XElement rootNode = doc.Root;

                foreach (XElement node in rootNode.Elements("Config"))
                {
                    string contextName = node.Element("ContextName").Value;
                    string layoutPath = null;
                    if( node.Element("LayoutPath") != null )
                        layoutPath = node.Element("LayoutPath").Value;

                    DockingLayoutContextConfiguration config = new DockingLayoutContextConfiguration(contextName);
                    config.LayoutPath = layoutPath;

                    XElement configurationsElement = node.Element("Configurations");
                    foreach (XElement n in configurationsElement.Elements("Configuration"))
                    {
                        string paneName = n.Element("PaneName").Value;
                        bool isVisble = Boolean.Parse(n.Element("IsVisible").Value);
                        bool isRestorable = Boolean.Parse(n.Element("IsRestorable").Value);
                        
                        DockingPaneConfiguration pane = new DockingPaneConfiguration(paneName);
                        pane.IsVisible = isVisble;
                        pane.IsRestorable = isRestorable;
                        
                        if (n.Element("DockingPaneType") != null)
                            pane.DockingPaneType = n.Element("DockingPaneType").Value;

                        XElement ri = n.Element("RestoreInformation");
                        if (ri != null)
                            pane.RestoreInformation = ri.Elements().ElementAt(0);

                        config.Configurations.Add(pane.PaneName, pane);
                    }
                    
                    this.AddConfiguration(config);
                }
            }
            catch { }

        }
コード例 #3
0
        /// <summary>
        /// Saves the current window configuration (opened windows).
        /// </summary>
        /// <param name="name">Name of the configuration.</param>
        public void SaveCurrentConfiguration(string name)
        {
            if (this.configuration == null)
                this.LoadConfiguration();

            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();
            }

            List<DockableContent> excludePanels = new List<DockableContent>();
            foreach(string paneName in this.viewLookup.Keys)
            {
                IDockableViewModel vm = this.viewLookup[paneName].View;

                if (vm is IContextableDockableViewModel)
                {
                    IContextableDockableViewModel cVM = vm as IContextableDockableViewModel;
                    if (!String.IsNullOrEmpty(cVM.ModelContextName))
                        if (cVM.ModelContextName != name)
                        {
                            excludePanels.Add(this.viewLookup[paneName].Pane);
                            continue;
                        }
                }

                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();
                }
            }

            SaveCurrentLayout(SaveLayoutDirectory + Path.DirectorySeparatorChar + config.LayoutPath, excludePanels);
        }
コード例 #4
0
 /// <summary>
 /// Adds a configuration.
 /// </summary>
 /// <param name="config">Configuration.</param>
 public void AddConfiguration(DockingLayoutContextConfiguration config)
 {
     if (!this.Configurations.ContainsKey(config.ContextName))
         this.Configurations.Add(config.ContextName, config);
     else
         this.Configurations[config.ContextName] = config;
 }