-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1166 from TestCentric/issue-1161
Add UI elements for textual filtering of tests
- Loading branch information
Showing
8 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/TestCentric/testcentric.gui/Controls/StretchToolStripTextBox.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// *********************************************************************** | ||
// Copyright (c) Charlie Poole and TestCentric contributors. | ||
// Licensed under the MIT License. See LICENSE file in root directory. | ||
// *********************************************************************** | ||
|
||
using System.Drawing; | ||
using System.Windows.Forms; | ||
using System; | ||
|
||
namespace TestCentric.Gui.Controls | ||
{ | ||
/// <summary> | ||
/// This class is required to stretch a ToolStripTextBox control within a ToolStrip to fill the available space and to resize when the control resizes. | ||
/// The implementation is from the Microsoft Windows Forms documentation, but simplified to the current use case. | ||
/// "How to: Stretch a ToolStripTextBox to Fill the Remaining Width of a ToolStrip" | ||
/// https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/stretch-a-toolstriptextbox-to-fill-the-remaining-width-of-a-toolstrip-wf?view=netframeworkdesktop-4.8 | ||
/// </summary> | ||
internal class StretchToolStripTextBox : ToolStripTextBox | ||
{ | ||
public override Size GetPreferredSize(Size constrainingSize) | ||
{ | ||
// Get width of the owning ToolStrip | ||
int textBoxMargin = 2; | ||
Int32 width = Owner.DisplayRectangle.Width - textBoxMargin; | ||
|
||
// If the available width is less than the default width, use the default width | ||
if (width < DefaultSize.Width) width = DefaultSize.Width; | ||
|
||
// Retrieve the preferred size from the base class, but change the width to the calculated width. | ||
Size size = base.GetPreferredSize(constrainingSize); | ||
size.Width = width; | ||
return size; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// *********************************************************************** | ||
// Copyright (c) Charlie Poole and TestCentric contributors. | ||
// Licensed under the MIT License. See LICENSE file in root directory. | ||
// *********************************************************************** | ||
|
||
namespace TestCentric.Gui.Elements | ||
{ | ||
/// <summary> | ||
/// The IChanged interface represents a IViewElement. | ||
/// If the IViewElement changes, it will raise the Changed event. | ||
/// </summary> | ||
public interface IChanged : IViewElement | ||
{ | ||
/// <summary> | ||
/// Event raised when the element is changed by the user | ||
/// </summary> | ||
event CommandHandler Changed; | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/TestCentric/testcentric.gui/Elements/ToolStripTextBoxElement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// *********************************************************************** | ||
// Copyright (c) Charlie Poole and TestCentric contributors. | ||
// Licensed under the MIT License. See LICENSE file in root directory. | ||
// *********************************************************************** | ||
|
||
|
||
using System; | ||
using System.Windows.Forms; | ||
|
||
namespace TestCentric.Gui.Elements | ||
{ | ||
/// <summary> | ||
/// This class implements the IChanged interface for a ToolStripTextBox control. It provides this additional functionality: | ||
/// - show a PlaceHoder text if there's no text input | ||
/// - Invoke the Changed event as soon as no further input is made within a short period of time. | ||
/// </summary> | ||
public class ToolStripTextBoxElement : ToolStripElement, IChanged | ||
{ | ||
private Timer _typingTimer; | ||
|
||
public event CommandHandler Changed; | ||
|
||
public ToolStripTextBoxElement(ToolStripTextBox textBox, string placeHolderText) | ||
: base(textBox) | ||
{ | ||
TextBox = textBox; | ||
PlaceHolderText = placeHolderText; | ||
TextBox.TextChanged += OnTextChanged; | ||
|
||
TextBox.LostFocus += OnTextBoxLostFocus; | ||
TextBox.GotFocus += OnTextBoxGotFocus; | ||
|
||
// Call LostFocus to set initial text and color | ||
OnTextBoxLostFocus(null, EventArgs.Empty); | ||
} | ||
|
||
private string PlaceHolderText { get; set; } | ||
|
||
private ToolStripTextBox TextBox { get; } | ||
|
||
private bool IsPlaceHolderTextShown { get; set; } | ||
|
||
private void OnTextBoxGotFocus(object sender, EventArgs e) | ||
{ | ||
// If the PlaceHolderText is shown, replace it with an empty text | ||
if (IsPlaceHolderTextShown) | ||
{ | ||
TextBox.Text = ""; | ||
TextBox.ForeColor = System.Drawing.Color.Black; | ||
IsPlaceHolderTextShown = false; | ||
} | ||
} | ||
|
||
private void OnTextBoxLostFocus(object sender, EventArgs e) | ||
{ | ||
// If there's no text input, show the PlaceHolderText instead | ||
string searchText = TextBox.Text; | ||
if (string.IsNullOrEmpty(searchText) && !string.IsNullOrEmpty(PlaceHolderText)) | ||
{ | ||
IsPlaceHolderTextShown = true; | ||
TextBox.Text = PlaceHolderText; | ||
TextBox.ForeColor = System.Drawing.Color.LightGray; | ||
} | ||
} | ||
|
||
private void OnTextChanged(object sender, EventArgs e) | ||
{ | ||
if (IsPlaceHolderTextShown) | ||
return; | ||
|
||
if (_typingTimer == null) | ||
{ | ||
_typingTimer = new Timer(); | ||
_typingTimer.Interval = 600; | ||
_typingTimer.Tick += TypingTimerTimeout; | ||
} | ||
|
||
_typingTimer.Stop(); | ||
_typingTimer.Start(); | ||
} | ||
|
||
private void TypingTimerTimeout(object sender, EventArgs e) | ||
{ | ||
var timer = sender as Timer; | ||
if (timer == null) | ||
return; | ||
|
||
// The timer must be stopped! | ||
timer.Stop(); | ||
if (Changed != null) | ||
Changed(); | ||
|
||
TextBox.Focus(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/TestCentric/testcentric.gui/Views/TestTreeView.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters