Skip to content

Commit

Permalink
Merge pull request irihitech#65 from irihitech/messagebox
Browse files Browse the repository at this point in the history
New control: Messagebox
  • Loading branch information
zdpcdt authored Jan 15, 2024
2 parents 5cf6b8a + 7e30e64 commit eaf9f06
Show file tree
Hide file tree
Showing 15 changed files with 605 additions and 0 deletions.
1 change: 1 addition & 0 deletions demo/Ursa.Demo/Models/MenuKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static class MenuKeys
public const string MenuKeyIconButton = "IconButton";
public const string MenuKeyKeyGestureInput = "KeyGestureInput";
public const string MenuKeyLoading = "Loading";
public const string MenuKeyMessageBox = "MessageBox";
public const string MenuKeyNavigation = "Navigation";
public const string MenuKeyPagination = "Pagination";
public const string MenuKeyTagInput = "TagInput";
Expand Down
34 changes: 34 additions & 0 deletions demo/Ursa.Demo/Pages/MessageBoxDemo.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<UserControl
x:Class="Ursa.Demo.Pages.MessageBoxDemo"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:Ursa.Demo.ViewModels"
d:DesignHeight="450"
d:DesignWidth="800"
x:CompileBindings="True"
x:DataType="vm:MessageBoxDemoViewModel"
mc:Ignorable="d">
<UserControl.Styles>
<Style Selector="Button">
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="Margin" Value="8"></Setter>
</Style>
</UserControl.Styles>
<StackPanel HorizontalAlignment="Left">
<ComboBox ItemsSource="{Binding Icons}" SelectedItem="{Binding SelectedIcon}" />
<ToggleSwitch Content="Try Long Message" IsChecked="{Binding UseLong}"></ToggleSwitch>
<ToggleSwitch Content="Show Title" IsChecked="{Binding UseTitle}"></ToggleSwitch>
<Button Command="{Binding DefaultMessageBoxCommand}" Content="Default" />
<Button Command="{Binding OkCommand}" Content="OK" />
<Button Command="{Binding OkCancelCommand}" Content="OKCancel" />
<Button Command="{Binding YesNoCommand}" Content="YesNo" />
<Button Command="{Binding YesNoCancelCommand}" Content="YesNoCancel" />

<TextBlock>
<Run Text="Last Clicked Result: "></Run>
<Run Text="{Binding Result}"></Run>
</TextBlock>
</StackPanel>
</UserControl>
15 changes: 15 additions & 0 deletions demo/Ursa.Demo/Pages/MessageBoxDemo.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Ursa.Demo.ViewModels;

namespace Ursa.Demo.Pages;

public partial class MessageBoxDemo : UserControl
{
public MessageBoxDemo()
{
InitializeComponent();
this.DataContext = new MessageBoxDemoViewModel();
}
}
1 change: 1 addition & 0 deletions demo/Ursa.Demo/ViewModels/MainViewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private void OnNavigation(MainViewViewModel vm, string s)
MenuKeys.MenuKeyIpBox => new IPv4BoxDemoViewModel(),
MenuKeys.MenuKeyKeyGestureInput => new KeyGestureInputDemoViewModel(),
MenuKeys.MenuKeyLoading => new LoadingDemoViewModel(),
MenuKeys.MenuKeyMessageBox => new MessageBoxDemoViewModel(),
MenuKeys.MenuKeyNavigation => new NavigationMenuDemoViewModel(),
MenuKeys.MenuKeyPagination => new PaginationDemoViewModel(),
MenuKeys.MenuKeyTagInput => new TagInputDemoViewModel(),
Expand Down
1 change: 1 addition & 0 deletions demo/Ursa.Demo/ViewModels/MenuViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public MenuViewModel()
new() { MenuHeader = "IPv4Box", Key = MenuKeys.MenuKeyIpBox },
new() { MenuHeader = "KeyGestureInput", Key = MenuKeys.MenuKeyKeyGestureInput },
new() { MenuHeader = "Loading", Key = MenuKeys.MenuKeyLoading },
new() { MenuHeader = "Message Box", Key = MenuKeys.MenuKeyMessageBox },
new() { MenuHeader = "Navigation", Key = MenuKeys.MenuKeyNavigation },
new() { MenuHeader = "Pagination", Key = MenuKeys.MenuKeyPagination },
new() { MenuHeader = "TagInput", Key = MenuKeys.MenuKeyTagInput },
Expand Down
105 changes: 105 additions & 0 deletions demo/Ursa.Demo/ViewModels/MessageBoxDemoViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Ursa.Controls;

namespace Ursa.Demo.ViewModels;

public class MessageBoxDemoViewModel: ObservableObject
{
private readonly string _longMessage = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

private readonly string _shortMessage = "Welcome to Ursa Avalonia!";
private string _message;
private string _title;

public ICommand DefaultMessageBoxCommand { get; set; }
public ICommand OkCommand { get; set; }
public ICommand YesNoCommand { get; set; }
public ICommand YesNoCancelCommand { get; set; }
public ICommand OkCancelCommand { get; set; }

public ObservableCollection<MessageBoxIcon> Icons { get; set; }

private MessageBoxIcon _selectedIcon;
public MessageBoxIcon SelectedIcon
{
get => _selectedIcon;
set => SetProperty(ref _selectedIcon, value);
}

private MessageBoxResult _result;
public MessageBoxResult Result
{
get => _result;
set => SetProperty(ref _result, value);
}

private bool _useLong;

public bool UseLong
{
get => _useLong;
set
{
SetProperty(ref _useLong, value);
_message = value ? _longMessage : _shortMessage;
}
}

private bool _useTitle;

public bool UseTitle
{
get => _useTitle;
set
{
SetProperty(ref _useTitle, value);
_title = value ? "Ursa MessageBox" : string.Empty;
}
}




public MessageBoxDemoViewModel()
{
DefaultMessageBoxCommand = new AsyncRelayCommand(OnDefaultMessageAsync);
OkCommand = new AsyncRelayCommand(OnOkAsync);
YesNoCommand = new AsyncRelayCommand(OnYesNoAsync);
YesNoCancelCommand = new AsyncRelayCommand(OnYesNoCancelAsync);
OkCancelCommand = new AsyncRelayCommand(OnOkCancelAsync);
Icons = new ObservableCollection<MessageBoxIcon>(
Enum.GetValues<MessageBoxIcon>());
SelectedIcon = MessageBoxIcon.None;
_message = _shortMessage;
}

private async Task OnDefaultMessageAsync()
{
Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon);
}

private async Task OnOkAsync()
{
Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon, button:MessageBoxButton.OK);
}

private async Task OnYesNoAsync()
{
Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon, button: MessageBoxButton.YesNo);
}

private async Task OnYesNoCancelAsync()
{
Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon, button: MessageBoxButton.YesNoCancel);
}

