OnStartup 启动窗体,构造函数加待查询单词
Browse files- build/goldendict-ng.sln +2 -2
- readme.txt +18 -0
- wpfmdict/App.xaml +6 -3
- wpfmdict/App.xaml.cs +8 -0
- wpfmdict/{wpfmdict.csproj → Echodict.csproj} +0 -0
- wpfmdict/EchodictWindow.xaml.cs +42 -0
build/goldendict-ng.sln
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
|
| 2 |
Microsoft Visual Studio Solution File, Format Version 12.00
|
| 3 |
# Visual Studio Version 17
|
| 4 |
-
VisualStudioVersion = 17.14.35806.103
|
| 5 |
MinimumVisualStudioVersion = 10.0.40219.1
|
| 6 |
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CMakePredefinedTargets", "CMakePredefinedTargets", "{7CB4EF44-1C18-3653-A901-3A42DFB69A4A}"
|
| 7 |
EndProject
|
|
@@ -67,7 +67,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "update_translations", "upda
|
|
| 67 |
{2DC5DD85-ECD5-37F0-9113-F14A9C4DBA16} = {2DC5DD85-ECD5-37F0-9113-F14A9C4DBA16}
|
| 68 |
EndProjectSection
|
| 69 |
EndProject
|
| 70 |
-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "
|
| 71 |
EndProject
|
| 72 |
Global
|
| 73 |
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
|
|
| 1 |
|
| 2 |
Microsoft Visual Studio Solution File, Format Version 12.00
|
| 3 |
# Visual Studio Version 17
|
| 4 |
+
VisualStudioVersion = 17.14.35806.103
|
| 5 |
MinimumVisualStudioVersion = 10.0.40219.1
|
| 6 |
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CMakePredefinedTargets", "CMakePredefinedTargets", "{7CB4EF44-1C18-3653-A901-3A42DFB69A4A}"
|
| 7 |
EndProject
|
|
|
|
| 67 |
{2DC5DD85-ECD5-37F0-9113-F14A9C4DBA16} = {2DC5DD85-ECD5-37F0-9113-F14A9C4DBA16}
|
| 68 |
EndProjectSection
|
| 69 |
EndProject
|
| 70 |
+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Echodict", "..\wpfmdict\Echodict.csproj", "{7192449E-2054-42E9-8993-D04A474CCDA4}"
|
| 71 |
EndProject
|
| 72 |
Global
|
| 73 |
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
readme.txt
CHANGED
|
@@ -1024,6 +1024,24 @@ goldendict-ng C++ 代码通过拦截 entry:// 协议并将其转换为内部查
|
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
|
|
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
+
`e:\huggingface\goldendict-ng\wpfmdict\EchodictWindow.xaml.cs` EchodictWindow 需要有一个默认参数 word,可传可不传。如果传了就作为启动程序后自动查询的词条,去查从配置文件指定的默认词典,并显示结果
|
| 1028 |
+
|
| 1029 |
+
我已经实现了这个功能。
|
| 1030 |
+
|
| 1031 |
+
### 修改内容 (Changes)
|
| 1032 |
+
1. 修改 EchodictWindow.xaml.cs :
|
| 1033 |
+
|
| 1034 |
+
- 构造函数修改为 public EchodictWindow(string? startupWord = null) 。
|
| 1035 |
+
- 在 ScanAndLoadDictionaries 方法(词典加载完成并恢复了默认配置后)中,如果 startupWord 不为空,则自动触发 Search 操作。这确保了查询使用的是配置文件中记录的最后一次选择的词典或分组。
|
| 1036 |
+
2. 修改 App.xaml :
|
| 1037 |
+
|
| 1038 |
+
- 移除了 StartupUri="EchodictWindow.xaml" ,改为在代码中手动控制启动。
|
| 1039 |
+
3. 修改 App.xaml.cs :
|
| 1040 |
+
|
| 1041 |
+
- 重写了 OnStartup 方法。
|
| 1042 |
+
- 解析命令行参数,如果有参数(即启动时的单词),则将其传递给 EchodictWindow 的构造函数。
|
| 1043 |
+
现在,您可以通过代码传递参数,或者在命令行运行程序时带上参数(例如 wpfmdict.exe hello ),程序启动后会自动使用配置的默认词典查询 "hello"。
|
| 1044 |
+
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
wpfmdict/App.xaml
CHANGED
|
@@ -1,9 +1,12 @@
|
|
| 1 |
-
|
| 2 |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
| 3 |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
| 4 |
-
xmlns:local="clr-namespace:
|
| 5 |
-
|
|
|
|
| 6 |
<Application.Resources>
|
| 7 |
|
| 8 |
</Application.Resources>
|
| 9 |
</Application>
|
|
|
|
|
|
|
|
|
| 1 |
+
<Application x:Class="Echodict.App"
|
| 2 |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
| 3 |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
| 4 |
+
xmlns:local="clr-namespace:Echodict"
|
| 5 |
+
|
| 6 |
+
>
|
| 7 |
<Application.Resources>
|
| 8 |
|
| 9 |
</Application.Resources>
|
| 10 |
</Application>
|
| 11 |
+
|
| 12 |
+
<!--StartupUri="EchodictWindow.xaml"-->
|
wpfmdict/App.xaml.cs
CHANGED
|
@@ -13,5 +13,13 @@ namespace Echodict
|
|
| 13 |
{
|
| 14 |
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
| 15 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|
| 17 |
}
|
|
|
|
| 13 |
{
|
| 14 |
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
| 15 |
}
|
| 16 |
+
|
| 17 |
+
protected override void OnStartup(StartupEventArgs e)
|
| 18 |
+
{
|
| 19 |
+
base.OnStartup(e);
|
| 20 |
+
string? word = e.Args.Length > 0 ? e.Args[0] : null;
|
| 21 |
+
var window = new EchodictWindow(word);
|
| 22 |
+
window.Show();
|
| 23 |
+
}
|
| 24 |
}
|
| 25 |
}
|
wpfmdict/{wpfmdict.csproj → Echodict.csproj}
RENAMED
|
File without changes
|
wpfmdict/EchodictWindow.xaml.cs
CHANGED
|
@@ -28,11 +28,42 @@ namespace Echodict
|
|
| 28 |
private List<DictGroup> _groups = new List<DictGroup>();
|
| 29 |
private string _currentSelectionId = "ALL";
|
| 30 |
private bool _isReady = false;
|
|
|
|
|
|
|
| 31 |
|
| 32 |
public EchodictWindow()
|
| 33 |
{
|
| 34 |
InitializeComponent();
|
| 35 |
LoadConfig();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
// Initial scan if we have paths but no dicts loaded yet
|
| 38 |
if (_sourcePaths.Count > 0)
|
|
@@ -57,6 +88,8 @@ namespace Echodict
|
|
| 57 |
_isReady = true;
|
| 58 |
}
|
| 59 |
|
|
|
|
|
|
|
| 60 |
private void LoadConfig()
|
| 61 |
{
|
| 62 |
try
|
|
@@ -196,6 +229,15 @@ namespace Echodict
|
|
| 196 |
RefreshDictSelector();
|
| 197 |
SaveConfig(); // Save to persist any state if needed, though mostly redundant here
|
| 198 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
// MessageBox.Show($"Loaded {_dicts.Count} dictionaries.", "Scan Complete");
|
| 200 |
}
|
| 201 |
|
|
|
|
| 28 |
private List<DictGroup> _groups = new List<DictGroup>();
|
| 29 |
private string _currentSelectionId = "ALL";
|
| 30 |
private bool _isReady = false;
|
| 31 |
+
private string? _startupWord;
|
| 32 |
+
|
| 33 |
|
| 34 |
public EchodictWindow()
|
| 35 |
{
|
| 36 |
InitializeComponent();
|
| 37 |
LoadConfig();
|
| 38 |
+
|
| 39 |
+
// Initial scan if we have paths but no dicts loaded yet
|
| 40 |
+
if (_sourcePaths.Count > 0)
|
| 41 |
+
{
|
| 42 |
+
Loaded += (s, e) => ScanAndLoadDictionaries();
|
| 43 |
+
}
|
| 44 |
+
else
|
| 45 |
+
{
|
| 46 |
+
// Initialize empty selector
|
| 47 |
+
RefreshDictSelector();
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
Browser.RequestHandler = new DictRequestHandler(_dicts, (query) =>
|
| 51 |
+
{
|
| 52 |
+
Dispatcher.Invoke(() =>
|
| 53 |
+
{
|
| 54 |
+
SideSearchBox.Text = query;
|
| 55 |
+
Search(query, true);
|
| 56 |
+
});
|
| 57 |
+
});
|
| 58 |
+
|
| 59 |
+
_isReady = true;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
public EchodictWindow(string? startupWord = null)
|
| 63 |
+
{
|
| 64 |
+
InitializeComponent();
|
| 65 |
+
_startupWord = startupWord;
|
| 66 |
+
LoadConfig();
|
| 67 |
|
| 68 |
// Initial scan if we have paths but no dicts loaded yet
|
| 69 |
if (_sourcePaths.Count > 0)
|
|
|
|
| 88 |
_isReady = true;
|
| 89 |
}
|
| 90 |
|
| 91 |
+
|
| 92 |
+
|
| 93 |
private void LoadConfig()
|
| 94 |
{
|
| 95 |
try
|
|
|
|
| 229 |
RefreshDictSelector();
|
| 230 |
SaveConfig(); // Save to persist any state if needed, though mostly redundant here
|
| 231 |
|
| 232 |
+
// Handle startup word
|
| 233 |
+
if (!string.IsNullOrEmpty(_startupWord))
|
| 234 |
+
{
|
| 235 |
+
// Ensure UI is updated before searching (though Search method handles it)
|
| 236 |
+
SideSearchBox.Text = _startupWord;
|
| 237 |
+
Search(_startupWord, true);
|
| 238 |
+
_startupWord = null; // Consume it
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
// MessageBox.Show($"Loaded {_dicts.Count} dictionaries.", "Scan Complete");
|
| 242 |
}
|
| 243 |
|