private void DeserializeFromScriptItems() { string directory = Path.GetDirectoryName(this.filePath); if (directory.EndsWith("\\") == false) { directory += "\\"; } string oldDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(directory); if (null != ScriptCountChanged) { // Notify event subscribers that the script count has changed. ScriptCountChangedEventArgs eventArgs = new ScriptCountChangedEventArgs(); eventArgs.ScriptsRemoved.AddRange(loadedScripts); ScriptCountChanged(this, eventArgs); } // Unsubscribe all existing handlers before they are cleared. foreach (IScriptObject existingScript in loadedScripts) { ITextBuffer textBuffer = existingScript.GetTextBuffer(); textBuffer.LinesUpdated -= linesUpdatedHandler; } loadedScripts.Clear(); foreach (ScriptItem scriptItem in solutionData.Scripts) { string scriptPath = scriptItem.RelativePath; IScriptObject scriptObject = OpenScript(Path.GetFullPath(scriptPath)); if (null != scriptObject && (scriptItem.EntryPoint != false)) { this.activeScript = scriptObject; } } foreach (BreakpointItem breakpoint in solutionData.Breakpoints) { string filePath = breakpoint.RelativePath; breakpoint.AbsolutePath = Path.GetFullPath(filePath); } Directory.SetCurrentDirectory(oldDirectory); }
internal bool CloseScript(int index) { solutionModified = true; // Changes should be persisted. showSaveSolutionDialog = true; if (index < 0 || (index >= loadedScripts.Count)) { throw new InvalidOperationException("Script does not exist!"); } ScriptObject script = loadedScripts[index] as ScriptObject; // Unsubscribe from text buffer event notification. ITextBuffer textBuffer = script.GetTextBuffer(); textBuffer.LinesUpdated -= linesUpdatedHandler; loadedScripts.RemoveAt(index); if (0 == loadedScripts.Count) { this.activeScript = null; } if (activeScript == script) { activeScript = null; } // Notify event subscribers that the script count has changed. if (null != ScriptCountChanged) { ScriptCountChangedEventArgs eventArgs = new ScriptCountChangedEventArgs(); eventArgs.ScriptsRemoved.Add(script); ScriptCountChanged(this, eventArgs); } script.DestroyScript(); return(true); }
internal IScriptObject AddNewScript(string fileContent) { solutionModified = true; // Changes should be persisted. showSaveSolutionDialog = true; IScriptObject script = new ScriptObject(fileContent); loadedScripts.Add(script); // Notify event subscribers that the script count has changed. if (null != ScriptCountChanged) { ScriptCountChangedEventArgs eventArgs = new ScriptCountChangedEventArgs(); eventArgs.ScriptsAdded.Add(script); ScriptCountChanged(this, eventArgs); } // Subscribe to the new text buffer event notification. ITextBuffer textBuffer = script.GetTextBuffer(); textBuffer.LinesUpdated += linesUpdatedHandler; return(script); }
internal IScriptObject OpenScript(string scriptPath) { solutionModified = true; // Changes should be persisted. showSaveSolutionDialog = true; if (File.Exists(scriptPath) == false) { return(null); // The file does not exist. } // If the entire script is so messed up that it cannot even be // parsed in a meaningful way, then "ParseScript" call will fail. // When that happens, we don't return "null" from here, the file // open should continue (and errors be shown as red colored text). IParsedScript parsedScript = InterfaceFactory.CreateParsedScript(); parsedScript.ParseScript(scriptPath); // Add the new script to loaded scripts. IScriptObject hostScript = new ScriptObject(parsedScript); loadedScripts.Add(hostScript); // Notify event subscribers that the script count has changed. if (null != ScriptCountChanged) { ScriptCountChangedEventArgs eventArgs = new ScriptCountChangedEventArgs(); eventArgs.ScriptsAdded.Add(hostScript); ScriptCountChanged(this, eventArgs); } // Subscribe to the new text buffer event notification. ITextBuffer textBuffer = hostScript.GetTextBuffer(); textBuffer.LinesUpdated += linesUpdatedHandler; return(hostScript); }
void OnScriptCountChanged(object sender, ScriptCountChangedEventArgs e) { this.totalOpenScripts += e.ScriptsAdded.Count; this.totalOpenScripts -= e.ScriptsRemoved.Count; }