Implement OK/Cancel buttons on OptionsDialog

This commit is contained in:
Michael Becker 2014-06-26 14:51:33 -04:00
parent 98c8990835
commit a4595d4382
2 changed files with 210 additions and 196 deletions

View File

@ -29,106 +29,108 @@ namespace UniversalEditor.UserInterface.WindowsForms.Dialogs
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.tv = new System.Windows.Forms.TreeView();
this.imlSmallIcons = new System.Windows.Forms.ImageList(this.components);
this.pnlContainer = new System.Windows.Forms.Panel();
this.sc = new System.Windows.Forms.SplitContainer();
this.cmdCancel = new System.Windows.Forms.Button();
this.cmdOK = new System.Windows.Forms.Button();
this.sc.Panel1.SuspendLayout();
this.sc.Panel2.SuspendLayout();
this.sc.SuspendLayout();
this.SuspendLayout();
//
// tv
//
this.tv.Dock = System.Windows.Forms.DockStyle.Fill;
this.tv.ImageIndex = 0;
this.tv.ImageList = this.imlSmallIcons;
this.tv.Location = new System.Drawing.Point(0, 0);
this.tv.Name = "tv";
this.tv.SelectedImageIndex = 0;
this.tv.Size = new System.Drawing.Size(150, 223);
this.tv.TabIndex = 0;
this.tv.AfterCollapse += new System.Windows.Forms.TreeViewEventHandler(this.tv_AfterCollapse);
this.tv.AfterExpand += new System.Windows.Forms.TreeViewEventHandler(this.tv_AfterExpand);
this.tv.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tv_AfterSelect);
//
// imlSmallIcons
//
this.imlSmallIcons.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
this.imlSmallIcons.ImageSize = new System.Drawing.Size(16, 16);
this.imlSmallIcons.TransparentColor = System.Drawing.Color.Transparent;
//
// pnlContainer
//
this.pnlContainer.Dock = System.Windows.Forms.DockStyle.Fill;
this.pnlContainer.Location = new System.Drawing.Point(0, 0);
this.pnlContainer.Name = "pnlContainer";
this.pnlContainer.Size = new System.Drawing.Size(296, 223);
this.pnlContainer.TabIndex = 1;
//
// sc
//
this.sc.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
this.components = new System.ComponentModel.Container();
this.tv = new System.Windows.Forms.TreeView();
this.imlSmallIcons = new System.Windows.Forms.ImageList(this.components);
this.pnlContainer = new System.Windows.Forms.Panel();
this.sc = new System.Windows.Forms.SplitContainer();
this.cmdCancel = new System.Windows.Forms.Button();
this.cmdOK = new System.Windows.Forms.Button();
this.sc.Panel1.SuspendLayout();
this.sc.Panel2.SuspendLayout();
this.sc.SuspendLayout();
this.SuspendLayout();
//
// tv
//
this.tv.Dock = System.Windows.Forms.DockStyle.Fill;
this.tv.ImageIndex = 0;
this.tv.ImageList = this.imlSmallIcons;
this.tv.Location = new System.Drawing.Point(0, 0);
this.tv.Name = "tv";
this.tv.SelectedImageIndex = 0;
this.tv.Size = new System.Drawing.Size(150, 223);
this.tv.TabIndex = 0;
this.tv.AfterCollapse += new System.Windows.Forms.TreeViewEventHandler(this.tv_AfterCollapse);
this.tv.AfterExpand += new System.Windows.Forms.TreeViewEventHandler(this.tv_AfterExpand);
this.tv.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tv_AfterSelect);
//
// imlSmallIcons
//
this.imlSmallIcons.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
this.imlSmallIcons.ImageSize = new System.Drawing.Size(16, 16);
this.imlSmallIcons.TransparentColor = System.Drawing.Color.Transparent;
//
// pnlContainer
//
this.pnlContainer.Dock = System.Windows.Forms.DockStyle.Fill;
this.pnlContainer.Location = new System.Drawing.Point(0, 0);
this.pnlContainer.Name = "pnlContainer";
this.pnlContainer.Size = new System.Drawing.Size(296, 223);
this.pnlContainer.TabIndex = 1;
//
// sc
//
this.sc.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.sc.Location = new System.Drawing.Point(12, 12);
this.sc.Name = "sc";
//
// sc.Panel1
//
this.sc.Panel1.Controls.Add(this.tv);
//
// sc.Panel2
//
this.sc.Panel2.Controls.Add(this.pnlContainer);
this.sc.Size = new System.Drawing.Size(450, 223);
this.sc.SplitterDistance = 150;
this.sc.TabIndex = 2;
//
// cmdCancel
//
this.cmdCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cmdCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.cmdCancel.Location = new System.Drawing.Point(387, 253);
this.cmdCancel.Name = "cmdCancel";
this.cmdCancel.Size = new System.Drawing.Size(75, 23);
this.cmdCancel.TabIndex = 3;
this.cmdCancel.Text = "Cancel";
this.cmdCancel.UseVisualStyleBackColor = true;
//
// cmdOK
//
this.cmdOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.cmdOK.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.cmdOK.Location = new System.Drawing.Point(306, 253);
this.cmdOK.Name = "cmdOK";
this.cmdOK.Size = new System.Drawing.Size(75, 23);
this.cmdOK.TabIndex = 3;
this.cmdOK.Text = "OK";
this.cmdOK.UseVisualStyleBackColor = true;
//
// OptionsDialog
//
this.AcceptButton = this.cmdOK;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cmdCancel;
this.ClientSize = new System.Drawing.Size(474, 288);
this.Controls.Add(this.cmdOK);
this.Controls.Add(this.cmdCancel);
this.Controls.Add(this.sc);
this.Name = "OptionsDialog";
this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Options";
this.sc.Panel1.ResumeLayout(false);
this.sc.Panel2.ResumeLayout(false);
this.sc.ResumeLayout(false);
this.ResumeLayout(false);
this.sc.Location = new System.Drawing.Point(12, 12);
this.sc.Name = "sc";
//
// sc.Panel1
//
this.sc.Panel1.Controls.Add(this.tv);
//
// sc.Panel2
//
this.sc.Panel2.Controls.Add(this.pnlContainer);
this.sc.Size = new System.Drawing.Size(450, 223);
this.sc.SplitterDistance = 150;
this.sc.TabIndex = 2;
//
// cmdCancel
//
this.cmdCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cmdCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.cmdCancel.Location = new System.Drawing.Point(387, 253);
this.cmdCancel.Name = "cmdCancel";
this.cmdCancel.Size = new System.Drawing.Size(75, 23);
this.cmdCancel.TabIndex = 3;
this.cmdCancel.Text = "Cancel";
this.cmdCancel.UseVisualStyleBackColor = true;
this.cmdCancel.Click += new System.EventHandler(this.cmdCancel_Click);
//
// cmdOK
//
this.cmdOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.cmdOK.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.cmdOK.Location = new System.Drawing.Point(306, 253);
this.cmdOK.Name = "cmdOK";
this.cmdOK.Size = new System.Drawing.Size(75, 23);
this.cmdOK.TabIndex = 3;
this.cmdOK.Text = "OK";
this.cmdOK.UseVisualStyleBackColor = true;
this.cmdOK.Click += new System.EventHandler(this.cmdOK_Click);
//
// OptionsDialog
//
this.AcceptButton = this.cmdOK;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cmdCancel;
this.ClientSize = new System.Drawing.Size(474, 288);
this.Controls.Add(this.cmdOK);
this.Controls.Add(this.cmdCancel);
this.Controls.Add(this.sc);
this.Name = "OptionsDialog";
this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Options";
this.sc.Panel1.ResumeLayout(false);
this.sc.Panel2.ResumeLayout(false);
this.sc.ResumeLayout(false);
this.ResumeLayout(false);
}

