diff --git a/trunk/EditForm.cs b/trunk/EditForm.cs index 4a01e13..7a39c24 100644 --- a/trunk/EditForm.cs +++ b/trunk/EditForm.cs @@ -45,6 +45,7 @@ using System.Text; using System.Windows.Forms; using LSLEditor.Docking; using LSLEditor.Helpers; +using System.Collections.Generic; namespace LSLEditor { @@ -52,7 +53,9 @@ namespace LSLEditor { public RuntimeConsole runtime; - private string m_FullPathName; + public List verboseQueue = new List(); + + private string m_FullPathName; private Guid m_Guid; // private bool sOutline = true; public LSLEditorForm parent; @@ -180,13 +183,29 @@ namespace LSLEditor void TextBox_OnDirtyChanged(object sender, EventArgs e) { - this.Text = this.ScriptName; - if (this.numberedTextBoxUC1.TextBox.Dirty) { - this.Text = this.Text.Trim() + "* "; - } else { - this.Text = this.Text.Trim() + " "; - } - TabPage tabPage = this.Tag as TabPage; + if(this.Text == null || this.ScriptName == null) + { + this.Text = this.ScriptName; + } + if (LSLIPathHelper.GetExpandedTabName(this.ScriptName) == this.Text) + { + if (this.numberedTextBoxUC1.TextBox.Dirty) + { + this.Text = this.Text.Trim() + "* "; + + } + } + else + { + this.Text = this.ScriptName; + if (this.numberedTextBoxUC1.TextBox.Dirty) { + this.Text = this.Text.Trim() + "* "; + } else { + this.Text = this.Text.Trim() + " "; + } + } + + TabPage tabPage = this.Tag as TabPage; if (tabPage != null) { tabPage.Text = this.Text; } @@ -307,30 +326,68 @@ namespace LSLEditor public void SaveCurrentFile(string strPath) { - this.FullPathName = strPath; - Encoding encodeAs = this.encodedAs; - if (this.IsScript && encodeAs == null) { - switch (Properties.Settings.Default.OutputFormat) { - case "UTF8": - encodeAs = Encoding.UTF8; - break; - case "Unicode": - encodeAs = Encoding.Unicode; - break; - case "BigEndianUnicode": - encodeAs = Encoding.BigEndianUnicode; - break; - default: - encodeAs = Encoding.Default; - break; - } - } else if (encodeAs == null) { - encodeAs = Encoding.UTF8; - } + // Check if this is an expanded.lsl + if (!LSLIPathHelper.IsExpandedLSL(strPath)) + { + this.FullPathName = strPath; + Encoding encodeAs = this.encodedAs; + if (this.IsScript && encodeAs == null) + { + switch (Properties.Settings.Default.OutputFormat) + { + case "UTF8": + encodeAs = Encoding.UTF8; + break; + case "Unicode": + encodeAs = Encoding.Unicode; + break; + case "BigEndianUnicode": + encodeAs = Encoding.BigEndianUnicode; + break; + default: + encodeAs = Encoding.Default; + break; + } + } + else if (encodeAs == null) + { + encodeAs = Encoding.UTF8; + } - this.numberedTextBoxUC1.TextBox.SaveCurrentFile(strPath, encodeAs); - this.encodedAs = encodeAs; - } + this.numberedTextBoxUC1.TextBox.SaveCurrentFile(strPath, encodeAs); + this.encodedAs = encodeAs; + + } else if (LSLIPathHelper.IsExpandedLSL(strPath)) + { + string LSLIfilePath = LSLIPathHelper.CreateCollapsedPathAndScriptName(strPath); + // Check if an LSLI version of this script exists + if (File.Exists(LSLIfilePath)) + { + // Save the LSLI file as well + File.WriteAllText(LSLIfilePath, LSLIConverter.CollapseToLSLI(this.numberedTextBoxUC1.TextBox.Text)); + EditForm form = null; + + // If it's currently open, then refresh it + for (int i = 0; i < Application.OpenForms.Count; i++) + { + Form openForm = Application.OpenForms[i]; + string filename = LSLIPathHelper.TrimStarsAndWhiteSpace(openForm.Text); + if (filename == Path.GetFileName(LSLIfilePath)) + { + form = (EditForm)openForm; + } + } + + if (form != null && form.Enabled) + { + parent.OpenFile(LSLIfilePath, Guid.NewGuid(), true); + form.Close(); + } + } + this.numberedTextBoxUC1.TextBox.Dirty = false; + this.Text = LSLIPathHelper.GetExpandedTabName(strPath); + } + } public void SaveCurrentFile() { @@ -397,12 +454,26 @@ namespace LSLEditor // for disposing this.components.Add(runtime); + foreach (string message in verboseQueue) + { + runtime.VerboseConsole(message); + + if (message.StartsWith("Error: ")) + { + StopCompiler(); + this.tabControl1.SelectedIndex = 0; + verboseQueue = new List(); + return false; + } + } + if (!runtime.Compile(this)) { this.tabControl1.SelectedIndex = 0; return false; } - TabPage tabPage = new TabPage("Debug"); + + TabPage tabPage = new TabPage("Debug"); tabPage.Controls.Add(runtime); this.tabControl1.TabPages.Add(tabPage); this.tabControl1.SelectedIndex = 1; @@ -422,7 +493,7 @@ namespace LSLEditor string lsl = SourceCode; // If it is LSLI, it needs to import scripts first, before it recognizes imported functions - if (LSLIConverter.IsLSLI(this.FullPathName)) + if (LSLIPathHelper.IsLSLI(this.FullPathName)) { LSLIConverter converter = new LSLIConverter(); lsl = converter.ExpandToLSL(this); diff --git a/trunk/Helpers/LSLIConverter.cs b/trunk/Helpers/LSLIConverter.cs index ca0564e..a100580 100644 --- a/trunk/Helpers/LSLIConverter.cs +++ b/trunk/Helpers/LSLIConverter.cs @@ -42,6 +42,7 @@ using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; +using System.Windows.Forms; namespace LSLEditor.Helpers { @@ -50,120 +51,24 @@ namespace LSLEditor.Helpers private EditForm editForm; private const string BEGIN = "//@BEGIN"; private const string END = "//@END"; - private static List validExtensions = new List() { "lsl", "lsli", ".lsl", ".lsli" }; + private static List validExtensions = new List() { "lsl", "lsli", ".lsl", ".lsli" }; // TODO: Optimize dit... public const string EXPANDED_SUBEXT = ".expanded"; public const string LSL_EXT = ".lsl"; public const string LSLI_EXT = ".lsli"; - - // NEW INCLUDE REGEX MATCHES ONLY FIRST OCCURENCE OF LINE ( OLD: ([\n]|^)+//@include\\(\".*?\"\\)(\\s\\w)? ) - // LAST NEW: ([\n]|^)+//@include\\(\".*?\"\\)(\\s)? - private const string INCLUDE_REGEX = "(\n|^)//@include\\(\".*?\"\\)"; // EVEN MORE SIMPLIFIED - private const string BEGIN_REGEX = "(\n|^)//@BEGIN"; // OLD: (\n|^)+//@BEGIN(\\s)*(\r|$) - private const string END_REGEX = "(\n|^)//@END"; //OLD: ([\n]|^)+//@END(\\s)*(\r|$) + + private const string INCLUDE_REGEX = "(\n|^)//@include\\(\".*?\"\\)"; + private const string BEGIN_REGEX = "(\n|^)" + BEGIN; //"(\n|^)//@BEGIN" + private const string END_REGEX = "(\n|^)" + END; private List implementedIncludes = new List(); + private int includeDepth = 0; public LSLIConverter() { } - /// - /// Checks if a filename is LSLI - /// - /// - /// - public static bool IsLSLI(string fileName) - { - return GetExtension(fileName) == LSLI_EXT; - } - - /// - /// Creates a new path and name from the original path and name based on the editForm. - /// E.g. turns path/to/file.lsli into path/to/file.expanded.lsl - /// - /// - public string CreateExpandedPathAndScriptName() - { - return RemoveExtension(editForm.FullPathName) + EXPANDED_SUBEXT + LSL_EXT; - } - - /// - /// Creates an expanded scriptname out of the current scriptname. - /// - /// - public string CreateExpandedScriptName(string filename = null) - { - string nameExpanded = ""; - if (filename != null) - { - nameExpanded = RemoveExtension(filename) + EXPANDED_SUBEXT + LSL_EXT; - } else - { - nameExpanded = RemoveExtension(editForm.Text) + EXPANDED_SUBEXT + LSL_EXT; - } - - nameExpanded = nameExpanded.IndexOf('*') > -1 ? nameExpanded.Remove(nameExpanded.IndexOf('*'), 1) : nameExpanded; - return nameExpanded; - } - - /// - /// Creates a new path and name from the original path and name based on the editForm. - /// E.g. turns path/to/file.expanded.lsl into path/to/file.lsli - /// - /// - public string CreateCollapsedPathAndScriptName() - { - return RemoveExtension(editForm.FullPathName) + LSLI_EXT; - } - - /// - /// Creates a LSLI scriptname out of the current scriptname. - /// - /// - public string CreateCollapsedScriptName() - { - string nameExpanded = RemoveExtension(editForm.Text) + LSLI_EXT; - nameExpanded = nameExpanded.IndexOf('*') > -1 ? nameExpanded.Remove(nameExpanded.IndexOf('*'), 1) : nameExpanded; - return nameExpanded; - } - - /// - /// Gets the extension from a string, includes '.' - /// Only returns the last extension - /// Returns empty string if the extension cannot be found - /// - /// - /// - private static string GetExtension(string filename) - { - int lastIndexOfDirectorySeperator = -1; - - // If '.' after last index of \\ or / - if (filename.Contains('/') || filename.Contains('\\')) - { - lastIndexOfDirectorySeperator = filename.LastIndexOf('/') > filename.LastIndexOf('\\') ? filename.LastIndexOf('/') : filename.LastIndexOf('\\'); - } - if(lastIndexOfDirectorySeperator != -1 && filename.Contains('.') && lastIndexOfDirectorySeperator < filename.LastIndexOf('.')) - { - return filename.Substring(filename.LastIndexOf('.')).TrimEnd(' '); - } - - return ""; - } - - /// - /// Removes the extension and possible expanded subextension from a filename - /// - /// - /// - private static string RemoveExtension(string filename) - { - filename = filename.Contains(EXPANDED_SUBEXT) ? filename.Replace(EXPANDED_SUBEXT, "") : filename; - return filename.Remove(filename.LastIndexOf(GetExtension(filename))); - } - /// /// Searches for a file with one of the validExtensions based on a name or path. /// @@ -178,7 +83,7 @@ namespace LSLEditor.Helpers return file; } - if (GetExtension(file) == "") + if (Path.GetExtension(file) == "") { List extensions = validExtensions.Where(e => e[0] == '.').ToList(); string pFile = ""; @@ -227,6 +132,21 @@ namespace LSLEditor.Helpers return relativePath; } + /// + /// This is a hack to get the correct line, since problems arose in WriteAfterLine when inserting index-based + /// + /// + /// + private int GetCorrectIndexOfLine(string lineBefore, string context) // TODO + { + //int correctIndex = -1; + //if(lineBefore.Trim('\n') == BEGIN) + //{ + // correctIndex = context.Where(l => l).LastIndexOf(lineBefore); + //} + return context.LastIndexOf(lineBefore); + } + /// /// Creates a new line in the context after another line /// @@ -234,10 +154,11 @@ namespace LSLEditor.Helpers /// /// /// Context with the new line - private StringBuilder WriteAfterLine(StringBuilder context, string newLine, string lineBefore) + private StringBuilder WriteAfterLine(StringBuilder context, string newLine, string lineBefore) // TODO: HIJ MOET KIJKEN NAAR DE INDEX VAN LINEBEFORE, NIET ZELF DE INDEX OPZOEKEN { string ctx = context.ToString(); - int lastIndexOfLineBefore = ctx.LastIndexOf(lineBefore); + //int lastIndexOfLineBefore = ctx.LastIndexOf(lineBefore); + int lastIndexOfLineBefore = GetCorrectIndexOfLine(lineBefore, ctx); int includeIndex = lastIndexOfLineBefore + lineBefore.Length; string hasSeperator = lineBefore.Substring(lineBefore.Length - 1, 1); @@ -253,36 +174,75 @@ namespace LSLEditor.Helpers } context.Insert(includeIndex, newLine); - string test = context.ToString(); + string test = context.ToString(); // Debug only return context; } - + + /// + /// Creates a new line in the context after a specified index + /// + /// + /// + /// + /// Context with the new line + //private StringBuilder WriteAfterLine(StringBuilder context, string newLine, int indexOfNewLine) // DEZE IS BETER, MAAR IN PRAKTIJK WERKT NIET... + //{ + // string ctx = context.ToString(); + // int includeIndex = indexOfNewLine; + + // string hasSeperator = context.ToString().Substring(indexOfNewLine - 1, 1); + // if (hasSeperator != "\n") + // { + // newLine = "\n" + newLine; + // } + + // hasSeperator = newLine.Substring(newLine.Length - 1, 1); + // if (hasSeperator != "\n") + // { + // newLine += "\n"; + // } + + // context.Insert(includeIndex, newLine); + // string test = context.ToString(); + // return context; + //} + /// /// Imports scripts from //@include statements /// /// Sourcecode /// Path of the source code of the script /// Sourcecode with imported scripts - private string ImportScripts(string strC, string pathOfScript) + private string ImportScripts(string strC, string pathOfScript) // TODO: Lange functie, kan ik deze opsplitten? { - if(GetExtension(pathOfScript).ToLower() != LSLI_EXT) + if(!LSLIPathHelper.IsLSLI(pathOfScript)) { // If it's not LSLI extension it can't import a script return strC; } + StringBuilder sb = new StringBuilder(strC); MatchCollection mIncludes = Regex.Matches(strC, INCLUDE_REGEX); // Find includes foreach (Match m in mIncludes) { + if (this.includeDepth == 0) + { + this.implementedIncludes = new List(); + } + includeDepth++; + string contentAfterMatchValue = strC.Substring(m.Index + m.Value.Length); int indexOfNewLine = contentAfterMatchValue.IndexOf('\n') + m.Index + m.Value.Length + 1; // Index of the first occurence of \n after this match string line = strC.Substring(m.Index, indexOfNewLine - m.Index); // Get full line - string pathOfInclude = Regex.Match(line, "\".*?\"").Value.Trim('"'); - string ext = GetExtension(pathOfInclude).ToLower(); + int lineNumber = strC.Take(indexOfNewLine - 1).Count(c => c == '\n') + 1; - if ((validExtensions.Contains(ext) || ext == "") && !this.CreateExpandedScriptName(pathOfScript).Contains(pathOfInclude) + string pathOfIncludeOriginal = Regex.Match(line, "\".*?\"").Value.Trim('"'); + string pathOfInclude = pathOfIncludeOriginal; + string ext = Path.GetExtension(pathOfInclude).ToLower(); + + if ((validExtensions.Contains(ext) || ext == "") && !LSLIPathHelper.CreateExpandedScriptName(pathOfScript).Contains(pathOfInclude) && !pathOfScript.Contains(pathOfInclude)) { // If path is relative @@ -292,6 +252,7 @@ namespace LSLEditor.Helpers } pathOfInclude = SearchFile(pathOfInclude); + if (pathOfInclude != "" && !this.implementedIncludes.Contains(Path.GetFullPath(pathOfInclude))) { sb = this.WriteAfterLine(sb, BEGIN, line); @@ -302,6 +263,7 @@ namespace LSLEditor.Helpers { this.implementedIncludes.Add(Path.GetFullPath(pathOfInclude)); string scriptRaw = sr.ReadToEnd(); + scriptRaw = scriptRaw.Replace("\n", "\n\t"); // If there are includes in the included script if (Regex.IsMatch(scriptRaw, INCLUDE_REGEX)) @@ -318,6 +280,34 @@ namespace LSLEditor.Helpers this.WriteAfterLine(sb, END, script); } + else if (pathOfInclude != "" && this.implementedIncludes.Contains(Path.GetFullPath(pathOfInclude))) + { + string message = "Error: Recursive include loop detected: \"" + Path.GetFullPath(pathOfInclude) + + "\". In script \"" + + Path.GetFileName(pathOfScript) + "\". Line " + lineNumber + "."; + + if (!editForm.verboseQueue.Contains(message)) + { + MessageBox.Show(message, "Oops...", MessageBoxButtons.OK, MessageBoxIcon.Error); + editForm.verboseQueue.Add(message); + } + } else + { + string correctPath = Path.GetFullPath(GetRelativePath(pathOfScript, Environment.CurrentDirectory) + pathOfIncludeOriginal); + string message = "Error: Unable to find file \"" + correctPath + + "\". In script \"" + Path.GetFileName(pathOfScript) + "\". Line " + lineNumber + "."; + + if (!editForm.verboseQueue.Contains(message)) + { + MessageBox.Show(message, "Oops...", MessageBoxButtons.OK, MessageBoxIcon.Error); + editForm.verboseQueue.Add(message); + } + } + } + includeDepth--; + if(this.implementedIncludes.Count > 0) + { + this.implementedIncludes.Remove(this.implementedIncludes.Last()); } } @@ -329,16 +319,15 @@ namespace LSLEditor.Helpers /// /// Sourcecode /// Sourcecode without imported scripts - private string RemoveScripts(string strC) // TODO: DIT VALT MISS NOG TE OPTIMALISEREN MET STRINGBUILDER IPV STRING + private static string RemoveScripts(string strC) { - //StringBuilder sb = new StringBuilder(strC); - - string result = strC; + StringBuilder sb = new StringBuilder(strC); + int indexOfFirstBeginStatement = -1; uint depth = 0; int readIndex = 0; - using(StringReader sr = new StringReader(strC)) + using (StringReader sr = new StringReader(strC)) { int amountOfLines = strC.Split('\n').Length; for (int i = 1; i < amountOfLines; i++) @@ -347,7 +336,7 @@ namespace LSLEditor.Helpers if (Regex.IsMatch(line, BEGIN_REGEX)) { - if(depth == 0) + if (depth == 0) { indexOfFirstBeginStatement = readIndex; } @@ -362,7 +351,7 @@ namespace LSLEditor.Helpers if (depth == 0) { - result = result.Remove(indexOfFirstBeginStatement, (readIndex - indexOfFirstBeginStatement)); + sb.Remove(indexOfFirstBeginStatement, (readIndex - indexOfFirstBeginStatement)); readIndex -= readIndex - indexOfFirstBeginStatement; indexOfFirstBeginStatement = -1; } @@ -370,7 +359,7 @@ namespace LSLEditor.Helpers } } - return result; + return sb.ToString(); } /// @@ -378,11 +367,37 @@ namespace LSLEditor.Helpers /// /// /// LSLI - public string CollapseToLSLI(EditForm editform) + public static string CollapseToLSLI(string source) + { + string sourceCode = RemoveScripts(source); + return sourceCode; + } + + /// + /// Call this to collapse LSL to LSLI + /// + /// + /// LSLI + public string CollapseToLSLIFromEditform(EditForm editform) { this.editForm = editform; - string sourceCode = RemoveScripts(editForm.SourceCode); - return sourceCode; + return CollapseToLSLI(editform.SourceCode); + } + + /// + /// Call this to collapse LSL to LSLI + /// + /// + /// LSLI + public static string CollapseToLSLIFromPath(string path) + { + string sourceCode = ""; + using(StreamReader sr = new StreamReader(path)) + { + sourceCode = sr.ReadToEnd(); + } + + return CollapseToLSLI(sourceCode); } /// diff --git a/trunk/Helpers/LSLIPathHelper.cs b/trunk/Helpers/LSLIPathHelper.cs new file mode 100644 index 0000000..e9aebd7 --- /dev/null +++ b/trunk/Helpers/LSLIPathHelper.cs @@ -0,0 +1,192 @@ +// +// ORIGINAL CODE BASE IS Copyright (C) 2006-2010 by Alphons van der Heijden. +// The code was donated on 2010-04-28 by Alphons van der Heijden to Brandon 'Dimentox Travanti' Husbands & +// Malcolm J. Kudra, who in turn License under the GPLv2 in agreement with Alphons van der Heijden's wishes. +// +// The community would like to thank Alphons for all of his hard work, blood sweat and tears. Without his work +// the community would be stuck with crappy editors. +// +// The source code in this file ("Source Code") is provided by The LSLEditor Group to you under the terms of the GNU +// General Public License, version 2.0 ("GPL"), unless you have obtained a separate licensing agreement ("Other +// License"), formally executed by you and The LSLEditor Group. +// Terms of the GPL can be found in the gplv2.txt document. +// +// GPLv2 Header +// ************ +// LSLEditor, a External editor for the LSL Language. +// Copyright (C) 2010 The LSLEditor Group. +// +// This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any +// later version. +// +// 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. +// +// You should have received a copy of the GNU General Public License along with this program; if not, write to the Free +// Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// ******************************************************************************************************************** +// The above copyright notice and this permission notice shall be included in copies or substantial portions of the +// Software. +// ******************************************************************************************************************** +// +// +// +// This class is used to help with paths and LSLI files. +// + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace LSLEditor.Helpers +{ + static class LSLIPathHelper + { + + /// + /// Checks if a filename is LSLI + /// + /// + /// + public static bool IsLSLI(string filename) + { + filename = TrimStarsAndWhiteSpace(filename); + return Path.GetExtension(filename).ToLower() == LSLIConverter.LSLI_EXT; + } + + /// + /// Checks if a filename is an expanded LSL file + /// + /// + /// + public static bool IsExpandedLSL(string filename) + { + filename = TrimStarsAndWhiteSpace(filename); + return filename.EndsWith(LSLIConverter.EXPANDED_SUBEXT + LSLIConverter.LSL_EXT); + } + + /// + /// Creates a LSLI scriptname from a filename. + /// + /// + public static string CreateCollapsedScriptName(string filename) + { + string nameCollapsed = RemoveDotInFrontOfFilename(Path.GetFileNameWithoutExtension(RemoveExpandedSubExtension(filename)) + LSLIConverter.LSLI_EXT); + return nameCollapsed; + } + + private static string RemoveExtension(string filename) + { + //filename = filename.Contains(LSLIConverter.EXPANDED_SUBEXT) ? filename.Replace(LSLIConverter.EXPANDED_SUBEXT, "") : filename; // Is nu een aparte functie voor + filename = TrimStarsAndWhiteSpace(filename.Remove(filename.LastIndexOf(Path.GetExtension(filename)))); + return filename; + } + + public static string RemoveExpandedSubExtension(string filename) + { + if (filename.Contains(LSLIConverter.EXPANDED_SUBEXT)) + { + return filename.Replace(LSLIConverter.EXPANDED_SUBEXT, ""); + } + + return filename; + } + + /// + /// Creates a new path and name from the given filename. + /// E.g. turns path/to/file.expanded.lsl into path/to/file.lsli + /// + /// + public static string CreateCollapsedPathAndScriptName(string filename) + { + return RemoveDotInFrontOfFilename(RemoveExtension(RemoveExpandedSubExtension(filename)) + LSLIConverter.LSLI_EXT); + } + + /// + /// Creates a new path and name from the original path and name based on the editForm. + /// E.g. turns path/to/file.lsli into path/to/.file.expanded.lsl + /// + /// + public static string CreateExpandedPathAndScriptName(string path) + { + return PutDotInFrontOfFilename(RemoveExtension(path) + LSLIConverter.EXPANDED_SUBEXT + LSLIConverter.LSL_EXT); + } + + /// + /// Creates an expanded scriptname out of the given filename. + /// + /// + public static string CreateExpandedScriptName(string filename) + { + string nameExpanded = ""; + if (filename != null) + { + nameExpanded = Path.GetFileNameWithoutExtension(filename) + LSLIConverter.EXPANDED_SUBEXT + LSLIConverter.LSL_EXT; + } + + return PutDotInFrontOfFilename(TrimStarsAndWhiteSpace(nameExpanded)); + } + + private static string PutDotInFrontOfFilename(string filename) + { + int afterLastIndexOfSeperator = (filename.LastIndexOf('\\') > filename.LastIndexOf('/') ? filename.LastIndexOf('\\') : filename.LastIndexOf('/')) + 1; + + if (filename.Substring(afterLastIndexOfSeperator, 1) == ".") + { + return filename; + } + + filename = filename.Insert(afterLastIndexOfSeperator, "."); + return filename; + } + + private static string RemoveDotInFrontOfFilename(string filename) + { + int afterLastIndexOfSeperator = (filename.LastIndexOf('\\') > filename.LastIndexOf('/') ? filename.LastIndexOf('\\') : filename.LastIndexOf('/')) + 1; + + if (filename.Substring(afterLastIndexOfSeperator, 1) != ".") + { + return filename; + } + + filename = filename.Remove(afterLastIndexOfSeperator, 1); + return filename; + } + + /// + /// "Hides" the file in the folder + /// + /// + public static void HideFile(string path) + { + File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden); + } + + /// + /// First checks if the file exists, then deletes it + /// + /// + public static void DeleteFile(string path) + { + if (File.Exists(path)) + { + File.Delete(path); + } + } + + public static string TrimStarsAndWhiteSpace(string str) + { + return str.Trim(' ').TrimEnd('*'); + } + + public static string GetExpandedTabName(string path) + { + if (path == null) return ""; + return RemoveDotInFrontOfFilename(Path.GetFileNameWithoutExtension(RemoveExpandedSubExtension(path)) + LSLIConverter.LSLI_EXT + " (Expanded LSL)"); + } + } +} diff --git a/trunk/LSLEditorForm.Designer.cs b/trunk/LSLEditorForm.Designer.cs index a6b48cd..d6d9c08 100644 --- a/trunk/LSLEditorForm.Designer.cs +++ b/trunk/LSLEditorForm.Designer.cs @@ -146,6 +146,7 @@ namespace LSLEditor this.pageSetupDialog1 = new System.Windows.Forms.PageSetupDialog(); this.openSolutionFilesDialog = new System.Windows.Forms.OpenFileDialog(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); + this.viewLSLIToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dockPanel = new LSLEditor.Docking.DockPanel(); this.menuStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout(); @@ -468,7 +469,8 @@ namespace LSLEditor this.advancedToolStripMenuItem, this.toolStripSeparator10, this.CollapseToLSLIToolStripMenuItem, - this.expandToLSLToolStripMenuItem}); + this.expandToLSLToolStripMenuItem, + this.viewLSLIToolStripMenuItem}); this.editStripMenuItem.Name = "editStripMenuItem"; this.editStripMenuItem.Size = new System.Drawing.Size(39, 20); this.editStripMenuItem.Text = "Edit"; @@ -939,6 +941,14 @@ namespace LSLEditor // this.openSolutionFilesDialog.FileName = "openFileDialog2"; // + // viewLSLIToolStripMenuItem + // + this.viewLSLIToolStripMenuItem.Name = "viewLSLIToolStripMenuItem"; + this.viewLSLIToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F12; + this.viewLSLIToolStripMenuItem.Size = new System.Drawing.Size(225, 22); + this.viewLSLIToolStripMenuItem.Text = "View LSLI"; + this.viewLSLIToolStripMenuItem.Click += new System.EventHandler(this.viewLSLIToolStripMenuItem_Click); + // // dockPanel // this.dockPanel.ActiveAutoHideContent = null; @@ -1126,5 +1136,6 @@ namespace LSLEditor private System.Windows.Forms.ToolStripSeparator toolStripSeparator10; private System.Windows.Forms.ToolStripMenuItem CollapseToLSLIToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem expandToLSLToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem viewLSLIToolStripMenuItem; } } \ No newline at end of file diff --git a/trunk/LSLEditorForm.cs b/trunk/LSLEditorForm.cs index bf227e7..36925a3 100644 --- a/trunk/LSLEditorForm.cs +++ b/trunk/LSLEditorForm.cs @@ -82,8 +82,7 @@ namespace LSLEditor private Browser browser; private SimulatorConsole SimulatorConsole; - - + public bool CancelClosing = false; public Solution.SolutionExplorer m_SolutionExplorer; @@ -417,6 +416,11 @@ namespace LSLEditor UpdateRecentFileList(strPath); + if(Helpers.LSLIPathHelper.IsExpandedLSL(editForm.Text)) + { + editForm.Text = Helpers.LSLIPathHelper.GetExpandedTabName(editForm.Text); + } + return editForm; } @@ -1146,6 +1150,7 @@ namespace LSLEditor this.SimulatorConsole = new SimulatorConsole(this.SolutionExplorer, this.Children); this.SimulatorConsole.Show(dockPanel); + //TODO: Show Simulator Console somewhere //this.panel1.Controls.Clear(); //this.panel1.Controls.Add(this.SimulatorConsole); @@ -1800,35 +1805,54 @@ namespace LSLEditor browser.ShowWebBrowser("LSLEditor QA", Properties.Settings.Default.qasite); } + /// + /// Gets a form based on it's form.Text property. + /// + /// + /// Returns null if not found + private Form GetForm(string formName) + { + EditForm desirableForm = null; + for (int i = 0; i < Children.Length; i++) //Application.OpenForms + { + Form form = Children[i]; + if (form.Text.TrimEnd(' ') == formName) + { + desirableForm = (EditForm)form; + } + } + + return desirableForm; + } + private void expandToLSLToolStripMenuItem_Click(object sender, EventArgs e) { EditForm editForm = this.ActiveMdiForm as EditForm; - if (editForm != null && editForm.FullPathName.IndexOf(Helpers.LSLIConverter.LSLI_EXT) > -1) + + if (editForm != null && Helpers.LSLIPathHelper.IsLSLI(editForm.Text)) { Helpers.LSLIConverter converter = new Helpers.LSLIConverter(); string lsl = converter.ExpandToLSL(editForm); - string file = converter.CreateExpandedPathAndScriptName(); + string file = Helpers.LSLIPathHelper.CreateExpandedPathAndScriptName(editForm.FullPathName); + + editForm.Close(); + + Helpers.LSLIPathHelper.DeleteFile(file); using (StreamWriter sw = new StreamWriter(file)) { sw.Write(lsl); } - - EditForm expandedForm = null; - for (int i = 0; i < Application.OpenForms.Count; i++) - { - Form form = Application.OpenForms[i]; - if (form.Text.TrimEnd(' ') == converter.CreateExpandedScriptName()) - { - expandedForm = (EditForm)form; - } - } + + Helpers.LSLIPathHelper.HideFile(file); + + EditForm expandedForm = (EditForm)GetForm(Helpers.LSLIPathHelper.CreateExpandedScriptName(Path.GetFileName(file))); if (expandedForm != null) { expandedForm.Close(); } - editForm.Close(); + OpenFile(file); } } @@ -1836,36 +1860,64 @@ namespace LSLEditor private void CollapseToLSLIToolStripMenuItem_Click(object sender, EventArgs e) { EditForm editForm = this.ActiveMdiForm as EditForm; - - // NOTE: This checks only if there's an LSL file, not if there's a extended subextension - if (editForm != null && editForm.FullPathName.IndexOf(Helpers.LSLIConverter.LSL_EXT) > -1) + + if (editForm != null && Helpers.LSLIPathHelper.IsExpandedLSL(editForm.ScriptName)) { Helpers.LSLIConverter converter = new Helpers.LSLIConverter(); - string lsli = converter.CollapseToLSLI(editForm); - string file = converter.CreateCollapsedPathAndScriptName(); + + Helpers.LSLIPathHelper.DeleteFile(editForm.FullPathName); + + string lsli = converter.CollapseToLSLIFromEditform(editForm); + string file = Helpers.LSLIPathHelper.CreateCollapsedPathAndScriptName(editForm.FullPathName); + + editForm.Close(); using (StreamWriter sw = new StreamWriter(file)) { sw.Write(lsli); } - - EditForm collapsedForm = null; - for (int i = 0; i < Application.OpenForms.Count; i++) - { - Form form = Application.OpenForms[i]; - if (form.Text.TrimEnd(' ') == converter.CreateCollapsedScriptName()) - { - collapsedForm = (EditForm)form; - } - } + + Form collapsedForm = GetForm(Helpers.LSLIPathHelper.CreateCollapsedScriptName(Path.GetFileName(file))); if (collapsedForm != null) { collapsedForm.Close(); } - editForm.Close(); + OpenFile(file); } } + + private void viewLSLIToolStripMenuItem_Click(object sender, EventArgs e) + { + EditForm editForm = this.ActiveMdiForm as EditForm; + + if(editForm != null) + { + if (Helpers.LSLIPathHelper.IsLSLI(editForm.Text)) + { + return; + } + + string pathOfLSLI = Helpers.LSLIPathHelper.CreateCollapsedPathAndScriptName(editForm.FullPathName); + + if (File.Exists(pathOfLSLI)) { + Form LSLIform = GetForm(Path.GetFileName(pathOfLSLI)); + + if (LSLIform != null) + { + LSLIform.Close(); + } + + OpenFile(pathOfLSLI); + + GetForm(Path.GetFileName(pathOfLSLI)).Enabled = false; + } + else + { + MessageBox.Show("Error: No related LSLI file found. \n \"" + pathOfLSLI + "\"", "Oops...", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } } } diff --git a/trunk/Properties/AssemblyInfo.cs b/trunk/Properties/AssemblyInfo.cs index ac83f41..0986f63 100644 --- a/trunk/Properties/AssemblyInfo.cs +++ b/trunk/Properties/AssemblyInfo.cs @@ -70,7 +70,7 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: // -[assembly: AssemblyVersion("2.55.0.378")] +[assembly: AssemblyVersion("2.55.0.549")] // // In order to sign your assembly you must specify a key to use. Refer to the @@ -100,4 +100,4 @@ using System.Runtime.InteropServices; [assembly: AssemblyDelaySign(false)] //[assembly: AssemblyKeyName("")] [assembly: ComVisibleAttribute(false)] -[assembly: AssemblyFileVersionAttribute("2.55.0.378")] +[assembly: AssemblyFileVersionAttribute("2.55.0.549")] diff --git a/trunk/RuntimeConsole.cs b/trunk/RuntimeConsole.cs index a778594..2c771a4 100644 --- a/trunk/RuntimeConsole.cs +++ b/trunk/RuntimeConsole.cs @@ -115,31 +115,17 @@ namespace LSLEditor { LSLIConverter lsliConverter = new LSLIConverter(); lsl = lsliConverter.ExpandToLSL(editForm); - string nameExpanded = lsliConverter.CreateExpandedScriptName(); - string path = lsliConverter.CreateExpandedPathAndScriptName(); + string nameExpanded = LSLIPathHelper.CreateExpandedScriptName(editForm.FullPathName); + string path = LSLIPathHelper.CreateExpandedPathAndScriptName(editForm.FullPathName); + + LSLIPathHelper.DeleteFile(path); using (StreamWriter sw = new StreamWriter(path)) { sw.Write(lsl); } - // NOTE: DE EXPANDED LSL WORDT NU IN DE ACHTERGROND GERUNT EN NIET MEER LATEN ZIEN OP 2 TABS - //EditForm expandedForm = null; - //for (int i = 0; i < Application.OpenForms.Count; i++) - //{ - // Form form = Application.OpenForms[i]; - // if(form.Text.TrimEnd(' ') == nameExpanded) - // { - // expandedForm = (EditForm)form; - // } - //} - - //// Open the expanded file if not already open - //if(expandedForm == null) - //{ - // mainForm.OpenFile(path, Guid.NewGuid(), true); // TODO: MOET AUTOMATISCH GAAN RUNNEN - //} - + LSLIPathHelper.HideFile(path); } CSharpCode = MakeSharp(editForm.ConfLSL, lsl); diff --git a/trunk/lsleditor.csproj b/trunk/lsleditor.csproj index 1e0d923..37b9e6e 100644 --- a/trunk/lsleditor.csproj +++ b/trunk/lsleditor.csproj @@ -336,6 +336,7 @@ true + true