Changed license to Apache License 2.0
This commit is contained in:
parent
857917aad5
commit
0037b7de46
47 changed files with 5942 additions and 5849 deletions
|
@ -1,55 +1,54 @@
|
|||
#region CPL License
|
||||
/*
|
||||
Nuclex Framework
|
||||
Copyright (C) 2002-2019 Nuclex Development Labs
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the IBM Common Public License as
|
||||
published by the IBM Corporation; either version 1.0 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
IBM Common Public License for more details.
|
||||
|
||||
You should have received a copy of the IBM Common Public
|
||||
License along with this library
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Nuclex.Windows.Forms.Messages {
|
||||
|
||||
/// <summary>Performs simple user interaction</summary>
|
||||
/// <remarks>
|
||||
/// Methods provided by this service can be covered using plain old message boxes
|
||||
/// and do not require special dialogs or calls to the task dialog API.
|
||||
/// </remarks>
|
||||
public interface IMessageService {
|
||||
|
||||
/// <summary>Triggered when a message is about to be displayed to the user</summary>
|
||||
event EventHandler<MessageEventArgs> MessageDisplaying;
|
||||
|
||||
/// <summary>Triggered when the user has acknowledged the current message</summary>
|
||||
event EventHandler MessageAcknowledged;
|
||||
|
||||
/// <summary>Asks the user a question that can be answered via several buttons</summary>
|
||||
/// <param name="image">Image that will be shown on the message box</param>
|
||||
/// <param name="text">Text that will be shown to the user</param>
|
||||
/// <param name="buttons">Buttons available for the user to click on</param>
|
||||
/// <returns>The button the user has clicked on</returns>
|
||||
DialogResult ShowQuestion(
|
||||
MessageBoxIcon image, MessageText text, MessageBoxButtons buttons
|
||||
);
|
||||
|
||||
/// <summary>Displays a notification to the user</summary>
|
||||
/// <param name="image">Image that will be shown on the message bx</param>
|
||||
/// <param name="text">Text that will be shown to the user</param>
|
||||
void ShowNotification(MessageBoxIcon image, MessageText text);
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Windows.Forms.Messages
|
||||
#region Apache License 2.0
|
||||
/*
|
||||
Nuclex .NET Framework
|
||||
Copyright (C) 2002-2024 Markus Ewald / Nuclex Development Labs
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Nuclex.Windows.Forms.Messages {
|
||||
|
||||
/// <summary>Performs simple user interaction</summary>
|
||||
/// <remarks>
|
||||
/// Methods provided by this service can be covered using plain old message boxes
|
||||
/// and do not require special dialogs or calls to the task dialog API.
|
||||
/// </remarks>
|
||||
public interface IMessageService {
|
||||
|
||||
/// <summary>Triggered when a message is about to be displayed to the user</summary>
|
||||
event EventHandler<MessageEventArgs> MessageDisplaying;
|
||||
|
||||
/// <summary>Triggered when the user has acknowledged the current message</summary>
|
||||
event EventHandler MessageAcknowledged;
|
||||
|
||||
/// <summary>Asks the user a question that can be answered via several buttons</summary>
|
||||
/// <param name="image">Image that will be shown on the message box</param>
|
||||
/// <param name="text">Text that will be shown to the user</param>
|
||||
/// <param name="buttons">Buttons available for the user to click on</param>
|
||||
/// <returns>The button the user has clicked on</returns>
|
||||
DialogResult ShowQuestion(
|
||||
MessageBoxIcon image, MessageText text, MessageBoxButtons buttons
|
||||
);
|
||||
|
||||
/// <summary>Displays a notification to the user</summary>
|
||||
/// <param name="image">Image that will be shown on the message bx</param>
|
||||
/// <param name="text">Text that will be shown to the user</param>
|
||||
void ShowNotification(MessageBoxIcon image, MessageText text);
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Windows.Forms.Messages
|
||||
|
|
|
@ -1,49 +1,48 @@
|
|||
#region CPL License
|
||||
/*
|
||||
Nuclex Framework
|
||||
Copyright (C) 2002-2019 Nuclex Development Labs
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the IBM Common Public License as
|
||||
published by the IBM Corporation; either version 1.0 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
IBM Common Public License for more details.
|
||||
|
||||
You should have received a copy of the IBM Common Public
|
||||
License along with this library
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Nuclex.Windows.Forms.Messages {
|
||||
|
||||
/// <summary>Unit tests for the message box event argument container</summary>
|
||||
[TestFixture]
|
||||
internal class MessageEventArgsTest {
|
||||
|
||||
/// <summary>Verifies that the image associated with the message gets stored</summary>
|
||||
[Test]
|
||||
public void ImageIsStored() {
|
||||
var arguments = new MessageEventArgs(MessageBoxIcon.Exclamation, null);
|
||||
Assert.AreEqual(MessageBoxIcon.Exclamation, arguments.Image);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the text associated with the message gets stored</summary>
|
||||
[Test]
|
||||
public void TextIsStored() {
|
||||
var text = new MessageText();
|
||||
var arguments = new MessageEventArgs(MessageBoxIcon.None, text);
|
||||
Assert.AreSame(text, arguments.Text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Windows.Forms.Messages
|
||||
#region Apache License 2.0
|
||||
/*
|
||||
Nuclex .NET Framework
|
||||
Copyright (C) 2002-2024 Markus Ewald / Nuclex Development Labs
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Nuclex.Windows.Forms.Messages {
|
||||
|
||||
/// <summary>Unit tests for the message box event argument container</summary>
|
||||
[TestFixture]
|
||||
internal class MessageEventArgsTest {
|
||||
|
||||
/// <summary>Verifies that the image associated with the message gets stored</summary>
|
||||
[Test]
|
||||
public void ImageIsStored() {
|
||||
var arguments = new MessageEventArgs(MessageBoxIcon.Exclamation, null);
|
||||
Assert.AreEqual(MessageBoxIcon.Exclamation, arguments.Image);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the text associated with the message gets stored</summary>
|
||||
[Test]
|
||||
public void TextIsStored() {
|
||||
var text = new MessageText();
|
||||
var arguments = new MessageEventArgs(MessageBoxIcon.None, text);
|
||||
Assert.AreSame(text, arguments.Text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Windows.Forms.Messages
|
||||
|
|
|
@ -1,54 +1,53 @@
|
|||
#region CPL License
|
||||
/*
|
||||
Nuclex Framework
|
||||
Copyright (C) 2002-2019 Nuclex Development Labs
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the IBM Common Public License as
|
||||
published by the IBM Corporation; either version 1.0 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
IBM Common Public License for more details.
|
||||
|
||||
You should have received a copy of the IBM Common Public
|
||||
License along with this library
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Nuclex.Windows.Forms.Messages {
|
||||
|
||||
/// <summary>Provides a displayed message and its severity to event subscribers</summary>
|
||||
public class MessageEventArgs : EventArgs {
|
||||
|
||||
/// <summary>Initializes a new message box event argument container</summary>
|
||||
/// <param name="image">Image the message box will be displaying</param>
|
||||
/// <param name="text">Text that will be displayed in the message box</param>
|
||||
public MessageEventArgs(MessageBoxIcon image, MessageText text) {
|
||||
this.image = image;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
/// <summary>Image that indicates the severity of the message being displayed</summary>
|
||||
public MessageBoxIcon Image {
|
||||
get { return this.image; }
|
||||
}
|
||||
|
||||
/// <summary>Text that is being displayed in the message box</summary>
|
||||
public MessageText Text {
|
||||
get { return this.text; }
|
||||
}
|
||||
|
||||
/// <summary>Image that indicates the severity of the message being displayed</summary>
|
||||
private MessageBoxIcon image;
|
||||
/// <summary>Text that is being displayed in the message box</summary>
|
||||
private MessageText text;
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Windows.Forms.Messages
|
||||
#region Apache License 2.0
|
||||
/*
|
||||
Nuclex .NET Framework
|
||||
Copyright (C) 2002-2024 Markus Ewald / Nuclex Development Labs
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Nuclex.Windows.Forms.Messages {
|
||||
|
||||
/// <summary>Provides a displayed message and its severity to event subscribers</summary>
|
||||
public class MessageEventArgs : EventArgs {
|
||||
|
||||
/// <summary>Initializes a new message box event argument container</summary>
|
||||
/// <param name="image">Image the message box will be displaying</param>
|
||||
/// <param name="text">Text that will be displayed in the message box</param>
|
||||
public MessageEventArgs(MessageBoxIcon image, MessageText text) {
|
||||
this.image = image;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
/// <summary>Image that indicates the severity of the message being displayed</summary>
|
||||
public MessageBoxIcon Image {
|
||||
get { return this.image; }
|
||||
}
|
||||
|
||||
/// <summary>Text that is being displayed in the message box</summary>
|
||||
public MessageText Text {
|
||||
get { return this.text; }
|
||||
}
|
||||
|
||||
/// <summary>Image that indicates the severity of the message being displayed</summary>
|
||||
private MessageBoxIcon image;
|
||||
/// <summary>Text that is being displayed in the message box</summary>
|
||||
private MessageText text;
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Windows.Forms.Messages
|
||||
|
|
|
@ -1,108 +1,107 @@
|
|||
#region CPL License
|
||||
/*
|
||||
Nuclex Framework
|
||||
Copyright (C) 2002-2019 Nuclex Development Labs
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the IBM Common Public License as
|
||||
published by the IBM Corporation; either version 1.0 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
IBM Common Public License for more details.
|
||||
|
||||
You should have received a copy of the IBM Common Public
|
||||
License along with this library
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Nuclex.Windows.Forms.Messages {
|
||||
|
||||
/// <summary>Contains helper methods for the message service</summary>
|
||||
public static class MessageServiceHelper {
|
||||
|
||||
/// <summary>Asks the user a question that can be answered with yes or no</summary>
|
||||
/// <param name="messageService">
|
||||
/// Message service that will be used to display the question
|
||||
/// </param>
|
||||
/// <param name="text">Text that will be shown on the message box</param>
|
||||
/// <returns>The button the user has clicked on</returns>
|
||||
public static DialogResult AskYesNo(
|
||||
this IMessageService messageService, MessageText text
|
||||
) {
|
||||
return messageService.ShowQuestion(
|
||||
MessageBoxIcon.Question, text, MessageBoxButtons.YesNo
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>Asks the user a question that can be answered with ok or cancel</summary>
|
||||
/// <param name="messageService">
|
||||
/// Message service that will be used to display the question
|
||||
/// </param>
|
||||
/// <param name="text">Text that will be shown on the message box</param>
|
||||
/// <returns>The button the user has clicked on</returns>
|
||||
public static DialogResult AskOkCancel(
|
||||
this IMessageService messageService, MessageText text
|
||||
) {
|
||||
return messageService.ShowQuestion(
|
||||
MessageBoxIcon.Question, text, MessageBoxButtons.OKCancel
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asks the user a question that can be answered with yes, no or cancel
|
||||
/// </summary>
|
||||
/// <param name="messageService">
|
||||
/// Message service that will be used to display the question
|
||||
/// </param>
|
||||
/// <param name="text">Text that will be shown on the message box</param>
|
||||
/// <returns>The button the user has clicked on</returns>
|
||||
public static DialogResult AskYesNoCancel(
|
||||
this IMessageService messageService, MessageText text
|
||||
) {
|
||||
return messageService.ShowQuestion(
|
||||
MessageBoxIcon.Question, text, MessageBoxButtons.YesNoCancel
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>Displays an informative message</summary>
|
||||
/// <param name="messageService">
|
||||
/// Message service that will be used to display the warning
|
||||
/// </param>
|
||||
/// <param name="text">Text to be displayed on the warning message</param>
|
||||
public static void Inform(
|
||||
this IMessageService messageService, MessageText text
|
||||
) {
|
||||
messageService.ShowNotification(MessageBoxIcon.Information, text);
|
||||
}
|
||||
|
||||
/// <summary>Displays a warning</summary>
|
||||
/// <param name="messageService">
|
||||
/// Message service that will be used to display the warning
|
||||
/// </param>
|
||||
/// <param name="text">Text to be displayed on the warning message</param>
|
||||
public static void Warn(
|
||||
this IMessageService messageService, MessageText text
|
||||
) {
|
||||
messageService.ShowNotification(MessageBoxIcon.Warning, text);
|
||||
}
|
||||
|
||||
/// <summary>Reports an error</summary>
|
||||
/// <param name="messageService">
|
||||
/// Message service that will be used to display the warning
|
||||
/// </param>
|
||||
/// <param name="text">Text to be displayed on the warning message</param>
|
||||
public static void ReportError(
|
||||
this IMessageService messageService, MessageText text
|
||||
) {
|
||||
messageService.ShowNotification(MessageBoxIcon.Error, text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Windows.Forms.Messages
|
||||
#region Apache License 2.0
|
||||
/*
|
||||
Nuclex .NET Framework
|
||||
Copyright (C) 2002-2024 Markus Ewald / Nuclex Development Labs
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Nuclex.Windows.Forms.Messages {
|
||||
|
||||
/// <summary>Contains helper methods for the message service</summary>
|
||||
public static class MessageServiceHelper {
|
||||
|
||||
/// <summary>Asks the user a question that can be answered with yes or no</summary>
|
||||
/// <param name="messageService">
|
||||
/// Message service that will be used to display the question
|
||||
/// </param>
|
||||
/// <param name="text">Text that will be shown on the message box</param>
|
||||
/// <returns>The button the user has clicked on</returns>
|
||||
public static DialogResult AskYesNo(
|
||||
this IMessageService messageService, MessageText text
|
||||
) {
|
||||
return messageService.ShowQuestion(
|
||||
MessageBoxIcon.Question, text, MessageBoxButtons.YesNo
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>Asks the user a question that can be answered with ok or cancel</summary>
|
||||
/// <param name="messageService">
|
||||
/// Message service that will be used to display the question
|
||||
/// </param>
|
||||
/// <param name="text">Text that will be shown on the message box</param>
|
||||
/// <returns>The button the user has clicked on</returns>
|
||||
public static DialogResult AskOkCancel(
|
||||
this IMessageService messageService, MessageText text
|
||||
) {
|
||||
return messageService.ShowQuestion(
|
||||
MessageBoxIcon.Question, text, MessageBoxButtons.OKCancel
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asks the user a question that can be answered with yes, no or cancel
|
||||
/// </summary>
|
||||
/// <param name="messageService">
|
||||
/// Message service that will be used to display the question
|
||||
/// </param>
|
||||
/// <param name="text">Text that will be shown on the message box</param>
|
||||
/// <returns>The button the user has clicked on</returns>
|
||||
public static DialogResult AskYesNoCancel(
|
||||
this IMessageService messageService, MessageText text
|
||||
) {
|
||||
return messageService.ShowQuestion(
|
||||
MessageBoxIcon.Question, text, MessageBoxButtons.YesNoCancel
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>Displays an informative message</summary>
|
||||
/// <param name="messageService">
|
||||
/// Message service that will be used to display the warning
|
||||
/// </param>
|
||||
/// <param name="text">Text to be displayed on the warning message</param>
|
||||
public static void Inform(
|
||||
this IMessageService messageService, MessageText text
|
||||
) {
|
||||
messageService.ShowNotification(MessageBoxIcon.Information, text);
|
||||
}
|
||||
|
||||
/// <summary>Displays a warning</summary>
|
||||
/// <param name="messageService">
|
||||
/// Message service that will be used to display the warning
|
||||
/// </param>
|
||||
/// <param name="text">Text to be displayed on the warning message</param>
|
||||
public static void Warn(
|
||||
this IMessageService messageService, MessageText text
|
||||
) {
|
||||
messageService.ShowNotification(MessageBoxIcon.Warning, text);
|
||||
}
|
||||
|
||||
/// <summary>Reports an error</summary>
|
||||
/// <param name="messageService">
|
||||
/// Message service that will be used to display the warning
|
||||
/// </param>
|
||||
/// <param name="text">Text to be displayed on the warning message</param>
|
||||
public static void ReportError(
|
||||
this IMessageService messageService, MessageText text
|
||||
) {
|
||||
messageService.ShowNotification(MessageBoxIcon.Error, text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Windows.Forms.Messages
|
||||
|
|
|
@ -1,51 +1,50 @@
|
|||
#region CPL License
|
||||
/*
|
||||
Nuclex Framework
|
||||
Copyright (C) 2002-2019 Nuclex Development Labs
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the IBM Common Public License as
|
||||
published by the IBM Corporation; either version 1.0 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
IBM Common Public License for more details.
|
||||
|
||||
You should have received a copy of the IBM Common Public
|
||||
License along with this library
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Nuclex.Windows.Forms.Messages {
|
||||
|
||||
/// <summary>Unit tests for the message text container</summary>
|
||||
[TestFixture]
|
||||
internal class MessageTextTest {
|
||||
|
||||
/// <summary>Ensures that the message text class provides a copy constructor</summary>
|
||||
[Test]
|
||||
public void HasCopyConstructor() {
|
||||
var text = new MessageText() {
|
||||
Caption = "Caption",
|
||||
Message = "Message",
|
||||
Details = "Details",
|
||||
ExpandedDetails = "ExpandedDetails"
|
||||
};
|
||||
var copy = new MessageText(text);
|
||||
|
||||
Assert.AreEqual(text.Caption, copy.Caption);
|
||||
Assert.AreEqual(text.Message, copy.Message);
|
||||
Assert.AreEqual(text.Details, copy.Details);
|
||||
Assert.AreEqual(text.ExpandedDetails, copy.ExpandedDetails);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Windows.Forms.Messages
|
||||
#region Apache License 2.0
|
||||
/*
|
||||
Nuclex .NET Framework
|
||||
Copyright (C) 2002-2024 Markus Ewald / Nuclex Development Labs
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Nuclex.Windows.Forms.Messages {
|
||||
|
||||
/// <summary>Unit tests for the message text container</summary>
|
||||
[TestFixture]
|
||||
internal class MessageTextTest {
|
||||
|
||||
/// <summary>Ensures that the message text class provides a copy constructor</summary>
|
||||
[Test]
|
||||
public void HasCopyConstructor() {
|
||||
var text = new MessageText() {
|
||||
Caption = "Caption",
|
||||
Message = "Message",
|
||||
Details = "Details",
|
||||
ExpandedDetails = "ExpandedDetails"
|
||||
};
|
||||
var copy = new MessageText(text);
|
||||
|
||||
Assert.AreEqual(text.Caption, copy.Caption);
|
||||
Assert.AreEqual(text.Message, copy.Message);
|
||||
Assert.AreEqual(text.Details, copy.Details);
|
||||
Assert.AreEqual(text.ExpandedDetails, copy.ExpandedDetails);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Windows.Forms.Messages
|
||||
|
|
|
@ -1,55 +1,54 @@
|
|||
#region CPL License
|
||||
/*
|
||||
Nuclex Framework
|
||||
Copyright (C) 2002-2019 Nuclex Development Labs
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the IBM Common Public License as
|
||||
published by the IBM Corporation; either version 1.0 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
IBM Common Public License for more details.
|
||||
|
||||
You should have received a copy of the IBM Common Public
|
||||
License along with this library
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace Nuclex.Windows.Forms.Messages {
|
||||
|
||||
/// <summary>Text that will be displayed in a message box</summary>
|
||||
public class MessageText {
|
||||
|
||||
/// <summary>Initializs a new message text</summary>
|
||||
public MessageText() { }
|
||||
|
||||
/// <summary>Initializes a new message text by copying another instance</summary>
|
||||
/// <param name="other">Instance that will be copied</param>
|
||||
public MessageText(MessageText other) {
|
||||
Caption = other.Caption;
|
||||
Message = other.Message;
|
||||
Details = other.Details;
|
||||
ExpandedDetails = other.ExpandedDetails;
|
||||
}
|
||||
|
||||
/// <summary>The caption used when the is displayed in a message box</summary>
|
||||
public string Caption { get; set; }
|
||||
/// <summary>Main message being displayed to the user</summary>
|
||||
public string Message { get; set; }
|
||||
/// <summary>Message details shown below the main message</summary>
|
||||
public string Details { get; set; }
|
||||
/// <summary>
|
||||
/// Additional informations the user can display by expanding
|
||||
/// the message dialog. Can be null, in which case the message dialog
|
||||
/// will not be expandable.
|
||||
/// </summary>
|
||||
public string ExpandedDetails { get; set; }
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Windows.Forms.Messages
|
||||
#region Apache License 2.0
|
||||
/*
|
||||
Nuclex .NET Framework
|
||||
Copyright (C) 2002-2024 Markus Ewald / Nuclex Development Labs
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
using System;
|
||||
|
||||
namespace Nuclex.Windows.Forms.Messages {
|
||||
|
||||
/// <summary>Text that will be displayed in a message box</summary>
|
||||
public class MessageText {
|
||||
|
||||
/// <summary>Initializs a new message text</summary>
|
||||
public MessageText() { }
|
||||
|
||||
/// <summary>Initializes a new message text by copying another instance</summary>
|
||||
/// <param name="other">Instance that will be copied</param>
|
||||
public MessageText(MessageText other) {
|
||||
Caption = other.Caption;
|
||||
Message = other.Message;
|
||||
Details = other.Details;
|
||||
ExpandedDetails = other.ExpandedDetails;
|
||||
}
|
||||
|
||||
/// <summary>The caption used when the is displayed in a message box</summary>
|
||||
public string Caption { get; set; }
|
||||
/// <summary>Main message being displayed to the user</summary>
|
||||
public string Message { get; set; }
|
||||
/// <summary>Message details shown below the main message</summary>
|
||||
public string Details { get; set; }
|
||||
/// <summary>
|
||||
/// Additional informations the user can display by expanding
|
||||
/// the message dialog. Can be null, in which case the message dialog
|
||||
/// will not be expandable.
|
||||
/// </summary>
|
||||
public string ExpandedDetails { get; set; }
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Windows.Forms.Messages
|
||||
|
|
|
@ -1,162 +1,161 @@
|
|||
#region CPL License
|
||||
/*
|
||||
Nuclex Framework
|
||||
Copyright (C) 2002-2019 Nuclex Development Labs
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the IBM Common Public License as
|
||||
published by the IBM Corporation; either version 1.0 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
IBM Common Public License for more details.
|
||||
|
||||
You should have received a copy of the IBM Common Public
|
||||
License along with this library
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Nuclex.Windows.Forms.Messages {
|
||||
|
||||
/// <summary>Uses task dialogs to display message boxes</summary>
|
||||
public class StandardMessageBoxManager : IMessageService {
|
||||
|
||||
#region class MessageScope
|
||||
|
||||
/// <summary>Triggers the message displayed and acknowledged events</summary>
|
||||
private class MessageScope : IDisposable {
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new message scope, triggering the message displayed event
|
||||
/// </summary>
|
||||
/// <param name="self">Message service the scope belongs to</param>
|
||||
/// <param name="image">Image of the message being displayed</param>
|
||||
/// <param name="text">Text contained in the message being displayed</param>
|
||||
public MessageScope(
|
||||
StandardMessageBoxManager self, MessageBoxIcon image, MessageText text
|
||||
) {
|
||||
EventHandler<MessageEventArgs> messageDisplayed = self.MessageDisplaying;
|
||||
if(messageDisplayed != null) {
|
||||
messageDisplayed(this, new MessageEventArgs(image, text));
|
||||
}
|
||||
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
/// <summary>Triggers the message acknowledged event</summary>
|
||||
public void Dispose() {
|
||||
EventHandler messageAcknowledged = self.MessageAcknowledged;
|
||||
if(messageAcknowledged != null) {
|
||||
messageAcknowledged(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Message service the scope belongs to</summary>
|
||||
private StandardMessageBoxManager self;
|
||||
|
||||
}
|
||||
|
||||
#endregion // class MessageScope
|
||||
|
||||
/// <summary>Delegate for the standard message box show function</summary>
|
||||
/// <param name="owner">Window that will modally display the message box</param>
|
||||
/// <param name="text">Text that will be presented to the user</param>
|
||||
/// <param name="caption">Contents of the message box' title bar</param>
|
||||
/// <param name="buttons">Buttons available for the user to choose from</param>
|
||||
/// <param name="icon">Icon that will be displayed next to the text</param>
|
||||
/// <returns>The choice made by the user if multiple buttons were provided</returns>
|
||||
private delegate DialogResult ShowMessageBoxDelegate(
|
||||
IWin32Window owner,
|
||||
string text,
|
||||
string caption,
|
||||
MessageBoxButtons buttons,
|
||||
MessageBoxIcon icon
|
||||
);
|
||||
|
||||
/// <summary>Triggered when a message is displayed to the user</summary>
|
||||
public event EventHandler<MessageEventArgs> MessageDisplaying;
|
||||
|
||||
/// <summary>Triggered when the user has acknowledged the current message</summary>
|
||||
public event EventHandler MessageAcknowledged;
|
||||
|
||||
/// <summary>Initializes a new task dialog message service</summary>
|
||||
public StandardMessageBoxManager() : this(NullActiveWindowTracker.Default) { }
|
||||
|
||||
/// <summary>Initializes a new task dialog message service</summary>
|
||||
/// <param name="tracker">
|
||||
/// Active window tracker used to obtain the parent window for message boxes
|
||||
/// </param>
|
||||
public StandardMessageBoxManager(IActiveWindowTracker tracker) {
|
||||
this.tracker = tracker;
|
||||
this.showMessageDelegate = new ShowMessageBoxDelegate(MessageBox.Show);
|
||||
}
|
||||
|
||||
/// <summary>Asks the user a question that can be answered via several buttons</summary>
|
||||
/// <param name="image">Image that will be shown on the message box</param>
|
||||
/// <param name="text">Text that will be shown to the user</param>
|
||||
/// <param name="buttons">Buttons available for the user to click on</param>
|
||||
/// <returns>The button the user has clicked on</returns>
|
||||
public DialogResult ShowQuestion(
|
||||
MessageBoxIcon image, MessageText text, MessageBoxButtons buttons
|
||||
) {
|
||||
using(var scope = new MessageScope(this, image, text)) {
|
||||
return showMessageBoxInActiveUiThread(
|
||||
text.Message,
|
||||
text.Caption,
|
||||
buttons,
|
||||
image
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Displays a notification to the user</summary>
|
||||
/// <param name="image">Image that will be shown on the message bx</param>
|
||||
/// <param name="text">Text that will be shown to the user</param>
|
||||
public void ShowNotification(MessageBoxIcon image, MessageText text) {
|
||||
using(var scope = new MessageScope(this, image, text)) {
|
||||
showMessageBoxInActiveUiThread(
|
||||
text.Message,
|
||||
text.Caption,
|
||||
MessageBoxButtons.OK,
|
||||
image
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Displays the message box in the active view's thread</summary>
|
||||
/// <param name="message">Text that will be presented to the user</param>
|
||||
/// <param name="caption">Contents of the message box' title bar</param>
|
||||
/// <param name="buttons">Buttons available for the user to choose from</param>
|
||||
/// <param name="image">Image that will be displayed next to the text</param>
|
||||
/// <returns></returns>
|
||||
private DialogResult showMessageBoxInActiveUiThread(
|
||||
string message,
|
||||
string caption,
|
||||
MessageBoxButtons buttons,
|
||||
MessageBoxIcon image
|
||||
) {
|
||||
Form mainWindow = this.tracker.ActiveWindow;
|
||||
if(mainWindow != null) {
|
||||
return (DialogResult)mainWindow.Invoke(
|
||||
this.showMessageDelegate,
|
||||
(IWin32Window)mainWindow, message, caption, buttons, image
|
||||
);
|
||||
}
|
||||
|
||||
// No window tracker or unknown main window -- just show the message box
|
||||
return MessageBox.Show(message, caption, buttons, image);
|
||||
}
|
||||
|
||||
/// <summary>Provides the currently active top-level window</summary>
|
||||
private IActiveWindowTracker tracker;
|
||||
/// <summary>Delegate for the MessageBox.Show() method</summary>
|
||||
private ShowMessageBoxDelegate showMessageDelegate;
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Windows.Forms.Messages
|
||||
#region Apache License 2.0
|
||||
/*
|
||||
Nuclex .NET Framework
|
||||
Copyright (C) 2002-2024 Markus Ewald / Nuclex Development Labs
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Nuclex.Windows.Forms.Messages {
|
||||
|
||||
/// <summary>Uses task dialogs to display message boxes</summary>
|
||||
public class StandardMessageBoxManager : IMessageService {
|
||||
|
||||
#region class MessageScope
|
||||
|
||||
/// <summary>Triggers the message displayed and acknowledged events</summary>
|
||||
private class MessageScope : IDisposable {
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new message scope, triggering the message displayed event
|
||||
/// </summary>
|
||||
/// <param name="self">Message service the scope belongs to</param>
|
||||
/// <param name="image">Image of the message being displayed</param>
|
||||
/// <param name="text">Text contained in the message being displayed</param>
|
||||
public MessageScope(
|
||||
StandardMessageBoxManager self, MessageBoxIcon image, MessageText text
|
||||
) {
|
||||
EventHandler<MessageEventArgs> messageDisplayed = self.MessageDisplaying;
|
||||
if(messageDisplayed != null) {
|
||||
messageDisplayed(this, new MessageEventArgs(image, text));
|
||||
}
|
||||
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
/// <summary>Triggers the message acknowledged event</summary>
|
||||
public void Dispose() {
|
||||
EventHandler messageAcknowledged = self.MessageAcknowledged;
|
||||
if(messageAcknowledged != null) {
|
||||
messageAcknowledged(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Message service the scope belongs to</summary>
|
||||
private StandardMessageBoxManager self;
|
||||
|
||||
}
|
||||
|
||||
#endregion // class MessageScope
|
||||
|
||||
/// <summary>Delegate for the standard message box show function</summary>
|
||||
/// <param name="owner">Window that will modally display the message box</param>
|
||||
/// <param name="text">Text that will be presented to the user</param>
|
||||
/// <param name="caption">Contents of the message box' title bar</param>
|
||||
/// <param name="buttons">Buttons available for the user to choose from</param>
|
||||
/// <param name="icon">Icon that will be displayed next to the text</param>
|
||||
/// <returns>The choice made by the user if multiple buttons were provided</returns>
|
||||
private delegate DialogResult ShowMessageBoxDelegate(
|
||||
IWin32Window owner,
|
||||
string text,
|
||||
string caption,
|
||||
MessageBoxButtons buttons,
|
||||
MessageBoxIcon icon
|
||||
);
|
||||
|
||||
/// <summary>Triggered when a message is displayed to the user</summary>
|
||||
public event EventHandler<MessageEventArgs> MessageDisplaying;
|
||||
|
||||
/// <summary>Triggered when the user has acknowledged the current message</summary>
|
||||
public event EventHandler MessageAcknowledged;
|
||||
|
||||
/// <summary>Initializes a new task dialog message service</summary>
|
||||
public StandardMessageBoxManager() : this(NullActiveWindowTracker.Default) { }
|
||||
|
||||
/// <summary>Initializes a new task dialog message service</summary>
|
||||
/// <param name="tracker">
|
||||
/// Active window tracker used to obtain the parent window for message boxes
|
||||
/// </param>
|
||||
public StandardMessageBoxManager(IActiveWindowTracker tracker) {
|
||||
this.tracker = tracker;
|
||||
this.showMessageDelegate = new ShowMessageBoxDelegate(MessageBox.Show);
|
||||
}
|
||||
|
||||
/// <summary>Asks the user a question that can be answered via several buttons</summary>
|
||||
/// <param name="image">Image that will be shown on the message box</param>
|
||||
/// <param name="text">Text that will be shown to the user</param>
|
||||
/// <param name="buttons">Buttons available for the user to click on</param>
|
||||
/// <returns>The button the user has clicked on</returns>
|
||||
public DialogResult ShowQuestion(
|
||||
MessageBoxIcon image, MessageText text, MessageBoxButtons buttons
|
||||
) {
|
||||
using(var scope = new MessageScope(this, image, text)) {
|
||||
return showMessageBoxInActiveUiThread(
|
||||
text.Message,
|
||||
text.Caption,
|
||||
buttons,
|
||||
image
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Displays a notification to the user</summary>
|
||||
/// <param name="image">Image that will be shown on the message bx</param>
|
||||
/// <param name="text">Text that will be shown to the user</param>
|
||||
public void ShowNotification(MessageBoxIcon image, MessageText text) {
|
||||
using(var scope = new MessageScope(this, image, text)) {
|
||||
showMessageBoxInActiveUiThread(
|
||||
text.Message,
|
||||
text.Caption,
|
||||
MessageBoxButtons.OK,
|
||||
image
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Displays the message box in the active view's thread</summary>
|
||||
/// <param name="message">Text that will be presented to the user</param>
|
||||
/// <param name="caption">Contents of the message box' title bar</param>
|
||||
/// <param name="buttons">Buttons available for the user to choose from</param>
|
||||
/// <param name="image">Image that will be displayed next to the text</param>
|
||||
/// <returns></returns>
|
||||
private DialogResult showMessageBoxInActiveUiThread(
|
||||
string message,
|
||||
string caption,
|
||||
MessageBoxButtons buttons,
|
||||
MessageBoxIcon image
|
||||
) {
|
||||
Form mainWindow = this.tracker.ActiveWindow;
|
||||
if(mainWindow != null) {
|
||||
return (DialogResult)mainWindow.Invoke(
|
||||
this.showMessageDelegate,
|
||||
(IWin32Window)mainWindow, message, caption, buttons, image
|
||||
);
|
||||
}
|
||||
|
||||
// No window tracker or unknown main window -- just show the message box
|
||||
return MessageBox.Show(message, caption, buttons, image);
|
||||
}
|
||||
|
||||
/// <summary>Provides the currently active top-level window</summary>
|
||||
private IActiveWindowTracker tracker;
|
||||
/// <summary>Delegate for the MessageBox.Show() method</summary>
|
||||
private ShowMessageBoxDelegate showMessageDelegate;
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Windows.Forms.Messages
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue