mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
move properties into models
This commit is contained in:
@@ -41,10 +41,10 @@
|
|||||||
<RowDefinition Height="Auto" x:Name="SubTitleRowDefinition" />
|
<RowDefinition Height="Auto" x:Name="SubTitleRowDefinition" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<TextBlock Style="{DynamicResource ItemTitleStyle}" DockPanel.Dock="Left"
|
<TextBlock Style="{DynamicResource ItemTitleStyle}" DockPanel.Dock="Left"
|
||||||
VerticalAlignment="Center" ToolTip="{Binding Title}" x:Name="Title"
|
VerticalAlignment="Center" ToolTip="{Binding Result.Title}" x:Name="Title"
|
||||||
Text="{Binding Title}" />
|
Text="{Binding Result.Title}" />
|
||||||
<TextBlock Style="{DynamicResource ItemSubTitleStyle}" ToolTip="{Binding SubTitle}"
|
<TextBlock Style="{DynamicResource ItemSubTitleStyle}" ToolTip="{Binding Result.SubTitle}"
|
||||||
Grid.Row="1" x:Name="SubTitle" Text="{Binding SubTitle}" />
|
Grid.Row="1" x:Name="SubTitle" Text="{Binding Result.SubTitle}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Button.Content>
|
</Button.Content>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@@ -168,7 +169,7 @@ namespace Wox.ViewModel
|
|||||||
results.SelectedIndex = int.Parse(index.ToString());
|
results.SelectedIndex = int.Parse(index.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = results.SelectedItem?.RawResult;
|
var result = results.SelectedItem?.Result;
|
||||||
if (result != null) // SelectedItem returns null if selection is empty.
|
if (result != null) // SelectedItem returns null if selection is empty.
|
||||||
{
|
{
|
||||||
bool hideWindow = result.Action != null && result.Action(new ActionContext
|
bool hideWindow = result.Action != null && result.Action(new ActionContext
|
||||||
@@ -193,7 +194,7 @@ namespace Wox.ViewModel
|
|||||||
{
|
{
|
||||||
if (!ContextMenuVisibility.IsVisible())
|
if (!ContextMenuVisibility.IsVisible())
|
||||||
{
|
{
|
||||||
var result = Results.SelectedItem?.RawResult;
|
var result = Results.SelectedItem?.Result;
|
||||||
|
|
||||||
if (result != null) // SelectedItem returns null if selection is empty.
|
if (result != null) // SelectedItem returns null if selection is empty.
|
||||||
{
|
{
|
||||||
@@ -340,12 +341,13 @@ namespace Wox.ViewModel
|
|||||||
{
|
{
|
||||||
|
|
||||||
List<Result> filterResults = new List<Result>();
|
List<Result> filterResults = new List<Result>();
|
||||||
foreach (var contextMenu in ContextMenu.Results)
|
foreach (var result in ContextMenu.Results.Select(r => r.Result))
|
||||||
{
|
{
|
||||||
if (StringMatcher.IsMatch(contextMenu.Title, query)
|
var matched = StringMatcher.IsMatch(result.Title, query) ||
|
||||||
|| StringMatcher.IsMatch(contextMenu.SubTitle, query))
|
StringMatcher.IsMatch(result.SubTitle, query);
|
||||||
|
if (matched)
|
||||||
{
|
{
|
||||||
filterResults.Add(contextMenu.RawResult);
|
filterResults.Add(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ContextMenu.Clear();
|
ContextMenu.Clear();
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows;
|
|
||||||
using Wox.Infrastructure.Image;
|
using Wox.Infrastructure.Image;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
|
||||||
@@ -9,86 +7,39 @@ namespace Wox.ViewModel
|
|||||||
{
|
{
|
||||||
public class ResultViewModel : BaseModel
|
public class ResultViewModel : BaseModel
|
||||||
{
|
{
|
||||||
#region Private Fields
|
|
||||||
|
|
||||||
private bool _isSelected;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
|
|
||||||
public ResultViewModel(Result result)
|
public ResultViewModel(Result result)
|
||||||
{
|
{
|
||||||
if (result != null)
|
if (result != null)
|
||||||
{
|
{
|
||||||
RawResult = result;
|
Result = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ImageSource Image => ImageLoader.Load(Result.IcoPath);
|
||||||
|
|
||||||
#endregion
|
public Result Result { get; }
|
||||||
|
|
||||||
#region ViewModel Properties
|
|
||||||
|
|
||||||
public string Title => RawResult.Title;
|
|
||||||
|
|
||||||
public string SubTitle => RawResult.SubTitle;
|
|
||||||
|
|
||||||
public string PluginID => RawResult.PluginID;
|
|
||||||
|
|
||||||
public ImageSource Image => ImageLoader.Load(RawResult.IcoPath);
|
|
||||||
|
|
||||||
public int Score
|
|
||||||
{
|
|
||||||
get { return RawResult.Score; }
|
|
||||||
set { RawResult.Score = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public Query OriginQuery
|
|
||||||
{
|
|
||||||
get { return RawResult.OriginQuery; }
|
|
||||||
set { RawResult.OriginQuery = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public Func<ActionContext, bool> Action
|
|
||||||
{
|
|
||||||
get { return RawResult.Action; }
|
|
||||||
set { RawResult.Action = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Properties
|
|
||||||
|
|
||||||
internal Result RawResult { get; }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
public void Update(ResultViewModel newResult)
|
|
||||||
{
|
|
||||||
RawResult.Score = newResult.RawResult.Score;
|
|
||||||
RawResult.OriginQuery = newResult.RawResult.OriginQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
{
|
{
|
||||||
ResultViewModel r = obj as ResultViewModel;
|
ResultViewModel r = obj as ResultViewModel;
|
||||||
if (r != null)
|
if (r != null)
|
||||||
{
|
{
|
||||||
return RawResult.Equals(r.RawResult);
|
return Result.Equals(r.Result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
return RawResult.GetHashCode();
|
return Result.GetHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return RawResult.ToString();
|
return Result.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ namespace Wox.ViewModel
|
|||||||
for (; index < list.Count; index++)
|
for (; index < list.Count; index++)
|
||||||
{
|
{
|
||||||
var result = list[index];
|
var result = list[index];
|
||||||
if (newScore > result.RawResult.Score)
|
if (newScore > result.Result.Score)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -113,12 +113,12 @@ namespace Wox.ViewModel
|
|||||||
|
|
||||||
public void RemoveResultsExcept(PluginMetadata metadata)
|
public void RemoveResultsExcept(PluginMetadata metadata)
|
||||||
{
|
{
|
||||||
Results.RemoveAll(r => r.RawResult.PluginID != metadata.ID);
|
Results.RemoveAll(r => r.Result.PluginID != metadata.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveResultsFor(PluginMetadata metadata)
|
public void RemoveResultsFor(PluginMetadata metadata)
|
||||||
{
|
{
|
||||||
Results.RemoveAll(r => r.PluginID == metadata.ID);
|
Results.RemoveAll(r => r.Result.PluginID == metadata.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -149,7 +149,7 @@ namespace Wox.ViewModel
|
|||||||
{
|
{
|
||||||
var newResults = newRawResults.Select(r => new ResultViewModel(r)).ToList();
|
var newResults = newRawResults.Select(r => new ResultViewModel(r)).ToList();
|
||||||
var results = Results.ToList();
|
var results = Results.ToList();
|
||||||
var oldResults = results.Where(r => r.PluginID == resultId).ToList();
|
var oldResults = results.Where(r => r.Result.PluginID == resultId).ToList();
|
||||||
|
|
||||||
// intersection of A (old results) and B (new newResults)
|
// intersection of A (old results) and B (new newResults)
|
||||||
var intersection = oldResults.Intersect(newResults).ToList();
|
var intersection = oldResults.Intersect(newResults).ToList();
|
||||||
@@ -164,15 +164,15 @@ namespace Wox.ViewModel
|
|||||||
foreach (var commonResult in intersection)
|
foreach (var commonResult in intersection)
|
||||||
{
|
{
|
||||||
int oldIndex = results.IndexOf(commonResult);
|
int oldIndex = results.IndexOf(commonResult);
|
||||||
int oldScore = results[oldIndex].Score;
|
int oldScore = results[oldIndex].Result.Score;
|
||||||
var newResult = newResults[newResults.IndexOf(commonResult)];
|
var newResult = newResults[newResults.IndexOf(commonResult)];
|
||||||
int newScore = newResult.Score;
|
int newScore = newResult.Result.Score;
|
||||||
if (newScore != oldScore)
|
if (newScore != oldScore)
|
||||||
{
|
{
|
||||||
var oldResult = results[oldIndex];
|
var oldResult = results[oldIndex];
|
||||||
|
|
||||||
oldResult.Score = newScore;
|
oldResult.Result.Score = newScore;
|
||||||
oldResult.OriginQuery = newResult.OriginQuery;
|
oldResult.Result.OriginQuery = newResult.Result.OriginQuery;
|
||||||
|
|
||||||
results.RemoveAt(oldIndex);
|
results.RemoveAt(oldIndex);
|
||||||
int newIndex = InsertIndexOf(newScore, results);
|
int newIndex = InsertIndexOf(newScore, results);
|
||||||
@@ -183,7 +183,7 @@ namespace Wox.ViewModel
|
|||||||
// insert result in relative complement of A in B
|
// insert result in relative complement of A in B
|
||||||
foreach (var result in newResults.Except(intersection))
|
foreach (var result in newResults.Except(intersection))
|
||||||
{
|
{
|
||||||
int newIndex = InsertIndexOf(result.Score, results);
|
int newIndex = InsertIndexOf(result.Result.Score, results);
|
||||||
results.Insert(newIndex, result);
|
results.Insert(newIndex, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,9 +223,9 @@ namespace Wox.ViewModel
|
|||||||
{
|
{
|
||||||
this[i] = newResult;
|
this[i] = newResult;
|
||||||
}
|
}
|
||||||
else if (oldResult.Score != newResult.Score)
|
else if (oldResult.Result.Score != newResult.Result.Score)
|
||||||
{
|
{
|
||||||
this[i].Score = newResult.Score;
|
this[i].Result.Score = newResult.Result.Score;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user