Routing rule add custom icon

pull/1912/head
2dust 2021-12-02 16:05:54 +08:00
parent c29ccf76d5
commit 1138d660b2
6 changed files with 716 additions and 530 deletions

View File

@ -34,6 +34,10 @@
this.panel2 = new System.Windows.Forms.Panel();
this.btnOK = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.label5 = new System.Windows.Forms.Label();
this.btnBrowse = new System.Windows.Forms.Button();
this.txtCustomIcon = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.txtUrl = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
@ -68,17 +72,17 @@
//
// btnClose
//
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
resources.ApplyResources(this.btnClose, "btnClose");
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnClose.Name = "btnClose";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// panel2
//
resources.ApplyResources(this.panel2, "panel2");
this.panel2.Controls.Add(this.btnClose);
this.panel2.Controls.Add(this.btnOK);
resources.ApplyResources(this.panel2, "panel2");
this.panel2.Name = "panel2";
//
// btnOK
@ -90,14 +94,40 @@
//
// panel1
//
resources.ApplyResources(this.panel1, "panel1");
this.panel1.Controls.Add(this.label5);
this.panel1.Controls.Add(this.btnBrowse);
this.panel1.Controls.Add(this.txtCustomIcon);
this.panel1.Controls.Add(this.label4);
this.panel1.Controls.Add(this.label1);
this.panel1.Controls.Add(this.txtUrl);
this.panel1.Controls.Add(this.label3);
this.panel1.Controls.Add(this.txtRemarks);
this.panel1.Controls.Add(this.label2);
resources.ApplyResources(this.panel1, "panel1");
this.panel1.Name = "panel1";
//
// label5
//
resources.ApplyResources(this.label5, "label5");
this.label5.Name = "label5";
//
// btnBrowse
//
resources.ApplyResources(this.btnBrowse, "btnBrowse");
this.btnBrowse.Name = "btnBrowse";
this.btnBrowse.UseVisualStyleBackColor = true;
this.btnBrowse.Click += new System.EventHandler(this.btnBrowse_Click);
//
// txtCustomIcon
//
resources.ApplyResources(this.txtCustomIcon, "txtCustomIcon");
this.txtCustomIcon.Name = "txtCustomIcon";
//
// label4
//
resources.ApplyResources(this.label4, "label4");
this.label4.Name = "label4";
//
// label1
//
resources.ApplyResources(this.label1, "label1");
@ -125,8 +155,8 @@
//
// lvRoutings
//
this.lvRoutings.ContextMenuStrip = this.cmsLv;
resources.ApplyResources(this.lvRoutings, "lvRoutings");
this.lvRoutings.ContextMenuStrip = this.cmsLv;
this.lvRoutings.FullRowSelect = true;
this.lvRoutings.GridLines = true;
this.lvRoutings.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
@ -142,6 +172,7 @@
//
// cmsLv
//
resources.ApplyResources(this.cmsLv, "cmsLv");
this.cmsLv.ImageScalingSize = new System.Drawing.Size(20, 20);
this.cmsLv.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuAdd,
@ -155,114 +186,113 @@
this.menuMoveBottom});
this.cmsLv.Name = "cmsLv";
this.cmsLv.OwnerItem = this.MenuItem1;
resources.ApplyResources(this.cmsLv, "cmsLv");
//
// menuAdd
//
this.menuAdd.Name = "menuAdd";
resources.ApplyResources(this.menuAdd, "menuAdd");
this.menuAdd.Name = "menuAdd";
this.menuAdd.Click += new System.EventHandler(this.menuAdd_Click);
//
// menuRemove
//
this.menuRemove.Name = "menuRemove";
resources.ApplyResources(this.menuRemove, "menuRemove");
this.menuRemove.Name = "menuRemove";
this.menuRemove.Click += new System.EventHandler(this.menuRemove_Click);
//
// menuSelectAll
//
this.menuSelectAll.Name = "menuSelectAll";
resources.ApplyResources(this.menuSelectAll, "menuSelectAll");
this.menuSelectAll.Name = "menuSelectAll";
this.menuSelectAll.Click += new System.EventHandler(this.menuSelectAll_Click);
//
// menuExportSelectedRules
//
this.menuExportSelectedRules.Name = "menuExportSelectedRules";
resources.ApplyResources(this.menuExportSelectedRules, "menuExportSelectedRules");
this.menuExportSelectedRules.Name = "menuExportSelectedRules";
this.menuExportSelectedRules.Click += new System.EventHandler(this.menuExportSelectedRules_Click);
//
// toolStripSeparator3
//
this.toolStripSeparator3.Name = "toolStripSeparator3";
resources.ApplyResources(this.toolStripSeparator3, "toolStripSeparator3");
this.toolStripSeparator3.Name = "toolStripSeparator3";
//
// menuMoveTop
//
this.menuMoveTop.Name = "menuMoveTop";
resources.ApplyResources(this.menuMoveTop, "menuMoveTop");
this.menuMoveTop.Name = "menuMoveTop";
this.menuMoveTop.Click += new System.EventHandler(this.menuMoveTop_Click);
//
// menuMoveUp
//
this.menuMoveUp.Name = "menuMoveUp";
resources.ApplyResources(this.menuMoveUp, "menuMoveUp");
this.menuMoveUp.Name = "menuMoveUp";
this.menuMoveUp.Click += new System.EventHandler(this.menuMoveUp_Click);
//
// menuMoveDown
//
this.menuMoveDown.Name = "menuMoveDown";
resources.ApplyResources(this.menuMoveDown, "menuMoveDown");
this.menuMoveDown.Name = "menuMoveDown";
this.menuMoveDown.Click += new System.EventHandler(this.menuMoveDown_Click);
//
// menuMoveBottom
//
this.menuMoveBottom.Name = "menuMoveBottom";
resources.ApplyResources(this.menuMoveBottom, "menuMoveBottom");
this.menuMoveBottom.Name = "menuMoveBottom";
this.menuMoveBottom.Click += new System.EventHandler(this.menuMoveBottom_Click);
//
// MenuItem1
//
resources.ApplyResources(this.MenuItem1, "MenuItem1");
this.MenuItem1.DropDown = this.cmsLv;
this.MenuItem1.Name = "MenuItem1";
resources.ApplyResources(this.MenuItem1, "MenuItem1");
//
// tabControl2
//
this.tabControl2.Controls.Add(this.tabPage2);
resources.ApplyResources(this.tabControl2, "tabControl2");
this.tabControl2.Controls.Add(this.tabPage2);
this.tabControl2.Name = "tabControl2";
this.tabControl2.SelectedIndex = 0;
//
// tabPage2
//
this.tabPage2.Controls.Add(this.lvRoutings);
resources.ApplyResources(this.tabPage2, "tabPage2");
this.tabPage2.Controls.Add(this.lvRoutings);
this.tabPage2.Name = "tabPage2";
this.tabPage2.UseVisualStyleBackColor = true;
//
// menuServer
//
resources.ApplyResources(this.menuServer, "menuServer");
this.menuServer.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.MenuItem1,
this.toolStripMenuItem1});
resources.ApplyResources(this.menuServer, "menuServer");
this.menuServer.Name = "menuServer";
//
// toolStripMenuItem1
//
resources.ApplyResources(this.toolStripMenuItem1, "toolStripMenuItem1");
this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuImportRulesFromFile,
this.menuImportRulesFromClipboard,
this.menuImportRulesFromUrl});
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
resources.ApplyResources(this.toolStripMenuItem1, "toolStripMenuItem1");
//
// menuImportRulesFromFile
//
this.menuImportRulesFromFile.Name = "menuImportRulesFromFile";
resources.ApplyResources(this.menuImportRulesFromFile, "menuImportRulesFromFile");
this.menuImportRulesFromFile.Name = "menuImportRulesFromFile";
this.menuImportRulesFromFile.Click += new System.EventHandler(this.menuImportRulesFromFile_Click);
//
// menuImportRulesFromClipboard
//
this.menuImportRulesFromClipboard.Name = "menuImportRulesFromClipboard";
resources.ApplyResources(this.menuImportRulesFromClipboard, "menuImportRulesFromClipboard");
this.menuImportRulesFromClipboard.Name = "menuImportRulesFromClipboard";
this.menuImportRulesFromClipboard.Click += new System.EventHandler(this.menuImportRulesFromClipboard_Click);
//
// menuImportRulesFromUrl
//
this.menuImportRulesFromUrl.Name = "menuImportRulesFromUrl";
resources.ApplyResources(this.menuImportRulesFromUrl, "menuImportRulesFromUrl");
this.menuImportRulesFromUrl.Name = "menuImportRulesFromUrl";
this.menuImportRulesFromUrl.Click += new System.EventHandler(this.menuImportRulesFromUrl_Click);
//
// RoutingRuleSettingForm
@ -319,5 +349,9 @@
private System.Windows.Forms.TextBox txtUrl;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtCustomIcon;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button btnBrowse;
private System.Windows.Forms.Label label5;
}
}

