Skip to content

Commit 69bca5d

Browse files
authored
Merge branch 'dev' into DragandDrop
2 parents 9ca67ac + 14c137a commit 69bca5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2411
-701
lines changed

Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Flow.Launcher.Core.ExternalPlugins
1+
using System;
2+
3+
namespace Flow.Launcher.Core.ExternalPlugins
24
{
35
public record UserPlugin
46
{
@@ -12,5 +14,8 @@ public record UserPlugin
1214
public string UrlDownload { get; set; }
1315
public string UrlSourceCode { get; set; }
1416
public string IcoPath { get; set; }
17+
public DateTime LatestReleaseDate { get; set; }
18+
public DateTime DateAdded { get; set; }
19+
1520
}
1621
}

Flow.Launcher.Infrastructure/StringMatcher.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
202202
if (allQuerySubstringsMatched)
203203
{
204204
var nearestSpaceIndex = CalculateClosestSpaceIndex(spaceIndices, firstMatchIndex);
205-
var score = CalculateSearchScore(query, stringToCompare, firstMatchIndex - nearestSpaceIndex - 1,
205+
206+
// firstMatchIndex - nearestSpaceIndex - 1 is to set the firstIndex as the index of the first matched char
207+
// preceded by a space e.g. 'world' matching 'hello world' firstIndex would be 0 not 6
208+
// giving more weight than 'we or donald' by allowing the distance calculation to treat the starting position at after the space.
209+
var score = CalculateSearchScore(query, stringToCompare, firstMatchIndex - nearestSpaceIndex - 1, spaceIndices,
206210
lastMatchIndex - firstMatchIndex, allSubstringsContainedInCompareString);
207211

208212
var resultList = indexList.Select(x => translationMapping?.MapToOriginalIndex(x) ?? x).Distinct().ToList();
@@ -296,14 +300,22 @@ private static bool AllQuerySubstringsMatched(int currentQuerySubstringIndex, in
296300
return currentQuerySubstringIndex >= querySubstringsLength;
297301
}
298302

299-
private static int CalculateSearchScore(string query, string stringToCompare, int firstIndex, int matchLen,
303+
private static int CalculateSearchScore(string query, string stringToCompare, int firstIndex, List<int> spaceIndices, int matchLen,
300304
bool allSubstringsContainedInCompareString)
301305
{
302306
// A match found near the beginning of a string is scored more than a match found near the end
303307
// A match is scored more if the characters in the patterns are closer to each other,
304308
// while the score is lower if they are more spread out
305309
var score = 100 * (query.Length + 1) / ((1 + firstIndex) + (matchLen + 1));
306310

311+
// Give more weight to a match that is closer to the start of the string.
312+
// if the first matched char is immediately before space and all strings are contained in the compare string e.g. 'world' matching 'hello world'
313+
// and 'world hello', because both have 'world' immediately preceded by space, their firstIndex will be 0 when distance is calculated,
314+
// to prevent them scoring the same, we adjust the score by deducting the number of spaces it has from the start of the string, so 'world hello'
315+
// will score slightly higher than 'hello world' because 'hello world' has one additional space.
316+
if (firstIndex == 0 && allSubstringsContainedInCompareString)
317+
score -= spaceIndices.Count;
318+
307319
// A match with less characters assigning more weights
308320
if (stringToCompare.Length - query.Length < 5)
309321
{

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public string Language
4141
public bool UseGlyphIcons { get; set; } = true;
4242
public bool UseAnimation { get; set; } = true;
4343
public bool UseSound { get; set; } = true;
44+
public bool UseClock { get; set; } = true;
45+
public bool UseDate { get; set; } = false;
46+
public string TimeFormat { get; set; } = "hh:mm tt";
47+
public string DateFormat { get; set; } = "MM'/'dd ddd";
4448
public bool FirstLaunch { get; set; } = true;
4549

4650
public double SettingWindowWidth { get; set; } = 1000;
@@ -199,7 +203,7 @@ public bool HideNotifyIcon
199203
}
200204
public bool LeaveCmdOpen { get; set; }
201205
public bool HideWhenDeactive { get; set; } = true;
202-
public bool RememberLastLaunchLocation { get; set; }
206+
public SearchWindowPositions SearchWindowPosition { get; set; } = SearchWindowPositions.MouseScreenCenter;
203207
public bool IgnoreHotkeysOnFullscreen { get; set; }
204208

205209
public HttpProxy Proxy { get; set; } = new HttpProxy();
@@ -225,4 +229,12 @@ public enum ColorSchemes
225229
Light,
226230
Dark
227231
}
232+
public enum SearchWindowPositions
233+
{
234+
RememberLastLaunchLocation,
235+
MouseScreenCenter,
236+
MouseScreenCenterTop,
237+
MouseScreenLeftTop,
238+
MouseScreenRightTop
239+
}
228240
}

Flow.Launcher.Test/FuzzyMatcherTest.cs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,20 @@ public void GivenQueryString_WhenAppliedPrecisionFiltering_ThenShouldReturnGreat
129129
}
130130
}
131131

132+
133+
/// <summary>
134+
/// These are standard match scenarios
135+
/// The intention of this test is provide a bench mark for how much the score has increased from a change.
136+
/// Usually the increase in scoring should not be drastic, increase of less than 10 is acceptable.
137+
/// </summary>
132138
[TestCase(Chrome, Chrome, 157)]
133-
[TestCase(Chrome, LastIsChrome, 147)]
139+
[TestCase(Chrome, LastIsChrome, 145)]
134140
[TestCase("chro", HelpCureHopeRaiseOnMindEntityChrome, 50)]
135141
[TestCase("chr", HelpCureHopeRaiseOnMindEntityChrome, 30)]
136142
[TestCase(Chrome, UninstallOrChangeProgramsOnYourComputer, 21)]
137143
[TestCase(Chrome, CandyCrushSagaFromKing, 0)]
138-
[TestCase("sql", MicrosoftSqlServerManagementStudio, 110)]
139-
[TestCase("sql manag", MicrosoftSqlServerManagementStudio, 121)] //double spacing intended
144+
[TestCase("sql", MicrosoftSqlServerManagementStudio, 109)]
145+
[TestCase("sql manag", MicrosoftSqlServerManagementStudio, 120)] //double spacing intended
140146
public void WhenGivenQueryString_ThenShouldReturn_TheDesiredScoring(
141147
string queryString, string compareString, int expectedScore)
142148
{
@@ -275,7 +281,40 @@ public void WhenGivenAQuery_Scoring_ShouldGiveMoreWeightToStartOfNewWord(
275281
$"Query: \"{queryString}\"{Environment.NewLine} " +
276282
$"CompareString1: \"{compareString1}\", Score: {compareString1Result.Score}{Environment.NewLine}" +
277283
$"Should be greater than{Environment.NewLine}" +
278-
$"CompareString2: \"{compareString2}\", Score: {compareString1Result.Score}{Environment.NewLine}");
284+
$"CompareString2: \"{compareString2}\", Score: {compareString2Result.Score}{Environment.NewLine}");
285+
}
286+
287+
[TestCase("red", "red colour", "metro red")]
288+
[TestCase("red", "this red colour", "this colour red")]
289+
[TestCase("red", "this red colour", "this colour is very red")]
290+
[TestCase("red", "this red colour", "this colour is surprisingly super awesome red and cool")]
291+
[TestCase("red", "this colour is surprisingly super red very and cool", "this colour is surprisingly super very red and cool")]
292+
public void WhenGivenTwoStrings_Scoring_ShouldGiveMoreWeightToTheStringCloserToIndexZero(
293+
string queryString, string compareString1, string compareString2)
294+
{
295+
// When
296+
var matcher = new StringMatcher { UserSettingSearchPrecision = SearchPrecisionScore.Regular };
297+
298+
// Given
299+
var compareString1Result = matcher.FuzzyMatch(queryString, compareString1);
300+
var compareString2Result = matcher.FuzzyMatch(queryString, compareString2);
301+
302+
Debug.WriteLine("");
303+
Debug.WriteLine("###############################################");
304+
Debug.WriteLine($"QueryString: \"{queryString}\"{Environment.NewLine}");
305+
Debug.WriteLine(
306+
$"CompareString1: \"{compareString1}\", Score: {compareString1Result.Score}{Environment.NewLine}");
307+
Debug.WriteLine(
308+
$"CompareString2: \"{compareString2}\", Score: {compareString2Result.Score}{Environment.NewLine}");
309+
Debug.WriteLine("###############################################");
310+
Debug.WriteLine("");
311+
312+
// Should
313+
Assert.True(compareString1Result.Score > compareString2Result.Score,
314+
$"Query: \"{queryString}\"{Environment.NewLine} " +
315+
$"CompareString1: \"{compareString1}\", Score: {compareString1Result.Score}{Environment.NewLine}" +
316+
$"Should be greater than{Environment.NewLine}" +
317+
$"CompareString2: \"{compareString2}\", Score: {compareString2Result.Score}{Environment.NewLine}");
279318
}
280319

