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<App>.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<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); - } - } - - } - } -} 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 @@ <Compile Include="Converters\OpacityModeConverter.cs" /> <Compile Include="Converters\StringEmptyConverter.cs" /> <Compile Include="Converters\StringNullOrEmptyToVisibilityConverter.cs" /> - <Compile Include="Helper\ListBoxItems.cs" /> + <Compile Include="Converters\VisibilityConverter.cs" /> <Compile Include="Helper\SingletonWindowOpener.cs" /> <Compile Include="ImageLoader\ImageCacheStroage.cs" /> + <Compile Include="PublicAPIInstance.cs" /> <Compile Include="Storage\QueryHistoryStorage.cs" /> <Compile Include="Storage\TopMostRecordStorage.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"> <DependentUpon>WoxUpdate.xaml</DependentUpon> </Compile>