From e15baeb4a2047ea06b5e947129a468bb7db6c8b9 Mon Sep 17 00:00:00 2001 From: Colin Liu Date: Thu, 18 Feb 2016 19:35:17 +0800 Subject: [PATCH] Remove unused code and add required code for MVVM --- Wox/App.xaml.cs | 14 ++++++-- Wox/Helper/ListBoxItems.cs | 71 -------------------------------------- Wox/Wox.csproj | 7 +++- 3 files changed, 18 insertions(+), 74 deletions(-) delete mode 100644 Wox/Helper/ListBoxItems.cs diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index 19ff2c2f17..2b9ed56c32 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -10,6 +10,8 @@ using Wox.CommandArgs; using Wox.Core.Plugin; using Wox.Helper; using Wox.Infrastructure; +using Wox.Plugin; +using Wox.ViewModel; using Stopwatch = Wox.Infrastructure.Stopwatch; @@ -20,6 +22,8 @@ namespace Wox private const string Unique = "Wox_Unique_Application_Mutex"; public static MainWindow Window { get; private set; } + public static IPublicAPI API { get; private set; } + [STAThread] public static void Main() { @@ -40,8 +44,14 @@ namespace Wox WoxDirectroy.Executable = Directory.GetParent(Assembly.GetExecutingAssembly().Location).ToString(); RegisterUnhandledException(); ThreadPool.QueueUserWorkItem(o => { ImageLoader.ImageLoader.PreloadImages(); }); + + + MainViewModel mainVM = new MainViewModel(); + API = new PublicAPIInstance(mainVM); Window = new MainWindow(); - PluginManager.Init(Window); + Window.DataContext = mainVM; + + PluginManager.Init(API); CommandArgsFactory.Execute(e.Args.ToList()); }); @@ -59,7 +69,7 @@ namespace Wox { if (args.Count > 0 && args[0] == SingleInstance.Restart) { - Window.CloseApp(); + API.CloseApp(); } else { diff --git a/Wox/Helper/ListBoxItems.cs b/Wox/Helper/ListBoxItems.cs deleted file mode 100644 index bb2bdc2a2e..0000000000 --- a/Wox/Helper/ListBoxItems.cs +++ /dev/null @@ -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 - // todo implement custom moveItem,removeItem,insertItem for better performance - { - public void RemoveAll(Predicate predicate) - { - CheckReentrancy(); - - List 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 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); - } - } - - } - } -} diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index d05cf6ffd1..e0e17c5cf2 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -123,12 +123,17 @@ - + + + + + + WoxUpdate.xaml