private void EditForm_FormClosing(object sender, FormClosingEventArgs e) { this.parent.CancelClosing = false; this.parent.ActivateMdiForm(this); if (this.Dirty) { 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); } } 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.GetReadOnlyTabName(ScriptName))); if (readOnlyLSLI != null) { readOnlyLSLI.Close(); } } if (!this.parent.IsReadOnly(this)) // If this is not a readonly (LSLI) { // Delete expanded file when closing string expandedFile = LSLIPathHelper.CreateExpandedPathAndScriptName(FullPathName); EditForm expandedForm = (EditForm)parent.GetForm(LSLIPathHelper.GetExpandedTabName(Path.GetFileName(expandedFile))); if (expandedForm != null && !LSLIPathHelper.IsExpandedLSL(ScriptName)) { expandedForm.Close(); } if (File.Exists(expandedFile)) { File.Delete(expandedFile); } } } this.parent.CancelClosing = e.Cancel; }
/// <summary> /// Converts this script (when it's LSLI) to expanded lsl and writes it. /// </summary> /// <returns></returns> 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); }