From 9fc9c8bc6053db73e6d9affe008d46f7ea5e733b Mon Sep 17 00:00:00 2001 From: Souryo Date: Sat, 25 Jun 2016 22:05:10 -0400 Subject: [PATCH] Archives: Added search box to select rom dialog --- GUI.NET/Forms/frmSelectRom.Designer.cs | 66 +++++++++++++++++++++++--- GUI.NET/Forms/frmSelectRom.cs | 55 ++++++++++++++++++++- GUI.NET/Forms/frmSelectRom.resx | 3 ++ 3 files changed, 117 insertions(+), 7 deletions(-) diff --git a/GUI.NET/Forms/frmSelectRom.Designer.cs b/GUI.NET/Forms/frmSelectRom.Designer.cs index d3d2b824..aca6a5a0 100644 --- a/GUI.NET/Forms/frmSelectRom.Designer.cs +++ b/GUI.NET/Forms/frmSelectRom.Designer.cs @@ -27,14 +27,20 @@ /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.lstRoms = new System.Windows.Forms.ListBox(); this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); this.btnOK = new System.Windows.Forms.Button(); this.btnCancel = new System.Windows.Forms.Button(); this.lblRomCount = new System.Windows.Forms.Label(); + this.lblSearch = new System.Windows.Forms.Label(); + this.txtSearch = new System.Windows.Forms.TextBox(); + this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); + this.tmrSearch = new System.Windows.Forms.Timer(this.components); this.tableLayoutPanel1.SuspendLayout(); this.flowLayoutPanel1.SuspendLayout(); + this.tableLayoutPanel2.SuspendLayout(); this.SuspendLayout(); // // tableLayoutPanel1 @@ -42,13 +48,15 @@ this.tableLayoutPanel1.ColumnCount = 2; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel1.Controls.Add(this.lstRoms, 0, 0); - this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel1, 1, 1); - this.tableLayoutPanel1.Controls.Add(this.lblRomCount, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.lstRoms, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel1, 1, 2); + this.tableLayoutPanel1.Controls.Add(this.lblRomCount, 0, 2); + this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel2, 0, 0); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; - this.tableLayoutPanel1.RowCount = 2; + this.tableLayoutPanel1.RowCount = 3; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); @@ -62,9 +70,9 @@ this.lstRoms.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lstRoms.FormattingEnabled = true; this.lstRoms.ItemHeight = 18; - this.lstRoms.Location = new System.Drawing.Point(3, 3); + this.lstRoms.Location = new System.Drawing.Point(3, 28); this.lstRoms.Name = "lstRoms"; - this.lstRoms.Size = new System.Drawing.Size(457, 207); + this.lstRoms.Size = new System.Drawing.Size(457, 182); this.lstRoms.TabIndex = 1; this.lstRoms.SelectedIndexChanged += new System.EventHandler(this.lstRoms_SelectedIndexChanged); this.lstRoms.DoubleClick += new System.EventHandler(this.lstRoms_DoubleClick); @@ -113,6 +121,46 @@ this.lblRomCount.TabIndex = 2; this.lblRomCount.Text = "### roms found"; // + // lblSearch + // + this.lblSearch.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.lblSearch.AutoSize = true; + this.lblSearch.Location = new System.Drawing.Point(3, 6); + this.lblSearch.Name = "lblSearch"; + this.lblSearch.Size = new System.Drawing.Size(44, 13); + this.lblSearch.TabIndex = 3; + this.lblSearch.Text = "Search:"; + // + // txtSearch + // + this.txtSearch.Dock = System.Windows.Forms.DockStyle.Fill; + this.txtSearch.Location = new System.Drawing.Point(53, 3); + this.txtSearch.Name = "txtSearch"; + this.txtSearch.Size = new System.Drawing.Size(407, 20); + this.txtSearch.TabIndex = 1; + // + // tableLayoutPanel2 + // + this.tableLayoutPanel2.ColumnCount = 2; + this.tableLayoutPanel1.SetColumnSpan(this.tableLayoutPanel2, 2); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel2.Controls.Add(this.txtSearch, 1, 0); + this.tableLayoutPanel2.Controls.Add(this.lblSearch, 0, 0); + this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel2.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel2.Margin = new System.Windows.Forms.Padding(0, 0, 0, 0); + this.tableLayoutPanel2.Name = "tableLayoutPanel2"; + this.tableLayoutPanel2.RowCount = 1; + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel2.Size = new System.Drawing.Size(463, 25); + this.tableLayoutPanel2.TabIndex = 5; + // + // tmrSearch + // + this.tmrSearch.Enabled = true; + this.tmrSearch.Tick += new System.EventHandler(this.tmrSearch_Tick); + // // frmSelectRom // this.AcceptButton = this.btnOK; @@ -127,6 +175,8 @@ this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); this.flowLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel2.ResumeLayout(false); + this.tableLayoutPanel2.PerformLayout(); this.ResumeLayout(false); } @@ -139,5 +189,9 @@ private System.Windows.Forms.Button btnOK; private System.Windows.Forms.Button btnCancel; private System.Windows.Forms.Label lblRomCount; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; + private System.Windows.Forms.TextBox txtSearch; + private System.Windows.Forms.Label lblSearch; + private System.Windows.Forms.Timer tmrSearch; } } \ No newline at end of file diff --git a/GUI.NET/Forms/frmSelectRom.cs b/GUI.NET/Forms/frmSelectRom.cs index dee604df..2c8430da 100644 --- a/GUI.NET/Forms/frmSelectRom.cs +++ b/GUI.NET/Forms/frmSelectRom.cs @@ -14,6 +14,7 @@ namespace Mesen.GUI.Forms { private List _romFiles; private int SelectedIndex { get; set; } + private string _previousSearch = ""; public frmSelectRom(List romFiles) { @@ -22,9 +23,53 @@ namespace Mesen.GUI.Forms _romFiles = romFiles; lblRomCount.Text = ResourceHelper.GetMessage("RomsFound", _romFiles.Count.ToString()); - lstRoms.Items.AddRange(romFiles.ToArray()); lstRoms.Sorted = true; this.DialogResult = DialogResult.Cancel; + + UpdateList(); + } + + protected override bool ProcessCmdKey(ref Message msg, Keys keyData) + { + if(txtSearch.Focused) { + if(keyData == Keys.Down || keyData == Keys.PageDown || keyData == Keys.Up || keyData == Keys.PageUp) { + lstRoms.Focus(); + if(lstRoms.Items.Count > 0) { + lstRoms.SelectedIndex = 0; + } + return true; + } + } else if(lstRoms.Focused && lstRoms.SelectedIndex <= 0) { + if(keyData == Keys.Up || keyData == Keys.PageUp) { + txtSearch.Focus(); + txtSearch.SelectAll(); + return true; + } + } + return base.ProcessCmdKey(ref msg, keyData); + } + + private void UpdateList() + { + lstRoms.Items.Clear(); + if(string.IsNullOrWhiteSpace(_previousSearch)) { + lstRoms.Items.AddRange(_romFiles.ToArray()); + } else { + List romsToAdd = new List(); + foreach(string rom in _romFiles) { + if(rom.IndexOf(_previousSearch, StringComparison.InvariantCultureIgnoreCase) >= 0) { + romsToAdd.Add(rom); + } + } + lstRoms.Items.AddRange(romsToAdd.ToArray()); + } + } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + txtSearch.Focus(); } public static bool SelectRom(string filename, out int archiveFileIndex) @@ -64,5 +109,13 @@ namespace Mesen.GUI.Forms { SetSelectedIndex(); } + + private void tmrSearch_Tick(object sender, EventArgs e) + { + if(txtSearch.Text.Trim() != _previousSearch) { + _previousSearch = txtSearch.Text.Trim(); + UpdateList(); + } + } } } diff --git a/GUI.NET/Forms/frmSelectRom.resx b/GUI.NET/Forms/frmSelectRom.resx index 8766f298..1dde2e8b 100644 --- a/GUI.NET/Forms/frmSelectRom.resx +++ b/GUI.NET/Forms/frmSelectRom.resx @@ -120,4 +120,7 @@ 17, 17 + + 107, 17 + \ No newline at end of file