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 System.IO;
using Mesnac.Gui.Edit.Global;
using Mesnac.Gui.Edit.Common;
namespace Mesnac.Gui.Edit.Dialog
{
public partial class FrmTemplateList : Form
{
private readonly string _templatePath = Application.StartupPath + AppConfigHandler.Instance.TemplatePath; //模板文件路径
private string _templateName = String.Empty; //模板名称
private string _selectTemplate = String.Empty; //选则的模板名称
private string _selectTemplatePath = String.Empty; //选择的模板路径
private bool exitFlag = false; //是否退出对话框
private string caption = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_Caption"));
private string msg = String.Empty;
///
/// 带参数构造方法
///
/// 模板名称
public FrmTemplateList(string templateName)
{
this._templateName = templateName;
InitializeComponent();
}
private void FrmTemplateList_Load(object sender, EventArgs e)
{
this.InitUIMethod();
this.listView1.Items.Clear();
string templateFullPath = Path.Combine(this._templatePath, this._templateName);
if (Directory.Exists(templateFullPath))
{
DirectoryInfo dir = new DirectoryInfo(templateFullPath);
IEnumerable subDirs = dir.EnumerateDirectories();
foreach (DirectoryInfo di in subDirs)
{
ListViewItem item = new ListViewItem();
item.Text = di.Name;
item.Tag = di.FullName;
item.SubItems.Add(di.FullName);
this.listView1.Items.Add(item);
}
this.listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
}
else
{
LoggingService.Warn("模板目录不存在!");
}
}
///
/// 初始化界面元素
///
public void InitUIMethod()
{
this.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_FrmTemplateList_Text"));
this.groupBox1.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_FrmTemplateList_groupBox1"));
this.btnOk.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_btnOK"));
this.btnCancel.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_btnCancel"));
this.listView1.Columns[0].Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_FrmTemplateList_listView1_columnName"));
this.listView1.Columns[1].Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_FrmTemplateList_listView1_columnComment"));
}
///
/// 选择的模板名称
///
public string SelectTemplate
{
get { return _selectTemplate; }
}
///
/// 选择的模板路径
///
public string SelectTemplatePath
{
get { return _selectTemplatePath; }
}
private void btnOk_Click(object sender, EventArgs e)
{
if (this.listView1.SelectedItems.Count == 0)
{
this.msg = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_FrmTemplateList_Msg1")); //请选择项目模板!
MessageBox.Show(this.msg, this.caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
this.exitFlag = false;
}
else
{
this._selectTemplate = this.listView1.SelectedItems[0].Text;
this._selectTemplatePath = this.listView1.SelectedItems[0].Tag.ToString();
this.exitFlag = true;
}
}
private void FrmTemplateList_FormClosing(object sender, FormClosingEventArgs e)
{
if (!this.exitFlag)
{
e.Cancel = true;
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.exitFlag = true;
}
}
}