private async Task OnOkCancelAsync()
{
Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon, button:MessageBoxButton.OKCancel);
}
}
149 changes: 149 additions & 0 deletions src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="https://irihi.tech/ursa">
<!-- Add Resources Here -->
<ControlTheme x:Key="{x:Type u:MessageBoxWindow}" TargetType="u:MessageBoxWindow">
<Setter Property="Title" Value="{x:Null}" />
<Setter Property="Background" Value="{DynamicResource WindowDefaultBackground}" />
<Setter Property="TransparencyBackgroundFallback" Value="{DynamicResource WindowDefaultBackground}" />
<Setter Property="Foreground" Value="{DynamicResource WindowDefaultForeground}" />
<Setter Property="FontSize" Value="{DynamicResource DefaultFontSize}" />
<Setter Property="FontFamily" Value="{DynamicResource DefaultFontFamily}" />
<Setter Property="Padding" Value="48 24" />
<Setter Property="SizeToContent" Value="WidthAndHeight" />
<Setter Property="WindowStartupLocation" Value="CenterOwner" />
<Setter Property="ExtendClientAreaTitleBarHeightHint" Value="0" />
<Setter Property="ExtendClientAreaToDecorationsHint" Value="True" />
<Setter Property="SystemDecorations" Value="BorderOnly" />
<Setter Property="CanResize" Value="False" />
<Setter Property="Template">
<ControlTemplate TargetType="u:MessageBoxWindow">
<Panel>
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" />
<Border Background="{TemplateBinding Background}" IsHitTestVisible="False" />
<Panel Margin="{TemplateBinding WindowDecorationMargin}" Background="Transparent" />
<Grid RowDefinitions="Auto, *, Auto">
<Grid Grid.Row="0" ColumnDefinitions="*, Auto">
<TextBlock
Grid.Column="0"
Margin="8,8,0,0"
FontSize="14"
FontWeight="Bold"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap"
Text="{TemplateBinding Title}" />
<!-- A temporary style copied from Semi. Will replace when I get time -->
<Button
Name="{x:Static u:MessageBoxWindow.PART_CloseButton}"
Grid.Column="1"
Margin="0,4,4,0"
Background="{DynamicResource CaptionButtonClosePointeroverBackground}"
BorderBrush="{DynamicResource CaptionButtonClosePressedBackground}"
Theme="{DynamicResource CaptionButton}">
<Button.Styles>
<Style Selector="Button:pointerover">
<Setter Property="Foreground" Value="White" />
</Style>
<Style Selector="Button:pressed">
<Setter Property="Foreground" Value="White" />
</Style>
</Button.Styles>
<PathIcon
Width="12"
Height="12"
Data="{DynamicResource WindowCloseIconGlyph}"
Foreground="{Binding $parent[Button].Foreground}" />
</Button>
</Grid>
<Grid
Grid.Row="1"
Margin="{TemplateBinding Padding}"
MaxWidth="{DynamicResource MessageBoxWindowContentMaxWidth}"
ColumnDefinitions="Auto, *">
<PathIcon
Name="PART_Icon"
Grid.Column="0"
Width="24"
Height="24"
Margin="0,0,12,0"
VerticalAlignment="Center" />
<ScrollViewer
Grid.Column="1"
MaxHeight="300"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto">
<TextBlock
Name="PART_ContentPresenter"
VerticalAlignment="Center"
Text="{TemplateBinding Content}"
TextAlignment="Left"
TextWrapping="Wrap" />
</ScrollViewer>
</Grid>
<StackPanel
Grid.Row="2"
Margin="0,0,8,8"
HorizontalAlignment="Right"
Orientation="Horizontal">
<Button
Name="{x:Static u:MessageBoxWindow.PART_CancelButton}"
Margin="8,0,0,0"
Classes="Tertiary"
Content="Cancel" />
<Button
Name="{x:Static u:MessageBoxWindow.PART_NoButton}"
Margin="8,0,0,0"
Classes="Danger"
Content="No" />
<Button
Name="{x:Static u:MessageBoxWindow.PART_YesButton}"
Margin="8,0,0,0"
Classes="Primary"
Content="Yes" />
<Button
Name="{x:Static u:MessageBoxWindow.PART_OKButton}"
Margin="8,0,0,0"
Classes="Primary"
Content="OK" />
</StackPanel>
</Grid>
</Panel>
</ControlTemplate>
</Setter>
<Style Selector="^[MessageIcon=None] /template/ PathIcon#PART_Icon">
<Setter Property="IsVisible" Value="False" />
</Style>
<Style Selector="^[MessageIcon=Asterisk] /template/ PathIcon#PART_Icon, ^[MessageIcon=Information] /template/ PathIcon#PART_Icon">
<Setter Property="IsVisible" Value="True" />
<Setter Property="Foreground" Value="{DynamicResource SemiBlue6}" />
<Setter Property="Data" Value="{DynamicResource MessageBoxWindowInformationIconGlyph}" />
</Style>
<Style Selector="^[MessageIcon=Error] /template/ PathIcon#PART_Icon, ^[MessageIcon=Hand] /template/ PathIcon#PART_Icon, ^[MessageIcon=Stop] /template/ PathIcon#PART_Icon">
<Setter Property="IsVisible" Value="True" />
<Setter Property="Foreground" Value="{DynamicResource SemiRed6}" />
<Setter Property="Data" Value="{DynamicResource MessageBoxWindowErrorIconGlyph}" />
</Style>
<Style Selector="^[MessageIcon=Exclamation] /template/ PathIcon#PART_Icon">
<Setter Property="IsVisible" Value="True" />
<Setter Property="Foreground" Value="{DynamicResource SemiYellow6}" />
<Setter Property="Data" Value="{DynamicResource MessageBoxWindowWarningIconGlyph}" />
</Style>
<Style Selector="^[MessageIcon=Question] /template/ PathIcon#PART_Icon">
<Setter Property="IsVisible" Value="True" />
<Setter Property="Foreground" Value="{DynamicResource SemiBlue6}" />
<Setter Property="Data" Value="{DynamicResource MessageBoxWindowQuestionIconGlyph}" />
</Style>
<Style Selector="^[MessageIcon=Warning] /template/ PathIcon#PART_Icon">
<Setter Property="IsVisible" Value="True" />
<Setter Property="Foreground" Value="{DynamicResource SemiOrange6}" />
<Setter Property="Data" Value="{DynamicResource MessageBoxWindowWarningIconGlyph}" />
</Style>
<Style Selector="^[MessageIcon=Success] /template/ PathIcon#PART_Icon">
<Setter Property="IsVisible" Value="True" />
<Setter Property="Foreground" Value="{DynamicResource SemiGreen6}" />
<Setter Property="Data" Value="{DynamicResource MessageBoxWindowSuccessIconGlyph}" />
</Style>

</ControlTheme>
</ResourceDictionary>
1 change: 1 addition & 0 deletions src/Ursa.Themes.Semi/Controls/_index.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ResourceInclude Source="IPv4Box.axaml" />
<ResourceInclude Source="KeyGestureInput.axaml" />
<ResourceInclude Source="Loading.axaml" />
<ResourceInclude Source="MessageBoxWindow.axaml" />
<ResourceInclude Source="Navigation.axaml" />
<ResourceInclude Source="Pagination.axaml" />
<ResourceInclude Source="TagInput.axaml" />
Expand Down
Loading

0 comments on commit eaf9f06

Please sign in to comment.