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.IO ;
2015-11-30 14:18:42 +00:00
using System.Windows.Forms ;
2009-04-19 18:07:22 +00:00
using CodeImp.DoomBuilder.Compilers ;
2015-11-30 14:18:42 +00:00
using CodeImp.DoomBuilder.Config ;
2016-11-24 11:55:11 +00:00
using CodeImp.DoomBuilder.Controls.Scripting ;
using CodeImp.DoomBuilder.Data.Scripting ;
2015-11-30 14:18:42 +00:00
using CodeImp.DoomBuilder.Windows ;
2016-01-27 14:08:15 +00:00
using ScintillaNET ;
2009-04-19 18:07:22 +00:00
#endregion
namespace CodeImp.DoomBuilder.Controls
{
internal partial class ScriptEditorPanel : UserControl
{
#region = = = = = = = = = = = = = = = = = = Constants
2016-04-17 22:52:03 +00:00
private static readonly Color QUICKSEARCH_FAIL_COLOR = Color . MistyRose ; //mxd
2009-04-19 18:07:22 +00:00
#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 ;
2015-11-30 14:18:42 +00:00
//mxd. Status update
private ScriptStatusInfo status ;
private int statusflashcount ;
private bool statusflashicon ;
2016-11-24 11:55:11 +00:00
//mxd
private ScriptEditorForm parentform ;
private ScriptIconsManager iconsmgr ;
//mxd. Text editor settings
private bool showwhitespace ;
private bool wraplonglines ;
private bool blockupdate ;
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Properties
public ScriptDocumentTab ActiveTab { get { return ( tabs . SelectedTab as ScriptDocumentTab ) ; } }
2016-11-24 11:55:11 +00:00
internal ScriptIconsManager Icons { get { return iconsmgr ; } }
public bool ShowWhitespace { get { return showwhitespace ; } }
public bool WrapLongLines { get { return wraplonglines ; } }
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Constructor
// Constructor
public ScriptEditorPanel ( )
{
InitializeComponent ( ) ;
2016-11-24 11:55:11 +00:00
iconsmgr = new ScriptIconsManager ( scripticons ) ; //mxd
tabs . ImageList = scripticons ; //mxd
2009-04-19 18:07:22 +00:00
}
// This initializes the control
2016-11-24 11:55:11 +00:00
public void Initialize ( ScriptEditorForm form )
2009-04-19 18:07:22 +00:00
{
2016-11-24 11:55:11 +00:00
parentform = form ; //mxd
2009-04-19 18:07:22 +00:00
// 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 )
{
2016-11-24 11:55:11 +00:00
Image icon = scripticons . Images [ iconsmgr . GetScriptIcon ( cfg . ScriptType ) ] ; //mxd
2009-04-19 18:07:22 +00:00
// Button for new script menu
2015-12-28 15:01:53 +00:00
ToolStripMenuItem item = new ToolStripMenuItem ( cfg . Description ) ;
2016-11-24 11:55:11 +00:00
item . Image = icon ; //mxd
2009-04-19 18:07:22 +00:00
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 ) ;
2016-11-24 11:55:11 +00:00
item . Image = icon ; //mxd
2009-04-19 18:07:22 +00:00
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 ) ;
2016-11-24 11:55:11 +00:00
//mxd. Button for the "New" menu item
item = new ToolStripMenuItem ( cfg . Description ) ;
item . Image = icon ; //mxd
item . Tag = cfg ;
item . Click + = buttonnew_Click ;
menunew . DropDownItems . Add ( item ) ;
2009-04-19 18:07:22 +00:00
}
// 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|*.*" ;
2016-11-24 11:55:11 +00:00
//mxd. Initialize script resources control
scriptresources . Setup ( this , General . Map . Data . ScriptResources ) ;
2009-04-19 18:07:22 +00:00
// Load the script lumps
2016-02-05 15:21:58 +00:00
ScriptDocumentTab activetab = null ; //mxd
2009-04-19 18:07:22 +00:00
foreach ( MapLumpInfo maplumpinfo in General . Map . Config . MapLumps . Values )
{
// Is this a script lump?
2016-01-27 14:08:15 +00:00
if ( maplumpinfo . ScriptBuild ) //mxd
2009-04-19 18:07:22 +00:00
{
2016-05-12 13:56:25 +00:00
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 ( ) ;
}
2009-04-19 18:07:22 +00:00
// Load this!
2016-05-12 13:56:25 +00:00
ScriptLumpDocumentTab t = new ScriptLumpDocumentTab ( this , maplumpinfo . Name , config ) ;
2016-02-05 15:21:58 +00:00
//mxd. Apply stored settings?
2016-11-24 11:55:11 +00:00
if ( General . Map . Options . ScriptDocumentSettings . ContainsKey ( maplumpinfo . Name ) )
2016-02-05 15:21:58 +00:00
{
2016-11-24 11:55:11 +00:00
t . SetViewSettings ( General . Map . Options . ScriptDocumentSettings [ maplumpinfo . Name ] ) ;
if ( General . Map . Options . ScriptDocumentSettings [ maplumpinfo . Name ] . IsActiveTab )
2016-02-05 15:21:58 +00:00
activetab = t ;
}
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
else
{
t . SetDefaultViewSettings ( ) ;
}
2016-02-05 15:21:58 +00:00
2016-01-27 14:08:15 +00:00
t . OnTextChanged + = tabpage_OnLumpTextChanged ; //mxd
2016-11-24 11:55:11 +00:00
t . Editor . Scintilla . UpdateUI + = scintilla_OnUpdateUI ; //mxd
2009-04-19 18:07:22 +00:00
tabs . TabPages . Add ( t ) ;
2014-07-11 10:13:26 +00:00
}
2016-01-27 14:08:15 +00:00
else if ( maplumpinfo . Script ! = null )
2014-07-11 10:13:26 +00:00
{
// Load this!
2016-01-27 14:08:15 +00:00
ScriptLumpDocumentTab t = new ScriptLumpDocumentTab ( this , maplumpinfo . Name , maplumpinfo . Script ) ;
2016-02-05 15:21:58 +00:00
//mxd. Apply stored settings?
2016-11-24 11:55:11 +00:00
if ( General . Map . Options . ScriptDocumentSettings . ContainsKey ( maplumpinfo . Name ) )
2016-02-05 15:21:58 +00:00
{
2016-11-24 11:55:11 +00:00
t . SetViewSettings ( General . Map . Options . ScriptDocumentSettings [ maplumpinfo . Name ] ) ;
if ( General . Map . Options . ScriptDocumentSettings [ maplumpinfo . Name ] . IsActiveTab )
2016-02-05 15:21:58 +00:00
activetab = t ;
}
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
else
{
t . SetDefaultViewSettings ( ) ;
}
2016-02-05 15:21:58 +00:00
2016-01-27 14:08:15 +00:00
t . OnTextChanged + = tabpage_OnLumpTextChanged ; //mxd
2016-11-24 11:55:11 +00:00
t . Editor . Scintilla . UpdateUI + = scintilla_OnUpdateUI ; //mxd
2014-07-11 10:13:26 +00:00
tabs . TabPages . Add ( t ) ;
2009-04-19 18:07:22 +00:00
}
}
2016-11-24 11:55:11 +00:00
// Load files, which were previously opened for this map
foreach ( ScriptDocumentSettings settings in General . Map . Options . ScriptDocumentSettings . Values )
2009-04-19 18:07:22 +00:00
{
2016-11-24 11:55:11 +00:00
switch ( settings . TabType )
2009-04-19 18:07:22 +00:00
{
2016-11-24 11:55:11 +00:00
//TODO: load all tab types here...
case ScriptDocumentTabType . LUMP : continue ;
case ScriptDocumentTabType . FILE :
// 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 ;
}
break ;
case ScriptDocumentTabType . RESOURCE :
// Find target resource...
if ( ! General . Map . Data . ScriptResources . ContainsKey ( settings . ScriptType ) ) continue ;
foreach ( ScriptResource res in General . Map . Data . ScriptResources [ settings . ScriptType ] )
{
if ( res . Resource . Location . location = = settings . ResourceLocation )
{
// Load this!
ScriptResourceDocumentTab t = OpenResource ( res ) ;
t . SetViewSettings ( settings ) ;
if ( settings . IsActiveTab ) activetab = t ;
break ;
}
}
break ;
default :
throw new NotImplementedException ( "Unknown ScriptDocumentTabType!" ) ;
2009-04-19 18:07:22 +00:00
}
}
2016-02-05 15:21:58 +00:00
//mxd. Reselect previously selected tab
if ( activetab ! = null )
{
tabs . SelectedTab = activetab ;
}
2016-11-24 11:55:11 +00:00
//mxd. Select the "Scripts" tab, because that's what user will want 99% of time
2016-03-04 08:10:56 +00:00
else if ( tabs . TabPages . Count > 0 )
2016-02-05 15:21:58 +00:00
{
2016-11-24 11:55:11 +00:00
int scriptsindex = - 1 ;
for ( int i = 0 ; i < tabs . TabPages . Count ; i + + )
{
if ( tabs . TabPages [ i ] . Text = = "SCRIPTS" )
{
scriptsindex = i ;
break ;
}
}
2016-02-05 15:21:58 +00:00
tabs . SelectedIndex = ( scriptsindex = = - 1 ? 0 : scriptsindex ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
activetab = tabs . TabPages [ tabs . SelectedIndex ] as ScriptDocumentTab ;
2016-02-05 15:21:58 +00:00
}
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
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
//mxd. If the map or script navigator has any compile errors, show them
if ( activetab ! = null )
{
2016-03-04 08:10:56 +00:00
List < CompilerError > errors = ( General . Map . Errors . Count > 0 ? General . Map . Errors : activetab . UpdateNavigator ( ) ) ;
2016-05-12 13:56:25 +00:00
if ( errors . Count > 0 ) ShowErrors ( errors , false ) ;
2016-03-04 08:10:56 +00:00
else ClearErrors ( ) ;
}
else
{
ClearErrors ( ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
}
2009-04-19 18:07:22 +00:00
// Done
2016-11-24 11:55:11 +00:00
UpdateInterface ( true ) ;
2009-04-19 18:07:22 +00:00
}
// This applies user preferences
public void ApplySettings ( )
{
2016-11-24 11:55:11 +00:00
// Set Errors panel settings
2009-04-19 18:07:22 +00:00
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 ) ;
2016-11-24 11:55:11 +00:00
//mxd. Set splitter position and state
if ( General . Settings . ReadSetting ( "scriptspanel.splittercollapsed" , false ) )
mainsplitter . IsCollapsed = true ;
int splitterdistance = General . Settings . ReadSetting ( "scriptspanel.splitterdistance" , int . MinValue ) ;
if ( splitterdistance = = int . MinValue )
{
splitterdistance = 200 ;
if ( MainForm . DPIScaler . Width ! = 1.0f )
splitterdistance = ( int ) Math . Round ( splitterdistance * MainForm . DPIScaler . Width ) ;
}
mainsplitter . SplitPosition = splitterdistance ;
//mxd. Set text editor settings
showwhitespace = General . Settings . ReadSetting ( "scriptspanel.showwhitespace" , false ) ;
buttonwhitespace . Checked = showwhitespace ;
menuwhitespace . Checked = showwhitespace ;
wraplonglines = General . Settings . ReadSetting ( "scriptspanel.wraplonglines" , false ) ;
buttonwordwrap . Checked = wraplonglines ;
menuwordwrap . Checked = wraplonglines ;
menustayontop . Checked = General . Settings . ScriptOnTop ;
ApplyTabSettings ( ) ;
2009-04-19 18:07:22 +00:00
}
// This saves user preferences
public void SaveSettings ( )
{
General . Settings . WriteSetting ( "scriptspanel.errorscolumn0width" , errorlist . Columns [ 0 ] . Width ) ;
General . Settings . WriteSetting ( "scriptspanel.errorscolumn1width" , errorlist . Columns [ 1 ] . Width ) ;
2016-11-24 11:55:11 +00:00
General . Settings . WriteSetting ( "scriptspanel.errorscolumn2width" , errorlist . Columns [ 2 ] . Width ) ; //mxd
General . Settings . WriteSetting ( "scriptspanel.splittercollapsed" , mainsplitter . IsCollapsed ) ; //mxd
General . Settings . WriteSetting ( "scriptspanel.splitterdistance" , mainsplitter . SplitPosition ) ; //mxd
General . Settings . WriteSetting ( "scriptspanel.showwhitespace" , showwhitespace ) ; //mxd
General . Settings . WriteSetting ( "scriptspanel.wraplonglines" , wraplonglines ) ; //mxd
2016-01-27 14:08:15 +00:00
}
//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 ;
}
}
2009-04-19 18:07:22 +00:00
}
2016-11-24 11:55:11 +00:00
//mxd
internal void OnReloadResources ( )
{
// Re-initialize script resources control
scriptresources . Setup ( this , General . Map . Data . ScriptResources ) ;
// Resource tabs may need re-linking...
foreach ( var tp in tabs . TabPages )
{
var tab = ( tp as ScriptResourceDocumentTab ) ;
if ( tab ! = null ) tab . OnReloadResources ( ) ;
}
}
//mxd. Handle heavy resource loss
internal void OnScriptResourceLost ( ScriptResourceDocumentTab sourcetab )
{
// Resource was lost. Remove tab
if ( ! sourcetab . IsChanged )
{
tabs . TabPages . Remove ( sourcetab ) ;
}
// Resource was lost, but the tab contains unsaved changes. Replace it with ScriptFileDocumentTab
else
{
int tabindex = tabs . TabPages . IndexOf ( sourcetab ) ;
var newtab = new ScriptFileDocumentTab ( sourcetab ) ;
tabs . SuspendLayout ( ) ;
tabs . TabPages . Remove ( sourcetab ) ;
tabs . TabPages . Insert ( tabindex , newtab ) ;
tabs . ResumeLayout ( ) ;
}
}
2009-04-19 18:07:22 +00:00
#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 ) )
2016-05-04 14:02:13 +00:00
DisplayStatus ( ScriptStatusType . Warning , "Can't find any occurrence of \"" + findoptions . FindText + "\"." ) ;
2009-04-19 18:07:22 +00:00
}
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 ) )
{
2015-11-30 14:18:42 +00:00
if ( ! ActiveTab . FindPrevious ( findoptions ) )
2016-05-04 14:02:13 +00:00
DisplayStatus ( ScriptStatusType . Warning , "Can't find any occurrence of \"" + findoptions . FindText + "\"." ) ;
2014-12-10 13:15:23 +00:00
}
else
{
General . MessageBeep ( MessageBeepType . Default ) ;
}
}
2009-04-19 18:07:22 +00:00
// Replace if possible
public void Replace ( FindReplaceOptions options )
{
2016-11-24 11:55:11 +00:00
if ( ! string . IsNullOrEmpty ( findoptions . FindText ) & & options . ReplaceWith ! = null & & ActiveTab ! = null & & ! ActiveTab . IsReadOnly )
2009-04-19 18:07:22 +00:00
{
2016-01-27 14:08:15 +00:00
if ( string . Compare ( ActiveTab . SelectedText , options . FindText , ! options . CaseSensitive ) = = 0 )
2009-04-19 18:07:22 +00:00
{
// Replace selection
ActiveTab . ReplaceSelection ( options . ReplaceWith ) ;
}
}
else
{
General . MessageBeep ( MessageBeepType . Default ) ;
}
}
// Replace all
public void ReplaceAll ( FindReplaceOptions options )
{
int replacements = 0 ;
findoptions = options ;
2016-11-24 11:55:11 +00:00
if ( ! string . IsNullOrEmpty ( findoptions . FindText ) & & options . ReplaceWith ! = null & & ActiveTab ! = null & & ! ActiveTab . IsReadOnly )
2009-04-19 18:07:22 +00:00
{
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 )
2016-05-04 14:02:13 +00:00
DisplayStatus ( ScriptStatusType . Warning , "Can't find any occurrence of \"" + findoptions . FindText + "\"." ) ;
2009-04-19 18:07:22 +00:00
else
2016-05-04 14:02:13 +00:00
DisplayStatus ( ScriptStatusType . Info , "Replaced " + replacements + " occurrences of \"" + findoptions . FindText + "\" with \"" + findoptions . ReplaceWith + "\"." ) ;
2009-04-19 18:07:22 +00:00
}
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
{
2016-11-24 11:55:11 +00:00
findreplaceform . CanReplace = ! ActiveTab . IsReadOnly ; //mxd
2010-08-02 06:11:35 +00:00
if ( findreplaceform . Visible )
findreplaceform . Focus ( ) ;
else
findreplaceform . Show ( this . ParentForm ) ;
if ( ActiveTab . SelectionEnd ! = ActiveTab . SelectionStart )
2016-01-27 14:08:15 +00:00
findreplaceform . SetFindText ( ActiveTab . SelectedText ) ;
2010-08-02 06:11:35 +00:00
}
2016-11-24 11:55:11 +00:00
catch { } // If we can't pop up the find/replace form right now, thats just too bad.
}
//mxd
public void GoToLine ( )
{
if ( ActiveTab = = null ) return ;
var form = new ScriptGoToLineForm { LineNumber = ActiveTab . Editor . Scintilla . CurrentLine } ;
if ( form . ShowDialog ( this . parentform ) = = DialogResult . OK )
2010-08-02 06:11:35 +00:00
{
2016-11-24 11:55:11 +00:00
ActiveTab . MoveToLine ( form . LineNumber - 1 ) ;
2010-08-02 06:11:35 +00:00
}
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
2016-05-12 13:56:25 +00:00
public void ShowErrors ( IEnumerable < CompilerError > errors , bool combine )
2009-04-19 18:07:22 +00:00
{
// Copy list
2016-05-12 13:56:25 +00:00
if ( combine ) //mxd
{
if ( compilererrors = = null ) compilererrors = new List < CompilerError > ( ) ;
if ( errors ! = null )
{
// Combine 2 error lists...
foreach ( CompilerError err in errors )
{
bool alreadyadded = false ;
foreach ( CompilerError compilererror in compilererrors )
{
if ( compilererror . Equals ( err ) )
{
alreadyadded = true ;
break ;
}
}
if ( ! alreadyadded ) compilererrors . Add ( err ) ;
}
}
}
2009-04-19 18:07:22 +00:00
else
2016-05-12 13:56:25 +00:00
{
compilererrors = ( errors ! = null ? new List < CompilerError > ( errors ) : new List < CompilerError > ( ) ) ;
}
2009-04-19 18:07:22 +00:00
// 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 ) ;
2015-11-24 10:46:49 +00:00
string filename = ( e . filename . StartsWith ( "?" ) ? e . filename . Replace ( "?" , "" ) : Path . GetFileName ( e . filename ) ) ; //mxd
string linenumber = ( e . linenumber ! = CompilerError . NO_LINE_NUMBER ? " (line " + ( e . linenumber + 1 ) + ")" : String . Empty ) ; //mxd
ei . SubItems . Add ( filename + linenumber ) ;
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 ( )
{
2016-11-24 11:55:11 +00:00
General . Map . Options . ScriptDocumentSettings . Clear ( ) ; //mxd
2016-02-05 15:21:58 +00:00
foreach ( ScriptDocumentTab t in tabs . TabPages ) //mxd
2009-04-19 18:07:22 +00:00
{
2016-11-24 11:55:11 +00:00
if ( t is ScriptFileDocumentTab )
{
// Don't store tabs, which were never saved (this only happens when a new tab was created and no text
// was entered into it before closing the script editor)
if ( t . ExplicitSave & & ! t . IsSaveAsRequired )
{
var settings = t . GetViewSettings ( ) ;
General . Map . Options . ScriptDocumentSettings [ settings . Filename ] = settings ;
}
}
else if ( t is ScriptLumpDocumentTab | | t is ScriptResourceDocumentTab )
2016-04-30 19:27:26 +00:00
{
2016-11-24 11:55:11 +00:00
var settings = t . GetViewSettings ( ) ;
General . Map . Options . ScriptDocumentSettings [ settings . Filename ] = settings ;
2016-04-30 19:27:26 +00:00
}
2016-02-05 15:21:58 +00:00
else
2016-04-30 19:27:26 +00:00
{
2016-11-24 11:55:11 +00:00
throw new NotImplementedException ( "Unknown ScriptDocumentTab type" ) ;
2016-04-30 19:27:26 +00:00
}
2009-04-19 18:07:22 +00:00
}
}
// 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
2016-01-27 14:08:15 +00:00
DialogResult result = MessageBox . Show ( this . ParentForm , "Do you want to save changes to " + t . Title + "?" , "Close File" , MessageBoxButtons . YesNoCancel , MessageBoxIcon . Question ) ;
2015-12-28 15:01:53 +00:00
switch ( result )
2009-04-19 18:07:22 +00:00
{
2015-07-15 09:09:47 +00:00
case DialogResult . Yes :
if ( ! SaveScript ( t ) ) return false ;
break ;
case DialogResult . Cancel :
return false ;
2009-04-19 18:07:22 +00:00
}
}
if ( ! saveonly )
{
2015-11-30 14:18:42 +00:00
//mxd. Select tab to the left of the one we are going to close
if ( t = = tabs . SelectedTab & & tabs . SelectedIndex > 0 )
tabs . SelectedIndex - - ;
2009-04-19 18:07:22 +00:00
// 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 ( )
{
foreach ( ScriptDocumentTab t in tabs . TabPages )
{
2015-11-30 14:18:42 +00:00
if ( ! t . ExplicitSave & & t . IsChanged ) return true ;
2009-04-19 18:07:22 +00:00
}
2015-11-30 14:18:42 +00:00
return false ;
2009-04-19 18:07:22 +00:00
}
// 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 ( ) ;
}
2016-11-24 11:55:11 +00:00
UpdateInterface ( false ) ;
2009-04-19 18:07:22 +00:00
}
// This updates the toolbar for the current status
2016-11-24 11:55:11 +00:00
private void UpdateInterface ( bool focuseditor )
2009-04-19 18:07:22 +00:00
{
int numscriptsopen = tabs . TabPages . Count ;
int explicitsavescripts = 0 ;
ScriptDocumentTab t = null ;
// Any explicit save scripts?
foreach ( ScriptDocumentTab dt in tabs . TabPages )
2016-11-24 11:55:11 +00:00
if ( dt . ExplicitSave & & ! dt . IsReadOnly ) explicitsavescripts + + ;
2009-04-19 18:07:22 +00:00
// Get current script, if any are open
2016-11-24 11:55:11 +00:00
if ( numscriptsopen > 0 ) t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
2009-04-19 18:07:22 +00:00
// Enable/disable buttons
2016-11-24 11:55:11 +00:00
bool tabiseditable = ( t ! = null & & ! t . IsReadOnly ) ; //mxd
buttonsave . Enabled = ( tabiseditable & & t . ExplicitSave & & t . IsChanged ) ;
2009-04-19 18:07:22 +00:00
buttonsaveall . Enabled = ( explicitsavescripts > 0 ) ;
2016-11-24 11:55:11 +00:00
buttoncompile . Enabled = ( tabiseditable & & t . Config . Compiler ! = null ) ;
Game Configurations: added Vanilla Strife, Vanilla Heretic and Vanilla Hexen game configurations.
Added "makedoorceil" game configuration property. Works the same way as "makedoortrack" and "makedoordoor", but for ceilings of door sectors.
Changed, Game configurations: the editor no longer tries to load DECORATE/MODELDEF/VOXELDEF/GLDEFS/REVERBS lumps when "decorategames" setting is not specified / is set to empty string.
Changed, General interface: "Tools -> Reload MODELDEF/VOXELDEF" and "Tools -> Reload GLDEFS" menu items are no longer shown when current game configuration doesn't support DECORATE.
Fixed a crash when pasting linedef/thing properties in Hexen map format.
Fixed, Visual mode: Visual Thing resources were not fully unloaded when resetting D3D device leading to crash when switching to the editor from a DX-using game engine (like ZDoom) running in fullscreen.
Fixed: in some cases, when current game configuration supported multiple script compilers, it was possible to open/create a map or change map options without selecting any script compiler.
Fixed, New Map Options window: default map name was not updated when switching game configurations.
Fixed: copied map element properties were not reset after switching to another map.
Fixed: stored textures for "Make Door" action were not reset after switching to another map.
Fixed, Game Configurations window: currently selected test engine name was not updated when pasting test engines from another configuration.
Fixed, Game Configurations: all "Heretic in Doom map format" configurations were using Doom sector effects list.
Fixed, Game Configurations: all "Strife in Doom map format" configurations were using Doom sector effects list.
2015-10-21 13:35:42 +00:00
buttonsearch . Enabled = ( t ! = null ) ; //mxd
2016-01-27 14:08:15 +00:00
buttonkeywordhelp . Enabled = ( t ! = null & & ! string . IsNullOrEmpty ( t . Config . KeywordHelp ) ) ;
2016-11-24 11:55:11 +00:00
buttonscriptconfig . Enabled = ( tabiseditable & & t . IsReconfigurable ) ;
// Undo/Redo
buttonundo . Enabled = ( tabiseditable & & t . Editor . Scintilla . CanUndo ) ;
buttonredo . Enabled = ( tabiseditable & & t . Editor . Scintilla . CanRedo ) ;
// Cut/Copy/Paste
buttoncopy . Enabled = ( t ! = null & & t . Editor . Scintilla . SelectionStart < t . Editor . Scintilla . SelectionEnd ) ;
buttoncut . Enabled = ( tabiseditable & & t . Editor . Scintilla . SelectionStart < t . Editor . Scintilla . SelectionEnd ) ;
buttonpaste . Enabled = ( tabiseditable & & t . Editor . Scintilla . CanPaste ) ;
//mxd. Snippets
buttonsnippets . DropDownItems . Clear ( ) ;
menusnippets . DropDownItems . Clear ( ) ;
bool havesnippets = ( tabiseditable & & t . Config . Snippets . Count > 0 ) ;
buttonsnippets . Enabled = havesnippets ;
menusnippets . Enabled = havesnippets ;
//mxd. Indent/Unindent
buttonindent . Enabled = tabiseditable ;
buttonunindent . Enabled = ( tabiseditable & & t . Editor . Scintilla . Lines [ t . Editor . Scintilla . CurrentLine ] . Indentation > 0 ) ;
//mxd. Whitespace
buttonwhitespace . Enabled = ( t ! = null ) ;
menuwhitespace . Enabled = ( t ! = null ) ;
//mxd. Wordwrap
buttonwordwrap . Enabled = ( t ! = null ) ;
menuwordwrap . Enabled = ( t ! = null ) ;
//mxd. Quick search options
searchmatchcase . Enabled = ( t ! = null ) ;
searchwholeword . Enabled = ( t ! = null ) ;
2009-04-19 18:07:22 +00:00
if ( t ! = null )
{
2016-04-17 22:52:03 +00:00
//mxd. Update quick search controls
searchbox . Enabled = true ;
if ( searchbox . Text . Length > 0 )
{
2016-11-24 11:55:11 +00:00
if ( t . Editor . Scintilla . Text . IndexOf ( searchbox . Text , searchmatchcase . Checked ? StringComparison . Ordinal : StringComparison . OrdinalIgnoreCase ) ! = - 1 )
2016-04-17 22:52:03 +00:00
{
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 ;
}
2009-04-19 18:07:22 +00:00
// 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
2015-11-30 14:18:42 +00:00
if ( t . Config ! = null & & t . Config . Snippets . Count > 0 )
2014-12-03 23:15:26 +00:00
{
2016-01-27 14:08:15 +00:00
if ( t . Config . Snippets . Count > 0 )
2016-11-24 11:55:11 +00:00
{
foreach ( string snippetname in t . Config . Snippets )
{
buttonsnippets . DropDownItems . Add ( snippetname ) . Click + = OnInsertSnippetClick ;
menusnippets . DropDownItems . Add ( snippetname ) . Click + = OnInsertSnippetClick ;
}
}
2014-05-13 09:43:58 +00:00
}
2009-04-19 18:07:22 +00:00
// Focus to script editor
if ( focuseditor ) ForceFocus ( ) ;
}
2016-04-17 22:52:03 +00:00
else
{
//mxd. Disable quick search controls
searchbox . Enabled = false ;
searchprev . Enabled = false ;
searchnext . Enabled = false ;
}
2015-11-30 14:18:42 +00:00
//mxd. Update script type description
scripttype . Text = ( ( t ! = null & & t . Config ! = null ) ? t . Config . Description : "Plain Text" ) ;
}
2009-04-19 18:07:22 +00:00
// This opens the given file, returns null when failed
public ScriptFileDocumentTab OpenFile ( string filename )
{
2016-11-24 11:55:11 +00:00
//mxd. Check if we already have this file opened
foreach ( var tab in tabs . TabPages )
{
if ( ! ( tab is ScriptFileDocumentTab ) ) continue ;
ScriptFileDocumentTab filetab = ( ScriptFileDocumentTab ) tab ;
if ( filetab . Filename = = filename )
{
tabs . SelectedTab = filetab ;
return filetab ;
}
}
2009-04-19 18:07:22 +00:00
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
2016-02-01 22:04:00 +00:00
if ( filename . EndsWith ( "." + ext , StringComparison . OrdinalIgnoreCase ) )
2009-04-19 18:07:22 +00:00
{
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 ( ) ;
2015-11-30 14:18:42 +00:00
if ( st ! = ScriptType . UNKNOWN )
2014-12-03 23:15:26 +00:00
{
2015-11-30 14:18:42 +00:00
foreach ( ScriptConfiguration cfg in scriptconfigs )
2014-12-03 23:15:26 +00:00
{
2015-11-30 14:18:42 +00:00
if ( cfg . ScriptType = = st )
2014-12-03 23:15:26 +00:00
{
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
2015-11-30 14:18:42 +00:00
t . OnTextChanged + = tabpage_OnTextChanged ; //mxd
2016-11-24 11:55:11 +00:00
t . Editor . Scintilla . UpdateUI + = scintilla_OnUpdateUI ;
UpdateInterface ( true ) ;
2009-04-19 18:07:22 +00:00
return t ;
}
2016-01-27 14:08:15 +00:00
// Failed
return null ;
2009-04-19 18:07:22 +00:00
}
2016-11-24 11:55:11 +00:00
//mxd
internal ScriptResourceDocumentTab OpenResource ( ScriptResource resource )
{
// Check if we already have this file opened
foreach ( var tab in tabs . TabPages )
{
if ( ! ( tab is ScriptResourceDocumentTab ) ) continue ;
ScriptResourceDocumentTab restab = ( ScriptResourceDocumentTab ) tab ;
if ( restab . Filename = = resource . FilePathName )
{
tabs . SelectedTab = restab ;
return restab ;
}
}
// Create new document
ScriptConfiguration config = General . GetScriptConfiguration ( resource . ScriptType ) ;
if ( config = = null | | config . ScriptType ! = resource . ScriptType )
{
General . ErrorLogger . Add ( ErrorType . Warning , "Incorrect or missing script configuration for \"" + resource . ScriptType + "\" script type. Using plain text configuration." ) ;
config = new ScriptConfiguration ( ) ;
}
var t = new ScriptResourceDocumentTab ( this , resource , config ) ;
// Mark any errors this script may have
if ( compilererrors ! = null ) t . MarkScriptErrors ( compilererrors ) ;
// Add to tabs
tabs . TabPages . Add ( t ) ;
tabs . SelectedTab = t ;
// Done
t . OnTextChanged + = tabpage_OnTextChanged ;
t . Editor . Scintilla . UpdateUI + = scintilla_OnUpdateUI ;
UpdateInterface ( true ) ;
return t ;
}
2009-04-19 18:07:22 +00:00
// This saves the current open script
public void ExplicitSaveCurrentTab ( )
{
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
2016-01-27 14:08:15 +00:00
if ( ( t ! = null ) )
2009-04-19 18:07:22 +00:00
{
2016-01-27 14:08:15 +00:00
if ( t . ExplicitSave )
buttonsave_Click ( this , EventArgs . Empty ) ;
else if ( t . Config . Compiler ! = null ) //mxd
buttoncompile_Click ( this , EventArgs . Empty ) ;
else
General . MessageBeep ( MessageBeepType . Default ) ;
2009-04-19 18:07:22 +00:00
}
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 ) ;
2016-01-27 14:08:15 +00:00
return ( t ! = null & & t . LaunchKeywordHelp ( ) ) ;
2013-08-08 11:04:13 +00:00
}
2015-11-30 14:18:42 +00:00
//mxd. This changes status text
private void DisplayStatus ( ScriptStatusType type , string message ) { DisplayStatus ( new ScriptStatusInfo ( type , message ) ) ; }
private void DisplayStatus ( ScriptStatusInfo newstatus )
{
// Stop timers
if ( ! newstatus . displayed )
{
statusresetter . Stop ( ) ;
statusflasher . Stop ( ) ;
statusflashicon = false ;
}
// Determine what to do specifically for this status type
switch ( newstatus . type )
{
// Shows information without flashing the icon.
case ScriptStatusType . Ready :
case ScriptStatusType . Info :
if ( ! newstatus . displayed )
{
statusresetter . Interval = MainForm . INFO_RESET_DELAY ;
statusresetter . Start ( ) ;
}
break ;
// Shows a warning, makes a warning sound and flashes a warning icon.
case ScriptStatusType . Warning :
if ( ! newstatus . displayed )
{
General . MessageBeep ( MessageBeepType . Warning ) ;
statusflasher . Interval = MainForm . WARNING_FLASH_INTERVAL ;
statusflashcount = MainForm . WARNING_FLASH_COUNT ;
statusflasher . Start ( ) ;
statusresetter . Interval = MainForm . WARNING_RESET_DELAY ;
statusresetter . Start ( ) ;
}
break ;
}
// Update status description
status = newstatus ;
status . displayed = true ;
statuslabel . Text = status . message ;
// Update icon as well
UpdateStatusIcon ( ) ;
// Refresh
statusbar . Invalidate ( ) ;
this . Update ( ) ;
}
// This updates the status icon
private void UpdateStatusIcon ( )
{
int statusflashindex = ( statusflashicon ? 1 : 0 ) ;
// Status type
switch ( status . type )
{
case ScriptStatusType . Ready :
case ScriptStatusType . Info :
statuslabel . Image = General . MainWindow . STATUS_IMAGES [ statusflashindex , 0 ] ;
break ;
case ScriptStatusType . Busy :
statuslabel . Image = General . MainWindow . STATUS_IMAGES [ statusflashindex , 2 ] ;
break ;
case ScriptStatusType . Warning :
statuslabel . Image = General . MainWindow . STATUS_IMAGES [ statusflashindex , 3 ] ;
break ;
default :
throw new NotImplementedException ( "Unsupported Script Status Type!" ) ;
}
}
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 ;
2015-11-30 14:18:42 +00:00
//mxd. Stop status timers
statusresetter . Stop ( ) ;
statusflasher . Stop ( ) ;
2014-12-10 13:15:23 +00:00
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 ) ;
2015-11-30 14:18:42 +00:00
//mxd. Update script type description
scripttype . Text = scriptconfig . Description ;
2009-04-19 18:07:22 +00:00
// Done
2016-11-24 11:55:11 +00:00
UpdateInterface ( true ) ;
2009-04-19 18:07:22 +00:00
}
// 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
2016-11-24 11:55:11 +00:00
UpdateInterface ( true ) ;
2009-04-19 18:07:22 +00:00
}
// Open script clicked
private void buttonopen_Click ( object sender , EventArgs e )
{
// Show open file dialog
if ( openfile . ShowDialog ( this . ParentForm ) = = DialogResult . OK )
{
2015-11-30 14:18:42 +00:00
//mxd. Gather already opened file names
List < string > openedfiles = new List < string > ( ) ;
foreach ( var page in tabs . TabPages )
{
var scriptpage = page as ScriptFileDocumentTab ;
if ( scriptpage ! = null ) openedfiles . Add ( scriptpage . Filename ) ;
}
//mxd. Add new tabs
foreach ( string name in openfile . FileNames )
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
if ( ! openedfiles . Contains ( name ) )
{
ScriptFileDocumentTab t = OpenFile ( name ) ;
// Apply document settings
2016-11-24 11:55:11 +00:00
if ( General . Map . Options . ScriptDocumentSettings . ContainsKey ( t . Filename ) )
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
{
2016-11-24 11:55:11 +00:00
t . SetViewSettings ( General . Map . Options . ScriptDocumentSettings [ t . Filename ] ) ;
}
else
{
// Apply default settings
t . SetDefaultViewSettings ( ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
}
}
2015-11-30 14:18:42 +00:00
}
// Select the last new item
foreach ( var page in tabs . TabPages )
{
var scriptpage = page as ScriptFileDocumentTab ;
if ( scriptpage ! = null & & scriptpage . Filename = = openfile . FileNames [ openfile . FileNames . Length - 1 ] )
{
tabs . SelectedTab = scriptpage ;
break ;
}
}
2009-04-19 18:07:22 +00:00
}
}
// Save script clicked
private void buttonsave_Click ( object sender , EventArgs e )
{
// Save the current script
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
SaveScript ( t ) ;
2016-11-24 11:55:11 +00:00
UpdateInterface ( true ) ;
2009-04-19 18:07:22 +00:00
}
// 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 ;
}
}
2016-11-24 11:55:11 +00:00
UpdateInterface ( true ) ;
2009-04-19 18:07:22 +00:00
}
// 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 ) ;
2016-11-24 11:55:11 +00:00
//mxd. Also compile if needed
if ( t . Config . Compiler ! = null ) t . Compile ( ) ;
2009-04-19 18:07:22 +00:00
return true ;
}
2016-01-27 14:08:15 +00:00
// Cancelled
return false ;
2009-04-19 18:07:22 +00:00
}
2016-01-27 14:08:15 +00:00
// Save to same filename
t . Save ( ) ;
2016-11-24 11:55:11 +00:00
2016-01-27 14:08:15 +00:00
return true ;
2009-04-19 18:07:22 +00:00
}
// A tab is selected
private void tabs_Selecting ( object sender , TabControlCancelEventArgs e )
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
//mxd. Update script navigator
ScriptDocumentTab tab = e . TabPage as ScriptDocumentTab ;
2016-03-07 20:01:13 +00:00
if ( tab ! = null )
{
// Show all errors...
2016-05-12 13:56:25 +00:00
ShowErrors ( tab . UpdateNavigator ( ) , true ) ;
2016-03-07 20:01:13 +00:00
}
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
2016-11-24 11:55:11 +00:00
UpdateInterface ( true ) ;
2009-04-19 18:07:22 +00:00
}
// 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 ;
}
}
2015-11-30 14:18:42 +00:00
else if ( t . ExplicitSave & & t . IsChanged )
2009-04-19 18:07:22 +00:00
{
2015-11-30 14:18:42 +00:00
// We can only compile when the script is saved
if ( ! SaveScript ( t ) ) return ;
2009-04-19 18:07:22 +00:00
}
// Compile now
2016-01-27 14:08:15 +00:00
DisplayStatus ( ScriptStatusType . Busy , "Compiling script \"" + t . Title + "\"..." ) ;
2009-04-19 18:07:22 +00:00
Cursor . Current = Cursors . WaitCursor ;
t . Compile ( ) ;
// Show warning
if ( ( compilererrors ! = null ) & & ( compilererrors . Count > 0 ) )
2016-01-27 14:08:15 +00:00
DisplayStatus ( ScriptStatusType . Warning , compilererrors . Count + " errors while compiling \"" + t . Title + "\"!" ) ;
2009-04-19 18:07:22 +00:00
else
2016-01-27 14:08:15 +00:00
DisplayStatus ( ScriptStatusType . Info , "Script \"" + t . Title + "\" compiled without errors." ) ;
2009-04-19 18:07:22 +00:00
Cursor . Current = Cursors . Default ;
2016-11-24 11:55:11 +00:00
UpdateInterface ( true ) ;
2009-04-19 18:07:22 +00:00
}
// Undo clicked
private void buttonundo_Click ( object sender , EventArgs e )
{
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
t . Undo ( ) ;
2016-11-24 11:55:11 +00:00
UpdateInterface ( true ) ;
2009-04-19 18:07:22 +00:00
}
// Redo clicked
private void buttonredo_Click ( object sender , EventArgs e )
{
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
t . Redo ( ) ;
2016-11-24 11:55:11 +00:00
UpdateInterface ( true ) ;
2009-04-19 18:07:22 +00:00
}
// Cut clicked
private void buttoncut_Click ( object sender , EventArgs e )
{
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
t . Cut ( ) ;
2016-11-24 11:55:11 +00:00
UpdateInterface ( true ) ;
2009-04-19 18:07:22 +00:00
}
// Copy clicked
private void buttoncopy_Click ( object sender , EventArgs e )
{
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
t . Copy ( ) ;
2016-11-24 11:55:11 +00:00
UpdateInterface ( true ) ;
2009-04-19 18:07:22 +00:00
}
// Paste clicked
private void buttonpaste_Click ( object sender , EventArgs e )
{
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
t . Paste ( ) ;
2016-11-24 11:55:11 +00:00
UpdateInterface ( true ) ;
2009-04-19 18:07:22 +00:00
}
2014-03-03 11:45:03 +00:00
2016-01-27 14:08:15 +00:00
//mxd
private void buttonunindent_Click ( object sender , EventArgs e )
{
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
t . IndentSelection ( false ) ;
}
//mxd
private void buttonindent_Click ( object sender , EventArgs e )
{
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
t . IndentSelection ( true ) ;
}
//mxd
private void buttonwhitespace_Click ( object sender , EventArgs e )
{
2016-11-24 11:55:11 +00:00
if ( blockupdate ) return ;
blockupdate = true ;
showwhitespace = ! showwhitespace ;
buttonwhitespace . Checked = showwhitespace ;
menuwhitespace . Checked = showwhitespace ;
blockupdate = false ;
2016-01-27 14:08:15 +00:00
ApplyTabSettings ( ) ;
}
//mxd
private void buttonwordwrap_Click ( object sender , EventArgs e )
{
2016-11-24 11:55:11 +00:00
if ( blockupdate ) return ;
blockupdate = true ;
wraplonglines = ! wraplonglines ;
buttonwordwrap . Checked = wraplonglines ;
menuwordwrap . Checked = wraplonglines ;
blockupdate = false ;
2016-01-27 14:08:15 +00:00
ApplyTabSettings ( ) ;
}
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
2016-11-24 11:55:11 +00:00
//mxd
private void menugotoline_Click ( object sender , EventArgs e )
{
GoToLine ( ) ;
}
//mxd
private void menuduplicateline_Click ( object sender , EventArgs e )
{
if ( ActiveTab ! = null ) ActiveTab . Editor . DuplicateLine ( ) ;
}
//mxd
private void menustayontop_Click ( object sender , EventArgs e )
{
General . Settings . ScriptOnTop = menustayontop . Checked ;
parentform . TopMost = General . Settings . ScriptOnTop ;
}
2014-05-13 09:43:58 +00:00
//mxd
private void OnInsertSnippetClick ( object sender , EventArgs eventArgs )
{
ScriptDocumentTab t = ( tabs . SelectedTab as ScriptDocumentTab ) ;
2016-01-27 14:08:15 +00:00
t . InsertSnippet ( ( ( ToolStripItem ) sender ) . Text ) ;
2014-05-13 09:43:58 +00:00
}
2009-04-19 18:07:22 +00:00
// Mouse released on tabs
private void tabs_MouseUp ( object sender , MouseEventArgs e )
{
ForceFocus ( ) ;
}
2015-11-30 14:18:42 +00:00
2016-11-24 11:55:11 +00:00
//mxd
private void tabs_OnCloseTabClicked ( object sender , TabControlEventArgs e )
{
ScriptDocumentTab t = ( e . TabPage as ScriptDocumentTab ) ;
//TODO: allow any tab to be closed.
if ( ! t . IsClosable ) return ;
CloseScript ( t , false ) ;
UpdateInterface ( true ) ;
}
2016-01-27 14:08:15 +00:00
//mxd. Text in ScriptFileDocumentTab was changed
2015-11-30 14:18:42 +00:00
private void tabpage_OnTextChanged ( object sender , EventArgs eventArgs )
{
if ( tabs . SelectedTab ! = null )
{
ScriptDocumentTab curtab = tabs . SelectedTab as ScriptDocumentTab ;
2016-01-27 14:08:15 +00:00
if ( curtab ! = null )
{
buttonsave . Enabled = ( curtab . ExplicitSave & & curtab . IsChanged ) ;
2016-11-24 11:55:11 +00:00
buttonundo . Enabled = curtab . Editor . Scintilla . CanUndo ;
buttonredo . Enabled = curtab . Editor . Scintilla . CanRedo ;
2016-01-27 14:08:15 +00:00
}
}
}
//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 )
{
2016-11-24 11:55:11 +00:00
buttonundo . Enabled = curtab . Editor . Scintilla . CanUndo ;
buttonredo . Enabled = curtab . Editor . Scintilla . CanRedo ;
2016-01-27 14:08:15 +00:00
}
}
}
//mxd
private void scintilla_OnUpdateUI ( object sender , UpdateUIEventArgs e )
{
Scintilla s = sender as Scintilla ;
if ( s ! = null )
{
// Update caret position info [line] : [caret pos start] OR [caret pos start x selection length] ([total lines])
positionlabel . Text = ( s . CurrentLine + 1 ) + " : "
+ ( s . SelectionStart + 1 - s . Lines [ s . LineFromPosition ( s . SelectionStart ) ] . Position )
+ ( s . SelectionStart ! = s . SelectionEnd ? "x" + ( s . SelectionEnd - s . SelectionStart ) : "" )
+ " (" + s . Lines . Count + ")" ;
// Update copy-paste buttons
buttoncut . Enabled = ( s . SelectionEnd > s . SelectionStart ) ;
buttoncopy . Enabled = ( s . SelectionEnd > s . SelectionStart ) ;
buttonpaste . Enabled = s . CanPaste ;
buttonunindent . Enabled = s . Lines [ s . CurrentLine ] . Indentation > 0 ;
2015-11-30 14:18:42 +00:00
}
}
2009-04-19 18:07:22 +00:00
// 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 ) ) ;
2016-04-17 22:52:03 +00:00
searchbox . BackColor = ( ( success | | searchbox . Text . Length = = 0 ) ? SystemColors . Window : QUICKSEARCH_FAIL_COLOR ) ;
2014-12-10 13:15:23 +00:00
searchnext . Enabled = success ;
searchprev . Enabled = success ;
}
private void searchnext_Click ( object sender , EventArgs e )
{
2016-11-24 11:55:11 +00:00
FindNext ( ) ;
2014-12-10 13:15:23 +00:00
}
private void searchprev_Click ( object sender , EventArgs e )
{
2016-11-24 11:55:11 +00:00
FindPrevious ( ) ;
2014-12-10 13:15:23 +00:00
}
2016-11-24 11:55:11 +00:00
// This flashes the status icon
2015-11-30 14:18:42 +00:00
private void statusflasher_Tick ( object sender , EventArgs e )
{
statusflashicon = ! statusflashicon ;
UpdateStatusIcon ( ) ;
statusflashcount - - ;
if ( statusflashcount = = 0 ) statusflasher . Stop ( ) ;
}
2016-11-24 11:55:11 +00:00
// This resets the status to ready
2015-11-30 14:18:42 +00:00
private void statusresetter_Tick ( object sender , EventArgs e )
{
DisplayStatus ( ScriptStatusType . Ready , null ) ;
}
2014-12-10 13:15:23 +00:00
#endregion
2016-11-24 11:55:11 +00:00
#region = = = = = = = = = = = = = = = = = = Menu opening events ( mxd )
private void filemenuitem_DropDownOpening ( object sender , EventArgs e )
{
ScriptDocumentTab t = ActiveTab ;
menusave . Enabled = ( t ! = null & & ! t . IsReadOnly & & t . ExplicitSave & & t . IsChanged ) ;
// Any explicit save scripts?
int explicitsavescripts = 0 ;
foreach ( ScriptDocumentTab dt in tabs . TabPages )
if ( dt . ExplicitSave & & ! dt . IsReadOnly ) explicitsavescripts + + ;
menusaveall . Enabled = ( explicitsavescripts > 0 ) ;
}
private void editmenuitem_DropDownOpening ( object sender , EventArgs e )
{
ScriptDocumentTab t = ActiveTab ;
if ( t ! = null )
{
Scintilla s = t . Editor . Scintilla ;
menuundo . Enabled = s . CanUndo ;
menuredo . Enabled = s . CanRedo ;
menucut . Enabled = ( s . SelectionEnd > s . SelectionStart ) ;
menucopy . Enabled = ( s . SelectionEnd > s . SelectionStart ) ;
menupaste . Enabled = s . CanPaste ;
menuindent . Enabled = true ;
menuunindent . Enabled = s . Lines [ s . CurrentLine ] . Indentation > 0 ;
menugotoline . Enabled = true ;
menuduplicateline . Enabled = true ;
}
else
{
menuundo . Enabled = false ;
menuredo . Enabled = false ;
menucut . Enabled = false ;
menucopy . Enabled = false ;
menupaste . Enabled = false ;
menusnippets . Enabled = false ;
menuindent . Enabled = false ;
menuunindent . Enabled = false ;
menugotoline . Enabled = false ;
menuduplicateline . Enabled = false ;
}
}
private void searchmenuitem_DropDownOpening ( object sender , EventArgs e )
{
ScriptDocumentTab t = ActiveTab ;
menufind . Enabled = ( t ! = null ) ;
bool enable = ( ! string . IsNullOrEmpty ( findoptions . FindText ) & & t ! = null ) ;
menufindnext . Enabled = enable ;
menufindprevious . Enabled = enable ;
}
private void toolsmenu_DropDownOpening ( object sender , EventArgs e )
{
ScriptDocumentTab t = ActiveTab ;
menucompile . Enabled = ( ActiveTab ! = null & & ! t . IsReadOnly & & t . Config . Compiler ! = null ) ;
}
#endregion
2009-04-19 18:07:22 +00:00
}
}