Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement speed search package manager #14381

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,40 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Threading;

namespace Dynamo.PackageManager.UI
{

/// <summary>
/// Interaction logic for SearchBoxControl.xaml
/// </summary>
public partial class SearchBoxControl : UserControl
{
private DispatcherTimer delayTimer;

// set delay for event 500ms
private static int delayTime = 500;
/// <summary>
/// Constructor
/// </summary>
public SearchBoxControl()
{
InitializeComponent();
}
private static DispatcherTimer Debounce(DispatcherTimer dispatcher, TimeSpan interval, Action action)
{
dispatcher?.Stop();
dispatcher = null;
dispatcher = new DispatcherTimer(interval, DispatcherPriority.ApplicationIdle, (s, e) =>
{
dispatcher?.Stop();
action.Invoke();
}, Dispatcher.CurrentDispatcher);
dispatcher?.Start();

return dispatcher;
}

/// <summary>
/// Handles Search Box Text Changed Event
Expand All @@ -29,14 +48,15 @@ public SearchBoxControl()
/// <exception cref="NotImplementedException"></exception>
private void SearchTextBox_OnTextChanged(object sender, TextChangedEventArgs e)
{
var textBox = sender as TextBox;
if (textBox == null) return;

(this.DataContext as PackageManagerSearchViewModel).SearchAndUpdateResults(textBox.Text);

textBox.Focus();
Debounce(delayTimer, TimeSpan.FromMilliseconds(delayTime), () =>
{
var textBox = sender as TextBox;
if (textBox == null) return;
(this.DataContext as PackageManagerSearchViewModel)?.SearchAndUpdateResults(textBox.Text);
textBox.Focus();
});
}

private void OnSearchClearButtonClicked(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
this.SearchTextBox.Clear();
Expand Down Expand Up @@ -110,7 +130,7 @@ public object[] ConvertBack(object value, Type[] targetTypes, object parameter,
}

/// <summary>
/// Converts null or empty string to Visibility Collapsed
/// Converts null or empty string to Visibility Collapsed
/// </summary>
public class NonEmptyStringToCollapsedConverter : IValueConverter
{
Expand Down Expand Up @@ -139,7 +159,7 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
}

/// <summary>
/// Converts null or empty string to Visibility Collapsed
/// Converts null or empty string to Visibility Collapsed
/// </summary>
public class EmptyStringToCollapsedConverter : IValueConverter
{
Expand Down
Loading