// Keyword help requested private void buttonkeywordhelp_Click(object sender, EventArgs e) { // Get script ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab); t.LaunchKeywordHelp(); }
// This closes a script and returns true when closed private bool CloseScript(ScriptDocumentTab t, bool saveonly) { if (t.IsChanged) { // Ask to save DialogResult result = MessageBox.Show(this.ParentForm, "Do you want to save changes to " + t.Text + "?", "Close File", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result == DialogResult.Yes) { // Save file if (!SaveScript(t)) { return(false); } } else if (result == DialogResult.Cancel) { // Cancel return(false); } } if (!saveonly) { // Close file tabs.TabPages.Remove(t); t.Dispose(); } return(true); }
// This is called by Save and Save All to save a script // Returns false when cancelled by the user private bool SaveScript(ScriptDocumentTab t) { // Do we have to do a save as? if (t.IsSaveAsRequired) { // Setup save dialog string scriptfilter = t.Config.Description + "|*." + string.Join(";*.", t.Config.Extensions); savefile.Filter = scriptfilter + "|All files|*.*"; if (savefile.ShowDialog(this.ParentForm) == DialogResult.OK) { // Save to new filename t.SaveAs(savefile.FileName); return(true); } else { // Cancelled return(false); } } else { // Save to same filename t.Save(); return(true); } }
// This closes a script and returns true when closed private bool CloseScript(ScriptDocumentTab t, bool saveonly) { if (t.IsChanged) { // Ask to save DialogResult result = MessageBox.Show(this.ParentForm, "Do you want to save changes to " + t.Title + "?", "Close File", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (result) { case DialogResult.Yes: if (!SaveScript(t)) { return(false); } break; case DialogResult.Cancel: return(false); } } if (!saveonly) { //mxd. Select tab to the left of the one we are going to close if (t == tabs.SelectedTab && tabs.SelectedIndex > 0) { tabs.SelectedIndex--; } // Close file tabs.TabPages.Remove(t); t.Dispose(); } return(true); }
// This closes the current file private void buttonclose_Click(object sender, EventArgs e) { ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab); CloseScript(t, false); UpdateToolbar(true); }
// Paste clicked private void buttonpaste_Click(object sender, EventArgs e) { ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab); t.Paste(); UpdateToolbar(true); }
//mxd. This launches keyword help website public bool LaunchKeywordHelp() { // Get script ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab); return(t != null && t.LaunchKeywordHelp()); }
// User double-clicks and error in the list private void errorlist_ItemActivate(object sender, EventArgs e) { // Anything selection? if (errorlist.SelectedItems.Count > 0) { // Get the compiler error CompilerError err = (CompilerError)errorlist.SelectedItems[0].Tag; // Show the tab with the script that matches bool foundscript = false; foreach (ScriptDocumentTab t in tabs.TabPages) { if (t.VerifyErrorForScript(err)) { tabs.SelectedTab = t; t.MoveToLine(err.linenumber); foundscript = true; break; } } // If we don't have the script opened, see if we can find the file and open the script if (!foundscript && File.Exists(err.filename)) { ScriptDocumentTab t = OpenFile(err.filename); if (t != null) { t.MoveToLine(err.linenumber); } } ForceFocus(); } }
// Save script clicked private void buttonsave_Click(object sender, EventArgs e) { // Save the current script ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab); SaveScript(t); UpdateToolbar(true); }
// This forces the focus to the script editor public void ForceFocus() { ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab); tabs.Focus(); if (t != null) { t.Focus(); } }
// Compile Script clicked private void buttoncompile_Click(object sender, EventArgs e) { // First save all implicit scripts to the temporary wad file ImplicitSave(); // Get script ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab); // Check if it must be saved as a new file if (t.ExplicitSave && t.IsSaveAsRequired) { // Save the script first! if (MessageBox.Show(this.ParentForm, "You must save your script before you can compile it. Do you want to save your script now?", "Compile Script", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { if (!SaveScript(t)) { return; } } else { return; } } else { if (t.ExplicitSave && t.IsChanged) { // We can only compile when the script is saved if (!SaveScript(t)) { return; } } } // Compile now General.MainWindow.DisplayStatus(StatusType.Busy, "Compiling script " + t.Text + "..."); Cursor.Current = Cursors.WaitCursor; t.Compile(); // Show warning if ((compilererrors != null) && (compilererrors.Count > 0)) { General.MainWindow.DisplayStatus(StatusType.Warning, compilererrors.Count.ToString() + " errors while compiling " + t.Text + "!"); } else { General.MainWindow.DisplayStatus(StatusType.Info, "Script " + t.Text + " compiled without errors."); } Cursor.Current = Cursors.Default; UpdateToolbar(true); }
//mxd. Text in ScriptLumpDocumentTab was changed private void tabpage_OnLumpTextChanged(object sender, EventArgs e) { if (tabs.SelectedTab != null) { ScriptDocumentTab curtab = tabs.SelectedTab as ScriptDocumentTab; if (curtab != null) { buttonundo.Enabled = curtab.Scintilla.CanUndo; buttonredo.Enabled = curtab.Scintilla.CanRedo; } } }
// When the user changes the script configuration private void buttonscriptconfig_Click(object sender, EventArgs e) { // Get the tab and new script config ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab); ScriptConfiguration scriptconfig = ((sender as ToolStripMenuItem).Tag as ScriptConfiguration); // Change script config t.ChangeScriptConfig(scriptconfig); // Done UpdateToolbar(true); }
//mxd private void ApplyTabSettings() { foreach (var tp in tabs.TabPages) { ScriptDocumentTab scripttab = (tp as ScriptDocumentTab); if (scripttab != null) { scripttab.WrapLongLines = buttonwordwrap.Checked; scripttab.ShowWhitespace = buttonwhitespace.Checked; } } }
// A tab is selected private void tabs_Selecting(object sender, TabControlCancelEventArgs e) { //mxd. Update script navigator ScriptDocumentTab tab = e.TabPage as ScriptDocumentTab; if (tab != null) { // Show all errors... ShowErrors(tab.UpdateNavigator(), true); } UpdateToolbar(true); }
//mxd. Text in ScriptFileDocumentTab was changed private void tabpage_OnTextChanged(object sender, EventArgs eventArgs) { if (tabs.SelectedTab != null) { ScriptDocumentTab curtab = tabs.SelectedTab as ScriptDocumentTab; if (curtab != null) { buttonsave.Enabled = (curtab.ExplicitSave && curtab.IsChanged); buttonundo.Enabled = curtab.Scintilla.CanUndo; buttonredo.Enabled = curtab.Scintilla.CanRedo; } } }
// This saves the current open script public void ExplicitSaveCurrentTab() { ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab); if ((t != null) && t.ExplicitSave) { buttonsave_Click(this, EventArgs.Empty); } else { General.MessageBeep(MessageBeepType.Default); } }
// This updates the toolbar for the current status private void UpdateToolbar(bool focuseditor) { int numscriptsopen = tabs.TabPages.Count; int explicitsavescripts = 0; ScriptDocumentTab t = null; // Any explicit save scripts? foreach (ScriptDocumentTab dt in tabs.TabPages) { if (dt.ExplicitSave) { explicitsavescripts++; } } // Get current script, if any are open if (numscriptsopen > 0) { t = (tabs.SelectedTab as ScriptDocumentTab); } // Enable/disable buttons buttonsave.Enabled = (t != null) && t.ExplicitSave; buttonsaveall.Enabled = (explicitsavescripts > 0); buttoncompile.Enabled = (t != null) && (t.Config.Compiler != null); buttonkeywordhelp.Enabled = (t != null) && !string.IsNullOrEmpty(t.Config.KeywordHelp); buttonscriptconfig.Enabled = (t != null) && t.IsReconfigurable; buttonundo.Enabled = (t != null); buttonredo.Enabled = (t != null); buttoncopy.Enabled = (t != null); buttoncut.Enabled = (t != null); buttonpaste.Enabled = (t != null); buttonclose.Enabled = (t != null) && t.IsClosable; if (t != null) { // Check the according script config in menu foreach (ToolStripMenuItem item in buttonscriptconfig.DropDownItems) { ScriptConfiguration config = (item.Tag as ScriptConfiguration); item.Checked = (config == t.Config); } // Focus to script editor if (focuseditor) { ForceFocus(); } } }
//mxd private void OnInsertSnippetClick(object sender, EventArgs eventArgs) { ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab); t.InsertSnippet(((ToolStripItem)sender).Text); }
// This updates the toolbar for the current status private void UpdateToolbar(bool focuseditor) { int numscriptsopen = tabs.TabPages.Count; int explicitsavescripts = 0; ScriptDocumentTab t = null; // Any explicit save scripts? foreach (ScriptDocumentTab dt in tabs.TabPages) { if (dt.ExplicitSave) { explicitsavescripts++; } } // Get current script, if any are open if (numscriptsopen > 0) { t = (tabs.SelectedTab as ScriptDocumentTab); } // Enable/disable buttons buttonsave.Enabled = (t != null && t.ExplicitSave && t.IsChanged); buttonsaveall.Enabled = (explicitsavescripts > 0); buttoncompile.Enabled = (t != null && t.Config.Compiler != null); buttonsearch.Enabled = (t != null); //mxd buttonkeywordhelp.Enabled = (t != null && !string.IsNullOrEmpty(t.Config.KeywordHelp)); buttonscriptconfig.Enabled = (t != null && t.IsReconfigurable); buttonundo.Enabled = (t != null && t.Scintilla.CanUndo); buttonredo.Enabled = (t != null && t.Scintilla.CanRedo); buttoncopy.Enabled = (t != null && t.Scintilla.SelectionStart < t.Scintilla.SelectionEnd); buttoncut.Enabled = (t != null && t.Scintilla.SelectionStart < t.Scintilla.SelectionEnd); buttonpaste.Enabled = (t != null && t.Scintilla.CanPaste); buttonclose.Enabled = (t != null && t.IsClosable); buttonsnippets.DropDownItems.Clear(); //mxd buttonsnippets.Enabled = (t != null && t.Config.Snippets.Count > 0); //mxd buttonindent.Enabled = (t != null); //mxd buttonunindent.Enabled = (t != null && t.Scintilla.Lines[t.Scintilla.CurrentLine].Indentation > 0); //mxd buttonwhitespace.Enabled = (t != null); //mxd buttonwordwrap.Enabled = (t != null); //mxd searchmatchcase.Enabled = (t != null); //mxd searchwholeword.Enabled = (t != null); //mxd if (t != null) { //mxd. Update quick search controls searchbox.Enabled = true; if (searchbox.Text.Length > 0) { if (t.Scintilla.Text.IndexOf(searchbox.Text, searchmatchcase.Checked ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase) != -1) { searchprev.Enabled = true; searchnext.Enabled = true; searchbox.BackColor = SystemColors.Window; } else { searchprev.Enabled = false; searchnext.Enabled = false; searchbox.BackColor = QUICKSEARCH_FAIL_COLOR; } } else { searchprev.Enabled = false; searchnext.Enabled = false; } // Check the according script config in menu foreach (ToolStripMenuItem item in buttonscriptconfig.DropDownItems) { ScriptConfiguration config = (item.Tag as ScriptConfiguration); item.Checked = (config == t.Config); } //mxd. Add snippets if (t.Config != null && t.Config.Snippets.Count > 0) { if (t.Config.Snippets.Count > 0) { foreach (string snippetname in t.Config.Snippets) { buttonsnippets.DropDownItems.Add(snippetname).Click += OnInsertSnippetClick; } } } // Focus to script editor if (focuseditor) { ForceFocus(); } } else { //mxd. Disable quick search controls searchbox.Enabled = false; searchprev.Enabled = false; searchnext.Enabled = false; } //mxd. Update script type description scripttype.Text = ((t != null && t.Config != null) ? t.Config.Description : "Plain Text"); }
//mxd private void buttonindent_Click(object sender, EventArgs e) { ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab); t.IndentSelection(true); }
// This initializes the control public void Initialize() { // Make list of script configs scriptconfigs = new List <ScriptConfiguration>(General.ScriptConfigs.Values); scriptconfigs.Add(new ScriptConfiguration()); scriptconfigs.Sort(); // Fill the list of new document types foreach (ScriptConfiguration cfg in scriptconfigs) { // Button for new script menu ToolStripMenuItem item = new ToolStripMenuItem(cfg.Description); //item.Image = buttonnew.Image; item.Tag = cfg; item.Click += buttonnew_Click; buttonnew.DropDownItems.Add(item); // Button for script type menu item = new ToolStripMenuItem(cfg.Description); //item.Image = buttonnew.Image; item.Tag = cfg; item.Click += buttonscriptconfig_Click; buttonscriptconfig.DropDownItems.Add(item); } // Setup supported extensions string filterall = ""; string filterseperate = ""; foreach (ScriptConfiguration cfg in scriptconfigs) { if (cfg.Extensions.Length > 0) { string exts = "*." + string.Join(";*.", cfg.Extensions); if (filterseperate.Length > 0) { filterseperate += "|"; } filterseperate += cfg.Description + "|" + exts; if (filterall.Length > 0) { filterall += ";"; } filterall += exts; } } openfile.Filter = "Script files|" + filterall + "|" + filterseperate + "|All files|*.*"; // Load the script lumps ScriptDocumentTab activetab = null; //mxd foreach (MapLumpInfo maplumpinfo in General.Map.Config.MapLumps.Values) { // Is this a script lump? if (maplumpinfo.ScriptBuild) //mxd { ScriptConfiguration config = General.GetScriptConfiguration(ScriptType.ACS); if (config == null) { General.ErrorLogger.Add(ErrorType.Warning, "Unable to find script configuration for \"" + ScriptType.ACS + "\" script type. Using plain text configuration."); config = new ScriptConfiguration(); } // Load this! ScriptLumpDocumentTab t = new ScriptLumpDocumentTab(this, maplumpinfo.Name, config); //mxd. Apply stored settings? if (General.Map.Options.ScriptLumpSettings.ContainsKey(maplumpinfo.Name)) { t.SetViewSettings(General.Map.Options.ScriptLumpSettings[maplumpinfo.Name]); if (General.Map.Options.ScriptLumpSettings[maplumpinfo.Name].IsActiveTab) { activetab = t; } } else { t.SetDefaultViewSettings(); } t.OnTextChanged += tabpage_OnLumpTextChanged; //mxd t.Scintilla.UpdateUI += scintilla_OnUpdateUI; //mxd tabs.TabPages.Add(t); } else if (maplumpinfo.Script != null) { // Load this! ScriptLumpDocumentTab t = new ScriptLumpDocumentTab(this, maplumpinfo.Name, maplumpinfo.Script); //mxd. Apply stored settings? if (General.Map.Options.ScriptLumpSettings.ContainsKey(maplumpinfo.Name)) { t.SetViewSettings(General.Map.Options.ScriptLumpSettings[maplumpinfo.Name]); if (General.Map.Options.ScriptLumpSettings[maplumpinfo.Name].IsActiveTab) { activetab = t; } } else { t.SetDefaultViewSettings(); } t.OnTextChanged += tabpage_OnLumpTextChanged; //mxd t.Scintilla.UpdateUI += scintilla_OnUpdateUI; //mxd tabs.TabPages.Add(t); } } // Load the files that were previously opened for this map foreach (ScriptDocumentSettings settings in General.Map.Options.ScriptFileSettings.Values) { // Does this file exist? if (File.Exists(settings.Filename)) { // Load this! ScriptFileDocumentTab t = OpenFile(settings.Filename); t.SetViewSettings(settings); //mxd if (settings.IsActiveTab) { activetab = t; } } } //mxd. Reselect previously selected tab if (activetab != null) { tabs.SelectedTab = activetab; } //mxd. Select "Scripts" tab, because that's what user will want 99% of time else if (tabs.TabPages.Count > 0) { int scriptsindex = GetTabPageIndex("SCRIPTS"); tabs.SelectedIndex = (scriptsindex == -1 ? 0 : scriptsindex); activetab = tabs.TabPages[tabs.SelectedIndex] as ScriptDocumentTab; } //mxd. Apply quick search settings searchmatchcase.Checked = matchcase; searchwholeword.Checked = matchwholeword; searchbox_TextChanged(this, EventArgs.Empty); //mxd. If the map or script navigator has any compile errors, show them if (activetab != null) { List <CompilerError> errors = (General.Map.Errors.Count > 0 ? General.Map.Errors : activetab.UpdateNavigator()); if (errors.Count > 0) { ShowErrors(errors, false); } else { ClearErrors(); } } else { ClearErrors(); } // Done UpdateToolbar(true); }