2016-05-22 05:44:27 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-05-23 02:14:59 +08:00
|
|
|
|
using System.IO;
|
2016-05-22 05:44:27 +08:00
|
|
|
|
using System.Linq;
|
2016-05-22 06:16:32 +08:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
2016-05-23 02:14:59 +08:00
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
2016-05-22 06:16:32 +08:00
|
|
|
|
using Wox.Core.Plugin;
|
2016-05-22 05:44:27 +08:00
|
|
|
|
using Wox.Core.Resource;
|
2016-05-23 02:14:59 +08:00
|
|
|
|
using Wox.Helper;
|
2016-05-23 06:51:17 +08:00
|
|
|
|
using Wox.Infrastructure;
|
2016-06-19 23:18:43 +08:00
|
|
|
|
using Wox.Infrastructure.Http;
|
2016-05-22 05:44:27 +08:00
|
|
|
|
using Wox.Infrastructure.Storage;
|
2016-06-19 23:18:43 +08:00
|
|
|
|
using Wox.Infrastructure.UserSettings;
|
2016-05-22 12:30:38 +08:00
|
|
|
|
using Wox.Plugin;
|
2016-05-22 05:44:27 +08:00
|
|
|
|
|
|
|
|
|
namespace Wox.ViewModel
|
|
|
|
|
{
|
2016-05-24 05:08:13 +08:00
|
|
|
|
public class SettingWindowViewModel : BaseModel
|
2016-05-22 05:44:27 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly JsonStrorage<Settings> _storage;
|
2016-05-22 12:30:38 +08:00
|
|
|
|
|
2016-05-23 06:51:17 +08:00
|
|
|
|
public SettingWindowViewModel()
|
|
|
|
|
{
|
|
|
|
|
_storage = new JsonStrorage<Settings>();
|
|
|
|
|
Settings = _storage.Load();
|
2016-05-24 05:08:13 +08:00
|
|
|
|
Settings.PropertyChanged += (s, e) =>
|
|
|
|
|
{
|
|
|
|
|
if (e.PropertyName == nameof(Settings.ActivateTimes))
|
|
|
|
|
{
|
|
|
|
|
OnPropertyChanged(nameof(ActivatedTimes));
|
|
|
|
|
}
|
|
|
|
|
};
|
2016-06-19 23:18:43 +08:00
|
|
|
|
|
|
|
|
|
// happlebao todo temp fix for instance code logic
|
|
|
|
|
InternationalizationManager.Instance.Settings = Settings;
|
|
|
|
|
InternationalizationManager.Instance.ChangeLanguage(Settings.Language);
|
|
|
|
|
ThemeManager.Instance.Settings = Settings;
|
|
|
|
|
Http.Proxy = Settings.Proxy;
|
2016-05-23 06:51:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Settings Settings { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Save()
|
|
|
|
|
{
|
|
|
|
|
_storage.Save();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-23 02:14:59 +08:00
|
|
|
|
#region general
|
2016-05-23 06:51:17 +08:00
|
|
|
|
|
2016-05-23 05:49:41 +08:00
|
|
|
|
public List<Language> Languages => _translater.LoadAvailableLanguages();
|
|
|
|
|
private Internationalization _translater => InternationalizationManager.Instance;
|
2016-05-22 05:44:27 +08:00
|
|
|
|
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
|
2016-05-23 06:51:17 +08:00
|
|
|
|
|
2016-05-23 02:14:59 +08:00
|
|
|
|
#endregion
|
2016-05-23 06:51:17 +08:00
|
|
|
|
|
2016-05-23 02:14:59 +08:00
|
|
|
|
#region plugin
|
2016-05-23 06:51:17 +08:00
|
|
|
|
|
2016-05-23 05:49:41 +08:00
|
|
|
|
public static string Plugin => "http://www.getwox.com/plugin";
|
2016-05-22 12:30:38 +08:00
|
|
|
|
public PluginViewModel SelectedPlugin { get; set; }
|
2016-05-23 06:51:17 +08:00
|
|
|
|
|
2016-05-22 12:51:00 +08:00
|
|
|
|
public IList<PluginViewModel> PluginViewModels
|
2016-05-22 12:30:38 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var plugins = PluginManager.AllPlugins;
|
|
|
|
|
var settings = Settings.PluginSettings.Plugins;
|
|
|
|
|
plugins.Sort((a, b) =>
|
|
|
|
|
{
|
|
|
|
|
var d1 = settings[a.Metadata.ID].Disabled;
|
|
|
|
|
var d2 = settings[b.Metadata.ID].Disabled;
|
|
|
|
|
if (d1 == d2)
|
|
|
|
|
{
|
2016-05-24 05:08:13 +08:00
|
|
|
|
return string.Compare(a.Metadata.Name, b.Metadata.Name, StringComparison.CurrentCulture);
|
2016-05-22 12:30:38 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return d1.CompareTo(d2);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var metadatas = plugins.Select(p => new PluginViewModel
|
|
|
|
|
{
|
|
|
|
|
PluginPair = p,
|
|
|
|
|
}).ToList();
|
|
|
|
|
return metadatas;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-22 06:42:23 +08:00
|
|
|
|
|
2016-05-22 12:30:38 +08:00
|
|
|
|
public Control SettingProvider
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-06-21 07:14:32 +08:00
|
|
|
|
var settingProvider = SelectedPlugin.PluginPair.Plugin as ISettingProvider;
|
2016-05-22 12:30:38 +08:00
|
|
|
|
if (settingProvider != null)
|
|
|
|
|
{
|
2016-05-23 02:23:20 +08:00
|
|
|
|
var control = settingProvider.CreateSettingPanel();
|
2016-05-22 12:30:38 +08:00
|
|
|
|
control.HorizontalAlignment = HorizontalAlignment.Stretch;
|
|
|
|
|
control.VerticalAlignment = VerticalAlignment.Stretch;
|
|
|
|
|
return control;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new Control();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-23 06:51:17 +08:00
|
|
|
|
|
2016-06-21 07:14:32 +08:00
|
|
|
|
|
|
|
|
|
|
2016-05-23 02:14:59 +08:00
|
|
|
|
#endregion
|
2016-05-23 06:51:17 +08:00
|
|
|
|
|
2016-05-23 02:14:59 +08:00
|
|
|
|
#region theme
|
2016-05-22 12:30:38 +08:00
|
|
|
|
|
2016-05-23 05:49:41 +08:00
|
|
|
|
public static string Theme => @"http://www.getwox.com/theme";
|
2016-05-23 06:51:17 +08:00
|
|
|
|
|
2016-05-23 02:14:59 +08:00
|
|
|
|
public string SelectedTheme
|
2016-05-22 12:51:00 +08:00
|
|
|
|
{
|
2016-05-23 06:51:17 +08:00
|
|
|
|
get { return Settings.Theme; }
|
2016-05-23 02:14:59 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Settings.Theme = value;
|
|
|
|
|
ThemeManager.Instance.ChangeTheme(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-23 06:51:17 +08:00
|
|
|
|
|
|
|
|
|
public List<string> Themes
|
|
|
|
|
=> ThemeManager.Instance.LoadAvailableThemes().Select(Path.GetFileNameWithoutExtension).ToList();
|
2016-05-23 02:14:59 +08:00
|
|
|
|
|
|
|
|
|
public Brush PreviewBackground
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var wallpaper = WallpaperPathRetrieval.GetWallpaperPath();
|
|
|
|
|
if (wallpaper != null && File.Exists(wallpaper))
|
|
|
|
|
{
|
|
|
|
|
var memStream = new MemoryStream(File.ReadAllBytes(wallpaper));
|
|
|
|
|
var bitmap = new BitmapImage();
|
|
|
|
|
bitmap.BeginInit();
|
|
|
|
|
bitmap.StreamSource = memStream;
|
|
|
|
|
bitmap.EndInit();
|
2016-05-24 05:08:13 +08:00
|
|
|
|
var brush = new ImageBrush(bitmap) { Stretch = Stretch.UniformToFill };
|
2016-05-23 02:14:59 +08:00
|
|
|
|
return brush;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var wallpaperColor = WallpaperPathRetrieval.GetWallpaperColor();
|
|
|
|
|
var brush = new SolidColorBrush(wallpaperColor);
|
|
|
|
|
return brush;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultsViewModel PreviewResults
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-05-23 06:51:17 +08:00
|
|
|
|
var results = new List<Result>
|
2016-05-23 02:14:59 +08:00
|
|
|
|
{
|
|
|
|
|
new Result
|
|
|
|
|
{
|
|
|
|
|
Title = "WoX is a launcher for Windows that simply works.",
|
2016-05-23 06:51:17 +08:00
|
|
|
|
SubTitle = "You can call it Windows omni-eXecutor if you want a long name."
|
2016-05-23 02:14:59 +08:00
|
|
|
|
},
|
|
|
|
|
new Result
|
|
|
|
|
{
|
|
|
|
|
Title = "Search for everything—applications, folders, files and more.",
|
2016-05-23 06:51:17 +08:00
|
|
|
|
SubTitle = "Use pinyin to search for programs. (yyy / wangyiyun → 网易云音乐)"
|
2016-05-23 02:14:59 +08:00
|
|
|
|
},
|
|
|
|
|
new Result
|
|
|
|
|
{
|
|
|
|
|
Title = "Keyword plugin search.",
|
2016-05-23 06:51:17 +08:00
|
|
|
|
SubTitle = "search google with g search_term."
|
2016-05-23 02:14:59 +08:00
|
|
|
|
},
|
|
|
|
|
new Result
|
|
|
|
|
{
|
|
|
|
|
Title = "Build custom themes at: ",
|
2016-05-23 06:51:17 +08:00
|
|
|
|
SubTitle = Theme
|
2016-05-23 02:14:59 +08:00
|
|
|
|
},
|
|
|
|
|
new Result
|
|
|
|
|
{
|
|
|
|
|
Title = "Install plugins from: ",
|
2016-05-23 06:51:17 +08:00
|
|
|
|
SubTitle = Plugin
|
2016-05-23 02:14:59 +08:00
|
|
|
|
},
|
|
|
|
|
new Result
|
|
|
|
|
{
|
2016-05-23 06:51:17 +08:00
|
|
|
|
Title = $"Open Source: {Constant.Github}",
|
|
|
|
|
SubTitle = "Please star it!"
|
2016-05-23 02:14:59 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
2016-05-24 05:08:13 +08:00
|
|
|
|
var vm = new ResultsViewModel();
|
2016-05-23 02:14:59 +08:00
|
|
|
|
vm.AddResults(results, "PREVIEW");
|
|
|
|
|
return vm;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FontFamily SelectedQueryBoxFont
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Fonts.SystemFontFamilies.Count(o =>
|
|
|
|
|
o.FamilyNames.Values != null &&
|
|
|
|
|
o.FamilyNames.Values.Contains(Settings.QueryBoxFont)) > 0)
|
|
|
|
|
{
|
|
|
|
|
var font = new FontFamily(Settings.QueryBoxFont);
|
|
|
|
|
return font;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var font = new FontFamily("Segoe UI");
|
|
|
|
|
return font;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Settings.QueryBoxFont = value.ToString();
|
|
|
|
|
ThemeManager.Instance.ChangeTheme(Settings.Theme);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FamilyTypeface SelectedQueryBoxFontFaces
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var typeface = SyntaxSugars.CallOrRescueDefault(
|
|
|
|
|
() => SelectedQueryBoxFont.ConvertFromInvariantStringsOrNormal(
|
|
|
|
|
Settings.QueryBoxFontStyle,
|
|
|
|
|
Settings.QueryBoxFontWeight,
|
|
|
|
|
Settings.QueryBoxFontStretch
|
|
|
|
|
));
|
|
|
|
|
return typeface;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Settings.QueryBoxFontStretch = value.Stretch.ToString();
|
|
|
|
|
Settings.QueryBoxFontWeight = value.Weight.ToString();
|
|
|
|
|
Settings.QueryBoxFontStyle = value.Style.ToString();
|
|
|
|
|
ThemeManager.Instance.ChangeTheme(Settings.Theme);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FontFamily SelectedResultFont
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Fonts.SystemFontFamilies.Count(o =>
|
|
|
|
|
o.FamilyNames.Values != null &&
|
|
|
|
|
o.FamilyNames.Values.Contains(Settings.ResultFont)) > 0)
|
|
|
|
|
{
|
|
|
|
|
var font = new FontFamily(Settings.ResultFont);
|
|
|
|
|
return font;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var font = new FontFamily("Segoe UI");
|
|
|
|
|
return font;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Settings.ResultFont = value.ToString();
|
|
|
|
|
ThemeManager.Instance.ChangeTheme(Settings.Theme);
|
|
|
|
|
}
|
2016-05-22 12:51:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-23 02:14:59 +08:00
|
|
|
|
public FamilyTypeface SelectedResultFontFaces
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var typeface = SyntaxSugars.CallOrRescueDefault(
|
|
|
|
|
() => SelectedQueryBoxFont.ConvertFromInvariantStringsOrNormal(
|
|
|
|
|
Settings.ResultFontStyle,
|
|
|
|
|
Settings.ResultFontWeight,
|
|
|
|
|
Settings.ResultFontStretch
|
|
|
|
|
));
|
|
|
|
|
return typeface;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Settings.ResultFontStretch = value.Stretch.ToString();
|
|
|
|
|
Settings.ResultFontWeight = value.Weight.ToString();
|
|
|
|
|
Settings.ResultFontStyle = value.Style.ToString();
|
|
|
|
|
ThemeManager.Instance.ChangeTheme(Settings.Theme);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-22 12:51:00 +08:00
|
|
|
|
|
2016-05-23 03:50:06 +08:00
|
|
|
|
#endregion
|
2016-05-23 06:51:17 +08:00
|
|
|
|
|
2016-05-23 03:50:06 +08:00
|
|
|
|
#region hotkey
|
2016-05-23 06:51:17 +08:00
|
|
|
|
|
2016-05-23 05:49:41 +08:00
|
|
|
|
public CustomPluginHotkey SelectedCustomPluginHotkey { get; set; }
|
2016-05-23 06:51:17 +08:00
|
|
|
|
|
2016-05-23 05:49:41 +08:00
|
|
|
|
#endregion
|
2016-05-23 06:51:17 +08:00
|
|
|
|
|
2016-05-23 05:49:41 +08:00
|
|
|
|
#region about
|
2016-05-23 03:50:06 +08:00
|
|
|
|
|
2016-05-23 06:51:17 +08:00
|
|
|
|
public static string Github => Constant.Github;
|
2016-05-23 05:49:41 +08:00
|
|
|
|
public static string ReleaseNotes => @"https://github.com/Wox-launcher/Wox/releases/latest";
|
2016-05-23 06:51:17 +08:00
|
|
|
|
public static string Version => Constant.Version;
|
2016-05-24 05:08:13 +08:00
|
|
|
|
public string ActivatedTimes => string.Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes);
|
2016-05-23 05:49:41 +08:00
|
|
|
|
private string _newVersionTips;
|
|
|
|
|
public string NewVersionTips
|
|
|
|
|
{
|
|
|
|
|
get { return _newVersionTips; }
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-05-24 05:08:13 +08:00
|
|
|
|
_newVersionTips = string.Format(_translater.GetTranslation("newVersionTips"), value);
|
2016-05-23 05:49:41 +08:00
|
|
|
|
NewVersionTipsVisibility = Visibility.Visible;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public Visibility NewVersionTipsVisibility { get; set; }
|
2016-05-22 12:30:38 +08:00
|
|
|
|
|
2016-05-23 06:51:17 +08:00
|
|
|
|
#endregion
|
2016-05-22 05:44:27 +08:00
|
|
|
|
}
|
2016-05-23 06:51:17 +08:00
|
|
|
|
}
|