281320
[TestCase("vim", "Vim", "ignoreDescription", "ignore.exe", "Vim Diff", "ignoreDescription", "ignore.exe")]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
using System.Windows.Controls;
9+
using System.Windows.Data;
10+
11+
namespace Flow.Launcher.Converters
12+
{
13+
public class BoolToVisibilityConverter : IValueConverter
14+
{
15+
public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
16+
{
17+
if (parameter != null)
18+
{
19+
if (value is true)
20+
{
21+
return Visibility.Collapsed;
22+
}
23+
24+
else
25+
{
26+
return Visibility.Visible;
27+
}
28+
}
29+
else {
30+
if (value is true)
31+
{
32+
return Visibility.Visible;
33+
}
34+
35+
else {
36+
return Visibility.Collapsed;
37+
}
38+
}
39+
}
40+
41+
public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture) => throw new System.InvalidOperationException();
42+
}
43+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
using Flow.Launcher.Core.Resource;
5+
using Flow.Launcher.ViewModel;
6+
7+
namespace Flow.Launcher.Converters
8+
{
9+
public class TextConverter : IValueConverter
10+
{
11+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
12+
{
13+
var ID = value.ToString();
14+
switch(ID)
15+
{
16+
case PluginStoreItemViewModel.NewRelease:
17+
return InternationalizationManager.Instance.GetTranslation("pluginStore_NewRelease");
18+
case PluginStoreItemViewModel.RecentlyUpdated:
19+
return InternationalizationManager.Instance.GetTranslation("pluginStore_RecentlyUpdated");
20+
case PluginStoreItemViewModel.None:
21+
return InternationalizationManager.Instance.GetTranslation("pluginStore_None");
22+
case PluginStoreItemViewModel.Installed:
23+
return InternationalizationManager.Instance.GetTranslation("pluginStore_Installed");
24+
default:
25+
return ID;
26+
}
27+
28+
}
29+
30+
public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture) => throw new System.InvalidOperationException();
31+
}
32+
}

Flow.Launcher/Helper/HotKeyMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal static class HotKeyMapper
1717
internal static void Initialize(MainViewModel mainVM)
1818
{
1919
mainViewModel = mainVM;
20-
settings = mainViewModel._settings;
20+
settings = mainViewModel.Settings;
2121

2222
SetHotkey(settings.Hotkey, OnToggleHotkey);
2323
LoadCustomPluginHotkey();

Flow.Launcher/Languages/da.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@
7777
<system:String x:Key="plugin_query_time">Søgetid:</system:String>
7878
<system:String x:Key="plugin_query_version">| Version</system:String>
7979
<system:String x:Key="plugin_query_web">Website</system:String>
80-
<system:String x:Key="plugin_uninstall">Uninstall</system:String>
80+
<system:String x:Key="uninstallbtn">Uninstall</system:String>
8181

8282

8383
<!-- Setting Plugin Store -->
8484
<system:String x:Key="pluginStore">Plugin Store</system:String>
8585
<system:String x:Key="refresh">Refresh</system:String>
86-
<system:String x:Key="install">Install</system:String>
86+
<system:String x:Key="installbtn">Install</system:String>
8787

8888
<!-- Setting Theme -->
8989
<system:String x:Key="theme">Tema</system:String>

Flow.Launcher/Languages/de.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@
7777
<system:String x:Key="plugin_query_time">Abfragezeit:</system:String>
7878
<system:String x:Key="plugin_query_version">Version</system:String>
7979
<system:String x:Key="plugin_query_web">Webseite</system:String>
80-
<system:String x:Key="plugin_uninstall">Deinstallieren</system:String>
80+
<system:String x:Key="uninstallbtn">Deinstallieren</system:String>
8181

8282

8383
<!-- Setting Plugin Store -->
8484
<system:String x:Key="pluginStore">Erweiterungen laden</system:String>
8585
<system:String x:Key="refresh">Aktualisieren</system:String>
86-
<system:String x:Key="install">Installieren</system:String>
86+
<system:String x:Key="installbtn">Installieren</system:String>
8787

8888
<!-- Setting Theme -->
8989
<system:String x:Key="theme">Design</system:String>

Flow.Launcher/Languages/en.xaml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
<system:String x:Key="textTitle">Text</system:String>
2424
<system:String x:Key="GameMode">Game Mode</system:String>
2525
<system:String x:Key="GameModeToolTip">Suspend the use of Hotkeys.</system:String>
26+
<system:String x:Key="PositionReset">Position Reset</system:String>
27+
<system:String x:Key="PositionResetToolTip">Reset search window position</system:String>
2628

2729
<!-- Setting General -->
2830
<system:String x:Key="flowlauncher_settings">Flow Launcher Settings</system:String>
@@ -33,7 +35,13 @@
3335
<system:String x:Key="setAutoStartFailed">Error setting launch on startup</system:String>
3436
<system:String x:Key="hideFlowLauncherWhenLoseFocus">Hide Flow Launcher when focus is lost</system:String>
3537
<system:String x:Key="dontPromptUpdateMsg">Do not show new version notifications</system:String>
38+
<system:String x:Key="SearchWindowPosition">Search Window Position</system:String>
3639
<system:String x:Key="rememberLastLocation">Remember last launch location</system:String>
40+
<system:String x:Key="SearchWindowPositionRememberLastLaunchLocation">Remember Last Location</system:String>
41+
<system:String x:Key="SearchWindowPositionMouseScreenCenter">Mouse Focused Screen - Center</system:String>
42+
<system:String x:Key="SearchWindowPositionMouseScreenCenterTop">Mouse Focused Screen - Center Top</system:String>
43+
<system:String x:Key="SearchWindowPositionMouseScreenLeftTop">Mouse Focused Screen - Left Top</system:String>
44+
<system:String x:Key="SearchWindowPositionMouseScreenRightTop">Mouse Focused Screen - Right Top</system:String>
3745
<system:String x:Key="language">Language</system:String>
3846
<system:String x:Key="lastQueryMode">Last Query Style</system:String>
3947
<system:String x:Key="lastQueryModeToolTip">Show/Hide previous results when Flow Launcher is reactivated.</system:String>
@@ -84,13 +92,24 @@
8492
<system:String x:Key="plugin_query_time">Query time:</system:String>
8593
<system:String x:Key="plugin_query_version">| Version</system:String>
8694
<system:String x:Key="plugin_query_web">Website</system:String>
87-
<system:String x:Key="plugin_uninstall">Uninstall</system:String>
8895

8996

9097
<!-- Setting Plugin Store -->
9198
<system:String x:Key="pluginStore">Plugin Store</system:String>
99+
<system:String x:Key="pluginStore_NewRelease">New Release</system:String>
100+
<system:String x:Key="pluginStore_RecentlyUpdated">Recently Updated</system:String>
101+
<system:String x:Key="pluginStore_None">Plugins</system:String>
102+
<system:String x:Key="pluginStore_Installed">Installed</system:String>
92103
<system:String x:Key="refresh">Refresh</system:String>
93-
<system:String x:Key="install">Install</system:String>
104+
<system:String x:Key="installbtn">Install</system:String>
105+
<system:String x:Key="uninstallbtn">Uninstall</system:String>
106+
<system:String x:Key="updatebtn">Update</system:String>
107+
<system:String x:Key="LabelInstalledToolTip">Plug-in already installed</system:String>
108+
<system:String x:Key="LabelNew">New Version</system:String>
109+
<system:String x:Key="LabelNewToolTip">This plug-in has been updated within the last 7 days</system:String>
110+
<system:String x:Key="LabelUpdateToolTip">New Update is Available</system:String>
111+
112+
94113

95114
<!-- Setting Theme -->
96115
<system:String x:Key="theme">Theme</system:String>
@@ -113,6 +132,8 @@
113132
<system:String x:Key="SoundEffectTip">Play a small sound when the search window opens</system:String>
114133
<system:String x:Key="Animation">Animation</system:String>
115134
<system:String x:Key="AnimationTip">Use Animation in UI</system:String>
135+
<system:String x:Key="Clock">Clock</system:String>
136+
<system:String x:Key="Date">Date</system:String>
116137

117138
<!-- Setting Hotkey -->
118139
<system:String x:Key="hotkey">Hotkey</system:String>

0 commit comments

Comments
 (0)