feature<*>: upgrade to .NET 5.0; use System.Text.Json instead of System.Xml; supports auto check update at startup

This commit is contained in:
leo 2020-12-01 10:31:46 +08:00
parent 1a46551a77
commit 4cde777b98
18 changed files with 300 additions and 80 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
.vs .vs
bin bin
obj obj
publish

8
build.bat Normal file
View file

@ -0,0 +1,8 @@
@echo off
cd src
dotnet publish -c Release -r win-x64 -o ..\publish\selfcontained\ -p:PublishSingleFile=true -p:PublishTrimmed=true -p:TrimMode=link --self-contained=true
dotnet publish -c Release -r win-x64 -o ..\publish\no-selfcontained\ -p:PublishSingleFile=true --self-contained=false
pause

View file

@ -76,7 +76,7 @@ namespace SourceGit {
} }
// Apply themes // Apply themes
if (Preference.UIUseLightTheme) { if (Preference.UseLightTheme) {
foreach (var rs in Current.Resources.MergedDictionaries) { foreach (var rs in Current.Resources.MergedDictionaries) {
if (rs.Source != null && rs.Source.OriginalString.StartsWith("pack://application:,,,/Resources/Themes/")) { if (rs.Source != null && rs.Source.OriginalString.StartsWith("pack://application:,,,/Resources/Themes/")) {
rs.Source = new Uri("pack://application:,,,/Resources/Themes/Light.xaml", UriKind.Absolute); rs.Source = new Uri("pack://application:,,,/Resources/Themes/Light.xaml", UriKind.Absolute);

View file

@ -27,7 +27,7 @@ namespace SourceGit.Converters {
status = change.Index; status = change.Index;
} }
if (App.Preference.UIUseLightTheme) { if (App.Preference.UseLightTheme) {
switch (status) { switch (status) {
case Git.Change.Status.Modified: return Brushes.Goldenrod; case Git.Change.Status.Modified: return Brushes.Goldenrod;
case Git.Change.Status.Added: return Brushes.Green; case Git.Change.Status.Added: return Brushes.Green;

View file

@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Xml.Serialization; using System.Text.Json;
namespace SourceGit.Git { namespace SourceGit.Git {
@ -48,7 +48,7 @@ namespace SourceGit.Git {
private static readonly string SAVE_PATH = Path.Combine( private static readonly string SAVE_PATH = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"SourceGit", "SourceGit",
"preference.xml"); "preference.json");
/// <summary> /// <summary>
/// Runtime singleton instance. /// Runtime singleton instance.
/// </summary> /// </summary>
@ -64,6 +64,17 @@ namespace SourceGit.Git {
} }
#endregion #endregion
#region SETTING_GENERAL
/// <summary>
/// Use light color theme.
/// </summary>
public bool UseLightTheme { get; set; }
/// <summary>
/// Check for updates.
/// </summary>
public bool CheckUpdate { get; set; }
#endregion
#region SETTING_GIT #region SETTING_GIT
/// <summary> /// <summary>
/// Git executable file path. /// Git executable file path.
@ -96,10 +107,6 @@ namespace SourceGit.Git {
/// </summary> /// </summary>
public double UIMainWindowHeight { get; set; } public double UIMainWindowHeight { get; set; }
/// <summary> /// <summary>
/// Use light color theme.
/// </summary>
public bool UIUseLightTheme { get; set; }
/// <summary>
/// Show/Hide tags' list view. /// Show/Hide tags' list view.
/// </summary> /// </summary>
public bool UIShowTags { get; set; } = true; public bool UIShowTags { get; set; } = true;
@ -144,16 +151,8 @@ namespace SourceGit.Git {
public static void Load() { public static void Load() {
if (!File.Exists(SAVE_PATH)) { if (!File.Exists(SAVE_PATH)) {
instance = new Preference(); instance = new Preference();
return; } else {
} instance = JsonSerializer.Deserialize<Preference>(File.ReadAllText(SAVE_PATH));
try {
var stream = new FileStream(SAVE_PATH, FileMode.Open);
var reader = new XmlSerializer(typeof(Preference));
instance = (Preference)reader.Deserialize(stream);
stream.Close();
} catch {
instance = new Preference();
} }
} }
@ -166,11 +165,8 @@ namespace SourceGit.Git {
var dir = Path.GetDirectoryName(SAVE_PATH); var dir = Path.GetDirectoryName(SAVE_PATH);
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
var stream = new FileStream(SAVE_PATH, FileMode.Create); var data = JsonSerializer.Serialize(instance, new JsonSerializerOptions() { WriteIndented = true });
var writer = new XmlSerializer(typeof(Preference)); File.WriteAllText(SAVE_PATH, data);
writer.Serialize(stream, instance);
stream.Flush();
stream.Close();
} }
#endregion #endregion

View file

@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Threading; using System.Windows.Threading;
using System.Xml.Serialization;
namespace SourceGit.Git { namespace SourceGit.Git {
@ -15,14 +15,14 @@ namespace SourceGit.Git {
public class Repository { public class Repository {
#region HOOKS #region HOOKS
[XmlIgnore] public Action<string> OnNavigateCommit = null; public Action<string> OnNavigateCommit = null;
[XmlIgnore] public Action OnWorkingCopyChanged = null; public Action OnWorkingCopyChanged = null;
[XmlIgnore] public Action OnTagChanged = null; public Action OnTagChanged = null;
[XmlIgnore] public Action OnStashChanged = null; public Action OnStashChanged = null;
[XmlIgnore] public Action OnBranchChanged = null; public Action OnBranchChanged = null;
[XmlIgnore] public Action OnCommitsChanged = null; public Action OnCommitsChanged = null;
[XmlIgnore] public Action OnSubmoduleChanged = null; public Action OnSubmoduleChanged = null;
[XmlIgnore] public Action OnClosing = null; public Action OnClosing = null;
#endregion #endregion
#region PROPERTIES_SAVED #region PROPERTIES_SAVED
@ -57,8 +57,8 @@ namespace SourceGit.Git {
#endregion #endregion
#region PROPERTIES_RUNTIME #region PROPERTIES_RUNTIME
[XmlIgnore] public Repository Parent = null; [JsonIgnore] public Repository Parent = null;
[XmlIgnore] public string GitDir = null; [JsonIgnore] public string GitDir = null;
private List<Remote> cachedRemotes = new List<Remote>(); private List<Remote> cachedRemotes = new List<Remote>();
private List<Branch> cachedBranches = new List<Branch>(); private List<Branch> cachedBranches = new List<Branch>();

25
src/Git/Version.cs Normal file
View file

@ -0,0 +1,25 @@
using System;
using System.Text.Json.Serialization;
namespace SourceGit.Git {
/// <summary>
/// Version information.
/// </summary>
public class Version {
[JsonPropertyName("id")]
public ulong Id { get; set; }
[JsonPropertyName("tag_name")]
public string TagName { get; set; }
[JsonPropertyName("target_commitish")]
public string CommitSHA { get; set; }
[JsonPropertyName("prerelease")]
public bool PreRelease { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("body")]
public string Body { get; set; }
[JsonPropertyName("created_at")]
public DateTime CreatedAt { get; set; }
}
}

View file

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net46</TargetFramework> <TargetFramework>net5.0-windows</TargetFramework>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
<ApplicationIcon>App.ico</ApplicationIcon> <ApplicationIcon>App.ico</ApplicationIcon>
@ -16,4 +16,10 @@
<RepositoryType>Public</RepositoryType> <RepositoryType>Public</RepositoryType>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> <PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<TrimmerRootAssembly Include="System.Runtime" />
<TrimmerRootAssembly Include="System.Diagnostics.Debug" />
<TrimmerRootAssembly Include="System.Runtime.Extensions" />
</ItemGroup>
</Project> </Project>

View file

@ -1,5 +1,4 @@
<Window x:Class="SourceGit.UI.About" <Window x:Class="SourceGit.UI.About"
x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@ -67,7 +66,7 @@
</StackPanel> </StackPanel>
<Label Grid.Row="1" Content="SourceGit - OPEN SOURCE GIT CLIENT" HorizontalContentAlignment="Center" VerticalContentAlignment="Bottom" FontSize="18" FontWeight="Bold"/> <Label Grid.Row="1" Content="SourceGit - OPEN SOURCE GIT CLIENT" HorizontalContentAlignment="Center" VerticalContentAlignment="Bottom" FontSize="18" FontWeight="Bold"/>
<Label Grid.Row="2" Content="{Binding ElementName=me, Path=Version}" HorizontalContentAlignment="Center" FontSize="11"/> <Label Grid.Row="2" x:Name="version" HorizontalContentAlignment="Center" FontSize="11"/>
<Label Grid.Row="3" HorizontalContentAlignment="Center" FontSize="11"> <Label Grid.Row="3" HorizontalContentAlignment="Center" FontSize="11">
<Hyperlink RequestNavigate="OpenSource" NavigateUri="https://gitee.com/sourcegit/SourceGit.git"> <Hyperlink RequestNavigate="OpenSource" NavigateUri="https://gitee.com/sourcegit/SourceGit.git">

View file

@ -10,21 +10,14 @@ namespace SourceGit.UI {
/// </summary> /// </summary>
public partial class About : Window { public partial class About : Window {
/// <summary>
/// Current app version
/// </summary>
public string Version {
get {
Assembly asm = Assembly.GetExecutingAssembly();
return "VERSION : " + asm.GetName().Version;
}
}
/// <summary> /// <summary>
/// Constructor /// Constructor
/// </summary> /// </summary>
public About() { public About() {
InitializeComponent(); InitializeComponent();
var asm = Assembly.GetExecutingAssembly().GetName();
version.Content = $"VERSION : v{asm.Version.Major}.{asm.Version.Minor}";
} }
/// <summary> /// <summary>
@ -33,7 +26,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void OpenSource(object sender, RequestNavigateEventArgs e) { private void OpenSource(object sender, RequestNavigateEventArgs e) {
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri)); Process.Start(new ProcessStartInfo("cmd", $"/c start {e.Uri.AbsoluteUri}") { CreateNoWindow = true });
e.Handled = true; e.Handled = true;
} }

View file

@ -93,7 +93,8 @@ namespace SourceGit.UI {
FlowDirection.LeftToRight, FlowDirection.LeftToRight,
new Typeface(blame.FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), new Typeface(blame.FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
12.0, 12.0,
Brushes.Black); Brushes.Black,
VisualTreeHelper.GetDpi(this).PixelsPerDip);
var lineNumberWidth = formatted.Width + 16; var lineNumberWidth = formatted.Width + 16;
var minWidth = area.ActualWidth - lineNumberWidth; var minWidth = area.ActualWidth - lineNumberWidth;

View file

@ -473,7 +473,8 @@ namespace SourceGit.UI {
FlowDirection.LeftToRight, FlowDirection.LeftToRight,
new Typeface(FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), new Typeface(FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
12.0, 12.0,
Brushes.Black); Brushes.Black,
VisualTreeHelper.GetDpi(this).PixelsPerDip);
return formatted.Width + 16; return formatted.Width + 16;
} }

View file

@ -42,8 +42,8 @@ namespace SourceGit.UI {
public static List<InteractiveRebaseModeInfo> Supported = new List<InteractiveRebaseModeInfo>() { public static List<InteractiveRebaseModeInfo> Supported = new List<InteractiveRebaseModeInfo>() {
new InteractiveRebaseModeInfo(InteractiveRebaseMode.Pick, "Pick", "Use this commit", Brushes.Green), new InteractiveRebaseModeInfo(InteractiveRebaseMode.Pick, "Pick", "Use this commit", Brushes.Green),
new InteractiveRebaseModeInfo(InteractiveRebaseMode.Reword, "Reword", "Edit the commit message", Brushes.Yellow), new InteractiveRebaseModeInfo(InteractiveRebaseMode.Reword, "Reword", "Edit the commit message", Brushes.Yellow),
new InteractiveRebaseModeInfo(InteractiveRebaseMode.Squash, "Squash", "Meld into previous commit", App.Preference.UIUseLightTheme ? Brushes.Gray : Brushes.White), new InteractiveRebaseModeInfo(InteractiveRebaseMode.Squash, "Squash", "Meld into previous commit", App.Preference.UseLightTheme ? Brushes.Gray : Brushes.White),
new InteractiveRebaseModeInfo(InteractiveRebaseMode.Fixup, "Fixup", "Like 'Squash' but discard log message", App.Preference.UIUseLightTheme ? Brushes.Gray : Brushes.White), new InteractiveRebaseModeInfo(InteractiveRebaseMode.Fixup, "Fixup", "Like 'Squash' but discard log message", App.Preference.UseLightTheme ? Brushes.Gray : Brushes.White),
new InteractiveRebaseModeInfo(InteractiveRebaseMode.Drop, "Drop", "Remove commit", Brushes.Red), new InteractiveRebaseModeInfo(InteractiveRebaseMode.Drop, "Drop", "Remove commit", Brushes.Red),
}; };
} }

View file

@ -10,7 +10,7 @@
Title="Source Git" Title="Source Git"
Width="{Binding Source={x:Static source:App.Preference}, Path=UIMainWindowWidth, Mode=TwoWay}" Width="{Binding Source={x:Static source:App.Preference}, Path=UIMainWindowWidth, Mode=TwoWay}"
Height="{Binding Source={x:Static source:App.Preference}, Path=UIMainWindowHeight, Mode=TwoWay}" Height="{Binding Source={x:Static source:App.Preference}, Path=UIMainWindowHeight, Mode=TwoWay}"
WindowStartupLocation="CenterScreen"> WindowStartupLocation="CenterOwner">
<!-- Enable WindowChrome Feature --> <!-- Enable WindowChrome Feature -->
<WindowChrome.WindowChrome> <WindowChrome.WindowChrome>

View file

@ -1,4 +1,10 @@
using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Net;
using System.Reflection;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
@ -45,6 +51,8 @@ namespace SourceGit.UI {
InitializeComponent(); InitializeComponent();
openedTabs.SelectedItem = Tabs[0]; openedTabs.SelectedItem = Tabs[0];
if (App.Preference.CheckUpdate) Task.Run(CheckUpdate);
} }
/// <summary> /// <summary>
@ -76,6 +84,33 @@ namespace SourceGit.UI {
openedTabs.SelectedItem = tab; openedTabs.SelectedItem = tab;
} }
/// <summary>
/// Checking for update.
/// </summary>
public void CheckUpdate() {
try {
var web = new WebClient();
var raw = web.DownloadString("https://gitee.com/api/v5/repos/sourcegit/SourceGit/releases/latest");
var ver = JsonSerializer.Deserialize<Git.Version>(raw);
var cur = Assembly.GetExecutingAssembly().GetName().Version;
var matches = Regex.Match(ver.TagName, @"^v(\d+)\.(\d+).*");
if (!matches.Success) return;
var major = int.Parse(matches.Groups[1].Value);
var minor = int.Parse(matches.Groups[2].Value);
if (major > cur.Major || (major == cur.Major && minor > cur.Minor)) {
Dispatcher.Invoke(() => {
var dialog = new UpdateAvailable(ver);
dialog.Owner = this;
dialog.Show();
});
}
} catch {
// IGNORE
}
}
#region LAYOUT_CONTENT #region LAYOUT_CONTENT
/// <summary> /// <summary>
/// Context menu for tab items. /// Context menu for tab items.

View file

@ -8,7 +8,7 @@
xmlns:app="clr-namespace:SourceGit" xmlns:app="clr-namespace:SourceGit"
xmlns:git="clr-namespace:SourceGit.Git" xmlns:git="clr-namespace:SourceGit.Git"
mc:Ignorable="d" mc:Ignorable="d"
Height="520" Width="500" Height="548" Width="500"
Title="Preference" Title="Preference"
WindowStartupLocation="CenterOwner" ResizeMode="NoResize"> WindowStartupLocation="CenterOwner" ResizeMode="NoResize">
@ -61,6 +61,7 @@
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="36"/> <RowDefinition Height="36"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="18"/> <RowDefinition Height="18"/>
<RowDefinition Height="36"/> <RowDefinition Height="36"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
@ -78,24 +79,30 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/> <ColumnDefinition Width="136"/>
<ColumnDefinition MinWidth="200" Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<!-- 显示 --> <!-- 通用 -->
<Label Grid.Row="0" Grid.ColumnSpan="2" Content="APPEARANCE" FontSize="16" FontWeight="DemiBold" Opacity=".85"/> <Label Grid.Row="0" Grid.ColumnSpan="2" Content="GENERAL SETTING" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="1" Grid.Column="0" Content="Light Theme :" HorizontalAlignment="Right"/> <Label Grid.Row="1" Grid.Column="0" Content="Light Theme :" HorizontalAlignment="Right"/>
<CheckBox <CheckBox
Grid.Row="1" Grid.Row="1"
Grid.Column="1" Grid.Column="1"
IsChecked="{Binding Source={x:Static app:App.Preference}, Path=UIUseLightTheme, Mode=TwoWay}" IsChecked="{Binding Source={x:Static app:App.Preference}, Path=UseLightTheme, Mode=TwoWay}"
Content="Restart required" Content="Restart required"
TextElement.FontStyle="Italic"/> TextElement.FontStyle="Italic"/>
<Label Grid.Row="2" Grid.Column="0" Content="Check for Update :" HorizontalAlignment="Right"/>
<CheckBox
Grid.Row="2"
Grid.Column="1"
IsChecked="{Binding Source={x:Static app:App.Preference}, Path=CheckUpdate, Mode=TwoWay}"
TextElement.FontStyle="Italic"/>
<!-- GIT相关配置 --> <!-- GIT相关配置 -->
<Label Grid.Row="3" Grid.ColumnSpan="2" Content="GIT INSTANCE" FontSize="16" FontWeight="DemiBold" Opacity=".85"/> <Label Grid.Row="4" Grid.ColumnSpan="2" Content="GIT INSTANCE" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="4" Grid.Column="0" Content="Install Path :" HorizontalAlignment="Right"/> <Label Grid.Row="5" Grid.Column="0" Content="Install Path :" HorizontalAlignment="Right"/>
<Grid Grid.Row="4" Grid.Column="1"> <Grid Grid.Row="5" Grid.Column="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="28"/> <ColumnDefinition Width="28"/>
@ -110,8 +117,8 @@
<Path Width="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder}"/> <Path Width="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder}"/>
</Button> </Button>
</Grid> </Grid>
<Label Grid.Row="5" Grid.Column="0" Content="Default Clone Dir :" HorizontalAlignment="Right"/> <Label Grid.Row="6" Grid.Column="0" Content="Default Clone Dir :" HorizontalAlignment="Right"/>
<Grid Grid.Row="5" Grid.Column="1"> <Grid Grid.Row="6" Grid.Column="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="28"/> <ColumnDefinition Width="28"/>
@ -128,13 +135,13 @@
</Grid> </Grid>
<!-- Global User --> <!-- Global User -->
<Label Grid.Row="7" Grid.ColumnSpan="2" Content="GLOBAL SETTING" FontSize="16" FontWeight="DemiBold" Opacity=".85"/> <Label Grid.Row="8" Grid.ColumnSpan="2" Content="GLOBAL SETTING" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="8" Grid.Column="0" Content="Name :" HorizontalAlignment="Right"/> <Label Grid.Row="9" Grid.Column="0" Content="Name :" HorizontalAlignment="Right"/>
<TextBox Grid.Row="8" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user name" Text="{Binding ElementName=me, Path=GlobalUser, Mode=TwoWay}"/> <TextBox Grid.Row="9" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user name" Text="{Binding ElementName=me, Path=GlobalUser, Mode=TwoWay}"/>
<Label Grid.Row="9" Grid.Column="0" Content="Email :" HorizontalAlignment="Right"/> <Label Grid.Row="10" Grid.Column="0" Content="Email :" HorizontalAlignment="Right"/>
<TextBox Grid.Row="9" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user email" Text="{Binding ElementName=me, Path=GlobalUserEmail, Mode=TwoWay}"/> <TextBox Grid.Row="10" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user email" Text="{Binding ElementName=me, Path=GlobalUserEmail, Mode=TwoWay}"/>
<Label Grid.Row="10" Grid.Column="0" Content="Auto CRLF :" HorizontalAlignment="Right"/> <Label Grid.Row="11" Grid.Column="0" Content="Auto CRLF :" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="10" Grid.Column="1" <ComboBox Grid.Row="11" Grid.Column="1"
x:Name="cmbAutoCRLF" x:Name="cmbAutoCRLF"
Height="24" Height="24"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
@ -151,9 +158,9 @@
</ComboBox> </ComboBox>
<!-- 合并工具配置 --> <!-- 合并工具配置 -->
<Label Grid.Row="12" Grid.ColumnSpan="2" Content="MERGE TOOL" FontSize="16" FontWeight="DemiBold" Opacity=".85"/> <Label Grid.Row="13" Grid.ColumnSpan="2" Content="MERGE TOOL" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="13" Grid.Column="0" Content="Merger :" HorizontalAlignment="Right"/> <Label Grid.Row="14" Grid.Column="0" Content="Merger :" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="13" Grid.Column="1" <ComboBox Grid.Row="14" Grid.Column="1"
Height="24" Height="24"
Padding="2,0,0,0" Padding="2,0,0,0"
HorizontalContentAlignment="Left" HorizontalContentAlignment="Left"
@ -162,8 +169,8 @@
ItemsSource="{Binding Source={x:Static git:MergeTool.Supported}}" ItemsSource="{Binding Source={x:Static git:MergeTool.Supported}}"
DisplayMemberPath="Name" DisplayMemberPath="Name"
SelectionChanged="ChangeMergeTool"/> SelectionChanged="ChangeMergeTool"/>
<Label Grid.Row="14" Grid.Column="0" Content="Install Path :" HorizontalAlignment="Right"/> <Label Grid.Row="15" Grid.Column="0" Content="Install Path :" HorizontalAlignment="Right"/>
<Grid Grid.Row="14" Grid.Column="1"> <Grid Grid.Row="15" Grid.Column="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="28"/> <ColumnDefinition Width="28"/>
@ -178,8 +185,8 @@
<Path Width="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder}"/> <Path Width="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder}"/>
</Button> </Button>
</Grid> </Grid>
<Label Grid.Row="15" Grid.Column="0" Content="Command :" HorizontalAlignment="Right"/> <Label Grid.Row="16" Grid.Column="0" Content="Command :" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="15" Grid.Column="1" <TextBlock Grid.Row="16" Grid.Column="1"
x:Name="txtMergeParam" x:Name="txtMergeParam"
VerticalAlignment="Center" VerticalAlignment="Center"
Foreground="{StaticResource Brush.FG2}"/> Foreground="{StaticResource Brush.FG2}"/>

102
src/UI/UpdateAvailable.xaml Normal file
View file

@ -0,0 +1,102 @@
<Window x:Class="SourceGit.UI.UpdateAvailable"
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"
mc:Ignorable="d"
FontFamily="Consolas"
Height="400" Width="500">
<!-- Enable WindowChrome Feature -->
<WindowChrome.WindowChrome>
<WindowChrome UseAeroCaptionButtons="False" CornerRadius="0" CaptionHeight="32"/>
</WindowChrome.WindowChrome>
<!-- Window Layout -->
<Border Background="{StaticResource Brush.BG1}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Titlebar -->
<Grid Grid.Row="0" Background="{StaticResource Brush.BG4}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- LOGO -->
<Path Width="20" Height="20" Margin="6,-1,2,0" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Fetch}"/>
<!-- Title -->
<Label Grid.Column="1" Content="UPDATE AVAILABLE" FontWeight="Light"/>
<!-- Close Button -->
<Button Click="Quit" Width="32" Grid.Column="3" WindowChrome.IsHitTestVisibleInChrome="True">
<Button.Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource Style.Button.HighlightHover}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
<Path Width="10" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Close}"/>
</Button>
</Grid>
<Grid Grid.Row="1" Margin="8">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="8"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="140"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Center">
<Path Width="20" Height="20" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Git}" Fill="#FFF05133"/>
<Label x:Name="txtRelease" Content="Release 2.1 available!" FontSize="18" FontWeight="Bold"/>
</StackPanel>
<Label Grid.Row="2" Grid.Column="0" Content="Publish Time :" HorizontalAlignment="Right"/>
<Label Grid.Row="2" Grid.Column="1" x:Name="txtTime" Content="2020/11/30 00:00:00"/>
<Label Grid.Row="3" Grid.Column="0" Content="Base On Commit :" HorizontalAlignment="Right"/>
<Label Grid.Row="3" Grid.Column="1" x:Name="txtBasedOn" Content="724908ea"/>
<Label Grid.Row="4" Grid.Column="0" Content="Is Pre-release :" HorizontalAlignment="Right"/>
<Label Grid.Row="4" Grid.Column="1" x:Name="txtPrerelease" Content="NO"/>
<Border Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Margin="6,6,6,0" BorderBrush="{StaticResource Brush.BG4}" BorderThickness="1">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<TextBlock FontSize="10pt"
FontFamily="Consolas"
Padding="8"
Opacity="0.8"
Background="{StaticResource Brush.BG2}"
Foreground="{StaticResource Brush.FG}"
x:Name="txtChangeLog"/>
</ScrollViewer>
</Border>
<StackPanel Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,8,0,0">
<Button Width="80" Height="24" Style="{StaticResource Style.Button.AccentBordered}" Content="DOWNLOAD" Click="Download"/>
<Button Width="80" Margin="8,0,0,0" Height="24" Style="{StaticResource Style.Button.Bordered}" Content="CANCEL" Click="Quit"/>
</StackPanel>
</Grid>
</Grid>
</Border>
</Window>

View file

@ -0,0 +1,46 @@
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Navigation;
namespace SourceGit.UI {
/// <summary>
/// Interaction logic for UpdateAvailable.xaml
/// </summary>
public partial class UpdateAvailable : Window {
private string tag = null;
/// <summary>
/// Constructor
/// </summary>
/// <param name="version"></param>
public UpdateAvailable(Git.Version version) {
InitializeComponent();
txtRelease.Content = $"{version.Name} is available!";
txtTime.Content = version.CreatedAt.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
txtBasedOn.Content = version.CommitSHA.Substring(0, 10);
txtPrerelease.Content = version.PreRelease ? "YES" : "NO";
txtChangeLog.Text = version.Body;
tag = version.TagName;
}
/// <summary>
/// Open source code link
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Download(object sender, RoutedEventArgs e) {
Process.Start(new ProcessStartInfo("cmd", $"/c start https://gitee.com/sourcegit/SourceGit/releases/{tag}") { CreateNoWindow = true });
e.Handled = true;
}
/// <summary>
/// Close this dialog
/// </summary>
private void Quit(object sender, RoutedEventArgs e) {
Close();
}
}
}