private void btnJhMessageBox_Click(object sender, RoutedEventArgs e) { _viewModel.MessageBoxType = this.JhMessageBoxTypeToUse; JhMessageBoxOptions options = new JhMessageBoxOptions(_viewModel.MessageBoxType); if (_viewModel.IsUsingDefaultTimeoutValue) { options.TimeoutPeriodInSeconds = 0; } else { options.TimeoutPeriodInSeconds = this.TimeToDisplayIt; _viewModel.TimeoutValue = options.TimeoutPeriodInSeconds; } string timeoutValueText = txtTime.Text; //var result = ParseLib.ParseForTimeInterval(timeoutValueText); //if (result.IsOk) //{ // _viewModel.TimeoutValue = (int)result.ValueInSeconds.Value; //} //else //{ // Console.WriteLine("What you put for TimeoutValue doesn't look valid to me. What-up-widat?"); // return; //} //options.TimeoutPeriodInSeconds = _viewModel.TimeoutValue; if (_viewModel.IsIncludingParentWindow) { options.ParentElement = this; } options.BackgroundTexture = _viewModel.BackgroundTexture; options.ButtonFlags = GetButtonsToShow(); options.CaptionAfterPrefix = _viewModel.CaptionAfterPrefix; if (!String.IsNullOrWhiteSpace(_viewModel.CompanyName) || !String.IsNullOrWhiteSpace(_viewModel.ApplicationName)) { options.CaptionPrefix = _viewModel.CompanyName + " " + _viewModel.ApplicationName; } options.DetailText = _viewModel.DetailText; options.SummaryText = _viewModel.SummaryText; options.IsCustomButtonStyles = _viewModel.IsCustomButtonStyles; options.IsSoundEnabled = _viewModel.IsSoundEnabled; options.IsToCenterOverParent = _viewModel.IsToCenterOverParent; options.IsToBeTopmostWindow = _viewModel.IsTopmostWindow; options.IsUsingAeroGlassEffect = _viewModel.IsUsingAeroGlassEffect; options.IsUsingNewerSoundScheme = _viewModel.IsUsingNewerSoundScheme; options.IsUsingNewerIcons = _viewModel.IsUsingNewerIcons; JhDialogResult r = _messageBoxManager.NotifyUser(options); txtResult.Text = "JhDialogResult." + r.ToString(); borderResult.Visibility = System.Windows.Visibility.Visible; lblResult.Visibility = System.Windows.Visibility.Visible; }
public string GetButtonText(JhDialogResult forWhichResponse) { string buttonText = String.Empty; switch (forWhichResponse) { case JhDialogResult.Abort: buttonText = _buttonAbortText; break; case JhDialogResult.Cancel: buttonText = _buttonCancelText; break; case JhDialogResult.Close: buttonText = _buttonCloseText; break; case JhDialogResult.Ignore: buttonText = _buttonIgnoreText; break; case JhDialogResult.No: buttonText = _buttonNoText; break; case JhDialogResult.Ok: buttonText = _buttonOkText; break; case JhDialogResult.Retry: buttonText = _buttonRetryText; break; case JhDialogResult.Yes: buttonText = _buttonYesText; break; default: break; } return(buttonText); }
public JhMessageBoxOptions SetButtonToolTip(JhDialogResult forWhichResponse, string tooltipText) { switch (forWhichResponse) { case JhDialogResult.Abort: _buttonAbortToolTipText = tooltipText; break; case JhDialogResult.Cancel: _buttonCancelToolTipText = tooltipText; break; case JhDialogResult.Close: _buttonCloseToolTipText = tooltipText; break; case JhDialogResult.Ignore: _buttonIgnoreToolTipText = tooltipText; break; case JhDialogResult.No: _buttonNoToolTipText = tooltipText; break; case JhDialogResult.Ok: _buttonOkToolTipText = tooltipText; break; case JhDialogResult.Retry: _buttonRetryToolTipText = tooltipText; break; case JhDialogResult.Yes: _buttonYesToolTipText = tooltipText; break; default: break; } return(this); }
/// <summary> /// Cause the message-box window to immediately close with the given Result. Used for testing. /// </summary> /// <param name="withWhatResult">the JhDialogResult to assign to the Result property upon closing</param> public void SimulateClosing(JhDialogResult withWhatResult) { this._messageBoxManager.MessageBoxWindow.Result = withWhatResult; this._messageBoxManager.MessageBoxWindow.Close(); }
/// <summary> /// Set the message-box such that, when run as part of an automated test, we "mock" the user-interaction such that /// it acts as though the user selects the button that yields the given JhDialogResult. /// </summary> /// <param name="buttonResult">This determines which button to emulate being pushed.</param> /// <returns>this instance of JhMessageBoxOptions, such that additional method-calls may be chained together</returns> public JhMessageBoxTestFacility SetButtonToSelect(JhDialogResult buttonResult) { _buttonResultToSelect = buttonResult; return(this); }
internal void SignalThatMessageBoxHasEnded(object sender, JhDialogResult result) { //TODO: May want to provide a value for error and isCancelled JhMessageBoxWindow messageBoxWindow = sender as JhMessageBoxWindow; JhMessageBoxOptions options = messageBoxWindow._options; options.SignalThatMessageBoxHasEnded(messageBoxWindow, result); }
public JhDialogResult Show(string messageBoxText, string caption, JhMessageBoxButtons buttons, JhMessageBoxType messageType, JhDialogResult defaultResult, FrameworkElement owner) { int defaultTimeout = JhMessageBoxOptions.GetDefaultTimeoutValueFor(messageType); #if !SILVERLIGHT JhDialogResult r = NotifyUser(summaryText: messageBoxText, detailText: "", buttons: buttons, messageType: messageType, captionAfterPrefix: caption, timeout: defaultTimeout, parent: owner); #else JhDialogResult r = NotifyUser(messageBoxText, "", caption, buttons, messageType, defaultTimeout); #endif // In this library, we ordinarily consider the TimedOut result to be the default result, // but here the caller of this method has specified a specific defaultResult. if (r == JhDialogResult.TimedOut) { r = defaultResult; } return r; }
public JhDialogResult Show(string messageBoxText, string caption, JhMessageBoxButtons buttons, JhMessageBoxType messageType, JhDialogResult defaultResult) { #if !SILVERLIGHT FrameworkElement owner = Application.Current.MainWindow; return Show(messageBoxText, caption, buttons, messageType, _defaultResult, owner); #else return Show(messageBoxText, caption, buttons, messageType, _defaultResult); #endif }
/// <summary> /// Display a message-box to the user asking a Yes-or-No question. Wait for his response or else close itself after the timeout has expired. /// </summary> /// <param name="question">the text of the question to pose to the user, which will go into the summary-text area of the message-box</param> /// <param name="defaultAnswer">this is the user-response to assume if the message-box is closed via its system-menu or times-out</param> /// <param name="detailText">additional text that can go into the detail-text area (optional)</param> /// <param name="caption">text to add to the normal default title-bar prefix that will appear as the 'caption' for this message-box (optional)</param> /// <param name="parent">the visual-element to consider as the parent, or owner, of this message-box (optional)</param> /// <returns>a JhDialogResult indicating which action the user took, or TimedOut if the user took no action before the timeout expired</returns> public JhDialogResult AskYesOrNo(string question, JhDialogResult defaultAnswer, string detailText = null, string caption = null, FrameworkElement parent = null) { #if SILVERLIGHT return NotifyUser(question, null, sFullCaption, JhMessageBoxButtons.Yes | JhMessageBoxButtons.No, JhMessageBoxType.Question, timeout); #else JhDialogResult r = NotifyUser(summaryText: question, detailText: null, captionAfterPrefix: caption, buttons: JhMessageBoxButtons.Yes | JhMessageBoxButtons.No, messageType: JhMessageBoxType.Question, timeout: 0, parent: parent); if (r == JhDialogResult.TimedOut) { return defaultAnswer; } else { return r; } #endif }
/// <summary> /// The constructor /// </summary> /// <param name="result">the JhDialogResult that the message-box was ended with</param> /// <param name="error">an exception if it was thrown during the operation of the message-box, otherwise null</param> /// <param name="messageBoxWindow">the message-box that raised this event</param> public MessageBoxCompletedArgs(JhDialogResult result, Exception error, JhMessageBoxWindow messageBoxWindow) : base(error: error, cancelled: false, userState: messageBoxWindow) { this.Result = result; this.MessageBoxWindow = messageBoxWindow; this.Options = messageBoxWindow._options; }
/// <summary> /// Raise the Completed event with parameters indicating the current message-box window and the user-response /// it was closed with. /// </summary> /// <remarks> /// This is attached to JhMessageBoxOptions because it's handler needs to exist at the instance-level, /// and the Options object is easily available to the developer. /// </remarks> /// <param name="messageBoxWindow">the message-box window that signaled this event</param> /// <param name="result">the user-response with which the message-box window was dismissed</param> public void SignalThatMessageBoxHasEnded(JhMessageBoxWindow messageBoxWindow, JhDialogResult result) { var args = new MessageBoxCompletedArgs(result: result, error: null, messageBoxWindow: messageBoxWindow); this.Completed(this, args); }
private void OnCompleted(object sender, MessageBoxCompletedArgs e) { _isCompletedEventRaised = true; _theResult = e.Result; }
/// <summary> /// Set the message-box such that, when run as part of an automated test, we "mock" the user-interaction such that /// it acts as though the user selects the button that yields the given JhDialogResult. /// </summary> /// <param name="buttonResult">This determines which button to emulate being pushed.</param> /// <returns>this instance of JhMessageBoxOptions, such that additional method-calls may be chained together</returns> public JhMessageBoxTestFacility SetButtonToSelect(JhDialogResult buttonResult) { _buttonResultToSelect = buttonResult; return this; }
public void TC05_NotifyUser_CustomButton1_CorrectResults() { using (var testMessageBox = JhMessageBox.BeginTest()) { var options = new JhMessageBoxOptions() .SetButtonFlags(JhMessageBoxButtons.Yes | JhMessageBoxButtons.No | JhMessageBoxButtons.Cancel) .SetButtonText(JhDialogResult.Yes, "Absolutely!") .SetSummaryText("The Summary Text") .SetIsAsynchronous(true); // We're going to test the event mechanism as well. options.Completed += new System.EventHandler<MessageBoxCompletedArgs>(OnCompleted); _isCompletedEventRaised = false; // Set this to any value other than what we are going to expect it to be. _theResult = JhDialogResult.Ignore; testMessageBox.TestFacility.SetToWaitForExplicitClose(); // Show the message-box. testMessageBox.NotifyUser(options); testMessageBox.TestFacility.AssertAMessageBoxIsBeingShown(); testMessageBox.TestFacility.AssertNoButtonIsPresent(); testMessageBox.TestFacility.AssertCancelButtonIsPresent(); testMessageBox.TestFacility.AssertButtonIsPresent("Absolutely!"); testMessageBox.TestFacility.SimulateClosing(JhDialogResult.Ok); testMessageBox.TestFacility.AssertAMessageBoxHasBeenShown(); Assert.IsTrue(_isCompletedEventRaised, "Why did the Completed event not get raised?"); Assert.AreEqual(JhDialogResult.Ok, _theResult, "The result did not get set correctly!"); } }