mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-11 05:52:19 +02:00
@@ -42,12 +42,22 @@ namespace Wox.Plugin
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string PluginDirectory { get; internal set; }
|
public string PluginDirectory { get; internal set; }
|
||||||
|
|
||||||
public new bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
{
|
{
|
||||||
if (obj == null || !(obj is Result)) return false;
|
Result r = obj as Result;
|
||||||
|
if (r != null)
|
||||||
|
{
|
||||||
|
return string.Equals(r.Title, Title) && string.Equals(r.SubTitle, SubTitle);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Result r = (Result)obj;
|
public override int GetHashCode()
|
||||||
return r.Title == Title && r.SubTitle == SubTitle;
|
{
|
||||||
|
return (Title?.GetHashCode() ?? 0) ^ (SubTitle?.GetHashCode() ?? 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
|||||||
@@ -441,36 +441,33 @@ namespace Wox
|
|||||||
|
|
||||||
private void TbQuery_OnTextChanged(object sender, TextChangedEventArgs e)
|
private void TbQuery_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (ignoreTextChange) { ignoreTextChange = false; return; }
|
if (ignoreTextChange) { ignoreTextChange = false; return; }
|
||||||
|
|
||||||
toolTip.IsOpen = false;
|
if (!string.IsNullOrEmpty(tbQuery.Text.Trim()))
|
||||||
pnlResult.Dirty = true;
|
|
||||||
if (IsInContextMenuMode)
|
|
||||||
{
|
{
|
||||||
QueryContextMenu();
|
toolTip.IsOpen = false;
|
||||||
return;
|
if (IsInContextMenuMode)
|
||||||
}
|
|
||||||
|
|
||||||
queryHasReturn = false;
|
|
||||||
|
|
||||||
Dispatcher.DelayInvoke("ClearResults", () =>
|
|
||||||
{
|
|
||||||
// Delay the invocation of clear method of pnlResult, minimize the time-span between clear results and add new results.
|
|
||||||
// So this will reduce 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
|
|
||||||
// didn't.
|
|
||||||
if (pnlResult.Dirty) pnlResult.Clear();
|
|
||||||
}, TimeSpan.FromMilliseconds(100));
|
|
||||||
Query(tbQuery.Text);
|
|
||||||
Dispatcher.DelayInvoke("ShowProgressbar", () =>
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(tbQuery.Text.Trim()) && tbQuery.Text != lastQuery && !queryHasReturn)
|
|
||||||
{
|
{
|
||||||
StartProgress();
|
QueryContextMenu();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}, TimeSpan.FromMilliseconds(150));
|
|
||||||
//reset query history index after user start new query
|
Query(tbQuery.Text);
|
||||||
ResetQueryHistoryIndex();
|
Dispatcher.DelayInvoke("ShowProgressbar", () =>
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(tbQuery.Text.Trim()) && tbQuery.Text != lastQuery && !queryHasReturn)
|
||||||
|
{
|
||||||
|
StartProgress();
|
||||||
|
}
|
||||||
|
}, TimeSpan.FromMilliseconds(150));
|
||||||
|
//reset query history index after user start new query
|
||||||
|
ResetQueryHistoryIndex();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pnlResult.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResetQueryHistoryIndex()
|
private void ResetQueryHistoryIndex()
|
||||||
@@ -720,7 +717,6 @@ namespace Wox
|
|||||||
if (history != null)
|
if (history != null)
|
||||||
{
|
{
|
||||||
ChangeQueryText(history.Query, true);
|
ChangeQueryText(history.Query, true);
|
||||||
pnlResult.Dirty = true;
|
|
||||||
var executeQueryHistoryTitle = GetTranslation("executeQuery");
|
var executeQueryHistoryTitle = GetTranslation("executeQuery");
|
||||||
var lastExecuteTime = GetTranslation("lastExecuteTime");
|
var lastExecuteTime = GetTranslation("lastExecuteTime");
|
||||||
UpdateResultViewInternal(new List<Result>()
|
UpdateResultViewInternal(new List<Result>()
|
||||||
|
|||||||
@@ -1,20 +1,27 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.Remoting.Contexts;
|
||||||
using Wox.Core.UserSettings;
|
using Wox.Core.UserSettings;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using Wox.Storage;
|
using Wox.Storage;
|
||||||
|
|
||||||
namespace Wox
|
namespace Wox
|
||||||
{
|
{
|
||||||
|
[Synchronization]
|
||||||
public partial class ResultPanel : UserControl
|
public partial class ResultPanel : UserControl
|
||||||
{
|
{
|
||||||
public event Action<Result> LeftMouseClickEvent;
|
public event Action<Result> LeftMouseClickEvent;
|
||||||
public event Action<Result> RightMouseClickEvent;
|
public event Action<Result> RightMouseClickEvent;
|
||||||
public event Action<Result, IDataObject, DragEventArgs> ItemDropEvent;
|
public event Action<Result, IDataObject, DragEventArgs> ItemDropEvent;
|
||||||
|
private readonly ObservableCollection<Result> _results; //todo, for better performance, override the default linear search
|
||||||
|
private readonly object _resultsUpdateLock = new object();
|
||||||
|
|
||||||
protected virtual void OnRightMouseClick(Result result)
|
protected virtual void OnRightMouseClick(Result result)
|
||||||
{
|
{
|
||||||
@@ -28,36 +35,69 @@ namespace Wox
|
|||||||
if (handler != null) handler(result);
|
if (handler != null) handler(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Dirty { get; set; }
|
|
||||||
|
|
||||||
public int MaxResultsToShow { get { return UserSettingStorage.Instance.MaxResultsToShow * 50; } }
|
public int MaxResultsToShow { get { return UserSettingStorage.Instance.MaxResultsToShow * 50; } }
|
||||||
|
|
||||||
public void AddResults(List<Result> results)
|
public void AddResults(List<Result> newResults)
|
||||||
{
|
{
|
||||||
if (Dirty)
|
if (newResults != null && newResults.Count > 0)
|
||||||
{
|
{
|
||||||
Dirty = false;
|
lock (_resultsUpdateLock)
|
||||||
lbResults.Items.Clear();
|
|
||||||
}
|
|
||||||
foreach (var result in results)
|
|
||||||
{
|
|
||||||
int position = 0;
|
|
||||||
if (IsTopMostResult(result))
|
|
||||||
{
|
{
|
||||||
result.Score = int.MaxValue;
|
var pluginId = newResults[0].PluginID;
|
||||||
}
|
var actionKeyword = newResults[0].OriginQuery.ActionKeyword;
|
||||||
else
|
List<Result> oldResults;
|
||||||
{
|
if (string.IsNullOrEmpty(actionKeyword))
|
||||||
if (result.Score >= int.MaxValue)
|
|
||||||
{
|
{
|
||||||
result.Score = int.MaxValue - 1;
|
oldResults = _results.Where(r => r.PluginID == pluginId).ToList();
|
||||||
}
|
}
|
||||||
position = GetInsertLocation(result.Score);
|
else
|
||||||
|
{
|
||||||
|
oldResults = _results.ToList();
|
||||||
|
}
|
||||||
|
// intersection of A (old results) and B (new newResults)
|
||||||
|
var intersection = oldResults.Intersect(newResults).ToList();
|
||||||
|
|
||||||
|
// remove result of relative complement of B in A
|
||||||
|
foreach (var result in oldResults.Except(intersection))
|
||||||
|
{
|
||||||
|
_results.Remove(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// update scores
|
||||||
|
foreach (var result in newResults)
|
||||||
|
{
|
||||||
|
if (IsTopMostResult(result))
|
||||||
|
{
|
||||||
|
result.Score = int.MaxValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update index for result in intersection of A and B
|
||||||
|
foreach (var result in intersection)
|
||||||
|
{
|
||||||
|
int oldIndex = _results.IndexOf(result);
|
||||||
|
int oldScore = _results[oldIndex].Score;
|
||||||
|
if (result.Score != oldScore)
|
||||||
|
{
|
||||||
|
int newIndex = InsertIndexOf(result.Score);
|
||||||
|
if (newIndex != oldIndex)
|
||||||
|
{
|
||||||
|
_results.Move(oldIndex, newIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// insert result in relative complement of A in B
|
||||||
|
foreach (var result in newResults.Except(intersection))
|
||||||
|
{
|
||||||
|
int newIndex = InsertIndexOf(result.Score);
|
||||||
|
_results.Insert(newIndex, result);
|
||||||
|
}
|
||||||
|
lbResults.Margin = lbResults.Items.Count > 0 ? new Thickness { Top = 8 } : new Thickness { Top = 0 };
|
||||||
|
SelectFirst();
|
||||||
}
|
}
|
||||||
lbResults.Items.Insert(position, result);
|
|
||||||
}
|
}
|
||||||
lbResults.Margin = lbResults.Items.Count > 0 ? new Thickness { Top = 8 } : new Thickness { Top = 0 };
|
|
||||||
SelectFirst();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsTopMostResult(Result result)
|
private bool IsTopMostResult(Result result)
|
||||||
@@ -65,33 +105,18 @@ namespace Wox
|
|||||||
return TopMostRecordStorage.Instance.IsTopMost(result);
|
return TopMostRecordStorage.Instance.IsTopMost(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetInsertLocation(int currentScore)
|
private int InsertIndexOf(int newScore)
|
||||||
{
|
{
|
||||||
int location = lbResults.Items.Count;
|
int index = 0;
|
||||||
if (lbResults.Items.Count == 0) return 0;
|
for (; index < lbResults.Items.Count; index++)
|
||||||
if (currentScore > ((Result)lbResults.Items[0]).Score) return 0;
|
|
||||||
|
|
||||||
for (int index = 1; index < lbResults.Items.Count; index++)
|
|
||||||
{
|
{
|
||||||
Result next = lbResults.Items[index] as Result;
|
Result result = lbResults.Items[index] as Result;
|
||||||
Result prev = lbResults.Items[index - 1] as Result;
|
if (newScore > result?.Score)
|
||||||
if (next != null && prev != null)
|
|
||||||
{
|
{
|
||||||
if ((currentScore >= next.Score && currentScore <= prev.Score))
|
break;
|
||||||
{
|
|
||||||
if (currentScore == next.Score)
|
|
||||||
{
|
|
||||||
location = index + 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
location = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return index;
|
||||||
return location;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SelectNext()
|
public void SelectNext()
|
||||||
@@ -211,12 +236,17 @@ namespace Wox
|
|||||||
public ResultPanel()
|
public ResultPanel()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_results = new ObservableCollection<Result>();
|
||||||
|
lbResults.ItemsSource = _results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
lbResults.Items.Clear();
|
lock (_resultsUpdateLock)
|
||||||
lbResults.Margin = new Thickness { Top = 0 };
|
{
|
||||||
|
_results.Clear();
|
||||||
|
lbResults.Margin = new Thickness { Top = 0 };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void lbResults_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void lbResults_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
|
|||||||
Reference in New Issue
Block a user