View File

@ -38,6 +38,7 @@ namespace v2rayN.Forms
txtRemarks.Text = routingItem.remarks ?? string.Empty;
txtUrl.Text = routingItem.url ?? string.Empty;
txtCustomIcon.Text = routingItem.customIcon ?? string.Empty;
InitRoutingsView();
RefreshRoutingsView();
@ -93,6 +94,7 @@ namespace v2rayN.Forms
{
routingItem.remarks = txtRemarks.Text.Trim();
routingItem.url = txtUrl.Text.Trim();
routingItem.customIcon = txtCustomIcon.Text.Trim();
if (ConfigHandler.AddRoutingItem(ref config, routingItem, EditIndex) == 0)
{
@ -108,6 +110,14 @@ namespace v2rayN.Forms
{
this.DialogResult = DialogResult.Cancel;
}
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "PNG|*.png";
openFileDialog1.ShowDialog();
txtCustomIcon.Text = openFileDialog1.FileName;
}
private void lvRoutings_DoubleClick(object sender, EventArgs e)
{
@ -340,8 +350,9 @@ namespace v2rayN.Forms
return ConfigHandler.AddBatchRoutingRules(ref routingItem, clipboardData, blReplace);
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

View File

@ -120,16 +120,31 @@
<data name="btnClose.Text" xml:space="preserve">
<value>取消(&amp;C)</value>
</data>
<data name="btnOK.Text" xml:space="preserve">
<value>确定(&amp;O)</value>
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="panel2.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 613</value>
<value>0, 501</value>
</data>
<data name="panel2.Size" type="System.Drawing.Size, System.Drawing">
<value>785, 60</value>
</data>
<data name="btnOK.Text" xml:space="preserve">
<value>确定(&amp;O)</value>
</data>
<data name="panel1.Size" type="System.Drawing.Size, System.Drawing">
<value>785, 147</value>
</data>
<data name="btnBrowse.Location" type="System.Drawing.Point, System.Drawing">
<value>670, 104</value>
</data>
<data name="txtCustomIcon.Location" type="System.Drawing.Point, System.Drawing">
<value>101, 105</value>
</data>
<data name="label4.Size" type="System.Drawing.Size, System.Drawing">
<value>65, 12</value>
</data>
<data name="label4.Text" xml:space="preserve">
<value>自定义图标</value>
</data>
<data name="label1.Size" type="System.Drawing.Size, System.Drawing">
<value>29, 12</value>
</data>
@ -154,9 +169,6 @@
<data name="label2.Text" xml:space="preserve">
<value>别名</value>
</data>
<data name="panel1.Size" type="System.Drawing.Size, System.Drawing">
<value>785, 109</value>
</data>
<data name="menuAdd.Size" type="System.Drawing.Size, System.Drawing">
<value>196, 22</value>
</data>
@ -235,19 +247,28 @@
</value>
</data>
<data name="lvRoutings.Size" type="System.Drawing.Size, System.Drawing">
<value>771, 447</value>
<value>771, 297</value>
</data>
<data name="tabControl2.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 172</value>
</data>
<data name="tabControl2.Size" type="System.Drawing.Size, System.Drawing">
<value>785, 329</value>
</data>
<data name="tabPage2.Size" type="System.Drawing.Size, System.Drawing">
<value>777, 453</value>
<value>777, 303</value>
</data>
<data name="tabPage2.Text" xml:space="preserve">
<value>规则列表</value>
</data>
<data name="tabControl2.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 134</value>
<data name="menuServer.Size" type="System.Drawing.Size, System.Drawing">
<value>785, 25</value>
</data>
<data name="tabControl2.Size" type="System.Drawing.Size, System.Drawing">
<value>785, 479</value>
<data name="toolStripMenuItem1.Size" type="System.Drawing.Size, System.Drawing">
<value>68, 21</value>
</data>
<data name="toolStripMenuItem1.Text" xml:space="preserve">
<value>导入规则</value>
</data>
<data name="menuImportRulesFromFile.Size" type="System.Drawing.Size, System.Drawing">
<value>189, 22</value>
@ -267,17 +288,8 @@
<data name="menuImportRulesFromUrl.Text" xml:space="preserve">
<value>从订阅Url中导入规则</value>
</data>
<data name="toolStripMenuItem1.Size" type="System.Drawing.Size, System.Drawing">
<value>68, 21</value>
</data>
<data name="toolStripMenuItem1.Text" xml:space="preserve">
<value>导入规则</value>
</data>
<data name="menuServer.Size" type="System.Drawing.Size, System.Drawing">
<value>785, 25</value>
</data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>785, 673</value>
<value>785, 561</value>
</data>
<data name="$this.Text" xml:space="preserve">
<value>规则集设置</value>

View File

@ -1,5 +1,6 @@
using System;
using System.Drawing;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
@ -50,9 +51,23 @@ namespace v2rayN.Handler
Graphics graphics = Graphics.FromImage(bitmap);
SolidBrush drawBrush = new SolidBrush(color);
graphics.FillEllipse(drawBrush, new Rectangle(0, 0, width, height));
int zoom = 16;
graphics.DrawImage(new Bitmap(Properties.Resources.notify, width - zoom, width - zoom), zoom / 2, zoom / 2);
var customIcon = false;
if (config.enableRoutingAdvanced)
{
var item = config.routings[config.routingIndex];
if (!Utils.IsNullOrEmpty(item.customIcon) && File.Exists(item.customIcon))
{
graphics.FillRectangle(drawBrush, new Rectangle(0, 0, width, height));
graphics.DrawImage(new Bitmap(item.customIcon), 0, 0);
customIcon = true;
}
}
if (!customIcon)
{
graphics.FillEllipse(drawBrush, new Rectangle(0, 0, width, height));
int zoom = 16;
graphics.DrawImage(new Bitmap(Properties.Resources.notify, width - zoom, width - zoom), zoom / 2, zoom / 2);
}
Icon createdIcon = Icon.FromHandle(bitmap.GetHicon());

View File

@ -27,6 +27,9 @@ namespace v2rayN.Mode
{
get; set;
}
public string customIcon
{
get; set;
}
}
}