Commit b9be8388 authored by keyongyu's avatar keyongyu

LanguageHelper

parent 5491a5a2
...@@ -246,7 +246,7 @@ bool savefile(bool saveas) ...@@ -246,7 +246,7 @@ bool savefile(bool saveas)
{ {
using (SaveFileDialog sfdlg = new SaveFileDialog()) using (SaveFileDialog sfdlg = new SaveFileDialog())
{ {
sfdlg.Filter = LANG.GetMsg(LMSG.ScriptFilter); sfdlg.Filter = LanguageHelper.GetMsg(LMSG.ScriptFilter);
if (sfdlg.ShowDialog() == DialogResult.OK) if (sfdlg.ShowDialog() == DialogResult.OK)
{ {
nowFile = sfdlg.FileName; nowFile = sfdlg.FileName;
...@@ -323,9 +323,9 @@ void QuitToolStripMenuItemClick(object sender, EventArgs e) ...@@ -323,9 +323,9 @@ void QuitToolStripMenuItemClick(object sender, EventArgs e)
void AboutToolStripMenuItemClick(object sender, EventArgs e) void AboutToolStripMenuItemClick(object sender, EventArgs e)
{ {
MyMsg.Show( MyMsg.Show(
LANG.GetMsg(LMSG.About) + "\t" + Application.ProductName + "\n" LanguageHelper.GetMsg(LMSG.About) + "\t" + Application.ProductName + "\n"
+ LANG.GetMsg(LMSG.Version) + "\t1.1.0.0\n" + LanguageHelper.GetMsg(LMSG.Version) + "\t1.1.0.0\n"
+ LANG.GetMsg(LMSG.Author) + "\t柯永裕\n" + LanguageHelper.GetMsg(LMSG.Author) + "\t柯永裕\n"
+ "Email:\t247321453@qq.com"); + "Email:\t247321453@qq.com");
} }
...@@ -333,7 +333,7 @@ void Menuitem_openClick(object sender, EventArgs e) ...@@ -333,7 +333,7 @@ void Menuitem_openClick(object sender, EventArgs e)
{ {
using (OpenFileDialog sfdlg = new OpenFileDialog()) using (OpenFileDialog sfdlg = new OpenFileDialog())
{ {
sfdlg.Filter = LANG.GetMsg(LMSG.ScriptFilter); sfdlg.Filter = LanguageHelper.GetMsg(LMSG.ScriptFilter);
if (sfdlg.ShowDialog() == DialogResult.OK) if (sfdlg.ShowDialog() == DialogResult.OK)
{ {
nowFile = sfdlg.FileName; nowFile = sfdlg.FileName;
......
...@@ -14,6 +14,8 @@ namespace DataEditorX.Config ...@@ -14,6 +14,8 @@ namespace DataEditorX.Config
public class MyConfig : XMLReader public class MyConfig : XMLReader
{ {
#region 常量 #region 常量
public const string TAG_SAVE_LAGN = "-savelanguage";
public const string TAG_SAVE_LAGN2 = "-sl";
/// <summary> /// <summary>
/// 窗口消息 打开文件 /// 窗口消息 打开文件
/// </summary> /// </summary>
......
...@@ -108,7 +108,7 @@ public void MenuHistory() ...@@ -108,7 +108,7 @@ public void MenuHistory()
mainForm.AddCdbMenu(tsmi); mainForm.AddCdbMenu(tsmi);
} }
mainForm.AddCdbMenu(new ToolStripSeparator()); mainForm.AddCdbMenu(new ToolStripSeparator());
ToolStripMenuItem tsmiclear = new ToolStripMenuItem(LANG.GetMsg(LMSG.ClearHistory)); ToolStripMenuItem tsmiclear = new ToolStripMenuItem(LanguageHelper.GetMsg(LMSG.ClearHistory));
tsmiclear.Click += MenuHistoryClear_Click; tsmiclear.Click += MenuHistoryClear_Click;
mainForm.AddCdbMenu(tsmiclear); mainForm.AddCdbMenu(tsmiclear);
//lua历史 //lua历史
...@@ -120,7 +120,7 @@ public void MenuHistory() ...@@ -120,7 +120,7 @@ public void MenuHistory()
mainForm.AddLuaMenu(tsmi); mainForm.AddLuaMenu(tsmi);
} }
mainForm.AddLuaMenu(new ToolStripSeparator()); mainForm.AddLuaMenu(new ToolStripSeparator());
ToolStripMenuItem tsmiclear2 = new ToolStripMenuItem(LANG.GetMsg(LMSG.ClearHistory)); ToolStripMenuItem tsmiclear2 = new ToolStripMenuItem(LanguageHelper.GetMsg(LMSG.ClearHistory));
tsmiclear2.Click += MenuHistoryClear2_Click; tsmiclear2.Click += MenuHistoryClear2_Click;
mainForm.AddLuaMenu(tsmiclear2); mainForm.AddLuaMenu(tsmiclear2);
} }
......
...@@ -824,9 +824,9 @@ void Tb_edittextTextChanged(object sender, EventArgs e) ...@@ -824,9 +824,9 @@ void Tb_edittextTextChanged(object sender, EventArgs e)
void Menuitem_aboutClick(object sender, EventArgs e) void Menuitem_aboutClick(object sender, EventArgs e)
{ {
MyMsg.Show( MyMsg.Show(
LANG.GetMsg(LMSG.About) + "\t" + Application.ProductName + "\n" LanguageHelper.GetMsg(LMSG.About) + "\t" + Application.ProductName + "\n"
+ LANG.GetMsg(LMSG.Version) + "\t" + Application.ProductVersion + "\n" + LanguageHelper.GetMsg(LMSG.Version) + "\t" + Application.ProductVersion + "\n"
+ LANG.GetMsg(LMSG.Author) + "\t柯永裕\n" + LanguageHelper.GetMsg(LMSG.Author) + "\t柯永裕\n"
+ "Email:\t247321453@qq.com"); + "Email:\t247321453@qq.com");
} }
...@@ -839,7 +839,7 @@ public void CheckUpdate(bool showNew) ...@@ -839,7 +839,7 @@ public void CheckUpdate(bool showNew)
if (!isRun()) if (!isRun())
{ {
tasker.SetTask(MyTask.CheckUpdate, null, showNew.ToString()); tasker.SetTask(MyTask.CheckUpdate, null, showNew.ToString());
Run(LANG.GetMsg(LMSG.checkUpdate)); Run(LanguageHelper.GetMsg(LMSG.checkUpdate));
} }
} }
bool CancelTask() bool CancelTask()
...@@ -874,8 +874,8 @@ void Menuitem_openClick(object sender, EventArgs e) ...@@ -874,8 +874,8 @@ void Menuitem_openClick(object sender, EventArgs e)
{ {
using (OpenFileDialog dlg = new OpenFileDialog()) using (OpenFileDialog dlg = new OpenFileDialog())
{ {
dlg.Title = LANG.GetMsg(LMSG.SelectDataBasePath); dlg.Title = LanguageHelper.GetMsg(LMSG.SelectDataBasePath);
dlg.Filter = LANG.GetMsg(LMSG.CdbType); dlg.Filter = LanguageHelper.GetMsg(LMSG.CdbType);
if (dlg.ShowDialog() == DialogResult.OK) if (dlg.ShowDialog() == DialogResult.OK)
{ {
Open(dlg.FileName); Open(dlg.FileName);
...@@ -887,8 +887,8 @@ void Menuitem_newClick(object sender, EventArgs e) ...@@ -887,8 +887,8 @@ void Menuitem_newClick(object sender, EventArgs e)
{ {
using (SaveFileDialog dlg = new SaveFileDialog()) using (SaveFileDialog dlg = new SaveFileDialog())
{ {
dlg.Title = LANG.GetMsg(LMSG.SelectDataBasePath); dlg.Title = LanguageHelper.GetMsg(LMSG.SelectDataBasePath);
dlg.Filter = LANG.GetMsg(LMSG.CdbType); dlg.Filter = LanguageHelper.GetMsg(LMSG.CdbType);
if (dlg.ShowDialog() == DialogResult.OK) if (dlg.ShowDialog() == DialogResult.OK)
{ {
if (DataBase.Create(dlg.FileName)) if (DataBase.Create(dlg.FileName))
...@@ -906,8 +906,8 @@ void Menuitem_readydkClick(object sender, EventArgs e) ...@@ -906,8 +906,8 @@ void Menuitem_readydkClick(object sender, EventArgs e)
return; return;
using (OpenFileDialog dlg = new OpenFileDialog()) using (OpenFileDialog dlg = new OpenFileDialog())
{ {
dlg.Title = LANG.GetMsg(LMSG.SelectYdkPath); dlg.Title = LanguageHelper.GetMsg(LMSG.SelectYdkPath);
dlg.Filter = LANG.GetMsg(LMSG.ydkType); dlg.Filter = LanguageHelper.GetMsg(LMSG.ydkType);
if (dlg.ShowDialog() == DialogResult.OK) if (dlg.ShowDialog() == DialogResult.OK)
{ {
tmpCodes.Clear(); tmpCodes.Clear();
...@@ -925,7 +925,7 @@ void Menuitem_readimagesClick(object sender, EventArgs e) ...@@ -925,7 +925,7 @@ void Menuitem_readimagesClick(object sender, EventArgs e)
return; return;
using (FolderBrowserDialog fdlg = new FolderBrowserDialog()) using (FolderBrowserDialog fdlg = new FolderBrowserDialog())
{ {
fdlg.Description = LANG.GetMsg(LMSG.SelectImagePath); fdlg.Description = LanguageHelper.GetMsg(LMSG.SelectImagePath);
if (fdlg.ShowDialog() == DialogResult.OK) if (fdlg.ShowDialog() == DialogResult.OK)
{ {
tmpCodes.Clear(); tmpCodes.Clear();
...@@ -994,7 +994,7 @@ void BgWorker1RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerC ...@@ -994,7 +994,7 @@ void BgWorker1RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerC
tasker.Cancel(); tasker.Cancel();
if (bgWorker1.IsBusy) if (bgWorker1.IsBusy)
bgWorker1.CancelAsync(); bgWorker1.CancelAsync();
MyMsg.Show(LANG.GetMsg(LMSG.TaskError) + "\n" + e.Error); MyMsg.Show(LanguageHelper.GetMsg(LMSG.TaskError) + "\n" + e.Error);
} }
else if (tasker.IsCancel() || e.Cancelled) else if (tasker.IsCancel() || e.Cancelled)
{//取消任务 {//取消任务
...@@ -1091,8 +1091,8 @@ void CopyTo(Card[] cards) ...@@ -1091,8 +1091,8 @@ void CopyTo(Card[] cards)
string filename = null; string filename = null;
using (OpenFileDialog dlg = new OpenFileDialog()) using (OpenFileDialog dlg = new OpenFileDialog())
{ {
dlg.Title = LANG.GetMsg(LMSG.SelectDataBasePath); dlg.Title = LanguageHelper.GetMsg(LMSG.SelectDataBasePath);
dlg.Filter = LANG.GetMsg(LMSG.CdbType); dlg.Filter = LanguageHelper.GetMsg(LMSG.CdbType);
if (dlg.ShowDialog() == DialogResult.OK) if (dlg.ShowDialog() == DialogResult.OK)
{ {
filename = dlg.FileName; filename = dlg.FileName;
...@@ -1119,7 +1119,7 @@ void Menuitem_cutimagesClick(object sender, EventArgs e) ...@@ -1119,7 +1119,7 @@ void Menuitem_cutimagesClick(object sender, EventArgs e)
bool isreplace = MyMsg.Question(LMSG.IfReplaceExistingImage); bool isreplace = MyMsg.Question(LMSG.IfReplaceExistingImage);
tasker.SetTask(MyTask.CutImages, cardlist.ToArray(), tasker.SetTask(MyTask.CutImages, cardlist.ToArray(),
ygopath.picpath, isreplace.ToString()); ygopath.picpath, isreplace.ToString());
Run(LANG.GetMsg(LMSG.CutImage)); Run(LanguageHelper.GetMsg(LMSG.CutImage));
} }
void Menuitem_saveasmse_selectClick(object sender, EventArgs e) void Menuitem_saveasmse_selectClick(object sender, EventArgs e)
{ {
...@@ -1144,8 +1144,8 @@ void SaveAsMSE(bool onlyselect) ...@@ -1144,8 +1144,8 @@ void SaveAsMSE(bool onlyselect)
//select save mse-set //select save mse-set
using (SaveFileDialog dlg = new SaveFileDialog()) using (SaveFileDialog dlg = new SaveFileDialog())
{ {
dlg.Title = LANG.GetMsg(LMSG.selectMseset); dlg.Title = LanguageHelper.GetMsg(LMSG.selectMseset);
dlg.Filter = LANG.GetMsg(LMSG.MseType); dlg.Filter = LanguageHelper.GetMsg(LMSG.MseType);
if (dlg.ShowDialog() == DialogResult.OK) if (dlg.ShowDialog() == DialogResult.OK)
{ {
bool isUpdate = false; bool isUpdate = false;
...@@ -1154,7 +1154,7 @@ void SaveAsMSE(bool onlyselect) ...@@ -1154,7 +1154,7 @@ void SaveAsMSE(bool onlyselect)
#endif #endif
tasker.SetTask(MyTask.SaveAsMSE, cards, tasker.SetTask(MyTask.SaveAsMSE, cards,
dlg.FileName, isUpdate.ToString()); dlg.FileName, isUpdate.ToString());
Run(LANG.GetMsg(LMSG.SaveMse)); Run(LanguageHelper.GetMsg(LMSG.SaveMse));
} }
} }
} }
...@@ -1168,8 +1168,8 @@ void ImportImageFromSelect() ...@@ -1168,8 +1168,8 @@ void ImportImageFromSelect()
return; return;
using (OpenFileDialog dlg = new OpenFileDialog()) using (OpenFileDialog dlg = new OpenFileDialog())
{ {
dlg.Title = LANG.GetMsg(LMSG.SelectImage) + "-" + tb_cardname.Text; dlg.Title = LanguageHelper.GetMsg(LMSG.SelectImage) + "-" + tb_cardname.Text;
dlg.Filter = LANG.GetMsg(LMSG.ImageType); dlg.Filter = LanguageHelper.GetMsg(LMSG.ImageType);
if (dlg.ShowDialog() == DialogResult.OK) if (dlg.ShowDialog() == DialogResult.OK)
{ {
//dlg.FileName; //dlg.FileName;
...@@ -1264,13 +1264,13 @@ void Menuitem_convertimageClick(object sender, EventArgs e) ...@@ -1264,13 +1264,13 @@ void Menuitem_convertimageClick(object sender, EventArgs e)
return; return;
using (FolderBrowserDialog fdlg = new FolderBrowserDialog()) using (FolderBrowserDialog fdlg = new FolderBrowserDialog())
{ {
fdlg.Description = LANG.GetMsg(LMSG.SelectImagePath); fdlg.Description = LanguageHelper.GetMsg(LMSG.SelectImagePath);
if (fdlg.ShowDialog() == DialogResult.OK) if (fdlg.ShowDialog() == DialogResult.OK)
{ {
bool isreplace = MyMsg.Question(LMSG.IfReplaceExistingImage); bool isreplace = MyMsg.Question(LMSG.IfReplaceExistingImage);
tasker.SetTask(MyTask.ConvertImages, null, tasker.SetTask(MyTask.ConvertImages, null,
fdlg.SelectedPath, ygopath.gamepath, isreplace.ToString()); fdlg.SelectedPath, ygopath.gamepath, isreplace.ToString());
Run(LANG.GetMsg(LMSG.ConvertImage)); Run(LanguageHelper.GetMsg(LMSG.ConvertImage));
} }
} }
} }
...@@ -1292,7 +1292,7 @@ void Menuitem_exportdataClick(object sender, EventArgs e) ...@@ -1292,7 +1292,7 @@ void Menuitem_exportdataClick(object sender, EventArgs e)
tasker.SetTask(MyTask.ExportData, tasker.SetTask(MyTask.ExportData,
GetCardList(false), GetCardList(false),
ygopath.gamepath, dlg.FileName); ygopath.gamepath, dlg.FileName);
Run(LANG.GetMsg(LMSG.ExportData)); Run(LanguageHelper.GetMsg(LMSG.ExportData));
} }
} }
...@@ -1490,15 +1490,15 @@ private void menuitem_readmse_Click(object sender, EventArgs e) ...@@ -1490,15 +1490,15 @@ private void menuitem_readmse_Click(object sender, EventArgs e)
//select open mse-set //select open mse-set
using (OpenFileDialog dlg = new OpenFileDialog()) using (OpenFileDialog dlg = new OpenFileDialog())
{ {
dlg.Title = LANG.GetMsg(LMSG.selectMseset); dlg.Title = LanguageHelper.GetMsg(LMSG.selectMseset);
dlg.Filter = LANG.GetMsg(LMSG.MseType); dlg.Filter = LanguageHelper.GetMsg(LMSG.MseType);
if (dlg.ShowDialog() == DialogResult.OK) if (dlg.ShowDialog() == DialogResult.OK)
{ {
bool isUpdate = false;//是否替换存在的图片 bool isUpdate = false;//是否替换存在的图片
isUpdate = MyMsg.Question(LMSG.IfReplaceExistingImage); isUpdate = MyMsg.Question(LMSG.IfReplaceExistingImage);
tasker.SetTask(MyTask.ReadMSE, null, tasker.SetTask(MyTask.ReadMSE, null,
dlg.FileName, isUpdate.ToString()); dlg.FileName, isUpdate.ToString());
Run(LANG.GetMsg(LMSG.ReadMSE)); Run(LanguageHelper.GetMsg(LMSG.ReadMSE));
} }
} }
} }
......
...@@ -17,18 +17,19 @@ namespace DataEditorX.Language ...@@ -17,18 +17,19 @@ namespace DataEditorX.Language
/// <summary> /// <summary>
/// Description of Language. /// Description of Language.
/// </summary> /// </summary>
public static class LANG public class LanguageHelper
{ {
static Dictionary<string, string> mWordslist = new Dictionary<string, string>(); static Dictionary<string, string> gWordsList = new Dictionary<string, string>();
static SortedList<LMSG, string> msglist = new SortedList<LMSG, string>(); static SortedList<LMSG, string> gMsgList = new SortedList<LMSG, string>();
const char SEP_CONTROL = '.'; const char SEP_CONTROL = '.';
const char SEP_LINE = '\t'; const char SEP_LINE = '\t';
Dictionary<string, string> mWordslist = new Dictionary<string, string>();
#region 获取消息文字 #region 获取消息文字
public static string GetMsg(LMSG lMsg) public static string GetMsg(LMSG lMsg)
{ {
if (msglist.IndexOfKey(lMsg) >= 0) if (gMsgList.IndexOfKey(lMsg) >= 0)
return msglist[lMsg]; return gMsgList[lMsg];
else else
return lMsg.ToString().Replace("_", " "); return lMsg.ToString().Replace("_", " ");
} }
...@@ -53,7 +54,7 @@ public static void SetFormLabel(Form fm) ...@@ -53,7 +54,7 @@ public static void SetFormLabel(Form fm)
static bool GetLabel(string key, out string title) static bool GetLabel(string key, out string title)
{ {
string v; string v;
if (mWordslist.TryGetValue(key, out v)) if (gWordsList.TryGetValue(key, out v))
{ {
title = v; title = v;
return true; return true;
...@@ -138,7 +139,7 @@ static void SetMenuItem(string pName, ToolStripItem tsi) ...@@ -138,7 +139,7 @@ static void SetMenuItem(string pName, ToolStripItem tsi)
#endregion #endregion
#region 获取控件信息 #region 获取控件信息
public static void GetFormLabel(Form fm) public void GetFormLabel(Form fm)
{ {
if (fm == null) if (fm == null)
return; return;
...@@ -149,13 +150,13 @@ public static void GetFormLabel(Form fm) ...@@ -149,13 +150,13 @@ public static void GetFormLabel(Form fm)
//fm.PerformLayout(); //fm.PerformLayout();
} }
static void AddLabel(string key, string title) void AddLabel(string key, string title)
{ {
if (!mWordslist.ContainsKey(key)) if (!mWordslist.ContainsKey(key))
mWordslist.Add(key, title); mWordslist.Add(key, title);
} }
static void GetControlLabel(Control c, string pName, void GetControlLabel(Control c, string pName,
string formName) string formName)
{ {
if (!string.IsNullOrEmpty(pName)) if (!string.IsNullOrEmpty(pName))
...@@ -203,7 +204,7 @@ static void AddLabel(string key, string title) ...@@ -203,7 +204,7 @@ static void AddLabel(string key, string title)
} }
} }
static void GetMenuItem(string pName, ToolStripItem tsi) void GetMenuItem(string pName, ToolStripItem tsi)
{ {
if (string.IsNullOrEmpty(tsi.Name)) if (string.IsNullOrEmpty(tsi.Name))
return; return;
...@@ -229,7 +230,7 @@ static void GetMenuItem(string pName, ToolStripItem tsi) ...@@ -229,7 +230,7 @@ static void GetMenuItem(string pName, ToolStripItem tsi)
#endregion #endregion
#region 保存语言文件 #region 保存语言文件
public static bool SaveLanguage(string conf) public bool SaveLanguage(string conf)
{ {
using (FileStream fs = new FileStream(conf, FileMode.Create, FileAccess.Write)) using (FileStream fs = new FileStream(conf, FileMode.Create, FileAccess.Write))
{ {
...@@ -239,14 +240,14 @@ public static bool SaveLanguage(string conf) ...@@ -239,14 +240,14 @@ public static bool SaveLanguage(string conf)
sw.WriteLine(k + SEP_LINE + mWordslist[k]); sw.WriteLine(k + SEP_LINE + mWordslist[k]);
} }
sw.WriteLine("#"); sw.WriteLine("#");
foreach (LMSG k in msglist.Keys) foreach (LMSG k in gMsgList.Keys)
{ {
//记得替换换行符 //记得替换换行符
sw.WriteLine("0x" + ((uint)k).ToString("x") + SEP_LINE + msglist[k].Replace("\n", "\\n")); sw.WriteLine("0x" + ((uint)k).ToString("x") + SEP_LINE + gMsgList[k].Replace("\n", "\\n"));
} }
foreach (LMSG k in Enum.GetValues(typeof(LMSG))) foreach (LMSG k in Enum.GetValues(typeof(LMSG)))
{ {
if (!msglist.ContainsKey(k)) if (!gMsgList.ContainsKey(k))
sw.WriteLine("0x" + ((uint)k).ToString("x") + SEP_LINE + k.ToString()); sw.WriteLine("0x" + ((uint)k).ToString("x") + SEP_LINE + k.ToString());
} }
sw.Close(); sw.Close();
...@@ -261,8 +262,8 @@ public static void LoadFormLabels(string f) ...@@ -261,8 +262,8 @@ public static void LoadFormLabels(string f)
{ {
if (!File.Exists(f)) if (!File.Exists(f))
return; return;
mWordslist.Clear(); gWordsList.Clear();
msglist.Clear(); gMsgList.Clear();
using (FileStream fs = new FileStream(f, FileMode.Open, FileAccess.Read)) using (FileStream fs = new FileStream(f, FileMode.Open, FileAccess.Read))
{ {
StreamReader sr = new StreamReader(fs, Encoding.UTF8); StreamReader sr = new StreamReader(fs, Encoding.UTF8);
...@@ -280,13 +281,13 @@ public static void LoadFormLabels(string f) ...@@ -280,13 +281,13 @@ public static void LoadFormLabels(string f)
{ {
uint.TryParse(words[0].Replace("0x", ""), NumberStyles.HexNumber, null, out utemp); uint.TryParse(words[0].Replace("0x", ""), NumberStyles.HexNumber, null, out utemp);
ltemp = (LMSG)utemp; ltemp = (LMSG)utemp;
if (msglist.IndexOfKey(ltemp) < 0)//记得替换换行符 if (gMsgList.IndexOfKey(ltemp) < 0)//记得替换换行符
msglist.Add(ltemp, words[1].Replace("\\n", "\n")); gMsgList.Add(ltemp, words[1].Replace("\\n", "\n"));
} }
else if (!line.StartsWith("#"))//加载界面语言 else if (!line.StartsWith("#"))//加载界面语言
{ {
if (!mWordslist.ContainsKey(words[0])) if (!gWordsList.ContainsKey(words[0]))
mWordslist.Add(words[0], words[1]); gWordsList.Add(words[0], words[1]);
} }
} }
sr.Close(); sr.Close();
......
...@@ -22,10 +22,10 @@ public static class MyMsg ...@@ -22,10 +22,10 @@ public static class MyMsg
static string info, warning, error, question; static string info, warning, error, question;
static MyMsg() static MyMsg()
{ {
info = LANG.GetMsg(LMSG.titleInfo); info = LanguageHelper.GetMsg(LMSG.titleInfo);
warning = LANG.GetMsg(LMSG.titleWarning); warning = LanguageHelper.GetMsg(LMSG.titleWarning);
error = LANG.GetMsg(LMSG.titleError); error = LanguageHelper.GetMsg(LMSG.titleError);
question = LANG.GetMsg(LMSG.titleQuestion); question = LanguageHelper.GetMsg(LMSG.titleQuestion);
} }
public static void Show(string strMsg) public static void Show(string strMsg)
{ {
...@@ -53,22 +53,22 @@ public static bool Question(string strQues) ...@@ -53,22 +53,22 @@ public static bool Question(string strQues)
} }
public static void Show(LMSG msg) public static void Show(LMSG msg)
{ {
MessageBox.Show(LANG.GetMsg(msg), info, MessageBox.Show(LanguageHelper.GetMsg(msg), info,
MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
public static void Warning(LMSG msg) public static void Warning(LMSG msg)
{ {
MessageBox.Show(LANG.GetMsg(msg), warning, MessageBox.Show(LanguageHelper.GetMsg(msg), warning,
MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBoxButtons.OK, MessageBoxIcon.Warning);
} }
public static void Error(LMSG msg) public static void Error(LMSG msg)
{ {
MessageBox.Show(LANG.GetMsg(msg), error, MessageBox.Show(LanguageHelper.GetMsg(msg), error,
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
public static bool Question(LMSG msg) public static bool Question(LMSG msg)
{ {
if(MessageBox.Show(LANG.GetMsg(msg), question, if(MessageBox.Show(LanguageHelper.GetMsg(msg), question,
MessageBoxButtons.OKCancel, MessageBoxButtons.OKCancel,
MessageBoxIcon.Question)==DialogResult.OK) MessageBoxIcon.Question)==DialogResult.OK)
return true; return true;
......
...@@ -343,8 +343,7 @@ private void InitializeComponent() ...@@ -343,8 +343,7 @@ private void InitializeComponent()
this.Name = "MainForm"; this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "MainForm"; this.Text = "MainForm";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainFormFormClosing); this.Load += new System.EventHandler(this.MainForm_Load);
this.Load += new System.EventHandler(this.MainFormLoad);
this.mainMenu.ResumeLayout(false); this.mainMenu.ResumeLayout(false);
this.mainMenu.PerformLayout(); this.mainMenu.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
......
...@@ -42,10 +42,6 @@ public partial class MainForm : Form, IMainForm ...@@ -42,10 +42,6 @@ public partial class MainForm : Form, IMainForm
#region 设置界面,消息语言 #region 设置界面,消息语言
public MainForm() public MainForm()
{ {
//检查更新
Thread th = new Thread(CheckUpdate);
th.IsBackground = true;//如果exe结束,则线程终止
th.Start();
//初始化控件 //初始化控件
InitializeComponent(); InitializeComponent();
} }
...@@ -103,11 +99,11 @@ void Init() ...@@ -103,11 +99,11 @@ void Init()
//读取历史记录 //读取历史记录
history.ReadHistory(MyPath.Combine(datapath, MyConfig.FILE_HISTORY)); history.ReadHistory(MyPath.Combine(datapath, MyConfig.FILE_HISTORY));
//加载多语言 //加载多语言
LANG.LoadFormLabels(conflang); LanguageHelper.LoadFormLabels(conflang);
} }
void InitForm() void InitForm()
{ {
LANG.SetFormLabel(this); LanguageHelper.SetFormLabel(this);
//设置所有窗口的语言 //设置所有窗口的语言
DockContentCollection contents = dockPanel1.Contents; DockContentCollection contents = dockPanel1.Contents;
...@@ -115,7 +111,7 @@ void InitForm() ...@@ -115,7 +111,7 @@ void InitForm()
{ {
if (dc is Form) if (dc is Form)
{ {
LANG.SetFormLabel((Form)dc); LanguageHelper.SetFormLabel((Form)dc);
} }
} }
//添加历史菜单 //添加历史菜单
...@@ -182,7 +178,7 @@ void OpenScript(string file) ...@@ -182,7 +178,7 @@ void OpenScript(string file)
{ {
CodeEditForm cf = new CodeEditForm(); CodeEditForm cf = new CodeEditForm();
//设置界面语言 //设置界面语言
LANG.SetFormLabel(cf); LanguageHelper.SetFormLabel(cf);
//设置cdb列表 //设置cdb列表
cf.SetCDBList(history.GetcdbHistory()); cf.SetCDBList(history.GetcdbHistory());
//初始化函数提示 //初始化函数提示
...@@ -200,7 +196,7 @@ void OpenDataBase(string file) ...@@ -200,7 +196,7 @@ void OpenDataBase(string file)
else else
def = new DataEditForm(datapath, file); def = new DataEditForm(datapath, file);
//设置语言 //设置语言
LANG.SetFormLabel(def); LanguageHelper.SetFormLabel(def);
//初始化界面数据 //初始化界面数据
def.InitControl(datacfg); def.InitControl(datacfg);
def.Show(dockPanel1, DockState.Document); def.Show(dockPanel1, DockState.Document);
...@@ -257,28 +253,6 @@ bool FindEditForm(string file, bool isOpen) ...@@ -257,28 +253,6 @@ bool FindEditForm(string file, bool isOpen)
} }
#endregion #endregion
#region 加载,关闭
void MainFormLoad(object sender, System.EventArgs e)
{
//检查更新
//bgWorker1.RunWorkerAsync();
}
void MainFormFormClosing(object sender, FormClosingEventArgs e)
{
#if DEBUG
LANG.GetFormLabel(this);
DockContentCollection contents = dockPanel1.Contents;
foreach (DockContent dc in contents)
{
LANG.GetFormLabel(dc);
}
//获取窗体文字
LANG.SaveLanguage(conflang + ".bak");
#endif
}
#endregion
#region 窗口管理 #region 窗口管理
//关闭当前 //关闭当前
void CloseToolStripMenuItemClick(object sender, EventArgs e) void CloseToolStripMenuItemClick(object sender, EventArgs e)
...@@ -342,11 +316,11 @@ void Menuitem_openClick(object sender, EventArgs e) ...@@ -342,11 +316,11 @@ void Menuitem_openClick(object sender, EventArgs e)
{ {
using (OpenFileDialog dlg = new OpenFileDialog()) using (OpenFileDialog dlg = new OpenFileDialog())
{ {
dlg.Title = LANG.GetMsg(LMSG.OpenFile); dlg.Title = LanguageHelper.GetMsg(LMSG.OpenFile);
if (GetActive() != null || dockPanel1.Contents.Count == 0)//判断当前窗口是不是DataEditor if (GetActive() != null || dockPanel1.Contents.Count == 0)//判断当前窗口是不是DataEditor
dlg.Filter = LANG.GetMsg(LMSG.CdbType); dlg.Filter = LanguageHelper.GetMsg(LMSG.CdbType);
else else
dlg.Filter = LANG.GetMsg(LMSG.ScriptFilter); dlg.Filter = LanguageHelper.GetMsg(LMSG.ScriptFilter);
if (dlg.ShowDialog() == DialogResult.OK) if (dlg.ShowDialog() == DialogResult.OK)
{ {
string file = dlg.FileName; string file = dlg.FileName;
...@@ -365,11 +339,11 @@ void Menuitem_newClick(object sender, EventArgs e) ...@@ -365,11 +339,11 @@ void Menuitem_newClick(object sender, EventArgs e)
{ {
using (SaveFileDialog dlg = new SaveFileDialog()) using (SaveFileDialog dlg = new SaveFileDialog())
{ {
dlg.Title = LANG.GetMsg(LMSG.NewFile); dlg.Title = LanguageHelper.GetMsg(LMSG.NewFile);
if (GetActive() != null)//判断当前窗口是不是DataEditor if (GetActive() != null)//判断当前窗口是不是DataEditor
dlg.Filter = LANG.GetMsg(LMSG.CdbType); dlg.Filter = LanguageHelper.GetMsg(LMSG.CdbType);
else else
dlg.Filter = LANG.GetMsg(LMSG.ScriptFilter); dlg.Filter = LanguageHelper.GetMsg(LMSG.ScriptFilter);
if (dlg.ShowDialog() == DialogResult.OK) if (dlg.ShowDialog() == DialogResult.OK)
{ {
string file = dlg.FileName; string file = dlg.FileName;
...@@ -513,5 +487,13 @@ private void bgWorker1_RunWorkerCompleted(object sender, System.ComponentModel.R ...@@ -513,5 +487,13 @@ private void bgWorker1_RunWorkerCompleted(object sender, System.ComponentModel.R
InitForm(); InitForm();
} }
#endregion #endregion
private void MainForm_Load(object sender, EventArgs e)
{
//检查更新
Thread th = new Thread(CheckUpdate);
th.IsBackground = true;//如果exe结束,则线程终止
th.Start();
}
} }
} }
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
using System.Reflection; using System.Reflection;
using System.Windows.Forms; using System.Windows.Forms;
using DataEditorX.Config; using DataEditorX.Config;
using DataEditorX.Language;
namespace DataEditorX namespace DataEditorX
{ {
...@@ -20,8 +21,15 @@ internal sealed class Program ...@@ -20,8 +21,15 @@ internal sealed class Program
[STAThread] [STAThread]
private static void Main(string[] args) private static void Main(string[] args)
{ {
string file = (args.Length > 0) ? args[0] : ""; string arg = (args.Length > 0) ? args[0] : "";
if (MyConfig.OpenOnExistForm(file))//在已经存在的窗口打开文件 if (arg == MyConfig.TAG_SAVE_LAGN || arg == MyConfig.TAG_SAVE_LAGN2)
{
//保存语言
SaveLanguage();
MessageBox.Show("Save Language OK.");
Environment.Exit(1);
}
if (MyConfig.OpenOnExistForm(arg))//在已经存在的窗口打开文件
Environment.Exit(1); Environment.Exit(1);
else//新建窗口 else//新建窗口
{ {
...@@ -29,13 +37,32 @@ private static void Main(string[] args) ...@@ -29,13 +37,32 @@ private static void Main(string[] args)
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
MainForm mainForm = new MainForm(); MainForm mainForm = new MainForm();
//设置将要打开的文件 //设置将要打开的文件
mainForm.setOpenFile(file); mainForm.setOpenFile(arg);
//数据目录 //数据目录
mainForm.SetDataPath(MyPath.Combine(Application.StartupPath, MyConfig.TAG_DATA)); mainForm.SetDataPath(MyPath.Combine(Application.StartupPath, MyConfig.TAG_DATA));
Application.Run(mainForm); Application.Run(mainForm);
} }
} }
static void SaveLanguage()
{
string datapath = MyPath.Combine(Application.StartupPath, MyConfig.TAG_DATA);
string conflang = MyConfig.GetLanguageFile(datapath);
LanguageHelper.LoadFormLabels(conflang);
LanguageHelper langhelper = new LanguageHelper();
MainForm form1 = new MainForm();
LanguageHelper.SetFormLabel(form1);
langhelper.GetFormLabel(form1);
DataEditForm form2 = new DataEditForm();
LanguageHelper.SetFormLabel(form2);
langhelper.GetFormLabel(form2);
CodeEditForm form3 = new CodeEditForm();
LanguageHelper.SetFormLabel(form3);
langhelper.GetFormLabel(form3);
// LANG.GetFormLabel(this);
//获取窗体文字
langhelper.SaveLanguage(conflang + ".bak");
}
} }
} }
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment