refactor<*>: rewrite all codes...

This commit is contained in:
leo 2021-04-29 20:05:55 +08:00
parent 89ff8aa744
commit 30ab8ae954
342 changed files with 17208 additions and 19633 deletions

View file

@ -0,0 +1,69 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.AddSubmodule"
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:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:validations="clr-namespace:SourceGit.Views.Validations"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.URL}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="0" Grid.Column="1"
x:Name="txtURL"
Height="24"
Placeholder="{StaticResource Text.RepositoryURL}">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="URL" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:GitURL/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.ParentFolder}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="1" Grid.Column="1"
x:Name="txtPath"
Height="24"
Placeholder="{StaticResource Text.ParentFolder.Placeholder}">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="Path" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:SubmodulePath/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
<CheckBox
Grid.Row="2" Grid.Column="1"
Margin="0,4,0,0"
x:Name="chkNested"
IsChecked="True"
Content="{StaticResource Text.Submodule.FetchNested}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,40 @@
using System.Threading.Tasks;
using System.Windows.Controls;
namespace SourceGit.Views.Popups {
/// <summary>
/// 新增子模块面板
/// </summary>
public partial class AddSubmodule : Controls.PopupWidget {
private string repo = null;
public string URL { get; set; }
public string Path { get; set; }
public AddSubmodule(string repo) {
this.repo = repo;
InitializeComponent();
}
public override string GetTitle() {
return App.Text("Submodule.Add");
}
public override Task<bool> Start() {
txtURL.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtURL)) return null;
txtPath.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtPath)) return null;
var recursive = chkNested.IsChecked == true;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
var succ = new Commands.Submodule(repo).Add(URL, Path, recursive, UpdateProgress);
Models.Watcher.SetEnabled(repo, true);
return succ;
});
}
}
}

View file

@ -0,0 +1,94 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.Apply"
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:converters="clr-namespace:SourceGit.Views.Converters"
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:models="clr-namespace:SourceGit.Models"
xmlns:validations="clr-namespace:SourceGit.Views.Validations"
mc:Ignorable="d"
d:DesignWidth="800" Height="Auto">
<Grid>
<Grid.Resources>
<converters:InverseBool x:Key="InverseBool"/>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Apply.File}"
HorizontalAlignment="Right"/>
<Grid
Grid.Row="0" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<controls:TextEdit
Grid.Column="0"
x:Name="txtPath"
Height="24"
Placeholder="{StaticResource Text.Apply.File.Placeholder}">
<controls:TextEdit.Text>
<Binding Path="File" ElementName="me" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:PatchFile/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
<Button
Grid.Column="1"
Click="OpenFileBrowser"
Height="24" Width="24"
Margin="2,0,0,0">
<Path Width="14" Height="14" Data="{StaticResource Icon.Folder}"/>
</Button>
</Grid>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Apply.WS}"
HorizontalAlignment="Right"/>
<ComboBox
Grid.Row="1" Grid.Column="1"
x:Name="cmbWSOption"
ItemsSource="{Binding Source={x:Static models:WhitespaceOption.Supported}}"
IsEnabled="{Binding ElementName=chkIngoreWS, Path=IsChecked, Converter={StaticResource InverseBool}}"
SelectedIndex="0"
Height="24"
VerticalAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="20">
<TextBlock Text="{Binding Name}" Margin="4,0"/>
<TextBlock Text="{Binding Desc}" Margin="4,0" FontSize="11" Foreground="{StaticResource Brush.FG2}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<CheckBox
Grid.Row="2" Grid.Column="1"
Margin="0,4,0,0"
x:Name="chkIngoreWS"
IsChecked="True"
Content="{StaticResource Text.Apply.IgnoreWS}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,50 @@
using Microsoft.Win32;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace SourceGit.Views.Popups {
/// <summary>
/// 应用补丁
/// </summary>
public partial class Apply : Controls.PopupWidget {
private string repo = null;
public string File { get; set; }
public Apply(string repo) {
this.repo = repo;
InitializeComponent();
}
public override string GetTitle() {
return App.Text("Apply.Title");
}
public override Task<bool> Start() {
txtPath.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtPath)) return null;
var ignoreWS = chkIngoreWS.IsChecked == true;
var wsMode = (cmbWSOption.SelectedItem as Models.WhitespaceOption).Arg;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
var succ = new Commands.Apply(repo, File, ignoreWS, wsMode).Exec();
Models.Watcher.SetEnabled(repo, true);
return succ;
});
}
private void OpenFileBrowser(object sender, System.Windows.RoutedEventArgs e) {
var dialog = new OpenFileDialog();
dialog.Filter = "Patch File|*.patch";
dialog.Title = App.Text("Apply.File.Placeholder");
dialog.InitialDirectory = repo;
dialog.CheckFileExists = true;
if (dialog.ShowDialog() == true) {
File = dialog.FileName;
txtPath.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
}
}
}
}

View file

@ -0,0 +1,41 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.CherryPick"
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:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignWidth="800" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.CherryPick.Commit}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.Commit}"/>
<TextBlock x:Name="txtCommit" Margin="8,0,0,0"/>
</StackPanel>
<CheckBox
Grid.Row="1" Grid.Column="1"
Margin="0,4,0,0"
x:Name="chkCommit"
IsChecked="True"
Content="{StaticResource Text.CherryPick.CommitChanges}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,35 @@
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 遴选面板
/// </summary>
public partial class CherryPick : Controls.PopupWidget {
private string repo = null;
private string commit = null;
public CherryPick(string repo, Models.Commit commit) {
this.repo = repo;
this.commit = commit.SHA;
InitializeComponent();
txtCommit.Text = $"{commit.ShortSHA} {commit.Subject}";
}
public override string GetTitle() {
return App.Text("CherryPick.Title");
}
public override Task<bool> Start() {
var noCommits = chkCommit.IsChecked != true;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
new Commands.CherryPick(repo, commit, noCommits).Exec();
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

128
src/Views/Popups/Clone.xaml Normal file
View file

@ -0,0 +1,128 @@
<controls:PopupWidget x:Class="SourceGit.Views.Popups.Clone"
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:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:validations="clr-namespace:SourceGit.Views.Validations"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Text="{StaticResource Text.Clone.RemoteURL}"
Margin="0,0,4,0"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="0" Grid.Column="1"
x:Name="txtUrl"
Height="24"
Placeholder="{StaticResource Text.Clone.RemoteURL.Placeholder}">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="Uri" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:GitURL/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
<TextBlock
Grid.Row="1" Grid.Column="0"
Text="{StaticResource Text.Clone.Folder}"
Margin="0,0,4,0"
HorizontalAlignment="Right"/>
<Grid Grid.Row="1" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="30"/>
</Grid.ColumnDefinitions>
<controls:TextEdit
Grid.Column="0"
x:Name="txtFolder"
Height="24"
Placeholder="{StaticResource Text.Clone.Folder.Placeholder}">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="Folder" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:CloneDir/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
<controls:IconButton
Grid.Column="1"
Click="OnFolderSelectorClick"
Width="24" Height="24"
Margin="2,0,0,0" Padding="4"
BorderBrush="{StaticResource Brush.Border1}"
BorderThickness="1"
Icon="{StaticResource Icon.Folder.Open}"/>
</Grid>
<TextBlock
Grid.Row="2" Grid.Column="0"
Text="{StaticResource Text.Clone.LocalName}"
Margin="0,0,4,0"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="2" Grid.Column="1"
Height="24"
x:Name="txtLocal"
Placeholder="{StaticResource Text.Clone.LocalName.Placeholder}">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="LocalName" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:LocalRepositoryName/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
<TextBlock
Grid.Row="3" Grid.Column="0"
Text="{StaticResource Text.Clone.RemoteName}"
Margin="0,0,4,0"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="3" Grid.Column="1"
x:Name="txtRemote"
Height="24"
Placeholder="{StaticResource Text.Clone.RemoteName.Placeholder}">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="RemoteName" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:RemoteName x:Name="ruleRemote"/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
<TextBlock
Grid.Row="4" Grid.Column="0"
Text="{StaticResource Text.Clone.AdditionalParam}"
Margin="0,0,4,0"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="4" Grid.Column="1"
Height="24"
Placeholder="{StaticResource Text.Clone.AdditionalParam.Placeholder}"
Text="{Binding ElementName=me, Path=ExtraArgs, Mode=TwoWay}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,63 @@
using System.Threading.Tasks;
using System.Windows.Controls;
namespace SourceGit.Views.Popups {
/// <summary>
/// 克隆
/// </summary>
public partial class Clone : Controls.PopupWidget {
public string Uri { get; set; }
public string Folder { get; set; }
public string LocalName { get; set; }
public string RemoteName { get; set; }
public string ExtraArgs { get; set; }
public Clone() {
Folder = Models.Preference.Instance.Git.DefaultCloneDir;
InitializeComponent();
ruleRemote.IsOptional = true;
}
public override string GetTitle() {
return App.Text("Clone");
}
public override Task<bool> Start() {
var checks = new Controls.TextEdit[] { txtUrl, txtFolder, txtLocal, txtRemote };
foreach (var edit in checks) {
edit.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(edit)) return null;
}
return Task.Run(() => {
var extras = string.IsNullOrEmpty(ExtraArgs) ? "" : ExtraArgs;
if (!string.IsNullOrEmpty(RemoteName)) extras += $" --origin {RemoteName}";
var succ = new Commands.Clone(Folder, Uri, LocalName, extras, UpdateProgress).Exec();
if (!succ) return false;
var path = Folder;
if (!string.IsNullOrEmpty(LocalName)) {
path += $"/{LocalName}";
} else {
var idx = Uri.LastIndexOfAny(new char[] { '\\', '/' });
var name = Uri.Substring(idx + 1);
path += $"/{name.Replace(".git", "")}";
}
var repo = Models.Preference.Instance.AddRepository(path, path + "/.git", "");
if (repo != null) Dispatcher.Invoke(() => Models.Watcher.Open(repo));
return true;
});
}
private void OnFolderSelectorClick(object sender, System.Windows.RoutedEventArgs e) {
FolderBrowser.Open(null, App.Text("Clone.Folder.Placeholder"), path => {
Folder = path;
txtFolder.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
});
}
}
}

View file

@ -0,0 +1,44 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.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:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Configure.User}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="0" Grid.Column="1"
Text="{Binding ElementName=me, Path=UserName, Mode=TwoWay}"
Height="24"
Placeholder="{StaticResource Text.Configure.User.Placeholder}"/>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Configure.Email}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="1" Grid.Column="1"
Text="{Binding ElementName=me, Path=UserEmail, Mode=TwoWay}"
Height="24"
Placeholder="{StaticResource Text.Configure.Email.Placeholder}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,39 @@
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 仓库配置
/// </summary>
public partial class Configure : Controls.PopupWidget {
private string repo = null;
public string UserName { get; set; }
public string UserEmail { get; set; }
public Configure(string repo) {
this.repo = repo;
var cmd = new Commands.Config(repo);
UserName = cmd.Get("user.name");
UserEmail = cmd.Get("user.email");
InitializeComponent();
}
public override string GetTitle() {
return App.Text("Configure");
}
public override Task<bool> Start() {
return Task.Run(() => {
var cmd = new Commands.Config(repo);
var oldUser = cmd.Get("user.name");
if (oldUser != UserName) cmd.Set("user.name", UserName);
var oldEmail = cmd.Get("user.email");
if (oldEmail != UserEmail) cmd.Set("user.email", UserEmail);
return true;
});
}
}
}

View file

@ -0,0 +1,77 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.CreateBranch"
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:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:converters="clr-namespace:SourceGit.Views.Converters"
xmlns:validations="clr-namespace:SourceGit.Views.Validations"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.Resources>
<converters:InverseBool x:Key="InverseBool"/>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.CreateBranch.BasedOn}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path x:Name="iconBased" Width="14" Height="14" Data="{StaticResource Icon.Branch}"/>
<TextBlock x:Name="txtBased" Margin="8,0,0,0"/>
</StackPanel>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.CreateBranch.Name}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="1" Grid.Column="1"
x:Name="txtBranchName"
Height="24"
Placeholder="{StaticResource Text.CreateBranch.Name.Placeholder}">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="BranchName" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:BranchName x:Name="ruleBranch"/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
<TextBlock
Grid.Row="2" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.CreateBranch.LocalChanges}"
HorizontalAlignment="Right"/>
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
<RadioButton Content="{StaticResource Text.CreateBranch.LocalChanges.StashAndReply}" GroupName="LocalChanges" IsChecked="{Binding AutoStash, ElementName=me}"/>
<RadioButton Content="{StaticResource Text.CreateBranch.LocalChanges.Discard}" Margin="8,0,0,0" GroupName="LocalChanges" IsChecked="{Binding AutoStash, ElementName=me, Mode=OneWay, Converter={StaticResource InverseBool}}"/>
</StackPanel>
<CheckBox
Grid.Row="3" Grid.Column="1"
x:Name="chkCheckout"
IsChecked="True"
Content="{StaticResource Text.CreateBranch.Checkout}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,83 @@
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media;
namespace SourceGit.Views.Popups {
/// <summary>
/// 新建分支面板
/// </summary>
public partial class CreateBranch : Controls.PopupWidget {
private string repo = null;
private string basedOn = null;
public string BranchName { get; set; }
public bool AutoStash { get; set; }
public CreateBranch(Models.Repository repo, Models.Branch branch) {
this.repo = repo.Path;
this.basedOn = branch.Head;
InitializeComponent();
ruleBranch.Repo = repo;
iconBased.Data = FindResource("Icon.Branch") as Geometry;
txtBased.Text = !string.IsNullOrEmpty(branch.Remote) ? $"{branch.Remote}/{branch.Name}" : branch.Name;
}
public CreateBranch(Models.Repository repo, Models.Commit commit) {
this.repo = repo.Path;
this.basedOn = commit.SHA;
InitializeComponent();
ruleBranch.Repo = repo;
iconBased.Data = FindResource("Icon.Commit") as Geometry;
txtBased.Text = $"{commit.ShortSHA} {commit.Subject}";
}
public CreateBranch(Models.Repository repo, Models.Tag tag) {
this.repo = repo.Path;
this.basedOn = tag.SHA;
InitializeComponent();
ruleBranch.Repo = repo;
iconBased.Data = FindResource("Icon.Tag") as Geometry;
txtBased.Text = tag.Name;
}
public override string GetTitle() {
return App.Text("CreateBranch");
}
public override Task<bool> Start() {
txtBranchName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtBranchName)) return null;
var checkout = chkCheckout.IsChecked == true;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
if (checkout) {
if (AutoStash) {
var changes = new Commands.LocalChanges(repo).Result();
if (changes.Count > 0) {
if (!new Commands.Stash(repo).Push(null, "NEWBRANCH_AUTO_STASH", true)) {
return false;
}
} else {
AutoStash = true;
}
}
new Commands.Checkout(repo).Branch(BranchName, basedOn);
if (AutoStash) new Commands.Stash(repo).Pop("stash@{0}");
} else {
new Commands.Branch(repo, BranchName).Create(basedOn);
}
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,69 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.CreateTag"
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:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:validations="clr-namespace:SourceGit.Views.Validations"
mc:Ignorable="d"
d:DesignWidth="800" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="64"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.CreateTag.BasedOn}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path x:Name="iconBased" Width="14" Height="14" Data="{StaticResource Icon.Branch}"/>
<TextBlock x:Name="txtBased" Margin="8,0,0,0"/>
</StackPanel>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.CreateTag.Name}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="1" Grid.Column="1"
x:Name="txtTagName"
Height="24"
Placeholder="{StaticResource Text.CreateTag.Name.Placeholder}">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="TagName" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:TagName x:Name="ruleTag"/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
<TextBlock
Grid.Row="2" Grid.Column="0"
Margin="0,6,8,0"
Text="{StaticResource Text.CreateTag.Message}"
HorizontalAlignment="Right" VerticalAlignment="Top"/>
<controls:TextEdit
Grid.Row="2" Grid.Column="1"
Text="{Binding ElementName=me, Path=Message, Mode=TwoWay}"
Height="56" Padding="0,2"
AcceptsReturn="True"
Placeholder="{StaticResource Text.CreateTag.Message.Placeholder}"
PlaceholderBaseline="Top"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,55 @@
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media;
namespace SourceGit.Views.Popups {
/// <summary>
/// 创建分支面板
/// </summary>
public partial class CreateTag : Controls.PopupWidget {
private string repo = null;
private string basedOn = null;
public string TagName { get; set; }
public string Message { get; set; }
public CreateTag(Models.Repository repo, Models.Branch branch) {
this.repo = repo.Path;
this.basedOn = branch.Head;
InitializeComponent();
ruleTag.Tags = new Commands.Tags(repo.Path).Result();
iconBased.Data = FindResource("Icon.Branch") as Geometry;
txtBased.Text = !string.IsNullOrEmpty(branch.Remote) ? $"{branch.Remote}/{branch.Name}" : branch.Name;
}
public CreateTag(Models.Repository repo, Models.Commit commit) {
this.repo = repo.Path;
this.basedOn = commit.SHA;
InitializeComponent();
ruleTag.Tags = new Commands.Tags(repo.Path).Result();
iconBased.Data = FindResource("Icon.Commit") as Geometry;
txtBased.Text = $"{commit.ShortSHA} {commit.Subject}";
}
public override string GetTitle() {
return App.Text("CreateTag");
}
public override Task<bool> Start() {
txtTagName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtTagName)) return null;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
new Commands.Tag(repo).Add(TagName, basedOn, Message);
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,33 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.DeleteBranch"
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:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.DeleteBranch.Branch}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.Branch}"/>
<TextBlock x:Name="txtTarget" Margin="8,0,0,0"/>
</StackPanel>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,40 @@
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 删除分支确认
/// </summary>
public partial class DeleteBranch : Controls.PopupWidget {
private string repo = null;
private string branch = null;
private string remote = null;
public DeleteBranch(string repo, string branch, string remote = null) {
this.repo = repo;
this.branch = branch;
this.remote = remote;
InitializeComponent();
if (string.IsNullOrEmpty(remote)) txtTarget.Text = branch;
else txtTarget.Text = $"{remote}/{branch}";
}
public override string GetTitle() {
return App.Text("DeleteBranch");
}
public override Task<bool> Start() {
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
if (string.IsNullOrEmpty(remote)) {
new Commands.Branch(repo, branch).Delete();
} else {
new Commands.Push(repo, remote, branch).Exec();
}
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,33 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.DeleteRemote"
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:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.DeleteRemote.Remote}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.Remote}"/>
<TextBlock x:Name="txtTarget" Margin="8,0,0,0"/>
</StackPanel>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,33 @@
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 删除远程确认
/// </summary>
public partial class DeleteRemote : Controls.PopupWidget {
private string repo = null;
private string remote = null;
public DeleteRemote(string repo, string remote) {
this.repo = repo;
this.remote = remote;
InitializeComponent();
txtTarget.Text = remote;
}
public override string GetTitle() {
return App.Text("DeleteRemote");
}
public override Task<bool> Start() {
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
new Commands.Remote(repo).Delete(remote);
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,33 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.DeleteSubmodule"
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:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.DeleteSubmodule.Path}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.Submodule}"/>
<TextBlock x:Name="txtPath" Margin="8,0,0,0"/>
</StackPanel>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,33 @@
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 删除子模块面板
/// </summary>
public partial class DeleteSubmodule : Controls.PopupWidget {
private string repo = null;
private string submodule = null;
public DeleteSubmodule(string repo, string submodule) {
this.repo = repo;
this.submodule = submodule;
InitializeComponent();
txtPath.Text = submodule;
}
public override string GetTitle() {
return App.Text("DeleteSubmodule");
}
public override Task<bool> Start() {
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
new Commands.Submodule(repo).Delete(submodule);
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,41 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.DeleteTag"
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:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.DeleteTag.Tag}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.Tag}"/>
<TextBlock x:Name="txtTag" Margin="8,0,0,0"/>
</StackPanel>
<CheckBox
Grid.Row="1" Grid.Column="1"
Margin="0,4,0,0"
x:Name="chkPush"
IsChecked="True"
Content="{StaticResource Text.DeleteTag.WithRemote}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,35 @@
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 删除标签
/// </summary>
public partial class DeleteTag : Controls.PopupWidget {
private string repo = null;
private string tag = null;
public DeleteTag(string repo, string tag) {
this.repo = repo;
this.tag = tag;
InitializeComponent();
txtTag.Text = tag;
}
public override string GetTitle() {
return App.Text("DeleteTag");
}
public override Task<bool> Start() {
var push = chkPush.IsChecked == true;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
new Commands.Tag(repo).Delete(tag, push);
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,39 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.Discard"
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:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Discard.Changes}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal">
<Path x:Name="icon" Width="12" Height="12" Data="{StaticResource Icon.File}"/>
<TextBlock x:Name="txtTip" Margin="4,0,0,0"/>
</StackPanel>
<TextBlock
Grid.Row="1" Grid.Column="1"
Margin="0,4,0,0"
Text="{StaticResource Text.Discard.Warning}"
Foreground="{StaticResource Brush.FG2}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,42 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Media;
namespace SourceGit.Views.Popups {
/// <summary>
/// 忽略变更
/// </summary>
public partial class Discard : Controls.PopupWidget {
private string repo = null;
private List<Models.Change> changes = null;
public Discard(string repo, List<Models.Change> changes) {
this.repo = repo;
this.changes = changes;
InitializeComponent();
if (changes == null || changes.Count == 0) {
icon.Data = FindResource("Icon.Folder") as Geometry;
txtTip.Text = App.Text("Discard.All");
} else if (changes.Count == 1) {
txtTip.Text = changes[0].Path;
} else {
txtTip.Text = App.Text("Discard.Total", changes.Count);
}
}
public override string GetTitle() {
return App.Text("Discard");
}
public override Task<bool> Start() {
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
new Commands.Discard(repo, changes).Exec();
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,57 @@
<controls:PopupWidget x:Class="SourceGit.Views.Popups.Fetch"
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:converters="clr-namespace:SourceGit.Views.Converters"
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.Resources>
<converters:InverseBool x:Key="InverseBool"/>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Fetch.Remote}"
HorizontalAlignment="Right"/>
<ComboBox
Grid.Row="0" Grid.Column="1"
x:Name="remotes"
VerticalAlignment="Center"
IsEnabled="{Binding ElementName=chkFetchAll, Path=IsChecked, Converter={StaticResource InverseBool}}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="20">
<Path Margin="4,0,0,0" Width="14" Height="14" Data="{StaticResource Icon.Remote}"/>
<TextBlock Text="{Binding Name}" Margin="8,0,0,0"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<CheckBox Grid.Row="1" Grid.Column="1"
Margin="0,4,0,0"
x:Name="chkFetchAll"
IsChecked="True"
Content="{StaticResource Text.Fetch.AllRemotes}"/>
<CheckBox Grid.Row="2" Grid.Column="1"
x:Name="chkPrune"
IsChecked="True"
Content="{StaticResource Text.Fetch.Prune}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,41 @@
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 拉取更新
/// </summary>
public partial class Fetch : Controls.PopupWidget {
private string repo = null;
public Fetch(Models.Repository repo, string preferRemote) {
this.repo = repo.Path;
InitializeComponent();
remotes.ItemsSource = repo.Remotes;
if (preferRemote != null) {
remotes.SelectedIndex = repo.Remotes.FindIndex(x => x.Name == preferRemote);
chkFetchAll.IsChecked = false;
} else {
remotes.SelectedIndex = 0;
chkFetchAll.IsChecked = true;
}
}
public override string GetTitle() {
return App.Text("Fetch.Title");
}
public override Task<bool> Start() {
var prune = chkPrune.IsChecked == true;
var remote = (remotes.SelectedItem as Models.Remote).Name;
if (chkFetchAll.IsChecked == true) remote = "--all";
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
var succ = new Commands.Fetch(repo, remote, prune, UpdateProgress).Exec();
Models.Watcher.SetEnabled(repo, true);
return succ;
});
}
}
}

View file

@ -0,0 +1,35 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.GitFlowFinish"
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:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignWidth="800" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
x:Name="txtPrefix"
HorizontalAlignment="Right"/>
<Path
Grid.Row="0" Grid.Column="1"
Width="14" Height="14"
Data="{StaticResource Icon.Branch}"/>
<TextBlock
Grid.Row="0" Grid.Column="2"
Margin="4,0,0,0"
x:Name="txtName"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,57 @@
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 完成GitFlow分支开发
/// </summary>
public partial class GitFlowFinish : Controls.PopupWidget {
private string repo = null;
private string name = null;
private Models.GitFlowBranchType type = Models.GitFlowBranchType.None;
public GitFlowFinish(Models.Repository repo, string branch, Models.GitFlowBranchType type) {
this.repo = repo.Path;
this.type = type;
InitializeComponent();
txtName.Text = branch;
switch (type) {
case Models.GitFlowBranchType.Feature:
txtPrefix.Text = App.Text("GitFlow.Feature");
name = branch.Substring(repo.GitFlow.Feature.Length);
break;
case Models.GitFlowBranchType.Release:
txtPrefix.Text = App.Text("GitFlow.Release");
name = branch.Substring(repo.GitFlow.Release.Length);
break;
case Models.GitFlowBranchType.Hotfix:
txtPrefix.Text = App.Text("GitFlow.Hotfix");
name = branch.Substring(repo.GitFlow.Hotfix.Length);
break;
}
}
public override string GetTitle() {
switch (type) {
case Models.GitFlowBranchType.Feature:
return App.Text("GitFlow.FinishFeature");
case Models.GitFlowBranchType.Release:
return App.Text("GitFlow.FinishRelease");
case Models.GitFlowBranchType.Hotfix:
return App.Text("GitFlow.FinishHotfix");
default:
return "";
}
}
public override Task<bool> Start() {
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
new Commands.GitFlow(repo).Finish(type, name);
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,41 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.GitFlowStart"
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:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:validations="clr-namespace:SourceGit.Views.Validations"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
x:Name="txtPrefix"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="0" Grid.Column="1"
x:Name="txtBranchName"
Height="24"
Placeholder="{StaticResource Text.GitFlow.StartPlaceholder}">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="BranchName" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:BranchName x:Name="ruleBranch"/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,62 @@
using System.Threading.Tasks;
using System.Windows.Controls;
namespace SourceGit.Views.Popups {
/// <summary>
/// Git-Flow start命令操作面板
/// </summary>
public partial class GitFlowStart : Controls.PopupWidget {
private string repo = null;
private Models.GitFlowBranchType type = Models.GitFlowBranchType.None;
public string BranchName { get; set; }
public GitFlowStart(Models.Repository repo, Models.GitFlowBranchType type) {
this.repo = repo.Path;
this.type = type;
InitializeComponent();
ruleBranch.Repo = repo;
switch (type) {
case Models.GitFlowBranchType.Feature:
ruleBranch.Prefix = repo.GitFlow.Feature;
txtPrefix.Text = repo.GitFlow.Feature;
break;
case Models.GitFlowBranchType.Release:
ruleBranch.Prefix = repo.GitFlow.Release;
txtPrefix.Text = repo.GitFlow.Release;
break;
case Models.GitFlowBranchType.Hotfix:
ruleBranch.Prefix = repo.GitFlow.Hotfix;
txtPrefix.Text = repo.GitFlow.Hotfix;
break;
}
}
public override string GetTitle() {
switch (type) {
case Models.GitFlowBranchType.Feature:
return App.Text("GitFlow.StartFeatureTitle");
case Models.GitFlowBranchType.Release:
return App.Text("GitFlow.StartReleaseTitle");
case Models.GitFlowBranchType.Hotfix:
return App.Text("GitFlow.StartHotfixTitle");
default:
return "";
}
}
public override Task<bool> Start() {
txtBranchName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtBranchName)) return null;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
new Commands.GitFlow(repo).Start(type, BranchName);
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,43 @@
<controls:PopupWidget x:Class="SourceGit.Views.Popups.Init"
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:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Text="{StaticResource Text.Init.Path}"
HorizontalAlignment="Right"/>
<Path
Grid.Row="0" Grid.Column="1"
Width="12" Height="12"
Margin="8,0"
Data="{StaticResource Icon.Folder.Fill}"
Fill="Goldenrod"/>
<TextBlock
Grid.Row="0" Grid.Column="2"
Text="{Binding ElementName=me, Path=WorkDir}"/>
<TextBlock
Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"
Text="{StaticResource Text.Init.Tip}"
Foreground="{StaticResource Brush.FG2}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,31 @@
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 初始化Git仓库确认框
/// </summary>
public partial class Init : Controls.PopupWidget {
public string WorkDir { get; set; }
public Init(string dir) {
WorkDir = dir;
InitializeComponent();
}
public override string GetTitle() {
return App.Text("Init");
}
public override Task<bool> Start() {
return Task.Run(() => {
var succ = new Commands.Init(WorkDir).Exec();
if (!succ) return false;
var repo = Models.Preference.Instance.AddRepository(WorkDir, WorkDir + "\\.git", "");
Models.Watcher.Open(repo);
return true;
});
}
}
}

View file

@ -0,0 +1,102 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.InitGitFlow"
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:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="8"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.GitFlow.ProductionBranch}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="0" Grid.Column="1"
x:Name="txtMaster"
Height="24"
Placeholder="master"
Text="master"/>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.GitFlow.DevelopBranch}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="1" Grid.Column="1"
x:Name="txtDevelop"
Height="24"
Placeholder="develop"
Text="develop"/>
<Rectangle
Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"
Height="1"
Fill="{StaticResource Brush.Border2}"/>
<TextBlock
Grid.Row="3" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.GitFlow.FeaturePrefix}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="3" Grid.Column="1"
x:Name="txtFeature"
Height="24"
Placeholder="feature/"
Text="feature/"/>
<TextBlock
Grid.Row="4" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.GitFlow.ReleasePrefix}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="4" Grid.Column="1"
x:Name="txtRelease"
Height="24"
Placeholder="release/"
Text="release/"/>
<TextBlock
Grid.Row="5" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.GitFlow.HotfixPrefix}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="5" Grid.Column="1"
x:Name="txtHotfix"
Height="24"
Placeholder="hotfix/"
Text="hotfix/"/>
<TextBlock
Grid.Row="6" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.GitFlow.TagPrefix}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="6" Grid.Column="1"
x:Name="txtTag"
Height="24"
Placeholder="{StaticResource Text.Optional}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,50 @@
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 初始化Git-Flow
/// </summary>
public partial class InitGitFlow : Controls.PopupWidget {
private Models.Repository repo = null;
public InitGitFlow(Models.Repository repo) {
this.repo = repo;
InitializeComponent();
}
public override string GetTitle() {
return App.Text("GitFlow.Init");
}
public override Task<bool> Start() {
var master = txtMaster.Text;
var dev = txtDevelop.Text;
var feature = txtFeature.Text;
var release = txtRelease.Text;
var hotfix = txtHotfix.Text;
var version = txtTag.Text;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo.Path, false);
var succ = new Commands.GitFlow(repo.Path).Init(master, dev, feature, release, hotfix, version);
var cmd = new Commands.Config(repo.Path);
if (succ) {
repo.GitFlow.Feature = cmd.Get("gitflow.prefix.feature");
repo.GitFlow.Release = cmd.Get("gitflow.prefix.release");
repo.GitFlow.Hotfix = cmd.Get("gitflow.prefix.hotfix");
} else {
cmd.Set("gitflow.branch.master", null);
cmd.Set("gitflow.branch.develop", null);
cmd.Set("gitflow.prefix.feature", null);
cmd.Set("gitflow.prefix.bugfix", null);
cmd.Set("gitflow.prefix.release", null);
cmd.Set("gitflow.prefix.hotfix", null);
cmd.Set("gitflow.prefix.support", null);
cmd.Set("gitflow.prefix.versiontag", null);
}
Models.Watcher.SetEnabled(repo.Path, true);
return true;
});
}
}
}

View file

@ -0,0 +1,71 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.Merge"
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:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:models="clr-namespace:SourceGit.Models"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Merge.Source}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.Branch}"/>
<TextBlock x:Name="txtSource" Margin="8,0,0,0"/>
</StackPanel>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Merge.Into}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="1" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.Branch}"/>
<TextBlock x:Name="txtInto" Margin="8,0,0,0"/>
</StackPanel>
<TextBlock
Grid.Row="2" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Merge.Mode}"
HorizontalAlignment="Right"/>
<ComboBox
Grid.Row="2" Grid.Column="1"
x:Name="cmbMode"
ItemsSource="{Binding Source={x:Static models:MergeOption.Supported}}"
SelectedIndex="0"
Height="24"
VerticalAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="20">
<TextBlock Text="{Binding Name}" Margin="4,0"/>
<TextBlock Text="{Binding Desc}" Margin="4,0" FontSize="11" Foreground="{StaticResource Brush.FG2}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,35 @@
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 合并操作界面
/// </summary>
public partial class Merge : Controls.PopupWidget {
private string repo = null;
private string source = null;
public Merge(string repo, string source, string dest) {
this.repo = repo;
this.source = source;
InitializeComponent();
txtSource.Text = source;
txtInto.Text = dest;
}
public override string GetTitle() {
return App.Text("Merge");
}
public override Task<bool> Start() {
var mode = (cmbMode.SelectedItem as Models.MergeOption).Arg;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
new Commands.Merge(repo, source, mode).Exec();
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,93 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.Pull"
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:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:converters="clr-namespace:SourceGit.Views.Converters"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<UserControl.Resources>
<converters:BranchToName x:Key="BranchToName"/>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Pull.Remote}"
HorizontalAlignment="Right"/>
<ComboBox
Grid.Row="0" Grid.Column="1"
x:Name="cmbRemotes"
Height="24"
VerticalAlignment="Center"
SelectionChanged="OnRemoteSelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="20">
<Path Margin="4,0,0,0" Width="14" Height="14" Data="{StaticResource Icon.Remote}"/>
<TextBlock Text="{Binding Name}" Margin="8,0,0,0"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Pull.Branch}"
HorizontalAlignment="Right"/>
<ComboBox
Grid.Row="1" Grid.Column="1"
x:Name="cmbBranches"
Height="24"
VerticalAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="20">
<Path Margin="4,0,0,0" Width="14" Height="14" Data="{StaticResource Icon.Branch}"/>
<TextBlock Text="{Binding ., Converter={StaticResource BranchToName}}" Margin="8,0,0,0"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBlock
Grid.Row="2" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Pull.Into}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="2" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.Branch}"/>
<TextBlock x:Name="txtInto" Margin="8,0,0,0"/>
</StackPanel>
<CheckBox Grid.Row="3" Grid.Column="1"
Margin="0,4,0,0"
x:Name="chkUseRebase"
IsChecked="True"
Content="{StaticResource Text.Pull.UseRebase}"/>
<CheckBox Grid.Row="4" Grid.Column="1"
x:Name="chkAutoStash"
IsChecked="True"
Content="{StaticResource Text.Pull.AutoStash}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,68 @@
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace SourceGit.Views.Popups {
/// <summary>
/// 拉回
/// </summary>
public partial class Pull : Controls.PopupWidget {
private Models.Repository repo = null;
private Models.Branch prefered = null;
public Pull(Models.Repository repo, Models.Branch preferRemoteBranch) {
this.repo = repo;
this.prefered = preferRemoteBranch;
InitializeComponent();
var current = repo.Branches.Find(x => x.IsCurrent);
txtInto.Text = current.Name;
if (prefered == null && !string.IsNullOrEmpty(current.Upstream)) {
prefered = repo.Branches.Find(x => x.FullName == current.Upstream);
}
cmbRemotes.ItemsSource = repo.Remotes;
if (prefered != null) {
cmbRemotes.SelectedItem = repo.Remotes.Find(x => x.Name == prefered.Remote);
} else {
cmbRemotes.SelectedItem = repo.Remotes[0];
}
}
public override string GetTitle() {
return App.Text("Pull.Title");
}
public override Task<bool> Start() {
var branch = cmbBranches.SelectedItem as Models.Branch;
if (branch == null) return null;
var rebase = chkUseRebase.IsChecked == true;
var autoStash = chkAutoStash.IsChecked == true;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo.Path, false);
var succ = new Commands.Pull(repo.Path, branch.Remote, branch.Name, rebase, autoStash, UpdateProgress).Exec();
Models.Watcher.SetEnabled(repo.Path, true);
return succ;
});
}
private void OnRemoteSelectionChanged(object sender, SelectionChangedEventArgs e) {
var remote = cmbRemotes.SelectedItem as Models.Remote;
if (remote == null) return;
var branches = repo.Branches.Where(x => x.Remote == remote.Name).ToList();
cmbBranches.ItemsSource = branches;
if (prefered != null && remote.Name == prefered.Remote) {
cmbBranches.SelectedItem = branches.Find(x => x.FullName == prefered.FullName);
} else {
cmbBranches.SelectedItem = branches[0];
}
}
}
}

100
src/Views/Popups/Push.xaml Normal file
View file

@ -0,0 +1,100 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.Push"
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:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:converters="clr-namespace:SourceGit.Views.Converters"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<UserControl.Resources>
<converters:BranchToName x:Key="BranchToName"/>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Push.Local}"
HorizontalAlignment="Right"/>
<ComboBox
Grid.Row="0" Grid.Column="1"
x:Name="cmbLocalBranches"
Height="24"
VerticalAlignment="Center"
SelectionChanged="OnLocalSelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="20">
<Path Margin="4,0,0,0" Width="14" Height="14" Data="{StaticResource Icon.Branch}"/>
<TextBlock Text="{Binding Name}" Margin="8,0,0,0"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Push.Remote}"
HorizontalAlignment="Right"/>
<ComboBox
Grid.Row="1" Grid.Column="1"
x:Name="cmbRemotes"
Height="24"
VerticalAlignment="Center"
SelectionChanged="OnRemoteSelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="20">
<Path Margin="4,0,0,0" Width="14" Height="14" Data="{StaticResource Icon.Remote}"/>
<TextBlock Text="{Binding Name}" Margin="8,0,0,0"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBlock
Grid.Row="2" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Push.To}"
HorizontalAlignment="Right"/>
<ComboBox
Grid.Row="2" Grid.Column="1"
x:Name="cmbRemoteBranches"
Height="24"
VerticalAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="20">
<Path Margin="4,0,0,0" Width="14" Height="14" Data="{StaticResource Icon.Branch}"/>
<TextBlock Text="{Binding ., Converter={StaticResource BranchToName}}" Margin="8,0,0,0"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<CheckBox Grid.Row="3" Grid.Column="1"
Margin="0,4,0,0"
x:Name="chkAllTags"
IsChecked="True"
Content="{StaticResource Text.Push.WithAllTags}"/>
<CheckBox Grid.Row="4" Grid.Column="1"
x:Name="chkForce"
IsChecked="True"
Content="{StaticResource Text.Push.Force}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,108 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace SourceGit.Views.Popups {
/// <summary>
/// 推送
/// </summary>
public partial class Push : Controls.PopupWidget {
private Models.Repository repo = null;
public Push(Models.Repository repo, Models.Branch localBranch) {
this.repo = repo;
InitializeComponent();
var localBranches = repo.Branches.Where(x => x.IsLocal).ToList();
cmbLocalBranches.ItemsSource = localBranches;
if (localBranch != null) cmbLocalBranches.SelectedItem = localBranch;
else cmbLocalBranches.SelectedItem = localBranches.Find(x => x.IsCurrent);
}
public override string GetTitle() {
return App.Text("Push.Title");
}
public override Task<bool> Start() {
var localBranch = cmbLocalBranches.SelectedItem as Models.Branch;
if (localBranch == null) return null;
var remoteBranch = cmbRemoteBranches.SelectedItem as Models.Branch;
if (remoteBranch == null) return null;
var withTags = chkAllTags.IsChecked == true;
var force = chkForce.IsChecked == true;
var track = string.IsNullOrEmpty(localBranch.Upstream);
return Task.Run(() => {
Models.Watcher.SetEnabled(repo.Path, false);
var succ = new Commands.Push(
repo.Path,
localBranch.Name,
remoteBranch.Remote,
remoteBranch.Name.Replace(" (new)", ""),
withTags,
force,
track,
UpdateProgress).Exec();
Models.Watcher.SetEnabled(repo.Path, true);
return succ;
});
}
private void OnLocalSelectionChanged(object sender, SelectionChangedEventArgs e) {
var local = cmbLocalBranches.SelectedItem as Models.Branch;
if (local == null) return;
cmbRemotes.ItemsSource = null;
cmbRemotes.ItemsSource = repo.Remotes;
if (!string.IsNullOrEmpty(local.Upstream)) {
cmbRemotes.SelectedItem = repo.Remotes.Find(x => local.Upstream.StartsWith($"refs/remotes/{x.Name}/"));
} else {
cmbRemotes.SelectedItem = repo.Remotes[0];
}
}
private void OnRemoteSelectionChanged(object sender, SelectionChangedEventArgs e) {
var local = cmbLocalBranches.SelectedItem as Models.Branch;
if (local == null) return;
var remote = cmbRemotes.SelectedItem as Models.Remote;
if (remote == null) return;
var remoteBranches = new List<Models.Branch>();
remoteBranches.AddRange(repo.Branches.Where(x => x.Remote == remote.Name));
cmbRemoteBranches.ItemsSource = null;
if (!string.IsNullOrEmpty(local.Upstream)) {
foreach (var b in remoteBranches) {
if (b.FullName == local.Upstream) {
cmbRemoteBranches.ItemsSource = remoteBranches;
cmbRemoteBranches.SelectedItem = b;
return;
}
}
}
var match = $"refs/remotes/{remote.Name}/{local.Name}";
foreach (var b in remoteBranches) {
if (b.FullName == match) {
cmbRemoteBranches.ItemsSource = remoteBranches;
cmbRemoteBranches.SelectedItem = b;
return;
}
}
var prefer = new Models.Branch() {
Remote = remote.Name,
Name = $"{local.Name} (new)"
};
remoteBranches.Add(prefer);
cmbRemoteBranches.ItemsSource = remoteBranches;
cmbRemoteBranches.SelectedItem = prefer;
}
}
}

View file

@ -0,0 +1,53 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.PushTag"
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:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.PushTag.Tag}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.Tag}"/>
<TextBlock x:Name="txtTag" Margin="8,0,0,0"/>
</StackPanel>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.PushTag.Remote}"
HorizontalAlignment="Right"/>
<ComboBox
Grid.Row="1" Grid.Column="1"
x:Name="cmbRemotes"
VerticalAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="20">
<Path Margin="4,0,0,0" Width="14" Height="14" Data="{StaticResource Icon.Remote}"/>
<TextBlock Text="{Binding Name}" Margin="8,0,0,0"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,38 @@
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 推送标签确认面板
/// </summary>
public partial class PushTag : Controls.PopupWidget {
private string repo = null;
private string tag = null;
public PushTag(Models.Repository repo, string tag) {
this.repo = repo.Path;
this.tag = tag;
InitializeComponent();
txtTag.Text = tag;
cmbRemotes.ItemsSource = repo.Remotes;
cmbRemotes.SelectedIndex = 0;
}
public override string GetTitle() {
return App.Text("PushTag");
}
public override Task<bool> Start() {
var remote = cmbRemotes.SelectedItem as Models.Remote;
if (remote == null) return null;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
new Commands.Push(repo, remote.Name, tag, false).Exec();
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,54 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.Rebase"
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:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Rebase.Target}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.Branch}"/>
<TextBlock x:Name="txtCurrent" Margin="8,0,0,0"/>
</StackPanel>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Rebase.On}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="1" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path x:Name="iconBased" Width="14" Height="14" Data="{StaticResource Icon.Branch}"/>
<TextBlock x:Name="txtOn" Margin="8,0,0,0"/>
</StackPanel>
<CheckBox
Grid.Row="2" Grid.Column="1"
x:Name="chkAutoStash"
IsChecked="True"
Content="{StaticResource Text.Rebase.AutoStash}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,48 @@
using System.Threading.Tasks;
using System.Windows.Media;
namespace SourceGit.Views.Popups {
/// <summary>
/// 变基操作面板
/// </summary>
public partial class Rebase : Controls.PopupWidget {
private string repo = null;
private string on = null;
public Rebase(string repo, string current, Models.Branch branch) {
this.repo = repo;
this.on = branch.Head;
InitializeComponent();
txtCurrent.Text = current;
txtOn.Text = !string.IsNullOrEmpty(branch.Remote) ? $"{branch.Remote}/{branch.Name}" : branch.Name;
iconBased.Data = FindResource("Icon.Branch") as Geometry;
}
public Rebase(string repo, string current, Models.Commit commit) {
this.repo = repo;
this.on = commit.SHA;
InitializeComponent();
txtCurrent.Text = current;
txtOn.Text = $"{commit.ShortSHA} {commit.Subject}";
iconBased.Data = FindResource("Icon.Branch") as Geometry;
}
public override string GetTitle() {
return App.Text("Rebase");
}
public override Task<bool> Start() {
var autoStash = chkAutoStash.IsChecked == true;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
new Commands.Rebase(repo, on, autoStash).Exec();
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,61 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.Remote"
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:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:validations="clr-namespace:SourceGit.Views.Validations"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Remote.Name}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="0" Grid.Column="1"
x:Name="txtName"
Height="24"
Placeholder="{StaticResource Text.Remote.Name.Placeholder}">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="RemoteName" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:RemoteName x:Name="ruleName"/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Remote.URL}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="1" Grid.Column="1"
x:Name="txtUrl"
Height="24"
Placeholder="{StaticResource Text.Remote.URL.Placeholder}">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="RemoteURL" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:GitURL x:Name="ruleURL"/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,59 @@
using System.Threading.Tasks;
using System.Windows.Controls;
namespace SourceGit.Views.Popups {
/// <summary>
/// 远程信息编辑面板
/// </summary>
public partial class Remote : Controls.PopupWidget {
private Models.Repository repo = null;
private Models.Remote remote = null;
public string RemoteName { get; set; }
public string RemoteURL { get; set; }
public Remote(Models.Repository repo, Models.Remote remote) {
this.repo = repo;
this.remote = remote;
if (remote != null) {
RemoteName = remote.Name;
RemoteURL = remote.URL;
}
InitializeComponent();
ruleName.Repo = repo;
}
public override string GetTitle() {
return App.Text(remote == null ? "Remote.AddTitle" : "Remote.EditTitle");
}
public override Task<bool> Start() {
txtName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtName)) return null;
txtUrl.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtUrl)) return null;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo.Path, false);
if (remote == null) {
var succ = new Commands.Remote(repo.Path).Add(RemoteName, RemoteURL);
if (succ) new Commands.Fetch(repo.Path, RemoteName, true, UpdateProgress).Exec();
} else {
if (remote.URL != RemoteURL) {
new Commands.Remote(repo.Path).SetURL(remote.Name, RemoteURL);
}
if (remote.Name != RemoteName) {
new Commands.Remote(repo.Path).Rename(remote.Name, RemoteName);
}
}
Models.Watcher.SetEnabled(repo.Path, true);
return true;
});
}
}
}

View file

@ -0,0 +1,55 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.RenameBranch"
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:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:validations="clr-namespace:SourceGit.Views.Validations"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.RenameBranch.Target}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.Branch}"/>
<TextBlock x:Name="txtTarget" Margin="8,0,0,0"/>
</StackPanel>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.RenameBranch.Name}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="1" Grid.Column="1"
x:Name="txtNewName"
Height="24"
Placeholder="{StaticResource Text.RenameBranch.Name.Placeholder}">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="NewName" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:BranchName x:Name="ruleBranch"/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,40 @@
using System.Threading.Tasks;
using System.Windows.Controls;
namespace SourceGit.Views.Popups {
/// <summary>
/// 本地分支改名
/// </summary>
public partial class RenameBranch : Controls.PopupWidget {
private string repo = null;
private string target = null;
public string NewName { get; set; }
public RenameBranch(Models.Repository repo, string target) {
this.repo = repo.Path;
this.target = target;
InitializeComponent();
ruleBranch.Repo = repo;
txtTarget.Text = target;
}
public override string GetTitle() {
return App.Text("RenameBranch");
}
public override Task<bool> Start() {
txtNewName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtNewName)) return null;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
new Commands.Branch(repo, target).Rename(NewName);
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,72 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.Reset"
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:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:models="clr-namespace:SourceGit.Models"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Reset.Target}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.Branch}"/>
<TextBlock x:Name="txtCurrent" Margin="8,0,0,0"/>
</StackPanel>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Reset.MoveTo}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="1" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.Commit}"/>
<TextBlock x:Name="txtMoveTo" Margin="8,0,0,0"/>
</StackPanel>
<TextBlock
Grid.Row="2" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Reset.Mode}"
HorizontalAlignment="Right"/>
<ComboBox
Grid.Row="2" Grid.Column="1"
x:Name="cmbMode"
ItemsSource="{Binding Source={x:Static models:ResetMode.Supported}}"
SelectedIndex="0"
Height="24"
VerticalAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="20">
<Path Width="12" Height="12" Margin="4,0,0,0" Fill="{Binding Color}" Data="M 0,0 A 180,180 180 1 1 1,1 Z"/>
<TextBlock Text="{Binding Name}" Margin="4,0"/>
<TextBlock Text="{Binding Desc}" Margin="4,0" FontSize="11" Foreground="{StaticResource Brush.FG2}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,35 @@
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 重置面板
/// </summary>
public partial class Reset : Controls.PopupWidget {
private string repo = null;
private string revision = null;
public Reset(string repo, string current, Models.Commit to) {
this.repo = repo;
this.revision = to.SHA;
InitializeComponent();
txtCurrent.Text = current;
txtMoveTo.Text = $"{to.ShortSHA} {to.Subject}";
}
public override string GetTitle() {
return App.Text("Reset");
}
public override Task<bool> Start() {
var mode = cmbMode.SelectedItem as Models.ResetMode;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
new Commands.Reset(repo, revision, mode.Arg).Exec();
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,41 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.Revert"
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:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Revert.Commit}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.Commit}"/>
<TextBlock x:Name="txtCommit" Margin="8,0,0,0"/>
</StackPanel>
<CheckBox
Grid.Row="1" Grid.Column="1"
Margin="0,4,0,0"
x:Name="chkCommit"
IsChecked="True"
Content="{StaticResource Text.Revert.CommitChanges}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,35 @@
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 撤销面板
/// </summary>
public partial class Revert : Controls.PopupWidget {
private string repo = null;
private string commit = null;
public Revert(string repo, Models.Commit commit) {
this.repo = repo;
this.commit = commit.SHA;
InitializeComponent();
txtCommit.Text = $"{commit.ShortSHA} {commit.Subject}";
}
public override string GetTitle() {
return App.Text("Revert");
}
public override Task<bool> Start() {
var commitChanges = chkCommit.IsChecked == true;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
new Commands.Revert(repo, commit, commitChanges).Exec();
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,38 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.Stash"
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:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignWidth="500" Height="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.Stash.Message}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="0" Grid.Column="1"
x:Name="txtMessage"
Height="24"
Placeholder="{StaticResource Text.Stash.Message.Placeholder}"/>
<CheckBox
Grid.Row="1" Grid.Column="1"
Margin="0,4,0,0"
x:Name="chkIncludeUntracked"
IsChecked="True"
Content="{StaticResource Text.Stash.IncludeUntracked}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 贮藏
/// </summary>
public partial class Stash : Controls.PopupWidget {
private string repo = null;
private List<string> files = null;
public Stash(string repo, List<string> files) {
this.repo = repo;
this.files = files;
InitializeComponent();
chkIncludeUntracked.IsEnabled = files == null || files.Count == 0;
}
public override string GetTitle() {
return App.Text("Stash.Title");
}
public override Task<bool> Start() {
var includeUntracked = chkIncludeUntracked.IsChecked == true;
var message = txtMessage.Text;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
if (files == null || files.Count == 0) {
new Commands.Stash(repo).Push(null, message, includeUntracked);
} else {
for (int i = 0; i < files.Count; i += 10) {
var count = Math.Min(10, files.Count - i);
var step = files.GetRange(i, count);
new Commands.Stash(repo).Push(step, message, includeUntracked);
}
}
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}