style<Welcome>: replace system message dialog with a custom one

This commit is contained in:
leo 2022-11-11 15:54:34 +08:00
parent 5434629f4c
commit a9bc0fec21
4 changed files with 123 additions and 9 deletions

View file

@ -0,0 +1,80 @@
<controls:Window
x:Class="SourceGit.Views.ConfirmDialog"
x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:validations="clr-namespace:SourceGit.Views.Validations"
mc:Ignorable="d"
WindowStartupLocation="CenterOwner"
Width="500" SizeToContent="Height"
ResizeMode="NoResize">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="28"/>
<RowDefinition Height="1"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Title bar -->
<Grid Grid.Row="0" Background="{DynamicResource Brush.TitleBar}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- Icon -->
<Path Grid.Column="0" Margin="6,0" Width="16" Height="16" Data="{StaticResource Icon.Help}"/>
<!-- Title -->
<TextBlock Grid.Column="1" x:Name="txtTitle" Text=""/>
<!-- Close -->
<controls:IconButton
Grid.Column="3"
Click="OnQuit"
Width="28"
IconSize="10"
Icon="{StaticResource Icon.Close}"
HoverBackground="Red"
WindowChrome.IsHitTestVisibleInChrome="True"/>
</Grid>
<Rectangle
Grid.Row="1"
Height="1"
HorizontalAlignment="Stretch"
Fill="{DynamicResource Brush.Border0}"/>
<Grid Grid.Row="2">
<!-- Body -->
<Grid Margin="8">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="48"/>
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
x:Name="txtMessage"
Text="{DynamicResource Text.Clone.RemoteURL}"
Margin="8, 16"
HorizontalAlignment="Center"
TextWrapping="Wrap"/>
<StackPanel
Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2"
Height="32"
Orientation="Horizontal"
HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Click="OnSure" Width="80" Content="{DynamicResource Text.Sure}" FontWeight="Bold"/>
<Button Click="OnQuit" Width="80" Margin="8,0,0,0" Content="{DynamicResource Text.Cancel}" FontWeight="Bold"/>
</StackPanel>
</Grid>
</Grid>
</Grid>
</controls:Window>

View file

@ -0,0 +1,33 @@
using System;
using System.Windows;
namespace SourceGit.Views {
/// <summary>
/// 通用的确认弹出框
/// </summary>
public partial class ConfirmDialog : Controls.Window {
private Action cbOK;
private Action cbCancel;
public ConfirmDialog(string title, string message, Action onOk, Action onCancel = null) {
InitializeComponent();
txtTitle.Text = title;
txtMessage.Text = message;
cbOK = onOk;
cbCancel = onCancel;
}
private void OnSure(object sender, RoutedEventArgs e) {
cbOK?.Invoke();
Close();
}
private void OnQuit(object sender, RoutedEventArgs e) {
cbCancel?.Invoke();
Close();
}
}
}

View file

@ -4,7 +4,6 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:widgets="clr-namespace:SourceGit.Views.Widgets"
xmlns:models="clr-namespace:SourceGit.Models"
xmlns:converters="clr-namespace:SourceGit.Views.Converters"
mc:Ignorable="d"
@ -139,7 +138,7 @@
<Border Grid.Column="0" Width="4" HorizontalAlignment="Left" Background="{Binding Bookmark, Converter={StaticResource IntToBookmarkBrush}}"/>
<StackPanel Grid.Column="1" Margin="4,0" Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontSize="12pt" FontFamily="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyContent, Mode=OneWay}"/>
<TextBlock Text="{Binding Name}" FontSize="12pt" FontFamily="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyContent, Mode=OneWay}" />
<TextBlock Text="{Binding Path}" FontSize="10pt" FontFamily="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyContent, Mode=OneWay}" Margin="8,0" Foreground="{DynamicResource Brush.FG2}"/>
</StackPanel>
@ -159,7 +158,6 @@
</ControlTemplate>
</Control.Template>
</Control>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

View file

@ -91,12 +91,15 @@ namespace SourceGit.Views.Widgets {
var repo = (sender as Button).DataContext as Models.Repository;
if (repo == null) return;
var result = MessageBox.Show(App.Text("ConfirmRemoveRepo", repo.Path), App.Text("Apply.Warn"), MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes) {
var confirmDialog = new ConfirmDialog(
App.Text("Apply.Warn"),
App.Text("ConfirmRemoveRepo", repo.Path),
() => {
Models.Preference.Instance.RemoveRepository(repo.Path);
UpdateVisibles();
}
});
confirmDialog.Owner = App.Current.MainWindow;
confirmDialog.ShowDialog();
e.Handled = true;
}