📄 messageservice.cs
字号:
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <version value="$version"/>
// </file>
using System;
using System.IO;
using System.Windows.Forms;
using System.Collections;
using System.Threading;
using System.Resources;
using System.Drawing;
using System.Diagnostics;
using System.Reflection;
using System.Xml;
using ICSharpCode.Core.AddIns;
using ICSharpCode.Core.Properties;
namespace ICSharpCode.Core.Services
{
/// <summary>
/// This interface must be implemented by all services.
/// </summary>
public class MessageService : AbstractService, IMessageService
{
StringParserService stringParserService = (StringParserService)ServiceManager.Services.GetService(typeof(StringParserService));
public void ShowError(Exception ex)
{
ShowError(ex, null);
}
public void ShowError(string message)
{
ShowError(null, message);
}
public void ShowErrorFormatted(string formatstring, params string[] formatitems)
{
ShowError(null, String.Format(stringParserService.Parse(formatstring), formatitems));
}
public void ShowError(Exception ex, string message)
{
string msg = String.Empty;
if (message != null) {
msg += message;
}
if (message != null && ex != null) {
msg += "\n\n";
}
if (ex != null) {
msg += "Exception occurred: " + ex.ToString();
}
MessageBox.Show(stringParserService.Parse(msg), stringParserService.Parse("${res:Global.ErrorText}"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}
public void ShowWarning(string message)
{
MessageBox.Show(stringParserService.Parse(message), stringParserService.Parse("${res:Global.WarningText}"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
public void ShowWarningFormatted(string formatstring, params string[] formatitems)
{
ShowWarning(String.Format(stringParserService.Parse(formatstring), formatitems));
}
public bool AskQuestion(string question, string caption)
{
return MessageBox.Show(stringParserService.Parse(question), stringParserService.Parse(caption), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes;
}
public bool AskQuestionFormatted(string caption, string formatstring, params string[] formatitems)
{
return AskQuestion(String.Format(stringParserService.Parse(formatstring), formatitems), caption);
}
public bool AskQuestionFormatted(string formatstring, params string[] formatitems)
{
return AskQuestion(String.Format(stringParserService.Parse(formatstring), formatitems));
}
public bool AskQuestion(string question)
{
Console.WriteLine("stps: " + stringParserService);
return AskQuestion(stringParserService.Parse(question), stringParserService.Parse("${res:Global.QuestionText}"));
}
public int ShowCustomDialog(string caption, string dialogText, params string[] buttontexts)
{
// TODO
return 0;
}
public void ShowMessage(string message)
{
ShowMessage(message, "SharpDevelop");
}
public void ShowMessageFormatted(string formatstring, params string[] formatitems)
{
ShowMessage(String.Format(stringParserService.Parse(formatstring), formatitems));
}
public void ShowMessageFormatted(string caption, string formatstring, params string[] formatitems)
{
ShowMessage(String.Format(stringParserService.Parse(formatstring), formatitems), caption);
}
public void ShowMessage(string message, string caption)
{
MessageBox.Show(stringParserService.Parse(message), stringParserService.Parse(caption), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -