| 0: | // TreeViewOptions.cs | |
| 1: | // Copyright (C) 2001 Mike Krueger | |
| 2: | // | |
| 3: | // This program is free software; you can redistribute it and/or modify | |
| 4: | // it under the terms of the GNU General Public License as published by | |
| 5: | // the Free Software Foundation; either version 2 of the License, or | |
| 6: | // (at your option) any later version. | |
| 7: | // | |
| 8: | // This program is distributed in the hope that it will be useful, | |
| 9: | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10: | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11: | // GNU General Public License for more details. | |
| 12: | // | |
| 13: | // You should have received a copy of the GNU General Public License | |
| 14: | // along with this program; if not, write to the Free Software | |
| 15: | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 16: | ||
| 17: | using System; | |
| 18: | using System.Drawing; | |
| 19: | using System.Collections; | |
| 20: | using System.ComponentModel; | |
| 21: | using System.Windows.Forms; | |
| 22: | using System.Xml; | |
| 23: | ||
| 24: | using SharpDevelop.Gui.Dialogs.OptionPanels; | |
| 25: | using SharpDevelop.Internal.Project; | |
| 26: | using SharpDevelop.Internal.Text; | |
| 27: | using SharpDevelop.Tool.Data; | |
| 28: | ||
| 29: | namespace SharpDevelop.Gui.Dialogs { | |
| 30: | ||
| 31: | /// <summary> | |
| 32: | /// TreeView options are used, when more options will be edited (for something like | |
| 33: | /// IDE Options + Plugin Options) | |
| 34: | /// </summary> | |
| 35: | public class TreeViewOptions : System.Windows.Forms.Form, ISdOptionDialog | |
| 36: | { | |
| 37: | private System.Windows.Forms.Panel panel1; | |
| 38: | private System.Windows.Forms.Button button1; | |
| 39: | private System.Windows.Forms.Button button2; | |
| 40: | private System.Windows.Forms.TreeView treeView1; | |
| 41: | private System.Windows.Forms.Splitter splitter1; | |
| 42: | private System.Windows.Forms.Panel panel2; | |
| 43: | private System.Windows.Forms.Label label1; | |
| 44: | private System.Windows.Forms.Panel panel3; | |
| 45: | ||
| 46: | ArrayList OptionPanels = new ArrayList(); | |
| 47: | ||
| 48: | /// <summary> | |
| 49: | /// Clean up any resources being used. | |
| 50: | /// </summary> | |
| 51: | protected override void Dispose(bool disposing) | |
| 52: | { | |
| 53: | if (disposing) { | |
| 54: | foreach (AbstractOptionPanel pane in OptionPanels) | |
| 55: | pane.Dispose(); | |
| 56: | } | |
| 57: | base.Dispose(disposing); | |
| 58: | } | |
| 59: | ||
| 60: | void AcceptEvent(object sender, EventArgs e) | |
| 61: | { | |
| 62: | foreach (AbstractOptionPanel pane in OptionPanels) | |
| 63: | pane.Accept(); | |
| 64: | } | |
| 65: | ||
| 66: | void ResetImageIndex(TreeNodeCollection nodes) | |
| 67: | { | |
| 68: | foreach (TreeNode node in nodes) { | |
| 69: | if (node.Nodes.Count > 0) { | |
| 70: | ResetImageIndex(node.Nodes); | |
| 71: | } else { | |
| 72: | node.ImageIndex = 2; | |
| 73: | node.SelectedImageIndex = 3; | |
| 74: | } | |
| 75: | } | |
| 76: | } | |
| 77: | bool b = true; | |
| 78: | void BeforeExpandNode(object sender, TreeViewCancelEventArgs e) | |
| 79: | { | |
| 80: | if (!b) | |
| 81: | return; | |
| 82: | b = false; | |
| 83: | treeView1.BeginUpdate(); | |
| 84: | TreeNode node = e.Node.FirstNode; | |
| 85: | while (node.Nodes.Count > 0) | |
| 86: | node = e.Node.FirstNode; | |
| 87: | treeView1.CollapseAll(); | |
| 88: | node.EnsureVisible(); | |
| 89: | node.ImageIndex = 3; | |
| 90: | treeView1.EndUpdate(); | |
| 91: | SetOptionPanelTo(node); | |
| 92: | b = true; | |
| 93: | } | |
| 94: | ||
| 95: | void BeforeSelectNode(object sender, TreeViewCancelEventArgs e) | |
| 96: | { | |
| 97: | ResetImageIndex(treeView1.Nodes); | |
| 98: | if (e.Node.Nodes.Count > 0) { // select folder | |
| 99: | if (e.Node.IsExpanded) { | |
| 100: | e.Node.Collapse(); | |
| 101: | } else | |
| 102: | e.Node.Expand(); | |
| 103: | } | |
| 104: | } | |
| 105: | void HandleClick(object sender, EventArgs e) | |
| 106: | { | |
| 107: | if (treeView1.GetNodeAt(treeView1.PointToClient(Control.MousePosition)) == treeView1.SelectedNode) { | |
| 108: | if (treeView1.SelectedNode.IsExpanded) { | |
| 109: | treeView1.SelectedNode.Collapse(); | |
| 110: | } else { | |
| 111: | treeView1.SelectedNode.Expand(); | |
| 112: | } | |
| 113: | } | |
| 114: | } | |
| 115: | ||
| 116: | void SetOptionPanelTo(TreeNode node) | |
| 117: | { | |
| 118: | foreach (AbstractOptionPanel panel in OptionPanels) { | |
| 119: | if (node.Text == panel.PanelName) { | |
| 120: | panel3.Controls.Clear(); | |
| 121: | panel3.Controls.Add(panel); | |
| 122: | panel.Dock = DockStyle.Fill; | |
| 123: | label1.Text = panel.PanelName; | |
| 124: | break; | |
| 125: | } | |
| 126: | } | |
| 127: | } | |
| 128: | ||
| 129: | void SelectNode(object sender, TreeViewEventArgs e) | |
| 130: | { | |
| 131: | SetOptionPanelTo(treeView1.SelectedNode); | |
| 132: | } | |
| 133: | ||
| 134: | public void AddOptionPanel(AbstractOptionPanel panel, string treenode) | |
| 135: | { | |
| 136: | OptionPanels.Add(panel); | |
| 137: | TreeNode node = new TreeNode(panel.PanelName); | |
| 138: | node.ImageIndex = 2; | |
| 139: | node.SelectedImageIndex = 3; | |
| 140: | ||
| 141: | TreeNode parent = null; | |
| 142: | ||
| 143: | foreach (TreeNode pnode in treeView1.Nodes) | |
| 144: | if (treenode == pnode.Text) { | |
| 145: | parent = pnode; | |
| 146: | break; | |
| 147: | } | |
| 148: | if (parent == null) { | |
| 149: | parent = new TreeNode(treenode); | |
| 150: | treeView1.Nodes.Add(parent); | |
| 151: | } | |
| 152: | parent.Nodes.Add(node); | |
| 153: | ||
| 154: | if (treeView1.SelectedNode == null) // set the first inserted option node as selected. | |
| 155: | treeView1.SelectedNode = node; | |
| 156: | } | |
| 157: | ||
| 158: | public void AddOptionPanel(AbstractOptionPanel panel) | |
| 159: | { | |
| 160: | AddOptionPanel(panel, Resource.GetString("Dialog.Options.TreeViewOptions.SharpDevelopOptionsText")); | |
| 161: | } | |
| 162: | ||
| 163: | void InitImageList() | |
| 164: | { | |
| 165: | ImageList imglist = new ImageList(); | |
| 166: | ||
| 167: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ClosedFolderBitmap")); | |
| 168: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.OpenFolderBitmap")); | |
| 169: | imglist.Images.Add(new Bitmap(1, 1)); | |
| 170: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.SelectionArrow")); | |
| 171: | ||
| 172: | treeView1.ImageList = imglist; | |
| 173: | } | |
| 174: | ||
| 175: | ||
| 176: | void ShowOpenFolderIcon(object sender, TreeViewCancelEventArgs e) | |
| 177: | { | |
| 178: | if (e.Node.Nodes.Count > 0) { | |
| 179: | e.Node.ImageIndex = e.Node.SelectedImageIndex = 1; | |
| 180: | } | |
| 181: | } | |
| 182: | ||
| 183: | void ShowClosedFolderIcon(object sender, TreeViewCancelEventArgs e) | |
| 184: | { | |
| 185: | if (e.Node.Nodes.Count > 0) { | |
| 186: | e.Node.ImageIndex = e.Node.SelectedImageIndex = 0; | |
| 187: | } | |
| 188: | } | |
| 189: | ||
| 190: | public TreeViewOptions(MainWindow window) | |
| 191: | { | |
| 192: | this.Text = Resource.GetString("Dialog.Options.TreeViewOptions.DialogName"); | |
| 193: | ||
| 194: | this.InitializeComponent(); | |
| 195: | ||
| 196: | button1.Click += new EventHandler(AcceptEvent); | |
| 197: | ||
| 198: | this.FormBorderStyle = FormBorderStyle.Sizable; | |
| 199: | MaximizeBox = MinimizeBox = false; | |
| 200: | ShowInTaskbar = false; | |
| 201: | StartPosition = FormStartPosition.CenterParent; | |
| 202: | Owner = window; | |
| 203: | Icon = Resource.GetIcon("Icons.16x16.Options"); | |
| 204: | InitImageList(); | |
| 205: | ||
| 206: | treeView1.BeforeExpand += new TreeViewCancelEventHandler(ShowOpenFolderIcon); | |
| 207: | treeView1.BeforeCollapse += new TreeViewCancelEventHandler(ShowClosedFolderIcon); | |
| 208: | } | |
| 209: | ||
| 210: | private void InitializeComponent() | |
| 211: | { | |
| 212: | this.panel1 = new System.Windows.Forms.Panel(); | |
| 213: | this.splitter1 = new System.Windows.Forms.Splitter(); | |
| 214: | this.treeView1 = new TreeView(); | |
| 215: | this.button1 = new System.Windows.Forms.Button(); | |
| 216: | this.button2 = new System.Windows.Forms.Button(); | |
| 217: | this.panel2 = new System.Windows.Forms.Panel(); | |
| 218: | this.label1 = new System.Windows.Forms.Label(); | |
| 219: | this.panel3 = new System.Windows.Forms.Panel(); | |
| 220: | this.panel1.SuspendLayout(); | |
| 221: | this.panel2.SuspendLayout(); | |
| 222: | this.SuspendLayout(); | |
| 223: | ||
| 224: | // | |
| 225: | // panel1 | |
| 226: | // | |
| 227: | this.panel1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | |
| 228: | | System.Windows.Forms.AnchorStyles.Left) | |
| 229: | | System.Windows.Forms.AnchorStyles.Right); | |
| 230: | this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {this.panel2, | |
| 231: | this.splitter1, | |
| 232: | this.treeView1}); | |
| 233: | this.panel1.Size = new System.Drawing.Size(592, 456); | |
| 234: | this.panel1.TabIndex = 0; | |
| 235: | ||
| 236: | // | |
| 237: | // splitter1 | |
| 238: | // | |
| 239: | this.splitter1.Location = new System.Drawing.Point(121, 0); | |
| 240: | this.splitter1.Size = new System.Drawing.Size(3, 456); | |
| 241: | this.splitter1.TabIndex = 1; | |
| 242: | this.splitter1.TabStop = false; | |
| 243: | ||
| 244: | // | |
| 245: | // treeView1 | |
| 246: | // | |
| 247: | this.treeView1.Dock = System.Windows.Forms.DockStyle.Left; | |
| 248: | this.treeView1.ImageIndex = -1; | |
| 249: | this.treeView1.SelectedImageIndex = -1; | |
| 250: | this.treeView1.Size = new System.Drawing.Size(170, 456); | |
| 251: | this.treeView1.TabIndex = 0; | |
| 252: | this.treeView1.HideSelection = false; | |
| 253: | ||
| 254: | this.treeView1.Click += new EventHandler(HandleClick); | |
| 255: | this.treeView1.AfterSelect += new TreeViewEventHandler(SelectNode); | |
| 256: | this.treeView1.BeforeSelect += new TreeViewCancelEventHandler(BeforeSelectNode); | |
| 257: | this.treeView1.BeforeExpand += new TreeViewCancelEventHandler(BeforeExpandNode); | |
| 258: | this.treeView1.ShowLines = this.treeView1.ShowPlusMinus = false; | |
| 259: | // | |
| 260: | // button1 | |
| 261: | // | |
| 262: | this.button1.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right); | |
| 263: | this.button1.Location = new System.Drawing.Point(428 + 8, 464); | |
| 264: | this.button1.Size = new System.Drawing.Size(74, 23); | |
| 265: | this.button1.TabIndex = 1; | |
| 266: | this.button1.DialogResult = DialogResult.OK; | |
| 267: | this.button1.Text = Resource.GetString("Global.OKButtonText"); | |
| 268: | ||
| 269: | // | |
| 270: | // button2 | |
| 271: | // | |
| 272: | this.button2.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right); | |
| 273: | this.button2.Location = new System.Drawing.Point(428 + 88, 464); | |
| 274: | this.button2.Size = new System.Drawing.Size(74, 23); | |
| 275: | this.button2.TabIndex = 2; | |
| 276: | this.button2.DialogResult = DialogResult.Cancel; | |
| 277: | this.button2.Text = Resource.GetString("Global.CancelButtonText"); | |
| 278: | ||
| 279: | // | |
| 280: | // panel2 | |
| 281: | // | |
| 282: | this.panel2.Controls.AddRange(new System.Windows.Forms.Control[] {this.panel3, | |
| 283: | this.label1}); | |
| 284: | this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; | |
| 285: | this.panel2.Location = new System.Drawing.Point(126, 0); | |
| 286: | this.panel2.Size = new System.Drawing.Size(466, 456); | |
| 287: | this.panel2.TabIndex = 2; | |
| 288: | ||
| 289: | // | |
| 290: | // label1 | |
| 291: | // | |
| 292: | this.label1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | |
| 293: | | System.Windows.Forms.AnchorStyles.Right); | |
| 294: | this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); | |
| 295: | this.label1.Location = new System.Drawing.Point(0, 8); | |
| 296: | this.label1.Size = new System.Drawing.Size(456, 24); | |
| 297: | this.label1.TabIndex = 2; | |
| 298: | ||
| 299: | // | |
| 300: | // panel3 | |
| 301: | // | |
| 302: | this.panel3.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | |
| 303: | | System.Windows.Forms.AnchorStyles.Left) | |
| 304: | | System.Windows.Forms.AnchorStyles.Right); | |
| 305: | this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; | |
| 306: | this.panel3.BackColor = System.Drawing.SystemColors.Control; | |
| 307: | this.panel3.Location = new System.Drawing.Point(0, 32); | |
| 308: | this.panel3.Size = new System.Drawing.Size(464, 424); | |
| 309: | this.panel3.TabIndex = 4; | |
| 310: | StartPosition = FormStartPosition.CenterScreen; | |
| 311: | // | |
| 312: | // Win32Form1 | |
| 313: | // | |
| 314: | this.AcceptButton = button1; | |
| 315: | this.CancelButton = button2; | |
| 316: | this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); | |
| 317: | this.ClientSize = new System.Drawing.Size(600, 493); | |
| 318: | this.Controls.AddRange(new System.Windows.Forms.Control[] {this.button2, | |
| 319: | this.button1, | |
| 320: | this.panel1}); | |
| 321: | this.panel1.ResumeLayout |