Added "Allman-style bracing in snippets" setting (located in Preferences -> Appearance -> Script Editor).

Snippets: changed token syntax from $XX to [XX]
[LB] (Line Break) marker can now be used in snippets.
Game Configurations: added "enabledbydefault" parameter. When set to true, a game configuration will be available by default (e.g. when an user starts the editor for the first time).
GZDB will no longer throw an exception when trying to update default value in a TypeHandler, which doesn't implement default value handling.
This commit is contained in:
MaxED 2014-05-15 08:32:08 +00:00
parent 9401828f73
commit 15bcea9417
24 changed files with 124 additions and 54 deletions

View file

@ -11,6 +11,9 @@ game = "Boom: Doom 2 (Doom format)";
// This is the simplified game engine/sourceport name
engine = "boom";
// Should this configuration be initially available?
enabledbydefault = true;
// *******************************************************
// * *
// * Note: all the elements that could be factorized *

View file

@ -11,6 +11,9 @@ game = "Doom: Doom 2 (Doom format)";
// This is the simplified game engine/sourceport name
engine = "doom2";
// Should this configuration be initially available?
enabledbydefault = true;
// *******************************************************
// * *
// * Note: all the elements that could be factorized *

View file

@ -11,6 +11,9 @@ game = "GZDoom: Doom (Hexen format)";
// This is the simplified game engine/sourceport name
engine = "gzdoom";
// Should this configuration be initially available?
enabledbydefault = true;
// *******************************************************
// * *
// * Note: all the elements that could be factorized *

View file

@ -11,6 +11,9 @@ game = "GZDoom: Doom (UDMF)";
// This is the simplified game engine/sourceport name
engine = "gzdoom";
// Should this configuration be initially available?
enabledbydefault = true;
// *******************************************************
// * *
// * Note: all the elements that could be factorized *

View file

@ -108,7 +108,7 @@ monsters
{
title = "Spectre";
width = 30;
sprite = "SARGA2A8";
sprite = "SARGF1";
class = "Spectre";
}

View file

@ -1,3 +1,3 @@
do {
do[LB]{
} until ($EP);
} until ([EP]);

View file

@ -1,3 +1,3 @@
do {
do[LB]{
} while ($EP);
} while ([EP]);

View file

