2009-04-19 18:07:22 +00:00
#region = = = = = = = = = = = = = = = = = = Copyright ( c ) 2007 Pascal vd Heiden
/ *
* Copyright ( c ) 2007 Pascal vd Heiden , www . codeimp . com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* /
#endregion
#region = = = = = = = = = = = = = = = = = = Namespaces
using System ;
using System.Collections.Generic ;
2014-12-10 13:15:23 +00:00
using System.Drawing ;
2009-04-19 18:07:22 +00:00
using System.Windows.Forms ;
using CodeImp.DoomBuilder.Windows ;
using CodeImp.DoomBuilder.Config ;
using System.Globalization ;
using System.IO ;
using CodeImp.DoomBuilder.Compilers ;
2012-07-16 09:45:21 +00:00
using CodeImp.DoomBuilder.GZBuilder.Data ;
2009-04-19 18:07:22 +00:00
#endregion
namespace CodeImp.DoomBuilder.Controls
{
internal partial class ScriptEditorPanel : UserControl
{
#region = = = = = = = = = = = = = = = = = = Constants
#endregion
#region = = = = = = = = = = = = = = = = = = Variables
private List < ScriptConfiguration > scriptconfigs ;
private List < CompilerError > compilererrors ;
// Find/Replace
private ScriptFindReplaceForm findreplaceform ;
private FindReplaceOptions findoptions ;
2014-12-10 13:15:23 +00:00
// Quick search bar settings (mxd)
private static bool matchwholeword ;
private static bool matchcase ;
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Properties
public ScriptDocumentTab ActiveTab { get { return ( tabs . SelectedTab as ScriptDocumentTab ) ; } }
#endregion
#region = = = = = = = = = = = = = = = = = = Constructor
// Constructor
public ScriptEditorPanel ( )
{
InitializeComponent ( ) ;
}
// This initializes the control
public void Initialize ( )
{
ToolStripMenuItem item ;
// 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
item = new ToolStripMenuItem ( cfg . Description ) ;
//item.Image = buttonnew.Image;
item . Tag = cfg ;
2014-02-21 14:42:12 +00:00
item . Click + = buttonnew_Click ;
2009-04-19 18:07:22 +00:00
buttonnew . DropDownItems . Add ( item ) ;
// Button for script type menu
item = new ToolStripMenuItem ( cfg . Description ) ;
//item.Image = buttonnew.Image;
item . Tag = cfg ;
2014-02-21 14:42:12 +00:00
item . Click + = buttonscriptconfig_Click ;
2009-04-19 18:07:22 +00:00
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
foreach ( MapLumpInfo maplumpinfo in General . Map . Config . MapLumps . Values )
{
// Is this a script lump?
2014-11-11 11:47:10 +00:00
if ( maplumpinfo . Script ! = null )
2009-04-19 18:07:22 +00:00
{
// Load this!
2014-11-11 11:47:10 +00:00
ScriptLumpDocumentTab t = new ScriptLumpDocumentTab ( this , maplumpinfo . Name , maplumpinfo . Script ) ;
2009-04-19 18:07:22 +00:00
tabs . TabPages . Add ( t ) ;
2014-07-11 10:13:26 +00:00
}
2014-11-11 11:47:10 +00:00
else if ( maplumpinfo . ScriptBuild ) //mxd
2014-07-11 10:13:26 +00:00
{
// Load this!
2014-11-11 11:47:10 +00:00
ScriptLumpDocumentTab t = new ScriptLumpDocumentTab ( this , maplumpinfo . Name , General . CompiledScriptConfigs [ General . Map . Options . ScriptCompiler ] ) ;
2014-07-11 10:13:26 +00:00
tabs . TabPages . Add ( t ) ;
2009-04-19 18:07:22 +00:00
}
}
// Load the files that were previously opened for this map
foreach ( String filename in General . Map . Options . ScriptFiles )
{
// Does this file exist?
if ( File . Exists ( filename ) )
{
// Load this!
OpenFile ( filename ) ;
}
}
2013-09-11 09:47:53 +00:00
//mxd. Select "Scripts" tab, because that's what user will want 99% of time
2014-12-03 23:15:26 +00:00
if ( tabs . TabPages . Count > 0 )
{
foreach ( TabPage p in tabs . TabPages )
{
if ( p . Text = = "SCRIPTS" )
{
2013-09-11 09:47:53 +00:00
tabs . SelectedTab = p ;
break ;
}
}
if ( tabs . SelectedIndex = = - 1 ) tabs . SelectedIndex = 0 ;
}
2014-12-10 13:15:23 +00:00
//mxd. Apply quick search settings
searchmatchcase . Checked = matchcase ;
searchwholeword . Checked = matchwholeword ;
searchbox_TextChanged ( this , EventArgs . Empty ) ;
2009-04-19 18:07:22 +00:00
// If the map has remembered any compile errors, then show them
ShowErrors ( General . Map . Errors ) ;
// Done
UpdateToolbar ( true ) ;
}
// This applies user preferences
public void ApplySettings ( )
{
// Apply settings
//int panel2size = General.Settings.ReadSetting("scriptspanel.splitter", splitter.ClientRectangle.Height - splitter.SplitterDistance);
//splitter.SplitterDistance = splitter.ClientRectangle.Height - panel2size;
errorlist . Columns [ 0 ] . Width = General . Settings . ReadSetting ( "scriptspanel.errorscolumn0width" , errorlist . Columns [ 0 ] . Width ) ;
errorlist . Columns [ 1 ] . Width = General . Settings . ReadSetting ( "scriptspanel.errorscolumn1width" , errorlist . Columns [ 1 ] . Width ) ;
errorlist . Columns [ 2 ] . Width = General . Settings . ReadSetting ( "scriptspanel.errorscolumn2width" , errorlist . Columns [ 2 ] . Width ) ;
}
// This saves user preferences
public void SaveSettings ( )
{
//General.Settings.WriteSetting("scriptspanel.splitter", splitter.ClientRectangle.Height - splitter.SplitterDistance);
General . Settings . WriteSetting ( "scriptspanel.errorscolumn0width" , errorlist . Columns [ 0 ] . Width ) ;
General . Settings . WriteSetting ( "scriptspanel.errorscolumn1width" , errorlist . Columns [ 1 ] . Width ) ;
General . Settings . WriteSetting ( "scriptspanel.errorscolumn2width" , errorlist . Columns [ 2 ] . Width ) ;
}
#endregion
#region = = = = = = = = = = = = = = = = = = Methods
// Find Next
public void FindNext ( FindReplaceOptions options )
{
// Save the options
findoptions = options ;
FindNext ( ) ;
}
// Find Next with saved options
public void FindNext ( )
{
if ( ! string . IsNullOrEmpty ( findoptions . FindText ) & & ( ActiveTab ! = null ) )
{
if ( ! ActiveTab . FindNext ( findoptions ) )
{
General . MainWindow . DisplayStatus ( StatusType . Warning , "Can't find any occurence of \"" + findoptions . FindText + "\"." ) ;
}
}
else
{
General . MessageBeep ( MessageBeepType . Default ) ;
}
}
2014-12-10 13:15:23 +00:00
// Find Previous
public void FindPrevious ( FindReplaceOptions options )
{
// Save the options
findoptions = options ;
FindPrevious ( ) ;
}
// Find Previous with saved options (mxd)
public void FindPrevious ( )
{
if ( ! string . IsNullOrEmpty ( findoptions . FindText ) & & ( ActiveTab ! = null ) )
{
if ( ! ActiveTab . FindPrevious ( findoptions ) )
{
General . MainWindow . DisplayStatus ( StatusType . Warning , "Can't find any occurence of \"" + findoptions . FindText + "\"." ) ;
}
}
else
{
General . MessageBeep ( MessageBeepType . Default ) ;
}
}
2009-04-19 18:07:22 +00:00
// Replace if possible
public void Replace ( FindReplaceOptions options )
{
if ( ! string . IsNullOrEmpty ( findoptions . FindText ) & & ( options . ReplaceWith ! = null ) & & ( ActiveTab ! = null ) )
{
if ( string . Compare ( ActiveTab . GetSelectedText ( ) , options . FindText , ! options . CaseSensitive ) = = 0 )
{
// Replace selection
ActiveTab . ReplaceSelection ( options . ReplaceWith ) ;
}
}
else
{
General . MessageBeep ( MessageBeepType . Default ) ;
}
}
// Replace all
public void ReplaceAll ( FindReplaceOptions options )
{
int replacements = 0 ;
findoptions = options ;
if ( ! string . IsNullOrEmpty ( findoptions . FindText ) & & ( options . ReplaceWith ! = null ) & & ( ActiveTab ! = null ) )
{
2010-08-02 06:11:35 +00:00
int firstfindpos = - 1 ;
int lastpos = - 1 ;
bool firstreplace = true ;
bool wrappedaround = false ;
int selectionstart = Math . Min ( ActiveTab . SelectionStart , ActiveTab . SelectionEnd ) ;
2009-04-19 18:07:22 +00:00
// Continue finding and replacing until nothing more found
while ( ActiveTab . FindNext ( findoptions ) )
{
2010-08-02 06:11:35 +00:00
int curpos = Math . Min ( ActiveTab . SelectionStart , ActiveTab . SelectionEnd ) ;
if ( curpos < = lastpos )
wrappedaround = true ;
if ( firstreplace )
{
// Remember where we started replacing
firstfindpos = curpos ;
}
else if ( wrappedaround )
{
// Make sure we don't go past our start point, or we could be in an endless loop
if ( curpos > = firstfindpos )
break ;
}
2009-04-19 18:07:22 +00:00
Replace ( findoptions ) ;
replacements + + ;
2010-08-02 06:11:35 +00:00
firstreplace = false ;
lastpos = curpos ;
2009-04-19 18:07:22 +00:00
}
2010-08-02 06:11:35 +00:00
// Restore selection
ActiveTab . SelectionStart = selectionstart ;
ActiveTab . SelectionEnd = selectionstart ;
2009-04-19 18:07:22 +00:00
// Show result
if ( replacements = = 0 )
General . MainWindow . DisplayStatus ( StatusType . Warning , "Can't find any occurence of \"" + findoptions . FindText + "\"." ) ;
else
General . MainWindow . DisplayStatus ( StatusType . Info , "Replaced " + replacements + " occurences of \"" + findoptions . FindText + "\" with \"" + findoptions . ReplaceWith + "\"." ) ;
}
else
{
General . MessageBeep ( MessageBeepType . Default ) ;
}
}
// This closed the Find & Replace subwindow
public void CloseFindReplace ( bool closing )
{
if ( findreplaceform ! = null )
{
if ( ! closing ) findreplaceform . Close ( ) ;
findreplaceform = null ;
}
}
// This opens the Find & Replace subwindow
public void OpenFindAndReplace ( )
{
if ( findreplaceform = = null )
findreplaceform = new ScriptFindReplaceForm ( ) ;
2010-08-02 06:11:35 +00:00
try
{
if ( findreplaceform . Visible )
findreplaceform . Focus ( ) ;
else
findreplaceform . Show ( this . ParentForm ) ;
if ( ActiveTab . SelectionEnd ! = ActiveTab . SelectionStart )
findreplaceform . SetFindText ( ActiveTab . GetSelectedText ( ) ) ;
}
catch ( Exception )
{
// If we can't pop up the find/replace form right now, thats just too bad.
}
2009-04-19 18:07:22 +00:00
}
// This refreshes all settings
public void RefreshSettings ( )
{
foreach ( ScriptDocumentTab t in tabs . TabPages )
{
t . RefreshSettings ( ) ;
}
}
// This clears all error marks and hides the errors list
public void ClearErrors ( )
{
// Hide list
splitter . Panel2Collapsed = true ;
errorlist . Items . Clear ( ) ;
// Clear marks
foreach ( ScriptDocumentTab t in tabs . TabPages )
{
t . ClearMarks ( ) ;
}
}
// This shows the errors panel with the given errors
// Also updates the scripts with markers for the given errors
public void ShowErrors ( IEnumerable < CompilerError > errors )
{
// Copy list
if ( errors ! = null )
compilererrors = new List < CompilerError > ( errors ) ;
else
compilererrors = new List < CompilerError > ( ) ;
// Fill list
errorlist . BeginUpdate ( ) ;
errorlist . Items . Clear ( ) ;
int listindex = 1 ;
foreach ( CompilerError e in compilererrors )
{
ListViewItem ei = new ListViewItem ( listindex . ToString ( ) ) ;
ei . ImageIndex = 0 ;
ei . SubItems . Add ( e . description ) ;
if ( e . filename . StartsWith ( "?" ) )
2014-05-15 13:16:30 +00:00
ei . SubItems . Add ( e . filename . Replace ( "?" , "" ) + " (line " + ( e . linenumber + 1 ) + ")" ) ;
2009-04-19 18:07:22 +00:00
else
2014-05-15 13:16:30 +00:00
ei . SubItems . Add ( Path . GetFileName ( e . filename ) + " (line " + ( e . linenumber + 1 ) + ")" ) ;
2009-04-19 18:07:22 +00:00
ei . Tag = e ;
errorlist . Items . Add ( ei ) ;
listindex + + ;
}
errorlist . EndUpdate ( ) ;
// Show marks on scripts
foreach ( ScriptDocumentTab t in tabs . TabPages )
{
t . MarkScriptErrors ( compilererrors ) ;
}
// Show/hide panel
splitter . Panel2Collapsed = ( errorlist . Items . Count = = 0 ) ;
}
// This writes all explicitly opened files to the configuration
public void WriteOpenFilesToConfiguration ( )
{
List < string > files = new List < string > ( ) ;
foreach ( ScriptDocumentTab t in tabs . TabPages )
{
if ( t . ExplicitSave ) files . Add ( t . Filename ) ;
}
General . Map . Options . ScriptFiles = files ;
}
// This asks to save files and returns the result
public bool AskSaveAll ( )
{
foreach ( ScriptDocumentTab t in tabs . TabPages )
{
if ( t . ExplicitSave )
{
if ( ! CloseScript ( t , true ) ) return false ;
}
}
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 . 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 returns true when any of the implicit-save scripts are changed
public bool CheckImplicitChanges ( )
{
bool changes = false ;
foreach ( ScriptDocumentTab t in tabs . TabPages )
{
if ( ! t . ExplicitSave & & t . IsChanged ) changes = true ;
}
return changes ;
}
// This forces the focus to the script editor
public void ForceFocus ( )
{
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
tabs . Focus ( ) ;
if ( t ! = null ) t . Focus ( ) ;
}
// This does an implicit save on all documents that use implicit saving
// Call this to save the lumps before disposing the panel!
public void ImplicitSave ( )
{
// Save all scripts
foreach ( ScriptDocumentTab t in tabs . TabPages )
{
if ( ! t . ExplicitSave ) t . Save ( ) ;
}
UpdateToolbar ( false ) ;
}
// 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 ) ;
2009-05-10 17:02:47 +00:00
buttonkeywordhelp . Enabled = ( t ! = null ) & & ! string . IsNullOrEmpty ( t . Config . KeywordHelp ) ;
2009-04-19 18:07:22 +00:00
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 ;
2014-05-13 09:43:58 +00:00
buttonsnippets . DropDownItems . Clear ( ) ; //mxd
buttonsnippets . Enabled = ( t ! = null ) & & t . Config . Snippets . Count > 0 ; //mxd
2009-04-19 18:07:22 +00:00
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 ) ;
}
2014-05-13 09:43:58 +00:00
//mxd. Add snippets
2014-12-03 23:15:26 +00:00
if ( t . Config . Snippets . Count > 0 )
{
foreach ( KeyValuePair < string , string [ ] > group in t . Config . Snippets )
2014-05-13 09:43:58 +00:00
buttonsnippets . DropDownItems . Add ( group . Key ) . Click + = OnInsertSnippetClick ;
}
2009-04-19 18:07:22 +00:00
// Focus to script editor
if ( focuseditor ) ForceFocus ( ) ;
}
}
// This opens the given file, returns null when failed
public ScriptFileDocumentTab OpenFile ( string filename )
{
ScriptConfiguration foundconfig = new ScriptConfiguration ( ) ;
// Find the most suitable script configuration to use
foreach ( ScriptConfiguration cfg in scriptconfigs )
{
foreach ( string ext in cfg . Extensions )
{
// Use this configuration if the extension matches
if ( filename . EndsWith ( "." + ext , true , CultureInfo . InvariantCulture ) )
{
foundconfig = cfg ;
break ;
}
}
}
// Create new document
ScriptFileDocumentTab t = new ScriptFileDocumentTab ( this , foundconfig ) ;
if ( t . Open ( filename ) )
{
2013-09-11 09:47:53 +00:00
//mxd
ScriptType st = t . VerifyScriptType ( ) ;
2014-12-03 23:15:26 +00:00
if ( st ! = ScriptType . UNKNOWN )
{
foreach ( ScriptConfiguration cfg in scriptconfigs )
{
if ( cfg . ScriptType = = st )
{
2013-09-11 09:47:53 +00:00
t . ChangeScriptConfig ( cfg ) ;
break ;
}
}
}
// Mark any errors this script may have
2014-12-03 23:15:26 +00:00
if ( compilererrors ! = null ) t . MarkScriptErrors ( compilererrors ) ;
2009-04-19 18:07:22 +00:00
// Add to tabs
tabs . TabPages . Add ( t ) ;
tabs . SelectedTab = t ;
// Done
UpdateToolbar ( true ) ;
return t ;
}
else
{
// Failed
return null ;
}
}
// 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 opens a script
public void OpenBrowseScript ( )
{
buttonopen_Click ( this , EventArgs . Empty ) ;
}
2013-08-08 11:04:13 +00:00
//mxd. This launches keyword help website
2014-12-03 23:15:26 +00:00
public bool LaunchKeywordHelp ( )
{
2013-08-08 11:04:13 +00:00
// Get script
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
return t . LaunchKeywordHelp ( ) ;
}
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Events
// Called when the window that contains this panel closes
public void OnClose ( )
{
2014-12-10 13:15:23 +00:00
//mxd. Store quick search settings
matchcase = searchmatchcase . Checked ;
matchwholeword = searchwholeword . Checked ;
2009-04-19 18:07:22 +00:00
// Close the sub windows now
if ( findreplaceform ! = null ) findreplaceform . Dispose ( ) ;
}
2009-05-10 17:02:47 +00:00
// Keyword help requested
private void buttonkeywordhelp_Click ( object sender , EventArgs e )
{
2013-08-08 11:04:13 +00:00
LaunchKeywordHelp ( ) ;
2009-05-10 17:02:47 +00:00
}
2009-04-19 18:07:22 +00:00
// 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 ) ;
}
// When new script is clicked
private void buttonnew_Click ( object sender , EventArgs e )
{
// Get the script config to use
ScriptConfiguration scriptconfig = ( ( sender as ToolStripMenuItem ) . Tag as ScriptConfiguration ) ;
// Create new document
ScriptFileDocumentTab t = new ScriptFileDocumentTab ( this , scriptconfig ) ;
tabs . TabPages . Add ( t ) ;
tabs . SelectedTab = t ;
// Done
UpdateToolbar ( true ) ;
}
// Open script clicked
private void buttonopen_Click ( object sender , EventArgs e )
{
// Show open file dialog
if ( openfile . ShowDialog ( this . ParentForm ) = = DialogResult . OK )
{
// TODO: Make multi-select possible
OpenFile ( openfile . FileName ) ;
}
}
// 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 ) ;
}
// Save All clicked
private void buttonsaveall_Click ( object sender , EventArgs e )
{
// Save all scripts
foreach ( ScriptDocumentTab t in tabs . TabPages )
{
// Use explicit save for this script?
if ( t . ExplicitSave )
{
if ( ! SaveScript ( t ) ) break ;
}
}
UpdateToolbar ( 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 ;
}
}
// A tab is selected
private void tabs_Selecting ( object sender , TabControlCancelEventArgs e )
{
UpdateToolbar ( 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 ) ;
}
// 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 ) )
2014-02-21 14:42:12 +00:00
General . MainWindow . DisplayStatus ( StatusType . Warning , compilererrors . Count + " errors while compiling " + t . Text + "!" ) ;
2009-04-19 18:07:22 +00:00
else
General . MainWindow . DisplayStatus ( StatusType . Info , "Script " + t . Text + " compiled without errors." ) ;
Cursor . Current = Cursors . Default ;
UpdateToolbar ( true ) ;
}
// Undo clicked
private void buttonundo_Click ( object sender , EventArgs e )
{
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
t . Undo ( ) ;
UpdateToolbar ( true ) ;
}
// Redo clicked
private void buttonredo_Click ( object sender , EventArgs e )
{
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
t . Redo ( ) ;
UpdateToolbar ( true ) ;
}
// Cut clicked
private void buttoncut_Click ( object sender , EventArgs e )
{
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
t . Cut ( ) ;
UpdateToolbar ( true ) ;
}
// Copy clicked
private void buttoncopy_Click ( object sender , EventArgs e )
{
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
t . Copy ( ) ;
UpdateToolbar ( true ) ;
}
// Paste clicked
private void buttonpaste_Click ( object sender , EventArgs e )
{
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
t . Paste ( ) ;
UpdateToolbar ( true ) ;
}
2014-03-03 11:45:03 +00:00
//mxd. Search clicked
private void buttonsearch_Click ( object sender , EventArgs e )
{
OpenFindAndReplace ( ) ;
}
2014-05-13 09:43:58 +00:00
//mxd
private void OnInsertSnippetClick ( object sender , EventArgs eventArgs )
{
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
t . InsertSnippet ( t . Config . Snippets [ ( ( ToolStripItem ) sender ) . Text ] ) ;
}
2009-04-19 18:07:22 +00:00
// Mouse released on tabs
private void tabs_MouseUp ( object sender , MouseEventArgs e )
{
ForceFocus ( ) ;
}
// 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 ( ) ;
}
}
#endregion
2014-12-10 13:15:23 +00:00
#region = = = = = = = = = = = = = = = = = = Quick Search ( mxd )
private FindReplaceOptions GetQuickSearchOptions ( )
{
return new FindReplaceOptions
{
CaseSensitive = searchmatchcase . Checked ,
WholeWord = searchwholeword . Checked ,
FindText = searchbox . Text
} ;
}
private void searchbox_TextChanged ( object sender , EventArgs e )
{
2014-12-10 14:22:54 +00:00
bool success = ( searchbox . Text . Length > 0 & & ActiveTab . FindNext ( GetQuickSearchOptions ( ) , true ) ) ;
2014-12-10 13:15:23 +00:00
searchbox . BackColor = ( ( success | | searchbox . Text . Length = = 0 ) ? SystemColors . Window : Color . MistyRose ) ;
searchnext . Enabled = success ;
searchprev . Enabled = success ;
}
private void searchnext_Click ( object sender , EventArgs e )
{
ActiveTab . FindNext ( GetQuickSearchOptions ( ) ) ;
}
private void searchprev_Click ( object sender , EventArgs e )
{
ActiveTab . FindPrevious ( GetQuickSearchOptions ( ) ) ;
}
#endregion
2009-04-19 18:07:22 +00:00
}
}