TBF : (1) SharedButtons: opt. buttons positions automated, (2) Export and import of transition sequences, ver. 2.18.1122

This commit is contained in:
Milan Hanajik 2019-01-25 12:52:05 +01:00
parent 9bed5e6682
commit 4e2c4c3bac
14 changed files with 416 additions and 205 deletions

View File

@ -1,7 +1,10 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
/// Copyright (c) 2013-2018 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
namespace Config.Entities
{
@ -37,5 +40,56 @@ namespace Config.Entities
foreach (var step in TransitionSteps) { result.TransitionSteps.Add(step.Clone()); }
return result;
}
}
public virtual void Export(StreamWriter output)
{
output.WriteLine(ItemNr.ToString(CultureInfo.InvariantCulture));
output.WriteLine(Name);
output.WriteLine(Description);
foreach (var step in TransitionSteps) { step.Export(output); }
output.WriteLine();
output.Close();
}
public static TransitionSequence Import(StreamReader input)
{
TransitionSequence result = new TransitionSequence();
result.ItemNr = int.Parse(input.ReadLine(), CultureInfo.InvariantCulture);
result.Name = input.ReadLine();
result.Description = input.ReadLine();
while (true)
{
TransitionStep step = TransitionStep.Import(input, result);
if (step == null)
break;
else
result.TransitionSteps.Add(step);
}
return result;
}
public virtual string Compare(StreamReader inp)
{
System.Text.StringBuilder diff = new System.Text.StringBuilder();
const string fmt = "{0} = {1}\r\n (in the file {2})\r\n";
string ln;
ln = inp.ReadLine(); /// skip ItemNr
ln = inp.ReadLine(); if (ln != Name) { diff.AppendFormat(fmt, "Name", Name, ln); };
ln = inp.ReadLine(); if (ln != Description) { diff.AppendFormat(fmt, "Description", Description, ln); };
//foreach (var step in TransitionSteps)
//{
// string testDiff = step.Compare(inp);
// if (testDiff.Contains(
//}
return diff.ToString();
}
}
}

View File

@ -1,8 +1,10 @@
///
/// Copyright (c) 2013-2015, 2017 Sensus Metering Systems
/// Copyright (c) 2013-2018 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
namespace Config.Entities
{
@ -61,5 +63,64 @@ namespace Config.Entities
result += indent + "PumpsWithFMPct = " + PumpWithFMPcts + Environment.NewLine;
return result;
}
public virtual void Export(StreamWriter output)
{
CultureInfo ci = CultureInfo.InvariantCulture;
output.WriteLine(ItemNr.ToString(ci));
output.WriteLine(Duration.ToString(ci));
output.WriteLine(Message);
output.WriteLine(EndCondition);
output.WriteLine(ValvesOpen);
output.WriteLine(ValvesClose);
output.WriteLine(RegulValvesPct);
output.WriteLine(PumpWithFMPcts);
}
public static TransitionStep Import(StreamReader input, TransitionSequence newSequence)
{
string firstLine = input.ReadLine();
if (string.IsNullOrEmpty(firstLine))
{
return null;
}
CultureInfo ci = CultureInfo.InvariantCulture;
int itemNr = int.Parse(firstLine, ci);
TransitionStep tst = new TransitionStep(itemNr, newSequence);
tst.Duration = int.Parse(input.ReadLine(), ci);
tst.Message = input.ReadLine();
tst.EndCondition = input.ReadLine();
tst.ValvesOpen = input.ReadLine();
tst.ValvesClose = input.ReadLine();
tst.RegulValvesPct = input.ReadLine();
tst.PumpWithFMPcts = input.ReadLine();
return tst;
}
public virtual string Compare(StreamReader inp)
{
System.Text.StringBuilder diff = new System.Text.StringBuilder();
string fmt = string.Format("Step {0} : ", ItemNr) + "{0} = {1}\r\n (in the file {2})\r\n";
string ln;
CultureInfo ci = CultureInfo.InvariantCulture;
string firstLine = inp.ReadLine();
if (string.IsNullOrEmpty(firstLine)) return string.Format("TransitionStep {0} is missing in the compared file\r\n", ItemNr);
if (ItemNr.ToString() != firstLine) { diff.AppendFormat(fmt, "ItemNr", ItemNr, firstLine); };
ln = inp.ReadLine(); if (ln != Duration.ToString(ci)) { diff.AppendFormat(fmt, "Duration", Duration.ToString(ci), ln); };
ln = inp.ReadLine(); if (ln != Message) { diff.AppendFormat(fmt, "Message", Message, ln); };
ln = inp.ReadLine(); if (ln != EndCondition) { diff.AppendFormat(fmt, "EndCondition", EndCondition, ln); };
ln = inp.ReadLine(); if (ln != ValvesOpen) { diff.AppendFormat(fmt, "ValvesOpen", ValvesOpen, ln); };
ln = inp.ReadLine(); if (ln != ValvesClose) { diff.AppendFormat(fmt, "ValvesClose", ValvesClose, ln); };
ln = inp.ReadLine(); if (ln != RegulValvesPct) { diff.AppendFormat(fmt, "RegulValvesPct", RegulValvesPct, ln); };
ln = inp.ReadLine(); if (ln != PumpWithFMPcts) { diff.AppendFormat(fmt, "PumpWithFMPcts", PumpWithFMPcts, ln); };
return diff.ToString();
}
}
}

