-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from Kurokitu/UpdateCheck
UpdateLog更换为Markdown并封装了新的弹窗组件
- Loading branch information
Showing
4 changed files
with
140 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<Window 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:md="https://github.com/whistyun/Markdown.Avalonia" | ||
mc:Ignorable="d" d:DesignWidth="432" d:DesignHeight="604" | ||
x:Class="TuneLab.GUI.UpdateDialog" | ||
Title="TuneLab" | ||
Width="432" | ||
Height="604" | ||
ExtendClientAreaChromeHints="NoChrome" | ||
ExtendClientAreaTitleBarHeightHint="40" | ||
ExtendClientAreaToDecorationsHint="True"> | ||
<Window.Styles> | ||
<Style Selector="TitleBar"> | ||
<Setter Property="Background" Value="DarkGray"/> | ||
<Setter Property="Foreground" Value="White"/> | ||
</Style> | ||
<Style Selector="Window"> | ||
<Setter Property="CornerRadius" Value="12"/> | ||
</Style> | ||
</Window.Styles> | ||
|
||
<DockPanel Margin="0"> | ||
<Grid DockPanel.Dock="Top" x:Name="TitleBar" Height="40"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<StackPanel Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Orientation="Horizontal" IsHitTestVisible="False"> | ||
<Label x:Name="TitleLabel" Content="Update" FontWeight="Bold" FontSize="14" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" /> | ||
</StackPanel> | ||
</Grid> | ||
|
||
<ContentControl x:Name="Content"> | ||
<Grid Margin="0" x:Name="ContentGrid"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition MinHeight="40" /> | ||
<RowDefinition MinHeight="452" /> | ||
<RowDefinition Height="56" /> | ||
</Grid.RowDefinitions> | ||
|
||
<StackPanel Grid.Row="0" Orientation="Vertical" Margin="12,0" VerticalAlignment="Center" x:Name="MessageStackPanel"> | ||
<SelectableTextBlock x:Name="MessageTextBlock" Text="This is a modal window." Foreground="White" TextWrapping="Wrap" TextAlignment="Start" FontSize="14" Padding="0" Margin="0" /> | ||
</StackPanel> | ||
|
||
<StackPanel Grid.Row="1" Orientation="Vertical" Margin="12,0" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="MarkDownStackPanel"> | ||
<md:MarkdownScrollViewer x:Name="MarkDownScrollViewer" /> | ||
</StackPanel> | ||
|
||
<Grid Grid.Row="2" x:Name="ButtonsPanel" Margin="0, 0, 0, 16"/> | ||
</Grid> | ||
</ContentControl> | ||
</DockPanel> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Media; | ||
using System; | ||
using TuneLab.Utils; | ||
using Button = TuneLab.GUI.Components.Button; | ||
using Markdown.Avalonia; | ||
using TuneLab.I18N; | ||
|
||
namespace TuneLab.GUI; | ||
|
||
internal partial class UpdateDialog : Window | ||
{ | ||
public enum ButtonType | ||
{ | ||
Primary, | ||
Normal | ||
} | ||
|
||
private Grid titleBar; | ||
private Label titleLabel; | ||
private SelectableTextBlock messageTextBlock; | ||
private MarkdownScrollViewer markDownScrollViewer; | ||
|
||
public UpdateDialog() | ||
{ | ||
InitializeComponent(); | ||
Focusable = true; | ||
CanResize = false; | ||
WindowState = WindowState.Normal; | ||
WindowStartupLocation = WindowStartupLocation.CenterScreen; | ||
Topmost = true; | ||
|
||
this.DataContext = this; | ||
this.Background = Style.BACK.ToBrush(); | ||
Content.Background = Style.INTERFACE.ToBrush(); | ||
|
||
titleBar = this.FindControl<Grid>("TitleBar") ?? throw new InvalidOperationException("TitleBar not found"); | ||
titleLabel = this.FindControl<Label>("TitleLabel") ?? throw new InvalidOperationException("TitleLabel not found"); | ||
messageTextBlock = this.FindControl<SelectableTextBlock>("MessageTextBlock") ?? throw new InvalidOperationException("MessageTextBlock not found"); | ||
markDownScrollViewer = this.FindControl<MarkdownScrollViewer>("MarkDownScrollViewer") ?? throw new InvalidOperationException("MarkDownScrollViewer not found"); | ||
|
||
titleLabel.Content = "Update Available".Tr(TC.Dialog); | ||
} | ||
|
||
public void SetMessage(string message) | ||
{ | ||
messageTextBlock.Text = message; | ||
} | ||
|
||
public void SetMDMessage(string message) | ||
{ | ||
markDownScrollViewer.Markdown = message; | ||
} | ||
|
||
public Button AddButton(string text, ButtonType type) | ||
{ | ||
ButtonsPanel.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); | ||
var button = new Button() { MinWidth = 96, Height = 40 }; | ||
|
||
if (type == ButtonType.Primary) | ||
button.AddContent(new() { Item = new BorderItem() { CornerRadius = 6 }, ColorSet = new() { Color = Style.BUTTON_PRIMARY, HoveredColor = Style.BUTTON_PRIMARY_HOVER } }); | ||
|
||
if (type == ButtonType.Normal) | ||
button.AddContent(new() { Item = new BorderItem() { CornerRadius = 6 }, ColorSet = new() { Color = Style.BUTTON_NORMAL, HoveredColor = Style.BUTTON_NORMAL_HOVER } }); | ||
|
||
button.AddContent(new() { Item = new TextItem() { Text = text }, ColorSet = new() { Color = type == ButtonType.Primary ? Colors.White : Style.LIGHT_WHITE } }); | ||
|
||
button.Clicked += Close; | ||
var buttonStack = new StackPanel() { Orientation = Avalonia.Layout.Orientation.Horizontal, HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center, Children = { button }, Height = 40, Margin = new(0) }; | ||
|
||
Grid.SetColumn(buttonStack, ButtonsPanel.ColumnDefinitions.Count - 1); | ||
ButtonsPanel.Children.Add(buttonStack); | ||
|
||
return button; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters