// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.Core.Services
{
///
/// Interface for the MessageService.
///
public interface IMessageService
{
///
/// Shows an error.
///
void ShowError(string message);
///
/// Shows an exception.
///
void ShowException(Exception ex, string message);
///
/// Shows a warning message.
///
void ShowWarning(string message);
///
/// Asks the user a Yes/No question, using "Yes" as the default button.
/// Returns true if yes was clicked, false if no was clicked.
///
bool AskQuestion(string question, string caption);
///
/// Shows a custom dialog.
///
/// The title of the dialog.
/// The description shown in the dialog.
///
/// The number of the button that is the default accept button.
/// Use -1 if you don't want to have an accept button.
///
///
/// The number of the button that is the cancel button.
/// Use -1 if you don't want to have a cancel button.
///
/// The captions of the buttons.
/// The number of the button that was clicked, or -1 if the dialog was closed without clicking a button.
int ShowCustomDialog(string caption, string dialogText, int acceptButtonIndex, int cancelButtonIndex, params string[] buttontexts);
string ShowInputBox(string caption, string dialogText, string defaultValue);
void ShowMessage(string message, string caption);
///
/// Show a message informing the user about a save error.
///
void InformSaveError(string fileName, string message, string dialogName, Exception exceptionGot);
///
/// Show a message informing the user about a save error,
/// and allow him to retry/save under alternative name.
///
ChooseSaveErrorResult ChooseSaveError(string fileName, string message, string dialogName, Exception exceptionGot, bool chooseLocationEnabled);
}
public sealed class ChooseSaveErrorResult
{
public bool IsRetry { get; private set; }
public bool IsIgnore { get; private set; }
public bool IsSaveAlternative { get { return AlternativeFileName != null; } }
public string AlternativeFileName { get; private set; }
private ChooseSaveErrorResult() {}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification="ChooseSaveErrorResult is immutable")]
public readonly static ChooseSaveErrorResult Retry = new ChooseSaveErrorResult { IsRetry = true };
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification="ChooseSaveErrorResult is immutable")]
public readonly static ChooseSaveErrorResult Ignore = new ChooseSaveErrorResult { IsIgnore = true };
public static ChooseSaveErrorResult SaveAlternative(string alternativeFileName)
{
if (alternativeFileName == null)
throw new ArgumentNullException("alternativeFileName");
return new ChooseSaveErrorResult { AlternativeFileName = alternativeFileName };
}
}
}