View File

@ -1,8 +1,9 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
/// Copyright (c) 2013-2018 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.IO;
namespace Config.Entities
{
@ -35,5 +36,24 @@ namespace Config.Entities
foreach (var step in VirtualBenchSteps) { result.VirtualBenchSteps.Add(step.Clone()); }
return result;
}
public virtual void Export(StreamWriter output)
{
/// TODO
}
public static VirtualBenchSequence Import(StreamReader input)
{
VirtualBenchSequence result = new VirtualBenchSequence();
/// TODO
return result;
}
public virtual string Compare(StreamReader inp)
{
System.Text.StringBuilder diff = new System.Text.StringBuilder();
/// TODO
return diff.ToString();
}
}
}

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.18.1110.0")]
[assembly: AssemblyFileVersion("2.18.1110.0")]
[assembly: AssemblyVersion("2.18.1122.0")]
[assembly: AssemblyFileVersion("2.18.1122.0")]

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.18.1115.0")]
[assembly: AssemblyFileVersion("2.18.1115.0")]
[assembly: AssemblyVersion("2.18.1122.0")]
[assembly: AssemblyFileVersion("2.18.1122.0")]

View File

@ -177,7 +177,7 @@ namespace TBF.BenchControl.TestMethods.Endurance
seqStepsCtrl.OkBtnClicked();
}
slctdTab = tabControl.SelectedIndex;
sharedButtons.SetEnabled(TBF.UiControls.SharedButtons.Buttons.Add, true);
sharedButtons.EnableButtons(TBF.UiControls.SharedButtons.Buttons.Add);
sharedButtons.DisableButtons(TBF.UiControls.SharedButtons.Buttons.Remove);
RefreshAllTabs();
}

View File

@ -31,69 +31,70 @@ namespace TBF.Forms
/// </summary>
private void InitializeComponent()
{
this.tabNameTextBox = new System.Windows.Forms.TextBox();
this.okButton = new System.Windows.Forms.Button();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.SuspendLayout();
//
// tabNameTextBox
//
this.tabNameTextBox.Location = new System.Drawing.Point(33, 25);
this.tabNameTextBox.Name = "tabNameTextBox";
this.tabNameTextBox.Size = new System.Drawing.Size(145, 20);
this.tabNameTextBox.TabIndex = 1;
//
// okButton
//
this.okButton.Location = new System.Drawing.Point(209, 18);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(85, 33);
this.okButton.TabIndex = 2;
this.okButton.Text = "OK";
this.okButton.UseVisualStyleBackColor = true;
this.okButton.Click += new System.EventHandler(this.okButton_Click);
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.Checked = true;
this.radioButton1.Location = new System.Drawing.Point(37, 63);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(121, 17);
this.radioButton1.TabIndex = 3;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "Transition sequence";
this.radioButton1.UseVisualStyleBackColor = true;
//
// radioButton2
//
this.radioButton2.AutoSize = true;
this.radioButton2.Location = new System.Drawing.Point(37, 86);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(137, 17);
this.radioButton2.TabIndex = 4;
this.radioButton2.Text = "Virtual bench sequence";
this.radioButton2.UseVisualStyleBackColor = true;
//
// TabNameDlg
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(316, 122);
this.Controls.Add(this.radioButton2);
this.Controls.Add(this.radioButton1);
this.Controls.Add(this.okButton);
this.Controls.Add(this.tabNameTextBox);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "TabNameDlg";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.Text = "TabName";
this.Load += new System.EventHandler(this.TabNameDlg_Load);
this.ResumeLayout(false);
this.PerformLayout();
this.tabNameTextBox = new System.Windows.Forms.TextBox();
this.okButton = new System.Windows.Forms.Button();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.SuspendLayout();
//
// tabNameTextBox
//
this.tabNameTextBox.Location = new System.Drawing.Point(33, 25);
this.tabNameTextBox.Name = "tabNameTextBox";
this.tabNameTextBox.Size = new System.Drawing.Size(145, 20);
this.tabNameTextBox.TabIndex = 1;
//
// okButton
//
this.okButton.Location = new System.Drawing.Point(209, 18);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(85, 33);
this.okButton.TabIndex = 2;
this.okButton.Text = "OK";
this.okButton.UseVisualStyleBackColor = true;
this.okButton.Click += new System.EventHandler(this.okButton_Click);
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.Checked = true;
this.radioButton1.Location = new System.Drawing.Point(37, 63);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(121, 17);
this.radioButton1.TabIndex = 3;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "Transition sequence";
this.radioButton1.UseVisualStyleBackColor = true;
//
// radioButton2
//
this.radioButton2.AutoSize = true;
this.radioButton2.Location = new System.Drawing.Point(37, 86);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(137, 17);
this.radioButton2.TabIndex = 4;
this.radioButton2.Text = "Virtual bench sequence";
this.radioButton2.UseVisualStyleBackColor = true;
//
// TabNameDlg
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(316, 122);
this.Controls.Add(this.radioButton2);
this.Controls.Add(this.radioButton1);
this.Controls.Add(this.okButton);
this.Controls.Add(this.tabNameTextBox);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "TabNameDlg";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "TabName";
this.Load += new System.EventHandler(this.TabNameDlg_Load);
this.ResumeLayout(false);
this.PerformLayout();
}

View File

@ -1851,7 +1851,14 @@ namespace TBF
selectedTab == ProcedureTabs.Process ||
selectedTab == ProcedureTabs.Parameters;
sharedButtons.SetEnabled(SharedButtons.Buttons.Add, isMetr12ProcOrParams);
if (isMetr12ProcOrParams)
{
sharedButtons.EnableButtons(SharedButtons.Buttons.Add);
}
else
{
sharedButtons.DisableButtons(SharedButtons.Buttons.Add);
}
//bool removeBtnEnabled = (selectedTab != ProcedureTabs.General &&
// selectedTab != ProcedureTabs.History &&

View File

@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.18.1120.0")]
[assembly: AssemblyFileVersion("2.18.1120.0")]
[assembly: AssemblyVersion("2.18.1122.0")]
[assembly: AssemblyFileVersion("2.18.1122.0")]

View File

@ -798,6 +798,15 @@ namespace TBF.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Compare.
/// </summary>
internal static string Compare {
get {
return ResourceManager.GetString("Compare", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Component.
/// </summary>
@ -1581,6 +1590,15 @@ namespace TBF.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Export.
/// </summary>
internal static string Export {
get {
return ResourceManager.GetString("Export", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to NOK.
/// </summary>
@ -1932,6 +1950,15 @@ namespace TBF.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Import.
/// </summary>
internal static string Import {
get {
return ResourceManager.GetString("Import", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Information.
/// </summary>

View File

@ -1918,4 +1918,13 @@
<data name="Previous" xml:space="preserve">
<value>Previous</value>
</data>
<data name="Compare" xml:space="preserve">
<value>Compare</value>
</data>
<data name="Export" xml:space="preserve">
<value>Export</value>
</data>
<data name="Import" xml:space="preserve">
<value>Import</value>
</data>
</root>

View File

@ -12,6 +12,7 @@ using TBF.BenchControl.Generic;
using TBF.BenchControl.GenericDevices;
using TBF.Resources;
using TBF.UiControls;
using System.IO;
namespace TBF
{
@ -57,6 +58,7 @@ namespace TBF
IList<ITabWithListViewEx> seqStepsCtrls;
public TransitionsDlg()
{
/// Detect display setting: 100% = 96dpi, 125% = 120dpi, 150% = 144dpi.
@ -68,8 +70,9 @@ namespace TBF
sharedButtons.RequiredGroupMembership = new Users.Grp.GID[] { Users.Grp.GID.Metrologists };
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove |
SharedButtons.Buttons.Up | SharedButtons.Buttons.Down |
SharedButtons.Buttons.NewTab | SharedButtons.Buttons.RenameTab |
SharedButtons.Buttons.RemoveTab;
SharedButtons.Buttons.Export | SharedButtons.Buttons.Import |
SharedButtons.Buttons.Compare | SharedButtons.Buttons.NewTab |
SharedButtons.Buttons.RenameTab | SharedButtons.Buttons.RemoveTab;
sharedButtons.Unlocked += Unlocked;
sharedButtons.OKClicked += okButton_Click;
sharedButtons.CancelClicked += cancelButton_Click;
@ -77,6 +80,9 @@ namespace TBF
sharedButtons.RemoveClicked += removeButton_Click;
sharedButtons.UpClicked += upButton_Click;
sharedButtons.DownClicked += downButton_Click;
sharedButtons.ExportClicked += exportButton_Click;
sharedButtons.ImportClicked += importButton_Click;
sharedButtons.CompareClicked += compareButton_Click;
sharedButtons.NewTabClicked += newTabButton_Click;
sharedButtons.RenameTabClicked += renameTabButton_Click;
sharedButtons.RemoveTabClicked += removeTabButton_Click;
@ -149,7 +155,7 @@ namespace TBF
private void TransitionsDlg_Load(object sender, EventArgs e)
{
Localize();
LoadFormPosition();
LoadUISettings();
/// Now refresh the content of the dialog
RefreshAllTabs();
@ -170,6 +176,7 @@ namespace TBF
foreach (var ctrl in seqStepsCtrls) ctrl.Unlock();
}
private void newTabButton_Click(object sender, EventArgs e)
{
Forms.TabNameDlg dlg;
@ -495,7 +502,7 @@ namespace TBF
Cursor.Current = Cursors.Default;
SaveFormPosition();
SaveUISettings();
DialogResult = DialogResult.OK;
Close();
return;
@ -503,13 +510,13 @@ namespace TBF
private void cancelButton_Click(object sender, EventArgs e)
{
SaveFormPosition();
SaveUISettings();
DialogResult = DialogResult.Cancel;
Close();
return;
}
private void SaveFormPosition()
private void SaveUISettings()
{
TBF.LocalSettings ls = Program.LocalSettings;
if (WindowState == FormWindowState.Normal)
@ -529,13 +536,13 @@ namespace TBF
ls.Save();
}
private void LoadFormPosition()
private void LoadUISettings()
{
TBF.LocalSettings ls = Program.LocalSettings;
Width = (ls.TransitionsDlgWidth > 0) ? ls.TransitionsDlgWidth : 1050;
Height = (ls.TransitionsDlgHeight > 0) ? ls.TransitionsDlgHeight : 360;
Left = (ls.TransitionsDlgLeft != 0) ? ls.TransitionsDlgLeft : 150;
Top = (ls.TransitionsDlgTop != 0) ? ls.TransitionsDlgTop : 150;
Height = (ls.TransitionsDlgHeight > 0) ? ls.TransitionsDlgHeight : 650;
Left = (ls.TransitionsDlgLeft != 0) ? ls.TransitionsDlgLeft : 100;
Top = (ls.TransitionsDlgTop != 0) ? ls.TransitionsDlgTop : 100;
}
@ -549,7 +556,7 @@ namespace TBF
seqStepsCtrls[slctdTab].OkBtnClicked();
}
slctdTab = tabControl.SelectedIndex;
sharedButtons.SetEnabled(SharedButtons.Buttons.Add, true);
sharedButtons.EnableButtons(SharedButtons.Buttons.Add);
sharedButtons.DisableButtons(SharedButtons.Buttons.Remove);
RefreshAllTabs();
}
@ -601,15 +608,6 @@ namespace TBF
}
}
private void purgeStartCtrl_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedIndexChanged(sender, e);
}
private void purgeEndCtrl_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedIndexChanged(sender, e);
}
/// <summary>
/// Common part for three xxxListViewEx_SelectedIndexChanged event handlers
@ -639,5 +637,62 @@ namespace TBF
UpdateButtonStates(SharedButtons.SelectedItemPos.Middle);
}
}
}
private void exportButton_Click(object sender, EventArgs e)
{
TabPage tabPage = tabControl.SelectedTab;
TransitionSequence transitionSeq = tabPage.Tag as TransitionSequence;
VirtualBenchSequence virtualBenchSeq = tabPage.Tag as VirtualBenchSequence;
SaveFileDialog dlg = new SaveFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
if (transitionSeq != null)
{
/// export transition sequence
transitionSeq.Export(new StreamWriter(dlg.FileName, false, System.Text.Encoding.UTF8));
}
else if (virtualBenchSeq != null)
{
/// export virtual sequence
virtualBenchSeq.Export(new StreamWriter(dlg.FileName, false, System.Text.Encoding.UTF8));
}
}
}
private void importButton_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() != DialogResult.OK) return;
/// Import a procedure from a file
int tabId = TransitionSequences.Count + VirtualBenchSequences.Count;
TransitionSequence newSequence = TransitionSequence.Import(new StreamReader(dlg.FileName, System.Text.Encoding.UTF8));
newSequence.ItemNr = tabId;
/// Find an unused procedure name
string newName;
bool nameUsed;
for (int nameId = 1; true; nameId++)
{
newName = string.Format("{0} imported{1}", newSequence.Name, (nameId == 1) ? string.Empty : string.Format("({0})", nameId));
nameUsed = false;
foreach (var seq in TransitionSequences) if (seq.Name.Equals(newName)) nameUsed = true;
if (!nameUsed) break;
}
newSequence.Name = newName;
TransitionSequences.Add(newSequence);
AddTransitionSeqTab(newSequence);
seqStepsCtrls[tabId].Unlock();
tabControl.SelectTab(tabId);
}
private void compareButton_Click(object sender, EventArgs e)
{
MessageBox.Show("Comparing sequences in not implemented yet");
}
}
}

View File

@ -151,7 +151,7 @@ namespace TBF.UiControls
// newTabButton
//
this.newTabButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.newTabButton.Location = new System.Drawing.Point(10, 394);
this.newTabButton.Location = new System.Drawing.Point(10, 565);
this.newTabButton.Name = "newTabButton";
this.newTabButton.Size = new System.Drawing.Size(80, 40);
this.newTabButton.TabIndex = 9;
@ -162,7 +162,7 @@ namespace TBF.UiControls
// renameTabButton
//
this.renameTabButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.renameTabButton.Location = new System.Drawing.Point(10, 437);
this.renameTabButton.Location = new System.Drawing.Point(10, 608);
this.renameTabButton.Name = "renameTabButton";
this.renameTabButton.Size = new System.Drawing.Size(80, 40);
this.renameTabButton.TabIndex = 10;
@ -173,7 +173,7 @@ namespace TBF.UiControls
// removeTabButton
//
this.removeTabButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.removeTabButton.Location = new System.Drawing.Point(10, 480);
this.removeTabButton.Location = new System.Drawing.Point(10, 651);
this.removeTabButton.Name = "removeTabButton";
this.removeTabButton.Size = new System.Drawing.Size(80, 40);
this.removeTabButton.TabIndex = 11;
@ -184,7 +184,7 @@ namespace TBF.UiControls
// moreButton
//
this.moreButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.moreButton.Location = new System.Drawing.Point(10, 523);
this.moreButton.Location = new System.Drawing.Point(10, 694);
this.moreButton.Name = "moreButton";
this.moreButton.Size = new System.Drawing.Size(80, 40);
this.moreButton.TabIndex = 12;
@ -246,7 +246,7 @@ namespace TBF.UiControls
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.okButton);
this.Name = "SharedButtons";
this.Size = new System.Drawing.Size(100, 649);
this.Size = new System.Drawing.Size(100, 805);
this.Load += new System.EventHandler(this.SharedDlgButtons_Load);
this.ResumeLayout(false);

