From e390bce8f62c4229eff0a09cf89b91290f7f7e45 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 30 Sep 2020 03:34:11 +0200 Subject: [PATCH] Find the exact Scintilla.NET API used by UDB and create a stub implementation so that it builds without --- Source/Core/Builder.csproj | 1 + Source/Core/BuilderMono.csproj | 19 + Source/Core/Config/ScriptConfiguration.cs | 10 - .../Controls/Scripting/ScriptDocumentTab.cs | 81 +--- .../Scripting/ScriptFileDocumentTab.cs | 2 - .../Scripting/ScriptResourceDocumentTab.cs | 64 --- .../Controls/Scripting/TextEditorControl.cs | 438 ++++++++++++++++++ Source/Core/Data/Scripting/ScriptHandler.cs | 24 - 8 files changed, 459 insertions(+), 180 deletions(-) create mode 100644 Source/Core/Controls/Scripting/TextEditorControl.cs diff --git a/Source/Core/Builder.csproj b/Source/Core/Builder.csproj index 50dab9c5..fb720b7a 100644 --- a/Source/Core/Builder.csproj +++ b/Source/Core/Builder.csproj @@ -179,6 +179,7 @@ ArgumentBox.cs + Component diff --git a/Source/Core/BuilderMono.csproj b/Source/Core/BuilderMono.csproj index c2c3c0b2..cfa28cf9 100644 --- a/Source/Core/BuilderMono.csproj +++ b/Source/Core/BuilderMono.csproj @@ -176,12 +176,19 @@ ArgumentBox.cs + Component Component + + UserControl + + + ScriptEditorPanel.cs + Component @@ -870,6 +877,18 @@ PasteOptionsControl.cs + + UserControl + + + ScriptEditorControl.cs + + + UserControl + + + ScriptEditorPreviewControl.cs + UserControl diff --git a/Source/Core/Config/ScriptConfiguration.cs b/Source/Core/Config/ScriptConfiguration.cs index 4f228e44..76541375 100755 --- a/Source/Core/Config/ScriptConfiguration.cs +++ b/Source/Core/Config/ScriptConfiguration.cs @@ -21,9 +21,7 @@ using System.Collections; using System.Collections.Generic; using System.IO; using CodeImp.DoomBuilder.IO; -#if !NO_SCINTILLA using ScintillaNET; -#endif #endregion @@ -77,9 +75,7 @@ namespace CodeImp.DoomBuilder.Config private readonly string[] extensions; private readonly bool casesensitive; private readonly int insertcase; -#if !NO_SCINTILLA private readonly Lexer lexer; -#endif private readonly string keywordhelp; private readonly string functionopen; private readonly string functionclose; @@ -118,9 +114,7 @@ namespace CodeImp.DoomBuilder.Config public string[] Extensions { get { return extensions; } } public bool CaseSensitive { get { return casesensitive; } } public int InsertCase { get { return insertcase; } } -#if !NO_SCINTILLA public Lexer Lexer { get { return lexer; } } -#endif public string KeywordHelp { get { return keywordhelp; } } public string FunctionOpen { get { return functionopen; } } public string FunctionClose { get { return functionclose; } } @@ -161,9 +155,7 @@ namespace CodeImp.DoomBuilder.Config this.braces = new HashSet(); //mxd // Settings - #if !NO_SCINTILLA lexer = Lexer.Null; - #endif casesensitive = false; codepage = 65001; parameters = ""; @@ -208,9 +200,7 @@ namespace CodeImp.DoomBuilder.Config resultlump = cfg.ReadSetting("resultlump", ""); casesensitive = cfg.ReadSetting("casesensitive", true); insertcase = cfg.ReadSetting("insertcase", 0); - #if !NO_SCINTILLA lexer = (Lexer)cfg.ReadSetting("lexer", (int)Lexer.Container); - #endif keywordhelp = cfg.ReadSetting("keywordhelp", ""); functionopen = cfg.ReadSetting("functionopen", ""); functionclose = cfg.ReadSetting("functionclose", ""); diff --git a/Source/Core/Controls/Scripting/ScriptDocumentTab.cs b/Source/Core/Controls/Scripting/ScriptDocumentTab.cs index ddb805d3..23b66767 100755 --- a/Source/Core/Controls/Scripting/ScriptDocumentTab.cs +++ b/Source/Core/Controls/Scripting/ScriptDocumentTab.cs @@ -28,87 +28,10 @@ using CodeImp.DoomBuilder.Config; using CodeImp.DoomBuilder.Compilers; using CodeImp.DoomBuilder.ZDoom.Scripting; using System.Text; +using ScintillaNET; #endregion -#if NO_SCINTILLA - -namespace CodeImp.DoomBuilder.Controls -{ - internal abstract class ScriptDocumentTab : TabPage - { - protected readonly ScriptEditorControl editor; - protected ScriptConfiguration config; - protected readonly ScriptEditorPanel panel; - protected ScriptDocumentTabType tabtype; - - 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 bool IsReadOnly { get { return false; } } - public virtual string Filename { get { return ""; } } - public ScriptEditorPanel Panel { get { return panel; } } - public ScriptEditorControl Editor { get; private set; } - public string Title { get; private set; } - public bool IsChanged { get { return false; } } - public int SelectionStart { get; set; } - public int SelectionEnd { get; set; } - public bool ShowWhitespace { get; set; } - public bool WrapLongLines { get; set; } - public string SelectedText { get { return ""; } } - public ScriptConfiguration Config { get { return config; } } - - public new event EventHandler OnTextChanged; - - protected ScriptDocumentTab(ScriptEditorPanel panel, ScriptConfiguration config) - { - this.panel = panel; - this.config = config; - - editor = new ScriptEditorControl(); - this.Controls.Add(editor); - } - - public bool LaunchKeywordHelp() { return false; } - public virtual void RefreshSettings() { } - public virtual void MoveToLine(int linenumber) { } - public virtual void ClearMarks() { } - public virtual void MarkScriptErrors(IEnumerable errors) { } - public virtual bool VerifyErrorForScript(CompilerError e) { return false; } - public virtual void Compile() { } - public virtual bool Save() { return false; } - public virtual bool SaveAs(string filename) { return false; } - public virtual void ChangeScriptConfig(ScriptConfiguration newconfig) { } - public void Undo() { } - public void Redo() { } - public void Cut() { } - public void Copy() { } - public void Paste() { } - public bool FindNext(FindReplaceOptions options) { return false; } - public bool FindNext(FindReplaceOptions options, bool useselectionstart) { return false; } - public bool FindPrevious(FindReplaceOptions options) { return false; } - public void ReplaceSelection(string replacement) { } - - internal virtual ScriptDocumentSettings GetViewSettings() { return new ScriptDocumentSettings {}; } - internal virtual void SetViewSettings(ScriptDocumentSettings settings) { } - internal void SetDefaultViewSettings() { } - - internal List UpdateNavigator() { return new List(); } - internal ScriptType VerifyScriptType() { return ScriptType.UNKNOWN; } - internal void InsertSnippet(string name) { } - internal void IndentSelection(bool indent) { } - - protected void SetTitle(string title) { } - protected void UpdateTitle() { } - protected void RemoveTrailingWhitespace() { } - } -} - -#else - -using ScintillaNET; - namespace CodeImp.DoomBuilder.Controls { internal abstract class ScriptDocumentTab : TabPage @@ -607,5 +530,3 @@ namespace CodeImp.DoomBuilder.Controls #endregion } } - -#endif diff --git a/Source/Core/Controls/Scripting/ScriptFileDocumentTab.cs b/Source/Core/Controls/Scripting/ScriptFileDocumentTab.cs index 666ac542..2d8d0f6c 100755 --- a/Source/Core/Controls/Scripting/ScriptFileDocumentTab.cs +++ b/Source/Core/Controls/Scripting/ScriptFileDocumentTab.cs @@ -68,9 +68,7 @@ namespace CodeImp.DoomBuilder.Controls { // Set text and view settings tabtype = ScriptDocumentTabType.FILE; -#if !NO_SCINTILLA editor.Scintilla.Text = sourcetab.Editor.Scintilla.Text; -#endif SetViewSettings(sourcetab.GetViewSettings()); // Set title diff --git a/Source/Core/Controls/Scripting/ScriptResourceDocumentTab.cs b/Source/Core/Controls/Scripting/ScriptResourceDocumentTab.cs index a6a6846f..7166e949 100755 --- a/Source/Core/Controls/Scripting/ScriptResourceDocumentTab.cs +++ b/Source/Core/Controls/Scripting/ScriptResourceDocumentTab.cs @@ -10,68 +10,6 @@ using CodeImp.DoomBuilder.Data.Scripting; #endregion -#if NO_SCINTILLA - -namespace CodeImp.DoomBuilder.Controls -{ - //mxd. Document tab bound to a resource entry. Script type can't be changed. Can be readonly. - //Must be replaced with ScriptFileDocumentTab when unable to locate target resource entry to save to. - internal sealed class ScriptResourceDocumentTab : ScriptDocumentTab - { - private ScriptResource source; - private string hash; - private string filepathname; - - public override bool IsReconfigurable { get { return false; } } - public override bool IsSaveAsRequired { get { return false; } } - public override bool IsReadOnly { get { return source.IsReadOnly; } } - public override string Filename { get { return filepathname; } } - internal ScriptResource Resource { get { return source; } } - - internal ScriptResourceDocumentTab(ScriptEditorPanel panel, ScriptResource resource, ScriptConfiguration config) : base(panel, config) - { - source = resource; - filepathname = source.FilePathName; - this.ToolTipText = filepathname; - } - - public override void Compile() - { - } - - // This checks if a script error applies to this script - public override bool VerifyErrorForScript(CompilerError e) - { - return (string.Compare(e.filename, source.Filename, true) == 0); - } - - public override bool Save() - { - if(source.IsReadOnly) return false; - return false; - } - - internal override ScriptDocumentSettings GetViewSettings() - { - // Store resource location - var settings = base.GetViewSettings(); - DataReader reader = source.Resource; - if(reader != null) - { - settings.ResourceLocation = reader.Location.location; - settings.Filename = Path.Combine(reader.Location.location, filepathname); // Make unique location - } - return settings; - } - - internal void OnReloadResources() - { - } - } -} - -#else - namespace CodeImp.DoomBuilder.Controls { //mxd. Document tab bound to a resource entry. Script type can't be changed. Can be readonly. @@ -227,5 +165,3 @@ namespace CodeImp.DoomBuilder.Controls #endregion } } - -#endif diff --git a/Source/Core/Controls/Scripting/TextEditorControl.cs b/Source/Core/Controls/Scripting/TextEditorControl.cs new file mode 100644 index 00000000..77a24600 --- /dev/null +++ b/Source/Core/Controls/Scripting/TextEditorControl.cs @@ -0,0 +1,438 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +#if NO_SCINTILLA + +namespace ScintillaNET +{ + public enum Lexer + { + Container = 0, + Null = 1, + Python = 2, + Cpp = 3, + Html = 4, + Xml = 5, + Perl = 6, + Sql = 7, + Vb = 8, + Properties = 9, + Batch = 12, + Lua = 15, + Pascal = 18, + Ada = 20, + Lisp = 21, + Ruby = 22, + VbScript = 28, + Asm = 34, + Fortran = 36, + Css = 38, + Verilog = 56, + BlitzBasic = 66, + PureBasic = 67, + PhpScript = 69, + Smalltalk = 72, + FreeBasic = 75, + R = 86, + PowerShell = 88, + Markdown = 98, + Json = 120 + } + + public enum WhitespaceMode + { + Invisible, + VisibleAlways, + VisibleAfterIndent, + VisibleOnlyIndent + } + + public enum WrapMode + { + None, + Word, + Char, + Whitespace + } + + public enum Command + { + Null + } + + public enum FoldAction + { + Contract + } + + [Flags] + public enum FoldFlags + { + LineAfterContracted + } + + public class Line + { + public int Position { get; private set; } + public int EndPosition { get; private set; } + public string Text { get; private set; } + public int WrapCount { get; private set; } + public int Indentation { get; set; } + public int FoldLevel { get; set; } + public bool Expanded { get; set; } + + public void FoldLine(FoldAction action) { } + public void Goto() { } + public void MarkerAdd(int marker) { } + } + + public class LineCollection // : IEnumerable + { + public int Count { get { return 0; } } + public Line this[int index] { get { return null; } } + } + + public enum StyleCase + { + Mixed + } + + public class Style + { + public const int Default = 0; + public const int LineNumber = 1; + public const int CallTip = 2; + public const int IndentGuide = 3; + public const int BraceLight = 4; + public const int BraceBad = 5; + public const int FoldDisplayText = 6; + + public Color BackColor { get; set; } + public Color ForeColor { get; set; } + public string Font { get; set; } + public int Size { get; set; } + public bool Bold { get; set; } + public bool Italic { get; set; } + public bool Underline { get; set; } + public StyleCase Case { get; set; } + } + + public class StyleCollection // : IEnumerable