Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Flow.Launcher.Test/Plugins/ExplorerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Flow.Launcher.Plugin.Explorer.Search.WindowsIndex;
using Flow.Launcher.Plugin.SharedCommands;
using NUnit.Framework;
using NUnit.Framework.Legacy;

Check warning on line 8 in Flow.Launcher.Test/Plugins/ExplorerTest.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`NUnit` is not a recognized word. (unrecognized-spelling)
using System;
using System.IO;
using System.Runtime.Versioning;
Expand Down Expand Up @@ -58,7 +58,7 @@
[SupportedOSPlatform("windows7.0")]
[TestCase("C:\\SomeFolder", "flow.launcher.sln", "SELECT TOP 100 System.FileName, System.ItemUrl, System.ItemType" +
" FROM SystemIndex WHERE directory='file:C:\\SomeFolder'" +
" AND (System.FileName LIKE 'flow.launcher.sln%' OR CONTAINS(System.FileName,'\"flow.launcher.sln*\"'))" +

Check warning on line 61 in Flow.Launcher.Test/Plugins/ExplorerTest.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`sln` is not a recognized word. (unrecognized-spelling)

Check warning on line 61 in Flow.Launcher.Test/Plugins/ExplorerTest.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`sln` is not a recognized word. (unrecognized-spelling)
$" ORDER BY {QueryConstructor.OrderIdentifier}")]
public void GivenWindowsIndexSearchTopLevelDirectory_WhenSearchingForSpecificItem_ThenQueryShouldUseExpectedString(
string folderPath, string userSearchString, string expectedString)
Expand All @@ -85,8 +85,8 @@
}

[SupportedOSPlatform("windows7.0")]
[TestCase("flow.launcher.sln", "SELECT TOP 100 \"System.FileName\", \"System.ItemUrl\", \"System.ItemType\" " +

Check warning on line 88 in Flow.Launcher.Test/Plugins/ExplorerTest.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`sln` is not a recognized word. (unrecognized-spelling)
"FROM \"SystemIndex\" WHERE (System.FileName LIKE 'flow.launcher.sln%' " +

Check warning on line 89 in Flow.Launcher.Test/Plugins/ExplorerTest.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`sln` is not a recognized word. (unrecognized-spelling)
$"OR CONTAINS(System.FileName,'\"flow.launcher.sln*\"',1033)) AND scope='file:' ORDER BY {QueryConstructor.OrderIdentifier}")]
[TestCase("", $"SELECT TOP 100 \"System.FileName\", \"System.ItemUrl\", \"System.ItemType\" FROM \"SystemIndex\" WHERE WorkId IS NOT NULL AND scope='file:' ORDER BY {QueryConstructor.OrderIdentifier}")]
public void GivenWindowsIndexSearch_WhenSearchAllFoldersAndFiles_ThenQueryShouldUseExpectedString(
Expand Down Expand Up @@ -126,7 +126,7 @@

[SupportedOSPlatform("windows7.0")]
[TestCase("some words", "SELECT TOP 100 System.FileName, System.ItemUrl, System.ItemType " +
$"FROM SystemIndex WHERE FREETEXT('some words') AND scope='file:' ORDER BY {QueryConstructor.OrderIdentifier}")]

Check warning on line 129 in Flow.Launcher.Test/Plugins/ExplorerTest.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`FREETEXT` is not a recognized word. (unrecognized-spelling)
public void GivenWindowsIndexSearch_WhenSearchForFileContent_ThenQueryShouldUseExpectedString(
string userSearchString, string expectedString)
{
Expand Down Expand Up @@ -239,8 +239,8 @@
}

[SupportedOSPlatform("windows7.0")]
[TestCase("c:\\somefolder\\>somefile", "*somefile*")]

Check warning on line 242 in Flow.Launcher.Test/Plugins/ExplorerTest.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`somefile` is not a recognized word. (unrecognized-spelling)
[TestCase("c:\\somefolder\\somefile", "somefile*")]

Check warning on line 243 in Flow.Launcher.Test/Plugins/ExplorerTest.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`somefolder` is not a recognized word. (unrecognized-spelling)

Check warning on line 243 in Flow.Launcher.Test/Plugins/ExplorerTest.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`somefile` is not a recognized word. (unrecognized-spelling)

Check warning on line 243 in Flow.Launcher.Test/Plugins/ExplorerTest.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`somefile` is not a recognized word. (unrecognized-spelling)
[TestCase("c:\\somefolder\\", "*")]
public void GivenDirectoryInfoSearch_WhenSearchPatternHotKeyIsSearchAll_ThenSearchCriteriaShouldUseCriteriaString(string path, string expectedString)
{
Expand Down Expand Up @@ -438,5 +438,49 @@
// 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");
Comment thread
Jack251970 marked this conversation as resolved.
}
}
}
}
1 change: 1 addition & 0 deletions Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<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>
<system:String x:Key="plugin_explorer_display_more_info_in_tooltip">Display more information like size and age in tooltips</system:String>
<system:String x:Key="plugin_explorer_default_open_in_file_manager">Hit Enter to open folder in Default File Manager</system:String>
<system:String x:Key="plugin_explorer_boost_home_folder_score">Prioritize home folders (Documents, Desktop, Downloads, etc.) in search results</system:String>
<system:String x:Key="plugin_explorer_usewindowsindexfordirectorysearch">Use Index Search For Path Search</system:String>
<system:String x:Key="plugin_explorer_manageindexoptions">Indexing Options</system:String>
<system:String x:Key="plugin_explorer_actionkeywordview_search">Search:</system:String>
Expand Down
45 changes: 45 additions & 0 deletions Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -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<HashSet<string>> HomeFolderPaths = new(() =>
{
var paths = new HashSet<string>(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))
Comment thread
jjw24 marked this conversation as resolved.
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"));
Comment thread
Jack251970 marked this conversation as resolved.
Comment thread
Jack251970 marked this conversation as resolved.

Comment thread
Jack251970 marked this conversation as resolved.
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));
Comment thread
Jack251970 marked this conversation as resolved.
}

