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;
|
2012-07-12 22:34:12 +00:00
|
|
|
using System.IO;
|
2009-04-19 18:07:22 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Text;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using CodeImp.DoomBuilder.Windows;
|
|
|
|
using CodeImp.DoomBuilder.Config;
|
|
|
|
using CodeImp.DoomBuilder.Compilers;
|
2012-07-12 22:34:12 +00:00
|
|
|
using CodeImp.DoomBuilder.GZBuilder.Data;
|
|
|
|
using CodeImp.DoomBuilder.GZBuilder.GZDoom;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Controls
|
|
|
|
{
|
|
|
|
internal abstract class ScriptDocumentTab : TabPage
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
2012-07-10 10:20:45 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
private const int NAVIGATOR_BORDER_TOP = 8; //mxd
|
2012-07-10 10:20:45 +00:00
|
|
|
private const int EDITOR_BORDER_TOP = 33;
|
2009-04-19 18:07:22 +00:00
|
|
|
private const int EDITOR_BORDER_BOTTOM = 4;
|
|
|
|
private const int EDITOR_BORDER_LEFT = 4;
|
|
|
|
private const int EDITOR_BORDER_RIGHT = 4;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// The script edit control
|
2014-05-13 14:41:51 +00:00
|
|
|
protected readonly ScriptEditorControl editor;
|
2014-12-03 23:15:26 +00:00
|
|
|
protected readonly ComboBox navigator; //mxd
|
2015-11-30 14:18:42 +00:00
|
|
|
private bool preventchanges; //mxd
|
|
|
|
private string title; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Derived classes must set this!
|
|
|
|
protected ScriptConfiguration config;
|
|
|
|
|
|
|
|
// The panel we're on
|
2014-05-13 14:41:51 +00:00
|
|
|
protected readonly ScriptEditorPanel panel;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public virtual bool ExplicitSave { get { return true; } }
|
|
|
|
public virtual bool IsSaveAsRequired { get { return true; } }
|
|
|
|
public virtual bool IsClosable { get { return true; } }
|
|
|
|
public virtual bool IsReconfigurable { get { return true; } }
|
|
|
|
public virtual string Filename { get { return null; } }
|
|
|
|
public ScriptEditorPanel Panel { get { return panel; } }
|
2015-11-30 14:18:42 +00:00
|
|
|
public new string Text { get { return title; } } //mxd
|
|
|
|
public bool IsChanged { get { return editor.IsChanged; } internal set { editor.IsChanged = value; } } //mxd. Added setter
|
2010-08-02 06:11:35 +00:00
|
|
|
public int SelectionStart { get { return editor.SelectionStart; } set { editor.SelectionStart = value; } }
|
|
|
|
public int SelectionEnd { get { return editor.SelectionEnd; } set { editor.SelectionEnd = value; } }
|
2009-04-19 18:07:22 +00:00
|
|
|
public ScriptConfiguration Config { get { return config; } }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2015-11-30 14:18:42 +00:00
|
|
|
#region ================== Events (mxd)
|
|
|
|
|
|
|
|
public new event EventHandler OnTextChanged; //mxd
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#region ================== Constructor
|
|
|
|
|
|
|
|
// Constructor
|
2015-05-27 12:38:03 +00:00
|
|
|
protected ScriptDocumentTab(ScriptEditorPanel panel)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Keep panel
|
|
|
|
this.panel = panel;
|
2012-07-10 10:20:45 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
|
|
|
navigator = new ComboBox();
|
|
|
|
navigator.Location = new Point(EDITOR_BORDER_LEFT, NAVIGATOR_BORDER_TOP);
|
|
|
|
navigator.Width = this.ClientSize.Width - EDITOR_BORDER_LEFT - EDITOR_BORDER_RIGHT;
|
|
|
|
navigator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
|
|
|
navigator.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
|
|
navigator.Name = "navigator";
|
|
|
|
navigator.TabStop = true;
|
|
|
|
navigator.TabIndex = 0;
|
2014-02-21 14:42:12 +00:00
|
|
|
navigator.DropDown += navigator_DropDown;
|
2014-03-03 11:45:03 +00:00
|
|
|
navigator.SelectedIndexChanged += navigator_SelectedIndexChanged;
|
2013-09-11 09:47:53 +00:00
|
|
|
this.Controls.Add(navigator);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Make the script control
|
|
|
|
editor = new ScriptEditorControl();
|
|
|
|
editor.Location = new Point(EDITOR_BORDER_LEFT, EDITOR_BORDER_TOP);
|
|
|
|
editor.Size = new Size(this.ClientSize.Width - EDITOR_BORDER_LEFT - EDITOR_BORDER_RIGHT,
|
|
|
|
this.ClientSize.Height - EDITOR_BORDER_TOP - EDITOR_BORDER_BOTTOM);
|
|
|
|
editor.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
|
|
|
editor.Name = "editor";
|
|
|
|
editor.TabStop = true;
|
2012-07-10 10:20:45 +00:00
|
|
|
editor.TabIndex = 1;
|
2009-04-19 18:07:22 +00:00
|
|
|
this.Controls.Add(editor);
|
|
|
|
|
|
|
|
// Bind events
|
|
|
|
editor.OnExplicitSaveTab += panel.ExplicitSaveCurrentTab;
|
|
|
|
editor.OnOpenScriptBrowser += panel.OpenBrowseScript;
|
|
|
|
editor.OnOpenFindAndReplace += panel.OpenFindAndReplace;
|
|
|
|
editor.OnFindNext += panel.FindNext;
|
2014-12-10 13:15:23 +00:00
|
|
|
editor.OnFindPrevious += panel.FindPrevious; //mxd
|
2015-11-30 14:18:42 +00:00
|
|
|
editor.OnTextChanged += editor_TextChanged; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disposer
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
{
|
|
|
|
// Remove events
|
|
|
|
editor.OnExplicitSaveTab -= panel.ExplicitSaveCurrentTab;
|
|
|
|
editor.OnOpenScriptBrowser -= panel.OpenBrowseScript;
|
|
|
|
editor.OnOpenFindAndReplace -= panel.OpenFindAndReplace;
|
|
|
|
editor.OnFindNext -= panel.FindNext;
|
2014-12-10 13:15:23 +00:00
|
|
|
editor.OnFindPrevious -= panel.FindPrevious; //mxd
|
2015-11-30 14:18:42 +00:00
|
|
|
editor.OnTextChanged -= editor_TextChanged; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
2009-05-10 17:02:47 +00:00
|
|
|
// This launches keyword help website
|
2013-08-08 11:04:13 +00:00
|
|
|
public bool LaunchKeywordHelp()
|
2009-05-10 17:02:47 +00:00
|
|
|
{
|
2013-08-08 11:04:13 +00:00
|
|
|
return editor.LaunchKeywordHelp();
|
2009-05-10 17:02:47 +00:00
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// This refreshes the style settings
|
|
|
|
public virtual void RefreshSettings()
|
|
|
|
{
|
|
|
|
editor.RefreshStyle();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This moves the caret to the given line
|
|
|
|
public virtual void MoveToLine(int linenumber)
|
|
|
|
{
|
|
|
|
editor.MoveToLine(linenumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This clears all marks
|
|
|
|
public virtual void ClearMarks()
|
|
|
|
{
|
|
|
|
editor.ClearMarks();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This creates error marks for errors that apply to this file
|
|
|
|
public virtual void MarkScriptErrors(IEnumerable<CompilerError> errors)
|
|
|
|
{
|
|
|
|
// Clear all marks
|
|
|
|
ClearMarks();
|
|
|
|
|
|
|
|
// Go for all errors that apply to this script
|
|
|
|
foreach(CompilerError e in errors)
|
|
|
|
{
|
|
|
|
if(VerifyErrorForScript(e))
|
|
|
|
{
|
|
|
|
// Add a mark on the line where this error occurred
|
|
|
|
editor.AddMark(e.linenumber);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This verifies if the specified error applies to this script
|
|
|
|
public virtual bool VerifyErrorForScript(CompilerError e)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This compiles the script
|
2012-07-23 21:28:23 +00:00
|
|
|
public virtual void Compile() { }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// This saves the document (used for both explicit and implicit)
|
|
|
|
// Return true when successfully saved
|
|
|
|
public virtual bool Save()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This saves the document to a new file
|
|
|
|
// Return true when successfully saved
|
|
|
|
public virtual bool SaveAs(string filename)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This changes the script configurations
|
|
|
|
public virtual void ChangeScriptConfig(ScriptConfiguration newconfig)
|
|
|
|
{
|
2014-12-03 23:15:26 +00:00
|
|
|
UpdateNavigator(); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call this to set the tab title
|
|
|
|
protected void SetTitle(string title)
|
|
|
|
{
|
2015-11-30 14:18:42 +00:00
|
|
|
this.title = title; //mxd
|
|
|
|
base.Text = (editor.IsChanged ? "\u25CF " + title : title); //mxd
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd
|
|
|
|
protected void UpdateTitle()
|
|
|
|
{
|
|
|
|
SetTitle(title);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Perform undo
|
|
|
|
public void Undo()
|
|
|
|
{
|
|
|
|
editor.Undo();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform redo
|
|
|
|
public void Redo()
|
|
|
|
{
|
|
|
|
editor.Redo();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform cut
|
|
|
|
public void Cut()
|
|
|
|
{
|
|
|
|
editor.Cut();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform copy
|
|
|
|
public void Copy()
|
|
|
|
{
|
|
|
|
editor.Copy();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform paste
|
|
|
|
public void Paste()
|
|
|
|
{
|
|
|
|
editor.Paste();
|
|
|
|
}
|
2014-12-10 13:15:23 +00:00
|
|
|
|
|
|
|
// Find next result (mxd)
|
|
|
|
public bool FindNext(FindReplaceOptions options)
|
|
|
|
{
|
|
|
|
return FindNext(options, false);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Find next result
|
2014-12-10 13:15:23 +00:00
|
|
|
public bool FindNext(FindReplaceOptions options, bool useselectionstart)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
byte[] data = editor.GetText();
|
|
|
|
string text = Encoding.GetEncoding(config.CodePage).GetString(data);
|
|
|
|
StringComparison mode = options.CaseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;
|
2014-12-10 13:15:23 +00:00
|
|
|
int startpos = (useselectionstart ? Math.Min(editor.SelectionStart, editor.SelectionEnd) : Math.Max(editor.SelectionStart, editor.SelectionEnd)); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
bool wrapped = false;
|
|
|
|
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
int result = text.IndexOf(options.FindText, startpos, mode);
|
|
|
|
if(result > -1)
|
|
|
|
{
|
|
|
|
// Check to see if it is the whole word
|
|
|
|
if(options.WholeWord)
|
|
|
|
{
|
|
|
|
// Veryfy that we have found a whole word
|
|
|
|
string foundword = editor.GetWordAt(result + 1);
|
|
|
|
if(foundword.Length != options.FindText.Length)
|
|
|
|
{
|
|
|
|
startpos = result + 1;
|
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Still ok?
|
|
|
|
if(result > -1)
|
|
|
|
{
|
|
|
|
// Select the result
|
|
|
|
editor.SelectionStart = result;
|
|
|
|
editor.SelectionEnd = result + options.FindText.Length;
|
|
|
|
editor.EnsureLineVisible(editor.LineFromPosition(editor.SelectionEnd));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If we haven't tried from the start, try from the start now
|
|
|
|
if((startpos > 0) && !wrapped)
|
|
|
|
{
|
|
|
|
startpos = 0;
|
|
|
|
wrapped = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Can't find it
|
|
|
|
return false;
|
2014-12-10 13:15:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find previous result (mxd)
|
|
|
|
public bool FindPrevious(FindReplaceOptions options)
|
|
|
|
{
|
2014-12-10 14:22:54 +00:00
|
|
|
bool wrapped = false;
|
2014-12-10 13:15:23 +00:00
|
|
|
byte[] data = editor.GetText();
|
|
|
|
string text = Encoding.GetEncoding(config.CodePage).GetString(data);
|
|
|
|
StringComparison mode = options.CaseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;
|
2014-12-10 14:22:54 +00:00
|
|
|
int endpos = Math.Min(editor.SelectionStart, editor.SelectionEnd) - 1;
|
|
|
|
if(endpos < 0)
|
|
|
|
{
|
|
|
|
endpos = text.Length - 1;
|
|
|
|
wrapped = true;
|
|
|
|
}
|
2014-12-10 13:15:23 +00:00
|
|
|
|
|
|
|
while(true)
|
|
|
|
{
|
2014-12-10 14:22:54 +00:00
|
|
|
int result = text.LastIndexOf(options.FindText, endpos, mode);
|
2014-12-10 13:15:23 +00:00
|
|
|
if(result > -1)
|
|
|
|
{
|
|
|
|
// Check to see if it is the whole word
|
|
|
|
if(options.WholeWord)
|
|
|
|
{
|
|
|
|
// Veryfy that we have found a whole word
|
|
|
|
string foundword = editor.GetWordAt(result + 1);
|
|
|
|
if(foundword.Length != options.FindText.Length)
|
|
|
|
{
|
|
|
|
endpos = result - 1;
|
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Still ok?
|
|
|
|
if(result > -1)
|
|
|
|
{
|
|
|
|
// Select the result
|
|
|
|
editor.SelectionStart = result;
|
|
|
|
editor.SelectionEnd = result + options.FindText.Length;
|
|
|
|
editor.EnsureLineVisible(editor.LineFromPosition(editor.SelectionEnd));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If we haven't tried from the end, try from the end now
|
|
|
|
if(!wrapped)
|
|
|
|
{
|
2014-12-10 14:22:54 +00:00
|
|
|
endpos = Math.Max(0, text.Length - 2);
|
2014-12-10 13:15:23 +00:00
|
|
|
wrapped = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Can't find it
|
|
|
|
return false;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This replaces the selection with the given text
|
|
|
|
public void ReplaceSelection(string replacement)
|
|
|
|
{
|
|
|
|
editor.ReplaceSelection(replacement);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This returns the selected text
|
|
|
|
public string GetSelectedText()
|
|
|
|
{
|
|
|
|
byte[] data = editor.GetText();
|
|
|
|
string text = Encoding.GetEncoding(config.CodePage).GetString(data);
|
|
|
|
if(editor.SelectionStart < editor.SelectionEnd)
|
|
|
|
return text.Substring(editor.SelectionStart, editor.SelectionEnd - editor.SelectionStart);
|
2014-03-03 11:45:03 +00:00
|
|
|
return "";
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
2014-12-03 23:15:26 +00:00
|
|
|
protected void UpdateNavigator()
|
2014-05-13 09:43:58 +00:00
|
|
|
{
|
2015-01-22 19:03:21 +00:00
|
|
|
switch(config.ScriptType)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2015-01-22 19:03:21 +00:00
|
|
|
case ScriptType.ACS:
|
|
|
|
UpdateNavigatorAcs(new MemoryStream(editor.GetText()));
|
|
|
|
break;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
2015-01-22 19:03:21 +00:00
|
|
|
case ScriptType.DECORATE:
|
|
|
|
UpdateNavigatorDecorate(new MemoryStream(editor.GetText()));
|
|
|
|
break;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
2015-01-22 19:03:21 +00:00
|
|
|
case ScriptType.MODELDEF:
|
|
|
|
UpdateNavigatorModeldef(new MemoryStream(editor.GetText()));
|
|
|
|
break;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
2015-01-22 19:03:21 +00:00
|
|
|
default: // Unsupported script type. Just clear the items
|
|
|
|
navigator.Items.Clear();
|
|
|
|
break;
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
2015-11-30 14:18:42 +00:00
|
|
|
|
|
|
|
// Put some text in the navigator (but don't actually trigger selection event)
|
2015-12-17 10:07:28 +00:00
|
|
|
navigator.Enabled = (navigator.Items.Count > 0);
|
2015-11-30 14:18:42 +00:00
|
|
|
if(navigator.Items.Count > 0)
|
|
|
|
{
|
|
|
|
preventchanges = true;
|
|
|
|
navigator.Text = navigator.Items[0].ToString();
|
|
|
|
preventchanges = false;
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
2014-12-03 23:15:26 +00:00
|
|
|
private void UpdateNavigatorDecorate(MemoryStream stream)
|
2014-05-13 09:43:58 +00:00
|
|
|
{
|
2015-12-17 10:07:28 +00:00
|
|
|
if(stream == null) return;
|
2013-09-11 09:47:53 +00:00
|
|
|
navigator.Items.Clear();
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
DecorateParserSE parser = new DecorateParserSE();
|
2015-12-18 10:16:53 +00:00
|
|
|
if(parser.Parse(stream, "DECORATE", false))
|
2015-12-17 10:07:28 +00:00
|
|
|
{
|
|
|
|
navigator.Items.AddRange(parser.Actors.ToArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
if(parser.HasError)
|
|
|
|
{
|
|
|
|
panel.ShowErrors(new List<CompilerError> { new CompilerError(parser.ErrorDescription, parser.ErrorSource, parser.ErrorLine) });
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
2014-12-03 23:15:26 +00:00
|
|
|
private void UpdateNavigatorModeldef(MemoryStream stream)
|
2014-05-13 09:43:58 +00:00
|
|
|
{
|
2015-12-17 10:07:28 +00:00
|
|
|
if(stream == null) return;
|
2013-09-11 09:47:53 +00:00
|
|
|
navigator.Items.Clear();
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
ModeldefParserSE parser = new ModeldefParserSE();
|
2015-12-18 10:16:53 +00:00
|
|
|
if(parser.Parse(stream, "MODELDEF", false))
|
2015-12-17 10:07:28 +00:00
|
|
|
{
|
|
|
|
navigator.Items.AddRange(parser.Models.ToArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
if(parser.HasError)
|
|
|
|
{
|
|
|
|
panel.ShowErrors(new List<CompilerError> { new CompilerError(parser.ErrorDescription, parser.ErrorSource, parser.ErrorLine) });
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
2014-12-03 23:15:26 +00:00
|
|
|
private void UpdateNavigatorAcs(MemoryStream stream)
|
2014-05-13 09:43:58 +00:00
|
|
|
{
|
2015-12-17 10:07:28 +00:00
|
|
|
if(stream == null) return;
|
2013-09-11 09:47:53 +00:00
|
|
|
navigator.Items.Clear();
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2015-11-30 14:18:42 +00:00
|
|
|
AcsParserSE parser = new AcsParserSE { AddArgumentsToScriptNames = true, IsMapScriptsLump = this is ScriptLumpDocumentTab };
|
2015-12-18 10:16:53 +00:00
|
|
|
if(parser.Parse(stream, "SCRIPTS", false))
|
2015-11-13 21:42:41 +00:00
|
|
|
{
|
|
|
|
navigator.Items.AddRange(parser.NamedScripts.ToArray());
|
|
|
|
navigator.Items.AddRange(parser.NumberedScripts.ToArray());
|
|
|
|
navigator.Items.AddRange(parser.Functions.ToArray());
|
|
|
|
}
|
2015-12-17 10:07:28 +00:00
|
|
|
|
|
|
|
if(parser.HasError)
|
|
|
|
{
|
|
|
|
panel.ShowErrors(new List<CompilerError> { new CompilerError(parser.ErrorDescription, parser.ErrorSource, parser.ErrorLine) });
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
2014-05-13 09:43:58 +00:00
|
|
|
internal ScriptType VerifyScriptType()
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
ScriptTypeParserSE parser = new ScriptTypeParserSE();
|
2015-12-18 10:16:53 +00:00
|
|
|
if(parser.Parse(new MemoryStream(editor.GetText()), config.Description, false))
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2015-12-17 10:07:28 +00:00
|
|
|
if(parser.ScriptType != ScriptType.UNKNOWN && config.ScriptType != parser.ScriptType)
|
2013-09-11 09:47:53 +00:00
|
|
|
return parser.ScriptType;
|
|
|
|
}
|
2015-12-17 10:07:28 +00:00
|
|
|
|
|
|
|
if(parser.HasError)
|
|
|
|
{
|
|
|
|
panel.ShowErrors(new List<CompilerError> { new CompilerError(parser.ErrorDescription, parser.ErrorSource, parser.ErrorLine) });
|
|
|
|
}
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
return ScriptType.UNKNOWN;
|
|
|
|
}
|
2012-07-16 09:45:21 +00:00
|
|
|
|
2014-05-13 09:43:58 +00:00
|
|
|
//mxd
|
|
|
|
internal void InsertSnippet(string[] lines)
|
|
|
|
{
|
|
|
|
editor.InsertSnippet(lines);
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Events
|
|
|
|
|
|
|
|
// Mouse released
|
|
|
|
protected override void OnMouseUp(MouseEventArgs e)
|
|
|
|
{
|
|
|
|
base.OnMouseUp(e);
|
|
|
|
|
|
|
|
// Focus to the editor!
|
|
|
|
editor.Focus();
|
|
|
|
editor.GrabFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Receiving focus?
|
|
|
|
protected override void OnGotFocus(EventArgs e)
|
|
|
|
{
|
|
|
|
base.OnGotFocus(e);
|
|
|
|
|
|
|
|
// Focus to the editor!
|
|
|
|
editor.Focus();
|
|
|
|
editor.GrabFocus();
|
|
|
|
}
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
2014-12-03 23:15:26 +00:00
|
|
|
private void navigator_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
{
|
2015-11-30 14:18:42 +00:00
|
|
|
if(!preventchanges && navigator.SelectedItem is ScriptItem)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
ScriptItem si = navigator.SelectedItem as ScriptItem;
|
2015-01-22 19:03:21 +00:00
|
|
|
editor.EnsureLineVisible(editor.LineFromPosition(si.CursorPosition));
|
|
|
|
editor.SelectionStart = si.CursorPosition;
|
|
|
|
editor.SelectionEnd = si.CursorPosition;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
|
|
|
// Focus to the editor!
|
|
|
|
editor.Focus();
|
|
|
|
editor.GrabFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd
|
2014-12-03 23:15:26 +00:00
|
|
|
private void navigator_DropDown(object sender, EventArgs e)
|
|
|
|
{
|
2015-11-30 14:18:42 +00:00
|
|
|
if(!preventchanges && editor.IsChanged) UpdateNavigator();
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd
|
|
|
|
private void editor_TextChanged(object sender, EventArgs eventArgs)
|
|
|
|
{
|
|
|
|
UpdateTitle();
|
|
|
|
if(OnTextChanged != null) OnTextChanged(this, EventArgs.Empty);
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|