feature<Avatar>: add settings for avatar server

This commit is contained in:
leo 2021-04-01 12:47:01 +08:00
parent 6a9ee67524
commit 3dfe3ae252
6 changed files with 73 additions and 21 deletions

View file

@ -53,6 +53,10 @@ namespace SourceGit {
/// </summary> /// </summary>
public string Locale { get; set; } = "en_US"; public string Locale { get; set; } = "en_US";
/// <summary> /// <summary>
/// Base URL to get avatar
/// </summary>
public string AvatarServer { get; set; } = "https://www.gravatar.com/avatar";
/// <summary>
/// Main window width /// Main window width
/// </summary> /// </summary>
public double WindowWidth { get; set; } public double WindowWidth { get; set; }

View file

@ -157,7 +157,7 @@ namespace SourceGit.Helpers {
Action job = () => { Action job = () => {
try { try {
HttpWebRequest req = WebRequest.CreateHttp("https://www.gravatar.com/avatar/" + md5 + "?d=404"); HttpWebRequest req = WebRequest.CreateHttp(App.Setting.UI.AvatarServer + md5 + "?d=404");
req.Timeout = 2000; req.Timeout = 2000;
req.Method = "GET"; req.Method = "GET";

View file

@ -348,6 +348,7 @@
<sys:String x:Key="Text.Preference.Locale">Display Language :</sys:String> <sys:String x:Key="Text.Preference.Locale">Display Language :</sys:String>
<sys:String x:Key="Text.Preference.UseLight">Light Theme :</sys:String> <sys:String x:Key="Text.Preference.UseLight">Light Theme :</sys:String>
<sys:String x:Key="Text.Preference.CheckUpdate">Check for Update :</sys:String> <sys:String x:Key="Text.Preference.CheckUpdate">Check for Update :</sys:String>
<sys:String x:Key="Text.Preference.AvatarServer">Avatar Server :</sys:String>
<sys:String x:Key="Text.Preference.Git">GIT INSTANCE</sys:String> <sys:String x:Key="Text.Preference.Git">GIT INSTANCE</sys:String>
<sys:String x:Key="Text.Preference.Git.Path">Install Path :</sys:String> <sys:String x:Key="Text.Preference.Git.Path">Install Path :</sys:String>
<sys:String x:Key="Text.Preference.Git.Path.Placeholder">Input path for git.exe</sys:String> <sys:String x:Key="Text.Preference.Git.Path.Placeholder">Input path for git.exe</sys:String>

View file

@ -348,6 +348,7 @@
<sys:String x:Key="Text.Preference.Locale">显示语言 </sys:String> <sys:String x:Key="Text.Preference.Locale">显示语言 </sys:String>
<sys:String x:Key="Text.Preference.UseLight">启用浅色主题 </sys:String> <sys:String x:Key="Text.Preference.UseLight">启用浅色主题 </sys:String>
<sys:String x:Key="Text.Preference.CheckUpdate">检测更新 </sys:String> <sys:String x:Key="Text.Preference.CheckUpdate">检测更新 </sys:String>
<sys:String x:Key="Text.Preference.AvatarServer">头像服务 </sys:String>
<sys:String x:Key="Text.Preference.Git">GIT配置</sys:String> <sys:String x:Key="Text.Preference.Git">GIT配置</sys:String>
<sys:String x:Key="Text.Preference.Git.Path">安装路径 </sys:String> <sys:String x:Key="Text.Preference.Git.Path">安装路径 </sys:String>
<sys:String x:Key="Text.Preference.Git.Path.Placeholder">填写git.exe所在位置</sys:String> <sys:String x:Key="Text.Preference.Git.Path.Placeholder">填写git.exe所在位置</sys:String>

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="560" Width="500" Height="588" Width="500"
Title="{StaticResource Text.Preference}" Title="{StaticResource Text.Preference}"
WindowStartupLocation="CenterOwner" ResizeMode="NoResize"> WindowStartupLocation="CenterOwner" ResizeMode="NoResize">
@ -63,6 +63,7 @@
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<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"/>
@ -112,10 +113,20 @@
IsChecked="{Binding Source={x:Static app:App.Setting}, Path=CheckUpdate, Mode=TwoWay}" IsChecked="{Binding Source={x:Static app:App.Setting}, Path=CheckUpdate, Mode=TwoWay}"
TextElement.FontStyle="Italic"/> TextElement.FontStyle="Italic"/>
<Label Grid.Row="4" Grid.Column="0" Content="{StaticResource Text.Preference.AvatarServer}" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="4" Grid.Column="1"
x:Name="cmbAvatarServer"
Height="24"
Width="140"
HorizontalAlignment="Left"
VerticalContentAlignment="Center"
DisplayMemberPath="Desc"
SelectionChanged="ChangeAvatarServer"/>
<!-- GIT相关配置 --> <!-- GIT相关配置 -->
<Label Grid.Row="5" Grid.ColumnSpan="2" Content="{StaticResource Text.Preference.Git}" FontSize="16" FontWeight="DemiBold" Opacity=".85"/> <Label Grid.Row="6" Grid.ColumnSpan="2" Content="{StaticResource Text.Preference.Git}" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="6" Grid.Column="0" Content="{StaticResource Text.Preference.Git.Path}" HorizontalAlignment="Right"/> <Label Grid.Row="7" Grid.Column="0" Content="{StaticResource Text.Preference.Git.Path}" HorizontalAlignment="Right"/>
<Grid Grid.Row="6" Grid.Column="1"> <Grid Grid.Row="7" Grid.Column="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="28"/> <ColumnDefinition Width="28"/>
@ -130,8 +141,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="7" Grid.Column="0" Content="{StaticResource Text.Preference.Git.Dir}" HorizontalAlignment="Right"/> <Label Grid.Row="8" Grid.Column="0" Content="{StaticResource Text.Preference.Git.Dir}" HorizontalAlignment="Right"/>
<Grid Grid.Row="7" Grid.Column="1"> <Grid Grid.Row="8" Grid.Column="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="28"/> <ColumnDefinition Width="28"/>
@ -148,13 +159,13 @@
</Grid> </Grid>
<!-- Global User --> <!-- Global User -->
<Label Grid.Row="9" Grid.ColumnSpan="2" Content="{StaticResource Text.Preference.Global}" FontSize="16" FontWeight="DemiBold" Opacity=".85"/> <Label Grid.Row="10" Grid.ColumnSpan="2" Content="{StaticResource Text.Preference.Global}" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="10" Grid.Column="0" Content="{StaticResource Text.Preference.User}" HorizontalAlignment="Right"/> <Label Grid.Row="11" Grid.Column="0" Content="{StaticResource Text.Preference.User}" HorizontalAlignment="Right"/>
<TextBox Grid.Row="10" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user name" Text="{Binding ElementName=me, Path=GlobalUser, Mode=TwoWay}"/> <TextBox Grid.Row="11" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user name" Text="{Binding ElementName=me, Path=GlobalUser, Mode=TwoWay}"/>
<Label Grid.Row="11" Grid.Column="0" Content="{StaticResource Text.Preference.Email}" HorizontalAlignment="Right"/> <Label Grid.Row="12" Grid.Column="0" Content="{StaticResource Text.Preference.Email}" HorizontalAlignment="Right"/>
<TextBox Grid.Row="11" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user email" Text="{Binding ElementName=me, Path=GlobalUserEmail, Mode=TwoWay}"/> <TextBox Grid.Row="12" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user email" Text="{Binding ElementName=me, Path=GlobalUserEmail, Mode=TwoWay}"/>
<Label Grid.Row="12" Grid.Column="0" Content="{StaticResource Text.Preference.CRLF}" HorizontalAlignment="Right"/> <Label Grid.Row="13" Grid.Column="0" Content="{StaticResource Text.Preference.CRLF}" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="12" Grid.Column="1" <ComboBox Grid.Row="13" Grid.Column="1"
x:Name="cmbAutoCRLF" x:Name="cmbAutoCRLF"
Height="24" Height="24"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
@ -171,9 +182,9 @@
</ComboBox> </ComboBox>
<!-- 合并工具配置 --> <!-- 合并工具配置 -->
<Label Grid.Row="14" Grid.ColumnSpan="2" Content="{StaticResource Text.Preference.Merger}" FontSize="16" FontWeight="DemiBold" Opacity=".85"/> <Label Grid.Row="15" Grid.ColumnSpan="2" Content="{StaticResource Text.Preference.Merger}" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="15" Grid.Column="0" Content="{StaticResource Text.Preference.Merger.Type}" HorizontalAlignment="Right"/> <Label Grid.Row="16" Grid.Column="0" Content="{StaticResource Text.Preference.Merger.Type}" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="15" Grid.Column="1" <ComboBox Grid.Row="16" Grid.Column="1"
Height="24" Height="24"
Padding="2,0,0,0" Padding="2,0,0,0"
HorizontalContentAlignment="Left" HorizontalContentAlignment="Left"
@ -182,8 +193,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="16" Grid.Column="0" Content="{StaticResource Text.Preference.Merger.Path}" HorizontalAlignment="Right"/> <Label Grid.Row="17" Grid.Column="0" Content="{StaticResource Text.Preference.Merger.Path}" HorizontalAlignment="Right"/>
<Grid Grid.Row="16" Grid.Column="1"> <Grid Grid.Row="17" Grid.Column="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="28"/> <ColumnDefinition Width="28"/>
@ -198,8 +209,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="17" Grid.Column="0" Content="{StaticResource Text.Preference.Merger.Cmd}" HorizontalAlignment="Right"/> <Label Grid.Row="18" Grid.Column="0" Content="{StaticResource Text.Preference.Merger.Cmd}" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="17" Grid.Column="1" <TextBlock Grid.Row="18" Grid.Column="1"
x:Name="txtMergeParam" x:Name="txtMergeParam"
VerticalAlignment="Center" VerticalAlignment="Center"
Foreground="{StaticResource Brush.FG2}"/> Foreground="{StaticResource Brush.FG2}"/>

View file

@ -63,6 +63,19 @@ namespace SourceGit.UI {
} }
} }
/// <summary>
/// Avatar server
/// </summary>
public class AvatarServer {
public string Value { get; set; }
public string Desc { get; set; }
public AvatarServer(string v, string d) {
Value = v;
Desc = d;
}
}
/// <summary> /// <summary>
/// Constructor. /// Constructor.
/// </summary> /// </summary>
@ -81,6 +94,13 @@ namespace SourceGit.UI {
cmbLang.ItemsSource = locales; cmbLang.ItemsSource = locales;
cmbLang.SelectedItem = locales.Find(o => o.Value == App.Setting.UI.Locale); cmbLang.SelectedItem = locales.Find(o => o.Value == App.Setting.UI.Locale);
var avatarServers = new List<AvatarServer>() {
new AvatarServer("https://www.gravatar.com/avatar/", "Gravatar官网"),
new AvatarServer("https://cdn.s.loli.top/avatar/", "Gravatar中国CDN"),
};
cmbAvatarServer.ItemsSource = avatarServers;
cmbAvatarServer.SelectedItem = avatarServers.Find(o => o.Value == App.Setting.UI.AvatarServer);
int mergeType = App.Setting.Tools.MergeTool; int mergeType = App.Setting.Tools.MergeTool;
var merger = Git.MergeTool.Supported[mergeType]; var merger = Git.MergeTool.Supported[mergeType];
txtMergePath.IsReadOnly = !merger.IsConfigured; txtMergePath.IsReadOnly = !merger.IsConfigured;
@ -126,6 +146,21 @@ namespace SourceGit.UI {
App.SaveSetting(); App.SaveSetting();
} }
/// <summary>
/// Set avatar server.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ChangeAvatarServer(object sender, SelectionChangedEventArgs e) {
if (e.AddedItems.Count != 1) return;
var s = e.AddedItems[0] as AvatarServer;
if (s == null) return;
App.Setting.UI.AvatarServer = s.Value;
App.SaveSetting();
}
/// <summary> /// <summary>
/// Select git executable file path. /// Select git executable file path.
/// </summary> /// </summary>