📄 managedictionariesform.cs
字号:
//#define use_ds
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace DLTool
{
/// <summary>
/// Summary description for ManageDictionariesForm.
/// </summary>
public class ManageDictionariesForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button m_doneButton;
private System.Windows.Forms.Button m_cancelButton;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button m_newButton;
private System.Windows.Forms.Button m_deleteButton;
private System.Windows.Forms.Button m_browseButton;
private System.Windows.Forms.TextBox m_nameTextBox;
private System.Windows.Forms.TextBox m_filenameTextBox;
private System.Windows.Forms.TextBox m_codePageTextBox;
private System.Windows.Forms.OpenFileDialog m_openFileDialog;
private System.Windows.Forms.ListBox m_listBox;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public ManageDictionariesForm( ArrayList dictDefs )
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.DictionaryDefinitions = dictDefs;
#if use_ds
m_listBox.DataSource = DictionaryDefinitions;
m_listBox.DisplayMember = "Language";
m_listBox.ValueMember = "Language";
#else
foreach ( object o in dictDefs )
{
m_listBox.Items.Add(
new DictDefListItem( o as DictionaryDefinition ) );
}
#endif
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.m_listBox = new System.Windows.Forms.ListBox();
this.m_doneButton = new System.Windows.Forms.Button();
this.m_cancelButton = new System.Windows.Forms.Button();
this.m_nameTextBox = new System.Windows.Forms.TextBox();
this.m_filenameTextBox = new System.Windows.Forms.TextBox();
this.m_codePageTextBox = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.m_newButton = new System.Windows.Forms.Button();
this.m_deleteButton = new System.Windows.Forms.Button();
this.m_browseButton = new System.Windows.Forms.Button();
this.m_openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.SuspendLayout();
//
// m_listBox
//
this.m_listBox.ItemHeight = 12;
this.m_listBox.Location = new System.Drawing.Point(0, 0);
this.m_listBox.Name = "m_listBox";
this.m_listBox.Size = new System.Drawing.Size(360, 112);
this.m_listBox.TabIndex = 4;
this.m_listBox.SelectedIndexChanged += new System.EventHandler(this.m_listBox_SelectedIndexChanged);
//
// m_doneButton
//
this.m_doneButton.Location = new System.Drawing.Point(24, 120);
this.m_doneButton.Name = "m_doneButton";
this.m_doneButton.Size = new System.Drawing.Size(64, 30);
this.m_doneButton.TabIndex = 0;
this.m_doneButton.Text = "完成";
this.m_doneButton.Click += new System.EventHandler(this.m_doneButton_Click);
//
// m_cancelButton
//
this.m_cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.m_cancelButton.Location = new System.Drawing.Point(104, 120);
this.m_cancelButton.Name = "m_cancelButton";
this.m_cancelButton.Size = new System.Drawing.Size(64, 29);
this.m_cancelButton.TabIndex = 1;
this.m_cancelButton.Text = "取消";
this.m_cancelButton.Click += new System.EventHandler(this.m_cancelButton_Click);
//
// m_nameTextBox
//
this.m_nameTextBox.Enabled = false;
this.m_nameTextBox.Location = new System.Drawing.Point(104, 168);
this.m_nameTextBox.MaxLength = 50;
this.m_nameTextBox.Name = "m_nameTextBox";
this.m_nameTextBox.Size = new System.Drawing.Size(152, 21);
this.m_nameTextBox.TabIndex = 5;
this.m_nameTextBox.Text = "";
this.m_nameTextBox.TextChanged += new System.EventHandler(this.m_nameTextBox_TextChanged);
//
// m_filenameTextBox
//
this.m_filenameTextBox.Enabled = false;
this.m_filenameTextBox.Location = new System.Drawing.Point(104, 216);
this.m_filenameTextBox.Name = "m_filenameTextBox";
this.m_filenameTextBox.Size = new System.Drawing.Size(152, 21);
this.m_filenameTextBox.TabIndex = 7;
this.m_filenameTextBox.Text = "";
this.m_filenameTextBox.TextChanged += new System.EventHandler(this.m_filenameTextBox_TextChanged);
//
// m_codePageTextBox
//
this.m_codePageTextBox.Enabled = false;
this.m_codePageTextBox.Location = new System.Drawing.Point(104, 192);
this.m_codePageTextBox.Name = "m_codePageTextBox";
this.m_codePageTextBox.Size = new System.Drawing.Size(152, 21);
this.m_codePageTextBox.TabIndex = 6;
this.m_codePageTextBox.Text = "";
this.m_codePageTextBox.TextChanged += new System.EventHandler(this.m_codePageTextBox_TextChanged);
//
// label1
//
this.label1.Location = new System.Drawing.Point(0, 168);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(88, 21);
this.label1.TabIndex = 9;
this.label1.Text = "字典名称:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label2
//
this.label2.Location = new System.Drawing.Point(-8, 216);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(96, 21);
this.label2.TabIndex = 11;
this.label2.Text = "字典位置:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label3
//
this.label3.Location = new System.Drawing.Point(0, 192);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(88, 22);
this.label3.TabIndex = 10;
this.label3.Text = "代码页:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// m_newButton
//
this.m_newButton.Location = new System.Drawing.Point(184, 120);
this.m_newButton.Name = "m_newButton";
this.m_newButton.Size = new System.Drawing.Size(64, 30);
this.m_newButton.TabIndex = 2;
this.m_newButton.Text = "新建";
this.m_newButton.Click += new System.EventHandler(this.m_newButton_Click);
//
// m_deleteButton
//
this.m_deleteButton.Location = new System.Drawing.Point(264, 120);
this.m_deleteButton.Name = "m_deleteButton";
this.m_deleteButton.Size = new System.Drawing.Size(64, 30);
this.m_deleteButton.TabIndex = 3;
this.m_deleteButton.Text = "删除";
this.m_deleteButton.Click += new System.EventHandler(this.m_deleteButton_Click);
//
// m_browseButton
//
this.m_browseButton.Enabled = false;
this.m_browseButton.Location = new System.Drawing.Point(264, 216);
this.m_browseButton.Name = "m_browseButton";
this.m_browseButton.Size = new System.Drawing.Size(64, 24);
this.m_browseButton.TabIndex = 8;
this.m_browseButton.Text = "浏览";
this.m_browseButton.Click += new System.EventHandler(this.m_browseButton_Click);
//
// ManageDictionariesForm
//
this.AcceptButton = this.m_doneButton;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.CancelButton = this.m_cancelButton;
this.ClientSize = new System.Drawing.Size(360, 365);
this.Controls.Add(this.m_browseButton);
this.Controls.Add(this.m_deleteButton);
this.Controls.Add(this.m_newButton);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.m_codePageTextBox);
this.Controls.Add(this.m_filenameTextBox);
this.Controls.Add(this.m_nameTextBox);
this.Controls.Add(this.m_cancelButton);
this.Controls.Add(this.m_doneButton);
this.Controls.Add(this.m_listBox);
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(368, 392);
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(368, 392);
this.Name = "ManageDictionariesForm";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.Text = "字典管理器";
this.TopMost = true;
this.Load += new System.EventHandler(this.ManageDictionariesForm_Load);
this.ResumeLayout(false);
}
#endregion
private class DictDefListItem
{
public DictionaryDefinition DictDef;
public DictDefListItem(DictionaryDefinition def )
{
DictDef = def;
}
public override string ToString()
{
return DictDef.Language;
}
}
public ArrayList DictionaryDefinitions;
private void m_doneButton_Click(object sender, System.EventArgs e)
{
this.DictionaryDefinitions.Clear();
#if use_ds
foreach( object o in m_listBox.Items )
{
// make sure no two entries have the same name
DictionaryDefinition first = o as DictionaryDefinition;
foreach( object j in m_listBox.Items )
{
if( o == j ) continue;
DictionaryDefinition second = j as DictionaryDefinition;
if( first.Language.Equals( second.Language ) )
{
MessageBox.Show("Can't have two dictionaries with same name!!");
return;
}
}
// make sure dictionary file is accessible
if( ! System.IO.File.Exists( first.Filename ) )
{
MessageBox.Show("Can't find dictionary file " + first.Filename );
return;
}
this.DictionaryDefinitions.Add( first );
}
#else
foreach( object o in m_listBox.Items )
{
// make sure no two entries have the same name
DictDefListItem first = o as DictDefListItem;
foreach( object j in m_listBox.Items )
{
if( o == j ) continue;
DictDefListItem second = j as DictDefListItem;
if( first.DictDef.Language.Equals( second.DictDef.Language ) )
{
MessageBox.Show("Can't have two dictionaries with same name!!");
return;
}
}
// make sure dictionary file is accessible
if( ! System.IO.File.Exists( first.DictDef.Filename ) )
{
MessageBox.Show("Can't find dictionary file " + first.DictDef.Filename );
return;
}
this.DictionaryDefinitions.Add( first.DictDef );
}
#endif
this.DialogResult = DialogResult.OK;
this.Close();
}
private void m_cancelButton_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
private void m_newButton_Click(object sender, System.EventArgs e)
{
DictionaryDefinition def = new DictionaryDefinition();
def.Language = "new dictionary";
#if use_ds
m_listBox.Items.Add( def );
#else
this.m_listBox.Items.Add( new DictDefListItem( def ) );
#endif
}
private void m_deleteButton_Click(object sender, System.EventArgs e)
{
if( m_listBox.SelectedItem != null )
{
m_listBox.Items.Remove( m_listBox.SelectedItem );
}
}
private void m_browseButton_Click(object sender, System.EventArgs e)
{
DialogResult result = m_openFileDialog.ShowDialog();
if( result != DialogResult.OK ) return;
this.m_filenameTextBox.Text = m_openFileDialog.FileName;
}
private void m_listBox_SelectedIndexChanged(object sender, System.EventArgs e)
{
// System.Diagnostics.Trace.WriteLine(sender.ToString(), "SDFL");
// System.Diagnostics.Trace.WriteLine("si: " + m_listBox.SelectedItem.ToString() );
#if use_ds
DictionaryDefinition def = m_listBox.SelectedItem as DictionaryDefinition;
if( def != null )
#else
DictDefListItem item = m_listBox.SelectedItem as DictDefListItem;
if( item == null )
#endif
{
m_nameTextBox.Enabled = false;
m_codePageTextBox.Enabled = false;
m_filenameTextBox.Enabled = false;
m_browseButton.Enabled = false;
m_nameTextBox.Text = "";
m_codePageTextBox.Text = "";
m_filenameTextBox.Text = "";
}
else
{
m_nameTextBox.Enabled = true;
m_codePageTextBox.Enabled = true;
m_filenameTextBox.Enabled = true;
m_browseButton.Enabled = true;
#if use_ds
m_nameTextBox.Text = def.Language;
m_codePageTextBox.Text = def.CodePage.ToString();
m_filenameTextBox.Text = def.Filename;
#else
m_nameTextBox.Text = item.DictDef.Language;
m_codePageTextBox.Text = item.DictDef.CodePage.ToString();
m_filenameTextBox.Text = item.DictDef.Filename;
#endif
}
}
private void m_nameTextBox_TextChanged(object sender, System.EventArgs e)
{
if( sender != m_nameTextBox ) return;
#if use_ds
DictionaryDefinition def = m_listBox.SelectedItem as DictionaryDefinition;
if( def != null ) def.Language = m_nameTextBox.Text;
#else
DictDefListItem item = m_listBox.SelectedItem as DictDefListItem;
if( item != null )
{
item.DictDef.Language = m_nameTextBox.Text;
// m_listBox.Items[m_listBox.SelectedIndex] = item;
// int index = m_listBox.SelectedIndex;
// m_listBox.Items.Remove( item );
// m_listBox.Items.Insert( index, new DictDefListItem( item DictDef ) );
// m_listBox.SelectedIndex = index;
}
#endif
}
private void m_codePageTextBox_TextChanged(object sender, System.EventArgs e)
{
if( sender != m_codePageTextBox ) return;
#if use_ds
DictionaryDefinition def = m_listBox.SelectedItem as DictionaryDefinition;
if( def != null )
{
try
{
def.CodePage = int.Parse( m_codePageTextBox.Text );
}
catch( System.FormatException )
{
// nothing...
}
}
#else
DictDefListItem item = m_listBox.SelectedItem as DictDefListItem;
if( item != null )
{
try
{
item.DictDef.CodePage = int.Parse( m_codePageTextBox.Text );
}
catch( System.FormatException )
{
// nothing...
}
}
#endif
}
private void m_filenameTextBox_TextChanged(object sender, System.EventArgs e)
{
// System.Diagnostics.Trace.WriteLine("sender: " + sender.ToString());
if( sender != m_filenameTextBox ) return;
#if use_ds
DictionaryDefinition def = m_listBox.SelectedItem as DictionaryDefinition;
if( def != null ) def.Filename = m_filenameTextBox.Text;
#else
DictDefListItem item = m_listBox.SelectedItem as DictDefListItem;
if( item != null )
{
item.DictDef.Filename = m_filenameTextBox.Text;
}
#endif
}
private void ManageDictionariesForm_Load(object sender, System.EventArgs e) {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -