Skip to content

Commit 139fbd3

Browse files
committed
增加字典加载失败的提示; 现在内置字典使用相对路径加载, 避免版本升级后路径与已保存路径不一致导致的加载失败;
1 parent 09e6bd8 commit 139fbd3

File tree

4 files changed

+46
-11
lines changed

4 files changed

+46
-11
lines changed

src/ChinesePinyinIntelliSenseExtenderPackage.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Runtime.InteropServices;
22
using System.Threading;
3+
using System.Windows;
34

45
using ChinesePinyinIntelliSenseExtender.Options;
56
using ChinesePinyinIntelliSenseExtender.Util;
@@ -12,9 +13,9 @@
1213
namespace ChinesePinyinIntelliSenseExtender;
1314

1415
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
15-
[Guid(ChinesePinyinIntelliSenseExtenderPackage.PackageGuidString)]
16-
[ProvideOptionPage(typeof(OptionPages.General), "IntelliSense拼音补全", "常规", 0, 0, true)]
17-
[ProvideOptionPage(typeof(OptionPages.DictionaryManage), "IntelliSense拼音补全", "字典", 0, 0, true)]
16+
[Guid(PackageGuidString)]
17+
[ProvideOptionPage(typeof(OptionPages.General), PackageName, "常规", 0, 0, true)]
18+
[ProvideOptionPage(typeof(OptionPages.DictionaryManage), PackageName, "字典", 0, 0, true)]
1819
[ProvideAutoLoad(UIContextGuids80.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
1920
[ProvideAutoLoad(UIContextGuids80.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)]
2021
[ProvideAutoLoad(UIContextGuids80.SolutionHasMultipleProjects, PackageAutoLoadFlags.BackgroundLoad)]
@@ -28,6 +29,8 @@ public sealed class ChinesePinyinIntelliSenseExtenderPackage : AsyncPackage
2829
/// </summary>
2930
public const string PackageGuidString = "cd4393db-d533-4077-93da-9fdad98ddacf";
3031

32+
public const string PackageName = "IntelliSense拼音补全";
33+
3134
#endregion Public 字段
3235

3336
#region Package Members
@@ -38,8 +41,16 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
3841

3942
var options = await DictionaryManageOptions.GetLiveInstanceAsync(cancellationToken);
4043

41-
_ = InputMethodDictionaryGroupProvider.LoadFromOptionsAsync(options, cancellationToken);
44+
_ = InputMethodDictionaryGroupProvider.LoadFromOptionsAsync(options, cancellationToken).ContinueWith(task =>
45+
{
46+
if (task.Exception is not null)
47+
{
48+
var exception = task.Exception.InnerException?.ToString();
49+
cancellationToken.ThrowIfCancellationRequested();
50+
MessageBox.Show($"Load options failed with \"{exception}\"", PackageName, MessageBoxButton.OK, MessageBoxImage.Error);
51+
}
52+
}, cancellationToken, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Current);
4253
}
4354

4455
#endregion Package Members
45-
}
56+
}

src/Options/DictionaryManagePage.Designer.cs

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Options/DictionaryManagePage.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ private void ButtonAddDictionaryApplyCombination_Click(object sender, EventArgs
7373
}
7474
}
7575

76+
private void ButtonResetDictionaryApplyCombination_Click(object sender, EventArgs e)
77+
{
78+
if (MessageBox.Show("确定重置字典组合为默认值吗?", ChinesePinyinIntelliSenseExtenderPackage.PackageName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
79+
{
80+
Options.DictionaryCombinations.Clear();
81+
LoadDictionaryCombinationTree();
82+
}
83+
}
84+
7685
private bool DeleteableDictionary(object sender)
7786
{
7887
return sender is ListBox listBox
@@ -145,4 +154,4 @@ private void TryReloadDictionaryCombinationTree(bool force)
145154
LoadDictionaryCombinationTree();
146155
}
147156
}
148-
}
157+
}

src/Util/InputMethodDictionaryLoader.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@ internal static class InputMethodDictionaryLoader
1717

1818
#region Public 属性
1919

20-
public static string KanaDicPath => Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Assets", "Dictionaries", "jap_poly.dict.yaml");
20+
public static string KanaDicPath => Path.Combine(".", "Assets", "Dictionaries", "jap_poly.dict.yaml");
2121

22-
public static string PinyinDicPath => Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Assets", "Dictionaries", "pinyin_simp.dict.yaml");
22+
public static string PinyinDicPath => Path.Combine(".", "Assets", "Dictionaries", "pinyin_simp.dict.yaml");
2323

24-
public static string Wubi86DicPath => Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Assets", "Dictionaries", "wubi86_jidian.dict.yaml");
24+
public static string Wubi86DicPath => Path.Combine(".", "Assets", "Dictionaries", "wubi86_jidian.dict.yaml");
2525

2626
#endregion Public 属性
2727

2828
#region Public 方法
2929

3030
public static async Task<InputMethodReverseDictionary> LoadFilesAsync(IEnumerable<string> paths, CancellationToken cancellationToken = default)
3131
{
32-
var allPath = paths.Select(m => m.Trim('\"')).ToArray();
32+
var workingDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
33+
34+
var allPath = paths.Select(m => Path.Combine(workingDirectory, m).Trim('\"')).ToArray();
3335

3436
foreach (var item in allPath)
3537
{

0 commit comments

Comments
 (0)