mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-23 13:14:59 +00:00
feature(Dashboard): add configuration for opened repository
1. User name and email for single repository 2. Simple commit template
This commit is contained in:
parent
3c896c33be
commit
53c65faecb
8 changed files with 221 additions and 3 deletions
71
SourceGit/UI/Configure.xaml
Normal file
71
SourceGit/UI/Configure.xaml
Normal file
|
@ -0,0 +1,71 @@
|
|||
<UserControl x:Class="SourceGit.UI.Configure"
|
||||
x:Name="me"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:helpers="clr-namespace:SourceGit.Helpers"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="500" Width="500" Height="314">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="36"/>
|
||||
<RowDefinition Height="8"/>
|
||||
<RowDefinition Height="28"/>
|
||||
<RowDefinition Height="28"/>
|
||||
<RowDefinition Height="18"/>
|
||||
<RowDefinition Height="36"/>
|
||||
<RowDefinition Height="8"/>
|
||||
<RowDefinition Height="102"/>
|
||||
<RowDefinition Height="18"/>
|
||||
<RowDefinition Height="32"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- 仓库帐号 -->
|
||||
<Label Grid.Row="0" Grid.ColumnSpan="2" Content="CREDENTIAL" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
|
||||
<Label Grid.Row="2" Grid.Column="0" Content="User : " HorizontalAlignment="Right"/>
|
||||
<TextBox
|
||||
Grid.Row="2"
|
||||
Grid.Column="1"
|
||||
Height="24"
|
||||
Text="{Binding ElementName=me, Path=UserName, Mode=TwoWay}"
|
||||
helpers:TextBoxHelper.Placeholder="User name for this repository"/>
|
||||
<Label Grid.Row="3" Grid.Column="0" Content="Email : " HorizontalAlignment="Right"/>
|
||||
<TextBox
|
||||
Grid.Row="3"
|
||||
Grid.Column="1"
|
||||
Height="24"
|
||||
Text="{Binding ElementName=me, Path=UserEmail, Mode=TwoWay}"
|
||||
helpers:TextBoxHelper.Placeholder="Email address"/>
|
||||
|
||||
<!-- 提交模板 -->
|
||||
<Label Grid.Row="5" Grid.ColumnSpan="2" Content="COMMIT TEMPLATE" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
|
||||
<Label Grid.Row="7" Grid.Column="0" Content="Template : " HorizontalAlignment="Right" VerticalAlignment="Top"/>
|
||||
<TextBox
|
||||
Grid.Row="7"
|
||||
Grid.Column="1"
|
||||
Height="100"
|
||||
AcceptsReturn="True"
|
||||
AcceptsTab="True"
|
||||
Padding="2"
|
||||
Text="{Binding ElementName=me, Path=CommitTemplate, Mode=TwoWay}"/>
|
||||
|
||||
<!-- 操作 -->
|
||||
<Grid Grid.Row="9" Grid.ColumnSpan="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="80"/>
|
||||
<ColumnDefinition Width="8"/>
|
||||
<ColumnDefinition Width="80"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Button Grid.Column="1" Click="Save" Content="SAVE" Style="{StaticResource Style.Button.AccentBordered}"/>
|
||||
<Button Grid.Column="3" Click="Close" Content="CLOSE" Style="{StaticResource Style.Button.Bordered}"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
122
SourceGit/UI/Configure.xaml.cs
Normal file
122
SourceGit/UI/Configure.xaml.cs
Normal file
|
@ -0,0 +1,122 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace SourceGit.UI {
|
||||
|
||||
/// <summary>
|
||||
/// Repository configuration dialog
|
||||
/// </summary>
|
||||
public partial class Configure : UserControl {
|
||||
private Git.Repository repo = null;
|
||||
|
||||
/// <summary>
|
||||
/// User name for this repository.
|
||||
/// </summary>
|
||||
public string UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// User email for this repository.
|
||||
/// </summary>
|
||||
public string UserEmail { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Commit template for this repository.
|
||||
/// </summary>
|
||||
public string CommitTemplate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="repo"></param>
|
||||
public Configure(Git.Repository repo) {
|
||||
this.repo = repo;
|
||||
|
||||
UserName = GetConfig("user.name");
|
||||
UserEmail = GetConfig("user.email");
|
||||
CommitTemplate = repo.CommitTemplate;
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show this dialog.
|
||||
/// </summary>
|
||||
/// <param name="repo"></param>
|
||||
public static void Show(Git.Repository repo) {
|
||||
PopupManager.Show(new Configure(repo));
|
||||
}
|
||||
|
||||
#region EVENTS
|
||||
private void Save(object sender, RoutedEventArgs e) {
|
||||
var oldUser = GetConfig("user.name");
|
||||
if (oldUser != UserName) SetConfig("user.name", UserName);
|
||||
|
||||
var oldEmail = GetConfig("user.email");
|
||||
if (oldEmail != UserEmail) SetConfig("user.email", UserEmail);
|
||||
|
||||
if (CommitTemplate != repo.CommitTemplate) {
|
||||
repo.CommitTemplate = CommitTemplate;
|
||||
Git.Preference.Save();
|
||||
}
|
||||
|
||||
Close(sender, e);
|
||||
}
|
||||
|
||||
private void Close(object sender, RoutedEventArgs e) {
|
||||
PopupManager.Close();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CONFIGURE
|
||||
private string GetConfig(string key) {
|
||||
if (!App.IsGitConfigured) return "";
|
||||
|
||||
var startInfo = new ProcessStartInfo();
|
||||
startInfo.FileName = App.Preference.GitExecutable;
|
||||
startInfo.Arguments = $"config {key}";
|
||||
startInfo.WorkingDirectory = repo.Path;
|
||||
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 {key} \"{val}\"";
|
||||
startInfo.WorkingDirectory = repo.Path;
|
||||
startInfo.UseShellExecute = false;
|
||||
startInfo.CreateNoWindow = true;
|
||||
|
||||
var proc = new Process() { StartInfo = startInfo };
|
||||
proc.Start();
|
||||
proc.WaitForExit();
|
||||
proc.Close();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -94,13 +94,19 @@
|
|||
|
||||
<!-- External Options -->
|
||||
<StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Click="OpenSearch" Margin="4,0" ToolTip="Search Commit">
|
||||
<Button Click="OpenSearch" Margin="4,0,0,0" ToolTip="Search Commit">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Path Width="14" Height="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Search}"/>
|
||||
<Path Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Search}"/>
|
||||
<Label Content="Search"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Click="OpenExplorer" Margin="4,0" ToolTip="Open In File Browser">
|
||||
<Button Click="OpenConfigure" Margin="4,0,0,0" ToolTip="Configure This Repository">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Path Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Setting}"/>
|
||||
<Label Content="Configure"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Click="OpenExplorer" Margin="4,0,0,0" ToolTip="Open In File Browser">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Path Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder.Open}"/>
|
||||
<Label Content="Explore"/>
|
||||
|
|
|
@ -321,6 +321,10 @@ namespace SourceGit.UI {
|
|||
}
|
||||
}
|
||||
|
||||
private void OpenConfigure(object sender, RoutedEventArgs e) {
|
||||
Configure.Show(repo);
|
||||
}
|
||||
|
||||
private void OpenExplorer(object sender, RoutedEventArgs e) {
|
||||
Process.Start(repo.Path);
|
||||
}
|
||||
|
|
|
@ -344,6 +344,7 @@
|
|||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
helpers:TextBoxHelper.Placeholder="Enter commit message"
|
||||
helpers:TextBoxHelper.PlaceholderBaseline="Top"
|
||||
GotFocus="CommitMsgGotFocus"
|
||||
PreviewMouseWheel="CommitMsgPreviewMouseWheel">
|
||||
<TextBox.Text>
|
||||
<Binding ElementName="me" Path="CommitMessage" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
|
||||
|
|
|
@ -697,6 +697,15 @@ namespace SourceGit.UI {
|
|||
#endregion
|
||||
|
||||
#region COMMIT_PANEL
|
||||
private void CommitMsgGotFocus(object sender, RoutedEventArgs e) {
|
||||
var textBox = sender as TextBox;
|
||||
if (textBox == null) return;
|
||||
|
||||
if (string.IsNullOrEmpty(textBox.Text) && !string.IsNullOrEmpty(Repo.CommitTemplate)) {
|
||||
textBox.Text = Repo.CommitTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
private void CommitMsgPreviewMouseWheel(object sender, MouseWheelEventArgs e) {
|
||||
var textBox = sender as TextBox;
|
||||
if (textBox == null) return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue