From 5d09cb7e57a8515d534367293f0643eab89358b6 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sat, 9 Jul 2022 15:07:07 +0200 Subject: [PATCH] Added the input dialog --- .../Dialogs/InputDialog.Designer.cs | 166 ++++++++++++++++++ .../UI WinForms/Dialogs/InputDialog.cs | 39 ++++ .../UI WinForms/Dialogs/InputDialog.resx | 60 +++++++ 3 files changed, 265 insertions(+) create mode 100644 I18N Commander/UI WinForms/Dialogs/InputDialog.Designer.cs create mode 100644 I18N Commander/UI WinForms/Dialogs/InputDialog.cs create mode 100644 I18N Commander/UI WinForms/Dialogs/InputDialog.resx diff --git a/I18N Commander/UI WinForms/Dialogs/InputDialog.Designer.cs b/I18N Commander/UI WinForms/Dialogs/InputDialog.Designer.cs new file mode 100644 index 0000000..f1b97b3 --- /dev/null +++ b/I18N Commander/UI WinForms/Dialogs/InputDialog.Designer.cs @@ -0,0 +1,166 @@ +namespace UI_WinForms.Dialogs +{ + partial class InputDialog + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.tableLayout = new System.Windows.Forms.TableLayoutPanel(); + this.labelHead = new System.Windows.Forms.Label(); + this.flowLayoutBottom = new System.Windows.Forms.FlowLayoutPanel(); + this.buttonOk = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.textBoxInput = new System.Windows.Forms.TextBox(); + this.checkBoxIsRoot = new System.Windows.Forms.CheckBox(); + this.tableLayout.SuspendLayout(); + this.flowLayoutBottom.SuspendLayout(); + this.SuspendLayout(); + // + // tableLayout + // + this.tableLayout.AutoSize = true; + this.tableLayout.ColumnCount = 1; + this.tableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayout.Controls.Add(this.labelHead, 0, 0); + this.tableLayout.Controls.Add(this.flowLayoutBottom, 0, 2); + this.tableLayout.Controls.Add(this.textBoxInput, 0, 1); + this.tableLayout.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayout.Location = new System.Drawing.Point(0, 0); + this.tableLayout.Name = "tableLayout"; + this.tableLayout.RowCount = 4; + this.tableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 66F)); + this.tableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayout.Size = new System.Drawing.Size(800, 139); + this.tableLayout.TabIndex = 0; + // + // labelHead + // + this.labelHead.AutoSize = true; + this.labelHead.Dock = System.Windows.Forms.DockStyle.Fill; + this.labelHead.Location = new System.Drawing.Point(3, 0); + this.labelHead.Name = "labelHead"; + this.labelHead.Size = new System.Drawing.Size(794, 28); + this.labelHead.TabIndex = 0; + this.labelHead.Text = "header"; + // + // flowLayoutBottom + // + this.flowLayoutBottom.Controls.Add(this.buttonOk); + this.flowLayoutBottom.Controls.Add(this.buttonCancel); + this.flowLayoutBottom.Controls.Add(this.checkBoxIsRoot); + this.flowLayoutBottom.Dock = System.Windows.Forms.DockStyle.Fill; + this.flowLayoutBottom.Location = new System.Drawing.Point(3, 68); + this.flowLayoutBottom.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); + this.flowLayoutBottom.Name = "flowLayoutBottom"; + this.flowLayoutBottom.Size = new System.Drawing.Size(797, 66); + this.flowLayoutBottom.TabIndex = 0; + // + // buttonOk + // + this.buttonOk.AutoSize = true; + this.buttonOk.Image = global::UI_WinForms.Resources.Icons.icons8_ok_512; + this.buttonOk.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.buttonOk.Location = new System.Drawing.Point(3, 3); + this.buttonOk.Name = "buttonOk"; + this.buttonOk.Size = new System.Drawing.Size(114, 60); + this.buttonOk.TabIndex = 1; + this.buttonOk.Text = "Ok"; + this.buttonOk.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; + this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click); + // + // buttonCancel + // + this.buttonCancel.AutoSize = true; + this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.buttonCancel.Image = global::UI_WinForms.Resources.Icons.icons8_cancel_512; + this.buttonCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.buttonCancel.Location = new System.Drawing.Point(123, 3); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(124, 60); + this.buttonCancel.TabIndex = 2; + this.buttonCancel.Text = "Cancel"; + this.buttonCancel.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // textBoxInput + // + this.textBoxInput.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBoxInput.Location = new System.Drawing.Point(6, 31); + this.textBoxInput.Margin = new System.Windows.Forms.Padding(6, 3, 3, 3); + this.textBoxInput.Name = "textBoxInput"; + this.textBoxInput.Size = new System.Drawing.Size(791, 34); + this.textBoxInput.TabIndex = 1; + this.textBoxInput.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBoxInput_KeyUp); + // + // checkBoxIsRoot + // + this.checkBoxIsRoot.AutoSize = true; + this.checkBoxIsRoot.Dock = System.Windows.Forms.DockStyle.Left; + this.checkBoxIsRoot.Location = new System.Drawing.Point(253, 3); + this.checkBoxIsRoot.Name = "checkBoxIsRoot"; + this.checkBoxIsRoot.Size = new System.Drawing.Size(458, 60); + this.checkBoxIsRoot.TabIndex = 3; + this.checkBoxIsRoot.Text = "Add a root node (i.e. ignoring the selected node)"; + this.checkBoxIsRoot.UseVisualStyleBackColor = true; + // + // InputDialog + // + this.AutoScaleDimensions = new System.Drawing.SizeF(120F, 120F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.AutoSize = true; + this.CancelButton = this.buttonCancel; + this.ClientSize = new System.Drawing.Size(800, 139); + this.Controls.Add(this.tableLayout); + this.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "InputDialog"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "InputDialog"; + this.tableLayout.ResumeLayout(false); + this.tableLayout.PerformLayout(); + this.flowLayoutBottom.ResumeLayout(false); + this.flowLayoutBottom.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TableLayoutPanel tableLayout; + private Label labelHead; + private FlowLayoutPanel flowLayoutBottom; + private TextBox textBoxInput; + private Button buttonOk; + private Button buttonCancel; + private CheckBox checkBoxIsRoot; + } +} \ No newline at end of file diff --git a/I18N Commander/UI WinForms/Dialogs/InputDialog.cs b/I18N Commander/UI WinForms/Dialogs/InputDialog.cs new file mode 100644 index 0000000..bce00a3 --- /dev/null +++ b/I18N Commander/UI WinForms/Dialogs/InputDialog.cs @@ -0,0 +1,39 @@ +namespace UI_WinForms.Dialogs; + +public partial class InputDialog : Form +{ + private InputDialog() + { + this.InitializeComponent(); + } + + public static InputResult Show(string message, string title, string placeholder = "", string preloadedText = "", string okButtonText = "Ok", string cancelButtonText = "Cancel") + { + using var inputDialog = new InputDialog(); + inputDialog.labelHead.Text = message; + inputDialog.Text = title; + inputDialog.textBoxInput.PlaceholderText = placeholder; + inputDialog.textBoxInput.Text = preloadedText; + inputDialog.buttonOk.Text = okButtonText; + inputDialog.buttonCancel.Text = cancelButtonText; + + return new InputResult(inputDialog.ShowDialog(), inputDialog.textBoxInput.Text, inputDialog.checkBoxIsRoot.Checked); + } + + private void textBoxInput_KeyUp(object sender, KeyEventArgs e) + { + if (e.KeyCode is Keys.Enter or Keys.Return) + this.buttonOk.PerformClick(); + } + + private void buttonOk_Click(object sender, EventArgs e) + { + if (!string.IsNullOrWhiteSpace(this.textBoxInput.Text)) + { + this.DialogResult = DialogResult.OK; + this.Close(); + } + } + + public readonly record struct InputResult(DialogResult DialogResult, string Text, bool IsRoot); +} \ No newline at end of file diff --git a/I18N Commander/UI WinForms/Dialogs/InputDialog.resx b/I18N Commander/UI WinForms/Dialogs/InputDialog.resx new file mode 100644 index 0000000..b5ae26c --- /dev/null +++ b/I18N Commander/UI WinForms/Dialogs/InputDialog.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file