void CloseEditor() { if (Changed) { var result = DecisionDialog.Show(Messages.EditorSaveQuestion, new[] { Messages.EditorSaveAnswerYes, Messages.EditorSaveAnswerNo, Messages.EditorSaveAnswerCancel }); if (result == 2) { return; } else if (result == 0) { SaveCurrent(); //Application apparently crashed, i.e. could not write file if (Changed) { CloseEditor(); return; } } } _kernel.RunningQueriesChanged -= OnRunningQueriesChanged; _parent.Remove(this); }
/// <summary> /// Closes all tabs. /// </summary> /// <returns>True: Cancel Close. False: Do not cancel.</returns> public Boolean CloseAll() { var filesChanged = 0; for (var i = 0; i < Files.Count; i++) { if (Files[i].Changed) { filesChanged++; } } if (filesChanged > 0) { var message = String.Format(Messages.EditorSaveQuestionMultiple, filesChanged); var result = DecisionDialog.Show(message, new[] { Messages.EditorSaveAnswerYesMultiple, Messages.EditorSaveAnswerNo, Messages.EditorSaveAnswerCancel }); if (result == 1) { return(false); } else if (result == 2) { return(true); } for (var i = 0; i < Files.Count; i++) { if (Files[i].Changed) { Files[i].Save.Execute(null); } } return(CloseAll()); } return(false); }
protected override void OnAccept(Window window) { var path = UserSelectedFile.FullName; if (File.Exists(path)) { var fn = Path.GetFileName(path); var message = String.Format(Messages.OverwriteQuestion, fn); var result = DecisionDialog.Show(message, new[] { Messages.OverwriteAnswerYes, Messages.OverwriteAnswerCancel }); if (result == 1) { return; } } base.OnAccept(window); }
private async void MainWindow_OnClosing(object sender, CancelEventArgs e) { if (CloseState.ForceClose.Equals(WindowCloseState)) { return; } if (CloseState.Closing.Equals(WindowCloseState)) { if (WindowState.Equals(WindowState.Minimized)) { WindowState = WindowState.Normal; } e.Cancel = true; SystemSounds.Exclamation.Play(); return; } WindowCloseState = CloseState.Closing; if (Context.IsNotSaved) { e.Cancel = true; if (WindowState.Equals(WindowState.Minimized)) { WindowState = WindowState.Normal; SystemSounds.Exclamation.Play(); RootDialog.Focus(); } if (RootDialog.IsOpen) { DialogHost.CloseDialogCommand.Execute(null, RootDialog); } var dialog = new DecisionDialog("Configuration has changed", "Do you want to save before closing?"); var result = (MessageBoxResult?)await DialogHost.Show(dialog, "RootDialog"); if (result == null) { return; } switch (result) { case MessageBoxResult.None: case MessageBoxResult.Cancel: WindowCloseState = CloseState.None; return; case MessageBoxResult.OK: case MessageBoxResult.Yes: Context.SaveContext(); WindowCloseState = CloseState.ForceClose; Close(); break; case MessageBoxResult.No: WindowCloseState = CloseState.ForceClose; Close(); break; } } }