public Task SaveAsync(IDocumentFileModel file) { return(ForFileAsync(file, m => true, async model => { await model.SaveAsync(); })); }
public Task OpenAsync(IDocumentFileModel file) { return(ForFileAsync(file, m => m != selectedFile, async model => { await processManager.RunMainProcessAsync(this, async() => { await StoreBackupAsync(); if (await model.OpenAsync()) { if (selectedFile != null) { await selectedFile.SaveSilentAsync(); if (!selectedFile.HasChanges) { selectedFile.Close(); } } selectedFile = model; } else { allFiles.Remove(file); } OnFileLoaded(selectedFile); }); })); }
private static void UpdateTitle(IDocumentFileModel file) { var name = string.Empty; if (file != null) { name = file.Name; if (file.HasChanges) { name += "*"; } } CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { var view = ApplicationView.GetForCurrentView(); if (view != null) { view.Title = name; } }).Forget(); }
public Task RenameAsync(IDocumentFileModel file, string newName) { Guard.ValidFileName(newName, nameof(newName)); return(ForFileAsync(file, m => true, async model => { if (!await model.RenameAsync(newName)) { if (selectedFile != model) { allFiles.Remove(file); } } })); }
private void Store_FileLoaded(object sender, DocumentFileEventArgs e) { UpdateTitle(e.File); if (currentFile != null) { currentFile.PropertyChanged -= CurrentFile_PropertyChanged; } currentFile = e.File; if (currentFile != null) { currentFile.PropertyChanged += CurrentFile_PropertyChanged; } }
public Task RemoveAsync(IDocumentFileModel file) { return(ForFileAsync(file, m => true, async model => { if (await model.RemoveAsync()) { allFiles.Remove(model); if (selectedFile == model) { selectedFile = null; OnFileLoaded(new DocumentFileEventArgs(null)); } } })); }
private void OnFileLoaded(IDocumentFileModel file) { OnFileLoaded(new DocumentFileEventArgs(file)); }
private static Task ForFileAsync(IDocumentFileModel file, Predicate <DocumentFileModel> predicate, Func <DocumentFileModel, Task> action) { var model = file as DocumentFileModel; return(model != null && predicate(model) ? action(model) : Task.FromResult(false)); }
public DocumentFileEventArgs(IDocumentFileModel file) { this.file = file; }