/*
* Filename: SelectCommand.cs
* Product: Versioning Controlled Build
* Solution: BuildAutoIncrement
* Project: Test
* Description: Dialog to select VCB command to execute.
* Copyright: Julijan �ribar, 2004-2010
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the author(s) be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Diagnostics;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace BuildAutoIncrement {
/// <summary>
/// Summary description for SelectCommand.
/// </summary>
public class SelectCommandForm : System.Windows.Forms.Form {
public enum VcbCommand {
GUI,
Save,
Build,
Rebuild
}
#region Controls
private System.Windows.Forms.Button m_buttonGUI;
private System.Windows.Forms.Button m_buttonSave;
private System.Windows.Forms.Button m_buttonBuild;
private System.Windows.Forms.Button m_buttonRebuild;
private System.Windows.Forms.Button m_buttonCancel;
private System.Windows.Forms.CheckBox m_checkBoxUseActualConfiguration;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Panel m_panelConfiguration;
private System.Windows.Forms.TabPage[] m_configurationTabPages;
private ConfigurationForm m_configurationForm;
#endregion // Controls
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private VcbCommand m_vcbCommand = VcbCommand.GUI;
private VcbConfiguration m_configuration;
public SelectCommandForm() {
InitializeComponent();
AddConfigurationControls();
m_checkBoxUseActualConfiguration.Checked = true;
m_configuration = ConfigurationPersister.Instance.Configuration;
}
public VcbCommand CommandToExecute {
get {
return m_vcbCommand;
}
}
public VcbConfiguration Configuration {
get {
Debug.Assert(m_configuration != null);
return m_configuration;
}
}
private void AddConfigurationControls() {
m_configurationForm = new ConfigurationForm();
// hack to avoid copying the code
ArrayList tabPages = new ArrayList();
int tabControlHeight = 0;
foreach (Control control in m_configurationForm.Controls) {
m_panelConfiguration.Controls.Add(control);
// remove "Appearance" tab page
if (control is TabControl) {
TabControl tc = (TabControl)control;
tabControlHeight = tc.Bounds.Height;
tc.Anchor = AnchorStyles.Top | AnchorStyles.Left;
foreach (TabPage tp in tc.TabPages) {
if (tp.Name == "m_tabPageAppearance") {
tc.TabPages.Remove(tp);
}
else {
tabPages.Add(tp);
}
}
tc.SelectedIndex = 0;
}
// disable all buttons
if (control is Button)
control.Enabled = false;
}
// store references to tab pages to allow enabling/disabling them
m_configurationTabPages = (TabPage[])tabPages.ToArray(typeof(TabPage));
int deltaY = tabControlHeight - m_panelConfiguration.ClientRectangle.Height + 8;
Size = new Size(Width, Height + deltaY);
}
protected override void OnClosing(CancelEventArgs e) {
if (DialogResult != DialogResult.Cancel && !m_checkBoxUseActualConfiguration.Checked) {
m_configuration = m_configurationForm.GetConfiguration();
}
base.OnClosing(e);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose (bool disposing) {
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.m_buttonGUI = new System.Windows.Forms.Button();
this.m_buttonSave = new System.Windows.Forms.Button();
this.m_buttonBuild = new System.Windows.Forms.Button();
this.m_buttonRebuild = new System.Windows.Forms.Button();
this.m_buttonCancel = new System.Windows.Forms.Button();
this.m_checkBoxUseActualConfiguration = new System.Windows.Forms.CheckBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.m_panelConfiguration = new System.Windows.Forms.Panel();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// m_buttonGUI
//
this.m_buttonGUI.DialogResult = System.Windows.Forms.DialogResult.OK;
this.m_buttonGUI.Location = new System.Drawing.Point(16, 16);
this.m_buttonGUI.Name = "m_buttonGUI";
this.m_buttonGUI.TabIndex = 0;
this.m_buttonGUI.Text = "GUI";
this.m_buttonGUI.Click += new System.EventHandler(this.m_buttonGUI_Click);
//
// m_buttonSave
//
this.m_buttonSave.DialogResult = System.Windows.Forms.DialogResult.OK;
this.m_buttonSave.Location = new System.Drawing.Point(16, 48);
this.m_buttonSave.Name = "m_buttonSave";
this.m_buttonSave.TabIndex = 1;
this.m_buttonSave.Text = "Save";
this.m_buttonSave.Click += new System.EventHandler(this.m_buttonSave_Click);
//
// m_buttonBuild
//
this.m_buttonBuild.DialogResult = System.Windows.Forms.DialogResult.OK;
this.m_buttonBuild.Location = new System.Drawing.Point(16, 80);
this.m_buttonBuild.Name = "m_buttonBuild";
this.m_buttonBuild.TabIndex = 2;
this.m_buttonBuild.Text = "Build";
this.m_buttonBuild.Click += new System.EventHandler(this.m_buttonBuild_Click);
//
// m_buttonRebuild
//
this.m_buttonRebuild.DialogResult = System.Windows.Forms.DialogResult.OK;
this.m_buttonRebuild.Location = new System.Drawing.Point(16, 112);
this.m_buttonRebuild.Name = "m_buttonRebuild";
this.m_buttonRebuild.TabIndex = 3;
this.m_buttonRebuild.Text = "Rebuild";
this.m_buttonRebuild.Click += new System.EventHandler(this.m_buttonRebuild_Click);
//
// m_buttonCancel
//
this.m_buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.m_buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.m_buttonCancel.Location = new System.Drawing.Point(16, 376);
this.m_buttonCancel.Name = "m_buttonCancel";
this.m_buttonCancel.TabIndex = 4;
this.m_buttonCancel.Text = "Cancel";
//
// m_checkBoxUseActualConfiguration
//
this.m_checkBoxUseActualConfiguration.Location = new System.Drawing.Point(16, 24);
this.m_checkBoxUseActualConfiguration.Name = "m_checkBoxUseActualConfiguration";
this.m_checkBoxUseActualConfiguration.Size = new System.Drawing.Size(168, 24);
this.m_checkBoxUseActualConfiguration.TabIndex = 0;
this.m_checkBoxUseActualConfiguration.Text = "Use &actual configuration";
this.m_checkBoxUseActualConfiguration.CheckedChanged += new System.EventHandler(this.m_checkBoxUseActualConfiguration_CheckedChanged);
//
// groupBox1
//
this.groupBox1.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.groupBox1.Controls.Add(this.m_panelConfiguration);
this.groupBox1.Controls.Add(this.m_checkBoxUseActualConfiguration);
this.groupBox1.Location = new System.Drawing.Point(112, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(364, 396);
this.groupBox1.TabIndex = 5;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Batch commands options";
//
// m_panelConfiguration
//
this.m_panelConfiguration.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.m_panelConfiguration.DockPadding.Bottom = -8;
this.m_panelConfiguration.DockPadding.Left = -8;
this.m_panelConfiguration.DockPadding.Right = -8;
this.m_panelConfiguration.DockPadding.Top = -8;
this.m_panelConfiguration.Location = new System.Drawing.Point(2, 48);
this.m_panelConfiguration.Name = "m_panelConfiguration";
this.m_panelConfiguration.Size = new System.Drawing.Size(358, 338);
this.m_panelConfiguration.TabIndex = 1;
//
// SelectCommandForm
//
this.AcceptButton = this.m_buttonGUI;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.m_buttonCancel;
this.ClientSize = new System.Drawing.Size(490, 415);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.m_buttonCancel);
this.Controls.Add(this.m_buttonRebuild);
this.Controls.Add(this.m_buttonBuild);
this.Controls.Add(this.m_buttonSave);
this.Controls.Add(this.m_buttonGUI);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "SelectCommandForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "VCB Test";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void m_buttonGUI_Click(object sender, System.EventArgs e) {
m_vcbCommand = VcbCommand.GUI;
this.Close();
}
private void m_buttonSave_Click(object sender, System.EventArgs e) {
m_vcbCommand = VcbCommand.Save;
this.Close();
}
private void m_buttonBuild_Click(object sender, System.EventArgs e) {
m_vcbCommand = VcbCommand.Build;
this.Close();
}
private void m_buttonRebuild_Click(object sender, System.EventArgs e) {
m_vcbCommand = VcbCommand.Rebuild;
this.Close();
}
private void m_checkBoxUseActualConfiguration_CheckedChanged(object sender, System.EventArgs e) {
foreach (TabPage tp in m_configurationTabPages) {
// undocumented propery for TabPage :o)
tp.Enabled = !m_checkBoxUseActualConfiguration.Checked;
}
}
protected override void OnLoad(EventArgs e) {
base.OnLoad (e);
Debug.Assert(m_configuration != null);
if (!m_configuration.ConfigurationFileRead) {
MessageBox.Show(this, "Failed to load configuration file - default configuration is used instead", "VCB Configuration Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// configuration failure has been reported - do not report any more
m_configuration.ConfigurationFileRead = true;
}
}
}
}