Skip to content

Commit

Permalink
Merge branch 'tomlm/storageProvider' of https://github.com/jinek/Cons…
Browse files Browse the repository at this point in the history
…olonia into tomlm/storageProvider
  • Loading branch information
tomlm committed Nov 26, 2024
2 parents d8d993b + 6c796b0 commit a4a4468
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 69 deletions.
15 changes: 9 additions & 6 deletions src/Consolonia.Core/Controls/MessageBox.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
WindowStartupLocation="CenterOwner"
Title="{Binding Title}">
<Grid RowDefinitions="Auto Auto">

<TextBlock Text="{Binding Text}" Margin="1"/>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1">

<TextBlock Text="{Binding Text}"
Margin="1" />

<StackPanel Orientation="Horizontal"
HorizontalAlignment="Right"
Grid.Row="1">
<Button x:Name="OkButton"
Content="{Binding OkContent}"
IsVisible="{Binding ShowOkButton}"
Click="OnOk"/>
Click="OnOk" />
<Button x:Name="YesButton"
Content="{Binding YesContent}"
IsVisible="{Binding ShowYesButton}"
Expand All @@ -28,7 +31,7 @@
<Button x:Name="CancelButton"
Content="{Binding CancelContent}"
IsVisible="{Binding ShowCancelButton}"
Click="OnCancel"/>
Click="OnCancel" />
</StackPanel>
</Grid>
</controls:DialogWindow>
118 changes: 61 additions & 57 deletions src/Consolonia.Core/Controls/MessageBox.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,30 @@ public partial class MessageBox : DialogWindow
AvaloniaProperty.RegisterDirect<MessageBox, object>(nameof(Ok), mb => mb.Ok, (mb, value) => mb.Ok = value);

public static readonly DirectProperty<MessageBox, object> CancelProperty =
AvaloniaProperty.RegisterDirect<MessageBox, object>(nameof(Cancel), mb => mb.Cancel, (mb, value) => mb.Cancel = value);
AvaloniaProperty.RegisterDirect<MessageBox, object>(nameof(Cancel), mb => mb.Cancel,
(mb, value) => mb.Cancel = value);

public static readonly DirectProperty<MessageBox, object> YesProperty =
AvaloniaProperty.RegisterDirect<MessageBox, object>(nameof(Yes), mb => mb.Yes, (mb, value) => mb.Yes = value);
AvaloniaProperty.RegisterDirect<MessageBox, object>(nameof(Yes), mb => mb.Yes,
(mb, value) => mb.Yes = value);

public static readonly DirectProperty<MessageBox, object> NoProperty =
AvaloniaProperty.RegisterDirect<MessageBox, object>(nameof(No), mb => mb.No, (mb, value) => mb.No = value);

public static readonly DirectProperty<MessageBox, Mode> ModeProperty =
AvaloniaProperty.RegisterDirect<MessageBox, Mode>(nameof(Mode), mb => mb.Mode, (mb, value) => mb.Mode = value);
AvaloniaProperty.RegisterDirect<MessageBox, Mode>(nameof(Mode), mb => mb.Mode,
(mb, value) => mb.Mode = value);

private object _cancel = "Cancel";

private Mode _mode = Mode.Ok;

private object _no = "No";


private object _ok = "OK";

private object _yes = "Yes";

public MessageBox()
{
Expand All @@ -41,36 +55,30 @@ public MessageBox()
InitializeComponent();
}

private Mode _mode = Mode.Ok;
public Mode Mode
{
get => _mode;
set => SetAndRaise(ModeProperty, ref _mode, value);
}


private object _ok = "OK";
public object Ok
{
get => _ok;
set => SetAndRaise(OkProperty, ref _ok, value);
}

private object _cancel = "Cancel";
public object Cancel
{
get => _cancel;
set => SetAndRaise(CancelProperty, ref _cancel, value);
}

private object _yes = "Yes";
public object Yes
{
get => _yes;
set => SetAndRaise(YesProperty, ref _yes, value);
}

private object _no = "No";
public object No
{
get => _no;
Expand All @@ -79,13 +87,10 @@ public object No

public async Task<MessageBoxResult> ShowDialogAsync(Control parent, string text, string title = null)
{
DataContext = new MessageBoxViewModel(Mode, Ok, Cancel, Yes, No, text, title ?? this.Title);
DataContext = new MessageBoxViewModel(Mode, Ok, Cancel, Yes, No, text, title ?? Title);
#nullable enable
var result = await ShowDialogAsync<MessageBoxResult?>(parent);
if (result.HasValue)
{
return result.Value;
}
if (result.HasValue) return result.Value;

Check notice on line 93 in src/Consolonia.Core/Controls/MessageBox.axaml.cs

View workflow job for this annotation

GitHub Actions / build

"[ConvertIfStatementToReturnStatement] Convert into 'return' statement" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Controls/MessageBox.axaml.cs(93,13)
return MessageBoxResult.Cancel;
#nullable disable
}
Expand All @@ -97,39 +102,47 @@ private void InitializeComponent()


private void OnOk(object sender, RoutedEventArgs e)
=> CloseDialog(MessageBoxResult.Ok);
{
CloseDialog(MessageBoxResult.Ok);
}

private void OnCancel(object sender, RoutedEventArgs e)
=> CloseDialog(MessageBoxResult.Cancel);
{
CloseDialog(MessageBoxResult.Cancel);
}

private void OnYes(object sender, RoutedEventArgs e)
=> CloseDialog(MessageBoxResult.Yes);
{
CloseDialog(MessageBoxResult.Yes);
}

private void OnNo(object sender, RoutedEventArgs e)
=> CloseDialog(MessageBoxResult.No);
{
CloseDialog(MessageBoxResult.No);
}
}

public enum Mode
{
/// <summary>
/// Specifies that the message box contains an OK button.
/// Specifies that the message box contains an OK button.
/// </summary>
Ok,

/// <summary>
/// Specifies that the message box contains OK and Cancel buttons.
/// Specifies that the message box contains OK and Cancel buttons.
/// </summary>
OkCancel,

/// <summary>
/// Specifies that the message box contains Yes and No buttons.
/// Specifies that the message box contains Yes and No buttons.
/// </summary>
YesNo,

/// <summary>
/// Specifies that the message box contains Yes, No, and Cancel buttons.
/// Specifies that the message box contains Yes, No, and Cancel buttons.
/// </summary>
YesNoCancel,
YesNoCancel
}

public enum MessageBoxResult
Expand All @@ -142,7 +155,30 @@ public enum MessageBoxResult

internal partial class MessageBoxViewModel : ObservableObject
{
internal MessageBoxViewModel(Mode mode, object okContent, object cancelContent, object yesContent, object noContent, string text, string title)
[ObservableProperty] private object _cancelContent;

[ObservableProperty] private Mode _mode;

[ObservableProperty] private object _noContent;

[ObservableProperty] private object _okContent;

[ObservableProperty] private bool _showCancelButton;

[ObservableProperty] private bool _showNoButton;

[ObservableProperty] private bool _showOkButton;

[ObservableProperty] private bool _showYesButton;

[ObservableProperty] private string _text;

[ObservableProperty] private string _title;

[ObservableProperty] private object _yesContent;

internal MessageBoxViewModel(Mode mode, object okContent, object cancelContent, object yesContent,
object noContent, string text, string title)
{
_mode = mode;
switch (mode)
Expand All @@ -164,45 +200,13 @@ internal MessageBoxViewModel(Mode mode, object okContent, object cancelContent,
ShowCancelButton = true;
break;
}

_okContent = okContent;
_cancelContent = cancelContent;
_yesContent = yesContent;
_noContent = noContent;
_text = text;
_title = title;
}

[ObservableProperty]
private Mode _mode;

[ObservableProperty]
private string _title;

[ObservableProperty]
private bool _showCancelButton;

[ObservableProperty]
private bool _showOkButton;

[ObservableProperty]
private bool _showYesButton;

[ObservableProperty]
private bool _showNoButton;

[ObservableProperty]
private object _okContent;

[ObservableProperty]
private object _cancelContent;

[ObservableProperty]
private object _yesContent;

[ObservableProperty]
private object _noContent;

[ObservableProperty]
private string _text;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
Margin="{DynamicResource ConsoloniaDialogWindowBorderMargin}"
ZIndex="10"
Orientation="Horizontal">
<helpers:SymbolsControl Text="{TemplateBinding Icon}" IsVisible="{Binding Icon.Length}"
<helpers:SymbolsControl Text="{TemplateBinding Icon}"
IsVisible="{Binding Icon.Length}"
Foreground="{TemplateBinding BorderBrush}" />
<TextBlock Text="{TemplateBinding Title}"
Margin="1 0 0 0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ public override void Render(DrawingContext context)
{
// Draw the text as a repeating pattern
var formattedText = new FormattedText(
string.Concat(
Enumerable.Repeat(Text, (int)Bounds.Width / Text.MeasureText())),
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
Typeface.Default, 1, Foreground);
string.Concat(
Enumerable.Repeat(Text, (int)Bounds.Width / Text.MeasureText())),
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
Typeface.Default, 1, Foreground);
for (int y = 0; y < Bounds.Height; y++)
context.DrawText(formattedText, new Point(0, y));
}
Expand Down

0 comments on commit a4a4468

Please sign in to comment.