Skip to content

Commit efdfd06

Browse files
committed
Merge branch 'AcronymFuzzy' of github.com:taooceros/Flow.Launcher into AcronymFuzzy
2 parents 58b717c + d81db91 commit efdfd06

File tree

27 files changed

+259
-146
lines changed

27 files changed

+259
-146
lines changed

Flow.Launcher.Infrastructure/PinyinAlphabet.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Text;
66
using JetBrains.Annotations;
77
using Flow.Launcher.Infrastructure.UserSettings;
8-
using Microsoft.AspNetCore.Localization;
98
using ToolGood.Words.Pinyin;
109

1110
namespace Flow.Launcher.Infrastructure
@@ -46,7 +45,6 @@ public int MapToOriginalIndex(int translatedIndex)
4645

4746
int count = 0;
4847

49-
5048
// Corner case handle
5149
if (translatedIndex < translatedIndexs[0])
5250
return translatedIndex;
@@ -114,7 +112,6 @@ public class PinyinAlphabet : IAlphabet
114112
private ConcurrentDictionary<string, (string translation, TranslationMapping map)> _pinyinCache =
115113
new ConcurrentDictionary<string, (string translation, TranslationMapping map)>();
116114

117-
118115
private Settings _settings;
119116

120117
public void Initialize([NotNull] Settings settings)

Flow.Launcher.Infrastructure/StringMatcher.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,17 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
6060
return new MatchResult(false, UserSettingSearchPrecision);
6161

6262
query = query.Trim();
63-
TranslationMapping map;
64-
(stringToCompare, map) = _alphabet?.Translate(stringToCompare) ?? (stringToCompare, null);
63+
TranslationMapping translationMapping;
64+
(stringToCompare, translationMapping) = _alphabet?.Translate(stringToCompare) ?? (stringToCompare, null);
6565

6666
var currentAcronymQueryIndex = 0;
6767
var acronymMatchData = new List<int>();
68-
var queryWithoutCase = opt.IgnoreCase ? query.ToLower() : query;
6968

7069
// preset acronymScore
7170
int acronymScore = 100;
7271

7372
var fullStringToCompareWithoutCase = opt.IgnoreCase ? stringToCompare.ToLower() : stringToCompare;
74-
73+
var queryWithoutCase = opt.IgnoreCase ? query.ToLower() : query;
7574

7675
var querySubstrings = queryWithoutCase.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);
7776
int currentQuerySubstringIndex = 0;
@@ -90,21 +89,16 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
9089

9190
bool spaceMet = false;
9291

93-
for (var compareStringIndex = 0;
94-
compareStringIndex < fullStringToCompareWithoutCase.Length;
95-
compareStringIndex++)
92+
for (var compareStringIndex = 0; compareStringIndex < fullStringToCompareWithoutCase.Length; compareStringIndex++)
9693
{
9794
if (currentAcronymQueryIndex >= queryWithoutCase.Length
9895
|| allQuerySubstringsMatched && acronymScore < (int) UserSettingSearchPrecision)
9996
break;
10097

101-
10298
// To maintain a list of indices which correspond to spaces in the string to compare
10399
// To populate the list only for the first query substring
104100
if (fullStringToCompareWithoutCase[compareStringIndex] == ' ' && currentQuerySubstringIndex == 0)
105-
{
106101
spaceIndices.Add(compareStringIndex);
107-
}
108102

109103
// Acronym check
110104
if (char.IsUpper(stringToCompare[compareStringIndex]) ||
@@ -153,7 +147,6 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
153147
continue;
154148
}
155149

156-
157150
if (firstMatchIndex < 0)
158151
{
159152
// first matched char will become the start of the compared string
@@ -214,7 +207,7 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
214207
// return acronym Match if possible
215208
if (acronymMatchData.Count == query.Length && acronymScore >= (int) UserSettingSearchPrecision)
216209
{
217-
acronymMatchData = acronymMatchData.Select(x => map?.MapToOriginalIndex(x) ?? x).Distinct().ToList();
210+
acronymMatchData = acronymMatchData.Select(x => translationMapping?.MapToOriginalIndex(x) ?? x).Distinct().ToList();
218211
return new MatchResult(true, UserSettingSearchPrecision, acronymMatchData, acronymScore);
219212
}
220213

@@ -225,7 +218,7 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
225218
var score = CalculateSearchScore(query, stringToCompare, firstMatchIndex - nearestSpaceIndex - 1,
226219
lastMatchIndex - firstMatchIndex, allSubstringsContainedInCompareString);
227220

228-
var resultList = indexList.Select(x => map?.MapToOriginalIndex(x) ?? x).Distinct().ToList();
221+
var resultList = indexList.Select(x => translationMapping?.MapToOriginalIndex(x) ?? x).Distinct().ToList();
229222
return new MatchResult(true, UserSettingSearchPrecision, resultList, score);
230223
}
231224

@@ -328,4 +321,4 @@ public class MatchOption
328321
{
329322
public bool IgnoreCase { get; set; } = true;
330323
}
331-
}
324+
}