View File

@ -17,23 +17,23 @@ namespace TBF.UiControls
public enum Buttons
{
None = 0,
OK = 1, /// always visible, text = 'Close' when locked
Cancel = 2, /// always visible
Add = 4, /// optional
Remove = 8, /// optional
Up = 0x10, /// optional
Down = 0x20, /// optional
Edit = 0x40, /// optional
Copy = 0x80, /// optional
NewTab = 0x100, /// optional
RenameTab = 0x200, /// optional
RemoveTab = 0x400, /// optional
More = 0x800, /// optional
Export = 0x1000, /// optional
Import = 0x2000, /// optional
Compare = 0x4000, /// optional
Add = (1 << 0), /// optional
Remove = (1 << 1), /// optional
Up = (1 << 2), /// optional
Down = (1 << 3), /// optional
Edit = (1 << 4), /// optional
Copy = (1 << 5), /// optional
Export = (1 << 6), /// optional
Import = (1 << 7), /// optional
Compare = (1 << 8), /// optional
NewTab = (1 << 9), /// optional
RenameTab = (1 << 10), /// optional
RemoveTab = (1 << 11), /// optional
More = (1 << 12), /// optional
}
readonly System.Windows.Forms.Button[] buttonCtrls;
/// <summary>
/// Optional buttons are Add, Remove, Up, Down, Edit and Copy.
/// OK and Cancel buttons are always visible (after unlock), but not always enabled.
@ -47,6 +47,8 @@ namespace TBF.UiControls
}
LockState lockState;
bool buttonsRepositionsed;
public bool MoreActive;
public int MoreButtonTop;
@ -72,12 +74,19 @@ namespace TBF.UiControls
/// </summary>
public SharedButtons()
{
InitializeComponent();
originalUser = Users.GlobalData.CurrentUser;
lockState = LockState.Locked;
MoreActive = false;
OptionalButtons = Buttons.None;
RequiredGroupMembership = null;
InitializeComponent();
buttonCtrls = new System.Windows.Forms.Button[]
{
addButton, removeButton, upButton, downButton, editButton, copyButton,
exportButton, importButton, compareButton,
newTabButton, renameTabButton, removeTabButton, moreButton,
};
OptionalButtons = Buttons.None;
buttonsRepositionsed = false;
}
/// <summary>
@ -96,120 +105,88 @@ namespace TBF.UiControls
downButton.Text = Strings.DownBtnText;
editButton.Text = Strings.EditBtnText;
copyButton.Text = Strings.CopyBtnText;
exportButton.Text = Strings.Export;
importButton.Text = Strings.Import;
compareButton.Text = Strings.Compare;
newTabButton.Text = Strings.NewTabBtnText;
renameTabButton.Text = Strings.RenameTabBtnText;
removeTabButton.Text = Strings.RemoveTabBtnText;
moreButton.Text = Strings.MoreBtnText;
cancelButton.Hide();
addButton.Hide();
removeButton.Hide();
upButton.Hide();
downButton.Hide();
editButton.Hide();
copyButton.Hide();
newTabButton.Hide();
renameTabButton.Hide();
removeTabButton.Hide();
moreButton.Hide();
exportButton.Hide();
importButton.Hide();
compareButton.Hide();
/// Reposition 'Edit' and 'Copy" buttons in case both 'Up' and 'Down' are hidden
if (((OptionalButtons & Buttons.Up) == 0) &&
((OptionalButtons & Buttons.Down) == 0))
{
editButton.Top = upButton.Top;
copyButton.Top = downButton.Top;
}
/// Reposition Tab-related button in case both 'Edit' and 'Copy" are hidden
if (((OptionalButtons & Buttons.Edit) == 0) &&
((OptionalButtons & Buttons.Copy) == 0))
{
removeTabButton.Top = newTabButton.Top + 15;
newTabButton.Top = editButton.Top + 15;
renameTabButton.Top = copyButton.Top + 15;
}
if ((OptionalButtons & Buttons.Add) == 0 &&
(OptionalButtons & Buttons.Remove) == 0 &&
(OptionalButtons & Buttons.Up) == 0 &&
(OptionalButtons & Buttons.Down) == 0 &&
(OptionalButtons & Buttons.Edit) == 0 &&
(OptionalButtons & Buttons.Copy) == 0 &&
(OptionalButtons & Buttons.NewTab) == 0 &&
(OptionalButtons & Buttons.RenameTab) == 0 &&
(OptionalButtons & Buttons.RemoveTab) == 0)
{
moreButton.Top = MoreButtonTop;
}
#if DEBUG
//unlockBtn_Click(sender, e);
#endif
ShowOrHideButtons((Buttons)0x7FFFFFFF, false);
}
void RepositionButtons(Buttons enabledButtons)
{
if (!buttonsRepositionsed)
{
buttonsRepositionsed = true; /// Reposition buttons once
int spacing = unlockButton.Height + 3;
const int ExtraSpacing = 15;
int nextTop = cancelButton.Top + spacing + ExtraSpacing;
for (int i = 0; i < buttonCtrls.Length; i++)
{
Buttons btn = (Buttons)(1 << i);
if ((OptionalButtons & btn) != 0)
{
buttonCtrls[i].Top = nextTop;
nextTop += spacing + ((btn == Buttons.Down || btn == Buttons.Compare || btn == Buttons.RemoveTab) ? ExtraSpacing : 0);
}
}
}
}
void ShowOrHideButtons(Buttons selectedButtons, bool value)
{
for (int i = 0; i < buttonCtrls.Length; i++)
{
if ((selectedButtons & (Buttons)(1 << i)) != 0) buttonCtrls[i].Visible = value;
}
}
public void EnableOrDisableButtons(Buttons selectedButtons, bool value)
{
for (int i = 0; i < buttonCtrls.Length; i++)
{
if ((selectedButtons & (Buttons)(1 << i)) != 0) buttonCtrls[i].Enabled = value;
}
}
/// <summary>
/// Update the visibility of buttons and OK button text when the dialog is unlocked
/// </summary>
public void UnlockButtons()
{
RepositionButtons(OptionalButtons);
unlockButton.Enabled = false;
okButton.Text = Strings.OkBtnText;
cancelButton.Show();
if ((OptionalButtons & Buttons.Add) != 0) addButton.Show();
if ((OptionalButtons & Buttons.Remove) != 0) removeButton.Show();
if ((OptionalButtons & Buttons.Up) != 0) upButton.Show();
if ((OptionalButtons & Buttons.Down) != 0) downButton.Show();
if ((OptionalButtons & Buttons.Edit) != 0) editButton.Show();
if ((OptionalButtons & Buttons.Copy) != 0) copyButton.Show();
if ((OptionalButtons & Buttons.NewTab) != 0) newTabButton.Show();
if ((OptionalButtons & Buttons.RenameTab) != 0) renameTabButton.Show();
if ((OptionalButtons & Buttons.RemoveTab) != 0) removeTabButton.Show();
if ((OptionalButtons & Buttons.More) != 0) moreButton.Show();
if ((OptionalButtons & Buttons.Export) != 0) exportButton.Show();
if ((OptionalButtons & Buttons.Import) != 0) importButton.Show();
if ((OptionalButtons & Buttons.Compare) != 0) compareButton.Show();
cancelButton.Visible = true;
ShowOrHideButtons(OptionalButtons, true);
lockState = LockState.Unlocked;
}
/// <summary>
/// Enable specified buttons
/// </summary>
public void EnableButtons(Buttons buttons)
public void EnableButtons(Buttons selectedButtons)
{
SetEnabled(buttons, true);
EnableOrDisableButtons(selectedButtons, true);
}
/// <summary>
/// Disable specified buttons
/// </summary>
public void DisableButtons(Buttons buttons)
public void DisableButtons(Buttons selectedButtons)
{
SetEnabled(buttons, false);
EnableOrDisableButtons(selectedButtons, false);
}
public void SetEnabled(Buttons buttons, bool value)
{
if ((buttons & Buttons.OK) != 0) okButton.Enabled = value;
if ((buttons & Buttons.Cancel) != 0) cancelButton.Enabled = value;
if ((buttons & Buttons.Add) != 0) addButton.Enabled = value;
if ((buttons & Buttons.Remove) != 0) removeButton.Enabled = value;
if ((buttons & Buttons.Up) != 0) upButton.Enabled = value;
if ((buttons & Buttons.Down) != 0) downButton.Enabled = value;
if ((buttons & Buttons.Edit) != 0) editButton.Enabled = value;
if ((buttons & Buttons.Copy) != 0) copyButton.Enabled = value;
if ((buttons & Buttons.NewTab) != 0) newTabButton.Enabled = value;
if ((buttons & Buttons.RenameTab) != 0) renameTabButton.Enabled = value;
if ((buttons & Buttons.RemoveTab) != 0) removeTabButton.Enabled = value;
if ((buttons & Buttons.More) != 0) moreButton.Enabled = value;
if ((buttons & Buttons.Export) != 0) exportButton.Enabled = value;
if ((buttons & Buttons.Import) != 0) importButton.Enabled = value;
if ((buttons & Buttons.Compare) != 0) compareButton.Enabled = value;
}
void RestoreUser()
{
Users.GlobalData.CurrentUser = originalUser;
@ -305,11 +282,11 @@ namespace TBF.UiControls
private void downBtn_Click(object s, EventArgs e) { if (DownClicked != null) DownClicked(s, e); }
private void editBtn_Click(object s, EventArgs e) { if (EditClicked != null) EditClicked(s, e); }
private void copyBtn_Click(object s, EventArgs e) { if (CopyClicked != null) CopyClicked(s, e); }
private void newTabButton_Click(object s, EventArgs e) { if (NewTabClicked != null) NewTabClicked(s, e); }
private void renameTabButton_Click(object s, EventArgs e) { if (RenameTabClicked != null) RenameTabClicked(s, e); }
private void removeTabButton_Click(object s, EventArgs e) { if (RemoveTabClicked != null) RemoveTabClicked(s, e); }
private void exportButton_Click(object s, EventArgs e) { if (ExportClicked != null) ExportClicked(s, e); }
private void importButton_Click(object s, EventArgs e) { if (ImportClicked != null) ImportClicked(s, e); }
private void compareButton_Click(object s, EventArgs e) { if (CompareClicked != null) CompareClicked(s, e); }
private void newTabButton_Click(object s, EventArgs e) { if (NewTabClicked != null) NewTabClicked(s, e); }
private void renameTabButton_Click(object s, EventArgs e) { if (RenameTabClicked != null) RenameTabClicked(s, e); }
private void removeTabButton_Click(object s, EventArgs e) { if (RemoveTabClicked != null) RemoveTabClicked(s, e); }
}
}