public void Save(DocumentPaneViewModel fileToSave, bool saveAsFlag = false) { if (fileToSave is StartPageViewModel) { return; } if (fileToSave.FilePath.Value != null && !saveAsFlag && !fileToSave.IsModified.Value) { return; } if (fileToSave.FilePath.Value == null || saveAsFlag) { var dialog = new CommonSaveFileDialog(); dialog.Filters.Add(new CommonFileDialogFilter("テキスト ファイル (*.txt)", "*.txt")); dialog.Filters.Add(new CommonFileDialogFilter("すべてのファイル (*.*)", "*.*")); dialog.DefaultFileName = fileToSave.FileName.Value; dialog.DefaultExtension = "txt"; if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { fileToSave.FilePath.Value = dialog.FileName; } else { return; } } FileManager.SaveTextFile(fileToSave.FilePath.Value, fileToSave.Text.Value, fileToSave.Encoding.Value); StatusService.Current.Notify(fileToSave.FilePath.Value + "に保存しました。"); this.ActiveDocument.Value.IsModified.Value = false; }
public static DocumentPaneViewModel GetViewModel(ScreenViewModel model, SimpleContentCommand command) { DocumentPaneViewModel dpvm = null; model.UiDispatcher.Invoke(() => { dpvm = GetViewModelInvoked(model, command); }); return(dpvm); }
public StarViewModel(DocumentPaneViewModel paneVm) { _paneVm = paneVm; _context = UserContext.Current; _paneCommand = _paneVm.GetPageCommand(); _messenger.RegisterAsync <BookmarkHasChangedMessage>(this, _context.Token, SetBookmarkedState); _messenger.RegisterAsync <BookmarkStatusResponseMessage>(this, _context.Token, SetBookmarkedState); _messenger.SendAsync <BookmarkStatusRequestMessage>(new BookmarkStatusRequestMessage(_paneCommand), _context.Token); ClickBookmarkCommand = new RelayCommand(() => { //IsBookmarked responds to clicks, and will be reflect that after-clicked state. _messenger.SendAsync(new BookmarkSetMessage(_paneCommand, IsBookmarked), _context.Token); }); IsEnabled = true; }
public void Close(DocumentPaneViewModel fileToClose) { if (fileToClose.IsModified.Value) { var dialog = new TaskDialog.TaskDialogOptions(); dialog.Owner = App.MainView; dialog.Title = "保存の確認"; dialog.MainInstruction = "ドキュメントを保存しますか?"; dialog.Content = "保存しない場合、現在の変更は失われます"; dialog.CustomButtons = new[] { "保存 (&S)", "保存しない (&N)", "キャンセル (&C)" }; var result = TaskDialog.TaskDialog.Show(dialog); switch (result.CustomButtonResult) { case 0: this.Save(fileToClose); if (fileToClose.IsModified.Value) { return; } break; case 1: break; case 2: return; } } this.Files.Remove(fileToClose); this.ToggleStartPage(); if (this.ActiveDocument.Value == fileToClose) { this.ActiveDocument.Value = this.Files.FirstOrDefault(); } }