Introduce viewmodel for settingwindow

This commit is contained in:
bao-qian 2016-05-21 22:44:27 +01:00
parent cc4b343cf4
commit 7d2ac2f55d
7 changed files with 51 additions and 15 deletions

View File

@ -13,6 +13,8 @@
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -80,6 +82,10 @@
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="PropertyChanged, Version=1.51.0.0, Culture=neutral, PublicKeyToken=ee3ee20bcf148ddd, processorArchitecture=MSIL">
<HintPath>..\packages\PropertyChanged.Fody.1.51.0\lib\dotnet\PropertyChanged.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Splat, Version=1.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Splat.1.6.2\lib\Net45\Splat.dll</HintPath>
<Private>True</Private>

View File

@ -42,13 +42,13 @@ namespace Wox
{
RegisterDispatcherUnhandledException();
var storage = new JsonStrorage<Settings>();
_settings = storage.Load();
var settingVM = new SettingWindowViewModel();
_settings = settingVM.Settings;
PluginManager.LoadPlugins(_settings.PluginSettings);
var vm = new MainViewModel(_settings, storage);
var window = new MainWindow(_settings, vm);
API = new PublicAPIInstance(_settings, vm);
var mainVM = new MainViewModel(_settings);
var window = new MainWindow(_settings, mainVM);
API = new PublicAPIInstance(settingVM, mainVM);
PluginManager.InitializePlugins(API);
ImageLoader.PreloadImages();

View File

@ -20,13 +20,13 @@ namespace Wox
{
public class PublicAPIInstance : IPublicAPI
{
private readonly Settings _settings;
private readonly SettingWindowViewModel _settingsViewModel;
#region Constructor
public PublicAPIInstance(Settings settings, MainViewModel mainVM)
public PublicAPIInstance(SettingWindowViewModel settingsViewModel, MainViewModel mainVM)
{
_settings = settings;
_settingsViewModel = settingsViewModel;
MainVM = mainVM;
//_settings = settings;
GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
@ -100,7 +100,7 @@ namespace Wox
{
Application.Current.Dispatcher.Invoke(() =>
{
SettingWindow sw = SingletonWindowOpener.Open<SettingWindow>(this, _settings);
SettingWindow sw = SingletonWindowOpener.Open<SettingWindow>(this, _settingsViewModel);
sw.SwitchTo(tabName);
});
}

View File

@ -37,10 +37,11 @@ namespace Wox
private bool themeTabLoaded;
private Settings _settings;
public SettingWindow(IPublicAPI api, Settings settings)
public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
{
InitializeComponent();
_settings = settings;
_settings = viewModel.Settings;
DataContext = viewModel;
_api = api;
ResultListBoxPreview.DataContext = new ResultsViewModel(_settings);
Loaded += Setting_Loaded;

View File

@ -38,7 +38,6 @@ namespace Wox.ViewModel
private string _queryTextBeforeLoadContextMenu;
private string _queryText;
private readonly JsonStrorage<Settings> _settingsStorage;
private readonly JsonStrorage<QueryHistory> _queryHistoryStorage;
private readonly JsonStrorage<UserSelectedRecord> _userSelectedRecordStorage;
private readonly JsonStrorage<TopMostRecord> _topMostRecordStorage;
@ -55,14 +54,13 @@ namespace Wox.ViewModel
#region Constructor
public MainViewModel(Settings settings, JsonStrorage<Settings> storage)
public MainViewModel(Settings settings)
{
_saved = false;
_queryTextBeforeLoadContextMenu = "";
_queryText = "";
_lastQuery = new Query();
_settingsStorage = storage;
_settings = settings;
// happlebao todo temp fix for instance code logic
@ -659,7 +657,6 @@ namespace Wox.ViewModel
{
if (!_saved)
{
_settingsStorage.Save();
_queryHistoryStorage.Save();
_userSelectedRecordStorage.Save();
_topMostRecordStorage.Save();

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wox.Core.Resource;
using Wox.Core.UserSettings;
using Wox.Infrastructure.Storage;
namespace Wox.ViewModel
{
public class SettingWindowViewModel
{
private readonly JsonStrorage<Settings> _storage;
public Settings Settings { get; set; }
public List<Language> Languages => InternationalizationManager.Instance.LoadAvailableLanguages();
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
public SettingWindowViewModel()
{
_storage = new JsonStrorage<Settings>();
Settings = _storage.Load();
}
public void Save()
{
_storage.Save();
}
}
}

View File

@ -30,6 +30,8 @@
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -167,6 +169,7 @@
<Compile Include="ViewModel\MainViewModel.cs" />
<Compile Include="ViewModel\ResultViewModel.cs" />
<Compile Include="ViewModel\ResultsViewModel.cs" />
<Compile Include="ViewModel\SettingWindowViewModel.cs" />
<Page Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>