using PaintDotNet.Base.CommTool;
using PaintDotNet.Instrument.CustomInterface;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PaintDotNet.Instrument
{
///
/// 自定义界面
///
internal class CustomInterfaceDialog : PdnBaseForm
{
///
/// 工作空间
///
private AppWorkspace appWorkspace;
///
/// 当前选中 1工具栏 2快捷键 3快捷栏
///
private int currentInedx = 0;
///
/// 工具栏自定义组件
///
private TopTools topTools;
///
/// 快捷键自定义组件
///
private ShortKeys shortKeys;
///
/// 快捷栏自定义组件
///
private FastTools fastTools;
///
/// 新增、重命名的弹窗
///
private CreateNameDialog createNameDialog;
///
/// 是否新建弹窗
///
private bool istoCreate = true;
#region 控件
private CustomControl.SelectButton buttonTopTools;
private CustomControl.SelectButton buttonShortKeys;
private CustomControl.SelectButton buttonFastTools;
private GroupBox groupBoxTypes;
private Button buttonSave;
private Button buttonExport;
private Button buttonImport;
private Button buttonCreateName;
private Button buttonDeleteName;
private Button buttonEditName;
private GroupBox groupBoxButtons;
//private Label label1;
//private Label label2;
#endregion
public CustomInterfaceDialog(AppWorkspace AppWorkspace)
{
this.appWorkspace = AppWorkspace;
InitializeComponent();
InitializeLanguageText();
this.StartPosition = FormStartPosition.CenterScreen;
this.topTools = new TopTools(this.appWorkspace);
this.topTools.CustomInterfaceDialog = this;
this.shortKeys = new ShortKeys(this.appWorkspace);
this.fastTools = new FastTools(this.appWorkspace);
this.buttonTopToolsClick(null, null);
}
private void InitializeLanguageText()
{
this.Text = PdnResources.GetString("Menu.Tools.CustomInterface.Text");
this.groupBoxTypes.Text = PdnResources.GetString("Menu.Type.text");
this.buttonFastTools.BtnText = PdnResources.GetString("Menu.tool.Generateshortcut.Shortcutbar.text");
this.buttonShortKeys.BtnText = PdnResources.GetString("Menu.hotkey.text");
this.buttonTopTools.BtnText = PdnResources.GetString("Menu.tool.Generateshortcut.toolbar.text");
this.groupBoxButtons.Text = PdnResources.GetString("Menu.operation.text");
this.buttonDeleteName.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
this.buttonEditName.Text = PdnResources.GetString("Menu.Rename.text");
this.buttonCreateName.Text = PdnResources.GetString("Menu.New.text");
this.buttonExport.Text = PdnResources.GetString("Menu.tool.Generateshortcut.Exportconfiguration.text");
this.buttonImport.Text = PdnResources.GetString("Menu.tool.Generateshortcut.Importconfiguration.text");
this.buttonSave.Text = PdnResources.GetString("Menu.File.Save.Text");
}
private void InitializeComponent()
{
this.groupBoxTypes = new System.Windows.Forms.GroupBox();
this.buttonFastTools = new PaintDotNet.CustomControl.SelectButton();
this.buttonShortKeys = new PaintDotNet.CustomControl.SelectButton();
this.buttonTopTools = new PaintDotNet.CustomControl.SelectButton();
this.groupBoxButtons = new System.Windows.Forms.GroupBox();
this.buttonDeleteName = new System.Windows.Forms.Button();
this.buttonEditName = new System.Windows.Forms.Button();
this.buttonCreateName = new System.Windows.Forms.Button();
this.buttonExport = new System.Windows.Forms.Button();
this.buttonImport = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button();
this.groupBoxTypes.SuspendLayout();
this.groupBoxButtons.SuspendLayout();
this.SuspendLayout();
//
// groupBoxTypes
//
this.groupBoxTypes.Controls.Add(this.buttonFastTools);
this.groupBoxTypes.Controls.Add(this.buttonShortKeys);
this.groupBoxTypes.Controls.Add(this.buttonTopTools);
this.groupBoxTypes.Location = new System.Drawing.Point(13, 13);
this.groupBoxTypes.Name = "groupBoxTypes";
this.groupBoxTypes.Size = new System.Drawing.Size(87, 463);
this.groupBoxTypes.TabIndex = 1;
this.groupBoxTypes.TabStop = false;
this.groupBoxTypes.Text = "类型";
//
// buttonFastTools
//
this.buttonFastTools.BackColor = System.Drawing.SystemColors.ControlDark;
this.buttonFastTools.BtnSelect = false;
this.buttonFastTools.BtnText = "按钮";
this.buttonFastTools.Location = new System.Drawing.Point(6, 83);
this.buttonFastTools.Name = "buttonFastTools";
this.buttonFastTools.Size = new System.Drawing.Size(75, 23);
this.buttonFastTools.TabIndex = 2;
this.buttonFastTools.Click += new System.EventHandler(this.buttonFastToolsClick);
//
// buttonShortKeys
//
this.buttonShortKeys.BackColor = System.Drawing.SystemColors.ControlDark;
this.buttonShortKeys.BtnSelect = false;
this.buttonShortKeys.BtnText = "按钮";
this.buttonShortKeys.Location = new System.Drawing.Point(6, 53);
this.buttonShortKeys.Name = "buttonShortKeys";
this.buttonShortKeys.Size = new System.Drawing.Size(75, 23);
this.buttonShortKeys.TabIndex = 1;
this.buttonShortKeys.Click += new System.EventHandler(this.buttonShortKeysClick);
//
// buttonTopTools
//
this.buttonTopTools.BackColor = System.Drawing.SystemColors.ControlDark;
this.buttonTopTools.BtnSelect = false;
this.buttonTopTools.BtnText = "按钮";
this.buttonTopTools.Location = new System.Drawing.Point(6, 23);
this.buttonTopTools.Name = "buttonTopTools";
this.buttonTopTools.Size = new System.Drawing.Size(75, 23);
this.buttonTopTools.TabIndex = 0;
this.buttonTopTools.Click += new System.EventHandler(this.buttonTopToolsClick);
//
// groupBoxButtons
//
this.groupBoxButtons.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBoxButtons.Controls.Add(this.buttonDeleteName);
this.groupBoxButtons.Controls.Add(this.buttonEditName);
this.groupBoxButtons.Controls.Add(this.buttonCreateName);
this.groupBoxButtons.Controls.Add(this.buttonExport);
this.groupBoxButtons.Controls.Add(this.buttonImport);
this.groupBoxButtons.Controls.Add(this.buttonSave);
this.groupBoxButtons.Location = new System.Drawing.Point(107, 13);
this.groupBoxButtons.Name = "groupBoxButtons";
this.groupBoxButtons.Size = new System.Drawing.Size(623, 58);
this.groupBoxButtons.TabIndex = 2;
this.groupBoxButtons.TabStop = false;
this.groupBoxButtons.Text = "操作";
//
// buttonDeleteName
//
this.buttonDeleteName.Location = new System.Drawing.Point(461, 23);
this.buttonDeleteName.Name = "buttonDeleteName";
this.buttonDeleteName.Size = new System.Drawing.Size(75, 23);
this.buttonDeleteName.TabIndex = 5;
this.buttonDeleteName.Text = "删除";
this.buttonDeleteName.UseVisualStyleBackColor = true;
this.buttonDeleteName.Click += new System.EventHandler(this.buttonDeleteNameClick);
//
// buttonEditName
//
this.buttonEditName.Location = new System.Drawing.Point(379, 23);
this.buttonEditName.Name = "buttonEditName";
this.buttonEditName.Size = new System.Drawing.Size(75, 23);
this.buttonEditName.TabIndex = 4;
this.buttonEditName.Text = "重命名";
this.buttonEditName.UseVisualStyleBackColor = true;
this.buttonEditName.Click += new System.EventHandler(this.buttonEditNameClick);
//
// buttonCreateName
//
this.buttonCreateName.Location = new System.Drawing.Point(297, 23);
this.buttonCreateName.Name = "buttonCreateName";
this.buttonCreateName.Size = new System.Drawing.Size(75, 23);
this.buttonCreateName.TabIndex = 3;
this.buttonCreateName.Text = "新建";
this.buttonCreateName.UseVisualStyleBackColor = true;
this.buttonCreateName.Click += new System.EventHandler(this.buttonCreateNameClick);
//
// buttonExport
//
this.buttonExport.Location = new System.Drawing.Point(135, 23);
this.buttonExport.Name = "buttonExport";
this.buttonExport.Size = new System.Drawing.Size(75, 23);
this.buttonExport.TabIndex = 2;
this.buttonExport.Text = "导出配置";
this.buttonExport.UseVisualStyleBackColor = true;
this.buttonExport.Click += new System.EventHandler(this.buttonExportClick);
//
// buttonImport
//
this.buttonImport.Location = new System.Drawing.Point(216, 23);
this.buttonImport.Name = "buttonImport";
this.buttonImport.Size = new System.Drawing.Size(75, 23);
this.buttonImport.TabIndex = 1;
this.buttonImport.Text = "导入配置";
this.buttonImport.UseVisualStyleBackColor = true;
this.buttonImport.Click += new System.EventHandler(this.buttonImportClick);
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(542, 23);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(75, 23);
this.buttonSave.TabIndex = 0;
this.buttonSave.Text = "保存";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSaveClick);
//
// CustomInterfaceDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.ClientSize = new System.Drawing.Size(742, 488);
this.Controls.Add(this.groupBoxButtons);
this.Controls.Add(this.groupBoxTypes);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CustomInterfaceDialog";
this.Text = "自定义界面";
this.Controls.SetChildIndex(this.groupBoxTypes, 0);
this.Controls.SetChildIndex(this.groupBoxButtons, 0);
this.groupBoxTypes.ResumeLayout(false);
this.groupBoxButtons.ResumeLayout(false);
this.ResumeLayout(false);
}
///
/// 工具栏
///
///
///
private void buttonTopToolsClick(object sender, EventArgs e)
{
if (currentInedx != 1)
{
//设置按钮的选中/非选择的状态
buttonTopTools.BtnSelect = true;
buttonShortKeys.BtnSelect = false;
buttonFastTools.BtnSelect = false;
this.Controls.Remove(this.shortKeys);
this.Controls.Remove(this.fastTools);
this.topTools.Location = new System.Drawing.Point(107, 78);
this.Controls.Add(this.topTools);
currentInedx = 1;
this.buttonSave.Text = PdnResources.GetString("Menu.File.Save.Text");
}
ChangeButtonByIndex();
}
///
/// 快捷键
///
///
///
private void buttonShortKeysClick(object sender, EventArgs e)
{
if (currentInedx != 2)
{
//设置按钮的选中/非选择的状态
buttonShortKeys.BtnSelect = true;
buttonFastTools.BtnSelect = false;
buttonTopTools.BtnSelect = false;
this.Controls.Remove(this.topTools);
this.Controls.Remove(this.fastTools);
this.shortKeys.Location = new System.Drawing.Point(107, 78);
this.Controls.Add(this.shortKeys);
currentInedx = 2;
this.buttonSave.Text = PdnResources.GetString("Menu.File.Close.Text");//#17140
}
ChangeButtonByIndex();
}
///
/// 快捷栏
///
///
///
private void buttonFastToolsClick(object sender, EventArgs e)
{
if (currentInedx != 3)
{
//设置按钮的选中/非选择的状态
buttonFastTools.BtnSelect = true;
buttonTopTools.BtnSelect = false;
buttonShortKeys.BtnSelect = false;
this.Controls.Remove(this.topTools);
this.Controls.Remove(this.shortKeys);
this.fastTools.Location = new System.Drawing.Point(107, 78);
this.Controls.Add(this.fastTools);
currentInedx = 3;
this.buttonSave.Text = PdnResources.GetString("Menu.File.Save.Text");
}
ChangeButtonByIndex();
}
private void ChangeButtonByIndex()
{
//6 135, 23
//5 216, 23
//7 297, 23 隐藏显示
//8 379, 23 隐藏显示
//9 461, 23 隐藏显示
//4 542, 23
switch (currentInedx)
{
case 1:
this.buttonCreateName.Visible = true;
this.buttonEditName.Visible = true;
this.buttonDeleteName.Visible = true;
this.buttonSave.Visible = false;//自定义菜单实时保存 导入配置重启生效 (这里可以去掉保存按钮了,因为实时保存,以及导入配置还差实时保存更新,或者提示“软件重启后生效”)
this.buttonExport.Location = new System.Drawing.Point(135 + 81, 23);
this.buttonImport.Location = new System.Drawing.Point(216 + 81, 23);
this.buttonCreateName.Location = new System.Drawing.Point(297 + 81, 23);
this.buttonEditName.Location = new System.Drawing.Point(379 + 81, 23);
this.buttonDeleteName.Location = new System.Drawing.Point(461 + 81, 23);
//this.buttonSave.Location = new System.Drawing.Point(542, 23);
break;
case 2:
this.buttonCreateName.Visible = false;
this.buttonEditName.Visible = false;
this.buttonDeleteName.Visible = false;
this.buttonSave.Visible = true;
this.buttonExport.Location = new System.Drawing.Point(379, 23);
this.buttonImport.Location = new System.Drawing.Point(461, 23);
this.buttonSave.Location = new System.Drawing.Point(542, 23);
break;
case 3:
this.buttonCreateName.Visible = false;
this.buttonEditName.Visible = false;
this.buttonDeleteName.Visible = false;
this.buttonSave.Visible = true;
this.buttonExport.Location = new System.Drawing.Point(379, 23);
this.buttonImport.Location = new System.Drawing.Point(461, 23);
this.buttonSave.Location = new System.Drawing.Point(542, 23);
break;
}
}
///
/// 保存
///
///
///
private void buttonSaveClick(object sender, EventArgs e)
{
switch (currentInedx)
{
case 1: //1工具栏
this.topTools.SaveToolbar();
break;
case 2: //2快捷键
this.Close();
//SaveShortcutKeys()???
break;
case 3: //3快捷栏
this.fastTools.SaveToolbar();
break;
}
//this.Close();
}
///
/// 删除
///
///
///
private void buttonDeleteNameClick(object sender, EventArgs e)
{
if(currentInedx==1) //1工具栏
{
if (MessageBox.Show(PdnResources.GetString("Menu.Areyousuretodelete.Text")+"?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) == DialogResult.OK)
{
this.topTools.TreeView2Delete();
}
}
}
///
/// 重命名
///
///
///
private void buttonEditNameClick(object sender, EventArgs e)
{
if(this.topTools.treeViewLeft.SelectedNode!=null)
{
istoCreate = false;
createNameDialog = new CreateNameDialog(this);
createNameDialog.SetThisText(PdnResources.GetString("Menu.tool.Generateshortcut.Edittoolbar.text"));
createNameDialog.SetTextBoxValue(this.topTools.GetSelectedNodeText());
createNameDialog.StartPosition = FormStartPosition.CenterParent;
createNameDialog.ShowDialog();
}
else
{
MessageBox.Show(PdnResources.GetString("Menu.leaseselectthetoolbarnode.Text"));
}
}
///
/// 新建
///
///
///
private void buttonCreateNameClick(object sender, EventArgs e)
{
istoCreate = true;
createNameDialog = new CreateNameDialog(this);
createNameDialog.SetThisText(PdnResources.GetString("Menu.tool.Generateshortcut.Newtoolbar.text"));
createNameDialog.StartPosition = FormStartPosition.CenterParent;
createNameDialog.ShowDialog();
}
///
/// 导入配置
///
///
///
private void buttonImportClick(object sender, EventArgs e)
{
switch (currentInedx)
{
case 1: //1工具栏
this.topTools.ImportToolbarXml();
break;
case 2: //2快捷键
this.shortKeys.ImportToolbarXml();
break;
case 3: //3快捷栏
this.fastTools.ImportToolbarXml();
break;
}
}
///
/// 导出配置
///
///
///
private void buttonExportClick(object sender, EventArgs e)
{
switch (currentInedx)
{
case 1: //1工具栏
this.topTools.ExportToolbarXml();
break;
case 2: //2快捷键
this.shortKeys.ExportToolbarXml();
break;
case 3: //3快捷栏
this.fastTools.ExportToolbarXml();
break;
}
}
///
/// 获取新建窗口里面输入的名称
///
///
public override void GetCreateName(string name)
{
if (!name.Equals(""))
{
if (istoCreate) //新增
{
this.topTools.CreateTreeView2Node(name);
}
else //重命名
{
this.topTools.ReNameTreeView2Node(name);
}
createNameDialog.Close();
}
else
{
MessageBox.Show(PdnResources.GetString("Menu.leaseenterworkflowname.Text"));
}
}
///
/// 重命名按钮的可用状态
///
///
public void RenameButtonStatus(bool canuse)
{
this.buttonEditName.Enabled = canuse;
}
///
/// 删除按钮的可用状态
///
///
public void DeleteButtonStatus(bool canuse)
{
this.buttonDeleteName.Enabled = canuse;
}
}
}