Flow.Launcher.Test/FuzzyMatcherTest.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public List<int> GetPrecisionScores()
4141
Enum.GetValues(typeof(SearchPrecisionScore))
4242
.Cast<SearchPrecisionScore>()
4343
.ToList()
44-
.ForEach(x => listToReturn.Add((int) x));
44+
.ForEach(x => listToReturn.Add((int)x));
4545

4646
return listToReturn;
4747
}
@@ -183,7 +183,7 @@ public void WhenGivenDesiredPrecision_ThenShouldReturn_AllResultsGreaterOrEqual(
183183
$"Query:{queryString}{Environment.NewLine} " +
184184
$"Compare:{compareString}{Environment.NewLine}" +
185185
$"Raw Score: {matchResult.RawScore}{Environment.NewLine}" +
186-
$"Precision Score: {(int) expectedPrecisionScore}");
186+
$"Precision Score: {(int)expectedPrecisionScore}");
187187
}
188188

189189
[TestCase("exce", "OverLeaf-Latex: An online LaTeX editor", SearchPrecisionScore.Regular, false)]
@@ -241,7 +241,7 @@ public void WhenGivenQuery_ShouldReturnResults_ContainingAllQuerySubstrings(
241241
$"Query:{queryString}{Environment.NewLine} " +
242242
$"Compare:{compareString}{Environment.NewLine}" +
243243
$"Raw Score: {matchResult.RawScore}{Environment.NewLine}" +
244-
$"Precision Score: {(int) expectedPrecisionScore}");
244+
$"Precision Score: {(int)expectedPrecisionScore}");
245245
}
246246

247247
[TestCase("man", "Task Manager", "eManual")]
@@ -309,7 +309,6 @@ public void WhenMultipleResults_ExactMatchingResult_ShouldHaveGreatestScore(
309309
[TestCase("vsp","Visual Studio Preview",100)]
310310
[TestCase("vsp","Visual Studio",0)]
311311
[TestCase("pc","Postman Canary",100)]
312-
313312
public void WhenGivenAnAcronymQuery_ShouldReturnAcronymScore(string queryString, string compareString,
314313
int desiredScore)
315314
{
@@ -322,4 +321,4 @@ public void WhenGivenAnAcronymQuery_ShouldReturnAcronymScore(string queryString,
322321
Desired Score: {desiredScore}");
323322
}
324323
}
325-
}
324+
}

Flow.Launcher/Languages/sk.xaml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<!--Setting General-->
1818
<system:String x:Key="flowlauncher_settings">Nastavenia Flow Launchera</system:String>
1919
<system:String x:Key="general">Všeobecné</system:String>
20+
<system:String x:Key="portableMode">Prenosný režim</system:String>
2021
<system:String x:Key="startFlowLauncherOnSystemStartup">Spustiť Flow Launcher po štarte systému</system:String>
2122
<system:String x:Key="hideFlowLauncherWhenLoseFocus">Schovať Flow Launcher po strate fokusu</system:String>
2223
<system:String x:Key="dontPromptUpdateMsg">Nezobrazovať upozornenia na novú verziu</system:String>
@@ -39,10 +40,13 @@
3940
<!--Setting Plugin-->
4041
<system:String x:Key="plugin">Plugin</system:String>
4142
<system:String x:Key="browserMorePlugins">Nájsť ďalšie pluginy</system:String>
43+
<system:String x:Key="enable">Povoliť</system:String>
4244
<system:String x:Key="disable">Zakázať</system:String>
4345
<system:String x:Key="actionKeywords">Skratka akcie</system:String>
4446
<system:String x:Key="currentActionKeywords">Aktuálna akcia skratky:</system:String>
4547
<system:String x:Key="newActionKeyword">Nová akcia skratky:</system:String>
48+
<system:String x:Key="currentPriority">Aktuálna priorita:</system:String>
49+
<system:String x:Key="newPriority">Nová priorita:</system:String>
4650
<system:String x:Key="pluginDirectory">Priečinok s pluginmi</system:String>
4751
<system:String x:Key="author">Autor</system:String>
4852
<system:String x:Key="plugin_init_time">Príprava:</system:String>
@@ -104,6 +108,10 @@
104108
</system:String>
105109
<system:String x:Key="releaseNotes">Poznámky k vydaniu</system:String>
106110

