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

@@ -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();
}
}
}