@ -1,3 +1,3 @@
for (int i = 0; i < $EP; i++) {
for (int i = 0; i < [EP]; i++)[LB]{
}

View file

@ -1,3 +1,3 @@
if ($EP) {
if ([EP])[LB]{
}

View file

@ -1,5 +1,5 @@
if ($EP) {
if ([EP])[LB]{
} else {
}[LB]else[LB]{
}

View file

@ -1,5 +1,5 @@
#include "zcommon.acs"
script 1 OPEN {
$EP
script 1 OPEN[LB]{
[EP]
}

View file

@ -1,3 +1,3 @@
script $EP (void) {
script [EP] (void)[LB]{
}

View file

@ -1,3 +1,3 @@
until ($EP) {
until ([EP])[LB]{
}

View file

@ -1,3 +1,3 @@
while ($EP) {
while ([EP])[LB]{
}

View file

@ -34,8 +34,14 @@
<strong>Example:</strong> to create the while loop, type &quot;<strong>while</strong>&quot;...<br /><img src="snippets_expand1.jpg"/><br />
<br />...and press the <strong>Tab</strong> key.<br /><img src="snippets_expand2.jpg"/></p>
<p><strong>Creating new code snippets:</strong><br />
Code snippets are plain text files stored in [GZDB]\Snippets\[category], so just create a new text file there and add the code you want into it. Currently the only supported &quot;special&quot; token is <strong>$EP</strong> (Entry Point) - that's the place where the cursor will be placed after inserting a snippet.<br />
<span class="style1">Warning:</span> snippet's file name should not contain spaces.</p>
Code snippets are plain text files stored in [GZDB]\Snippets\[category], so just create a new text file there and add the code you want into it.<br />
There are several special tokens you can use: </p>
<ul>
<li><strong>[EP]</strong> (Entry Point) - that's the place where the cursor will be placed after inserting a snippet.</li>
<li><strong>[LB]</strong> (Line Break)
- these will be converted to line breaks when &quot;<strong>Allman-style bracing in snippets</strong>&quot; (located in Preferences -&gt; Appearance -&gt; Script Editor) setting is enabled, or a space character when it's not.
</ul>
<span class="style1">Warning:</span> snippet's file name must not contain spaces.
<p><strong>Creating new code snippets for custom scripting configurations:</strong><br />
To add snippets to a scripting configuration, which doesn't already have existing snippets (&quot;Insert a Code Snippet&quot; drop-down is disabled in the Script Editor), you'll have to:</p>
<ol>

View file

@ -118,7 +118,7 @@ namespace CodeImp.DoomBuilder.Config
this.nodebuildertest = General.Settings.ReadSetting("configurations." + settingskey + ".nodebuildertest", MISSING_NODEBUILDER);
this.resources = new DataLocationList(General.Settings.Config, "configurations." + settingskey + ".resources");
this.startmode = General.Settings.ReadSetting("configurations." + settingskey + ".startmode", "VerticesMode");
this.enabled = General.Settings.ReadSetting("configurations." + settingskey + ".enabled", false); //mxd
this.enabled = General.Settings.ReadSetting("configurations." + settingskey + ".enabled", config.ReadSetting("enabledbydefault", false)); //mxd
//mxd. read test engines
testEngines = new List<EngineInfo>();

View file

@ -66,6 +66,7 @@ namespace CodeImp.DoomBuilder.Config
private bool scriptfontbold;
private bool scriptontop;
private bool scriptautoindent;
private bool snippetsallmanstyle; //mxd
private int scripttabwidth;
private int previewimagesize;
private int autoscrollspeed;
@ -155,6 +156,7 @@ namespace CodeImp.DoomBuilder.Config
public bool AnimateVisualSelection { get { return animatevisualselection; } internal set { animatevisualselection = value; } }
public int ScriptTabWidth { get { return scripttabwidth; } internal set { scripttabwidth = value; } }
public bool ScriptAutoIndent { get { return scriptautoindent; } internal set { scriptautoindent = value; } }
public bool SnippetsAllmanStyle { get { return snippetsallmanstyle; } internal set { snippetsallmanstyle = value; } } //mxd
internal int PreviousVersion { get { return previousversion; } }
internal PasteOptions PasteOptions { get { return pasteoptions; } set { pasteoptions = value; } }
public int DockersPosition { get { return dockersposition; } internal set { dockersposition = value; } }
@ -254,6 +256,7 @@ namespace CodeImp.DoomBuilder.Config
scriptfontsize = cfg.ReadSetting("scriptfontsize", 10);
scriptfontbold = cfg.ReadSetting("scriptfontbold", false);
scriptautoindent = cfg.ReadSetting("scriptautoindent", true);
snippetsallmanstyle = cfg.ReadSetting("snippetsallmanstyle", false); //mxd
scriptontop = cfg.ReadSetting("scriptontop", true);
scripttabwidth = cfg.ReadSetting("scripttabwidth", 4);
previewimagesize = cfg.ReadSetting("previewimagesize", 1);
@ -344,6 +347,7 @@ namespace CodeImp.DoomBuilder.Config
cfg.WriteSetting("scriptontop", scriptontop);
cfg.WriteSetting("scripttabwidth", scripttabwidth);
cfg.WriteSetting("scriptautoindent", scriptautoindent);
cfg.WriteSetting("snippetsallmanstyle", snippetsallmanstyle); //mxd
cfg.WriteSetting("previewimagesize", previewimagesize);
cfg.WriteSetting("autoscrollspeed", autoscrollspeed);
cfg.WriteSetting("zoomfactor", zoomfactor);

View file

@ -663,18 +663,18 @@ namespace CodeImp.DoomBuilder.Controls
string spaces = new String(' ', General.Settings.ScriptTabWidth);
int entrypos = -1;
int entryline = -1;
string[] processedlines = new string[lines.Length];
string[] processedlines = processLineBreaks(lines);
for (int i = 0; i < lines.Length; i++) {
processedlines[i] = lines[i].Replace("\t", spaces);
processedlines[i] = processedlines[i].Replace("\t", spaces);
//check if we have the $EP marker
//check if we have the [EP] marker
if (entrypos == -1) {
int pos = processedlines[i].IndexOf("$EP");
int pos = processedlines[i].IndexOf("[EP]");
if (pos != -1) {
entryline = curline + i;
entrypos = pos + numtabs;
processedlines[i] = processedlines[i].Remove(pos, 3);
processedlines[i] = processedlines[i].Remove(pos, 4);
}
}
}
@ -685,7 +685,7 @@ namespace CodeImp.DoomBuilder.Controls
scriptedit.SelectionEnd = scriptedit.WordEndPosition(scriptedit.CurrentPos, true);
scriptedit.ReplaceSel(text);
//move the cursor if we had the $EP marker
//move the cursor if we had the [EP] marker
if (entrypos != -1) {
MoveToLine(entryline);
scriptedit.SelectionStart = scriptedit.PositionFromLine(entryline) + entrypos;
@ -693,6 +693,27 @@ namespace CodeImp.DoomBuilder.Controls
}
}
//mxd. This converts [LB] markers to line breaks if necessary
private string[] processLineBreaks(string[] lines)
{
List<string> result = new List<string>(lines.Length);
string[] separator = new[] { "[LB]" };
foreach(string line in lines) {
if(line.IndexOf(separator[0]) != -1) {
if(General.Settings.SnippetsAllmanStyle) {
result.AddRange(line.Split(separator, StringSplitOptions.RemoveEmptyEntries));
} else {
result.Add(line.Replace(separator[0], " "));
}
} else {
result.Add(line);
}
}
return result.ToArray();
}
#endregion
#region ================== Events

View file

@ -73,8 +73,6 @@ namespace CodeImp.DoomBuilder.Types
public override void SetValue(object value)
{
int result;
// Null?
if(value == null)
{
@ -89,6 +87,7 @@ namespace CodeImp.DoomBuilder.Types
else
{
// Try parsing as string
int result;
if(int.TryParse(value.ToString(), NumberStyles.Integer, CultureInfo.CurrentCulture, out result))
{
this.value = result;

View file

@ -64,7 +64,7 @@ namespace CodeImp.DoomBuilder.Types
base.SetupField(attr, fieldinfo);
// Keep enum list reference
if(fieldinfo != null) list = fieldinfo.Enum; else list = new EnumList();
list = (fieldinfo != null ? fieldinfo.Enum : new EnumList());
}
#endregion
@ -140,7 +140,8 @@ namespace CodeImp.DoomBuilder.Types
}
//mxd
public override void SetDefaultValue() {
public override void SetDefaultValue()
{
value = defaultValue;
}
@ -171,9 +172,9 @@ namespace CodeImp.DoomBuilder.Types
}
}
public override string GetStringValue()
public override string GetStringValue()
{
if(this.value != null) return this.value.Title; else return "NULL";
return (this.value != null ? this.value.Title : "NULL");
}
// This returns an enum list

View file

@ -124,10 +124,8 @@ namespace CodeImp.DoomBuilder.Types
// How the value is actually validated and stored is up to the implementation
public abstract void SetValue(object value);
//mxd. this should replace current value with default one
public virtual void SetDefaultValue() {
throw new NotSupportedException("Override this method to support default value for this type");
}
//mxd. This should replace current value with the default one
public virtual void SetDefaultValue() { }
// This must return the value as one of the primitive data types
// supported by UDMF: int, string, float or bool
@ -136,7 +134,7 @@ namespace CodeImp.DoomBuilder.Types
// This must return the value as integer (for arguments)
public virtual int GetIntValue()
{
throw new NotSupportedException("Override this method to support it as integer for arguments");
throw new NotImplementedException("Override this method to support it as integer for arguments");
}
// This must return the value as a string for displaying

View file

@ -38,6 +38,7 @@ namespace CodeImp.DoomBuilder.Windows
System.Windows.Forms.Label label18;
System.Windows.Forms.Label label20;
System.Windows.Forms.Label label21;
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PreferencesForm));
this.recentFiles = new Dotnetrix.Controls.TrackBar();
this.labelRecentFiles = new System.Windows.Forms.Label();
this.label25 = new System.Windows.Forms.Label();
@ -142,10 +143,11 @@ namespace CodeImp.DoomBuilder.Windows
this.imagebrightnesslabel = new System.Windows.Forms.Label();
this.imagebrightness = new Dotnetrix.Controls.TrackBar();
this.colorsgroup3 = new System.Windows.Forms.GroupBox();
this.fontpreview = new System.Windows.Forms.RichTextBox();
this.snippetsallmanstyle = new System.Windows.Forms.CheckBox();
this.scripttabwidth = new CodeImp.DoomBuilder.Controls.ButtonsNumericTextbox();
this.scriptautoindent = new System.Windows.Forms.CheckBox();
this.label10 = new System.Windows.Forms.Label();
this.fontpreview = new System.Windows.Forms.RichTextBox();
this.scriptfontsize = new System.Windows.Forms.ComboBox();
this.label8 = new System.Windows.Forms.Label();
this.scriptfontbold = new System.Windows.Forms.CheckBox();
@ -478,6 +480,8 @@ namespace CodeImp.DoomBuilder.Windows
label18.TabIndex = 25;
label18.Text = "Max. dynamic lights to render:";
label18.TextAlign = System.Drawing.ContentAlignment.TopRight;
this.toolTip1.SetToolTip(label18, "Controlls how many dynamic lights could be \r\nrendered simultaneously in Visual mo" +
"de ");
//
// label20
//
@ -1490,10 +1494,11 @@ namespace CodeImp.DoomBuilder.Windows
//
this.colorsgroup3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.colorsgroup3.Controls.Add(this.fontpreview);
this.colorsgroup3.Controls.Add(this.snippetsallmanstyle);
this.colorsgroup3.Controls.Add(this.scripttabwidth);
this.colorsgroup3.Controls.Add(this.scriptautoindent);
this.colorsgroup3.Controls.Add(this.label10);
this.colorsgroup3.Controls.Add(this.fontpreview);
this.colorsgroup3.Controls.Add(this.scriptfontsize);
this.colorsgroup3.Controls.Add(this.label8);
this.colorsgroup3.Controls.Add(this.scriptfontbold);
@ -1514,19 +1519,16 @@ namespace CodeImp.DoomBuilder.Windows
this.colorsgroup3.Text = " Script editor ";
this.colorsgroup3.Visible = false;
//
// fontpreview
// snippetsallmanstyle
//
this.fontpreview.Cursor = System.Windows.Forms.Cursors.Arrow;
this.fontpreview.DetectUrls = false;
this.fontpreview.Location = new System.Drawing.Point(202, 73);
this.fontpreview.Name = "fontpreview";
this.fontpreview.ReadOnly = true;
this.fontpreview.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
this.fontpreview.Size = new System.Drawing.Size(233, 100);
this.fontpreview.TabIndex = 33;
this.fontpreview.Text = "1 #include \"zcommon.acs\"\n2 script 0 (void) { //a comment\n3 CONSTANT_VALUE;\n" +
"4 }";
this.fontpreview.WordWrap = false;
this.snippetsallmanstyle.AutoSize = true;
this.snippetsallmanstyle.Location = new System.Drawing.Point(202, 187);
this.snippetsallmanstyle.Name = "snippetsallmanstyle";
this.snippetsallmanstyle.Size = new System.Drawing.Size(179, 18);
this.snippetsallmanstyle.TabIndex = 34;
this.snippetsallmanstyle.Text = "Allman-style bracing in snippets";
this.toolTip1.SetToolTip(this.snippetsallmanstyle, resources.GetString("snippetsallmanstyle.ToolTip"));
this.snippetsallmanstyle.UseVisualStyleBackColor = true;
//
// scripttabwidth
//
@ -1535,7 +1537,7 @@ namespace CodeImp.DoomBuilder.Windows
this.scripttabwidth.AllowRelative = false;
this.scripttabwidth.ButtonStep = 2;
this.scripttabwidth.ButtonStepFloat = 1F;
this.scripttabwidth.Location = new System.Drawing.Point(259, 179);
this.scripttabwidth.Location = new System.Drawing.Point(364, 157);
this.scripttabwidth.Name = "scripttabwidth";
this.scripttabwidth.Size = new System.Drawing.Size(71, 24);
this.scripttabwidth.StepValues = null;
@ -1544,7 +1546,7 @@ namespace CodeImp.DoomBuilder.Windows
// scriptautoindent
//
this.scriptautoindent.AutoSize = true;
this.scriptautoindent.Location = new System.Drawing.Point(354, 183);
this.scriptautoindent.Location = new System.Drawing.Point(202, 161);
this.scriptautoindent.Name = "scriptautoindent";
this.scriptautoindent.Size = new System.Drawing.Size(81, 18);
this.scriptautoindent.TabIndex = 31;
@ -1554,12 +1556,26 @@ namespace CodeImp.DoomBuilder.Windows
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(199, 184);
this.label10.Location = new System.Drawing.Point(304, 162);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(57, 14);
this.label10.TabIndex = 30;
this.label10.Text = "Tab width:";
//
// fontpreview
//
this.fontpreview.Cursor = System.Windows.Forms.Cursors.Arrow;
this.fontpreview.DetectUrls = false;
this.fontpreview.Location = new System.Drawing.Point(202, 70);
this.fontpreview.Name = "fontpreview";
this.fontpreview.ReadOnly = true;
this.fontpreview.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
this.fontpreview.Size = new System.Drawing.Size(233, 80);
this.fontpreview.TabIndex = 33;
this.fontpreview.Text = "1 #include \"zcommon.acs\"\n2 script 0 (void) { //a comment\n3 CONSTANT_VALUE;\n" +
"4 }";
this.fontpreview.WordWrap = false;
//
// scriptfontsize
//
this.scriptfontsize.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
@ -1582,7 +1598,7 @@ namespace CodeImp.DoomBuilder.Windows
"36",
"48",
"72"});
this.scriptfontsize.Location = new System.Drawing.Point(236, 45);
this.scriptfontsize.Location = new System.Drawing.Point(236, 43);
this.scriptfontsize.Name = "scriptfontsize";
this.scriptfontsize.Size = new System.Drawing.Size(94, 22);
this.scriptfontsize.TabIndex = 25;
@ -1591,7 +1607,7 @@ namespace CodeImp.DoomBuilder.Windows
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(199, 48);
this.label8.Location = new System.Drawing.Point(199, 46);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(31, 14);
this.label8.TabIndex = 28;
@ -1600,7 +1616,7 @@ namespace CodeImp.DoomBuilder.Windows
// scriptfontbold
//
this.scriptfontbold.AutoSize = true;
this.scriptfontbold.Location = new System.Drawing.Point(354, 47);
this.scriptfontbold.Location = new System.Drawing.Point(354, 45);
this.scriptfontbold.Name = "scriptfontbold";
this.scriptfontbold.Size = new System.Drawing.Size(47, 18);
this.scriptfontbold.TabIndex = 26;
@ -1941,5 +1957,6 @@ namespace CodeImp.DoomBuilder.Windows
private Dotnetrix.Controls.TrackBar recentFiles;
private System.Windows.Forms.Label labelRecentFiles;
private System.Windows.Forms.Label label25;
private System.Windows.Forms.CheckBox snippetsallmanstyle;
}
}

View file

@ -74,6 +74,7 @@ namespace CodeImp.DoomBuilder.Windows
scriptontop.Checked = General.Settings.ScriptOnTop;
scripttabwidth.Text = General.Settings.ScriptTabWidth.ToString();
scriptautoindent.Checked = General.Settings.ScriptAutoIndent;
snippetsallmanstyle.Checked = General.Settings.SnippetsAllmanStyle; //mxd
previewsize.Value = General.Clamp(General.Settings.PreviewImageSize, previewsize.Minimum, previewsize.Maximum);
autoscrollspeed.Value = General.Clamp(General.Settings.AutoScrollSpeed, autoscrollspeed.Minimum, autoscrollspeed.Maximum);
zoomfactor.Value = General.Clamp(General.Settings.ZoomFactor, zoomfactor.Minimum, zoomfactor.Maximum);
@ -225,6 +226,7 @@ namespace CodeImp.DoomBuilder.Windows
General.Settings.ScriptOnTop = scriptontop.Checked;
General.Settings.ScriptTabWidth = scripttabwidth.GetResult(General.Settings.ScriptTabWidth);
General.Settings.ScriptAutoIndent = scriptautoindent.Checked;
General.Settings.SnippetsAllmanStyle = snippetsallmanstyle.Checked; //mxd
General.Settings.PreviewImageSize = previewsize.Value;
General.Settings.AutoScrollSpeed = autoscrollspeed.Value;
General.Settings.ZoomFactor = zoomfactor.Value;

View file

@ -144,4 +144,14 @@
<metadata name="label21.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<data name="snippetsallmanstyle.ToolTip" xml:space="preserve">
<value>When enabled, the opening brace
will be placed on a new line.
Technical side: when enabled, $LB
markers in snippets will be replaced
with newline characters, otherwise
they will be replaced with spaces
</value>
</data>
</root>