mirror of
https://github.com/BluePointLilac/ContextMenuManager.git
synced 2026-01-14 06:04:00 +08:00
添加更换网页搜索引擎的设置功能
This commit is contained in:
@@ -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 })
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user