public void OnCancel(object sender, RoutedEventArgs e) { userOption = ReadOnlyDialogResult.Cancel; this.Close(); }
public bool SaveScript(bool saveAs) { if (parsedScript == null) { return(false); } string filePath = parsedScript.GetScriptPath(); if (false == saveAs) // This is just a simple save. { if (scriptState.textBuffer.ScriptModified == false) { return(true); // Nothing has changed, no need! } } if ((File.Exists(filePath) && ((File.GetAttributes(filePath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)) || SystemFile(filePath)) { if (saveAs == false) { if (!SystemFile(filePath)) { ReadOnlyDialogResult result = dialog.ShowReadOnlyDialog(true); if (result == ReadOnlyDialogResult.OverWrite) { FileAttributes attributes = File.GetAttributes(filePath); File.SetAttributes(filePath, attributes ^ FileAttributes.ReadOnly); } else if (result == ReadOnlyDialogResult.SaveAs) { saveAs = true; } else { return(false); } } else { ReadOnlyDialogResult result = dialog.ShowReadOnlyDialog(false); if (result == ReadOnlyDialogResult.SaveAs) { saveAs = true; } else { return(false); } } } } if (filePath == "" || saveAs) { string newFilePath = null; while (true) { newFilePath = PromptScriptSave(); if (string.IsNullOrEmpty(newFilePath)) { return(false); } int newFileIndex = Solution.Current.GetScriptIndexFromPath(newFilePath); if (newFileIndex != -1 && newFileIndex != Solution.Current.ActiveScriptIndex) { dialog.ShowFileAlreadyOpenDialog(); } else { break; } } // The check for the filePath is to see if the file is // being saved into the same file or a new file. if (!string.Equals(filePath, newFilePath)) { scriptState.textBuffer.ScriptModified = true; filePath = newFilePath; InitializeFileWatcher(newFilePath); } if (null != newFilePath) { TextEditorCore.Instance.Data.AddToRecentFileList(newFilePath); } } if (fileWatcher != null) { fileWatcher.EnableRaisingEvents = false; } try { StreamWriter streamWriter = new StreamWriter(filePath); string fileContent = scriptState.textBuffer.GetContent(); fileContent = fileContent.Replace("\n", "\r\n"); streamWriter.Write(fileContent); streamWriter.Close(); } catch (Exception) { IDialogProvider dialog = TextEditorCore.DialogProvider; string message = string.Format("Could not access file '{0}', please try again.", filePath); dialog.DisplayStatusMessage(StatusTypes.Warning, message, 5); return(false); } if (fileWatcher != null) { fileWatcher.EnableRaisingEvents = true; } bool parseResult = parsedScript.ParseScript(filePath); scriptState.textBuffer.ScriptModified = false; return(parseResult); }
public void OnOverwrite(object sender, RoutedEventArgs e) { userOption = ReadOnlyDialogResult.OverWrite; this.Close(); }
public void OnSaveAs(object sender, RoutedEventArgs e) { userOption = ReadOnlyDialogResult.SaveAs; this.Close(); }