diff --git a/trunk/EditForm.Designer.cs b/trunk/EditForm.Designer.cs index c3be10c..948ca05 100644 --- a/trunk/EditForm.Designer.cs +++ b/trunk/EditForm.Designer.cs @@ -31,8 +31,8 @@ namespace LSLEditor this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); - this.tvOutline = new System.Windows.Forms.TreeView(); this.numberedTextBoxUC1 = new NumberedTextBox.NumberedTextBoxUC(); + this.tvOutline = new System.Windows.Forms.TreeView(); this.tabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); this.splitContainer1.Panel1.SuspendLayout(); @@ -83,18 +83,6 @@ namespace LSLEditor this.splitContainer1.SplitterDistance = 397; this.splitContainer1.TabIndex = 7; // - // tvOutline - // - this.tvOutline.Dock = System.Windows.Forms.DockStyle.Fill; - this.tvOutline.HotTracking = true; - this.tvOutline.Location = new System.Drawing.Point(0, 0); - this.tvOutline.Name = "tvOutline"; - this.tvOutline.Size = new System.Drawing.Size(141, 228); - this.tvOutline.TabIndex = 6; - this.tvOutline.VisibleChanged += new System.EventHandler(this.tvOutline_VisibleChanged); - this.tvOutline.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvOutline_AfterSelect); - this.tvOutline.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tvOutline_NodeMouseClick); - // // numberedTextBoxUC1 // this.numberedTextBoxUC1.Dock = System.Windows.Forms.DockStyle.Fill; @@ -103,12 +91,25 @@ namespace LSLEditor this.numberedTextBoxUC1.Size = new System.Drawing.Size(393, 228); this.numberedTextBoxUC1.TabIndex = 4; // + // tvOutline + // + this.tvOutline.Dock = System.Windows.Forms.DockStyle.Fill; + this.tvOutline.HotTracking = true; + this.tvOutline.Location = new System.Drawing.Point(0, 0); + this.tvOutline.Name = "tvOutline"; + this.tvOutline.Size = new System.Drawing.Size(141, 228); + this.tvOutline.TabIndex = 6; + this.tvOutline.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvOutline_AfterSelect); + this.tvOutline.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tvOutline_NodeMouseClick); + this.tvOutline.VisibleChanged += new System.EventHandler(this.tvOutline_VisibleChanged); + // // EditForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(560, 264); this.Controls.Add(this.tabControl1); + this.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Name = "EditForm"; this.Text = "EditForm"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.EditForm_FormClosing); diff --git a/trunk/EditForm.cs b/trunk/EditForm.cs index 7a39c24..ffd36b8 100644 --- a/trunk/EditForm.cs +++ b/trunk/EditForm.cs @@ -183,6 +183,11 @@ namespace LSLEditor void TextBox_OnDirtyChanged(object sender, EventArgs e) { + if(parent.IsReadOnly(this)) + { + Dirty = false; + return; + } if(this.Text == null || this.ScriptName == null) { this.Text = this.ScriptName; @@ -215,7 +220,7 @@ namespace LSLEditor private void exitToolStripMenuItem_Click(object sender, EventArgs e) { - this.Close(); + this.Close(); } public string FullPathName @@ -538,14 +543,44 @@ namespace LSLEditor { this.parent.CancelClosing = false; if (this.Dirty) { - DialogResult dialogResult = MessageBox.Show(this, @"Save """ + this.ScriptName + @"""?", "File has changed", MessageBoxButtons.YesNoCancel); + string scriptToSave = ScriptName; + if (LSLIPathHelper.IsExpandedLSL(ScriptName)) + { + // Expanded scripts will always be saved as LSLI's + scriptToSave = LSLIPathHelper.CreateCollapsedScriptName(scriptToSave); + } + + DialogResult dialogResult = MessageBox.Show(this, @"Save """ + scriptToSave + @"""?", "File has changed", MessageBoxButtons.YesNoCancel); if (dialogResult == DialogResult.Yes) { e.Cancel = !this.parent.SaveFile(this, false); } else { e.Cancel = (dialogResult == DialogResult.Cancel); - } + } } - this.parent.CancelClosing = e.Cancel; + + if (!e.Cancel) + { + // Close related readonly's if this is an expanded script + if (LSLIPathHelper.IsExpandedLSL(ScriptName)) + { + // Check if a LSLI readonly is open + EditForm readOnlyLSLI = (EditForm)parent.GetForm(Path.GetFileName( + LSLIPathHelper.CreateCollapsedScriptName(ScriptName)) + " (Read Only)"); + + if (readOnlyLSLI != null) + { + readOnlyLSLI.Close(); + } + } + + // Delete expanded file when closing + string expandedFile = LSLIPathHelper.CreateExpandedPathAndScriptName(FullPathName); + if (File.Exists(expandedFile)) + { + File.Delete(expandedFile); + } + } + this.parent.CancelClosing = e.Cancel; } private void disableCompilesyntaxCheckToolStripMenuItem_Click(object sender, EventArgs e) @@ -589,6 +624,6 @@ namespace LSLEditor private void tvOutline_VisibleChanged(object sender, EventArgs e) { this.tvOutline.ExpandAll(); - } - } + } + } } diff --git a/trunk/Helpers/LSLIConverter.cs b/trunk/Helpers/LSLIConverter.cs index 9dea866..d60dc2d 100644 --- a/trunk/Helpers/LSLIConverter.cs +++ b/trunk/Helpers/LSLIConverter.cs @@ -51,15 +51,20 @@ 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" }; // TODO: Optimize dit... + private const string INCLUDE = "//@include"; public const string EXPANDED_SUBEXT = ".expanded"; public const string LSL_EXT = ".lsl"; public const string LSLI_EXT = ".lsli"; + public static List validExtensions = new List() { LSLI_EXT, LSL_EXT }; - private const string INCLUDE_REGEX = "(\\s+|^)//@include\\(\".*?\"\\)";// Eerst was '\\s+' '\n' - private const string BEGIN_REGEX = "(\\s+|^)" + BEGIN; //"(\n|^)//@BEGIN" + private const string INCLUDE_REGEX = "(\n|^)\\s*" + INCLUDE + "\\(\".*?\"\\).*";//"(\\s+|^)" + INCLUDE + "\\(\".*?\"\\)"; + private const string BEGIN_REGEX = "(\\s+|^)" + BEGIN; private const string END_REGEX = "(\\s+|^)" + END; + private const string EMPTY_OR_WHITESPACE_REGEX = "^\\s*$"; + private const string PATH_OF_INCLUDE_REGEX = "\".*?\""; + + private const string EMPTY_SCRIPT = "// Empty script\n"; private List implementedIncludes = new List(); private int includeDepth = 0; @@ -69,73 +74,110 @@ namespace LSLEditor.Helpers } + //private string GetFile(string file) // TODO? + //{ + // if (File.Exists(directory)) + // { + // return file; + // } + // if (Path.GetExtension(file) == "") + // { + // string pFile = ""; + + // foreach (string extension in validExtensions) + // { + // pFile = file + extension; + + // if (File.Exists(pFile)) + // { + // return pFile; + // } + // } + // } + //} + /// - /// Searches for a file with one of the validExtensions based on a name or path. + /// Searches for a file with one of the validExtensions based on a name or path. Also searches in the IncludeDirectories /// /// /// File path private string SearchFile(string file) { - // TODO: Check of settings IncludeFromFolder aanstaat - - if (File.Exists(file)) + // If setting IncludeDirectories is enabled + foreach (string directory in Properties.Settings.Default.IncludeDirectories) { - return file; - } - - if (Path.GetExtension(file) == "") - { - List extensions = validExtensions.Where(e => e[0] == '.').ToList(); - string pFile = ""; - - foreach (string extension in extensions) + string pFile; + if(file.Contains(directory)) { - pFile = file + extension; + pFile = file; + } else + { + pFile = directory + file; + } - if (File.Exists(pFile)) { - return pFile; + if (File.Exists(pFile)) + { + return pFile; + } + + if (Path.GetExtension(file) == "") + { + foreach (string extension in validExtensions) + { + if (file.Contains(directory)) + { + pFile = file + extension; + } + else + { + pFile = directory + file + extension; + } + + if (File.Exists(pFile)) + { + return pFile; + } } } } + // If IncludeDirectories setting is disabled + if (Properties.Settings.Default.IncludeDirectories.Count == 0) + { + if (File.Exists(file)) + { + return file; + } + + if (Path.GetExtension(file) == "") + { + string pFile = ""; + + foreach (string extension in validExtensions) + { + pFile = file + extension; + + if (File.Exists(pFile)) { + return pFile; + } + } + } + } + + return ""; } /// - /// Creates a relative path between two paths + /// Finds all indexes of a value in a string /// - /// The file or folder to create a relative path towards - /// The base folder + /// + /// /// - private string GetRelativePath(string filespec, string folder) - { - filespec = Path.GetFullPath(filespec).ToLower(); - if(validExtensions.Contains(filespec.Substring(filespec.LastIndexOf(".") + 1))) - { - int lastIndexOfSeperator = filespec.LastIndexOf('\\') > filespec.LastIndexOf('/') ? filespec.LastIndexOf('\\') : filespec.LastIndexOf('/'); - filespec = filespec.Remove(lastIndexOfSeperator); - } - Uri pathUri = new Uri(filespec); - - if (!folder.EndsWith(Path.DirectorySeparatorChar.ToString())) - { - folder += Path.DirectorySeparatorChar; - } - Uri folderUri = new Uri(folder); - string relativePath = Uri.UnescapeDataString(folderUri.MakeRelativeUri(pathUri).ToString().Replace('/', Path.DirectorySeparatorChar)); - - if (relativePath.Substring(relativePath.Length - 3) != Path.DirectorySeparatorChar.ToString()) - { - relativePath += Path.DirectorySeparatorChar; - } - - return relativePath; - } - public static List AllIndexesOf(string str, string value) { if (String.IsNullOrEmpty(value)) - throw new ArgumentException("the string to find may not be empty", "value"); + throw new ArgumentException("The string to find may not be empty", "value"); List indexes = new List(); for (int index = 0; ; index += value.Length) { @@ -147,33 +189,43 @@ namespace LSLEditor.Helpers } /// - /// This is a hack to get the correct line, since problems arose in WriteAfterLine when inserting index-based + /// This is a hack to get the correct line, since problems arose in WriteAfterLine when inserting index-based. + /// It checks for each occurance of lineBefore (when it's an include statement) if it has a BEGIN after it. /// /// /// private int GetCorrectIndexOfLine(string lineBefore, string context) { - if (Regex.IsMatch(lineBefore.Trim('\n'), INCLUDE_REGEX) - && lineBefore.Trim('\n').EndsWith(Regex.Match(lineBefore.Trim('\n'), INCLUDE_REGEX).ToString())) // Line before this line is an include statement, that means this is a BEGIN statement + string trimmedLine = Regex.Replace(lineBefore, @"\s+", ""); + string matchString = Regex.Match(trimmedLine, INCLUDE_REGEX).ToString(); + + // Tussen de één na laatste en de laatste moet de include statement staan, of na de laatste + int lastButOneNewLineIndex = lineBefore.TrimEnd('\n').LastIndexOf('\n') > -1 ? lineBefore.TrimEnd('\n').LastIndexOf('\n') : 0; + string lineBeforeAfterLastButOneNewLine = lineBefore.Substring(lastButOneNewLineIndex).TrimEnd('\n'); // Best variable name ever? + + if (Regex.IsMatch(lineBefore.TrimEnd('\n'), INCLUDE_REGEX) + && Regex.IsMatch(lineBeforeAfterLastButOneNewLine, INCLUDE_REGEX)) // Line before this line is an include statement, that means this is a BEGIN statement //lineBefore.TrimEnd('\n').EndsWith(matchString) { // Get all matches with this linebefore List allIndexes = AllIndexesOf(context, lineBefore); - foreach(int index in allIndexes) + foreach (int index in allIndexes) { // Check wether there is already a begin statement - string actualLineBefore = context.Substring(index + lineBefore.Length).Trim('\n'); - if (actualLineBefore.StartsWith(BEGIN)) + string targetText = context.Substring(index + lineBefore.Length); // This is the text after lineBefore + targetText = Regex.Replace(targetText, @"\s+", ""); + + if (targetText.StartsWith(BEGIN)) // If the targetted text starts with BEGIN, then we should keep searching { continue; } else { - return index; + return index; // Found a free spot! Return the index } } } - return context.LastIndexOf(lineBefore); + return context.LastIndexOf(lineBefore); // If the lineBefore is not an include statement, simply return the last index of it. } /// @@ -183,7 +235,7 @@ namespace LSLEditor.Helpers /// /// /// Context with the new line - private StringBuilder WriteAfterLine(StringBuilder context, string newLine, string lineBefore) // TODO: HIJ MOET KIJKEN NAAR DE INDEX VAN LINEBEFORE, NIET ZELF DE INDEX OPZOEKEN + private StringBuilder WriteAfterLine(StringBuilder context, string newLine, string lineBefore) { string ctx = context.ToString(); int lastIndexOfLineBefore = GetCorrectIndexOfLine(lineBefore, ctx); @@ -206,6 +258,10 @@ namespace LSLEditor.Helpers return context; } + /// + /// Shows an 'Oops...' messagebox with the message and verboses it. + /// + /// private void ShowError(string message) { if (!editForm.verboseQueue.Contains(message)) @@ -215,6 +271,12 @@ namespace LSLEditor.Helpers } } + /// + /// Returns the amount of tabs for an include depth + /// + /// + /// + /// private string GetTabsForIncludeDepth(int includeDepth, bool OneLess = false) // TODO: Dit wordt wss een setting. Tabs hangt namelijk af van de hoeveelheid ingedente include statement. { string tabs = ""; @@ -230,13 +292,144 @@ namespace LSLEditor.Helpers return tabs; } + /// + /// Returns the amount of tabs in front of an include statement + /// + /// + /// + private string GetTabsForIndentedInclude(string includeLine, int includeDepth, bool isDebug = false) + { + if(includeLine.Contains("\t")) + { + int includeIndex = Regex.Match(includeLine, INCLUDE).Index; + + string beforeInclude = includeLine.Substring(0, includeIndex); + int tabCount = 0; + + // Count the tabs between the start of the line and the begin of the include. NOTE: HIJ MOET ALLEEN DE INCLUDEDEPTH AFTREKKEN WANNEER HIJ DEBUG IS + if (isDebug) + { + tabCount = beforeInclude.Count(f => f == '\t') - (includeDepth - 1); // The tabcount should be without the includeDepth, because this was already added. + } else + { + tabCount = beforeInclude.Count(f => f == '\t'); + } + + string tabs = ""; + for (int i = 0; i < tabCount; i++) + { + tabs += "\t"; + } + return tabs; + } + return ""; + } + + /// + /// Returns the amount of tabs for an include script + /// + /// + /// + /// + /// + private string GetTabsForIncludeScript(string includeLine, int includeDepth, bool OneLess = false) + { + string includeDepthTabs = GetTabsForIncludeDepth(includeDepth, OneLess); + string indentedIncludeTabs = GetTabsForIndentedInclude(includeLine, includeDepth, true); + + + return includeDepthTabs + indentedIncludeTabs; + } + + /// + /// Returns the line of the match within a context + /// + /// + /// + /// + private string GetLineOfMatch(string context, Match m) + { + string contentAfterMatchValue = context.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 + return context.Substring(m.Index, indexOfNewLine - m.Index); // Get full line + } + + /// + /// Inserts an included script and writes the expanded script for export. + /// + /// + /// + /// + /// + private StringBuilder WriteExportScript(string pathOfInclude, StringBuilder sb, string includeLine) + { + string script = GetTabsForIndentedInclude(includeLine, includeDepth) + EMPTY_SCRIPT; + using (StreamReader sr = new StreamReader(pathOfInclude)) + { + this.implementedIncludes.Add(Path.GetFullPath(pathOfInclude)); + string scriptRaw = sr.ReadToEnd(); + scriptRaw = GetTabsForIndentedInclude(includeLine, includeDepth) + scriptRaw.Replace("\n", "\n" + GetTabsForIndentedInclude(includeLine, includeDepth)); + + // If there are includes in the included script + if (Regex.IsMatch(scriptRaw, INCLUDE_REGEX)) + { + // Then import these scripts too + script = ImportScripts(scriptRaw, pathOfInclude, false) + "\n"; + } + else if (!Regex.IsMatch(scriptRaw, EMPTY_OR_WHITESPACE_REGEX)) + { + script = scriptRaw + "\n"; + } + } + this.WriteAfterLine(sb, script, includeLine); + string ctx = sb.ToString(); + return new StringBuilder(ctx.Remove(ctx.IndexOf(includeLine.TrimStart('\n')), includeLine.TrimStart('\n').Length)); // Deletes the include statement + } + + /// + /// Inserts an included script and writes it to the expanded script for debug. + /// + /// + /// + /// + /// + private StringBuilder WriteDebugScript(string pathOfInclude, StringBuilder sb, string includeLine) + { + sb = this.WriteAfterLine(sb, GetTabsForIncludeScript(includeLine, includeDepth, true) + BEGIN, includeLine); + + // Insert included script + string script = GetTabsForIncludeScript(includeLine, includeDepth) + EMPTY_SCRIPT; + + using (StreamReader sr = new StreamReader(pathOfInclude)) + { + this.implementedIncludes.Add(Path.GetFullPath(pathOfInclude)); + string scriptRaw = sr.ReadToEnd(); + scriptRaw = GetTabsForIncludeScript(includeLine, includeDepth) + scriptRaw.Replace("\n", "\n" + GetTabsForIncludeScript(includeLine, includeDepth)); + + // If there are includes in the included script + if (Regex.IsMatch(scriptRaw, INCLUDE_REGEX)) + { + // Then import these scripts too + script = "\n" + ImportScripts(scriptRaw, pathOfInclude) + "\n"; + } + else if (!Regex.IsMatch(scriptRaw, EMPTY_OR_WHITESPACE_REGEX))// Check if its not empty or whitespace + { + script = scriptRaw + "\n"; + } + } + + this.WriteAfterLine(sb, script, BEGIN + "\n"); + this.WriteAfterLine(sb, GetTabsForIncludeScript(includeLine, includeDepth, true) + END, script); + return sb; + } + /// /// 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, bool ShowBeginEnd = true) // TODO: Lange functie, kan ik deze opsplitten? + private string ImportScripts(string strC, string pathOfScript, bool ShowBeginEnd = true) { if(!LSLIPathHelper.IsLSLI(pathOfScript)) { @@ -255,13 +448,10 @@ namespace LSLEditor.Helpers } 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 line = GetLineOfMatch(strC, m); + int lineNumber = strC.Take(m.Index + line.Length - 1).Count(c => c == '\n') + 1; - int lineNumber = strC.Take(indexOfNewLine - 1).Count(c => c == '\n') + 1; - - string pathOfIncludeOriginal = Regex.Match(line, "\".*?\"").Value.Trim('"'); + string pathOfIncludeOriginal = Regex.Match(line, PATH_OF_INCLUDE_REGEX).Value.Trim('"'); string pathOfInclude = pathOfIncludeOriginal; string ext = Path.GetExtension(pathOfInclude).ToLower(); @@ -269,54 +459,24 @@ namespace LSLEditor.Helpers && !pathOfScript.Contains(pathOfInclude)) { // If path is relative - if (!Path.IsPathRooted(pathOfInclude)) + if (!Path.IsPathRooted(pathOfInclude) && Properties.Settings.Default.IncludeDirectories.Count == 0) { - pathOfInclude = GetRelativePath(pathOfScript, Environment.CurrentDirectory) + pathOfInclude; + pathOfInclude = LSLIPathHelper.GetRelativePath(pathOfScript, Environment.CurrentDirectory) + pathOfInclude; + } else if (this.implementedIncludes.Count > 0) + { + pathOfInclude = Path.GetDirectoryName(this.implementedIncludes.LastOrDefault()) + '\\' + pathOfInclude; } pathOfInclude = SearchFile(pathOfInclude); if (pathOfInclude != "" && !this.implementedIncludes.Contains(Path.GetFullPath(pathOfInclude))) { - if(ShowBeginEnd) + if(!ShowBeginEnd) { - sb = this.WriteAfterLine(sb, GetTabsForIncludeDepth(includeDepth, true) + BEGIN, line); - } - - // Insert included script - string script = GetTabsForIncludeDepth(includeDepth) + "// Empty script\n"; - using (StreamReader sr = new StreamReader(pathOfInclude)) - { - this.implementedIncludes.Add(Path.GetFullPath(pathOfInclude)); - string scriptRaw = sr.ReadToEnd(); - scriptRaw = GetTabsForIncludeDepth(includeDepth) + scriptRaw.Replace("\n", "\n" + GetTabsForIncludeDepth(includeDepth)); - - // If there are includes in the included script - if (Regex.IsMatch(scriptRaw, INCLUDE_REGEX)) - { - // Then import these scripts too - if (ShowBeginEnd) - { - script = "\n" + ImportScripts(scriptRaw, pathOfInclude) + "\n"; - } else - { - script = "\n" + ImportScripts(scriptRaw, pathOfInclude, false) + "\n"; - } - } else if(!Regex.IsMatch(scriptRaw, "^\\s*$"))// Check if its not empty or whitespace // scriptRaw != "" && scriptRaw != " ") - { - script = scriptRaw + "\n"; - } - } - - if (ShowBeginEnd) - { - this.WriteAfterLine(sb, script, BEGIN + "\n"); - this.WriteAfterLine(sb, GetTabsForIncludeDepth(includeDepth, true) + END, script); + sb = WriteExportScript(pathOfInclude, sb, line); } else { - this.WriteAfterLine(sb, script, line); - string ctx = sb.ToString(); - sb = new StringBuilder(ctx.Remove(ctx.IndexOf(line.TrimStart('\n')), line.TrimStart('\n').Length)); + sb = WriteDebugScript(pathOfInclude, sb, line); } } else if (pathOfInclude != "" && this.implementedIncludes.Contains(Path.GetFullPath(pathOfInclude))) @@ -328,7 +488,7 @@ namespace LSLEditor.Helpers ShowError(message); } else { - string correctPath = Path.GetFullPath(GetRelativePath(pathOfScript, Environment.CurrentDirectory) + pathOfIncludeOriginal); + string correctPath = Path.GetFullPath(LSLIPathHelper.GetRelativePath(pathOfScript, Environment.CurrentDirectory) + pathOfIncludeOriginal); string message = "Error: Unable to find file \"" + correctPath + "\". In script \"" + Path.GetFileName(pathOfScript) + "\". Line " + lineNumber + "."; @@ -439,7 +599,18 @@ namespace LSLEditor.Helpers public string ExpandToLSL(EditForm editForm, bool ShowBeginEnd = true) { this.editForm = editForm; - string sourceCode = ImportScripts(editForm.SourceCode, editForm.FullPathName, ShowBeginEnd); + string strC = editForm.SourceCode; + string fullPathName = editForm.FullPathName; + + if (LSLIPathHelper.IsExpandedLSL(editForm.ScriptName)) + { + // Collapse first, to ensure it is expanded showing or not showing begin/end. + strC = CollapseToLSLI(strC); + // Mimic LSLI file + fullPathName = LSLIPathHelper.CreateCollapsedPathAndScriptName(fullPathName); + } + + string sourceCode = ImportScripts(strC, fullPathName, ShowBeginEnd); return sourceCode; } } diff --git a/trunk/Helpers/LSLIPathHelper.cs b/trunk/Helpers/LSLIPathHelper.cs index 4c8afb1..41ca3a3 100644 --- a/trunk/Helpers/LSLIPathHelper.cs +++ b/trunk/Helpers/LSLIPathHelper.cs @@ -81,7 +81,6 @@ namespace LSLEditor.Helpers 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; } @@ -113,7 +112,13 @@ namespace LSLEditor.Helpers /// public static string CreateExpandedPathAndScriptName(string path) { - return PutDotInFrontOfFilename(RemoveExtension(path) + LSLIConverter.EXPANDED_SUBEXT + LSLIConverter.LSL_EXT); + if(path.Contains(LSLIConverter.EXPANDED_SUBEXT)) + { + return PutDotInFrontOfFilename(RemoveExtension(path) + LSLIConverter.LSL_EXT); + } else + { + return PutDotInFrontOfFilename(RemoveExtension(path) + LSLIConverter.EXPANDED_SUBEXT + LSLIConverter.LSL_EXT); + } } /// @@ -158,7 +163,7 @@ namespace LSLEditor.Helpers } /// - /// "Hides" the file in the folder + /// "Hides" the file in the folder by setting it's attributes to "Hidden" /// /// public static void HideFile(string path) @@ -183,10 +188,48 @@ namespace LSLEditor.Helpers return str.Trim(' ').TrimEnd('*'); } + /// + /// Turns an expanded script name into a string to be displayed as the tab name + /// + /// + /// public static string GetExpandedTabName(string path) { if (path == null) return ""; return RemoveDotInFrontOfFilename(Path.GetFileNameWithoutExtension(RemoveExpandedSubExtension(path)) + LSLIConverter.LSLI_EXT + " (Expanded LSL)"); } + + // TODO: CREATE SAME FUNCTION AS ABOVE FOR READONLY TAB NAME (IS CURRENTLY HARD-CODED) + + /// + /// Creates a relative path between two paths + /// + /// The file or folder to create a relative path towards + /// The base folder + /// + public static string GetRelativePath(string filespec, string folder) + { + filespec = Path.GetFullPath(filespec).ToLower(); + if (LSLIConverter.validExtensions.Contains(filespec.Substring(filespec.LastIndexOf(".")))) + { + int lastIndexOfSeperator = filespec.LastIndexOf('\\') > filespec.LastIndexOf('/') ? filespec.LastIndexOf('\\') : filespec.LastIndexOf('/'); + filespec = filespec.Remove(lastIndexOfSeperator); + } + Uri pathUri = new Uri(filespec); + + if (!folder.EndsWith(Path.DirectorySeparatorChar.ToString())) + { + folder += Path.DirectorySeparatorChar; + } + Uri folderUri = new Uri(folder); + string relativePath = Uri.UnescapeDataString(folderUri.MakeRelativeUri(pathUri).ToString().Replace('/', Path.DirectorySeparatorChar)); + + if (relativePath.Substring(relativePath.Length - 3) != Path.DirectorySeparatorChar.ToString()) + { + relativePath += Path.DirectorySeparatorChar; + } + + return relativePath; + } } } diff --git a/trunk/LSLEditorForm.Designer.cs b/trunk/LSLEditorForm.Designer.cs index 1df0d70..a9fc05f 100644 --- a/trunk/LSLEditorForm.Designer.cs +++ b/trunk/LSLEditorForm.Designer.cs @@ -150,6 +150,7 @@ namespace LSLEditor this.openSolutionFilesDialog = new System.Windows.Forms.OpenFileDialog(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.dockPanel = new LSLEditor.Docking.DockPanel(); + this.lSLIScriptToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout(); this.contextMenuStrip1.SuspendLayout(); @@ -211,6 +212,7 @@ namespace LSLEditor this.newToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.newProjectToolStripMenuItem, this.newFileToolStripMenuItem, + this.lSLIScriptToolStripMenuItem, this.notecardToolStripMenuItem}); this.newToolStripMenuItem.Name = "newToolStripMenuItem"; this.newToolStripMenuItem.Size = new System.Drawing.Size(191, 22); @@ -231,7 +233,7 @@ namespace LSLEditor this.newFileToolStripMenuItem.Name = "newFileToolStripMenuItem"; this.newFileToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N))); this.newFileToolStripMenuItem.Size = new System.Drawing.Size(202, 22); - this.newFileToolStripMenuItem.Text = "Script"; + this.newFileToolStripMenuItem.Text = "LSL Script"; this.newFileToolStripMenuItem.Click += new System.EventHandler(this.newFileToolStripMenuItem_Click); // // notecardToolStripMenuItem @@ -1021,6 +1023,16 @@ namespace LSLEditor this.dockPanel.Skin = dockPanelSkin1; this.dockPanel.TabIndex = 10; // + // lSLIScriptToolStripMenuItem + // + this.lSLIScriptToolStripMenuItem.Image = global::LSLEditor.Properties.Resources.NEWDOC; + this.lSLIScriptToolStripMenuItem.Name = "lSLIScriptToolStripMenuItem"; + this.lSLIScriptToolStripMenuItem.ShortcutKeyDisplayString = ""; + this.lSLIScriptToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.M))); + this.lSLIScriptToolStripMenuItem.Size = new System.Drawing.Size(202, 22); + this.lSLIScriptToolStripMenuItem.Text = "LSLI Script"; + this.lSLIScriptToolStripMenuItem.Click += new System.EventHandler(this.lSLIScriptToolStripMenuItem_Click); + // // LSLEditorForm // this.AllowDrop = true; @@ -1157,5 +1169,6 @@ namespace LSLEditor private System.Windows.Forms.ToolStripMenuItem viewLSLIToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator11; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2; + private System.Windows.Forms.ToolStripMenuItem lSLIScriptToolStripMenuItem; } } \ No newline at end of file diff --git a/trunk/LSLEditorForm.cs b/trunk/LSLEditorForm.cs index ab34ec1..8f1e4f8 100644 --- a/trunk/LSLEditorForm.cs +++ b/trunk/LSLEditorForm.cs @@ -354,7 +354,15 @@ namespace LSLEditor void TextBox_OnCursorPositionChanged(object sender, SyntaxRichTextBox.CursorPositionEventArgs e) { - this.toolStripStatusLabel1.Text = string.Format("Ln {0,-10} Col {1,-10} Ch {2,-20} Ttl {3,-10} {4,-10} {5,-10}", e.Line, e.Column, e.Char, e.Total, e.Insert ? "INS" : "OVR", e.Caps ? "CAP" : ""); + EditForm editForm = (EditForm)this.ActiveMdiForm; + string expandedWarning = ""; + if (Helpers.LSLIPathHelper.IsExpandedLSL(editForm.ScriptName)) + { + expandedWarning = "Warning: Editing in included sections will be erased when collapsing/saving!"; + } + + this.toolStripStatusLabel1.Text = string.Format("Ln {0,-10} Col {1,-10} Ch {2,-20} Ttl {3,-10} {4,-10} {5,-10} {6}", + e.Line, e.Column, e.Char, e.Total, e.Insert ? "INS" : "OVR", e.Caps ? "CAP" : "", expandedWarning); } private XmlDocument GetXmlFromResource(string strName) @@ -378,14 +386,20 @@ namespace LSLEditor AddForm(editForm); } - private void NewFile() + private void NewFile(bool isLSLI = false) { EditForm editForm = new EditForm(this); editForm.SourceCode = Helpers.GetTemplate.Source(); editForm.TextBox.FormatDocument(); editForm.TextBox.ClearUndoStack(); - editForm.FullPathName = Properties.Settings.Default.ExampleName; - editForm.TextBox.OnCursorPositionChanged += new SyntaxRichTextBox.CursorPositionChangedHandler(TextBox_OnCursorPositionChanged); + if(isLSLI) + { + editForm.FullPathName = Properties.Settings.Default.ExampleNameLSLI; + } else + { + editForm.FullPathName = Properties.Settings.Default.ExampleName; + } + editForm.TextBox.OnCursorPositionChanged += new SyntaxRichTextBox.CursorPositionChangedHandler(TextBox_OnCursorPositionChanged); AddForm(editForm); } @@ -1007,7 +1021,14 @@ namespace LSLEditor } ActivateMdiForm(editForm); if (editForm.Dirty) { - DialogResult dialogResult = MessageBox.Show(this, @"Save """ + editForm.ScriptName + @"""?", "File has changed", MessageBoxButtons.YesNoCancel); + string scriptToSave = editForm.ScriptName; + if(Helpers.LSLIPathHelper.IsExpandedLSL(editForm.ScriptName)) + { + // Expanded scripts will always be saved as LSLI's + scriptToSave = Helpers.LSLIPathHelper.CreateCollapsedScriptName(scriptToSave); + } + + DialogResult dialogResult = MessageBox.Show(this, @"Save """ + scriptToSave + @"""?", "File has changed", MessageBoxButtons.YesNoCancel); if (dialogResult == DialogResult.Cancel) { return false; } @@ -1022,7 +1043,14 @@ namespace LSLEditor if (dialogResult == DialogResult.No) { editForm.Dirty = false; } - } + + // Delete expanded file when closing + string expandedFile = Helpers.LSLIPathHelper.CreateExpandedPathAndScriptName(editForm.FullPathName); + if (File.Exists(expandedFile)) + { + File.Delete(expandedFile); + } + } CloseActiveWindow(); } return true; @@ -1349,7 +1377,8 @@ namespace LSLEditor public void CloseActiveWindow() { - if (this.IsMdiContainer) { + EditForm editForm = this.ActiveMdiForm as EditForm; + if (this.IsMdiContainer) { if (this.ActiveMdiForm != null && !this.ActiveMdiForm.IsDisposed) { this.ActiveMdiForm.Close(); } @@ -1824,13 +1853,13 @@ namespace LSLEditor /// /// /// Returns null if not found - private Form GetForm(string formName) + public 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) + if (Helpers.LSLIPathHelper.TrimStarsAndWhiteSpace(form.Text) == formName) //.TrimEnd(' ') { desirableForm = (EditForm)form; } @@ -1839,6 +1868,52 @@ namespace LSLEditor return desirableForm; } + /// + /// Sets the readonly property of the textbox in the form + /// + /// + /// + public void SetReadOnly(EditForm form, bool isReadOnly) + { + foreach (Control c in form.tabControl.SelectedTab.Controls) + { + Type dfsa = c.GetType(); + if (c.GetType() == typeof(SplitContainer)) + { + NumberedTextBox.NumberedTextBoxUC a = (NumberedTextBox.NumberedTextBoxUC)((SplitContainer)c).ActiveControl; + if(a != null) + { + a.TextBox.ReadOnly = isReadOnly; + } + } + } + } + + /// + /// Gets the forms readonly property and returns it. + /// + /// + /// + public bool IsReadOnly(EditForm form) + { + foreach (Control c in form.tabControl.SelectedTab.Controls) + { + Type dfsa = c.GetType(); + if (c.GetType() == typeof(SplitContainer)) + { + NumberedTextBox.NumberedTextBoxUC a = (NumberedTextBox.NumberedTextBoxUC)((SplitContainer)c).ActiveControl; + if(a != null) + { + return a.TextBox.ReadOnly; + } else + { + return true; + } + } + } + return false; + } + private void expandToLSLToolStripMenuItem_Click(object sender, EventArgs e) { EditForm editForm = this.ActiveMdiForm as EditForm; @@ -1849,25 +1924,48 @@ namespace LSLEditor string lsl = converter.ExpandToLSL(editForm); string file = Helpers.LSLIPathHelper.CreateExpandedPathAndScriptName(editForm.FullPathName); - editForm.Close(); - - Helpers.LSLIPathHelper.DeleteFile(file); - - using (StreamWriter sw = new StreamWriter(file)) + // Check if the expanded form is already open. If so, then overwrite the content of it. + if(GetForm(Helpers.LSLIPathHelper.GetExpandedTabName(Helpers.LSLIPathHelper.CreateExpandedScriptName(editForm.ScriptName))) != null) { - sw.Write(lsl); + EditForm oldExpandedForm = (EditForm)GetForm(Helpers.LSLIPathHelper.GetExpandedTabName(Helpers.LSLIPathHelper.CreateExpandedScriptName(editForm.ScriptName))); + oldExpandedForm.SourceCode = lsl; + //oldExpandedForm.TabIndex = editForm.TabIndex; // TODO: Keep tabIndex when expanding/collapsing the same + oldExpandedForm.Show(); + SetReadOnly(oldExpandedForm, false); + oldExpandedForm.Dirty = editForm.Dirty; + + if (editForm.Dirty) + { + oldExpandedForm.Text = Helpers.LSLIPathHelper.GetExpandedTabName(editForm.Text) + "*"; + } else + { + oldExpandedForm.Text = Helpers.LSLIPathHelper.GetExpandedTabName(editForm.Text); + } } + else + { // If not already open + Helpers.LSLIPathHelper.DeleteFile(file); - Helpers.LSLIPathHelper.HideFile(file); + using (StreamWriter sw = new StreamWriter(file)) + { + sw.Write(lsl); + } + + Helpers.LSLIPathHelper.HideFile(file); - EditForm expandedForm = (EditForm)GetForm(Helpers.LSLIPathHelper.CreateExpandedScriptName(Path.GetFileName(file))); + EditForm expandedForm = (EditForm)GetForm(Helpers.LSLIPathHelper.CreateExpandedScriptName(Path.GetFileName(file))); - if (expandedForm != null) - { - expandedForm.Close(); + if (expandedForm != null) + { + expandedForm.Close(); + } + + OpenFile(file); + EditForm lslForm = (EditForm)GetForm(Helpers.LSLIPathHelper.GetExpandedTabName(file)); + lslForm.Dirty = editForm.Dirty; + //lslForm.Text = Helpers.LSLIPathHelper.GetExpandedTabName(editForm.Text); } - - OpenFile(file); + editForm.Hide(); } } @@ -1883,22 +1981,29 @@ namespace LSLEditor string lsli = converter.CollapseToLSLIFromEditform(editForm); string file = Helpers.LSLIPathHelper.CreateCollapsedPathAndScriptName(editForm.FullPathName); - - editForm.Close(); - - using (StreamWriter sw = new StreamWriter(file)) - { - sw.Write(lsli); - } - Form collapsedForm = GetForm(Helpers.LSLIPathHelper.CreateCollapsedScriptName(Path.GetFileName(file))); - - if (collapsedForm != null) + // Check if the LSLI form is already open (but hidden) + if (GetForm(Path.GetFileName(file)) != null) { - collapsedForm.Close(); + EditForm LSLIform = (EditForm)GetForm(Path.GetFileName(file)); + LSLIform.SourceCode = lsli; + LSLIform.Show(); + SetReadOnly(LSLIform, false); + + LSLIform.Dirty = editForm.Dirty; + } + else + { + OpenFile(file); + EditForm LSLIform = (EditForm)GetForm(Path.GetFileName(file)); + LSLIform.Dirty = editForm.Dirty; } - OpenFile(file); + if (GetForm(Path.GetFileName(file) + " (Read Only)") != null) // if readonly is open, close it + { + GetForm(Path.GetFileName(file) + " (Read Only)").Close(); + } + editForm.Hide(); } } @@ -1916,16 +2021,22 @@ namespace LSLEditor string pathOfLSLI = Helpers.LSLIPathHelper.CreateCollapsedPathAndScriptName(editForm.FullPathName); if (File.Exists(pathOfLSLI)) { - Form LSLIform = GetForm(Path.GetFileName(pathOfLSLI)); + string tabText = Path.GetFileName(pathOfLSLI) + " (Read Only)"; - if (LSLIform != null) + // If old LSLI readonly is open + Form OldReadOnlyLSLIform = GetForm(tabText); + + if (OldReadOnlyLSLIform != null) { - LSLIform.Close(); + OldReadOnlyLSLIform.Close(); } OpenFile(pathOfLSLI); - - GetForm(Path.GetFileName(pathOfLSLI)).Enabled = false; + + EditForm lsliForm = (EditForm) GetForm(Path.GetFileName(pathOfLSLI)); + SetReadOnly(lsliForm, true); + lsliForm.AutoScroll = true; + lsliForm.Text = tabText; } else { @@ -1933,7 +2044,8 @@ namespace LSLEditor } } } - + + // Export button (Ctrl+E) private void toolStripMenuItem2_Click(object sender, EventArgs e) { StreamWriter streamWriter; @@ -1951,10 +2063,18 @@ namespace LSLEditor if ((streamWriter = new StreamWriter(saveFileDialog1.OpenFile())) != null) { Helpers.LSLIConverter lsliConverter = new Helpers.LSLIConverter(); - streamWriter.Write(lsliConverter.ExpandToLSL(editForm, false)); + + bool showBeginEnd = Properties.Settings.Default.ShowIncludeMetaData; + streamWriter.Write(lsliConverter.ExpandToLSL(editForm, showBeginEnd)); streamWriter.Close(); + OpenFile(Path.GetFullPath(saveFileDialog1.FileName)); } } } + + private void lSLIScriptToolStripMenuItem_Click(object sender, EventArgs e) + { + NewFile(true); + } } } diff --git a/trunk/Properties/AssemblyInfo.cs b/trunk/Properties/AssemblyInfo.cs index 9e89003..02bdcf3 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.590")] +[assembly: AssemblyVersion("2.55.0.825")] // // 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.590")] +[assembly: AssemblyFileVersionAttribute("2.55.0.825")] diff --git a/trunk/Properties/Settings.Designer.cs b/trunk/Properties/Settings.Designer.cs index e70c577..daf917d 100644 --- a/trunk/Properties/Settings.Designer.cs +++ b/trunk/Properties/Settings.Designer.cs @@ -8,6 +8,8 @@ // //------------------------------------------------------------------------------ +using System.Collections.Generic; + namespace LSLEditor.Properties { @@ -257,6 +259,17 @@ namespace LSLEditor.Properties { } } + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("new.lsli")] + public string ExampleNameLSLI + { + get + { + return ((string)(this["ExampleNameLSLI"])); + } + } + [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("ReleaseNotes.htm")] @@ -699,6 +712,36 @@ namespace LSLEditor.Properties { } } + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public List IncludeDirectories + { + get + { + return ((List)(this["IncludeDirectories"])); + } + set + { + this["IncludeDirectories"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool ShowIncludeMetaData + { + get + { + return ((bool)(this["ShowIncludeMetaData"])); + } + set + { + this["ShowIncludeMetaData"] = value; + } + } + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("False")] diff --git a/trunk/Resource/ToolsOptions.xml b/trunk/Resource/ToolsOptions.xml index 224d2c0..2b12553 100644 --- a/trunk/Resource/ToolsOptions.xml +++ b/trunk/Resource/ToolsOptions.xml @@ -8,6 +8,8 @@ + + diff --git a/trunk/RuntimeConsole.cs b/trunk/RuntimeConsole.cs index 2c771a4..a27f5aa 100644 --- a/trunk/RuntimeConsole.cs +++ b/trunk/RuntimeConsole.cs @@ -68,8 +68,6 @@ namespace LSLEditor private string CSharpCode; private EditForm editForm; - private bool isLSLI = true; // Deze moet aflezen van de extensie van het script in de tab of het LSL is of LSLI - private bool GetNewHost() { bool blnResult = false; @@ -99,6 +97,28 @@ namespace LSLEditor return blnResult; } + /// + /// Converts this script (when it's LSLI) to expanded lsl and writes it. + /// + /// + private string ConvertLSLI() + { + LSLIConverter lsliConverter = new LSLIConverter(); + string lsl = lsliConverter.ExpandToLSL(editForm); + string nameExpanded = LSLIPathHelper.CreateExpandedScriptName(editForm.FullPathName); + string path = LSLIPathHelper.CreateExpandedPathAndScriptName(editForm.FullPathName); + + LSLIPathHelper.DeleteFile(path); + + using (StreamWriter sw = new StreamWriter(path)) + { + sw.Write(lsl); + } + + LSLIPathHelper.HideFile(path); + return lsl; + } + public bool Compile(EditForm editForm) { this.editForm = editForm; @@ -111,21 +131,17 @@ namespace LSLEditor string lsl = editForm.SourceCode; - if (isLSLI && editForm.FullPathName.IndexOf(LSLIConverter.EXPANDED_SUBEXT) < 0) // Expand LSLI to LSL + // If not hidden and not readonly + if (!editForm.IsHidden && !this.mainForm.IsReadOnly(editForm)) { - LSLIConverter lsliConverter = new LSLIConverter(); - lsl = lsliConverter.ExpandToLSL(editForm); - string nameExpanded = LSLIPathHelper.CreateExpandedScriptName(editForm.FullPathName); - string path = LSLIPathHelper.CreateExpandedPathAndScriptName(editForm.FullPathName); - - LSLIPathHelper.DeleteFile(path); - - using (StreamWriter sw = new StreamWriter(path)) + if (LSLIPathHelper.IsLSLI(editForm.ScriptName)) // Expand LSLI to LSL { - sw.Write(lsl); + lsl = ConvertLSLI(); } - - LSLIPathHelper.HideFile(path); + } else + { + this.editForm.StopCompiler(); + return false; } CSharpCode = MakeSharp(editForm.ConfLSL, lsl); diff --git a/trunk/Solution/SolutionExplorer.cs b/trunk/Solution/SolutionExplorer.cs index 423e185..e60f20e 100644 --- a/trunk/Solution/SolutionExplorer.cs +++ b/trunk/Solution/SolutionExplorer.cs @@ -1725,15 +1725,40 @@ namespace LSLEditor.Solution timer.Tag = null; Guid guid = ((RealTag)e.Node.Tag).Guid; + string path = GetFullPath(e.Node); - // already opened - EditForm editForm = GetEditForm(guid); + // already opened + EditForm editForm = GetEditForm(guid); if (editForm != null) { TabPage tabPage = editForm.Tag as TabPage; if (tabPage == null) { - editForm.Focus(); + if(editForm.Visible) + { + editForm.Focus(); + } else + { + // Check if there's a related expanded lsl or lsli opened. If so, focus it. Else open the lsli. + EditForm expandedForm = (EditForm)parent.GetForm(Helpers.LSLIPathHelper.GetExpandedTabName(Helpers.LSLIPathHelper.CreateExpandedScriptName(Path.GetFileName(path)))); + EditForm collapsedForm = (EditForm)parent.GetForm(Helpers.LSLIPathHelper.CreateCollapsedScriptName(Path.GetFileName(path))); + if (expandedForm != null && expandedForm.Visible) + { + expandedForm.Focus(); + } + else if (collapsedForm != null && collapsedForm.Visible) + { + collapsedForm.Focus(); + } + else + { + // Open a new one + if (GetTypeSL(e.Node) == TypeSL.Script) + { + this.parent.OpenFile(GetFullPath(e.Node), guid, true); + } + } + } } else { @@ -1744,9 +1769,37 @@ namespace LSLEditor.Solution return; } - // open a new one - if (GetTypeSL(e.Node) == TypeSL.Script) - this.parent.OpenFile(GetFullPath(e.Node), guid, true); + // Check if it's an lsli that has an open expanded form + if (GetTypeSL(e.Node) == TypeSL.Script) + { + if (Helpers.LSLIPathHelper.IsLSLI(path)) { + // Check if there's a related expanded lsl opened. If so, focus it. Else open the lsli. + EditForm expandedForm = (EditForm)parent.GetForm(Helpers.LSLIPathHelper.GetExpandedTabName(Helpers.LSLIPathHelper.CreateExpandedScriptName(Path.GetFileName(path)))); + EditForm collapsedForm = (EditForm)parent.GetForm(Helpers.LSLIPathHelper.CreateCollapsedScriptName(Path.GetFileName(path))); + if (expandedForm != null && expandedForm.Visible) + { + expandedForm.Focus(); + } else if(collapsedForm != null && collapsedForm.Visible) + { + collapsedForm.Focus(); + } else + { + // Open a new one + if (GetTypeSL(e.Node) == TypeSL.Script) + { + this.parent.OpenFile(GetFullPath(e.Node), guid, true); + } + } + } else + { + // Open a new one + if (GetTypeSL(e.Node) == TypeSL.Script) + { + this.parent.OpenFile(GetFullPath(e.Node), guid, true); + } + } + } + if (GetTypeSL(e.Node) == TypeSL.Notecard) this.parent.OpenFile(GetFullPath(e.Node), guid, false); } diff --git a/trunk/Tools/IncludeExportSettings.Designer.cs b/trunk/Tools/IncludeExportSettings.Designer.cs new file mode 100644 index 0000000..f37936a --- /dev/null +++ b/trunk/Tools/IncludeExportSettings.Designer.cs @@ -0,0 +1,74 @@ +namespace LSLEditor.Tools +{ + partial class IncludeExportSettings + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.groupBoxIncludeExportSettings = new System.Windows.Forms.GroupBox(); + this.checkBox1 = new System.Windows.Forms.CheckBox(); + this.groupBoxIncludeExportSettings.SuspendLayout(); + this.SuspendLayout(); + // + // groupBoxIncludeExportSettings + // + this.groupBoxIncludeExportSettings.Controls.Add(this.checkBox1); + this.groupBoxIncludeExportSettings.Location = new System.Drawing.Point(3, 3); + this.groupBoxIncludeExportSettings.Name = "groupBoxIncludeExportSettings"; + this.groupBoxIncludeExportSettings.Size = new System.Drawing.Size(380, 64); + this.groupBoxIncludeExportSettings.TabIndex = 0; + this.groupBoxIncludeExportSettings.TabStop = false; + this.groupBoxIncludeExportSettings.Text = "Include export settings"; + // + // checkBox1 + // + this.checkBox1.AutoSize = true; + this.checkBox1.Location = new System.Drawing.Point(16, 28); + this.checkBox1.Name = "checkBox1"; + this.checkBox1.Size = new System.Drawing.Size(184, 17); + this.checkBox1.TabIndex = 0; + this.checkBox1.Text = "Show include metadata on export"; + this.checkBox1.UseVisualStyleBackColor = true; + // + // IncludeExportSettings + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.groupBoxIncludeExportSettings); + this.Name = "IncludeExportSettings"; + this.Size = new System.Drawing.Size(386, 266); + this.groupBoxIncludeExportSettings.ResumeLayout(false); + this.groupBoxIncludeExportSettings.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.GroupBox groupBoxIncludeExportSettings; + private System.Windows.Forms.CheckBox checkBox1; + } +} diff --git a/trunk/Tools/IncludeExportSettings.cs b/trunk/Tools/IncludeExportSettings.cs new file mode 100644 index 0000000..8faba5c --- /dev/null +++ b/trunk/Tools/IncludeExportSettings.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace LSLEditor.Tools +{ + public partial class IncludeExportSettings : UserControl, ICommit + { + public IncludeExportSettings() + { + InitializeComponent(); + checkBox1.Checked = Properties.Settings.Default.ShowIncludeMetaData; + } + + public void Commit() + { + Properties.Settings.Default.ShowIncludeMetaData = checkBox1.Checked; + } + } +} diff --git a/trunk/Tools/IncludeExportSettings.resx b/trunk/Tools/IncludeExportSettings.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/trunk/Tools/IncludeExportSettings.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/trunk/Tools/ProjectIncludes.Designer.cs b/trunk/Tools/ProjectIncludes.Designer.cs new file mode 100644 index 0000000..0f62874 --- /dev/null +++ b/trunk/Tools/ProjectIncludes.Designer.cs @@ -0,0 +1,139 @@ +namespace LSLEditor.Tools +{ + partial class ProjectIncludes + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBoxAddIncludeDir = new System.Windows.Forms.TextBox(); + this.groupBoxIncludeDirs = new System.Windows.Forms.GroupBox(); + this.buttonRemove = new System.Windows.Forms.Button(); + this.buttonAddIncludeDir = new System.Windows.Forms.Button(); + this.listBoxIncludeDirs = new System.Windows.Forms.ListBox(); + this.buttonBrowseDirs = new System.Windows.Forms.Button(); + this.labelIncludeDirs = new System.Windows.Forms.Label(); + this.folderBrowserDialogSelectIncludeDir = new System.Windows.Forms.FolderBrowserDialog(); + this.groupBoxIncludeDirs.SuspendLayout(); + this.SuspendLayout(); + // + // textBoxAddIncludeDir + // + this.textBoxAddIncludeDir.Location = new System.Drawing.Point(16, 40); + this.textBoxAddIncludeDir.Name = "textBoxAddIncludeDir"; + this.textBoxAddIncludeDir.Size = new System.Drawing.Size(270, 20); + this.textBoxAddIncludeDir.TabIndex = 0; + this.textBoxAddIncludeDir.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxAddIncludeDir_KeyPress); + // + // groupBoxIncludeDirs + // + this.groupBoxIncludeDirs.Controls.Add(this.buttonRemove); + this.groupBoxIncludeDirs.Controls.Add(this.buttonAddIncludeDir); + this.groupBoxIncludeDirs.Controls.Add(this.listBoxIncludeDirs); + this.groupBoxIncludeDirs.Controls.Add(this.buttonBrowseDirs); + this.groupBoxIncludeDirs.Controls.Add(this.labelIncludeDirs); + this.groupBoxIncludeDirs.Location = new System.Drawing.Point(3, 3); + this.groupBoxIncludeDirs.Name = "groupBoxIncludeDirs"; + this.groupBoxIncludeDirs.Size = new System.Drawing.Size(386, 266); + this.groupBoxIncludeDirs.TabIndex = 1; + this.groupBoxIncludeDirs.TabStop = false; + this.groupBoxIncludeDirs.Text = "Include directories"; + // + // buttonRemove + // + this.buttonRemove.Location = new System.Drawing.Point(290, 229); + this.buttonRemove.Name = "buttonRemove"; + this.buttonRemove.Size = new System.Drawing.Size(75, 23); + this.buttonRemove.TabIndex = 4; + this.buttonRemove.Text = "Remove"; + this.buttonRemove.UseVisualStyleBackColor = true; + this.buttonRemove.Click += new System.EventHandler(this.buttonRemove_Click); + // + // buttonAddIncludeDir + // + this.buttonAddIncludeDir.Location = new System.Drawing.Point(331, 36); + this.buttonAddIncludeDir.Name = "buttonAddIncludeDir"; + this.buttonAddIncludeDir.Size = new System.Drawing.Size(34, 23); + this.buttonAddIncludeDir.TabIndex = 3; + this.buttonAddIncludeDir.Text = "Add"; + this.buttonAddIncludeDir.UseVisualStyleBackColor = true; + this.buttonAddIncludeDir.Click += new System.EventHandler(this.buttonAddIncludeDir_Click); + // + // listBoxIncludeDirs + // + this.listBoxIncludeDirs.FormattingEnabled = true; + this.listBoxIncludeDirs.HorizontalScrollbar = true; + this.listBoxIncludeDirs.Location = new System.Drawing.Point(13, 76); + this.listBoxIncludeDirs.Name = "listBoxIncludeDirs"; + this.listBoxIncludeDirs.Size = new System.Drawing.Size(352, 147); + this.listBoxIncludeDirs.TabIndex = 2; + this.listBoxIncludeDirs.KeyUp += new System.Windows.Forms.KeyEventHandler(this.listBoxIncludeDirs_KeyUp); + // + // buttonBrowseDirs + // + this.buttonBrowseDirs.Location = new System.Drawing.Point(292, 36); + this.buttonBrowseDirs.Name = "buttonBrowseDirs"; + this.buttonBrowseDirs.Size = new System.Drawing.Size(32, 23); + this.buttonBrowseDirs.TabIndex = 1; + this.buttonBrowseDirs.Text = "..."; + this.buttonBrowseDirs.UseVisualStyleBackColor = true; + this.buttonBrowseDirs.Click += new System.EventHandler(this.buttonBrowseDirs_Click); + // + // labelIncludeDirs + // + this.labelIncludeDirs.AutoSize = true; + this.labelIncludeDirs.Location = new System.Drawing.Point(14, 20); + this.labelIncludeDirs.Name = "labelIncludeDirs"; + this.labelIncludeDirs.Size = new System.Drawing.Size(109, 13); + this.labelIncludeDirs.TabIndex = 0; + this.labelIncludeDirs.Text = "Add include directory:"; + // + // ProjectIncludes + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.textBoxAddIncludeDir); + this.Controls.Add(this.groupBoxIncludeDirs); + this.Name = "ProjectIncludes"; + this.Size = new System.Drawing.Size(392, 272); + this.groupBoxIncludeDirs.ResumeLayout(false); + this.groupBoxIncludeDirs.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox textBoxAddIncludeDir; + private System.Windows.Forms.GroupBox groupBoxIncludeDirs; + private System.Windows.Forms.Label labelIncludeDirs; + private System.Windows.Forms.Button buttonBrowseDirs; + private System.Windows.Forms.ListBox listBoxIncludeDirs; + private System.Windows.Forms.Button buttonAddIncludeDir; + private System.Windows.Forms.Button buttonRemove; + private System.Windows.Forms.FolderBrowserDialog folderBrowserDialogSelectIncludeDir; + } +} diff --git a/trunk/Tools/ProjectIncludes.cs b/trunk/Tools/ProjectIncludes.cs new file mode 100644 index 0000000..0208a1d --- /dev/null +++ b/trunk/Tools/ProjectIncludes.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.IO; + +namespace LSLEditor.Tools +{ + public partial class ProjectIncludes : UserControl, ICommit + { + public ProjectIncludes() + { + InitializeComponent(); + listBoxIncludeDirs.Items.Clear(); + listBoxIncludeDirs.Items.AddRange(Properties.Settings.Default.IncludeDirectories.ToArray()); + } + + private bool AddToIncludeDirs(string path) + { + // Check if it can find the directory + if(Directory.Exists(path)) + { + // Put directory seperator after path + path = path.LastOrDefault() == '\\' || path.LastOrDefault() == '/' ? path : path + '\\'; + + // Check if it's already in the settings + if(!Properties.Settings.Default.IncludeDirectories.Contains(path)) + { + // Add to listbox + listBoxIncludeDirs.Items.Add(path); + return true; + } + } else + { + MessageBox.Show("The given directory was not found. \n\"" + path + "\"", "Oops...", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + return false; + } + + private bool RemoveFromIncludeDirs() + { + if(listBoxIncludeDirs.SelectedItem != null) + { + listBoxIncludeDirs.Items.Remove(listBoxIncludeDirs.SelectedItem); + return true; + } + return false; + } + + public void Commit() + { + List items = new List(); + // Add to settings + foreach(Object item in listBoxIncludeDirs.Items) + { + items.Add(item.ToString()); + } + + Properties.Settings.Default.IncludeDirectories = items; + } + + private void buttonAddIncludeDir_Click(object sender, EventArgs e) + { + if(textBoxAddIncludeDir.Text != "") + { + AddToIncludeDirs(textBoxAddIncludeDir.Text); + } + } + + private void textBoxAddIncludeDir_KeyPress(object sender, KeyPressEventArgs e) + { + if(e.KeyChar == (char)Keys.Enter) + { + if (textBoxAddIncludeDir.Text != "") + { + AddToIncludeDirs(textBoxAddIncludeDir.Text); + } + } + } + + private void buttonBrowseDirs_Click(object sender, EventArgs e) + { + this.folderBrowserDialogSelectIncludeDir.RootFolder = Environment.SpecialFolder.MyComputer; + if (this.folderBrowserDialogSelectIncludeDir.ShowDialog(this) == DialogResult.OK) + { + AddToIncludeDirs(this.folderBrowserDialogSelectIncludeDir.SelectedPath); + } + } + + private void buttonRemove_Click(object sender, EventArgs e) + { + RemoveFromIncludeDirs(); + } + + private void listBoxIncludeDirs_KeyUp(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Delete || e.KeyCode == Keys.Back) + { + RemoveFromIncludeDirs(); + } + } + } +} diff --git a/trunk/Tools/ProjectIncludes.resx b/trunk/Tools/ProjectIncludes.resx new file mode 100644 index 0000000..2ff500f --- /dev/null +++ b/trunk/Tools/ProjectIncludes.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/trunk/lsleditor.csproj b/trunk/lsleditor.csproj index 9745130..f24ba4c 100644 --- a/trunk/lsleditor.csproj +++ b/trunk/lsleditor.csproj @@ -643,6 +643,18 @@ EnvironmentPlugins.cs true + + UserControl + + + IncludeExportSettings.cs + + + UserControl + + + ProjectIncludes.cs + UserControl true @@ -962,7 +974,9 @@ - + + Designer + @@ -989,6 +1003,12 @@ Designer EnvironmentPlugins.cs + + IncludeExportSettings.cs + + + ProjectIncludes.cs + RuntimeGeneral.cs Designer