You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
5.0 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.Core;
using Mesnac.Basic;
using Mesnac.Gui.Edit.Pad;
using Mesnac.Gui.Edit.ViewContent;
namespace Mesnac.Gui.Edit.Dialog
{
public partial class FrmNew : Form
{
#region 定义变量
private string fileName = String.Empty;
private CreateType _createType = CreateType.Form;
private string caption = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_Caption"));
#endregion
#region 构造方法
public FrmNew(string fileName)
{
this.fileName = fileName;
InitializeComponent();
}
public FrmNew(string fileName, CreateType createType)
{
this.fileName = fileName;
InitializeComponent();
this._createType = createType;
}
#endregion
#region 窗体加载
private void FrmNew_Load(object sender, EventArgs e)
{
this.InitUIMethod();
this.InitData();
}
#endregion
#region 界面初始化
public void InitUIMethod()
{
this.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_FrmNew_Text"));
if (this._createType == CreateType.Form)
{
this.label1.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_FrmNew_label1"));
}
else if (this._createType == CreateType.Command)
{
this.label1.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_FrmNew_label1_Command"));
this.label2.Visible = false;
this.txtNodeName.Visible = false;
}
this.label2.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_FrmNew_label2"));
this.btnAdd.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_FrmNew_btnAdd"));
this.btnCancel.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_btnCancel"));
}
#endregion
#region 数据初始化
public void InitData()
{
this.txtFileName.Text = fileName;
}
#endregion
#region 属性定义
/// <summary>
/// 新建文件的文件名
/// </summary>
public string FileName
{
get
{
return this.txtFileName.Text;
}
}
/// <summary>
/// 节点名称
/// </summary>
public string NodeName
{
get
{
return this.txtNodeName.Text;
}
}
#endregion
#region 添加
private void btnAdd_Click(object sender, EventArgs e)
{
string msg = String.Empty;
if (String.IsNullOrEmpty(this.txtFileName.Text.Trim()))
{
msg = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_FrmNew_Msg1")); //"新建文件名不能为空!"
MessageBox.Show(msg, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
bool flag = false;
if (this._createType == CreateType.Form)
{
foreach (Mesnac.PlugIn.View.IViewContent vc in Mesnac.Gui.Workbench.WorkbenchSingleton.Workbench.ViewContentCollection)
{
if (vc.TitleName == this.txtFileName.Text.Trim())
{
flag = true;
break;
}
}
}
else if (this._createType == CreateType.Command)
{
ProjectWindow projectWindow = DisplayUtil<ProjectWindow>.PadInstance;
if (projectWindow != null)
{
if (projectWindow.Tree.GetFirstNodeByNodeName(this.txtFileName.Text.Trim()) != null)
{
flag = true;
}
}
}
if (flag)
{
msg = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_FrmNew_Msg2")); //工程中已经存在此文件,请先删除或使用新名称!
MessageBox.Show(msg, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
}
}
#endregion
#region 取消
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
}
#endregion
}
}