111+
<!--Priority Setting Dialog-->
112+
<system:String x:Key="priority_tips">Vyššie číslo znamená, že výsledok bude vyššie. Skúste nastaviť napr. 5. Ak chcete, aby boli výsledky nižšie ako ktorékoľvek iné doplnky, zadajte záporné číslo</system:String>
113+
<system:String x:Key="invalidPriority">Prosím, zadajte platné číslo pre prioritu!</system:String>
114+
107115
<!--Action Keyword Setting Dialog-->
108116
<system:String x:Key="oldActionKeywords">Stará skratka akcie</system:String>
109117
<system:String x:Key="newActionKeywords">Nová skratka akcie</system:String>
@@ -116,6 +124,7 @@
116124
<system:String x:Key="actionkeyword_tips">Použite * ak nechcete určiť skratku pre akciu</system:String>
117125

118126
<!--Custom Query Hotkey Dialog-->
127+
<system:String x:Key="customeQueryHotkeyTitle">Vlastná klávesová skratka pre plugin</system:String>
119128
<system:String x:Key="preview">Náhľad</system:String>
120129
<system:String x:Key="hotkeyIsNotUnavailable">Klávesová skratka je nedostupná, prosím, zadajte novú</system:String>
121130
<system:String x:Key="invalidPluginHotkey">Neplatná klávesová skratka pluginu</system:String>
@@ -140,11 +149,23 @@
140149
<system:String x:Key="reportWindow_report_failed">Odoslanie hlásenia zlyhalo</system:String>
141150
<system:String x:Key="reportWindow_flowlauncher_got_an_error">Flow Launcher zaznamenal chybu</system:String>
142151

152+
<!--General Notice-->
153+
<system:String x:Key="pleaseWait">Čakajte, prosím…</system:String>
154+
143155
<!--update-->
144-
<system:String x:Key="update_flowlauncher_update_new_version_available">Je dostupná nová verzia Flow Launcher {0}</system:String>
156+
<system:String x:Key="update_flowlauncher_update_check">Kontrolujú sa akutalizácie</system:String>
157+
<system:String x:Key="update_flowlauncher_already_on_latest">Už máte najnovšiu verizu Flow Launchera</system:String>
158+
<system:String x:Key="update_flowlauncher_update_found">Bola nájdená aktualizácia</system:String>
159+
<system:String x:Key="update_flowlauncher_updating">Aktualizuje sa…</system:String>
160+
<system:String x:Key="update_flowlauncher_fail_moving_portable_user_profile_data">Flow Launcher nedokázal presunúť používateľské údaje do aktualizovanej verzie.
161+
Prosím, presuňte profilový priečinok „data“ z {0} do {1}</system:String>
162+
<system:String x:Key="update_flowlauncher_new_update">Nová aktualizácia</system:String>
163+
<system:String x:Key="update_flowlauncher_update_new_version_available">Je dostupná nová verzia Flow Launchera {0}</system:String>
145164
<system:String x:Key="update_flowlauncher_update_error">Počas inštalácie aktualizácií došlo k chybe</system:String>
146165
<system:String x:Key="update_flowlauncher_update">Aktualizovať</system:String>
147166
<system:String x:Key="update_flowlauncher_update_cancel">Zrušiť</system:String>
167+
<system:String x:Key="update_flowlauncher_fail">Aktualizácia zlyhala</system:String>
168+
<system:String x:Key="update_flowlauncher_check_connection">Skontrolujte pripojenie a skúste aktualizovať nastavenia servera proxy na github-cloud.s3.amazonaws.com.</system:String>
148169
<system:String x:Key="update_flowlauncher_update_restart_flowlauncher_tip">Tento upgrade reštartuje Flow Launcher</system:String>
149170
<system:String x:Key="update_flowlauncher_update_upadte_files">Nasledujúce súbory budú aktualizované</system:String>
150171
<system:String x:Key="update_flowlauncher_update_files">Aktualizovať súbory</system:String>

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
using Flow.Launcher.Plugin.SharedCommands;
2020
using Flow.Launcher.Storage;
2121
using Flow.Launcher.Infrastructure.Logger;
22-
using System.Threading.Tasks.Dataflow;
2322

