From 1c77887629391168f87616e5a61f55ab48ec13ce Mon Sep 17 00:00:00 2001 From: Divyansh Srivastava Date: Tue, 11 Aug 2020 15:06:40 -0700 Subject: [PATCH] Reduce folder plugin results (#5631) * Reduce folder plugin results * Added warning message * Added UI content for warning message in folder plugin * nit fixes for folder plugin changes * Localised warning message * fix Merge conflicts * nit fixes and move warning to end of results * Add IDisposable interface to folder plugin * Add images to MSI --- installer/PowerToysSetup/Product.wxs | 2 +- .../Microsoft.Plugin.Folder/FolderSettings.cs | 6 ++ .../Images/Warning.dark.png | Bin 0 -> 566 bytes .../Images/Warning.light.png | Bin 0 -> 580 bytes .../Microsoft.Plugin.Folder/Languages/de.xaml | 3 + .../Microsoft.Plugin.Folder/Languages/en.xaml | 3 + .../Microsoft.Plugin.Folder/Languages/pl.xaml | 3 + .../Microsoft.Plugin.Folder/Languages/tr.xaml | 3 + .../Languages/zh-cn.xaml | 3 + .../Languages/zh-tw.xaml | 3 + .../Plugins/Microsoft.Plugin.Folder/Main.cs | 74 ++++++++++++++++-- .../Microsoft.Plugin.Folder.csproj | 6 ++ 12 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Images/Warning.dark.png create mode 100644 src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Images/Warning.light.png diff --git a/installer/PowerToysSetup/Product.wxs b/installer/PowerToysSetup/Product.wxs index 8dcbca9bc9..148b0ee6ef 100644 --- a/installer/PowerToysSetup/Product.wxs +++ b/installer/PowerToysSetup/Product.wxs @@ -901,7 +901,7 @@ - + diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/FolderSettings.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/FolderSettings.cs index bdcf7051a4..f4c813e05d 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/FolderSettings.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/FolderSettings.cs @@ -11,5 +11,11 @@ namespace Microsoft.Plugin.Folder { [JsonProperty] public List FolderLinks { get; } = new List(); + + [JsonProperty] + public int MaxFolderResults { get; set; } = 50; + + [JsonProperty] + public int MaxFileResults { get; set; } = 50; } } diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Images/Warning.dark.png b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Images/Warning.dark.png new file mode 100644 index 0000000000000000000000000000000000000000..9ae30c0548f9e9ed370873e6e97ea7f29f01f7ed GIT binary patch literal 566 zcmV-60?GY}P)@4J?l_4XHULYNr^79P>pqy!;KIv=YJfuJc?R&10DkwecA*|1ll!s5B0vvhS&^y$ zN@^AX4&MnT-MJ2+RQC%GSh}DFpmMq7zyM(6f*ydV`xJnc3n~DPdMp3~7jyueu1lN& ztG*xx;HaN+JX=PmotC>^t~<*C80t#^YR`fQK%!Rc@Pvr_p%b?_F5Pb=>(1Aa0Wj5< zT*hk80vn)4B@U2weLjFteNGvjgK6$aEC7uT`o#8YkV41{l?k*dyS*COE;|^E8%xM=Anj-Z%wum<%nxsZszRh-gj1&@b{C zT3nf3CG>Il%p}i%&$f1}ZUA;#>Q>qu(CKD3YxNHN0I3xoK=-1gxBvhE07*qoM6N<$ Ef|pYB=Kufz literal 0 HcmV?d00001 diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Images/Warning.light.png b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Images/Warning.light.png new file mode 100644 index 0000000000000000000000000000000000000000..30e0d9737ed2bc41f1b37b1fb37194206e255bfe GIT binary patch literal 580 zcmV-K0=xZ*P)PW3Cjk0MzYQt&=N- zEC7{#G7n%%N#shw9pJF{cLlC;o&|S+y8Wu}oBrl?E4c!+-8?yOBv*i#>0Bwe0dSVN z=hl{T1CSV&jM0L)07&gh$7vv30GiA$fz#a(w^Ypa7B5v%-YFylv{_vOm)j9mRQP1Q z|LN+TLNY*`(KY}A@=PHKAZ9ZL;F&@aK+I$ez%vCi0B4Z{;O0wjA~OKj#~grH3MK%F zJqdth9WDtI0B4^zl>m68pazgylLAQBYfC~6AhEAWATx%)jhNOqM4yWCN=86C;b}RsveMA5jGb`ZahYm7; zG4Lg6Bg>7%0$8j_i)|XG-H!#R*`E)}{V%JOBDuNc0M9f=@-{CD(DaUz+uZv(_f9nm zFe~s70?xgQQmwbc+hmJZw|^y6n;&5?dj^hBL(&#KK$1R($$bJ25|ftbd;-78ID$a+ Sf{(ob0000Copy path (Ctrl+C) Open path in console (Ctrl+Shift+C) Open containing folder (Ctrl+Shift+E) + + Warning: Folder Plugin Results truncated. + Showing {0} of {1} results \ No newline at end of file diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/en.xaml b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/en.xaml index 810d1e6031..edef84f9f4 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/en.xaml +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/en.xaml @@ -14,4 +14,7 @@ Copy path (Ctrl+C) Open path in console (Ctrl+Shift+C) Open containing folder (Ctrl+Shift+E) + + Warning: Folder Plugin Results truncated. + Showing {0} of {1} results \ No newline at end of file diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/pl.xaml b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/pl.xaml index effc57a9ed..6df27b6824 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/pl.xaml +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/pl.xaml @@ -14,4 +14,7 @@ Copy path (Ctrl+C) Open path in console (Ctrl+Shift+C) Open containing folder (Ctrl+Shift+E) + + Warning: Folder Plugin Results truncated. + Showing {0} of {1} results \ No newline at end of file diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/tr.xaml b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/tr.xaml index 3761a990ad..a8f3271aa2 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/tr.xaml +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/tr.xaml @@ -14,4 +14,7 @@ Copy path (Ctrl+C) Open path in console (Ctrl+Shift+C) Open containing folder (Ctrl+Shift+E) + + Warning: Folder Plugin Results truncated. + Showing {0} of {1} results \ No newline at end of file diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/zh-cn.xaml b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/zh-cn.xaml index 0f5961ef7d..4f17a3023f 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/zh-cn.xaml +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/zh-cn.xaml @@ -14,4 +14,7 @@ Copy path (Ctrl+C) Open path in console (Ctrl+Shift+C) Open containing folder (Ctrl+Shift+E) + + Warning: Folder Plugin Results truncated. + Showing {0} of {1} results \ No newline at end of file diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/zh-tw.xaml b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/zh-tw.xaml index c085fba0e3..290e502049 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/zh-tw.xaml +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Languages/zh-tw.xaml @@ -14,4 +14,7 @@ Copy path (Ctrl+C) Open path in console (Ctrl+Shift+C) Open containing folder (Ctrl+Shift+E) + + Warning: Folder Plugin Results truncated. + Showing {0} of {1} results diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Main.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Main.cs index 03eaafdddc..cd4d873c12 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Main.cs @@ -18,7 +18,7 @@ using Wox.Plugin; namespace Microsoft.Plugin.Folder { - public class Main : IPlugin, ISettingProvider, IPluginI18n, ISavable, IContextMenu + public class Main : IPlugin, ISettingProvider, IPluginI18n, ISavable, IContextMenu, IDisposable { public const string FolderImagePath = "Images\\folder.dark.png"; public const string FileImagePath = "Images\\file.dark.png"; @@ -26,14 +26,13 @@ namespace Microsoft.Plugin.Folder public const string CopyImagePath = "Images\\copy.dark.png"; private const string _fileExplorerProgramName = "explorer"; - private static readonly PluginJsonStorage _storage = new PluginJsonStorage(); private static readonly FolderSettings _settings = _storage.Load(); - private static List _driverNames; - private PluginInitContext _context; - + private static PluginInitContext _context; private IContextMenu _contextMenuLoader; + private static string warningIconPath; + private bool _disposed = false; public void Save() { @@ -47,9 +46,30 @@ namespace Microsoft.Plugin.Folder public void Init(PluginInitContext context) { - _context = context; + _context = context ?? throw new ArgumentNullException(nameof(context)); _contextMenuLoader = new ContextMenuLoader(context); InitialDriverList(); + + _context.API.ThemeChanged += OnThemeChanged; + UpdateIconPath(_context.API.GetCurrentTheme()); + } + + private static void UpdateIconPath(Theme theme) + { + if (theme == Theme.Light || theme == Theme.HighContrastWhite) + { + warningIconPath = "Images/Warning.light.png"; + } + else + { + warningIconPath = "Images/Warning.dark.png"; + } + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1313:Parameter names should begin with lower-case letter", Justification = "The parameter is unused")] + private void OnThemeChanged(Theme _, Theme newTheme) + { + UpdateIconPath(newTheme); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "Do not want to change the behavior of the application, but want to enforce static analysis")] @@ -253,8 +273,28 @@ namespace Microsoft.Plugin.Folder throw; } - // Initial ordering, this order can be updated later by UpdateResultView.MainViewModel based on history of user selection. - return results.Concat(folderList.OrderBy(x => x.Title)).Concat(fileList.OrderBy(x => x.Title)).ToList(); + results = results.Concat(folderList.OrderBy(x => x.Title).Take(_settings.MaxFolderResults)).Concat(fileList.OrderBy(x => x.Title).Take(_settings.MaxFileResults)).ToList(); + + // Show warning message if result has been truncated + if (folderList.Count > _settings.MaxFolderResults || fileList.Count > _settings.MaxFileResults) + { + var preTruncationCount = folderList.Count + fileList.Count; + var postTruncationCount = Math.Min(folderList.Count, _settings.MaxFolderResults) + Math.Min(fileList.Count, _settings.MaxFileResults); + results.Add(CreateTruncatedItemsResult(search, preTruncationCount, postTruncationCount)); + } + + return results.ToList(); + } + + private static Result CreateTruncatedItemsResult(string search, int preTruncationCount, int postTruncationCount) + { + return new Result + { + Title = _context.API.GetTranslation("Microsoft_plugin_folder_truncation_warning_title"), + QueryTextDisplay = search, + SubTitle = string.Format(CultureInfo.InvariantCulture, _context.API.GetTranslation("Microsoft_plugin_folder_truncation_warning_subtitle"), postTruncationCount, preTruncationCount), + IcoPath = warningIconPath, + }; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alve and instead inform the user of the error")] @@ -330,5 +370,23 @@ namespace Microsoft.Plugin.Folder public void UpdateSettings(PowerLauncherSettings settings) { } + + public void Dispose() + { + Dispose(disposing: true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (!_disposed) + { + if (disposing) + { + _context.API.ThemeChanged -= OnThemeChanged; + _disposed = true; + } + } + } } } diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Microsoft.Plugin.Folder.csproj b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Microsoft.Plugin.Folder.csproj index 0de29244ba..93365f1560 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Microsoft.Plugin.Folder.csproj +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Microsoft.Plugin.Folder.csproj @@ -134,6 +134,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest +