diff --git a/CHANGELOG.md b/CHANGELOG.md
index 675da3f6a9..e3cc48cc52 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file.
- [Core] Users are less able to run two copies of CKAN at the same time. (#1265 by: mgsdk, #1357 by pjf, #1828 by politas; reviewed: ayan4m1)
- [NetKAN] Add Curse as a $kref source (#1608 by: airminer, Olympic1; reviewed: dbent, pjf, techman83, ayan4m1)
- [All] Relationship changes now prompt reinstalling (#1730 by: dbent, #1885 by: @ayan4m1; reviewed: plague006, pjf)
+- [GUI] Add "X" icon to filter text boxes that clears the control (#1883 by ayan4m1; reviewed: politas)
## v1.18.1
diff --git a/GUI/CKAN-GUI.csproj b/GUI/CKAN-GUI.csproj
index 51010b1ef8..e31bbb2fc1 100644
--- a/GUI/CKAN-GUI.csproj
+++ b/GUI/CKAN-GUI.csproj
@@ -77,6 +77,12 @@
ChooseKSPInstance.cs
+
+ Component
+
+
+ HintTextBox.cs
+
Code
@@ -181,6 +187,9 @@
ErrorDialog.cs
+
+ HintTextBox.cs
+
KSPCommandLineOptionsDialog.cs
@@ -290,5 +299,6 @@
+
\ No newline at end of file
diff --git a/GUI/HintTextBox.Designer.cs b/GUI/HintTextBox.Designer.cs
new file mode 100644
index 0000000000..4f1832775a
--- /dev/null
+++ b/GUI/HintTextBox.Designer.cs
@@ -0,0 +1,46 @@
+using System.Drawing;
+using System.Windows.Forms;
+
+namespace CKAN
+{
+ partial class HintTextBox
+ {
+ ///
+ /// 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 Component Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.SuspendLayout();
+ //
+ // HintTextBox
+ //
+ this.SizeChanged += new System.EventHandler(this.HintTextBox_SizeChanged);
+ this.TextChanged += new System.EventHandler(this.HintTextBox_TextChanged);
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+ }
+}
diff --git a/GUI/HintTextBox.cs b/GUI/HintTextBox.cs
new file mode 100644
index 0000000000..6f7842f0a5
--- /dev/null
+++ b/GUI/HintTextBox.cs
@@ -0,0 +1,106 @@
+using System;
+using System.Drawing;
+using System.Windows.Forms;
+
+namespace CKAN
+{
+ ///
+ /// A textbox which shows a "clear text" icon on the right side
+ /// whenever data is present.
+ ///
+ public partial class HintTextBox : TextBox
+ {
+ private readonly PictureBox _clearIcon;
+
+ ///
+ /// Creates a HintTextBox object.
+ ///
+ public HintTextBox()
+ {
+ InitializeComponent();
+
+ // set up clear icon state and handlers
+ _clearIcon = new PictureBox()
+ {
+ BackColor = Color.Transparent,
+ Visible = false,
+ Cursor = Cursors.Hand,
+ Image = global::CKAN.Properties.Resources.textClear,
+ SizeMode = PictureBoxSizeMode.CenterImage
+ };
+
+ // post-instantiation setup
+ _clearIcon.Size = _clearIcon.Image.Size;
+ _clearIcon.Click += HintClearIcon_Click;
+
+ // add icon and show form
+ Controls.Add(_clearIcon);
+ _clearIcon.Parent = this;
+ _clearIcon.BringToFront();
+ }
+
+ ///
+ /// When the icon is clicked, reset the textbox value.
+ ///
+ /// The control sending the event
+ /// The event arguments
+ private void HintClearIcon_Click(object sender, EventArgs e)
+ {
+ Text = string.Empty;
+ }
+
+ ///
+ /// Show the clear icon when the textbox has data
+ ///
+ /// The control sending the event
+ /// The event arguments
+ private void HintTextBox_TextChanged(object sender, EventArgs e)
+ {
+ // sanity checks
+ if (!Visible || ReadOnly)
+ {
+ return;
+ }
+
+ _clearIcon.Visible = (TextLength > 0);
+ }
+
+ ///
+ /// Adjust the position of the clear icon regardless of control size.
+ ///
+ /// The control sending the event
+ /// The event arguments
+ private void HintTextBox_SizeChanged(object sender, EventArgs e)
+ {
+ if (_clearIcon.Image == null)
+ {
+ return;
+ }
+
+ _clearIcon.Location = new Point(
+ // align with right edge of textbox minus 5px
+ Width - _clearIcon.Width - 5,
+ // need to divide these as decimals and drop back to int at the end
+ (int)Math.Ceiling(Height / 2d - (_clearIcon.Height / 2d))
+ );
+ }
+
+ ///
+ /// Intercept the low-level key press messages to catch Esc,
+ /// which causes the textbox to clear
+ ///
+ /// Win32 Message object
+ /// Which keys are being pressed
+ ///
+ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
+ {
+ if (keyData == Keys.Escape)
+ {
+ Text = "";
+ return true;
+ }
+
+ return base.ProcessCmdKey(ref msg, keyData);
+ }
+ }
+}
diff --git a/GUI/HintTextBox.resx b/GUI/HintTextBox.resx
new file mode 100644
index 0000000000..e5858cc294
--- /dev/null
+++ b/GUI/HintTextBox.resx
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
+ False
+
+
\ No newline at end of file
diff --git a/GUI/Main.Designer.cs b/GUI/Main.Designer.cs
index ab9e73a7ed..a777f01f39 100644
--- a/GUI/Main.Designer.cs
+++ b/GUI/Main.Designer.cs
@@ -107,13 +107,13 @@ private void InitializeComponent()
this.StatusLabel = new System.Windows.Forms.Label();
this.MainTabControl = new CKAN.MainTabControl();
this.ManageModsTabPage = new System.Windows.Forms.TabPage();
- this.FilterByAuthorTextBox = new System.Windows.Forms.TextBox();
+ this.FilterByAuthorTextBox = new HintTextBox();
this.FilterByAuthorLabel = new System.Windows.Forms.Label();
this.KSPVersionLabel = new System.Windows.Forms.Label();
this.FilterByNameLabel = new System.Windows.Forms.Label();
- this.FilterByNameTextBox = new System.Windows.Forms.TextBox();
+ this.FilterByNameTextBox = new HintTextBox();
this.FilterByDescriptionLabel = new System.Windows.Forms.Label();
- this.FilterByDescriptionTextBox = new System.Windows.Forms.TextBox();
+ this.FilterByDescriptionTextBox = new HintTextBox();
this.ChangesetTabPage = new System.Windows.Forms.TabPage();
this.CancelChangesButton = new System.Windows.Forms.Button();
this.ConfirmChangesButton = new System.Windows.Forms.Button();
@@ -1548,9 +1548,9 @@ private void InitializeComponent()
private TabPage ManageModsTabPage;
private Label KSPVersionLabel;
private Label FilterByNameLabel;
- private TextBox FilterByNameTextBox;
+ private HintTextBox FilterByNameTextBox;
private Label FilterByDescriptionLabel;
- private TextBox FilterByDescriptionTextBox;
+ private HintTextBox FilterByDescriptionTextBox;
private TabPage WaitTabPage;
private Button CancelCurrentActionButton;
private TextBox LogTextBox;
diff --git a/GUI/Properties/Resources.Designer.cs b/GUI/Properties/Resources.Designer.cs
index 422ccc6350..79c9c70f64 100644
--- a/GUI/Properties/Resources.Designer.cs
+++ b/GUI/Properties/Resources.Designer.cs
@@ -148,6 +148,16 @@ internal static System.Drawing.Bitmap settings {
}
}
+ ///
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap textClear {
+ get {
+ object obj = ResourceManager.GetObject("textClear", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
///
/// Looks up a localized resource of type System.Drawing.Bitmap.
///
diff --git a/GUI/Properties/Resources.resx b/GUI/Properties/Resources.resx
index 6416c54ebf..d7ccda9e2b 100644
--- a/GUI/Properties/Resources.resx
+++ b/GUI/Properties/Resources.resx
@@ -1,4 +1,4 @@
-
+