working on script editor

This commit is contained in:
codeimp 2008-10-26 23:10:48 +00:00
parent 1c42184989
commit 4e07270816
8 changed files with 537 additions and 1 deletions

View file

@ -79,6 +79,11 @@
<Compile Include="Controls\ArgumentBox.Designer.cs">
<DependentUpon>ArgumentBox.cs</DependentUpon>
</Compile>
<Compile Include="Controls\ScriptLineInfo.cs" />
<Compile Include="Controls\ScriptEditControl.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\ScriptMarking.cs" />
<Compile Include="Data\DirectoryReader.cs" />
<Compile Include="Data\FileImage.cs" />
<Compile Include="Data\FlatImage.cs" />
@ -323,6 +328,12 @@
<Compile Include="Windows\ResourceOptionsForm.Designer.cs">
<DependentUpon>ResourceOptionsForm.cs</DependentUpon>
</Compile>
<Compile Include="Windows\ScriptEditTestForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Windows\ScriptEditTestForm.Designer.cs">
<DependentUpon>ScriptEditTestForm.cs</DependentUpon>
</Compile>
<Compile Include="Windows\SectorEditForm.cs">
<SubType>Form</SubType>
</Compile>
@ -651,6 +662,10 @@
<SubType>Designer</SubType>
<DependentUpon>CustomFieldsForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Windows\ScriptEditTestForm.resx">
<SubType>Designer</SubType>
<DependentUpon>ScriptEditTestForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Windows\TextEditForm.resx">
<SubType>Designer</SubType>
<DependentUpon>TextEditForm.cs</DependentUpon>

View file

@ -0,0 +1,213 @@
#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;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Diagnostics;
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Map;
#endregion
namespace CodeImp.DoomBuilder.Controls
{
public partial class ScriptEditControl : RichTextBox
{
#region ================== Constants
// Update delay in milliseconds
private const int UPDATE_DELAY = 100;
#endregion
#region ================== Variables
// Range in which updating is required
// Only the timer may reset this range, the key press methods
private int updatestartline;
private int updateendline;
// Line information
private ScriptLineInfo[] lineinfo;
// Update timer
private Timer updatetimer;
#endregion
#region ================== Properties
// These prevent changing these properties
public new bool AcceptsTab { get { return base.AcceptsTab; } }
public new bool AllowDrop { get { return base.AllowDrop; } }
public new bool AutoWordSelection { get { return base.AutoWordSelection; } }
public new bool EnableAutoDragDrop { get { return base.EnableAutoDragDrop; } }
public new bool Multiline { get { return base.Multiline; } }
public new bool ShortcutsEnabled { get { return base.ShortcutsEnabled; } }
public new bool WordWrap { get { return base.WordWrap; } }
public new float ZoomFactor { get { return base.ZoomFactor; } }
#endregion
#region ================== Contructor
// Constructor
public ScriptEditControl()
{
// Properties that we need to have set this way.
// No, you cannot choose these yourself.
base.AcceptsTab = true;
base.AllowDrop = false;
base.AutoWordSelection = false;
base.EnableAutoDragDrop = false;
base.Multiline = true;
base.ShortcutsEnabled = false;
base.WordWrap = false;
base.ZoomFactor = 1.0f;
// Initialize
if(!this.DesignMode)
{
lineinfo = new ScriptLineInfo[1];
lineinfo[0] = new ScriptLineInfo(ScriptMarking.None);
updatetimer = new Timer();
updatetimer.Interval = UPDATE_DELAY;
updatetimer.Tick += new EventHandler(OnUpdateTimerTick);
}
}
// Disposer
protected override void Dispose(bool disposing)
{
// Disposing?
if(!base.IsDisposed)
{
// Dispose managed resources
if(disposing)
{
if(!this.DesignMode)
{
updatetimer.Stop();
updatetimer.Dispose();
lineinfo = null;
}
}
}
base.Dispose(disposing);
}
#endregion
#region ================== Events
// Key pressed
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
// Check in which range this keypress must update the highlighting.
// The range may only be increased, not decreased!
int startline = base.GetLineFromCharIndex(base.SelectionStart);
int endline = base.GetLineFromCharIndex(base.SelectionStart + base.SelectionLength);
if(startline < updatestartline) updatestartline = startline;
if(endline < updatestartline) updatestartline = endline;
if(startline > updateendline) updateendline = startline;
if(endline > updateendline) updateendline = endline;
}
// Key presses (repeating)
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
// (Re)start timer!
updatetimer.Stop();
updatetimer.Start();
}
// Time to update!
private void OnUpdateTimerTick(object sender, EventArgs e)
{
updatetimer.Stop();
UpdateRange();
}
#endregion
#region ================== Methods
// This updates the range
private void UpdateRange()
{
bool continueupdate = false;
int updateline = updatestartline;
// First make sure the lineinfo array is big enough
if(base.Lines.Length >= lineinfo.Length)
{
// Resize array
ScriptLineInfo[] oldlineinfo = lineinfo;
lineinfo = new ScriptLineInfo[base.Lines.Length + 1];
oldlineinfo.CopyTo(lineinfo, 0);
}
// Start updating the range
// Or go beyond the range when the result has influence on the next line
while((updateline <= updateendline) || continueupdate)
{
continueupdate = UpdateLine(updateline++);
}
// Reset the range to current position/selection
int startline = base.GetLineFromCharIndex(base.SelectionStart);
int endline = base.GetLineFromCharIndex(base.SelectionStart + base.SelectionLength);
updatestartline = Math.Min(startline, endline);
updateendline = Math.Max(startline, endline);
}
// This parses a single line to update the syntax highlighting
// Before calling this make sure the lineinfo array is resized correctly!
// Returns true if the change continues on the next line (multi-line comment changes)
private bool UpdateLine(int lineindex)
{
// Get the start information
ScriptLineInfo startinfo = lineinfo[lineindex];
ScriptLineInfo endinfo = lineinfo[lineindex + 1];
// TODO: Scan the line
// TODO: Use regexes for this?
// Update next line info
lineinfo[lineindex + 1] = endinfo;
// Check if this changes anything on the next line
return ((startinfo.startmarking == ScriptMarking.BlockComment) &&
(endinfo.startmarking != ScriptMarking.BlockComment)) ||
((startinfo.startmarking != ScriptMarking.BlockComment) &&
(endinfo.startmarking == ScriptMarking.BlockComment));
}
#endregion
}
}

