mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-18 22:41:46 +00:00
Added: script editor will now automatically trim trailing whitespace on save.
This commit is contained in:
parent
bd00eef8de
commit
271df46f2a
6 changed files with 54 additions and 6 deletions
|
@ -28,6 +28,7 @@ using CodeImp.DoomBuilder.Config;
|
|||
using CodeImp.DoomBuilder.Compilers;
|
||||
using CodeImp.DoomBuilder.ZDoom.Scripting;
|
||||
using ScintillaNET;
|
||||
using System.Text;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -203,6 +204,44 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
// This compiles the script
|
||||
public virtual void Compile() { }
|
||||
|
||||
// [ZZ] this removes trailing whitespace from every line
|
||||
protected void RemoveTrailingWhitespace()
|
||||
{
|
||||
// after changing the contents, selection should stay on the same line, and just move to the end of that line if it was on the trailing space.
|
||||
int selectionStart = editor.SelectionStart;
|
||||
int selectionEnd = editor.SelectionEnd;
|
||||
|
||||
int offset = 0;
|
||||
string text = editor.Text;
|
||||
string[] atext = text.Split(new char[] { '\n' });
|
||||
for (int i = 0; i < atext.Length; i++)
|
||||
{
|
||||
string oldtext = atext[i];
|
||||
string newtext = oldtext.TrimEnd();
|
||||
int lendiff = oldtext.Length - newtext.Length;
|
||||
|
||||
bool selectioninline1 = selectionStart >= offset && selectionStart < offset + oldtext.Length;
|
||||
bool selectioninline2 = selectionEnd >= offset && selectionEnd < offset + oldtext.Length;
|
||||
|
||||
if (selectioninline1 && selectionStart > offset + newtext.Length)
|
||||
selectionStart = offset + newtext.Length;
|
||||
|
||||
if (selectioninline2 && selectionEnd > offset + newtext.Length)
|
||||
selectionEnd = offset + newtext.Length;
|
||||
|
||||
atext[i] = newtext;
|
||||
offset += newtext.Length + 1; // include \n
|
||||
if (selectionStart > offset)
|
||||
selectionStart -= lendiff;
|
||||
if (selectionEnd > offset)
|
||||
selectionEnd -= lendiff;
|
||||
}
|
||||
|
||||
editor.Text = string.Join("\n", atext);
|
||||
editor.SelectionStart = selectionStart;
|
||||
editor.SelectionEnd = selectionEnd;
|
||||
}
|
||||
|
||||
// This saves the document (used for both explicit and implicit)
|
||||
// Return true when successfully saved
|
||||
public virtual bool Save()
|
||||
|
|
|
@ -104,7 +104,10 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
// Return true when successfully saved
|
||||
public override bool Save()
|
||||
{
|
||||
try
|
||||
// [ZZ] remove trailing whitespace
|
||||
RemoveTrailingWhitespace();
|
||||
|
||||
try
|
||||
{
|
||||
// Write the file
|
||||
File.WriteAllBytes(filepathname, editor.GetText());
|
||||
|
|
|
@ -108,6 +108,9 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
// Implicit save
|
||||
public override bool Save()
|
||||
{
|
||||
// [ZZ] remove trailing whitespace
|
||||
RemoveTrailingWhitespace();
|
||||
|
||||
// Store the lump data
|
||||
MemoryStream stream = new MemoryStream(editor.GetText());
|
||||
General.Map.SetLumpData(lumpname, stream);
|
||||
|
|
|
@ -95,8 +95,11 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
{
|
||||
if(source.IsReadOnly) return false;
|
||||
|
||||
// Find lump, check it's hash
|
||||
bool dosave = true;
|
||||
// [ZZ] remove trailing whitespace
|
||||
RemoveTrailingWhitespace();
|
||||
|
||||
// Find lump, check it's hash
|
||||
bool dosave = true;
|
||||
DataReader reader = source.Resource;
|
||||
// reload the reader
|
||||
bool wasReadOnly = reader.IsReadOnly;
|
||||
|
|
|
@ -30,6 +30,6 @@ using CodeImp.DoomBuilder;
|
|||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.3.0.2903")]
|
||||
[assembly: AssemblyVersion("2.3.0.2904")]
|
||||
[assembly: NeutralResourcesLanguageAttribute("en")]
|
||||
[assembly: AssemblyHash("4a79c74")]
|
||||
[assembly: AssemblyHash("bd00eef")]
|
||||
|
|
|
@ -29,5 +29,5 @@ using System.Resources;
|
|||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.3.0.2903")]
|
||||
[assembly: AssemblyVersion("2.3.0.2904")]
|
||||
[assembly: NeutralResourcesLanguageAttribute("en")]
|
||||
|
|
Loading…
Reference in a new issue