2423
namespace Flow.Launcher.ViewModel
2524
{

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

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
using Flow.Launcher.Infrastructure.Logger;
88
using Flow.Launcher.Plugin.SharedCommands;
99
using Flow.Launcher.Plugin.Explorer.Search;
10-
using Flow.Launcher.Plugin.Explorer.Search.FolderLinks;
10+
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
1111
using System.Linq;
1212
using MessageBox = System.Windows.Forms.MessageBox;
1313
using MessageBoxIcon = System.Windows.Forms.MessageBoxIcon;
1414
using MessageBoxButton = System.Windows.Forms.MessageBoxButtons;
1515
using DialogResult = System.Windows.Forms.DialogResult;
16+
using Flow.Launcher.Plugin.Explorer.ViewModels;
1617

1718
namespace Flow.Launcher.Plugin.Explorer
1819
{
@@ -22,10 +23,13 @@ internal class ContextMenu : IContextMenu
2223

2324
private Settings Settings { get; set; }
2425

25-
public ContextMenu(PluginInitContext context, Settings settings)
26+
private SettingsViewModel ViewModel { get; set; }
27+
28+
public ContextMenu(PluginInitContext context, Settings settings, SettingsViewModel vm)
2629
{
2730
Context = context;
2831
Settings = settings;
32+
ViewModel = vm;
2933
}
3034

3135
public List<Result> LoadContextMenus(Result selectedResult)
@@ -50,6 +54,58 @@ public List<Result> LoadContextMenus(Result selectedResult)
5054

5155
var icoPath = (record.Type == ResultType.File) ? Constants.FileImagePath : Constants.FolderImagePath;
5256
var fileOrFolder = (record.Type == ResultType.File) ? "file" : "folder";
57+
58+
if (!Settings.QuickAccessLinks.Any(x => x.Path == record.FullPath))
59+
{
60+
contextMenus.Add(new Result
61+
{
62+
Title = Context.API.GetTranslation("plugin_explorer_add_to_quickaccess_title"),
63+
SubTitle = string.Format(Context.API.GetTranslation("plugin_explorer_add_to_quickaccess_subtitle"), fileOrFolder),
64+
Action = (context) =>
65+
{
66+
Settings.QuickAccessLinks.Add(new AccessLink { Path = record.FullPath, Type = record.Type });
67+
68+
Context.API.ShowMsg(Context.API.GetTranslation("plugin_explorer_addfilefoldersuccess"),
69+
string.Format(
70+
Context.API.GetTranslation("plugin_explorer_addfilefoldersuccess_detail"),
71+
fileOrFolder),
72+
Constants.ExplorerIconImageFullPath);
73+
74+
ViewModel.Save();
75+
76+
return true;
77+
},
78+
SubTitleToolTip = Context.API.GetTranslation("plugin_explorer_contextmenu_titletooltip"),
79+
TitleToolTip = Context.API.GetTranslation("plugin_explorer_contextmenu_titletooltip"),
80+
IcoPath = Constants.QuickAccessImagePath
81+
});
82+
}
83+
else
84+
{
85+
contextMenus.Add(new Result
86+
{
87+
Title = Context.API.GetTranslation("plugin_explorer_remove_from_quickaccess_title"),
88+
SubTitle = string.Format(Context.API.GetTranslation("plugin_explorer_remove_from_quickaccess_subtitle"), fileOrFolder),
89+
Action = (context) =>
90+
{
91+
Settings.QuickAccessLinks.Remove(Settings.QuickAccessLinks.FirstOrDefault(x => x.Path == record.FullPath));
92+
93+
Context.API.ShowMsg(Context.API.GetTranslation("plugin_explorer_removefilefoldersuccess"),
94+
string.Format(
95+
Context.API.GetTranslation("plugin_explorer_removefilefoldersuccess_detail"),
96+
fileOrFolder),
97+
Constants.ExplorerIconImageFullPath);
98+
99+
ViewModel.Save();
100+
101+
return true;
102+
},
103+
SubTitleToolTip = Context.API.GetTranslation("plugin_explorer_contextmenu_remove_titletooltip"),
104+
TitleToolTip = Context.API.GetTranslation("plugin_explorer_contextmenu_remove_titletooltip"),
105+
IcoPath = Constants.RemoveQuickAccessImagePath
106+
});
107+
}
108+
53109
contextMenus.Add(new Result
54110
{
55111
Title = Context.API.GetTranslation("plugin_explorer_copypath"),
@@ -228,7 +284,7 @@ private Result CreateAddToIndexSearchExclusionListResult(SearchResult record)
228284
Action = _ =>
229285
{
230286
if(!Settings.IndexSearchExcludedSubdirectoryPaths.Any(x => x.Path == record.FullPath))
231-
Settings.IndexSearchExcludedSubdirectoryPaths.Add(new FolderLink { Path = record.FullPath });
287+
Settings.IndexSearchExcludedSubdirectoryPaths.Add(new AccessLink { Path = record.FullPath });
232288

233289
Task.Run(() =>
234290
{
42.8 KB
Loading
11.3 KB
Loading

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<system:String x:Key="plugin_explorer_edit">Edit</system:String>
1717
<system:String x:Key="plugin_explorer_add">Add</system:String>
1818
<system:String x:Key="plugin_explorer_manageactionkeywords_header">Customise Action Keywords</system:String>
19-
<system:String x:Key="plugin_explorer_quickfolderaccess_header">Quick Folder Access Paths</system:String>
19+
<system:String x:Key="plugin_explorer_quickaccesslinks_header">Quick Access Links</system:String>
2020
<system:String x:Key="plugin_explorer_indexsearchexcludedpaths_header">Index Search Excluded Paths</system:String>
2121
<system:String x:Key="plugin_explorer_manageindexoptions">Indexing Options</system:String>
2222
<system:String x:Key="plugin_explorer_actionkeywordview_search">Search Activation:</system:String>
@@ -42,5 +42,15 @@
4242
<system:String x:Key="plugin_explorer_openindexingoptions">Open Windows Indexing Options</system:String>
4343
<system:String x:Key="plugin_explorer_openindexingoptions_subtitle">Manage indexed files and folders</system:String>
4444
<system:String x:Key="plugin_explorer_openindexingoptions_errormsg">Failed to open Windows Indexing Options</system:String>
45+
<system:String x:Key="plugin_explorer_add_to_quickaccess_title">Add to Quick Access</system:String>
46+
<system:String x:Key="plugin_explorer_add_to_quickaccess_subtitle">Add the current {0} to Quick Access</system:String>
47+
<system:String x:Key="plugin_explorer_addfilefoldersuccess">Successfully Added</system:String>
48+
<system:String x:Key="plugin_explorer_addfilefoldersuccess_detail">Successfully added to Quick Access</system:String>
49+
<system:String x:Key="plugin_explorer_removefilefoldersuccess">Successfully Removed</system:String>
50+
<system:String x:Key="plugin_explorer_removefilefoldersuccess_detail">Successfully removed from Quick Access</system:String>
51+
<system:String x:Key="plugin_explorer_contextmenu_titletooltip">Add to Quick Access so it can be opened with Explorer's Search Activation action keyword</system:String>
52+
<system:String x:Key="plugin_explorer_contextmenu_remove_titletooltip">Remove from Quick Access</system:String>
53+
<system:String x:Key="plugin_explorer_remove_from_quickaccess_title">Remove from Quick Access</system:String>
54+
<system:String x:Key="plugin_explorer_remove_from_quickaccess_subtitle">Remove the current {0} from Quick Access</system:String>
4555

4656
</ResourceDictionary>

0 commit comments

Comments
 (0)