View file

@ -0,0 +1,46 @@
#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;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Diagnostics;
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Map;
#endregion
namespace CodeImp.DoomBuilder.Controls
{
internal struct ScriptLineInfo
{
// Members
public ScriptMarking startmarking;
// Constructor
public ScriptLineInfo(ScriptMarking marking)
{
startmarking = marking;
}
}
}

View file

@ -0,0 +1,43 @@
#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;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Diagnostics;
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Map;
#endregion
namespace CodeImp.DoomBuilder.Controls
{
internal enum ScriptMarking
{
None,
LineComment,
BlockComment,
Function,
Constant,
Literal
}
}

View file

@ -1345,7 +1345,7 @@ namespace CodeImp.DoomBuilder
[BeginAction("testaction")]
internal static void TestAction()
{
ThingEditForm t = new ThingEditForm();
ScriptEditTestForm t = new ScriptEditTestForm();
t.ShowDialog(mainwindow);
t.Dispose();
}

View file

@ -0,0 +1,58 @@
namespace CodeImp.DoomBuilder.Windows
{
partial class ScriptEditTestForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if(disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.scriptedit = new CodeImp.DoomBuilder.Controls.ScriptEditControl();
this.SuspendLayout();
//
// scriptedit
//
this.scriptedit.Location = new System.Drawing.Point(12, 12);
this.scriptedit.Name = "scriptedit";
this.scriptedit.Size = new System.Drawing.Size(643, 487);
this.scriptedit.TabIndex = 0;
this.scriptedit.Text = "";
//
// ScriptEditTestForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(667, 511);
this.Controls.Add(this.scriptedit);
this.Name = "ScriptEditTestForm";
this.Text = "ScriptEditTestForm";
this.ResumeLayout(false);
}
#endregion
private CodeImp.DoomBuilder.Controls.ScriptEditControl scriptedit;
}
}

View file

@ -0,0 +1,41 @@
#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;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Diagnostics;
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Map;
#endregion
namespace CodeImp.DoomBuilder.Windows
{
public partial class ScriptEditTestForm : Form
{
public ScriptEditTestForm()
{
InitializeComponent();
}
}
}

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>