////////////////////////////////////////////////////////////////////////// public bool LoadFromXmlNode(XmlNode Node) { try { this.Name = Node.Name; XmlNode ChildNode = Node.FirstChild; while (ChildNode != null) { if (ChildNode is XmlText) { SetValue(ChildNode.Value); } else if (ChildNode is XmlElement) { SettingsNode SetNode = new SettingsNode(); if (SetNode.LoadFromXmlNode(ChildNode)) { Children.Add(SetNode); } } ChildNode = ChildNode.NextSibling; } return(true); } catch { return(false); } }
////////////////////////////////////////////////////////////////////////// public SettingsNode GetNode(string Path, bool CaseSensitive, bool CreateIfDoesntExist) { string[] PathSplit = Path.Split(new char[] { '\\', '/' }); SettingsNode Child = this; for (int i = 0; i < PathSplit.Length; i++) { string Name = PathSplit[i]; SettingsNode NewChild = Child.GetChildByName(Name, CaseSensitive); if (NewChild == null && CreateIfDoesntExist) { NewChild = new SettingsNode(Name); Child.Children.Add(NewChild); } Child = NewChild; if (Child == null) { break; } } return(Child); }
////////////////////////////////////////////////////////////////////////// protected void LoadControls(Control ParentControl, SettingsNode RootNode) { foreach (Control C in ParentControl.Controls) { if (C is ILayoutAwareControl) { ((ILayoutAwareControl)C).LoadControlLayout(RootNode); } else { if (C is SplitContainer) { SplitContainer Ctrl = C as SplitContainer; if (!Ctrl.IsSplitterFixed) { SettingsNode Node = RootNode.GetNode(Ctrl.Name); if (Node != null) { try { Ctrl.SplitterDistance = Node.GetInt("SplitterDistance", Ctrl.SplitterDistance); } catch { } } } } if (C is ListView) { ListView Ctrl = C as ListView; SettingsNode Node = RootNode.GetNode(Ctrl.Name, false, true); if (Node != null) { for (int i = 0; i < Ctrl.Columns.Count; i++) { ColumnHeader Col = Ctrl.Columns[i]; Col.Width = Node.GetInt("Col" + i.ToString() + "Width", Col.Width); } } } if(C is TabControl) { TabControl Ctrl = C as TabControl; SettingsNode Node = RootNode.GetNode(Ctrl.Name, false, true); if (Node != null) { int SelIndex = Node.GetInt("SelectedIndex", Ctrl.SelectedIndex); if (SelIndex >= 0 && SelIndex < Ctrl.TabCount) Ctrl.SelectedIndex = SelIndex; } } } if (C.Controls.Count > 0) LoadControls(C, RootNode); } }
////////////////////////////////////////////////////////////////////////// public void SetValue(string Path, Color Val) { SettingsNode Node = GetNode(Path, false, true); if (Node != null) { Node.SetValue(Val); } }
////////////////////////////////////////////////////////////////////////// public virtual void SaveControlLayout(SettingsNode RootNode) { SettingsNode Node = RootNode.GetNode(this.Name, false, true); if (Node != null) { for (int i = 0; i < Columns.Count; i++) { Node.SetValue("Col" + i.ToString() + "Width", Columns[i].Width); } } }
////////////////////////////////////////////////////////////////////////// public virtual void LoadControlLayout(SettingsNode RootNode) { SettingsNode Node = RootNode.GetNode(this.Name, false, true); if (Node != null) { for (int i = 0; i < Columns.Count; i++) { TreeColumn Col = Columns[i]; Col.Width = Node.GetInt("Col" + i.ToString() + "Width", Col.Width); } } }
////////////////////////////////////////////////////////////////////////// public Color GetColor(string Path, Color InitValue) { SettingsNode Node = GetNode(Path, false, false); if (Node != null) { return(Node.GetColor()); } else { return(InitValue); } }
////////////////////////////////////////////////////////////////////////// public bool GetBool(string Path, bool InitValue) { SettingsNode Node = GetNode(Path, false, false); if (Node != null) { return(Node.GetBool()); } else { return(InitValue); } }
////////////////////////////////////////////////////////////////////////// public int GetInt(string Path, int InitValue) { SettingsNode Node = GetNode(Path, false, false); if (Node != null) { return(Node.GetInt()); } else { return(InitValue); } }
////////////////////////////////////////////////////////////////////////// public string GetString(string Path, string InitValue) { SettingsNode Node = GetNode(Path, false, false); if (Node != null) { return(Node.GetString()); } else { return(InitValue); } }
////////////////////////////////////////////////////////////////////////// protected void SaveControls(Control ParentControl, SettingsNode RootNode) { foreach (Control C in ParentControl.Controls) { if (C is ILayoutAwareControl) { ((ILayoutAwareControl)C).SaveControlLayout(RootNode); } else { if (C is SplitContainer) { SplitContainer Ctrl = C as SplitContainer; SettingsNode Node = RootNode.GetNode(Ctrl.Name, false, true); if (Node != null) { Node.SetValue("SplitterDistance", Ctrl.SplitterDistance); } } if (C is ListView) { ListView Ctrl = C as ListView; SettingsNode Node = RootNode.GetNode(Ctrl.Name, false, true); if (Node != null) { for (int i = 0; i < Ctrl.Columns.Count; i++) { Node.SetValue("Col" + i.ToString() + "Width", Ctrl.Columns[i].Width); } } } if (C is TabControl) { TabControl Ctrl = C as TabControl; SettingsNode Node = RootNode.GetNode(Ctrl.Name, false, true); if (Node != null) { Node.SetValue("SelectedIndex", Ctrl.SelectedIndex); } } } if (C.Controls.Count > 0) { SaveControls(C, RootNode); } } }
////////////////////////////////////////////////////////////////////////// protected void SaveLayout(SettingsNode RootNode) { SettingsNode LayoutNode = RootNode.GetNode("Layout\\" + this.Name, false, true); if (LayoutNode != null) { LayoutNode.SetValue("FormState", (int)this.WindowState); LayoutNode.SetValue("FormPosX", FormStateRect.Location.X); LayoutNode.SetValue("FormPosY", FormStateRect.Location.Y); LayoutNode.SetValue("FormWidth", FormStateRect.Size.Width); LayoutNode.SetValue("FormHeight", FormStateRect.Size.Height); SaveControls(this, LayoutNode); } }
////////////////////////////////////////////////////////////////////////// private void LoadSettings(SettingsNode RootNode) { SettingsNode Section = RootNode.GetNode(this.Name, true); if (Section != null) { TxtProjectFile.Text = Section.GetString("ProjectFile"); TxtExtensions.Text = Section.GetString("ScriptExtensions"); foreach (IntegratorModule Mod in modules) { Mod.LoadSettings(Section); } } if (TxtExtensions.Text == "") TxtExtensions.Text = "script inc"; }
////////////////////////////////////////////////////////////////////////// protected void LoadLayout(SettingsNode RootNode) { SettingsNode LayoutNode = RootNode.GetNode("Layout\\" + this.Name); if (LayoutNode != null) { // load position Point FormLoc = new Point(LayoutNode.GetInt("FormPosX", this.Location.X), LayoutNode.GetInt("FormPosY", this.Location.Y)); // load size if (this.FormBorderStyle == FormBorderStyle.Sizable || this.FormBorderStyle == FormBorderStyle.SizableToolWindow) { this.Size = new Size(LayoutNode.GetInt("FormWidth", this.Size.Width), LayoutNode.GetInt("FormHeight", this.Size.Height)); } // make sure the position/size is valid on current monitor setup bool FoundScreen = false; Point LowerRight = new Point(FormLoc.X + this.Size.Width, FormLoc.Y + this.Size.Height); foreach (Screen Scr in Screen.AllScreens) { if (Scr.Bounds.Contains(FormLoc) || Scr.Bounds.Contains(LowerRight)) { FoundScreen = true; } } if (FoundScreen) { this.Location = FormLoc; } // remember window position FormStateRect.Location = this.Location; FormStateRect.Size = this.Size; this.WindowState = (FormWindowState)LayoutNode.GetInt("FormState", (int)FormWindowState.Normal); LoadControls(this, LayoutNode); } else { FormStateRect.Location = this.Location; FormStateRect.Size = this.Size; } }
////////////////////////////////////////////////////////////////////////// public override void SaveSettings(SettingsNode RootNode) { RootNode.SetValue("GeshiOutputDir", TxtOutputDir.Text); }
////////////////////////////////////////////////////////////////////////// public override void LoadSettings(SettingsNode RootNode) { TxtOutputDir.Text = RootNode.GetString("GeshiOutputDir"); }
////////////////////////////////////////////////////////////////////////// protected void LoadControls(Control ParentControl, SettingsNode RootNode) { foreach (Control C in ParentControl.Controls) { if (C is ILayoutAwareControl) { ((ILayoutAwareControl)C).LoadControlLayout(RootNode); } else { if (C is SplitContainer) { SplitContainer Ctrl = C as SplitContainer; if (!Ctrl.IsSplitterFixed) { SettingsNode Node = RootNode.GetNode(Ctrl.Name); if (Node != null) { try { Ctrl.SplitterDistance = Node.GetInt("SplitterDistance", Ctrl.SplitterDistance); } catch { } } } } if (C is ListView) { ListView Ctrl = C as ListView; SettingsNode Node = RootNode.GetNode(Ctrl.Name, false, true); if (Node != null) { for (int i = 0; i < Ctrl.Columns.Count; i++) { ColumnHeader Col = Ctrl.Columns[i]; Col.Width = Node.GetInt("Col" + i.ToString() + "Width", Col.Width); } } } if (C is TabControl) { TabControl Ctrl = C as TabControl; SettingsNode Node = RootNode.GetNode(Ctrl.Name, false, true); if (Node != null) { int SelIndex = Node.GetInt("SelectedIndex", Ctrl.SelectedIndex); if (SelIndex >= 0 && SelIndex < Ctrl.TabCount) { Ctrl.SelectedIndex = SelIndex; } } } } if (C.Controls.Count > 0) { LoadControls(C, RootNode); } } }
////////////////////////////////////////////////////////////////////////// public SettingsNode GetNode(string Path, bool CaseSensitive, bool CreateIfDoesntExist) { string[] PathSplit = Path.Split(new char[] { '\\', '/' }); SettingsNode Child = this; for(int i=0; i<PathSplit.Length; i++) { string Name = PathSplit[i]; SettingsNode NewChild = Child.GetChildByName(Name, CaseSensitive); if (NewChild == null && CreateIfDoesntExist) { NewChild = new SettingsNode(Name); Child.Children.Add(NewChild); } Child = NewChild; if (Child == null) break; } return Child; }
////////////////////////////////////////////////////////////////////////// public virtual void LoadSettings(SettingsNode RootNode) { }
////////////////////////////////////////////////////////////////////////// public bool LoadFromXmlNode(XmlNode Node) { try { this.Name = Node.Name; XmlNode ChildNode = Node.FirstChild; while (ChildNode != null) { if (ChildNode is XmlText) { SetValue(ChildNode.Value); } else if (ChildNode is XmlElement) { SettingsNode SetNode = new SettingsNode(); if (SetNode.LoadFromXmlNode(ChildNode)) Children.Add(SetNode); } ChildNode = ChildNode.NextSibling; } return true; } catch { return false; } }
////////////////////////////////////////////////////////////////////////// public void LoadSettings(SettingsNode RootNode) { SettingsNode Section = RootNode.GetNode("General", true); if (Section == null) return; SelectionColor = Section.GetColor("SelectionColor", SelectionColor); BoxColor = Section.GetColor("BoxColor", BoxColor); WindowCanvas.BackColor = Section.GetColor("BackgroundColor", WindowCanvas.BackColor); GridSize = new Size(Section.GetInt("GridWidth", GridSize.Width), Section.GetInt("GridHeight", GridSize.Height)); _RecentFiles.Clear(); SettingsNode RecentList = Section.GetNode("RecentFiles"); if (RecentList != null) { foreach (SettingsNode Node in RecentList.Children) { string RecentFile = Node.GetString(); if(File.Exists(RecentFile)) _RecentFiles.Add(RecentFile); } } }
////////////////////////////////////////////////////////////////////////// public void SaveSettings(SettingsNode RootNode) { SettingsNode Section = RootNode.GetNode("General", true, true); if (Section == null) return; Section.Clear(); Section.SetValue("SelectionColor", SelectionColor); Section.SetValue("BoxColor", BoxColor); Section.SetValue("BackgroundColor", WindowCanvas.BackColor); Section.SetValue("GridWidth", GridSize.Width); Section.SetValue("GridHeight", GridSize.Height); SettingsNode RecentList = new SettingsNode("RecentFiles"); foreach (string RecentFile in _RecentFiles) { RecentList.Children.Add(new SettingsNode("RecentFile", RecentFile)); } Section.Children.Add(RecentList); }
////////////////////////////////////////////////////////////////////////// protected void LoadLayout(SettingsNode RootNode) { SettingsNode LayoutNode = RootNode.GetNode("Layout\\" + this.Name); if (LayoutNode != null) { // load position Point FormLoc = new Point(LayoutNode.GetInt("FormPosX", this.Location.X), LayoutNode.GetInt("FormPosY", this.Location.Y)); // load size if (this.FormBorderStyle == FormBorderStyle.Sizable || this.FormBorderStyle == FormBorderStyle.SizableToolWindow) { this.Size = new Size(LayoutNode.GetInt("FormWidth", this.Size.Width), LayoutNode.GetInt("FormHeight", this.Size.Height)); } // make sure the position/size is valid on current monitor setup bool FoundScreen = false; Point LowerRight = new Point(FormLoc.X + this.Size.Width, FormLoc.Y + this.Size.Height); foreach (Screen Scr in Screen.AllScreens) { if (Scr.Bounds.Contains(FormLoc) || Scr.Bounds.Contains(LowerRight)) FoundScreen = true; } if (FoundScreen) this.Location = FormLoc; // remember window position FormStateRect.Location = this.Location; FormStateRect.Size = this.Size; this.WindowState = (FormWindowState)LayoutNode.GetInt("FormState", (int)FormWindowState.Normal); LoadControls(this, LayoutNode); } else { FormStateRect.Location = this.Location; FormStateRect.Size = this.Size; } }
////////////////////////////////////////////////////////////////////////// protected void SaveControls(Control ParentControl, SettingsNode RootNode) { foreach (Control C in ParentControl.Controls) { if (C is ILayoutAwareControl) { ((ILayoutAwareControl)C).SaveControlLayout(RootNode); } else { if (C is SplitContainer) { SplitContainer Ctrl = C as SplitContainer; SettingsNode Node = RootNode.GetNode(Ctrl.Name, false, true); if (Node != null) { Node.SetValue("SplitterDistance", Ctrl.SplitterDistance); } } if (C is ListView) { ListView Ctrl = C as ListView; SettingsNode Node = RootNode.GetNode(Ctrl.Name, false, true); if (Node != null) { for (int i = 0; i < Ctrl.Columns.Count; i++) { Node.SetValue("Col" + i.ToString() + "Width", Ctrl.Columns[i].Width); } } } if (C is TabControl) { TabControl Ctrl = C as TabControl; SettingsNode Node = RootNode.GetNode(Ctrl.Name, false, true); if (Node != null) { Node.SetValue("SelectedIndex", Ctrl.SelectedIndex); } } } if (C.Controls.Count > 0) SaveControls(C, RootNode); } }
////////////////////////////////////////////////////////////////////////// protected void SaveLayout(SettingsNode RootNode) { SettingsNode LayoutNode = RootNode.GetNode("Layout\\" + this.Name, false, true); if (LayoutNode != null) { LayoutNode.SetValue("FormState", (int)this.WindowState); LayoutNode.SetValue("FormPosX", FormStateRect.Location.X); LayoutNode.SetValue("FormPosY", FormStateRect.Location.Y); LayoutNode.SetValue("FormWidth", FormStateRect.Size.Width); LayoutNode.SetValue("FormHeight", FormStateRect.Size.Height); SaveControls(this, LayoutNode); } }
////////////////////////////////////////////////////////////////////////// public virtual void SaveSettings(SettingsNode RootNode) { }
////////////////////////////////////////////////////////////////////////// private void SaveSettings(SettingsNode RootNode) { SettingsNode Section = RootNode.GetNode(this.Name, true, true); if (Section == null) return; Section.Clear(); Section.SetValue("ProjectFile", TxtProjectFile.Text); Section.SetValue("ScriptExtensions", TxtExtensions.Text); foreach(IntegratorModule Mod in modules) { Mod.SaveSettings(Section); } }