Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jamsoft committed May 26, 2024
2 parents 6362b69 + dad9be1 commit 9787593
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 35 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ var btnResult = await _messageBoxService.Show(viewModel);
<Setter Property="Fill" Value="Red"/>
</Style>
```

### Custom Button Text
```csharp
var result = await _messageBoxService.Show("German Yes No Cancel", "Möchten Sie weitermachen?",
MsgBoxButton.YesNoCancel,
MsgBoxImage.Question, "Nein", "Ja", "Abbrechen");
```
# File Paths
### Open Any File
```csharp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,6 @@ public MainWindowViewModel(IDialogService dialogService, IMessageBoxService mess
ShowMessageBoxCommand = new DelegateCommand(ShowMessageBoxCommandExecuted, () => true);
}

private async void ShowMessageBoxCommandExecuted()
{
var resultOkCancel = await _messageBoxService.Show("OK Cancel", "Do you want to carry on?", MsgBoxButton.OkCancel, MsgBoxImage.Error);
Message = $"{resultOkCancel} clicked";

var resultOk = await _messageBoxService.Show("Ok", "Do you want to carry on?", MsgBoxButton.Ok, MsgBoxImage.Information);
Message = $"{resultOk} clicked";

var resultYesNo = await _messageBoxService.Show("Yes No", "Do you want to carry on?", MsgBoxButton.YesNo, MsgBoxImage.Asterisk);
Message = $"{resultYesNo} clicked";

var resultYesNoCancel = await _messageBoxService.Show("Yes No Cancel", "Do you want to carry on?", MsgBoxButton.YesNoCancel, MsgBoxImage.Question);
Message = $"{resultYesNoCancel} clicked";

var resultYesNoWarning = await _messageBoxService.Show("Yes No", "Do you want to carry on?", MsgBoxButton.YesNo, MsgBoxImage.Warning);
Message = $"{resultYesNoWarning} clicked";

var resultYesNoNoIcon = await _messageBoxService.Show("Yes No Without Icon", "Do you want to carry on?", MsgBoxButton.YesNo);
Message = $"{resultYesNoNoIcon} clicked";

var viewModel = new MsgBoxViewModel("Yes No With Icon", "Do you want to carry on?", MsgBoxButton.YesNo, MsgBoxImage.Warning);
var resultVm = await _messageBoxService.Show(viewModel);
Message = $"{resultVm} clicked";
}

public ICommand? ShowMessageBoxCommand
{
get => _showMessageBoxCommand;
Expand Down Expand Up @@ -352,4 +327,32 @@ private void WizardViewCommandExecuted()
_dialogService.StartWizard(vm, model => { Message = $"Wizard Closed - {model.GetType()}"; });
}
}

private async void ShowMessageBoxCommandExecuted()
{
var resultOkCancel = await _messageBoxService.Show("OK Cancel", "Do you want to carry on?", MsgBoxButton.OkCancel, MsgBoxImage.Error);
Message = $"{resultOkCancel} clicked";

var resultOk = await _messageBoxService.Show("Ok", "Do you want to carry on?", MsgBoxButton.Ok, MsgBoxImage.Information);
Message = $"{resultOk} clicked";

var resultYesNo = await _messageBoxService.Show("Yes No", "Do you want to carry on?", MsgBoxButton.YesNo, MsgBoxImage.Asterisk);
Message = $"{resultYesNo} clicked";

var resultYesNoCancel = await _messageBoxService.Show("Yes No Cancel", "Do you want to carry on?", MsgBoxButton.YesNoCancel, MsgBoxImage.Question);
Message = $"{resultYesNoCancel} clicked";

var resultYesNoWarning = await _messageBoxService.Show("Yes No", "Do you want to carry on?", MsgBoxButton.YesNo, MsgBoxImage.Warning);
Message = $"{resultYesNoWarning} clicked";

var resultYesNoNoIcon = await _messageBoxService.Show("Yes No Without Icon", "Do you want to carry on?", MsgBoxButton.YesNo);
Message = $"{resultYesNoNoIcon} clicked";

var viewModel = new MsgBoxViewModel("Yes No With Icon", "Do you want to carry on?", MsgBoxButton.YesNo, MsgBoxImage.Warning);
var resultVm = await _messageBoxService.Show(viewModel);
Message = $"{resultVm} clicked";

var resultYesNoCancelCustomButtonText = await _messageBoxService.Show("German Yes No Cancel", "Möchten Sie weitermachen?", MsgBoxButton.YesNoCancel, MsgBoxImage.Question, "Nein", "Ja", "Abbrechen");
Message = $"{resultYesNoCancelCustomButtonText} clicked";
}
}
9 changes: 6 additions & 3 deletions src/JamSoft.AvaloniaUI.Dialogs/IMessageBoxService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace JamSoft.AvaloniaUI.Dialogs;

/// <summary>
/// The message box service interface
/// </summary>
public interface IMessageBoxService
{
/// <summary>
Expand All @@ -13,15 +16,15 @@ public interface IMessageBoxService
/// <param name="button">the button configuration</param>
/// <param name="icon">the icon enum</param>
/// <param name="noButtonText">the negative response button text value</param>
/// <param name="yesButtonText">the positive response button text</param>
/// <param name="yesButtonText">the positive response button text used for Yes/OK buttons</param>
/// <param name="cancelButtonText">the cancel response button text</param>
/// <returns><see cref="MsgBoxResult"/></returns>
/// <returns>the <see cref="MsgBoxResult"/> response</returns>
Task<MsgBoxResult> Show(string caption, string messageBoxText, MsgBoxButton button, MsgBoxImage icon = MsgBoxImage.None, string? noButtonText = null, string? yesButtonText = null, string? cancelButtonText = null);

/// <summary>
/// Show a message box with the specified view model
/// </summary>
/// <param name="viewModel">the view model instance</param>
/// <returns><see cref="MsgBoxResult"/></returns>
/// <returns>the <see cref="MsgBoxResult"/> response</returns>
Task<MsgBoxResult> Show(IMsgBoxViewModel viewModel);
}
10 changes: 5 additions & 5 deletions src/JamSoft.AvaloniaUI.Dialogs/JamSoft.AvaloniaUI.Dialogs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>JamSoft AvaloniaUI Dialogs</Title>
<Company>JamSoft Solution Ltd</Company>
<Product>JamSoft AvaloniaUI LCD Label Control</Product>
<Product>JamSoft AvaloniaUI Dialog Library</Product>
<Authors>James Green</Authors>
<Description>A standardised service for managing dialogs and child windows in Avalonia UI.</Description>
<Copyright>JamSoft Solutions Ltd 2024</Copyright>
<PackageProjectUrl>https://github.com/jamsoft/JamSoft.AvaloniaUI.Dialogs</PackageProjectUrl>
<RepositoryUrl>https://github.com/jamsoft/JamSoft.AvaloniaUI.Dialogs</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>avalonia, avaloniaui, dialogs, mvvm, wizard</PackageTags>
<PackageTags>avalonia, avaloniaui, dialogs, mvvm, wizard, messagebox</PackageTags>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageIcon>JamSoftLogo-Splat513x513.png</PackageIcon>
<SignAssembly>true</SignAssembly>
Expand All @@ -40,10 +40,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.6" />
<PackageReference Include="Avalonia" Version="11.0.0" />
<AvaloniaResource Include="Assets\**" />
<PackageReference Include="Avalonia.Diagnostics" Version="11.0.6" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.6" />
<PackageReference Include="Avalonia.Diagnostics" Version="11.0.0" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
18 changes: 18 additions & 0 deletions src/JamSoft.AvaloniaUI.Dialogs/MsgBox/MsgBoxButton.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
namespace JamSoft.AvaloniaUI.Dialogs.MsgBox;

/// <summary>
/// The message box button enum
/// </summary>
public enum MsgBoxButton
{
/// <summary>
/// Show the OK button
/// </summary>
Ok,

/// <summary>
/// Show the OK and Cancel buttons
/// </summary>
OkCancel,

/// <summary>
/// Show the Yes and No buttons
/// </summary>
YesNo,

/// <summary>
/// Show the Yes, No and Cancel buttons
/// </summary>
YesNoCancel
}
42 changes: 42 additions & 0 deletions src/JamSoft.AvaloniaUI.Dialogs/MsgBox/MsgBoxImage.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,57 @@
namespace JamSoft.AvaloniaUI.Dialogs.MsgBox;

/// <summary>
/// Specifies the icon to display in a message box
/// </summary>
public enum MsgBoxImage
{
/// <summary>
/// Show no icon
/// </summary>
None,

/// <summary>
/// Show the Asterisk icon
/// </summary>
Asterisk,

/// <summary>
/// Show the Exclamation icon
/// </summary>
Exclamation,

/// <summary>
/// Show the Hand icon
/// </summary>
Hand,

/// <summary>
/// Show the Stop icon
/// </summary>
Stop,

/// <summary>
/// Show the Error icon
/// </summary>
Error,

/// <summary>
/// Show the Question icon
/// </summary>
Question,

/// <summary>
/// Show the Warning icon
/// </summary>
Warning,

/// <summary>
/// Show the Information icon
/// </summary>
Information,

/// <summary>
/// Show a custom icon
/// </summary>
Custom
}
22 changes: 22 additions & 0 deletions src/JamSoft.AvaloniaUI.Dialogs/MsgBox/MsgBoxResult.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
namespace JamSoft.AvaloniaUI.Dialogs.MsgBox;

/// <summary>
/// The message box result enum
/// </summary>
public enum MsgBoxResult
{
/// <summary>
/// The default value
/// </summary>
None,

/// <summary>
/// The OK value
/// </summary>
Ok,

/// <summary>
/// The Cancel value
/// </summary>
Cancel,

/// <summary>
/// The Yes value
/// </summary>
Yes,

/// <summary>
/// The No value
/// </summary>
No
}
6 changes: 5 additions & 1 deletion src/JamSoft.AvaloniaUI.Dialogs/ViewModels/DialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ protected DialogViewModel()
CancelCommandText = "Cancel";
}

/// <summary>
/// Invokes the request close dialog event
/// </summary>
/// <param name="e"></param>
protected void InvokeRequestCloseDialog(RequestCloseDialogEventArgs e)
{
RequestCloseDialog?.Invoke(this, e);
Expand Down Expand Up @@ -142,7 +146,7 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName
}

/// <summary>
///
/// The property changed event
/// </summary>
public event PropertyChangedEventHandler? PropertyChanged;
}
6 changes: 6 additions & 0 deletions src/JamSoft.AvaloniaUI.Dialogs/ViewModels/IMsgBoxViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@

namespace JamSoft.AvaloniaUI.Dialogs.ViewModels;

/// <summary>
/// The message box view model interface
/// </summary>
public interface IMsgBoxViewModel : INotifyPropertyChanged, IDialogResultVmHelper
{
/// <summary>
/// Determines if the dialog has an icon to show
/// </summary>
bool HasIcon { get; }

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions src/JamSoft.AvaloniaUI.Dialogs/ViewModels/MsgBoxViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public MsgBoxViewModel(string caption, string message, MsgBoxButton buttons, Msg
SetupButtons();
}

/// <summary>
/// Determines if the dialog has an icon to show
/// </summary>
public bool HasIcon => Icon is not null;

/// <summary>
Expand All @@ -72,6 +75,9 @@ public MsgBoxImage MsgBoxImage
}
}

/// <summary>
/// Configures the icon for the dialog
/// </summary>
protected virtual void SetImage()
{
if (MsgBoxImage == MsgBoxImage.Custom)
Expand Down
6 changes: 6 additions & 0 deletions src/JamSoft.AvaloniaUI.Dialogs/Views/MsgBoxView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

namespace JamSoft.AvaloniaUI.Dialogs.Views;

/// <summary>
/// The message box view
/// </summary>
public partial class MsgBoxView : UserControl
{
/// <summary>
/// The default constructor
/// </summary>
public MsgBoxView()
{
InitializeComponent();
Expand Down

0 comments on commit 9787593

Please sign in to comment.