diff --git a/Flow.Launcher.Test/Plugins/ExplorerTest.cs b/Flow.Launcher.Test/Plugins/ExplorerTest.cs index 9ec95215556..b443734c7d1 100644 --- a/Flow.Launcher.Test/Plugins/ExplorerTest.cs +++ b/Flow.Launcher.Test/Plugins/ExplorerTest.cs @@ -438,5 +438,49 @@ public void GivenPath_WhenHavingEnvironmentVariableOrNot_ThenShouldBeExpected(st // Then ClassicAssert.AreEqual(result, expectedResult); } + + [Test] + public void GivenNonHomeFolderPaths_WhenCheckedWithIsHomeFolderPath_ThenShouldReturnFalse() + { + // Given + var nonHomeFolders = new[] + { + @"C:\SomeRandomFolder", + @"C:\Windows\System32", + @"C:\Program Files", + }; + + // When, Then + foreach (var folder in nonHomeFolders) + { + ClassicAssert.IsFalse(ResultManager.IsHomeFolderPath(folder), + $"Expected '{folder}' to NOT be recognized as a home folder"); + } + } + + [Test] + public void GivenPathsInsideHomeDirectories_WhenCheckedWithIsHomeFolderPath_ThenShouldReturnTrue() +{ + var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + + if (string.IsNullOrEmpty(desktopPath)) + { + Assert.Ignore("Desktop special folder path is unavailable in this environment."); + } + + var homeFolderVariants = new[] + { + Path.Combine(desktopPath, "dummy_desktop_file"), + Path.Combine(desktopPath, "dummy_desktop_folder") + "\\\\", + desktopPath + "\\\\dummy_desktop_folder\\\\", + Path.Combine(desktopPath, "dummy_desktop_folder", "dummy_desktop_file"), + }; + + foreach (var path in homeFolderVariants) + { + ClassicAssert.IsTrue(ResultManager.IsHomeFolderPath(path), + $"Expected '{path}' to be recognized as inside a home folder"); + } + } } } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml index 45c0d72acd9..1eae757083c 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml @@ -51,6 +51,7 @@ Use search result's location as the working directory of the executable Display more information like size and age in tooltips Hit Enter to open folder in Default File Manager + Prioritize home folders (Documents, Desktop, Downloads, etc.) in search results Use Index Search For Path Search Indexing Options Search: diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index 18eb168b9bd..bf87cf1dadc 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -21,6 +22,47 @@ public static class ResultManager private static PluginInitContext Context; private static Settings Settings { get; set; } + private const int HomeFolderScoreBoost = 50; + + private static readonly Lazy> HomeFolderPaths = new(() => + { + var paths = new HashSet(StringComparer.OrdinalIgnoreCase); + + var specialFolders = new[] + { + Environment.SpecialFolder.MyDocuments, + Environment.SpecialFolder.MyPictures, + Environment.SpecialFolder.MyMusic, + Environment.SpecialFolder.MyVideos, + Environment.SpecialFolder.Desktop, + Environment.SpecialFolder.UserProfile, + }; + + foreach (var folder in specialFolders) + { + var path = Environment.GetFolderPath(folder); + if (!string.IsNullOrEmpty(path)) + paths.Add(path); + } + + // Downloads has no dedicated SpecialFolder enum value + var userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + if (!string.IsNullOrEmpty(userProfile)) + paths.Add(Path.Combine(userProfile, "Downloads")); + + return paths; + }); + + public static bool IsHomeFolderPath(string path) + { + if (string.IsNullOrEmpty(path)) + return false; + + var normalizedPath = path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + return HomeFolderPaths.Value.Any(homeFolderPath => + FilesFolders.PathContains(homeFolderPath, normalizedPath, allowEqual: true)); + } + public static void Init(PluginInitContext context, Settings settings) { Context = context; @@ -94,6 +136,9 @@ internal static void ShowNativeContextMenu(string path, ResultType type) internal static Result CreateFolderResult(string title, string subtitle, string path, Query query, int score = 0, bool windowsIndexed = false) { + if (Settings.BoostHomeFolderScore && IsHomeFolderPath(path)) + score += HomeFolderScoreBoost; + return new Result { Title = title, diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs index 08e0015d4e1..b0fbad84fbe 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs @@ -39,6 +39,8 @@ public class Settings public bool DisplayMoreInformationInToolTip { get; set; } = false; + public bool BoostHomeFolderScore { get; set; } = true; + public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign; public bool SearchActionKeywordEnabled { get; set; } = true; diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml index 79000e70055..d6066df953f 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml @@ -202,6 +202,7 @@ + @@ -234,16 +235,25 @@ Content="{DynamicResource plugin_explorer_display_more_info_in_tooltip}" IsChecked="{Binding Settings.DisplayMoreInformationInToolTip}" /> - + + @@ -262,7 +272,7 @@ @@ -289,7 +299,7 @@ @@ -316,14 +326,14 @@