Skip to content

Commit

Permalink
Add interface IChanged; Use interface IChanged instead of ISelection …
Browse files Browse the repository at this point in the history
…in class TextBoxElement
  • Loading branch information
rowo360 committed Jan 10, 2025
1 parent c84d775 commit ef41947
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 27 deletions.
19 changes: 19 additions & 0 deletions src/TestCentric/testcentric.gui/Elements/IChanged.cs
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;
}
}
29 changes: 6 additions & 23 deletions src/TestCentric/testcentric.gui/Elements/TextBoxElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
namespace TestCentric.Gui.Elements
{
/// <summary>
/// This class implements the ISelection interface for a TextBox control. It provides this additional functionality:
/// This class implements the IChanged interface for a TextBox control. It provides this additional functionality:
/// - show a PlaceHoder text if there's no text input
/// - Invoke the SelectionChanged event as soon as no further input is made within a short period of time.
/// - Invoke the Changed event as soon as no further input is made within a short period of time.
/// </summary>
public class TextBoxElement : ISelection
public class TextBoxElement : IChanged
{
private Timer _typingTimer;

public event CommandHandler SelectionChanged;
public event CommandHandler Changed;

public TextBoxElement(Control textBox, string placeHolderText)
{
Expand All @@ -33,18 +33,6 @@ public TextBoxElement(Control textBox, string placeHolderText)
OnTextBoxLostFocus(null, EventArgs.Empty);
}

public string SelectedItem
{
get => TextBox.Text;
set => TextBox.Text = value;
}

public int SelectedIndex
{
get => 0;
set => throw new NotImplementedException();
}

public bool Enabled
{
get => TextBox.Enabled;
Expand Down Expand Up @@ -74,11 +62,6 @@ public void InvokeIfRequired(MethodInvoker _delegate)
throw new NotImplementedException();
}

public void Refresh()
{
throw new NotImplementedException();
}

private void OnTextBoxGotFocus(object sender, EventArgs e)
{
// If the PlaceHolderText is shown, replace it with an empty text
Expand Down Expand Up @@ -126,8 +109,8 @@ private void TypingTimerTimeout(object sender, EventArgs e)

// The timer must be stopped!
timer.Stop();
if (SelectionChanged != null)
SelectionChanged();
if (Changed != null)
Changed();

TextBox.Focus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private void WireUpEvents()
_model.TestCentricTestFilter.OutcomeFilter = filter;
};

_view.TextFilter.SelectionChanged += () =>
_view.TextFilter.Changed += () =>
{
var text = _view.TextFilter.Text;
_model.TestCentricTestFilter.TextFilter = text;
Expand Down
2 changes: 1 addition & 1 deletion src/TestCentric/testcentric.gui/Views/ITestTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public interface ITestTreeView : IView
// Test Filter related properties / methods
IMultiSelection OutcomeFilter { get; }

ISelection TextFilter { get; }
IChanged TextFilter { get; }

void SetTestFilterVisibility(bool visible);

Expand Down
2 changes: 1 addition & 1 deletion src/TestCentric/testcentric.gui/Views/TestTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public bool CheckBoxes

public IMultiSelection OutcomeFilter { get; private set; }

public ISelection TextFilter { get; private set; }
public IChanged TextFilter { get; private set; }

public TreeNode ContextNode { get; private set; }
public ContextMenuStrip TreeContextMenu => TreeView.ContextMenuStrip;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void TextFilterChanged_ApplyFilter()
_view.TextFilter.Text.Returns("TestA");

// 2. Act
_view.TextFilter.SelectionChanged += Raise.Event<CommandHandler>();
_view.TextFilter.Changed += Raise.Event<CommandHandler>();

// 3. Assert
_model.TestCentricTestFilter.Received().TextFilter = "TestA";
Expand Down

0 comments on commit ef41947

Please sign in to comment.