From 7e4a37c1a3e01ef0bebde31c36771bfcab65e0d8 Mon Sep 17 00:00:00 2001 From: DB p Date: Mon, 29 Apr 2024 12:38:51 +0900 Subject: [PATCH] Fix General --- .../ViewModels/GeneralViewModel.cs | 182 ++++++++++++++++++ Flow.Launcher/SettingPages/Views/Theme.xaml | 97 ++++------ .../ViewModel/SettingWindowViewModel.cs | 43 ----- 3 files changed, 220 insertions(+), 102 deletions(-) diff --git a/Flow.Launcher/SettingPages/ViewModels/GeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/GeneralViewModel.cs index 02e1c80fe..693d1db51 100644 --- a/Flow.Launcher/SettingPages/ViewModels/GeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/GeneralViewModel.cs @@ -29,6 +29,8 @@ using Flow.Launcher.Core.Resource; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; using Flow.Launcher.Plugin.SharedModels; +using Flow.Launcher.Infrastructure; +using static Flow.Launcher.ViewModel.SettingWindowViewModel; namespace Flow.Launcher.SettingPages.ViewModels { @@ -49,6 +51,30 @@ namespace Flow.Launcher.SettingPages.ViewModels public SearchWindowScreens Value { get; set; } } + + public bool StartFlowLauncherOnSystemStartup + { + get => Settings.StartFlowLauncherOnSystemStartup; + set + { + Settings.StartFlowLauncherOnSystemStartup = value; + + try + { + if (value) + AutoStartup.Enable(); + else + AutoStartup.Disable(); + } + catch (Exception e) + { + Notification.Show(InternationalizationManager.Instance.GetTranslation("setAutoStartFailed"), + e.Message); + } + } + } + + private Internationalization _translater => InternationalizationManager.Instance; public List SearchWindowScreens { @@ -69,5 +95,161 @@ namespace Flow.Launcher.SettingPages.ViewModels } + + public List SearchWindowAligns + { + get + { + List modes = new List(); + var enums = (SearchWindowAligns[])Enum.GetValues(typeof(SearchWindowAligns)); + foreach (var e in enums) + { + var key = $"SearchWindowAlign{e}"; + var display = _translater.GetTranslation(key); + var m = new SearchWindowAlign { Display = display, Value = e, }; + modes.Add(m); + } + + return modes; + } + } + + public List ScreenNumbers + { + get + { + var screens = System.Windows.Forms.Screen.AllScreens; + var screenNumbers = new List(); + for (int i = 1; i <= screens.Length; i++) + { + screenNumbers.Add(i); + } + + return screenNumbers; + } + } + + // This is only required to set at startup. When portable mode enabled/disabled a restart is always required + private bool _portableMode = DataLocation.PortableDataLocationInUse(); + + public bool PortableMode + { + get => _portableMode; + set + { + if (!_portable.CanUpdatePortability()) + return; + + if (DataLocation.PortableDataLocationInUse()) + { + _portable.DisablePortableMode(); + } + else + { + _portable.EnablePortableMode(); + } + } + } + + + // todo a better name? + public class LastQueryMode : BaseModel + { + public string Display { get; set; } + public Infrastructure.UserSettings.LastQueryMode Value { get; set; } + } + + private List _lastQueryModes = new List(); + + public List LastQueryModes + { + get + { + if (_lastQueryModes.Count == 0) + { + _lastQueryModes = InitLastQueryModes(); + } + + return _lastQueryModes; + } + } + + private List InitLastQueryModes() + { + var modes = new List(); + var enums = (Infrastructure.UserSettings.LastQueryMode[])Enum.GetValues( + typeof(Infrastructure.UserSettings.LastQueryMode)); + foreach (var e in enums) + { + var key = $"LastQuery{e}"; + var display = _translater.GetTranslation(key); + var m = new LastQueryMode { Display = display, Value = e, }; + modes.Add(m); + } + + return modes; + } + + private void UpdateLastQueryModeDisplay() + { + foreach (var item in LastQueryModes) + { + item.Display = _translater.GetTranslation($"LastQuery{item.Value}"); + } + } + + public string Language + { + get + { + return Settings.Language; + } + set + { + InternationalizationManager.Instance.ChangeLanguage(value); + + if (InternationalizationManager.Instance.PromptShouldUsePinyin(value)) + ShouldUsePinyin = true; + + UpdateLastQueryModeDisplay(); + } + } + + public bool ShouldUsePinyin + { + get + { + return Settings.ShouldUsePinyin; + } + set + { + Settings.ShouldUsePinyin = value; + } + } + + public List QuerySearchPrecisionStrings + { + get + { + var precisionStrings = new List(); + + var enumList = Enum.GetValues(typeof(SearchPrecisionScore)).Cast().ToList(); + + enumList.ForEach(x => precisionStrings.Add(x.ToString())); + + return precisionStrings; + } + } + + public List OpenResultModifiersList => new List + { + KeyConstant.Alt, KeyConstant.Ctrl, $"{KeyConstant.Ctrl}+{KeyConstant.Alt}" + }; + + public List Languages => _translater.LoadAvailableLanguages(); + public IEnumerable MaxResultsRange => Enumerable.Range(2, 16); + + public string AlwaysPreviewToolTip => + string.Format(_translater.GetTranslation("AlwaysPreviewToolTip"), Settings.PreviewHotkey); } } diff --git a/Flow.Launcher/SettingPages/Views/Theme.xaml b/Flow.Launcher/SettingPages/Views/Theme.xaml index 73aca09a0..7ee9c7934 100644 --- a/Flow.Launcher/SettingPages/Views/Theme.xaml +++ b/Flow.Launcher/SettingPages/Views/Theme.xaml @@ -2,6 +2,7 @@ x:Class="Flow.Launcher.SettingPages.Views.Theme" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:cc="clr-namespace:Flow.Launcher.Resources.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:flowlauncher="clr-namespace:Flow.Launcher" xmlns:local="clr-namespace:Flow.Launcher.SettingPages.Views" @@ -13,14 +14,6 @@ d:DesignWidth="800" Style="{DynamicResource SettingPageBasic}" mc:Ignorable="d"> - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - -  - - - + + + + + + + + + + + @@ -324,8 +303,8 @@ + Margin="0,0,18,0" + IsOn="{Binding UseGlyphIcons, Mode=TwoWay}" /> diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 087cc345c..67d605a11 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -112,49 +112,6 @@ namespace Flow.Launcher.ViewModel string.Format(_translater.GetTranslation("AlwaysPreviewToolTip"), Settings.PreviewHotkey); - public bool StartFlowLauncherOnSystemStartup - { - get => Settings.StartFlowLauncherOnSystemStartup; - set - { - Settings.StartFlowLauncherOnSystemStartup = value; - - try - { - if (value) - AutoStartup.Enable(); - else - AutoStartup.Disable(); - } - catch (Exception e) - { - Notification.Show(InternationalizationManager.Instance.GetTranslation("setAutoStartFailed"), - e.Message); - } - } - } - - // This is only required to set at startup. When portable mode enabled/disabled a restart is always required - private bool _portableMode = DataLocation.PortableDataLocationInUse(); - - public bool PortableMode - { - get => _portableMode; - set - { - if (!_portable.CanUpdatePortability()) - return; - - if (DataLocation.PortableDataLocationInUse()) - { - _portable.DisablePortableMode(); - } - else - { - _portable.EnablePortableMode(); - } - } - } /// /// Save Flow settings. Plugins settings are not included.