////////////////////////////////////////////////////////////////////////// private void OnAddLanguage(object sender, EventArgs e) { if (ListLanguages.SelectedIndex < 0 || ListLanguages.SelectedIndex >= 20) { return; } if (!File.Exists(UeWordFilePath)) { return; } if (DialogResult.Yes != MessageBox.Show("Do you really want to replace '" + ListLanguages.SelectedItem.ToString() + "' with WME scripts?", ParentForm.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { return; } WordFileItem Item = GetWordFileItem(ListLanguages.SelectedIndex + 1); if (Item == null) { Item = new WordFileItem(); WordFileItems.Add(Item); } FillWordFileEntry(ListLanguages.SelectedIndex + 1, Item); SaveWordFile(); LoadInfo(); }
////////////////////////////////////////////////////////////////////////// private void LoadWordFile() { WordFileItems = new List <WordFileItem>(); if (!File.Exists(UeWordFilePath)) { return; } WordFileItem CurrItem = null; using (StreamReader sr = new StreamReader(UeWordFilePath, Encoding.Default, true)) { Regex R = new Regex("/L[0-9]+\".*\".*"); string Line; while ((Line = sr.ReadLine()) != null) { if (R.IsMatch(Line)) { if (CurrItem != null) { WordFileItems.Add(CurrItem); } CurrItem = new WordFileItem(); CurrItem.Lines.Add(Line); ScanLanguageLine(Line, out CurrItem.Order, out CurrItem.Name); } else { if (CurrItem != null) { CurrItem.Lines.Add(Line); } } } if (CurrItem != null) { WordFileItems.Add(CurrItem); } } }
////////////////////////////////////////////////////////////////////////// protected void LoadInfoFromIni(string UeIniPath) { if (!File.Exists(UeIniPath)) { return; } IniFile Ini = new IniFile(UeIniPath); // read word file UeWordFilePath = Ini.ReadString("Settings", "Language File"); LoadWordFile(); for (int i = 0; i < 20; i++) { WordFileItem Item = GetWordFileItem(i + 1); if (Item == null) { ListLanguages.Items.Add("<empty slot>"); } else { ListLanguages.Items.Add(Item.Name); } } // read tools for (int i = 0; i < 10; i++) { string Val = Ini.ReadString("Tools", "Tool Menu" + i.ToString(), ""); if (Val == null || Val == string.Empty) { Val = "<empty slot>"; ListTools.Items.Add(Val); break; } else { ListTools.Items.Add(Val); } } }
////////////////////////////////////////////////////////////////////////// private void FillWordFileEntry(int Order, WordFileItem Item) { Item.Order = Order; Item.Name = "WME Script"; Item.Lines.Clear(); // language definition string LangLine = ""; LangLine += "/L" + Order.ToString() + "\"WME Script\""; LangLine += " Line Comment = //"; LangLine += " Block Comment On = /* Block Comment Off = */ NestBlockComments"; LangLine += " Line Comment = //"; LangLine += " Escape Char = ~ String Chars = \""; string[] Extensions = ParentForm.GetExtensions(); LangLine += " File Extensions ="; foreach (string Ext in Extensions) { LangLine += " " + Ext; } Item.Lines.Add(LangLine); Item.Lines.Add("/Delimiters = ~!@%^&*()-+=|\\/{}[]:;\"'<> , .?"); Item.Lines.Add("/Function String = \"%[ ^t]++function^(*(*)^)\""); Item.Lines.Add("/Function String 1 = \"%[ ^t]++method^(*(*)^)\""); Item.Lines.Add("/Indent Strings = \"{\" \"else\""); Item.Lines.Add("/Unindent Strings = \"}\""); Item.Lines.Add("/Open Brace Strings = \"{\" \"(\" \"[\" \"<\""); Item.Lines.Add("/Close Brace Strings = \"}\" \")\" \"]\" \">\""); Item.Lines.Add("/Open Fold Strings = \"{\" \"#region\""); Item.Lines.Add("/Close Fold Strings = \"}\" \"#endregion\""); WordHolder wh = new WordHolder(); // keywords Item.Lines.Add("/C1\"Keywords\" STYLE_KEYWORD"); foreach (string Keyword in ScriptTokenizer.Keywords) { wh.AddWord(Keyword); } Item.Lines.Add(wh.GetWords()); // read XML docs ScriptInfo Info = new ScriptInfo(); Info.ReadXml(WmeUtils.XmlDocsPath); // methods Item.Lines.Add("/C2\"Methods\" STYLE_METHOD"); wh = new WordHolder(); foreach (ScriptObject Obj in Info.Objects) { foreach (ScriptMethod Method in Obj.Methods) { //if (Method.IsGlobal) continue; foreach (string Header in Method.Headers) { int Brace = Header.IndexOf("("); if (Brace >= 0) { wh.AddWord(Header.Substring(0, Brace).Trim()); } } } } Item.Lines.Add(wh.GetWords()); // attributes Item.Lines.Add("/C3\"Properties\" STYLE_ATTRIBUTE"); wh = new WordHolder(); foreach (ScriptObject Obj in Info.Objects) { foreach (ScriptAttribute Attr in Obj.Attributes) { if (Attr.Name.StartsWith("[")) { continue; } wh.AddWord(Attr.Name); } } Item.Lines.Add(wh.GetWords()); // preprocessor Item.Lines.Add("/C4\"Preprocessor\" STYLE_EXTENSION"); Item.Lines.Add("#endregion #include #region"); }
////////////////////////////////////////////////////////////////////////// private void OnAddLanguage(object sender, EventArgs e) { if (ListLanguages.SelectedIndex < 0 || ListLanguages.SelectedIndex >= 20) return; if (!File.Exists(UeWordFilePath)) return; if (DialogResult.Yes != MessageBox.Show("Do you really want to replace '" + ListLanguages.SelectedItem.ToString() + "' with WME scripts?", ParentForm.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question)) return; WordFileItem Item = GetWordFileItem(ListLanguages.SelectedIndex + 1); if(Item==null) { Item = new WordFileItem(); WordFileItems.Add(Item); } FillWordFileEntry(ListLanguages.SelectedIndex + 1, Item); SaveWordFile(); LoadInfo(); }
////////////////////////////////////////////////////////////////////////// private void LoadWordFile() { WordFileItems = new List<WordFileItem>(); if (!File.Exists(UeWordFilePath)) return; WordFileItem CurrItem = null; using (StreamReader sr = new StreamReader(UeWordFilePath, Encoding.Default, true)) { Regex R = new Regex("/L[0-9]+\".*\".*"); string Line; while ((Line = sr.ReadLine()) != null) { if(R.IsMatch(Line)) { if (CurrItem != null) WordFileItems.Add(CurrItem); CurrItem = new WordFileItem(); CurrItem.Lines.Add(Line); ScanLanguageLine(Line, out CurrItem.Order, out CurrItem.Name); } else { if (CurrItem != null) CurrItem.Lines.Add(Line); } } if (CurrItem != null) WordFileItems.Add(CurrItem); } }
////////////////////////////////////////////////////////////////////////// private void FillWordFileEntry(int Order, WordFileItem Item) { Item.Order = Order; Item.Name = "WME Script"; Item.Lines.Clear(); // language definition string LangLine = ""; LangLine += "/L" + Order.ToString() + "\"WME Script\""; LangLine += " Line Comment = //"; LangLine += " Block Comment On = /* Block Comment Off = */ NestBlockComments"; LangLine += " Line Comment = //"; LangLine += " Escape Char = ~ String Chars = \""; string[] Extensions = ParentForm.GetExtensions(); LangLine += " File Extensions ="; foreach(string Ext in Extensions) { LangLine += " " + Ext; } Item.Lines.Add(LangLine); Item.Lines.Add("/Delimiters = ~!@%^&*()-+=|\\/{}[]:;\"'<> , .?"); Item.Lines.Add("/Function String = \"%[ ^t]++function^(*(*)^)\""); Item.Lines.Add("/Function String 1 = \"%[ ^t]++method^(*(*)^)\""); Item.Lines.Add("/Indent Strings = \"{\" \"else\""); Item.Lines.Add("/Unindent Strings = \"}\""); Item.Lines.Add("/Open Brace Strings = \"{\" \"(\" \"[\" \"<\""); Item.Lines.Add("/Close Brace Strings = \"}\" \")\" \"]\" \">\""); Item.Lines.Add("/Open Fold Strings = \"{\" \"#region\""); Item.Lines.Add("/Close Fold Strings = \"}\" \"#endregion\""); WordHolder wh = new WordHolder(); // keywords Item.Lines.Add("/C1\"Keywords\" STYLE_KEYWORD"); foreach(string Keyword in ScriptTokenizer.Keywords) { wh.AddWord(Keyword); } Item.Lines.Add(wh.GetWords()); // read XML docs ScriptInfo Info = new ScriptInfo(); Info.ReadXml(WmeUtils.XmlDocsPath); // methods Item.Lines.Add("/C2\"Methods\" STYLE_METHOD"); wh = new WordHolder(); foreach(ScriptObject Obj in Info.Objects) { foreach(ScriptMethod Method in Obj.Methods) { //if (Method.IsGlobal) continue; foreach(string Header in Method.Headers) { int Brace = Header.IndexOf("("); if(Brace >= 0) { wh.AddWord(Header.Substring(0, Brace).Trim()); } } } } Item.Lines.Add(wh.GetWords()); // attributes Item.Lines.Add("/C3\"Properties\" STYLE_ATTRIBUTE"); wh = new WordHolder(); foreach (ScriptObject Obj in Info.Objects) { foreach (ScriptAttribute Attr in Obj.Attributes) { if (Attr.Name.StartsWith("[")) continue; wh.AddWord(Attr.Name); } } Item.Lines.Add(wh.GetWords()); // preprocessor Item.Lines.Add("/C4\"Preprocessor\" STYLE_EXTENSION"); Item.Lines.Add("#endregion #include #region"); }