//TODO: Remove ScriptDocumentTab from here public override List <CompilerError> UpdateFunctionBarItems(ScriptDocumentTab tab, MemoryStream stream, ComboBox target) { List <CompilerError> result = new List <CompilerError>(); if (stream == null) { return(result); } target.Items.Clear(); ModeldefParserSE parser = new ModeldefParserSE(); TextResourceData data = new TextResourceData(stream, new DataLocation(), "MODELDEF", false); if (parser.Parse(data, false)) { target.Items.AddRange(parser.Models.ToArray()); } if (parser.HasError) { result.Add(new CompilerError(parser.ErrorDescription, parser.ErrorSource, parser.ErrorLine)); } return(result); }
//TODO: Remove ScriptDocumentTab from here public override List <CompilerError> UpdateFunctionBarItems(ScriptDocumentTab tab, MemoryStream stream, ComboBox target) { List <CompilerError> result = new List <CompilerError>(); if (stream == null) { return(result); } target.Items.Clear(); AcsParserSE parser = new AcsParserSE { AddArgumentsToScriptNames = true, IsMapScriptsLump = tab is ScriptLumpDocumentTab, IgnoreErrors = true }; DataLocation dl = new DataLocation(DataLocation.RESOURCE_DIRECTORY, Path.GetDirectoryName(string.IsNullOrEmpty(tab.Filename)? tab.Title : tab.Filename), false, false, false); TextResourceData data = new TextResourceData(stream, dl, (parser.IsMapScriptsLump ? "?SCRIPTS" : tab.Filename)); if (parser.Parse(data, false)) { target.Items.AddRange(parser.NamedScripts.ToArray()); target.Items.AddRange(parser.NumberedScripts.ToArray()); target.Items.AddRange(parser.Functions.ToArray()); } if (parser.HasError) { result.Add(new CompilerError(parser.ErrorDescription, parser.ErrorSource, parser.ErrorLine)); } return(result); }
//mxd. Replace private void replacebutton_Click(object sender, EventArgs e) { var editor = General.Map.ScriptEditor.Editor; FindReplaceOptions options = MakeOptions(); AddComboboxText(replacefindbox, options.FindText); AddComboboxText(replacebox, options.ReplaceWith); ScriptDocumentTab curtab = editor.ActiveTab; if (curtab == null) { return; } // Search from selection start, then replace if (!curtab.FindNext(options, true) || !editor.Replace(options)) { editor.DisplayStatus(ScriptStatusType.Warning, "Can't find any occurrence of \"" + options.FindText + "\"."); return; } // Find & show next match curtab.FindNext(options); }
//mxd. Bookmark all private void bookmarkallbutton_Click(object sender, EventArgs e) { FindReplaceOptions options = MakeOptions(); AddComboboxText(findbox, options.FindText); // Determine script type ScriptType scripttype = ScriptType.UNKNOWN; switch (options.SearchMode) { case FindReplaceSearchMode.CURRENT_FILE: case FindReplaceSearchMode.CURRENT_PROJECT_CURRENT_SCRIPT_TYPE: case FindReplaceSearchMode.OPENED_TABS_CURRENT_SCRIPT_TYPE: ScriptDocumentTab t = General.Map.ScriptEditor.Editor.ActiveTab; if (t != null) { scripttype = t.Config.ScriptType; } break; } if (General.Map.ScriptEditor.Editor.FindUsages(options, scripttype)) { this.Close(); } }
//mxd. Replace All private void replaceallbutton_Click(object sender, EventArgs e) { var editor = General.Map.ScriptEditor.Editor; FindReplaceOptions options = MakeOptions(); AddComboboxText(replacefindbox, options.FindText); AddComboboxText(replacebox, options.ReplaceWith); // Find next match ScriptDocumentTab curtab = editor.ActiveTab; if (curtab == null || !curtab.FindNext(options, true)) { editor.DisplayStatus(ScriptStatusType.Warning, "Can't find any occurrence of \"" + options.FindText + "\"."); return; } // Replace loop int replacements = 0; while (editor.FindNext(options) && editor.Replace(options)) { replacements++; } // Show result if (replacements == 0) { editor.DisplayStatus(ScriptStatusType.Warning, "Can't find any occurrence of \"" + options.FindText + "\"."); } else { editor.DisplayStatus(ScriptStatusType.Info, "Replaced " + replacements + " occurrences of \"" + options.FindText + "\" with \"" + options.ReplaceWith + "\"."); // Find & select the last match on the now-current tab curtab = editor.ActiveTab; if (curtab != null) { options.FindText = options.ReplaceWith; options.ReplaceWith = null; curtab.SelectionStart = curtab.Text.Length; curtab.SelectionEnd = curtab.SelectionStart; curtab.FindPrevious(options); } } }
//mxd. Replace All private void replaceallbutton_Click(object sender, EventArgs e) { var editor = General.Map.ScriptEditor.Editor; FindReplaceOptions options = MakeOptions(); AddComboboxText(replacefindbox, options.FindText); AddComboboxText(replacebox, options.ReplaceWith); // Find next match // [ZZ] why are we doing this? we aren't limited to the current tab..... /* * ScriptDocumentTab curtab = editor.ActiveTab; * if(curtab == null || !curtab.FindNext(options, true)) * { * editor.DisplayStatus(ScriptStatusType.Warning, "Can't find any occurrence of \"" + options.FindText + "\"."); * return; * }*/ // Replace loop // We don't really want to do this outside of the script editor. int replacements = editor.FindReplace(options); // Show result if (replacements == 0) { editor.DisplayStatus(ScriptStatusType.Warning, "Can't find any occurrence of \"" + options.FindText + "\"."); } else { editor.DisplayStatus(ScriptStatusType.Info, "Replaced " + replacements + " occurrences of \"" + options.FindText + "\" with \"" + options.ReplaceWith + "\"."); // Find & select the last match on the now-current tab ScriptDocumentTab curtab = editor.ActiveTab; if (curtab != null) { options.FindText = options.ReplaceWith; options.ReplaceWith = null; curtab.SelectionStart = curtab.Text.Length; curtab.SelectionEnd = curtab.SelectionStart; curtab.FindPrevious(options); } } }
//TODO: Remove ScriptDocumentTab from here public virtual List <CompilerError> UpdateFunctionBarItems(ScriptDocumentTab tab, MemoryStream stream, ComboBox target) { // Unsupported script type. Just clear the items target.Items.Clear(); return(new List <CompilerError>()); }