From 04a10ed62d42f8d019d9eef72efd86ad50b2c52a Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 7 Oct 2021 21:58:54 +1100 Subject: [PATCH] add glyph option to settings --- .../UserSettings/Settings.cs | 1 + Flow.Launcher/Flow.Launcher.csproj | 4 +- Flow.Launcher/Languages/en.xaml | 7 ++-- Flow.Launcher/Languages/sk.xaml | 3 +- Flow.Launcher/Languages/zh-cn.xaml | 3 +- Flow.Launcher/SettingWindow.xaml | 16 +++++++- Flow.Launcher/ViewModel/MainViewModel.cs | 4 +- Flow.Launcher/ViewModel/ResultViewModel.cs | 37 +++++++++++++++++-- .../ViewModel/SettingWindowViewModel.cs | 6 +++ Plugins/Flow.Launcher.Plugin.Program/Main.cs | 4 +- .../Programs/Win32.cs | 12 +++--- Plugins/Flow.Launcher.Plugin.Sys/Main.cs | 32 ++++++++-------- 12 files changed, 89 insertions(+), 40 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index ebef2c631..907314ba8 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -32,6 +32,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings public string ResultFontStyle { get; set; } public string ResultFontWeight { get; set; } public string ResultFontStretch { get; set; } + public bool UseGlyphIcons { get; set; } = true; /// diff --git a/Flow.Launcher/Flow.Launcher.csproj b/Flow.Launcher/Flow.Launcher.csproj index bafb157cc..edf41e193 100644 --- a/Flow.Launcher/Flow.Launcher.csproj +++ b/Flow.Launcher/Flow.Launcher.csproj @@ -48,7 +48,6 @@ - @@ -78,6 +77,9 @@ Designer PreserveNewest + + PreserveNewest + diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 90a920e3e..420c08ba0 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -38,7 +38,7 @@ Hide tray icon Query Search Precision Should Use Pinyin - Allows using Pinyin to search. Pinyin is the standard system of romanized spelling for transliterating Chinese + Allows using Pinyin to search. Pinyin is the standard system of romanized spelling for translating Chinese Shadow effect is not allowed while current theme has blur effect enabled @@ -81,8 +81,9 @@ Please select an item Are you sure you want to delete {0} plugin hotkey? Query window shadow effect - Shadow effect has a substantial usage of GPU. - Not recommended if your computer performance is limited. + Shadow effect has a substantial usage of GPU. Not recommended if your computer performance is limited. + Use Segoe Fluent Icons + Use Segoe Fluent Icons where supported HTTP Proxy diff --git a/Flow.Launcher/Languages/sk.xaml b/Flow.Launcher/Languages/sk.xaml index 346c70837..5e63020a8 100644 --- a/Flow.Launcher/Languages/sk.xaml +++ b/Flow.Launcher/Languages/sk.xaml @@ -81,8 +81,7 @@ Vyberte položku, prosím Ste si istý, že chcete odstrániť klávesovú skratku {0} pre plugin? Tieňový efekt v poli vyhľadávania - Tieňový efekt významne využíva GPU. - Neodporúča sa, ak je výkon počítača obmedzený. + Tieňový efekt významne využíva GPU. Neodporúča sa, ak je výkon počítača obmedzený. HTTP Proxy diff --git a/Flow.Launcher/Languages/zh-cn.xaml b/Flow.Launcher/Languages/zh-cn.xaml index efc7f19d9..0c2307dc5 100644 --- a/Flow.Launcher/Languages/zh-cn.xaml +++ b/Flow.Launcher/Languages/zh-cn.xaml @@ -76,8 +76,7 @@ 请选择一项 你确定要删除插件 {0} 的热键吗? 查询窗口阴影效果 - 阴影效果将占用大量的GPU资源。 - 如果您的计算机性能有限,则不建议使用。 + 阴影效果将占用大量的GPU资源。 如果您的计算机性能有限,则不建议使用。 HTTP 代理 diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index a8f17d013..7dc8829be 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -20,7 +20,7 @@ MinWidth="850" MinHeight="600" Loaded="OnLoaded" - Closed="OnClosed" + Closed="OnClosed" d:DataContext="{d:DesignInstance vm:SettingWindowViewModel}"> @@ -29,7 +29,6 @@ - @@ -677,6 +676,19 @@ + + + + + + + + +  + + + + diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index fbe8a7f38..4212280bb 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -596,8 +596,8 @@ namespace Flow.Launcher.ViewModel menu = new Result { Title = InternationalizationManager.Instance.GetTranslation("setAsTopMostInThisQuery"), - //IcoPath = "Images\\up.png", - Glyph = new GlyphInfo(FontFamily: "Segoe Fluent Icons", Glyph: "\xeac2"), + IcoPath = "Images\\up.png", + Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xeac2"), PluginDirectory = Constant.ProgramDirectory, Action = _ => { diff --git a/Flow.Launcher/ViewModel/ResultViewModel.cs b/Flow.Launcher/ViewModel/ResultViewModel.cs index a1da2e200..ed3d842e3 100644 --- a/Flow.Launcher/ViewModel/ResultViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultViewModel.cs @@ -46,11 +46,40 @@ namespace Flow.Launcher.ViewModel public Visibility ShowOpenResultHotkey => Settings.ShowOpenResultHotkey ? Visibility.Visible : Visibility.Collapsed; - public Visibility ShowIcon => Result.IcoPath != null || Result.Icon is not null || Glyph == null - ? Visibility.Visible - : Visibility.Hidden; + public Visibility ShowIcon + { + get + { + // If both glyph and image icons are not available, it will then be the default icon + if (!ImgIconAvailable && !GlyphAvailable) + return Visibility.Visible; + + // Although user can choose to use glyph icons, plugins may choose to supply only image icons. + // In this case we ignore the setting because otherwise icons will not display as intended + if (Settings.UseGlyphIcons && !GlyphAvailable && ImgIconAvailable) + return Visibility.Visible; + + return !Settings.UseGlyphIcons && ImgIconAvailable ? Visibility.Visible : Visibility.Hidden; + } + } + + public Visibility ShowGlyph + { + get + { + // Although user can choose to not use glyph icons, plugins may choose to supply only glyph icons. + // In this case we ignore the setting because otherwise icons will not display as intended + if (!Settings.UseGlyphIcons && !ImgIconAvailable && GlyphAvailable) + return Visibility.Visible; + + return Settings.UseGlyphIcons && GlyphAvailable ? Visibility.Visible : Visibility.Hidden; + } + } + + private bool GlyphAvailable => Glyph is not null; + + private bool ImgIconAvailable => !string.IsNullOrEmpty(Result.IcoPath) || Result.Icon is not null; - public Visibility ShowGlyph => Glyph is not null ? Visibility.Visible : Visibility.Hidden; public string OpenResultModifiers => Settings.OpenResultModifiers; public string ShowTitleToolTip => string.IsNullOrEmpty(Result.TitleToolTip) diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 53789d2d9..d3a4f9a83 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -304,6 +304,12 @@ namespace Flow.Launcher.ViewModel } } + public bool UseGlyphIcons + { + get { return Settings.UseGlyphIcons; } + set { Settings.UseGlyphIcons = value; } + } + public Brush PreviewBackground { get diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs index cc997b68c..5a8a65985 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs @@ -190,8 +190,8 @@ namespace Flow.Launcher.Plugin.Program "flowlauncher_plugin_program_disable_dlgtitle_success_message")); return false; }, - //IcoPath = "Images/disable.png" - Glyph = new GlyphInfo(FontFamily: "Segoe Fluent Icons", Glyph: "\xece4"), + IcoPath = "Images/disable.png", + Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xece4"), } ); diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs index c22d1a488..a09b8c254 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs @@ -149,8 +149,8 @@ namespace Flow.Launcher.Plugin.Program.Programs return true; }, - //IcoPath = "Images/user.png" - Glyph = new GlyphInfo(FontFamily: "Segoe Fluent Icons", Glyph: "\xe7ee"), + IcoPath = "Images/user.png", + Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xe7ee"), }, new Result { @@ -169,8 +169,8 @@ namespace Flow.Launcher.Plugin.Program.Programs return true; }, - //IcoPath = "Images/cmd.png" - Glyph = new GlyphInfo(FontFamily: "Segoe Fluent Icons", Glyph: "\xe7ef"), + IcoPath = "Images/cmd.png", + Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xe7ef"), }, new Result { @@ -194,8 +194,8 @@ namespace Flow.Launcher.Plugin.Program.Programs return true; }, - //IcoPath = "Images/folder.png" - Glyph = new GlyphInfo(FontFamily: "Segoe Fluent Icons", Glyph: "\xe838"), + IcoPath = "Images/folder.png", + Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xe838"), } }; return contextMenus; diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs index a8c82b0ff..282c8a25d 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs @@ -96,8 +96,8 @@ namespace Flow.Launcher.Plugin.Sys { Title = "Shutdown", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer"), - Glyph = new GlyphInfo (FontFamily:"Segoe Fluent Icons", Glyph:"\xe7e8"), - //IcoPath = "Images\\shutdown.png", + Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe7e8"), + IcoPath = "Images\\shutdown.png", Action = c => { var reuslt = MessageBox.Show( @@ -116,8 +116,8 @@ namespace Flow.Launcher.Plugin.Sys { Title = "Restart", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"), - Glyph = new GlyphInfo (FontFamily:"Segoe Fluent Icons", Glyph:"\xe777"), - //IcoPath = "Images\\restart.png", + Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe777"), + IcoPath = "Images\\restart.png", Action = c => { var result = MessageBox.Show( @@ -136,8 +136,8 @@ namespace Flow.Launcher.Plugin.Sys { Title = "Restart With Advanced Boot Options", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_restart_advanced"), - Glyph = new GlyphInfo (FontFamily:"Segoe Fluent Icons", Glyph:"\xecc5"), - //IcoPath = "Images\\restart_advanced.png", + Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xecc5"), + IcoPath = "Images\\restart_advanced.png", Action = c => { var result = MessageBox.Show( @@ -155,16 +155,16 @@ namespace Flow.Launcher.Plugin.Sys { Title = "Log Off", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_log_off"), - Glyph = new GlyphInfo (FontFamily:"Segoe Fluent Icons", Glyph:"\xe77b"), - //IcoPath = "Images\\logoff.png", + Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe77b"), + IcoPath = "Images\\logoff.png", Action = c => ExitWindowsEx(EWX_LOGOFF, 0) }, new Result { Title = "Lock", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_lock"), - Glyph = new GlyphInfo (FontFamily:"Segoe Fluent Icons", Glyph:"\xe72e"), - //IcoPath = "Images\\lock.png", + Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe72e"), + IcoPath = "Images\\lock.png", Action = c => { LockWorkStation(); @@ -175,16 +175,16 @@ namespace Flow.Launcher.Plugin.Sys { Title = "Sleep", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_sleep"), - Glyph = new GlyphInfo (FontFamily:"Segoe Fluent Icons", Glyph:"\xec46"), - //IcoPath = "Images\\sleep.png", + Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xec46"), + IcoPath = "Images\\sleep.png", Action = c => FormsApplication.SetSuspendState(PowerState.Suspend, false, false) }, new Result { Title = "Hibernate", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_hibernate"), - Glyph = new GlyphInfo (FontFamily:"Segoe Fluent Icons", Glyph:"\xe945"), - //IcoPath = "Images\\hibernate.png", + Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe945"), + IcoPath = "Images\\hibernate.png", Action= c => { var info = ShellCommand.SetProcessStartInfo("shutdown", arguments:"/h"); @@ -200,8 +200,8 @@ namespace Flow.Launcher.Plugin.Sys { Title = "Empty Recycle Bin", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_emptyrecyclebin"), - //IcoPath = "Images\\recyclebin.png", - Glyph = new GlyphInfo (FontFamily:"Segoe Fluent Icons", Glyph:"\xe74d"), + IcoPath = "Images\\recyclebin.png", + Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe74d"), Action = c => { // http://www.pinvoke.net/default.aspx/shell32/SHEmptyRecycleBin.html