public static void Init(PluginInitContext context, Settings settings)
{
Context = context;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
44 changes: 27 additions & 17 deletions Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
Expand Down Expand Up @@ -234,16 +235,25 @@
Content="{DynamicResource plugin_explorer_display_more_info_in_tooltip}"
IsChecked="{Binding Settings.DisplayMoreInformationInToolTip}" />

<TextBlock
<CheckBox
Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
HorizontalAlignment="Left"
Content="{DynamicResource plugin_explorer_boost_home_folder_score}"
IsChecked="{Binding Settings.BoostHomeFolderScore}" />

<TextBlock
Grid.Row="4"
Grid.Column="0"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Foreground="{DynamicResource Color05B}"
Text="{DynamicResource plugin_explorer_file_editor_path}" />
<StackPanel
Grid.Row="3"
Grid.Row="4"
Grid.Column="1"
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
Orientation="Horizontal">
Expand All @@ -262,15 +272,15 @@
</StackPanel>

<TextBlock
Grid.Row="4"
Grid.Row="5"
Grid.Column="0"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Foreground="{DynamicResource Color05B}"
Text="{DynamicResource plugin_explorer_folder_editor_path}" />
<StackPanel
Grid.Row="4"
Grid.Row="5"
Grid.Column="1"
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
Orientation="Horizontal">
Expand All @@ -289,15 +299,15 @@
</StackPanel>

<TextBlock
Grid.Row="5"
Grid.Row="6"
Grid.Column="0"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Foreground="{DynamicResource Color05B}"
Text="{DynamicResource plugin_explorer_shell_path}" />
<StackPanel
Grid.Row="5"
Grid.Row="6"
Grid.Column="1"
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
Orientation="Horizontal">
Expand All @@ -316,14 +326,14 @@
</StackPanel>

<TextBlock
Grid.Row="6"
Grid.Row="7"
Grid.Column="0"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
VerticalAlignment="Center"
Foreground="{DynamicResource Color05B}"
Text="{DynamicResource plugin_explorer_Index_Search_Engine}" />
<ComboBox
Grid.Row="6"
Grid.Row="7"
Grid.Column="1"
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
HorizontalAlignment="Left"
Expand All @@ -333,14 +343,14 @@
SelectedItem="{Binding SelectedIndexSearchEngine}" />

<TextBlock
Grid.Row="7"
Grid.Row="8"
Grid.Column="0"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
VerticalAlignment="Center"
Foreground="{DynamicResource Color05B}"
Text="{DynamicResource plugin_explorer_Content_Search_Engine}" />
<ComboBox
Grid.Row="7"
Grid.Row="8"
Grid.Column="1"
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
HorizontalAlignment="Left"
Expand All @@ -350,14 +360,14 @@
SelectedItem="{Binding SelectedContentSearchEngine}" />

<TextBlock
Grid.Row="8"
Grid.Row="9"
Grid.Column="0"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
VerticalAlignment="Center"
Foreground="{DynamicResource Color05B}"
Text="{DynamicResource plugin_explorer_Directory_Recursive_Search_Engine}" />
<ComboBox
Grid.Row="8"
Grid.Row="9"
Grid.Column="1"
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
HorizontalAlignment="Left"
Expand All @@ -367,14 +377,14 @@
SelectedItem="{Binding SelectedPathEnumerationEngine}" />

<TextBlock
Grid.Row="9"
Grid.Row="10"
Grid.Column="0"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
VerticalAlignment="Center"
Foreground="{DynamicResource Color05B}"
Text="{DynamicResource plugin_explorer_Excluded_File_Types}" />
<TextBox
Grid.Row="9"
Grid.Row="10"
Grid.Column="1"
MinWidth="{StaticResource SettingPanelTextBoxMinWidth}"
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
Expand All @@ -383,14 +393,14 @@
ToolTip="{DynamicResource plugin_explorer_Excluded_File_Types_Tooltip}" />

<TextBlock
Grid.Row="10"
Grid.Row="11"
Grid.Column="0"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
VerticalAlignment="Center"
Foreground="{DynamicResource Color05B}"
Text="{DynamicResource plugin_explorer_Maximum_Results}" />
<TextBox
Grid.Row="10"
Grid.Row="11"
Grid.Column="1"
MinWidth="{StaticResource SettingPanelTextBoxMinWidth}"
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
Expand All @@ -402,7 +412,7 @@
ToolTip="{DynamicResource plugin_explorer_Maximum_Results_Tooltip}" />

<Button
Grid.Row="11"
Grid.Row="12"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
Expand Down
Loading