mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07: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
|
@ -50,6 +50,10 @@ namespace SourceGit.Git {
|
|||
/// Last 10 Commit message.
|
||||
/// </summary>
|
||||
public List<string> CommitMsgRecords { get; set; } = new List<string>();
|
||||
/// <summary>
|
||||
/// Commit template.
|
||||
/// </summary>
|
||||
public string CommitTemplate { get; set; }
|
||||
#endregion
|
||||
|
||||
#region PROPERTIES_RUNTIME
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
<Geometry x:Key="Icon.UnstageAll">M768 800V684.8L512 480 256 684.8V800l256-204.8L768 800zM512 339.2L768 544V428.8L512 224 256 428.8V544l256-204.8z</Geometry>
|
||||
|
||||
<Geometry x:Key="Icon.Preference">M64.2 180.3h418.2v120.6H64.2zM64.2 461.7h358.5v120.6H64.2zM64.2 723.1h418.2v120.6H64.2zM601.9 180.3h358.5v120.6H601.9zM482.4 119.9h179.2v241.3H482.4zM303.2 401.4h179.2v241.3H303.2zM482.4 662.8h179.2v241.3H482.4zM540.3 461.7h420.1v120.6H540.3zM601.9 723.1h358.5v120.6H601.9z</Geometry>
|
||||
<Geometry x:Key="Icon.Setting">M887 576.8v-129.4L796.6 418c-4.6-14-10.2-27.4-16.8-40.4l43.2-84.8-91.6-91.6-84.8 43.2c-13-6.6-26.6-12.2-40.4-16.8l-29.4-90.4h-129.4L418 227.6c-13.8 4.6-27.4 10.2-40.4 16.8l-84.8-43.2-91.6 91.6 43.2 84.8c-6.6 13-12.2 26.6-16.8 40.4l-90.4 29.4v129.4l90.4 29.4c4.6 13.8 10.2 27.4 16.8 40.4l-43.2 84.8 91.6 91.6 84.8-43.2c13 6.6 26.6 12.2 40.4 16.8l29.4 90.4h129.4l29.4-90.4c14-4.6 27.4-10.2 40.4-16.8l84.8 43.2 91.6-91.6-43.2-84.8c6.6-13 12.2-26.6 16.8-40.4l90.4-29.4zM512 662c-82.8 0-150-67.2-150-150s67.2-150 150-150 150 67.2 150 150-67.2 150-150 150z</Geometry>
|
||||
<Geometry x:Key="Icon.Info">M 38,19C 48.4934,19 57,27.5066 57,38C 57,48.4934 48.4934,57 38,57C 27.5066,57 19,48.4934 19,38C 19,27.5066 27.5066,19 38,19 Z M 33.25,33.25L 33.25,36.4167L 36.4166,36.4167L 36.4166,47.5L 33.25,47.5L 33.25,50.6667L 44.3333,50.6667L 44.3333,47.5L 41.1666,47.5L 41.1666,36.4167L 41.1666,33.25L 33.25,33.25 Z M 38.7917,25.3333C 37.48,25.3333 36.4167,26.3967 36.4167,27.7083C 36.4167,29.02 37.48,30.0833 38.7917,30.0833C 40.1033,30.0833 41.1667,29.02 41.1667,27.7083C 41.1667,26.3967 40.1033,25.3333 38.7917,25.3333 Z</Geometry>
|
||||
<Geometry x:Key="Icon.Folder">M64 864h896V288h-396.224a64 64 0 0 1-57.242667-35.376L460.224 160H64v704z m-64 32V128a32 32 0 0 1 32-32h448a32 32 0 0 1 28.624 17.690667L563.776 224H992a32 32 0 0 1 32 32v640a32 32 0 0 1-32 32H32a32 32 0 0 1-32-32z</Geometry>
|
||||
<Geometry x:Key="Icon.Folder.Fill">M448 64l128 128h448v768H0V64z</Geometry>
|
||||
|
|
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…
Reference in a new issue