Skip to content

Commit 2bd6e9a

Browse files
authored
Boost score for Windows home folder in Explorer results (#4357)
1 parent 1003008 commit 2bd6e9a

5 files changed

Lines changed: 119 additions & 17 deletions

File tree

Flow.Launcher.Test/Plugins/ExplorerTest.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,5 +438,49 @@ public void GivenPath_WhenHavingEnvironmentVariableOrNot_ThenShouldBeExpected(st
438438
// Then
439439
ClassicAssert.AreEqual(result, expectedResult);
440440
}
441+
442+
[Test]
443+
public void GivenNonHomeFolderPaths_WhenCheckedWithIsHomeFolderPath_ThenShouldReturnFalse()
444+
{
445+
// Given
446+
var nonHomeFolders = new[]
447+
{
448+
@"C:\SomeRandomFolder",
449+
@"C:\Windows\System32",
450+
@"C:\Program Files",
451+
};
452+
453+
// When, Then
454+
foreach (var folder in nonHomeFolders)
455+
{
456+
ClassicAssert.IsFalse(ResultManager.IsHomeFolderPath(folder),
457+
$"Expected '{folder}' to NOT be recognized as a home folder");
458+
}
459+
}
460+
461+
[Test]
462+
public void GivenPathsInsideHomeDirectories_WhenCheckedWithIsHomeFolderPath_ThenShouldReturnTrue()
463+
{
464+
var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
465+
466+
if (string.IsNullOrEmpty(desktopPath))
467+
{
468+
Assert.Ignore("Desktop special folder path is unavailable in this environment.");
469+
}
470+
471+
var homeFolderVariants = new[]
472+
{
473+
Path.Combine(desktopPath, "dummy_desktop_file"),
474+
Path.Combine(desktopPath, "dummy_desktop_folder") + "\\\\",
475+
desktopPath + "\\\\dummy_desktop_folder\\\\",
476+
Path.Combine(desktopPath, "dummy_desktop_folder", "dummy_desktop_file"),
477+
};
478+
479+
foreach (var path in homeFolderVariants)
480+
{
481+
ClassicAssert.IsTrue(ResultManager.IsHomeFolderPath(path),
482+
$"Expected '{path}' to be recognized as inside a home folder");
483+
}
484+
}
441485
}
442486
}

Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<system:String x:Key="plugin_explorer_use_location_as_working_dir">Use search result's location as the working directory of the executable</system:String>
5252
<system:String x:Key="plugin_explorer_display_more_info_in_tooltip">Display more information like size and age in tooltips</system:String>
5353
<system:String x:Key="plugin_explorer_default_open_in_file_manager">Hit Enter to open folder in Default File Manager</system:String>
54+
<system:String x:Key="plugin_explorer_boost_home_folder_score">Prioritize home folders (Documents, Desktop, Downloads, etc.) in search results</system:String>
5455
<system:String x:Key="plugin_explorer_usewindowsindexfordirectorysearch">Use Index Search For Path Search</system:String>
5556
<system:String x:Key="plugin_explorer_manageindexoptions">Indexing Options</system:String>
5657
<system:String x:Key="plugin_explorer_actionkeywordview_search">Search:</system:String>

Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Linq;
45
using System.Threading.Tasks;
@@ -21,6 +22,47 @@ public static class ResultManager
2122
private static PluginInitContext Context;
2223
private static Settings Settings { get; set; }
2324

25+
private const int HomeFolderScoreBoost = 50;
26+
27+
private static readonly Lazy<HashSet<string>> HomeFolderPaths = new(() =>
28+
{
29+
var paths = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
30+
31+
var specialFolders = new[]
32+
{
33+
Environment.SpecialFolder.MyDocuments,
34+
Environment.SpecialFolder.MyPictures,
35+
Environment.SpecialFolder.MyMusic,
36+
Environment.SpecialFolder.MyVideos,
37+
Environment.SpecialFolder.Desktop,
38+
Environment.SpecialFolder.UserProfile,
39+
};
40+
41+
foreach (var folder in specialFolders)
42+
{
43+
var path = Environment.GetFolderPath(folder);
44+
if (!string.IsNullOrEmpty(path))
45+
paths.Add(path);
46+
}
47+
48+
// Downloads has no dedicated SpecialFolder enum value
49+
var userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
50+
if (!string.IsNullOrEmpty(userProfile))
51+
paths.Add(Path.Combine(userProfile, "Downloads"));
52+
53+
return paths;
54+
});
55+
56+
public static bool IsHomeFolderPath(string path)
57+
{
58+
if (string.IsNullOrEmpty(path))
59+
return false;
60+
61+
var normalizedPath = path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
62+
return HomeFolderPaths.Value.Any(homeFolderPath =>
63+
FilesFolders.PathContains(homeFolderPath, normalizedPath, allowEqual: true));
64+
}
65+
2466
public static void Init(PluginInitContext context, Settings settings)
2567
{
2668
Context = context;
@@ -94,6 +136,9 @@ internal static void ShowNativeContextMenu(string path, ResultType type)
94136

95137
internal static Result CreateFolderResult(string title, string subtitle, string path, Query query, int score = 0, bool windowsIndexed = false)
96138
{
139+
if (Settings.BoostHomeFolderScore && IsHomeFolderPath(path))
140+
score += HomeFolderScoreBoost;
141+
97142
return new Result
98143
{
99144
Title = title,

Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class Settings
3939

4040
public bool DisplayMoreInformationInToolTip { get; set; } = false;
4141

42+
public bool BoostHomeFolderScore { get; set; } = true;
43+
4244
public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
4345

4446
public bool SearchActionKeywordEnabled { get; set; } = true;

Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
<RowDefinition Height="Auto" />
203203
<RowDefinition Height="Auto" />
204204
<RowDefinition Height="Auto" />
205+
<RowDefinition Height="Auto" />
205206
</Grid.RowDefinitions>
206207
<Grid.ColumnDefinitions>
207208
<ColumnDefinition Width="Auto" />
@@ -234,16 +235,25 @@
234235
Content="{DynamicResource plugin_explorer_display_more_info_in_tooltip}"
235236
IsChecked="{Binding Settings.DisplayMoreInformationInToolTip}" />
236237

237-
<TextBlock
238+
<CheckBox
238239
Grid.Row="3"
239240
Grid.Column="0"
241+
Grid.ColumnSpan="2"
242+
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
243+
HorizontalAlignment="Left"
244+
Content="{DynamicResource plugin_explorer_boost_home_folder_score}"
245+
IsChecked="{Binding Settings.BoostHomeFolderScore}" />
246+
247+
<TextBlock
248+
Grid.Row="4"
249+
Grid.Column="0"
240250
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
241251
HorizontalAlignment="Left"
242252
VerticalAlignment="Center"
243253
Foreground="{DynamicResource Color05B}"
244254
Text="{DynamicResource plugin_explorer_file_editor_path}" />
245255
<StackPanel
246-
Grid.Row="3"
256+
Grid.Row="4"
247257
Grid.Column="1"
248258
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
249259
Orientation="Horizontal">
@@ -262,15 +272,15 @@
262272
</StackPanel>
263273

264274
<TextBlock
265-
Grid.Row="4"
275+
Grid.Row="5"
266276
Grid.Column="0"
267277
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
268278
HorizontalAlignment="Left"
269279
VerticalAlignment="Center"
270280
Foreground="{DynamicResource Color05B}"
271281
Text="{DynamicResource plugin_explorer_folder_editor_path}" />
272282
<StackPanel
273-
Grid.Row="4"
283+
Grid.Row="5"
274284
Grid.Column="1"
275285
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
276286
Orientation="Horizontal">
@@ -289,15 +299,15 @@
289299
</StackPanel>
290300

291301
<TextBlock
292-
Grid.Row="5"
302+
Grid.Row="6"
293303
Grid.Column="0"
294304
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
295305
HorizontalAlignment="Left"
296306
VerticalAlignment="Center"
297307
Foreground="{DynamicResource Color05B}"
298308
Text="{DynamicResource plugin_explorer_shell_path}" />
299309
<StackPanel
300-
Grid.Row="5"
310+
Grid.Row="6"
301311
Grid.Column="1"
302312
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
303313
Orientation="Horizontal">
@@ -316,14 +326,14 @@
316326
</StackPanel>
317327

318328
<TextBlock
319-
Grid.Row="6"
329+
Grid.Row="7"
320330
Grid.Column="0"
321331
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
322332
VerticalAlignment="Center"
323333
Foreground="{DynamicResource Color05B}"
324334
Text="{DynamicResource plugin_explorer_Index_Search_Engine}" />
325335
<ComboBox
326-
Grid.Row="6"
336+
Grid.Row="7"
327337
Grid.Column="1"
328338
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
329339
HorizontalAlignment="Left"
@@ -333,14 +343,14 @@
333343
SelectedItem="{Binding SelectedIndexSearchEngine}" />
334344

335345
<TextBlock
336-
Grid.Row="7"
346+
Grid.Row="8"
337347
Grid.Column="0"
338348
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
339349
VerticalAlignment="Center"
340350
Foreground="{DynamicResource Color05B}"
341351
Text="{DynamicResource plugin_explorer_Content_Search_Engine}" />
342352
<ComboBox
343-
Grid.Row="7"
353+
Grid.Row="8"
344354
Grid.Column="1"
345355
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
346356
HorizontalAlignment="Left"
@@ -350,14 +360,14 @@
350360
SelectedItem="{Binding SelectedContentSearchEngine}" />
351361

352362
<TextBlock
353-
Grid.Row="8"
363+
Grid.Row="9"
354364
Grid.Column="0"
355365
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
356366
VerticalAlignment="Center"
357367
Foreground="{DynamicResource Color05B}"
358368
Text="{DynamicResource plugin_explorer_Directory_Recursive_Search_Engine}" />
359369
<ComboBox
360-
Grid.Row="8"
370+
Grid.Row="9"
361371
Grid.Column="1"
362372
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
363373
HorizontalAlignment="Left"
@@ -367,14 +377,14 @@
367377
SelectedItem="{Binding SelectedPathEnumerationEngine}" />
368378

369379
<TextBlock
370-
Grid.Row="9"
380+
Grid.Row="10"
371381
Grid.Column="0"
372382
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
373383
VerticalAlignment="Center"
374384
Foreground="{DynamicResource Color05B}"
375385
Text="{DynamicResource plugin_explorer_Excluded_File_Types}" />
376386
<TextBox
377-
Grid.Row="9"
387+
Grid.Row="10"
378388
Grid.Column="1"
379389
MinWidth="{StaticResource SettingPanelTextBoxMinWidth}"
380390
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
@@ -383,14 +393,14 @@
383393
ToolTip="{DynamicResource plugin_explorer_Excluded_File_Types_Tooltip}" />
384394

385395
<TextBlock
386-
Grid.Row="10"
396+
Grid.Row="11"
387397
Grid.Column="0"
388398
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
389399
VerticalAlignment="Center"
390400
Foreground="{DynamicResource Color05B}"
391401
Text="{DynamicResource plugin_explorer_Maximum_Results}" />
392402
<TextBox
393-
Grid.Row="10"
403+
Grid.Row="11"
394404
Grid.Column="1"
395405
MinWidth="{StaticResource SettingPanelTextBoxMinWidth}"
396406
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
@@ -402,7 +412,7 @@
402412
ToolTip="{DynamicResource plugin_explorer_Maximum_Results_Tooltip}" />
403413

404414
<Button
405-
Grid.Row="11"
415+
Grid.Row="12"
406416
Grid.Column="0"
407417
Grid.ColumnSpan="2"
408418
Margin="{StaticResource SettingPanelItemTopBottomMargin}"

0 commit comments

Comments
 (0)