mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-30 00:24:59 +00:00
feature<SubTree>: supports git subtree
feature
This commit is contained in:
parent
6b602e70c5
commit
130b5a66ab
22 changed files with 784 additions and 10 deletions
86
src/Views/Popups/AddSubTree.xaml
Normal file
86
src/Views/Popups/AddSubTree.xaml
Normal file
|
@ -0,0 +1,86 @@
|
|||
<controls:PopupWidget
|
||||
x:Class="SourceGit.Views.Popups.AddSubTree"
|
||||
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:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
<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.AddSubTree.Source}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<controls:TextEdit
|
||||
Grid.Row="0" Grid.Column="1"
|
||||
x:Name="txtSource"
|
||||
Height="24">
|
||||
<controls:TextEdit.Text>
|
||||
<Binding ElementName="me" Path="Source" 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.AddSubTree.Branch}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<controls:TextEdit
|
||||
Grid.Row="1" Grid.Column="1"
|
||||
x:Name="txtRef"
|
||||
Height="24">
|
||||
<controls:TextEdit.Text>
|
||||
<Binding ElementName="me" Path="Ref" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
|
||||
<Binding.ValidationRules>
|
||||
<validations:Required/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</controls:TextEdit.Text>
|
||||
</controls:TextEdit>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="2" Grid.Column="0"
|
||||
Margin="0,0,8,0"
|
||||
Text="{StaticResource Text.AddSubTree.Prefix}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<controls:TextEdit
|
||||
Grid.Row="2" Grid.Column="1"
|
||||
x:Name="txtPrefix"
|
||||
Height="24">
|
||||
<controls:TextEdit.Text>
|
||||
<Binding ElementName="me" Path="Prefix" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
|
||||
<Binding.ValidationRules>
|
||||
<validations:RelativePath/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</controls:TextEdit.Text>
|
||||
</controls:TextEdit>
|
||||
|
||||
<CheckBox
|
||||
Grid.Row="3" Grid.Column="1"
|
||||
Margin="0,4,0,0"
|
||||
x:Name="chkSquash"
|
||||
IsChecked="True"
|
||||
Content="{StaticResource Text.AddSubTree.Squash}"/>
|
||||
</Grid>
|
||||
</controls:PopupWidget>
|
57
src/Views/Popups/AddSubTree.xaml.cs
Normal file
57
src/Views/Popups/AddSubTree.xaml.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Popups {
|
||||
|
||||
/// <summary>
|
||||
/// 添加子树面板
|
||||
/// </summary>
|
||||
public partial class AddSubTree : Controls.PopupWidget {
|
||||
private Models.Repository repo = null;
|
||||
|
||||
public string Source { get; set; }
|
||||
public string Ref { get; set; }
|
||||
public string Prefix { get; set; }
|
||||
|
||||
public AddSubTree(Models.Repository repo) {
|
||||
this.repo = repo;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public override string GetTitle() {
|
||||
return App.Text("AddSubTree");
|
||||
}
|
||||
|
||||
public override Task<bool> Start() {
|
||||
txtSource.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
||||
if (Validation.GetHasError(txtSource)) return null;
|
||||
|
||||
txtPrefix.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
||||
if (Validation.GetHasError(txtPrefix)) return null;
|
||||
|
||||
txtRef.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
||||
if (Validation.GetHasError(txtRef)) return null;
|
||||
|
||||
var squash = chkSquash.IsChecked == true;
|
||||
if (repo.SubTrees.FindIndex(x => x.Prefix == Prefix) >= 0) {
|
||||
Models.Exception.Raise($"Subtree add failed. Prefix({Prefix}) already exists!");
|
||||
return null;
|
||||
}
|
||||
|
||||
return Task.Run(() => {
|
||||
Models.Watcher.SetEnabled(repo.Path, false);
|
||||
var succ = new Commands.SubTree(repo.Path).Add(Prefix, Source, Ref, squash, UpdateProgress);
|
||||
if (succ) {
|
||||
repo.SubTrees.Add(new Models.SubTree() {
|
||||
Prefix = Prefix,
|
||||
Remote = Source,
|
||||
});
|
||||
Models.Preference.Save();
|
||||
Models.Watcher.Get(repo.Path)?.RefreshSubTrees();
|
||||
}
|
||||
Models.Watcher.SetEnabled(repo.Path, true);
|
||||
return succ;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -53,7 +53,7 @@
|
|||
<controls:TextEdit.Text>
|
||||
<Binding ElementName="me" Path="Path" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
|
||||
<Binding.ValidationRules>
|
||||
<validations:SubmodulePath/>
|
||||
<validations:RelativePath/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</controls:TextEdit.Text>
|
||||
|
|
54
src/Views/Popups/EditSubTree.xaml
Normal file
54
src/Views/Popups/EditSubTree.xaml
Normal file
|
@ -0,0 +1,54 @@
|
|||
<controls:PopupWidget
|
||||
x:Class="SourceGit.Views.Popups.EditSubTree"
|
||||
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:DesignHeight="450" d:DesignWidth="800">
|
||||
<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.EditSubTree.Prefix}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<StackPanel
|
||||
Grid.Row="0" Grid.Column="1"
|
||||
Orientation="Horizontal"
|
||||
VerticalAlignment="Center">
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icon.SubTree}"/>
|
||||
<TextBlock x:Name="txtPrefix" Margin="8,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="1" Grid.Column="0"
|
||||
Margin="0,0,8,0"
|
||||
Text="{StaticResource Text.EditSubTree.Source}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<controls:TextEdit
|
||||
Grid.Row="1" Grid.Column="1"
|
||||
x:Name="txtSource"
|
||||
Height="24">
|
||||
<controls:TextEdit.Text>
|
||||
<Binding ElementName="me" Path="Source" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
|
||||
<Binding.ValidationRules>
|
||||
<validations:GitURL/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</controls:TextEdit.Text>
|
||||
</controls:TextEdit>
|
||||
</Grid>
|
||||
</controls:PopupWidget>
|
34
src/Views/Popups/EditSubTree.xaml.cs
Normal file
34
src/Views/Popups/EditSubTree.xaml.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Popups {
|
||||
/// <summary>
|
||||
/// 编辑子树
|
||||
/// </summary>
|
||||
public partial class EditSubTree : Controls.PopupWidget {
|
||||
private Models.Repository repo;
|
||||
private Models.SubTree subtree;
|
||||
|
||||
public string Source {
|
||||
get { return subtree.Remote; }
|
||||
set { subtree.Remote = value; }
|
||||
}
|
||||
|
||||
public EditSubTree(Models.Repository repo, string prefix) {
|
||||
this.repo = repo;
|
||||
this.subtree = repo.SubTrees.Find(x => x.Prefix == prefix);
|
||||
InitializeComponent();
|
||||
txtPrefix.Text = prefix;
|
||||
}
|
||||
|
||||
public override string GetTitle() {
|
||||
return App.Text("EditSubTree");
|
||||
}
|
||||
|
||||
public override Task<bool> Start() {
|
||||
txtSource.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
||||
if (Validation.GetHasError(txtSource)) return null;
|
||||
return Task.Run(() => true);
|
||||
}
|
||||
}
|
||||
}
|
76
src/Views/Popups/SubTreePull.xaml
Normal file
76
src/Views/Popups/SubTreePull.xaml
Normal file
|
@ -0,0 +1,76 @@
|
|||
<controls:PopupWidget
|
||||
x:Class="SourceGit.Views.Popups.SubTreePull"
|
||||
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:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
<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.SubTreePullOrPush.Prefix}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<StackPanel
|
||||
Grid.Row="0" Grid.Column="1"
|
||||
Orientation="Horizontal"
|
||||
VerticalAlignment="Center">
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icon.SubTree}"/>
|
||||
<TextBlock x:Name="txtPrefix" Margin="8,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="1" Grid.Column="0"
|
||||
Margin="0,0,8,0"
|
||||
Text="{StaticResource Text.SubTreePullOrPush.Source}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<StackPanel
|
||||
Grid.Row="1" Grid.Column="1"
|
||||
Orientation="Horizontal"
|
||||
VerticalAlignment="Center">
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icon.Remote}"/>
|
||||
<TextBlock x:Name="txtSource" Margin="8,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="2" Grid.Column="0"
|
||||
Margin="0,0,8,0"
|
||||
Text="{StaticResource Text.SubTreePullOrPush.Branch}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<controls:TextEdit
|
||||
Grid.Row="2" Grid.Column="1"
|
||||
x:Name="txtBranch"
|
||||
Height="24">
|
||||
<controls:TextEdit.Text>
|
||||
<Binding ElementName="me" Path="Branch" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
|
||||
<Binding.ValidationRules>
|
||||
<validations:Required/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</controls:TextEdit.Text>
|
||||
</controls:TextEdit>
|
||||
|
||||
<CheckBox
|
||||
Grid.Row="3" Grid.Column="1"
|
||||
Margin="0,4,0,0"
|
||||
x:Name="chkSquash"
|
||||
IsChecked="True"
|
||||
Content="{StaticResource Text.SubTreePullOrPush.Squash}"/>
|
||||
</Grid>
|
||||
</controls:PopupWidget>
|
43
src/Views/Popups/SubTreePull.xaml.cs
Normal file
43
src/Views/Popups/SubTreePull.xaml.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Popups {
|
||||
/// <summary>
|
||||
/// 拉取
|
||||
/// </summary>
|
||||
public partial class SubTreePull : Controls.PopupWidget {
|
||||
private string repo;
|
||||
private Models.SubTree subtree;
|
||||
|
||||
public string Branch {
|
||||
get { return subtree.Branch; }
|
||||
set { subtree.Branch = value; }
|
||||
}
|
||||
|
||||
public SubTreePull(string repo, Models.SubTree subtree) {
|
||||
this.repo = repo;
|
||||
this.subtree = subtree;
|
||||
InitializeComponent();
|
||||
txtPrefix.Text = subtree.Prefix;
|
||||
txtSource.Text = subtree.Remote;
|
||||
}
|
||||
|
||||
public override string GetTitle() {
|
||||
return App.Text("SubTreePullOrPush.Pull");
|
||||
}
|
||||
|
||||
public override Task<bool> Start() {
|
||||
txtBranch.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
||||
if (Validation.GetHasError(txtBranch)) return null;
|
||||
|
||||
var squash = chkSquash.IsChecked == true;
|
||||
|
||||
return Task.Run(() => {
|
||||
Models.Watcher.SetEnabled(repo, false);
|
||||
new Commands.SubTree(repo).Pull(subtree.Prefix, subtree.Remote, Branch, squash, UpdateProgress);
|
||||
Models.Watcher.SetEnabled(repo, true);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
68
src/Views/Popups/SubTreePush.xaml
Normal file
68
src/Views/Popups/SubTreePush.xaml
Normal file
|
@ -0,0 +1,68 @@
|
|||
<controls:PopupWidget
|
||||
x:Class="SourceGit.Views.Popups.SubTreePush"
|
||||
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:DesignHeight="450" d:DesignWidth="800">
|
||||
<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.SubTreePullOrPush.Prefix}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<StackPanel
|
||||
Grid.Row="0" Grid.Column="1"
|
||||
Orientation="Horizontal"
|
||||
VerticalAlignment="Center">
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icon.SubTree}"/>
|
||||
<TextBlock x:Name="txtPrefix" Margin="8,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="1" Grid.Column="0"
|
||||
Margin="0,0,8,0"
|
||||
Text="{StaticResource Text.SubTreePullOrPush.Source}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<StackPanel
|
||||
Grid.Row="1" Grid.Column="1"
|
||||
Orientation="Horizontal"
|
||||
VerticalAlignment="Center">
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icon.Remote}"/>
|
||||
<TextBlock x:Name="txtSource" Margin="8,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="2" Grid.Column="0"
|
||||
Margin="0,0,8,0"
|
||||
Text="{StaticResource Text.SubTreePullOrPush.Branch}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<controls:TextEdit
|
||||
Grid.Row="2" Grid.Column="1"
|
||||
x:Name="txtBranch"
|
||||
Height="24">
|
||||
<controls:TextEdit.Text>
|
||||
<Binding ElementName="me" Path="Branch" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
|
||||
<Binding.ValidationRules>
|
||||
<validations:Required/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</controls:TextEdit.Text>
|
||||
</controls:TextEdit>
|
||||
</Grid>
|
||||
</controls:PopupWidget>
|
41
src/Views/Popups/SubTreePush.xaml.cs
Normal file
41
src/Views/Popups/SubTreePush.xaml.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Popups {
|
||||
/// <summary>
|
||||
/// 推送
|
||||
/// </summary>
|
||||
public partial class SubTreePush : Controls.PopupWidget {
|
||||
private string repo;
|
||||
private Models.SubTree subtree;
|
||||
|
||||
public string Branch {
|
||||
get { return subtree.Branch; }
|
||||
set { subtree.Branch = value; }
|
||||
}
|
||||
|
||||
public SubTreePush(string repo, Models.SubTree subtree) {
|
||||
this.repo = repo;
|
||||
this.subtree = subtree;
|
||||
InitializeComponent();
|
||||
txtPrefix.Text = subtree.Prefix;
|
||||
txtSource.Text = subtree.Remote;
|
||||
}
|
||||
|
||||
public override string GetTitle() {
|
||||
return App.Text("SubTreePullOrPush.Push");
|
||||
}
|
||||
|
||||
public override Task<bool> Start() {
|
||||
txtBranch.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
||||
if (Validation.GetHasError(txtBranch)) return null;
|
||||
|
||||
return Task.Run(() => {
|
||||
Models.Watcher.SetEnabled(repo, false);
|
||||
new Commands.SubTree(repo).Push(subtree.Prefix, subtree.Remote, Branch, UpdateProgress);
|
||||
Models.Watcher.SetEnabled(repo, true);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
40
src/Views/Popups/UnlinkSubTree.xaml
Normal file
40
src/Views/Popups/UnlinkSubTree.xaml
Normal file
|
@ -0,0 +1,40 @@
|
|||
<controls:PopupWidget
|
||||
x:Class="SourceGit.Views.Popups.UnlinkSubTree"
|
||||
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:DesignHeight="450" d:DesignWidth="800">
|
||||
<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.UnlinkSubTree.Prefix}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<StackPanel
|
||||
Grid.Row="0" Grid.Column="1"
|
||||
Orientation="Horizontal"
|
||||
VerticalAlignment="Center">
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icon.SubTree}"/>
|
||||
<TextBlock x:Name="txtPrefix" Margin="8,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="1" Grid.Column="1"
|
||||
Margin="0,0,8,0"
|
||||
Text="{StaticResource Text.UnlinkSubTree.Tips}"
|
||||
HorizontalAlignment="Left"/>
|
||||
</Grid>
|
||||
</controls:PopupWidget>
|
34
src/Views/Popups/UnlinkSubTree.xaml.cs
Normal file
34
src/Views/Popups/UnlinkSubTree.xaml.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.Views.Popups {
|
||||
/// <summary>
|
||||
/// 删除子树
|
||||
/// </summary>
|
||||
public partial class UnlinkSubTree : Controls.PopupWidget {
|
||||
private Models.Repository repo;
|
||||
private string prefix;
|
||||
|
||||
public UnlinkSubTree(Models.Repository repo, string prefix) {
|
||||
this.repo = repo;
|
||||
this.prefix = prefix;
|
||||
InitializeComponent();
|
||||
txtPrefix.Text = prefix;
|
||||
}
|
||||
|
||||
public override string GetTitle() {
|
||||
return App.Text("UnlinkSubTree");
|
||||
}
|
||||
|
||||
public override Task<bool> Start() {
|
||||
return Task.Run(() => {
|
||||
var idx = repo.SubTrees.FindIndex(x => x.Prefix == prefix);
|
||||
if (idx >= 0) {
|
||||
repo.SubTrees.RemoveAt(idx);
|
||||
Models.Preference.Save();
|
||||
Models.Watcher.Get(repo.Path)?.RefreshSubTrees();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,17 +1,16 @@
|
|||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Validations {
|
||||
public class SubmodulePath : ValidationRule {
|
||||
public class RelativePath : ValidationRule {
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
|
||||
var path = value as string;
|
||||
if (string.IsNullOrEmpty(path)) return ValidationResult.ValidResult;
|
||||
|
||||
var regex = new Regex(@"^[\w\-\._/]+$");
|
||||
var succ = regex.IsMatch(path.Trim());
|
||||
return !succ ? new ValidationResult(false, App.Text("BadSubmodulePath")) : ValidationResult.ValidResult;
|
||||
return !succ ? new ValidationResult(false, App.Text("BadRelativePath")) : ValidationResult.ValidResult;
|
||||
}
|
||||
}
|
||||
}
|
13
src/Views/Validations/Required.cs
Normal file
13
src/Views/Validations/Required.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Validations {
|
||||
public class Required : ValidationRule {
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
|
||||
var path = value as string;
|
||||
return string.IsNullOrEmpty(path) ?
|
||||
new ValidationResult(false, App.Text("Required")) :
|
||||
ValidationResult.ValidResult;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -110,6 +110,8 @@
|
|||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="24"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="24"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.Resources>
|
||||
|
@ -326,7 +328,7 @@
|
|||
Grid.Row="7"
|
||||
x:Name="tagList"
|
||||
RowHeight="24"
|
||||
Height="200"
|
||||
MaxHeight="200"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
Visibility="{Binding ElementName=tglTags, Path=IsChecked, Converter={StaticResource BoolToCollapsed}}"
|
||||
|
@ -386,7 +388,7 @@
|
|||
Grid.Row="9"
|
||||
x:Name="submoduleList"
|
||||
RowHeight="24"
|
||||
Height="100"
|
||||
MaxHeight="100"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
Visibility="{Binding ElementName=tglSubmodules, Path=IsChecked, Converter={StaticResource BoolToCollapsed}}"
|
||||
|
@ -411,6 +413,52 @@
|
|||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
<!-- SUBTREES -->
|
||||
<ToggleButton
|
||||
Grid.Row="10"
|
||||
x:Name="tglSubTrees"
|
||||
Style="{StaticResource Style.ToggleButton.Expender}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Grid.Column="0" Margin="8,0,0,0" Text="{StaticResource Text.Dashboard.SubTrees}" FontWeight="DemiBold" Foreground="{StaticResource Brush.FG2}"/>
|
||||
<TextBlock Grid.Column="1" x:Name="txtSubTreeCount" FontWeight="DemiBold" Margin="4,0,0,0" Foreground="{StaticResource Brush.FG2}"/>
|
||||
<controls:IconButton Grid.Column="2" Click="OpenAddSubTree" Width="14" Height="14" Margin="0,0,4,0" Icon="{StaticResource Icon.TreeAddNode}" ToolTip="{StaticResource Text.Dashboard.SubTrees.Add}"/>
|
||||
</Grid>
|
||||
</ToggleButton>
|
||||
<DataGrid
|
||||
Grid.Row="11"
|
||||
x:Name="subTreeList"
|
||||
RowHeight="24"
|
||||
MaxHeight="100"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
Visibility="{Binding ElementName=tglSubTrees, Path=IsChecked, Converter={StaticResource BoolToCollapsed}}"
|
||||
SelectionMode="Single"
|
||||
SelectionUnit="FullRow"
|
||||
ContextMenuOpening="OnSubTreeContextMenuOpening">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTemplateColumn Width="*">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Path Grid.Column="0" Width="10" Height="10" Margin="16,0,8,0" Data="{StaticResource Icon.SubTree}"/>
|
||||
<TextBlock Grid.Column="1" Text="{Binding Prefix}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
|
||||
<!-- Splitter -->
|
||||
|
|
|
@ -60,6 +60,7 @@ namespace SourceGit.Views.Widgets {
|
|||
UpdateStashes();
|
||||
UpdateTags();
|
||||
UpdateSubmodules();
|
||||
UpdateSubTrees();
|
||||
|
||||
var watcher = Models.Watcher.Get(repo.Path);
|
||||
watcher.Navigate += NavigateTo;
|
||||
|
@ -68,6 +69,7 @@ namespace SourceGit.Views.Widgets {
|
|||
watcher.StashChanged += UpdateStashes;
|
||||
watcher.TagChanged += UpdateTags;
|
||||
watcher.SubmoduleChanged += UpdateSubmodules;
|
||||
watcher.SubTreeChanged += UpdateSubTrees;
|
||||
|
||||
Unloaded += (o, e) => {
|
||||
localBranches.Clear();
|
||||
|
@ -257,6 +259,14 @@ namespace SourceGit.Views.Widgets {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
private void UpdateSubTrees() {
|
||||
Dispatcher.Invoke(() => {
|
||||
txtSubTreeCount.Text = $"({repo.SubTrees.Count})";
|
||||
subTreeList.ItemsSource = null;
|
||||
subTreeList.ItemsSource = repo.SubTrees;
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TOOLBAR_COMMANDS
|
||||
|
@ -909,6 +919,55 @@ namespace SourceGit.Views.Widgets {
|
|||
}
|
||||
#endregion
|
||||
|
||||
#region SUBTREES
|
||||
private void OpenAddSubTree(object sender, RoutedEventArgs e) {
|
||||
new Popups.AddSubTree(repo).Show();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnSubTreeContextMenuOpening(object sender, ContextMenuEventArgs e) {
|
||||
var subtree = subTreeList.SelectedItem as Models.SubTree;
|
||||
if (subtree == null) return;
|
||||
|
||||
var edit = new MenuItem();
|
||||
edit.Header = App.Text("SubTree.Edit");
|
||||
edit.Click += (o, ev) => {
|
||||
new Popups.EditSubTree(repo, subtree.Prefix).Show();
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
var unlink = new MenuItem();
|
||||
unlink.Header = App.Text("SubTree.Unlink");
|
||||
unlink.Click += (o, ev) => {
|
||||
new Popups.UnlinkSubTree(repo, subtree.Prefix).Show();
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
var pull = new MenuItem();
|
||||
pull.Header = App.Text("SubTree.Pull");
|
||||
pull.Click += (o, ev) => {
|
||||
new Popups.SubTreePull(repo.Path, subtree).Show();
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
var push = new MenuItem();
|
||||
push.Header = App.Text("SubTree.Push");
|
||||
push.Click += (o, ev) => {
|
||||
new Popups.SubTreePush(repo.Path, subtree).Show();
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
var menu = new ContextMenu();
|
||||
menu.Items.Add(edit);
|
||||
menu.Items.Add(unlink);
|
||||
menu.Items.Add(new Separator());
|
||||
menu.Items.Add(pull);
|
||||
menu.Items.Add(push);
|
||||
menu.IsOpen = true;
|
||||
e.Handled = true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region FILTERS
|
||||
private void OnFilterChanged(object sender, RoutedEventArgs e) {
|
||||
var toggle = sender as ToggleButton;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue