mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
Remove unused code and add required code for MVVM
This commit is contained in:
parent
f16804c0f8
commit
e15baeb4a2
@ -10,6 +10,8 @@ using Wox.CommandArgs;
|
|||||||
using Wox.Core.Plugin;
|
using Wox.Core.Plugin;
|
||||||
using Wox.Helper;
|
using Wox.Helper;
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
|
using Wox.Plugin;
|
||||||
|
using Wox.ViewModel;
|
||||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||||
|
|
||||||
|
|
||||||
@ -20,6 +22,8 @@ namespace Wox
|
|||||||
private const string Unique = "Wox_Unique_Application_Mutex";
|
private const string Unique = "Wox_Unique_Application_Mutex";
|
||||||
public static MainWindow Window { get; private set; }
|
public static MainWindow Window { get; private set; }
|
||||||
|
|
||||||
|
public static IPublicAPI API { get; private set; }
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main()
|
public static void Main()
|
||||||
{
|
{
|
||||||
@ -40,8 +44,14 @@ namespace Wox
|
|||||||
WoxDirectroy.Executable = Directory.GetParent(Assembly.GetExecutingAssembly().Location).ToString();
|
WoxDirectroy.Executable = Directory.GetParent(Assembly.GetExecutingAssembly().Location).ToString();
|
||||||
RegisterUnhandledException();
|
RegisterUnhandledException();
|
||||||
ThreadPool.QueueUserWorkItem(o => { ImageLoader.ImageLoader.PreloadImages(); });
|
ThreadPool.QueueUserWorkItem(o => { ImageLoader.ImageLoader.PreloadImages(); });
|
||||||
|
|
||||||
|
|
||||||
|
MainViewModel mainVM = new MainViewModel();
|
||||||
|
API = new PublicAPIInstance(mainVM);
|
||||||
Window = new MainWindow();
|
Window = new MainWindow();
|
||||||
PluginManager.Init(Window);
|
Window.DataContext = mainVM;
|
||||||
|
|
||||||
|
PluginManager.Init(API);
|
||||||
CommandArgsFactory.Execute(e.Args.ToList());
|
CommandArgsFactory.Execute(e.Args.ToList());
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -59,7 +69,7 @@ namespace Wox
|
|||||||
{
|
{
|
||||||
if (args.Count > 0 && args[0] == SingleInstance<App>.Restart)
|
if (args.Count > 0 && args[0] == SingleInstance<App>.Restart)
|
||||||
{
|
{
|
||||||
Window.CloseApp();
|
API.CloseApp();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Collections.Specialized;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Linq;
|
|
||||||
using Wox.Plugin;
|
|
||||||
|
|
||||||
namespace Wox.Helper
|
|
||||||
{
|
|
||||||
class ListBoxItems : ObservableCollection<Result>
|
|
||||||
// todo implement custom moveItem,removeItem,insertItem for better performance
|
|
||||||
{
|
|
||||||
public void RemoveAll(Predicate<Result> predicate)
|
|
||||||
{
|
|
||||||
CheckReentrancy();
|
|
||||||
|
|
||||||
List<Result> itemsToRemove = Items.Where(x => predicate(x)).ToList();
|
|
||||||
if (itemsToRemove.Count > 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
itemsToRemove.ForEach(item => Items.Remove(item));
|
|
||||||
|
|
||||||
OnPropertyChanged(new PropertyChangedEventArgs("Count"));
|
|
||||||
OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
|
|
||||||
// fuck ms
|
|
||||||
// http://blogs.msdn.com/b/nathannesbit/archive/2009/04/20/addrange-and-observablecollection.aspx
|
|
||||||
// http://geekswithblogs.net/NewThingsILearned/archive/2008/01/16/listcollectionviewcollectionview-doesnt-support-notifycollectionchanged-with-multiple-items.aspx
|
|
||||||
// PS: don't use Reset for other data updates, it will cause UI flickering
|
|
||||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(List<Result> newItems)
|
|
||||||
{
|
|
||||||
int newCount = newItems.Count;
|
|
||||||
int oldCount = Items.Count;
|
|
||||||
int location = newCount > oldCount ? oldCount : newCount;
|
|
||||||
for (int i = 0; i < location; i++)
|
|
||||||
{
|
|
||||||
Result oldItem = Items[i];
|
|
||||||
Result newItem = newItems[i];
|
|
||||||
if (!oldItem.Equals(newItem))
|
|
||||||
{
|
|
||||||
this[i] = newItem;
|
|
||||||
}
|
|
||||||
else if (oldItem.Score != newItem.Score)
|
|
||||||
{
|
|
||||||
this[i].Score = newItem.Score;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newCount > oldCount)
|
|
||||||
{
|
|
||||||
for (int i = oldCount; i < newCount; i++)
|
|
||||||
{
|
|
||||||
Add(newItems[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int removeIndex = newCount;
|
|
||||||
for (int i = newCount; i < oldCount; i++)
|
|
||||||
{
|
|
||||||
RemoveAt(removeIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -123,12 +123,17 @@
|
|||||||
<Compile Include="Converters\OpacityModeConverter.cs" />
|
<Compile Include="Converters\OpacityModeConverter.cs" />
|
||||||
<Compile Include="Converters\StringEmptyConverter.cs" />
|
<Compile Include="Converters\StringEmptyConverter.cs" />
|
||||||
<Compile Include="Converters\StringNullOrEmptyToVisibilityConverter.cs" />
|
<Compile Include="Converters\StringNullOrEmptyToVisibilityConverter.cs" />
|
||||||
<Compile Include="Helper\ListBoxItems.cs" />
|
<Compile Include="Converters\VisibilityConverter.cs" />
|
||||||
<Compile Include="Helper\SingletonWindowOpener.cs" />
|
<Compile Include="Helper\SingletonWindowOpener.cs" />
|
||||||
<Compile Include="ImageLoader\ImageCacheStroage.cs" />
|
<Compile Include="ImageLoader\ImageCacheStroage.cs" />
|
||||||
|
<Compile Include="PublicAPIInstance.cs" />
|
||||||
<Compile Include="Storage\QueryHistoryStorage.cs" />
|
<Compile Include="Storage\QueryHistoryStorage.cs" />
|
||||||
<Compile Include="Storage\TopMostRecordStorage.cs" />
|
<Compile Include="Storage\TopMostRecordStorage.cs" />
|
||||||
<Compile Include="Storage\UserSelectedRecordStorage.cs" />
|
<Compile Include="Storage\UserSelectedRecordStorage.cs" />
|
||||||
|
<Compile Include="ViewModel\BaseViewModel.cs" />
|
||||||
|
<Compile Include="ViewModel\MainViewModel.cs" />
|
||||||
|
<Compile Include="ViewModel\ResultItemViewModel.cs" />
|
||||||
|
<Compile Include="ViewModel\ResultPanelViewModel.cs" />
|
||||||
<Compile Include="WoxUpdate.xaml.cs">
|
<Compile Include="WoxUpdate.xaml.cs">
|
||||||
<DependentUpon>WoxUpdate.xaml</DependentUpon>
|
<DependentUpon>WoxUpdate.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
Loading…
Reference in New Issue
Block a user