private void OnNewDoc(bool firstDocument) { if (DesignMode) { return; } var ea = new DocEventArgs(firstDocument); NewDocNeeded(this, ea); Document = ea.Document; CurrentFileName = null; IsDocumentChanged = false; DocOpenedOrCreated(this, EventArgs.Empty); }
private void OnOpen(string filePath) { if (OpenDocNeeded != null) { var ea = new DocEventArgs(false) { FileName = filePath }; OpenDocNeeded(this, ea); Document = ea.Document; } else { using (var stream = File.OpenRead(filePath)) using (var zip = new GZipStream(stream, CompressionMode.Decompress)) Document = new BinaryFormatter().Deserialize(zip); } DocOpenedOrCreated(this, EventArgs.Empty); }
private void OnSave(string fileName) { var args = new DocEventArgs(false) { Document = Document, FileName = fileName }; Saving(this, args); if (SaveDocNeeded != null) { SaveDocNeeded(this, args); } else { using (var stream = File.OpenWrite(fileName)) using (var zip = new GZipStream(stream, CompressionMode.Compress)) new BinaryFormatter().Serialize(zip, Document); } }