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
|
|
|
//mxd
|
|
|
|
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;
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
2014-05-13 14:41:51 +00:00
|
|
|
protected readonly ComboBox navigator;
|
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; } }
|
|
|
|
public bool IsChanged { get { return editor.IsChanged; } }
|
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
|
|
|
|
|
|
|
|
#region ================== Constructor
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public ScriptDocumentTab(ScriptEditorPanel panel)
|
|
|
|
{
|
|
|
|
// 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-03-03 11:45:03 +00:00
|
|
|
navigator.Enabled = false;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
updateNavigator(); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call this to set the tab title
|
|
|
|
protected void SetTitle(string title)
|
|
|
|
{
|
|
|
|
this.Text = title;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find next result
|
|
|
|
public bool FindNext(FindReplaceOptions options)
|
|
|
|
{
|
|
|
|
byte[] data = editor.GetText();
|
|
|
|
string text = Encoding.GetEncoding(config.CodePage).GetString(data);
|
|
|
|
StringComparison mode = options.CaseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;
|
|
|
|
int startpos = Math.Max(editor.SelectionStart, editor.SelectionEnd);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-05-13 09:43:58 +00:00
|
|
|
protected void updateNavigator()
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd. known script type?
|
|
|
|
if (Array.IndexOf(ScriptTypes.TYPES, config.Description) != -1) {
|
|
|
|
updateNavigator(new MemoryStream(editor.GetText()), config.Description);
|
|
|
|
navigator.Enabled = true;
|
|
|
|
}else{
|
|
|
|
navigator.Items.Clear();
|
|
|
|
navigator.Enabled = false;
|
|
|
|
}
|
|
|
|
}
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
2014-05-13 09:43:58 +00:00
|
|
|
private void updateNavigator(MemoryStream stream, string scriptType)
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
if (scriptType == ScriptTypes.TYPES[(int)ScriptType.ACS]) {
|
|
|
|
updateNavigatorAcs(stream);
|
|
|
|
} else if (scriptType == ScriptTypes.TYPES[(int)ScriptType.MODELDEF]) {
|
|
|
|
updateNavigatorModeldef(stream);
|
|
|
|
} else if (scriptType == ScriptTypes.TYPES[(int)ScriptType.DECORATE]) {
|
|
|
|
updateNavigatorDecorate(stream);
|
|
|
|
}
|
|
|
|
}
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
2014-05-13 09:43:58 +00:00
|
|
|
private void updateNavigatorDecorate(MemoryStream stream)
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
if (stream == null) return;
|
2012-07-12 22:34:12 +00:00
|
|
|
|
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();
|
|
|
|
parser.Parse(stream, "DECORATE");
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
if (parser.Actors.Count == 0) return;
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
navigator.Items.AddRange(parser.Actors.ToArray());
|
|
|
|
}
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
2014-05-13 09:43:58 +00:00
|
|
|
private void updateNavigatorModeldef(MemoryStream stream)
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
if (stream == null) return;
|
2012-07-12 22:34:12 +00:00
|
|
|
|
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();
|
|
|
|
parser.Parse(stream, "MODELDEF");
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
if (parser.Models.Count == 0) return;
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
navigator.Items.AddRange(parser.Models.ToArray());
|
|
|
|
}
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
2014-05-13 09:43:58 +00:00
|
|
|
private void updateNavigatorAcs(MemoryStream stream)
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
if (stream == null) return;
|
|
|
|
|
|
|
|
navigator.Items.Clear();
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
AcsParserSE parser = new AcsParserSE();
|
|
|
|
parser.Parse(stream, "ACS");
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
if (parser.NamedScripts.Count == 0 && parser.NumberedScripts.Count == 0) return;
|
2012-07-12 22:34:12 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
if(General.Map.UDMF)
|
|
|
|
navigator.Items.AddRange(parser.NamedScripts.ToArray());
|
2012-07-16 09:45:21 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
navigator.Items.AddRange(parser.NumberedScripts.ToArray());
|
|
|
|
}
|
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();
|
|
|
|
if (parser.Parse(new MemoryStream(editor.GetText()), config.Description)) {
|
|
|
|
if (parser.ScriptType != (int)ScriptType.UNKNOWN && config.Description != ScriptTypes.TYPES[(int)parser.ScriptType])
|
|
|
|
return parser.ScriptType;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
protected void navigator_SelectedIndexChanged(object sender, EventArgs e) {
|
|
|
|
if (navigator.SelectedItem is ScriptItem) {
|
|
|
|
ScriptItem si = navigator.SelectedItem as ScriptItem;
|
|
|
|
editor.EnsureLineVisible(editor.LineFromPosition(si.SelectionStart));
|
|
|
|
editor.SelectionStart = si.SelectionStart;
|
|
|
|
editor.SelectionEnd = si.SelectionEnd;
|
|
|
|
|
|
|
|
// Focus to the editor!
|
|
|
|
editor.Focus();
|
|
|
|
editor.GrabFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd
|
|
|
|
protected void navigator_DropDown(object sender, EventArgs e) {
|
|
|
|
if(editor.IsChanged) updateNavigator();
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|