public FileViewModel Open(string filepath) { var fileViewModel = _files.FirstOrDefault(fm => fm.FilePath == filepath); if (fileViewModel != null) return fileViewModel; fileViewModel = new FileViewModel(filepath); _files.Add(fileViewModel); return fileViewModel; }
internal void Save(FileViewModel fileToSave, bool saveAsFlag = false) { if (fileToSave.FilePath == null || saveAsFlag) { var dlg = new SaveFileDialog(); if (dlg.ShowDialog().GetValueOrDefault()) { fileToSave.Save(dlg.FileName); } } else { fileToSave.Save(); } }
internal void Close(FileViewModel fileToClose) { if (fileToClose.IsModified) { var res = MessageBox.Show(string.Format("Save changes for file '{0}'?", fileToClose.FileName), "AvalonDock Test App", MessageBoxButton.YesNoCancel); if (res == MessageBoxResult.Cancel) return; if (res == MessageBoxResult.Yes) { Save(fileToClose); } } bool replaceActive = fileToClose == ActiveDocument; _files.Remove(fileToClose); if (replaceActive) { if (_files.Count > 0) { ActiveDocument = _files.Last(); } else { ActiveDocument = null; } } }
internal void Execute(FileViewModel fileToClose) { }