完善“添加本地GUID字典”功能

This commit is contained in:
蓝点lilac
2020-11-13 10:18:14 +08:00
parent 247a657374
commit a94ce223a6
8 changed files with 64 additions and 23 deletions

View File

@@ -185,6 +185,7 @@ namespace ContextMenuManager
public static string MultiMenu => GetValue("MultiMenu");
public static string InputGuid => GetValue("InputGuid");
public static string AddGuidDic => GetValue("AddGuidDic");
public static string DeleteGuidDic => GetValue("DeleteGuidDic");
public static string SelectExtension => GetValue("SelectExtension");
public static string CheckReference => GetValue("CheckReference");
public static string CheckCommon => GetValue("CheckCommon");
@@ -249,6 +250,7 @@ namespace ContextMenuManager
public static string Separator => GetValue("Separator");
public static string AddExistingItems => GetValue("AddExistingItems");
public static string AddCommonItems => GetValue("AddCommonItems");
public static string DeleteGuidDic => GetValue("DeleteGuidDic");
}
}
}

View File

@@ -30,7 +30,7 @@ namespace BulePointLilac.Methods
ReadLines(lines);
}
protected readonly Dictionary<string, Dictionary<string, string>> rootDic
public readonly Dictionary<string, Dictionary<string, string>> RootDic
= new Dictionary<string, Dictionary<string, string>>(StringComparer.OrdinalIgnoreCase);
private void ReadLines(List<string> lines)
@@ -54,9 +54,9 @@ namespace BulePointLilac.Methods
int m = section.IndexOf(']') - 1;
if(m < 0) continue;
section = section.Substring(1, m);
if(rootDic.ContainsKey(section)) continue;
if(RootDic.ContainsKey(section)) continue;
var keyValues = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
rootDic.Add(section, keyValues);
RootDic.Add(section, keyValues);
for(int j = indexs[i] + 1; j < indexs[i + 1]; j++)
{
@@ -70,7 +70,7 @@ namespace BulePointLilac.Methods
public string GetValue(string section, string key)
{
if(rootDic.TryGetValue(section, out Dictionary<string, string> sectionDic))
if(RootDic.TryGetValue(section, out Dictionary<string, string> sectionDic))
if(sectionDic.TryGetValue(key, out string value))
return value;
return string.Empty;

View File

@@ -249,8 +249,8 @@ namespace ContextMenuManager.Controls
cmbLanguages.Items.Add(language);
}
txtTranslators.Text = str;
cmbLanguages.SelectedIndex = GetSelectIndex();
}
cmbLanguages.SelectedIndex = GetSelectIndex();
}
private void ChangeLanguage()

View File

@@ -10,6 +10,7 @@ namespace ContextMenuManager.Controls
{
public Image ItemIcon { get; set; }
public string ItemName { get; set; }
public bool IsDelete { get; private set; }
public string ItemIconPath { get; set; }
public int ItemIconIndex { get; set; }
public string ItemIconLocation
@@ -39,6 +40,7 @@ namespace ContextMenuManager.Controls
this.ItemIconPath = frm.ItemIconPath;
this.ItemIconIndex = frm.ItemIconIndex;
}
this.IsDelete = frm.IsDelete;
return flag;
}
}
@@ -63,12 +65,14 @@ namespace ContextMenuManager.Controls
get => txtName.Text;
set => txtName.Text = value;
}
public string ItemIconPath { get; set; }
public int ItemIconIndex { get; set; }
public Image ItemIcon {
public Image ItemIcon
{
get => picIcon.Image;
set => picIcon.Image = value;
}
public string ItemIconPath { get; set; }
public int ItemIconIndex { get; set; }
public bool IsDelete { get; private set; }
readonly TextBox txtName = new TextBox();
readonly Label lblName = new Label
@@ -86,7 +90,7 @@ namespace ContextMenuManager.Controls
Size = SystemInformation.IconSize,
BackColor = Color.White
};
readonly Button btnIcon = new Button
readonly Button btnBrowse = new Button
{
Text = AppString.Dialog.Browse,
AutoSize = true
@@ -103,21 +107,32 @@ namespace ContextMenuManager.Controls
DialogResult = DialogResult.Cancel,
AutoSize = true
};
readonly Button btnDelete = new Button
{
Text = AppString.Dialog.DeleteGuidDic,
DialogResult = DialogResult.Cancel,
AutoSize = true
};
private void InitializeComponents()
{
this.Controls.AddRange(new Control[] { lblName, txtName, lblIcon, picIcon, btnIcon, btnOk, btnCancel });
this.Controls.AddRange(new Control[] { lblName, txtName, lblIcon, picIcon, btnBrowse, btnDelete, btnOk, btnCancel });
int a = 20.DpiZoom();
lblName.Left = lblName.Top = lblIcon.Left = txtName.Top = a;
lblName.Left = lblName.Top = lblIcon.Left = btnDelete.Left = txtName.Top = a;
txtName.Left = lblName.Right + a;
lblIcon.Top = picIcon.Top = btnIcon.Top = lblName.Bottom + a;
btnOk.Left = picIcon.Left = lblIcon.Right + a;
btnOk.Top = btnCancel.Top = picIcon.Bottom + a;
btnIcon.Left = btnCancel.Left = btnOk.Right + a;
btnOk.Left = btnDelete.Right + a;
btnCancel.Left = btnOk.Right + a;
txtName.Width = btnCancel.Right - txtName.Left;
btnBrowse.Left = btnCancel.Right - btnBrowse.Width;
picIcon.Left = btnOk.Left + (btnOk.Width - picIcon.Width) / 2;
btnBrowse.Top = txtName.Bottom + a;
picIcon.Top = btnBrowse.Top + (btnBrowse.Height - picIcon.Height) / 2;
lblIcon.Top = btnBrowse.Top + (btnBrowse.Height - lblIcon.Height) / 2;
btnDelete.Top = btnOk.Top = btnCancel.Top = btnBrowse.Bottom + a;
this.ClientSize = new Size(btnCancel.Right + a, btnCancel.Bottom + a);
btnIcon.Click += (sender, e) => SelectIcon();
MyToolTip.SetToolTip(btnDelete, AppString.Tip.DeleteGuidDic);
btnBrowse.Click += (sender, e) => SelectIcon();
btnDelete.Click += (sender, e) => this.IsDelete = true;
}
private void SelectIcon()

View File

@@ -155,14 +155,26 @@ namespace ContextMenuManager.Controls
dlg.ItemIcon = this.Image;
dlg.ItemIconPath = this.IconLocation.IconPath;
dlg.ItemIconIndex = this.IconLocation.IconIndex;
if(dlg.ShowDialog() != DialogResult.OK) return;
Directory.CreateDirectory(Program.ConfigDir);
IniFileHelper helper = new IniFileHelper(Program.GuidInfosDicPath);
string section = this.Guid.ToString();
if(dlg.ShowDialog() != DialogResult.OK)
{
if(dlg.IsDelete) {
helper.DeleteSection(section);
GuidInfo.ItemTextDic.Remove(this.Guid);
GuidInfo.ItemImageDic.Remove(this.Guid);
GuidInfo.IconLocationDic.Remove(this.Guid);
GuidInfo.UserDic.RootDic.Remove(section);
this.Text = this.ItemText;
this.Image = GuidInfo.GetImage(Guid);
}
return;
}
Directory.CreateDirectory(Program.ConfigDir);
if(!string.IsNullOrWhiteSpace(dlg.ItemName))
{
helper.SetValue(section, "Text", dlg.ItemName);
this.Text = dlg.ItemName;
this.Text = ResourceString.GetDirectString(dlg.ItemName);
if(GuidInfo.ItemTextDic.ContainsKey(this.Guid))
{
GuidInfo.ItemTextDic[this.Guid] = this.Text;
@@ -185,6 +197,14 @@ namespace ContextMenuManager.Controls
GuidInfo.IconLocationDic.Add(this.Guid, location);
}
this.Image = dlg.ItemIcon;
if(GuidInfo.ItemImageDic.ContainsKey(this.Guid))
{
GuidInfo.ItemImageDic[this.Guid] = this.Image;
}
else
{
GuidInfo.ItemImageDic.Add(this.Guid, this.Image);
}
}
}
}

View File

@@ -23,11 +23,11 @@ namespace ContextMenuManager
}
private static IniReader AppDic;
private static readonly IniReader UserDic = new IniReader(Program.GuidInfosDicPath);
public static readonly IniReader UserDic = new IniReader(Program.GuidInfosDicPath);
public static readonly Dictionary<Guid, IconLocation> IconLocationDic = new Dictionary<Guid, IconLocation>();
private static readonly Dictionary<Guid, string> FilePathDic = new Dictionary<Guid, string>();
public static readonly Dictionary<Guid, string> ItemTextDic = new Dictionary<Guid, string>();
private static readonly Dictionary<Guid, Image> ItemImageDic = new Dictionary<Guid, Image>();
public static readonly Dictionary<Guid, Image> ItemImageDic = new Dictionary<Guid, Image>();
public static bool TryGetGuid(string value, out Guid guid) => TryGetGuid(value, out guid, out _);

View File

@@ -152,6 +152,7 @@ SingleMenu = 一级
MultiMenu = 多级
InputGuid = 输入Guid
AddGuidDic = 添加Guid本地字典
DeleteGuidDic = 删除
SelectExtension = 请选择一个文件扩展名
CheckReference = 请勾选你想要添加引用的菜单项目
CheckCommon = 请勾选你想要添加的常用菜单项目
@@ -190,6 +191,7 @@ AddExistingItems = 添加对现有项目的引用
AddSeparator = 添加分隔线
Separator = 项目分隔线
AddCommonItems = 添加常用菜单项目
DeleteGuidDic = 删除用户自行添加的该项的本地Guid字典
[Other]
DictionaryDescription = 字典说明

View File

@@ -152,6 +152,7 @@ SingleMenu = 一级
MultiMenu = 多级
InputGuid = 输入Guid
AddGuidDic = 添加Guid本地字典
DeleteGuidDic = 删除
SelectExtension = 请选择一个文件扩展名
CheckReference = 请勾选你想要添加引用的菜单项目
CheckCommon = 请勾选你想要添加的常用菜单项目
@@ -190,6 +191,7 @@ AddExistingItems = 添加对现有项目的引用
AddSeparator = 添加分隔线
Separator = 项目分隔线
AddCommonItems = 添加常用菜单项目
DeleteGuidDic = 删除用户自行添加的该项的本地Guid字典
[Other]
DictionaryDescription = 字典说明