mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 06:29:44 +08:00
Refactoring DelayInvoke
In MainWindow.xaml.cs, the reference of originQuery, lastQuery and tbQuery.Text are same, so remove originQuery is fine.
This commit is contained in:
parent
2dfcee6b25
commit
26a6264039
@ -12,20 +12,13 @@ namespace Wox
|
|||||||
new Dictionary<string, DispatcherTimer>();
|
new Dictionary<string, DispatcherTimer>();
|
||||||
private static readonly object syncRoot = new object();
|
private static readonly object syncRoot = new object();
|
||||||
|
|
||||||
public static string DelayInvoke(this Dispatcher dispatcher, string namedInvocation,
|
public static void DelayInvoke(this Dispatcher dispatcher, string namedInvocation,
|
||||||
Action<string> action, TimeSpan delay,
|
Action action, TimeSpan delay,
|
||||||
DispatcherPriority priority = DispatcherPriority.Normal)
|
|
||||||
{
|
|
||||||
return DelayInvoke(dispatcher, namedInvocation, action, delay, string.Empty, priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string DelayInvoke(this Dispatcher dispatcher, string namedInvocation,
|
|
||||||
Action<string> action, TimeSpan delay, string arg,
|
|
||||||
DispatcherPriority priority = DispatcherPriority.Normal)
|
DispatcherPriority priority = DispatcherPriority.Normal)
|
||||||
{
|
{
|
||||||
lock (syncRoot)
|
lock (syncRoot)
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(namedInvocation))
|
if (string.IsNullOrEmpty(namedInvocation))
|
||||||
{
|
{
|
||||||
namedInvocation = Guid.NewGuid().ToString();
|
namedInvocation = Guid.NewGuid().ToString();
|
||||||
}
|
}
|
||||||
@ -36,11 +29,10 @@ namespace Wox
|
|||||||
var timer = new DispatcherTimer(delay, priority, (s, e) =>
|
var timer = new DispatcherTimer(delay, priority, (s, e) =>
|
||||||
{
|
{
|
||||||
RemoveTimer(namedInvocation);
|
RemoveTimer(namedInvocation);
|
||||||
action(arg);
|
action();
|
||||||
}, dispatcher);
|
}, dispatcher);
|
||||||
timer.Start();
|
timer.Start();
|
||||||
timers.Add(namedInvocation, timer);
|
timers.Add(namedInvocation, timer);
|
||||||
return namedInvocation;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ namespace Wox
|
|||||||
}
|
}
|
||||||
|
|
||||||
Dispatcher.DelayInvoke("HotkeyAvailabilityTest",
|
Dispatcher.DelayInvoke("HotkeyAvailabilityTest",
|
||||||
o =>
|
() =>
|
||||||
{
|
{
|
||||||
SetHotkey(hotkeyModel);
|
SetHotkey(hotkeyModel);
|
||||||
},
|
},
|
||||||
|
@ -457,27 +457,27 @@ namespace Wox
|
|||||||
int searchDelay = GetSearchDelay(lastQuery);
|
int searchDelay = GetSearchDelay(lastQuery);
|
||||||
|
|
||||||
Dispatcher.DelayInvoke("UpdateSearch",
|
Dispatcher.DelayInvoke("UpdateSearch",
|
||||||
o =>
|
() =>
|
||||||
{
|
{
|
||||||
Dispatcher.DelayInvoke("ClearResults", i =>
|
Dispatcher.DelayInvoke("ClearResults", () =>
|
||||||
{
|
{
|
||||||
// first try to use clear method inside pnlResult, which is more closer to the add new results
|
// first try to use clear method inside pnlResult, which is more closer to the add new results
|
||||||
// and this will not bring splash issues.After waiting 100ms, if there still no results added, we
|
// and this will not bring splash issues.After waiting 100ms, if there still no results added, we
|
||||||
// must clear the result. otherwise, it will be confused why the query changed, but the results
|
// must clear the result. otherwise, it will be confused why the query changed, but the results
|
||||||
// didn't.
|
// didn't.
|
||||||
if (pnlResult.Dirty) pnlResult.Clear();
|
if (pnlResult.Dirty) pnlResult.Clear();
|
||||||
}, TimeSpan.FromMilliseconds(100), null);
|
}, TimeSpan.FromMilliseconds(100));
|
||||||
queryHasReturn = false;
|
queryHasReturn = false;
|
||||||
Query query = new Query(lastQuery);
|
Query query = new Query(lastQuery);
|
||||||
query.IsIntantQuery = searchDelay == 0;
|
query.IsIntantQuery = searchDelay == 0;
|
||||||
Query(query);
|
Query(query);
|
||||||
Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
|
Dispatcher.DelayInvoke("ShowProgressbar", () =>
|
||||||
{
|
{
|
||||||
if (!queryHasReturn && originQuery == tbQuery.Text && !string.IsNullOrEmpty(lastQuery))
|
if (!queryHasReturn && !string.IsNullOrEmpty(lastQuery))
|
||||||
{
|
{
|
||||||
StartProgress();
|
StartProgress();
|
||||||
}
|
}
|
||||||
}, TimeSpan.FromMilliseconds(150), tbQuery.Text);
|
}, TimeSpan.FromMilliseconds(150));
|
||||||
//reset query history index after user start new query
|
//reset query history index after user start new query
|
||||||
ResetQueryHistoryIndex();
|
ResetQueryHistoryIndex();
|
||||||
}, TimeSpan.FromMilliseconds(searchDelay));
|
}, TimeSpan.FromMilliseconds(searchDelay));
|
||||||
|
@ -71,7 +71,7 @@ namespace Wox {
|
|||||||
Show();
|
Show();
|
||||||
|
|
||||||
Dispatcher.DelayInvoke("ShowMsg",
|
Dispatcher.DelayInvoke("ShowMsg",
|
||||||
o => {
|
() => {
|
||||||
if (!closing) {
|
if (!closing) {
|
||||||
closing = true;
|
closing = true;
|
||||||
Dispatcher.Invoke(new Action(fadeOutStoryboard.Begin));
|
Dispatcher.Invoke(new Action(fadeOutStoryboard.Begin));
|
||||||
|
@ -225,7 +225,7 @@ namespace Wox
|
|||||||
if (e.AddedItems.Count > 0 && e.AddedItems[0] != null)
|
if (e.AddedItems.Count > 0 && e.AddedItems[0] != null)
|
||||||
{
|
{
|
||||||
lbResults.ScrollIntoView(e.AddedItems[0]);
|
lbResults.ScrollIntoView(e.AddedItems[0]);
|
||||||
Dispatcher.DelayInvoke("UpdateItemNumber", o =>
|
Dispatcher.DelayInvoke("UpdateItemNumber", () =>
|
||||||
{
|
{
|
||||||
UpdateItemNumber();
|
UpdateItemNumber();
|
||||||
}, TimeSpan.FromMilliseconds(3));
|
}, TimeSpan.FromMilliseconds(3));
|
||||||
|
@ -464,7 +464,7 @@ namespace Wox
|
|||||||
|
|
||||||
private void DelayChangeTheme()
|
private void DelayChangeTheme()
|
||||||
{
|
{
|
||||||
Dispatcher.DelayInvoke("delayChangeTheme", o =>
|
Dispatcher.DelayInvoke("delayChangeTheme", () =>
|
||||||
{
|
{
|
||||||
ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
|
ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
|
||||||
}, TimeSpan.FromMilliseconds(100));
|
}, TimeSpan.FromMilliseconds(100));
|
||||||
|
Loading…
Reference in New Issue
Block a user