mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 11:39:16 +08:00
Introduce viewmodel for settingwindow
This commit is contained in:
parent
cc4b343cf4
commit
7d2ac2f55d
@ -13,6 +13,8 @@
|
|||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
|
<NuGetPackageImportStamp>
|
||||||
|
</NuGetPackageImportStamp>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
@ -80,6 +82,10 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="PresentationCore" />
|
<Reference Include="PresentationCore" />
|
||||||
<Reference Include="PresentationFramework" />
|
<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">
|
<Reference Include="Splat, Version=1.6.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Splat.1.6.2\lib\Net45\Splat.dll</HintPath>
|
<HintPath>..\packages\Splat.1.6.2\lib\Net45\Splat.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
|
@ -42,13 +42,13 @@ namespace Wox
|
|||||||
{
|
{
|
||||||
RegisterDispatcherUnhandledException();
|
RegisterDispatcherUnhandledException();
|
||||||
|
|
||||||
var storage = new JsonStrorage<Settings>();
|
var settingVM = new SettingWindowViewModel();
|
||||||
_settings = storage.Load();
|
_settings = settingVM.Settings;
|
||||||
|
|
||||||
PluginManager.LoadPlugins(_settings.PluginSettings);
|
PluginManager.LoadPlugins(_settings.PluginSettings);
|
||||||
var vm = new MainViewModel(_settings, storage);
|
var mainVM = new MainViewModel(_settings);
|
||||||
var window = new MainWindow(_settings, vm);
|
var window = new MainWindow(_settings, mainVM);
|
||||||
API = new PublicAPIInstance(_settings, vm);
|
API = new PublicAPIInstance(settingVM, mainVM);
|
||||||
PluginManager.InitializePlugins(API);
|
PluginManager.InitializePlugins(API);
|
||||||
|
|
||||||
ImageLoader.PreloadImages();
|
ImageLoader.PreloadImages();
|
||||||
|
@ -20,13 +20,13 @@ namespace Wox
|
|||||||
{
|
{
|
||||||
public class PublicAPIInstance : IPublicAPI
|
public class PublicAPIInstance : IPublicAPI
|
||||||
{
|
{
|
||||||
private readonly Settings _settings;
|
private readonly SettingWindowViewModel _settingsViewModel;
|
||||||
|
|
||||||
#region Constructor
|
#region Constructor
|
||||||
|
|
||||||
public PublicAPIInstance(Settings settings, MainViewModel mainVM)
|
public PublicAPIInstance(SettingWindowViewModel settingsViewModel, MainViewModel mainVM)
|
||||||
{
|
{
|
||||||
_settings = settings;
|
_settingsViewModel = settingsViewModel;
|
||||||
MainVM = mainVM;
|
MainVM = mainVM;
|
||||||
//_settings = settings;
|
//_settings = settings;
|
||||||
GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
|
GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
|
||||||
@ -100,7 +100,7 @@ namespace Wox
|
|||||||
{
|
{
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
SettingWindow sw = SingletonWindowOpener.Open<SettingWindow>(this, _settings);
|
SettingWindow sw = SingletonWindowOpener.Open<SettingWindow>(this, _settingsViewModel);
|
||||||
sw.SwitchTo(tabName);
|
sw.SwitchTo(tabName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -37,10 +37,11 @@ namespace Wox
|
|||||||
private bool themeTabLoaded;
|
private bool themeTabLoaded;
|
||||||
private Settings _settings;
|
private Settings _settings;
|
||||||
|
|
||||||
public SettingWindow(IPublicAPI api, Settings settings)
|
public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_settings = settings;
|
_settings = viewModel.Settings;
|
||||||
|
DataContext = viewModel;
|
||||||
_api = api;
|
_api = api;
|
||||||
ResultListBoxPreview.DataContext = new ResultsViewModel(_settings);
|
ResultListBoxPreview.DataContext = new ResultsViewModel(_settings);
|
||||||
Loaded += Setting_Loaded;
|
Loaded += Setting_Loaded;
|
||||||
|
@ -38,7 +38,6 @@ namespace Wox.ViewModel
|
|||||||
private string _queryTextBeforeLoadContextMenu;
|
private string _queryTextBeforeLoadContextMenu;
|
||||||
private string _queryText;
|
private string _queryText;
|
||||||
|
|
||||||
private readonly JsonStrorage<Settings> _settingsStorage;
|
|
||||||
private readonly JsonStrorage<QueryHistory> _queryHistoryStorage;
|
private readonly JsonStrorage<QueryHistory> _queryHistoryStorage;
|
||||||
private readonly JsonStrorage<UserSelectedRecord> _userSelectedRecordStorage;
|
private readonly JsonStrorage<UserSelectedRecord> _userSelectedRecordStorage;
|
||||||
private readonly JsonStrorage<TopMostRecord> _topMostRecordStorage;
|
private readonly JsonStrorage<TopMostRecord> _topMostRecordStorage;
|
||||||
@ -55,14 +54,13 @@ namespace Wox.ViewModel
|
|||||||
|
|
||||||
#region Constructor
|
#region Constructor
|
||||||
|
|
||||||
public MainViewModel(Settings settings, JsonStrorage<Settings> storage)
|
public MainViewModel(Settings settings)
|
||||||
{
|
{
|
||||||
_saved = false;
|
_saved = false;
|
||||||
_queryTextBeforeLoadContextMenu = "";
|
_queryTextBeforeLoadContextMenu = "";
|
||||||
_queryText = "";
|
_queryText = "";
|
||||||
_lastQuery = new Query();
|
_lastQuery = new Query();
|
||||||
|
|
||||||
_settingsStorage = storage;
|
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
|
|
||||||
// happlebao todo temp fix for instance code logic
|
// happlebao todo temp fix for instance code logic
|
||||||
@ -659,7 +657,6 @@ namespace Wox.ViewModel
|
|||||||
{
|
{
|
||||||
if (!_saved)
|
if (!_saved)
|
||||||
{
|
{
|
||||||
_settingsStorage.Save();
|
|
||||||
_queryHistoryStorage.Save();
|
_queryHistoryStorage.Save();
|
||||||
_userSelectedRecordStorage.Save();
|
_userSelectedRecordStorage.Save();
|
||||||
_topMostRecordStorage.Save();
|
_topMostRecordStorage.Save();
|
||||||
|
29
Wox/ViewModel/SettingWindowViewModel.cs
Normal file
29
Wox/ViewModel/SettingWindowViewModel.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -30,6 +30,8 @@
|
|||||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||||
<UseApplicationTrust>false</UseApplicationTrust>
|
<UseApplicationTrust>false</UseApplicationTrust>
|
||||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||||
|
<NuGetPackageImportStamp>
|
||||||
|
</NuGetPackageImportStamp>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
@ -167,6 +169,7 @@
|
|||||||
<Compile Include="ViewModel\MainViewModel.cs" />
|
<Compile Include="ViewModel\MainViewModel.cs" />
|
||||||
<Compile Include="ViewModel\ResultViewModel.cs" />
|
<Compile Include="ViewModel\ResultViewModel.cs" />
|
||||||
<Compile Include="ViewModel\ResultsViewModel.cs" />
|
<Compile Include="ViewModel\ResultsViewModel.cs" />
|
||||||
|
<Compile Include="ViewModel\SettingWindowViewModel.cs" />
|
||||||
<Page Include="App.xaml">
|
<Page Include="App.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
|
Loading…
Reference in New Issue
Block a user