Skip to content

Commit 71938cd

Browse files
committed
Merge branch 'dev' of github.com:Flow-Launcher/Flow.Launcher into ProgressBarDispatcher
2 parents b3cdd6b + 16cc489 commit 71938cd

Some content is hidden

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

55 files changed

+3115
-28717
lines changed

Flow.Launcher.Infrastructure/Constant.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Diagnostics;
1+
using System.Diagnostics;
22
using System.IO;
33
using System.Reflection;
44

@@ -21,6 +21,7 @@ public static class Constant
2121
public static readonly string PreinstalledDirectory = Path.Combine(ProgramDirectory, Plugins);
2222
public const string Issue = "https://github.com/Flow-Launcher/Flow.Launcher/issues/new";
2323
public static readonly string Version = FileVersionInfo.GetVersionInfo(Assembly.Location.NonNull()).ProductVersion;
24+
public static readonly string Dev = "Dev";
2425
public const string Documentation = "https://flowlauncher.com/docs/#/usage-tips";
2526

2627
public static readonly int ThumbnailSize = 64;

Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,11 @@
5858
<PackageReference Include="NLog.Schema" Version="4.7.10" />
5959
<PackageReference Include="NLog.Web.AspNetCore" Version="4.13.0" />
6060
<PackageReference Include="PropertyChanged.Fody" Version="3.4.0" />
61-
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
61+
<PackageReference Include="System.Drawing.Common" Version="5.0.3" />
6262
<!--ToolGood.Words.Pinyin v3.0.2.6 results in high memory usage when search with pinyin is enabled-->
6363
<!--Bumping to it or higher needs to test and ensure this is no longer a problem-->
6464
<PackageReference Include="ToolGood.Words.Pinyin" Version="3.0.1.4" />
6565
</ItemGroup>
6666

67-
<ItemGroup>
68-
<None Update="pinyindb\pinyin_gwoyeu_mapping.xml">
69-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
70-
</None>
71-
<None Update="pinyindb\pinyin_mapping.xml">
72-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
73-
</None>
74-
<None Update="pinyindb\unicode_to_hanyu_pinyin.txt">
75-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
76-
</None>
77-
</ItemGroup>
7867

7968
</Project>

Flow.Launcher.Infrastructure/Logger/Log.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Diagnostics;
1+
using System.Diagnostics;
22
using System.IO;
33
using System.Runtime.CompilerServices;
44
using NLog;

Flow.Launcher.Infrastructure/PinyinAlphabet.cs

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class TranslationMapping
1515

1616
private List<int> originalIndexs = new List<int>();
1717
private List<int> translatedIndexs = new List<int>();
18-
private int translaedLength = 0;
18+
private int translatedLength = 0;
1919

2020
public string key { get; private set; }
2121

@@ -32,13 +32,13 @@ public void AddNewIndex(int originalIndex, int translatedIndex, int length)
3232
originalIndexs.Add(originalIndex);
3333
translatedIndexs.Add(translatedIndex);
3434
translatedIndexs.Add(translatedIndex + length);
35-
translaedLength += length - 1;
35+
translatedLength += length - 1;
3636
}
3737

3838
public int MapToOriginalIndex(int translatedIndex)
3939
{
4040
if (translatedIndex > translatedIndexs.Last())
41-
return translatedIndex - translaedLength - 1;
41+
return translatedIndex - translatedLength - 1;
4242

4343
int lowerBound = 0;
4444
int upperBound = originalIndexs.Count - 1;
@@ -83,7 +83,7 @@ public int MapToOriginalIndex(int translatedIndex)
8383
translatedIndex < translatedIndexs[upperBound * 2])
8484
{
8585
int indexDef = 0;
86-
86+
8787
for (int j = 0; j < upperBound; j++)
8888
{
8989
indexDef += translatedIndexs[j * 2 + 1] - translatedIndexs[j * 2];
@@ -102,9 +102,24 @@ public void endConstruct()
102102
}
103103
}
104104

105+
/// <summary>
106+
/// Translate a language to English letters using a given rule.
107+
/// </summary>
105108
public interface IAlphabet
106109
{
110+
/// <summary>
111+
/// Translate a string to English letters, using a given rule.
112+
/// </summary>
113+
/// <param name="stringToTranslate">String to translate.</param>
114+
/// <returns></returns>
107115
public (string translation, TranslationMapping map) Translate(string stringToTranslate);
116+
117+
/// <summary>
118+
/// Determine if a string can be translated to English letter with this Alphabet.
119+
/// </summary>
120+
/// <param name="stringToTranslate">String to translate.</param>
121+
/// <returns></returns>
122+
public bool CanBeTranslated(string stringToTranslate);
108123
}
109124

110125
public class PinyinAlphabet : IAlphabet
@@ -119,63 +134,70 @@ public void Initialize([NotNull] Settings settings)
119134
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
120135
}
121136

137+
public bool CanBeTranslated(string stringToTranslate)
138+
{
139+
return WordsHelper.HasChinese(stringToTranslate);
140+
}
141+
122142
public (string translation, TranslationMapping map) Translate(string content)
123143
{
124144
if (_settings.ShouldUsePinyin)
125145
{
126146
if (!_pinyinCache.ContainsKey(content))
127147
{
128-
if (WordsHelper.HasChinese(content))
129-
{
130-
var resultList = WordsHelper.GetPinyinList(content);
131-
132-
StringBuilder resultBuilder = new StringBuilder();
133-
TranslationMapping map = new TranslationMapping();
134-
135-
bool pre = false;
148+
return BuildCacheFromContent(content);
149+
}
150+
else
151+
{
152+
return _pinyinCache[content];
153+
}
154+
}
155+
return (content, null);
156+
}
136157

137-
for (int i = 0; i < resultList.Length; i++)
138-
{
139-
if (content[i] >= 0x3400 && content[i] <= 0x9FD5)
140-
{
141-
map.AddNewIndex(i, resultBuilder.Length, resultList[i].Length + 1);
142-
resultBuilder.Append(' ');
143-
resultBuilder.Append(resultList[i]);
144-
pre = true;
145-
}
146-
else
147-
{
148-
if (pre)
149-
{
150-
pre = false;
151-
resultBuilder.Append(' ');
152-
}
153-
154-
resultBuilder.Append(resultList[i]);
155-
}
156-
}
158+
private (string translation, TranslationMapping map) BuildCacheFromContent(string content)
159+
{
160+
if (WordsHelper.HasChinese(content))
161+
{
162+
var resultList = WordsHelper.GetPinyinList(content);
157163

158-
map.endConstruct();
164+
StringBuilder resultBuilder = new StringBuilder();
165+
TranslationMapping map = new TranslationMapping();
159166

160-
var key = resultBuilder.ToString();
161-
map.setKey(key);
167+
bool pre = false;
162168

163-
return _pinyinCache[content] = (key, map);
169+
for (int i = 0; i < resultList.Length; i++)
170+
{
171+
if (content[i] >= 0x3400 && content[i] <= 0x9FD5)
172+
{
173+
map.AddNewIndex(i, resultBuilder.Length, resultList[i].Length + 1);
174+
resultBuilder.Append(' ');
175+
resultBuilder.Append(resultList[i]);
176+
pre = true;
164177
}
165178
else
166179
{
167-
return (content, null);
180+
if (pre)
181+
{
182+
pre = false;
183+
resultBuilder.Append(' ');
184+
}
185+
186+
resultBuilder.Append(resultList[i]);
168187
}
169188
}
170-
else
171-
{
172-
return _pinyinCache[content];
173-
}
189+
190+
map.endConstruct();
191+
192+
var key = resultBuilder.ToString();
193+
map.setKey(key);
194+
195+
return _pinyinCache[content] = (key, map);
174196
}
175197
else
176198
{
177199
return (content, null);
178200
}
179201
}
180202
}
181-
}
203+
}

Flow.Launcher.Infrastructure/StringMatcher.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Flow.Launcher.Plugin.SharedModels;
1+
using Flow.Launcher.Plugin.SharedModels;
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;
@@ -60,8 +60,13 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
6060
return new MatchResult(false, UserSettingSearchPrecision);
6161

6262
query = query.Trim();
63-
TranslationMapping translationMapping;
64-
(stringToCompare, translationMapping) = _alphabet?.Translate(stringToCompare) ?? (stringToCompare, null);
63+
TranslationMapping translationMapping = null;
64+
if (_alphabet is not null && !_alphabet.CanBeTranslated(query))
65+
{
66+
// We assume that if a query can be translated (containing characters of a language, like Chinese)
67+
// it actually means user doesn't want it to be translated to English letters.
68+
(stringToCompare, translationMapping) = _alphabet.Translate(stringToCompare);
69+
}
6570

6671
var currentAcronymQueryIndex = 0;
6772
var acronymMatchData = new List<int>();
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Text.Json.Serialization;
3+
4+
namespace Flow.Launcher.Infrastructure.UserSettings
5+
{
6+
public abstract class ShortcutBaseModel
7+
{
8+
public string Key { get; set; }
9+
10+
[JsonIgnore]
11+
public Func<string> Expand { get; set; } = () => { return ""; };
12+
13+
public override bool Equals(object obj)
14+
{
15+
return obj is ShortcutBaseModel other &&
16+
Key == other.Key;
17+
}
18+
19+
public override int GetHashCode()
20+
{
21+
return Key.GetHashCode();
22+
}
23+
}
24+
25+
public class CustomShortcutModel : ShortcutBaseModel
26+
{
27+
public string Value { get; set; }
28+
29+
[JsonConstructorAttribute]
30+
public CustomShortcutModel(string key, string value)
31+
{
32+
Key = key;
33+
Value = value;
34+
Expand = () => { return Value; };
35+
}
36+
37+
public void Deconstruct(out string key, out string value)
38+
{
39+
key = Key;
40+
value = Value;
41+
}
42+
43+
public static implicit operator (string Key, string Value)(CustomShortcutModel shortcut)
44+
{
45+
return (shortcut.Key, shortcut.Value);
46+
}
47+
48+
public static implicit operator CustomShortcutModel((string Key, string Value) shortcut)
49+
{
50+
return new CustomShortcutModel(shortcut.Key, shortcut.Value);
51+
}
52+
}
53+
54+
public class BuiltinShortcutModel : ShortcutBaseModel
55+
{
56+
public string Description { get; set; }
57+
58+
public BuiltinShortcutModel(string key, string description, Func<string> expand)
59+
{
60+
Key = key;
61+
Description = description;
62+
Expand = expand ?? (() => { return ""; });
63+
}
64+
}
65+
}

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.ObjectModel;
44
using System.Drawing;
55
using System.Text.Json.Serialization;
6+
using System.Windows;
67
using Flow.Launcher.Plugin;
78
using Flow.Launcher.Plugin.SharedModels;
89
using Flow.Launcher;
@@ -51,6 +52,7 @@ public string Language
5152
public double SettingWindowHeight { get; set; } = 700;
5253
public double SettingWindowTop { get; set; }
5354
public double SettingWindowLeft { get; set; }
55+
public System.Windows.WindowState SettingWindowState { get; set; } = WindowState.Normal;
5456

5557
public int CustomExplorerIndex { get; set; } = 0;
5658

@@ -129,8 +131,7 @@ public CustomBrowserViewModel CustomBrowser
129131
PrivateArg = "-private",
130132
EnablePrivate = false,
131133
Editable = false
132-
}
133-
,
134+
},
134135
new()
135136
{
136137
Name = "MS Edge",
@@ -186,6 +187,13 @@ public string QuerySearchPrecisionString
186187

187188
public ObservableCollection<CustomPluginHotkey> CustomPluginHotkeys { get; set; } = new ObservableCollection<CustomPluginHotkey>();
188189

190+
public ObservableCollection<CustomShortcutModel> CustomShortcuts { get; set; } = new ObservableCollection<CustomShortcutModel>();
191+
192+
[JsonIgnore]
193+
public ObservableCollection<BuiltinShortcutModel> BuiltinShortcuts { get; set; } = new ObservableCollection<BuiltinShortcutModel>() {
194+
new BuiltinShortcutModel("{clipboard}", "shortcut_clipboard_description", Clipboard.GetText)
195+
};
196+
189197
public bool DontPromptUpdateMsg { get; set; }
190198
public bool EnableUpdateLog { get; set; }
191199

0 commit comments

Comments
 (0)