View File

@ -7,114 +7,126 @@ using System.Windows.Forms;
namespace UniversalEditor.UserInterface.WindowsForms.Dialogs
{
public partial class OptionsDialog : AwesomeControls.Dialog
{
public OptionsDialog()
{
InitializeComponent();
public partial class OptionsDialog : AwesomeControls.Dialog
{
public OptionsDialog()
{
InitializeComponent();
IconMethods.PopulateSystemIcons(ref imlSmallIcons);
IconMethods.PopulateSystemIcons(ref imlSmallIcons);
IOptionPanelImplementation[] panels = UniversalEditor.UserInterface.Common.Reflection.GetAvailableOptionPanels();
foreach (IOptionPanelImplementation panel in panels)
{
if (panel is OptionPanel && panel.GetType().IsSubclassOf(typeof(OptionPanel)))
{
OptionPanel oppanel = (panel as OptionPanel);
TreeNode tnParent = null;
IOptionPanelImplementation[] panels = UniversalEditor.UserInterface.Common.Reflection.GetAvailableOptionPanels();
foreach (IOptionPanelImplementation panel in panels)
{
if (panel is OptionPanel && panel.GetType().IsSubclassOf(typeof(OptionPanel)))
{
OptionPanel oppanel = (panel as OptionPanel);
TreeNode tnParent = null;
#region get the parent
for (int i = 0; i < oppanel.OptionGroups.Length - 1; i++)
{
TreeNodeCollection tnc = null;
if (tnParent == null)
{
tnc = tv.Nodes;
}
else
{
tnc = tnParent.Nodes;
}
if (tnc.ContainsKey(oppanel.OptionGroups[i]))
{
tnParent = tnc[oppanel.OptionGroups[i]];
}
else
{
tnParent = tnc.Add(oppanel.OptionGroups[i], oppanel.OptionGroups[i], "generic-folder-closed");
}
}
#endregion
#region get the parent
for (int i = 0; i < oppanel.OptionGroups.Length - 1; i++)
{
TreeNodeCollection tnc = null;
if (tnParent == null)
{
tnc = tv.Nodes;
}
else
{
tnc = tnParent.Nodes;
}
if (tnc.ContainsKey(oppanel.OptionGroups[i]))
{
tnParent = tnc[oppanel.OptionGroups[i]];
}
else
{
tnParent = tnc.Add(oppanel.OptionGroups[i], oppanel.OptionGroups[i], "generic-folder-closed");
}
}
#endregion
if (tnParent == null)
{
tnParent = tv.Nodes.Add(oppanel.OptionGroups[oppanel.OptionGroups.Length - 1], oppanel.OptionGroups[oppanel.OptionGroups.Length - 1], oppanel.OptionGroups[oppanel.OptionGroups.Length - 1]);
}
else
{
tnParent = tnParent.Nodes.Add(oppanel.OptionGroups[oppanel.OptionGroups.Length - 1], oppanel.OptionGroups[oppanel.OptionGroups.Length - 1], oppanel.OptionGroups[oppanel.OptionGroups.Length - 1]);
}
if (tnParent == null)
{
tnParent = tv.Nodes.Add(oppanel.OptionGroups[oppanel.OptionGroups.Length - 1], oppanel.OptionGroups[oppanel.OptionGroups.Length - 1], oppanel.OptionGroups[oppanel.OptionGroups.Length - 1]);
}
else
{
tnParent = tnParent.Nodes.Add(oppanel.OptionGroups[oppanel.OptionGroups.Length - 1], oppanel.OptionGroups[oppanel.OptionGroups.Length - 1], oppanel.OptionGroups[oppanel.OptionGroups.Length - 1]);
}
tnParent.Tag = oppanel;
tnParent.SelectedImageKey = tnParent.ImageKey;
if (!imlSmallIcons.Images.ContainsKey(tnParent.Text) && oppanel.IconImage != null)
{
imlSmallIcons.Images.Add(tnParent.Text, oppanel.IconImage);
}
tnParent.Tag = oppanel;
tnParent.SelectedImageKey = tnParent.ImageKey;
if (!imlSmallIcons.Images.ContainsKey(tnParent.Text) && oppanel.IconImage != null)
{
imlSmallIcons.Images.Add(tnParent.Text, oppanel.IconImage);
}
oppanel.Dock = DockStyle.Fill;
pnlContainer.Controls.Add(oppanel);
}
}
oppanel.Dock = DockStyle.Fill;
pnlContainer.Controls.Add(oppanel);
}
}
Font = SystemFonts.MenuFont;
AutoSize = true;
}
Font = SystemFonts.MenuFont;
AutoSize = true;
}
private void SwitchPanel(OptionPanel panel)
{
foreach (Control ctl in pnlContainer.Controls)
{
if (ctl == panel)
{
ctl.Enabled = true;
ctl.Visible = true;
ctl.BringToFront();
}
else
{
ctl.Visible = false;
ctl.Enabled = false;
}
}
}
private void SwitchPanel(OptionPanel panel)
{
foreach (Control ctl in pnlContainer.Controls)
{
if (ctl == panel)
{
ctl.Enabled = true;
ctl.Visible = true;
ctl.BringToFront();
}
else
{
ctl.Visible = false;
ctl.Enabled = false;
}
}
}
private void tv_AfterSelect(object sender, TreeViewEventArgs e)
{
if (e.Node == null) return;
OptionPanel panel = (e.Node.Tag as OptionPanel);
SwitchPanel(panel);
}
private void tv_AfterSelect(object sender, TreeViewEventArgs e)
{
if (e.Node == null) return;
OptionPanel panel = (e.Node.Tag as OptionPanel);
SwitchPanel(panel);
}
private void tv_AfterCollapse(object sender, TreeViewEventArgs e)
{
if (e.Node == null) return;
if (e.Node.ImageKey == "generic-folder-open")
{
e.Node.ImageKey = "generic-folder-closed";
e.Node.SelectedImageKey = "generic-folder-closed";
}
}
private void tv_AfterCollapse(object sender, TreeViewEventArgs e)
{
if (e.Node == null) return;
if (e.Node.ImageKey == "generic-folder-open")
{
e.Node.ImageKey = "generic-folder-closed";
e.Node.SelectedImageKey = "generic-folder-closed";
}
}
private void tv_AfterExpand(object sender, TreeViewEventArgs e)
{
if (e.Node == null) return;
if (e.Node.ImageKey == "generic-folder-closed")
{
e.Node.ImageKey = "generic-folder-open";
e.Node.SelectedImageKey = "generic-folder-open";
}
}
}
private void tv_AfterExpand(object sender, TreeViewEventArgs e)
{
if (e.Node == null) return;
if (e.Node.ImageKey == "generic-folder-closed")
{
e.Node.ImageKey = "generic-folder-open";
e.Node.SelectedImageKey = "generic-folder-open";
}
}
private void cmdOK_Click(object sender, EventArgs e)
{
this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
private void cmdCancel_Click(object sender, EventArgs e)
{
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.Close();
}
}
}