mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
Use idea from PUMA to configure global user name and email
This commit is contained in:
parent
38227b1d57
commit
d0f6077dc9
3 changed files with 90 additions and 9 deletions
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
开源的Git客户端,仅用于Windows 10。单文件,无需安装,< 500KB。
|
开源的Git客户端,仅用于Windows 10。单文件,无需安装,< 500KB。
|
||||||
|
|
||||||
|
## 预览
|
||||||
|
|
||||||
* DarkTheme
|
* DarkTheme
|
||||||
|
|
||||||
![Preview_Dark](./Preview_Dark.png)
|
![Preview_Dark](./Preview_Dark.png)
|
||||||
|
@ -10,3 +12,7 @@
|
||||||
|
|
||||||
![Preview_Light](./Preview_Light.png)
|
![Preview_Light](./Preview_Light.png)
|
||||||
|
|
||||||
|
|
||||||
|
## Thanks
|
||||||
|
|
||||||
|
* [PUMA](https://gitee.com/whgfu) 配置默认User
|
||||||
|
|
|
@ -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="362" Width="500">
|
Height="472" Width="500">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="36"/>
|
<RowDefinition Height="36"/>
|
||||||
|
@ -21,6 +21,10 @@
|
||||||
<RowDefinition Height="36"/>
|
<RowDefinition Height="36"/>
|
||||||
<RowDefinition Height="28"/>
|
<RowDefinition Height="28"/>
|
||||||
<RowDefinition Height="28"/>
|
<RowDefinition Height="28"/>
|
||||||
|
<RowDefinition Height="18"/>
|
||||||
|
<RowDefinition Height="36"/>
|
||||||
|
<RowDefinition Height="28"/>
|
||||||
|
<RowDefinition Height="28"/>
|
||||||
<RowDefinition Height="28"/>
|
<RowDefinition Height="28"/>
|
||||||
<RowDefinition Height="18"/>
|
<RowDefinition Height="18"/>
|
||||||
<RowDefinition Height="32"/>
|
<RowDefinition Height="32"/>
|
||||||
|
@ -75,11 +79,18 @@
|
||||||
<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>
|
||||||
|
|
||||||
|
<!-- Global User -->
|
||||||
|
<Label Grid.Row="7" Grid.ColumnSpan="2" Content="Global User" FontSize="18"/>
|
||||||
|
<Label Grid.Row="8" 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}"/>
|
||||||
|
<Label Grid.Row="9" 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}"/>
|
||||||
|
|
||||||
<!-- 合并工具配置 -->
|
<!-- 合并工具配置 -->
|
||||||
<Label Grid.Row="7" Grid.ColumnSpan="2" Content="Merge Tool" FontSize="18"/>
|
<Label Grid.Row="11" Grid.ColumnSpan="2" Content="Merge Tool" FontSize="18"/>
|
||||||
<Label Grid.Row="8" Grid.Column="0" Content="Choose Merger :" HorizontalAlignment="Right"/>
|
<Label Grid.Row="12" Grid.Column="0" Content="Choose Merger :" HorizontalAlignment="Right"/>
|
||||||
<ComboBox Grid.Row="8" Grid.Column="1"
|
<ComboBox Grid.Row="12" Grid.Column="1"
|
||||||
Height="24"
|
Height="24"
|
||||||
Padding="2,0,0,0"
|
Padding="2,0,0,0"
|
||||||
HorizontalContentAlignment="Left"
|
HorizontalContentAlignment="Left"
|
||||||
|
@ -88,8 +99,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="9" Grid.Column="0" Content="Install Path :" HorizontalAlignment="Right"/>
|
<Label Grid.Row="13" Grid.Column="0" Content="Install Path :" HorizontalAlignment="Right"/>
|
||||||
<Grid Grid.Row="9" Grid.Column="1">
|
<Grid Grid.Row="13" Grid.Column="1">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*"/>
|
||||||
<ColumnDefinition Width="28"/>
|
<ColumnDefinition Width="28"/>
|
||||||
|
@ -104,13 +115,13 @@
|
||||||
<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="10" Grid.Column="0" Content="Command :" HorizontalAlignment="Right"/>
|
<Label Grid.Row="14" Grid.Column="0" Content="Command :" HorizontalAlignment="Right"/>
|
||||||
<TextBlock Grid.Row="10" Grid.Column="1"
|
<TextBlock Grid.Row="14" Grid.Column="1"
|
||||||
x:Name="txtMergeParam"
|
x:Name="txtMergeParam"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Foreground="{StaticResource Brush.FG2}"/>
|
Foreground="{StaticResource Brush.FG2}"/>
|
||||||
|
|
||||||
<Button Grid.Row="12" Grid.Column="1"
|
<Button Grid.Row="16" Grid.Column="1"
|
||||||
Content="CLOSE"
|
Content="CLOSE"
|
||||||
Click="Close"
|
Click="Close"
|
||||||
Width="80"
|
Width="80"
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
|
||||||
|
@ -10,10 +12,29 @@ namespace SourceGit.UI {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class Preference : UserControl {
|
public partial class Preference : UserControl {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Git global user name.
|
||||||
|
/// </summary>
|
||||||
|
public string GlobalUser {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Git global user email.
|
||||||
|
/// </summary>
|
||||||
|
public string GlobalUserEmail {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Preference() {
|
public Preference() {
|
||||||
|
GlobalUser = GetConfig("user.name");
|
||||||
|
GlobalUserEmail = GetConfig("user.email");
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
int mergeType = App.Preference.MergeTool;
|
int mergeType = App.Preference.MergeTool;
|
||||||
|
@ -33,6 +54,12 @@ namespace SourceGit.UI {
|
||||||
/// Close this dialog
|
/// Close this dialog
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Close(object sender, RoutedEventArgs e) {
|
private void Close(object sender, RoutedEventArgs e) {
|
||||||
|
var oldUser = GetConfig("user.name");
|
||||||
|
if (oldUser != GlobalUser) SetConfig("user.name", GlobalUser);
|
||||||
|
|
||||||
|
var oldEmail = GetConfig("user.email");
|
||||||
|
if (oldEmail != GlobalUserEmail) SetConfig("user.email", GlobalUserEmail);
|
||||||
|
|
||||||
PopupManager.Close();
|
PopupManager.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,5 +137,42 @@ namespace SourceGit.UI {
|
||||||
App.Preference.MergeExecutable = dialog.FileName;
|
App.Preference.MergeExecutable = dialog.FileName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region CONFIG
|
||||||
|
private string GetConfig(string key) {
|
||||||
|
if (!App.IsGitConfigured) return "";
|
||||||
|
|
||||||
|
var startInfo = new ProcessStartInfo();
|
||||||
|
startInfo.FileName = App.Preference.GitExecutable;
|
||||||
|
startInfo.Arguments = $"config --global {key}";
|
||||||
|
startInfo.UseShellExecute = false;
|
||||||
|
startInfo.CreateNoWindow = true;
|
||||||
|
startInfo.RedirectStandardOutput = true;
|
||||||
|
startInfo.StandardOutputEncoding = Encoding.UTF8;
|
||||||
|
|
||||||
|
var proc = new Process() { StartInfo = startInfo };
|
||||||
|
proc.Start();
|
||||||
|
var output = proc.StandardOutput.ReadToEnd();
|
||||||
|
proc.WaitForExit();
|
||||||
|
proc.Close();
|
||||||
|
|
||||||
|
return output.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetConfig(string key, string val) {
|
||||||
|
if (!App.IsGitConfigured) return;
|
||||||
|
|
||||||
|
var startInfo = new ProcessStartInfo();
|
||||||
|
startInfo.FileName = App.Preference.GitExecutable;
|
||||||
|
startInfo.Arguments = $"config --global {key} \"{val}\"";
|
||||||
|
startInfo.UseShellExecute = false;
|
||||||
|
startInfo.CreateNoWindow = true;
|
||||||
|
|
||||||
|
var proc = new Process() { StartInfo = startInfo };
|
||||||
|
proc.Start();
|
||||||
|
proc.WaitForExit();
|
||||||
|
proc.Close();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue