From 39b0576e53cb7fb52cb1f6fb4767e4334b5ee6e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=93=9D=E7=82=B9lilac?= Date: Sun, 20 Dec 2020 00:43:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9B=B4=E6=8D=A2=E7=BD=91?= =?UTF-8?q?=E9=A1=B5=E6=90=9C=E7=B4=A2=E5=BC=95=E6=93=8E=E7=9A=84=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ContextMenuManager/AppConfig.cs | 24 +++++++++ ContextMenuManager/Controls/AboutApp.cs | 50 +++++++++++++++++-- .../Controls/Interfaces/ITsiWebSearchItem.cs | 4 +- 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/ContextMenuManager/AppConfig.cs b/ContextMenuManager/AppConfig.cs index c2c6136..682858a 100644 --- a/ContextMenuManager/AppConfig.cs +++ b/ContextMenuManager/AppConfig.cs @@ -40,6 +40,16 @@ namespace ContextMenuManager public const string ThIRDRULESDICXML = "ThirdRulesDic.xml"; public const string ENHANCEMENUSICXML = "EnhanceMenusDic.xml"; + public static readonly string[] EngineUrls = + { + "https://www.baidu.com/s?wd=%s", //百度搜索 + "https://www.bing.com/search?q=%s", //必应搜索 + "https://www.google.com/search?q=%s", //谷歌搜索 + "https://www.dogedoge.com/results?q=%s", //多吉搜索 + "https://www.sogou.com/web?query=%s", //搜狗搜索 + "https://www.so.com/s?q=%s", //360搜索 + }; + private static IniReader ConfigReader => new IniReader(ConfigIni); private static IniWriter ConfigWriter => new IniWriter(ConfigIni); @@ -105,6 +115,20 @@ namespace ContextMenuManager set => ConfigWriter.SetValue("General", "ProtectOpenItem", (value ? 1 : 0).ToString()); } + public static string EngineUrl + { + get + { + string url = ConfigReader.GetValue("General", "EngineUrl"); + if(url.IsNullOrWhiteSpace()) url = EngineUrls[0]; + return url; + } + set + { + ConfigWriter.SetValue("General", "EngineUrl", value); + } + } + private static void CreateDirs() { foreach(string dirPath in new[] { ConfigDir, BackupDir, LangsDir, DicsDir, WebDicsDir, UserDicsDir }) diff --git a/ContextMenuManager/Controls/AboutApp.cs b/ContextMenuManager/Controls/AboutApp.cs index 6ec5c52..0dfdfe3 100644 --- a/ContextMenuManager/Controls/AboutApp.cs +++ b/ContextMenuManager/Controls/AboutApp.cs @@ -293,12 +293,13 @@ namespace ContextMenuManager.Controls mliBackup.AddCtrs(new Control[] { chkBackup, btnBackupDir }); mliUpdate.AddCtrs(new Control[] { lblGitee, lblGithub, lblUpdate }); mliProtect.AddCtr(chkProtect); + mliEngine.AddCtr(cmbEngine); MyToolTip.SetToolTip(btnConfigDir, AppString.Other.OpenConfigDir); MyToolTip.SetToolTip(btnBackupDir, AppString.Other.OpenBackupDir); MyToolTip.SetToolTip(lblUpdate, AppString.Tip.CheckUpdate + Environment.NewLine + AppString.Tip.LastCheckUpdateTime + AppConfig.LastCheckUpdateTime.ToLongDateString()); cmbConfigDir.Items.AddRange(new[] { AppString.Other.SaveToAppData, AppString.Other.SaveToAppDir }); - cmbConfigDir.Width = 160.DpiZoom(); + cmbEngine.Items.AddRange(new[] { "Baidu", "Bing", "Google", "DogeDoge", "Sogou", "360", AppString.Other.CustomEngine }); btnConfigDir.MouseDown += (sender, e) => Process.Start(AppConfig.ConfigDir); btnBackupDir.MouseDown += (sender, e) => Process.Start(AppConfig.BackupDir); lblGithub.Click += (sender, e) => Process.Start(GITHUBRELEASES); @@ -322,6 +323,29 @@ namespace ContextMenuManager.Controls Application.Restart(); } }; + cmbEngine.SelectionChangeCommitted += (sender, e) => + { + if(cmbEngine.SelectedIndex < cmbEngine.Items.Count - 1) + { + AppConfig.EngineUrl = AppConfig.EngineUrls[cmbEngine.SelectedIndex]; + } + else + { + using(InputDialog dlg = new InputDialog { Title = AppString.Other.SetCustomEngine }) + { + dlg.Text = AppConfig.EngineUrl; + if(dlg.ShowDialog() == DialogResult.OK) AppConfig.EngineUrl = dlg.Text; + string url = AppConfig.EngineUrl; + for(int i = 0; i < AppConfig.EngineUrls.Length; i++) + { + if(url.Equals(AppConfig.EngineUrls[i])) + { + cmbEngine.SelectedIndex = i; break; + } + } + } + } + }; chkBackup.MouseDown += (sender, e) => AppConfig.AutoBackup = chkBackup.Checked = !chkBackup.Checked; chkProtect.MouseDown += (sender, e) => AppConfig.ProtectOpenItem = chkProtect.Checked = !chkProtect.Checked; } @@ -333,7 +357,8 @@ namespace ContextMenuManager.Controls }; readonly ComboBox cmbConfigDir = new ComboBox { - DropDownStyle = ComboBoxStyle.DropDownList + DropDownStyle = ComboBoxStyle.DropDownList, + Width = 160.DpiZoom() }; readonly PictureButton btnConfigDir = new PictureButton(AppImage.Open); @@ -379,12 +404,31 @@ namespace ContextMenuManager.Controls }; readonly MyCheckBox chkProtect = new MyCheckBox(); + readonly MyListItem mliEngine = new MyListItem + { + Text = AppString.Other.WebSearchEngine, + HasImage = false + }; + readonly ComboBox cmbEngine = new ComboBox + { + DropDownStyle = ComboBoxStyle.DropDownList, + Width = 100.DpiZoom() + }; + public void LoadItems() { - this.AddItems(new[] { mliUpdate, mliConfigDir, mliBackup, mliProtect }); + this.AddItems(new[] { mliUpdate, mliConfigDir, mliBackup, mliProtect, mliEngine }); cmbConfigDir.SelectedIndex = AppConfig.SaveToAppDir ? 1 : 0; chkBackup.Checked = AppConfig.AutoBackup; chkProtect.Checked = AppConfig.ProtectOpenItem; + string url = AppConfig.EngineUrl; + for(int i = 0; i <= AppConfig.EngineUrls.Length; i++) + { + if(i == AppConfig.EngineUrls.Length || url.Equals(AppConfig.EngineUrls[i])) + { + cmbEngine.SelectedIndex = i; break; + } + } } } } \ No newline at end of file diff --git a/ContextMenuManager/Controls/Interfaces/ITsiWebSearchItem.cs b/ContextMenuManager/Controls/Interfaces/ITsiWebSearchItem.cs index 04196d7..3f7b1e5 100644 --- a/ContextMenuManager/Controls/Interfaces/ITsiWebSearchItem.cs +++ b/ContextMenuManager/Controls/Interfaces/ITsiWebSearchItem.cs @@ -11,8 +11,6 @@ namespace ContextMenuManager.Controls.Interfaces sealed class WebSearchMenuItem : ToolStripMenuItem { - public static string EnginePath = "https://www.baidu.com/s?wd="; - public WebSearchMenuItem(ITsiWebSearchItem item) : base(AppString.Menu.WebSearch) { this.Click += (sender, e) => WebSearch(item.SearchText); @@ -22,7 +20,7 @@ namespace ContextMenuManager.Controls.Interfaces { //替换网址转义符 text = text.Replace("%", "%25").Replace("#", "%23").Replace("&", "%26").Replace("+", "%2B"); - Process.Start(EnginePath + text); + Process.Start(AppConfig.EngineUrl.Replace("%s", text)); } } } \ No newline at end of file