feature<WorkingCopy>: gitee issue #I54W26 - toggle untracked files in working copy changes

This commit is contained in:
leo 2022-05-05 09:57:28 +08:00
parent b04c94ccc1
commit 35235df7bc
10 changed files with 3432 additions and 3370 deletions

View file

@ -8,11 +8,12 @@ namespace SourceGit.Commands {
/// </summary> /// </summary>
public class LocalChanges : Command { public class LocalChanges : Command {
private static readonly Regex REG_FORMAT = new Regex(@"^(\s?[\w\?]{1,4})\s+(.+)$"); private static readonly Regex REG_FORMAT = new Regex(@"^(\s?[\w\?]{1,4})\s+(.+)$");
private static readonly string[] UNTRACKED = new string[] { "no", "all" };
private List<Models.Change> changes = new List<Models.Change>(); private List<Models.Change> changes = new List<Models.Change>();
public LocalChanges(string path) { public LocalChanges(string path, bool includeUntracked = true) {
Cwd = path; Cwd = path;
Args = "status -uall --ignore-submodules=dirty --porcelain"; Args = $"status -u{UNTRACKED[includeUntracked ? 1 : 0]} --ignore-submodules=dirty --porcelain";
} }
public List<Models.Change> Result() { public List<Models.Change> Result() {

View file

@ -94,6 +94,11 @@ namespace SourceGit.Models {
/// 启用自动拉取远程变更每10分钟一次 /// 启用自动拉取远程变更每10分钟一次
/// </summary> /// </summary>
public bool AutoFetchRemotes { get; set; } = true; public bool AutoFetchRemotes { get; set; } = true;
/// <summary>
/// 在本地变更列表中显示未跟踪文件
/// </summary>
public bool IncludeUntrackedInWC { get; set; } = true;
} }
/// <summary> /// <summary>

View file

@ -34,6 +34,9 @@
<Geometry x:Key="Icon.ScrollLeft">M75 100 27 51 76 3z</Geometry> <Geometry x:Key="Icon.ScrollLeft">M75 100 27 51 76 3z</Geometry>
<Geometry x:Key="Icon.ScrollRight">M27 3 L 75 51 L 27 100z</Geometry> <Geometry x:Key="Icon.ScrollRight">M27 3 L 75 51 L 27 100z</Geometry>
<Geometry x:Key="Icon.Eye">M520 168C291 168 95 311 16 512c79 201 275 344 504 344 229 0 425-143 504-344-79-201-275-344-504-344zm0 573c-126 0-229-103-229-229s103-229 229-229c126 0 229 103 229 229s-103 229-229 229zm0-367c-76 0-137 62-137 137s62 137 137 137S657 588 657 512s-62-137-137-137z</Geometry>
<Geometry x:Key="Icon.EyeClose">M734 128c-33-19-74-8-93 25l-41 70c-28-6-58-9-90-9-294 0-445 298-445 298s82 149 231 236l-31 54c-19 33-8 74 25 93 33 19 74 8 93-25L759 222C778 189 767 147 734 128zM305 512c0-115 93-208 207-208 14 0 27 1 40 4l-37 64c-1 0-2 0-2 0-77 0-140 63-140 140 0 26 7 51 20 71l-37 64C324 611 305 564 305 512zM771 301 700 423c13 27 20 57 20 89 0 110-84 200-192 208l-51 89c12 1 24 2 36 2 292 0 446-298 446-298S895 388 771 301z</Geometry>
<Geometry x:Key="Icon.Preference">M716.3 383.1c0 38.4-6.5 76-19.4 111.8l-10.7 29.7 229.6 229.5c44.5 44.6 44.5 117.1 0 161.6a113.6 113.6 0 01-80.8 33.5a113.6 113.6 0 01-80.8-33.5L529 694l-32 13a331.6 331.6 0 01-111.9 19.4A333.5 333.5 0 0150 383.1c0-39 6.8-77.2 20-113.6L285 482l194-195-214-210A331 331 0 01383.1 50A333.5 333.5 0 01716.3 383.1zM231.6 31.6l-22.9 9.9a22.2 22.2 0 00-5.9 4.2a19.5 19.5 0 000 27.5l215 215.2L288.4 417.8 77.8 207.1a26 26 0 00-17.2-7.1a22.8 22.8 0 00-21.5 15a400.5 400.5 0 00-7.5 16.6A381.6 381.6 0 000 384c0 211.7 172.2 384 384 384c44.3 0 87.6-7.5 129-22.3L743.1 975.8A163.5 163.5 0 00859.5 1024c43.9 0 85.3-17.1 116.4-48.2a164.8 164.8 0 000-233L745.5 513C760.5 471.5 768 428 768 384C768 172 596 0 384 0c-53 0-104 10.5-152.5 31.5z</Geometry> <Geometry x:Key="Icon.Preference">M716.3 383.1c0 38.4-6.5 76-19.4 111.8l-10.7 29.7 229.6 229.5c44.5 44.6 44.5 117.1 0 161.6a113.6 113.6 0 01-80.8 33.5a113.6 113.6 0 01-80.8-33.5L529 694l-32 13a331.6 331.6 0 01-111.9 19.4A333.5 333.5 0 0150 383.1c0-39 6.8-77.2 20-113.6L285 482l194-195-214-210A331 331 0 01383.1 50A333.5 333.5 0 01716.3 383.1zM231.6 31.6l-22.9 9.9a22.2 22.2 0 00-5.9 4.2a19.5 19.5 0 000 27.5l215 215.2L288.4 417.8 77.8 207.1a26 26 0 00-17.2-7.1a22.8 22.8 0 00-21.5 15a400.5 400.5 0 00-7.5 16.6A381.6 381.6 0 000 384c0 211.7 172.2 384 384 384c44.3 0 87.6-7.5 129-22.3L743.1 975.8A163.5 163.5 0 00859.5 1024c43.9 0 85.3-17.1 116.4-48.2a164.8 164.8 0 000-233L745.5 513C760.5 471.5 768 428 768 384C768 172 596 0 384 0c-53 0-104 10.5-152.5 31.5z</Geometry>
<Geometry x:Key="Icon.Setting">M928 500a21 21 0 00-19-20L858 472a11 11 0 01-9-9c-1-6-2-13-3-19a11 11 0 015-12l46-25a21 21 0 0010-26l-8-22a21 21 0 00-24-13l-51 10a11 11 0 01-12-6c-3-6-6-11-10-17a11 11 0 011-13l34-39a21 21 0 001-28l-15-18a20 20 0 00-27-4l-45 27a11 11 0 01-13-1c-5-4-10-9-15-12a11 11 0 01-3-12l19-49a21 21 0 00-9-26l-20-12a21 21 0 00-27 6L650 193a9 9 0 01-11 3c-1-1-12-5-20-7a11 11 0 01-7-10l1-52a21 21 0 00-17-22l-23-4a21 21 0 00-24 14L532 164a11 11 0 01-11 7h-20a11 11 0 01-11-7l-17-49a21 21 0 00-24-15l-23 4a21 21 0 00-17 22l1 52a11 11 0 01-8 11c-5 2-15 6-19 7c-4 1-8 0-12-4l-33-40A21 21 0 00313 146l-20 12A21 21 0 00285 184l19 49a11 11 0 01-3 12c-5 4-10 8-15 12a11 11 0 01-13 1L228 231a21 21 0 00-27 4L186 253a21 21 0 001 28L221 320a11 11 0 011 13c-3 5-7 11-10 17a11 11 0 01-12 6l-51-10a21 21 0 00-24 13l-8 22a21 21 0 0010 26l46 25a11 11 0 015 12l0 3c-1 6-2 11-3 16a11 11 0 01-9 9l-51 8A21 21 0 0096 500v23A21 21 0 00114 544l51 8a11 11 0 019 9c1 6 2 13 3 19a11 11 0 01-5 12l-46 25a21 21 0 00-10 26l8 22a21 21 0 0024 13l51-10a11 11 0 0112 6c3 6 6 11 10 17a11 11 0 01-1 13l-34 39a21 21 0 00-1 28l15 18a20 20 0 0027 4l45-27a11 11 0 0113 1c5 4 10 9 15 12a11 11 0 013 12l-19 49a21 21 0 009 26l20 12a21 21 0 0027-6L374 832c3-3 7-5 10-4c7 3 12 5 20 7a11 11 0 018 10l-1 52a21 21 0 0017 22l23 4a21 21 0 0024-14l17-50a11 11 0 0111-7h20a11 11 0 0111 7l17 49a21 21 0 0020 15a19 19 0 004 0l23-4a21 21 0 0017-22l-1-52a11 11 0 018-10c8-3 13-5 18-7l1 0c6-2 9 0 11 3l34 41A21 21 0 00710 878l20-12a21 21 0 009-26l-18-49a11 11 0 013-12c5-4 10-8 15-12a11 11 0 0113-1l45 27a21 21 0 0027-4l15-18a21 21 0 00-1-28l-34-39a11 11 0 01-1-13c3-5 7-11 10-17a11 11 0 0112-6l51 10a21 21 0 0024-13l8-22a21 21 0 00-10-26l-46-25a11 11 0 01-5-12l0-3c1-6 2-11 3-16a11 11 0 019-9l51-8a21 21 0 0018-21v-23zm-565 188a32 32 0 01-51 5a270 270 0 011-363a32 32 0 0151 6l91 161a32 32 0 010 31zM512 782a270 270 0 01-57-6a32 32 0 01-20-47l92-160a32 32 0 0127-16h184a32 32 0 0130 41c-35 109-137 188-257 188zm15-328L436 294a32 32 0 0121-47a268 268 0 0155-6c120 0 222 79 257 188a32 32 0 01-30 41h-184a32 32 0 01-28-16z</Geometry> <Geometry x:Key="Icon.Setting">M928 500a21 21 0 00-19-20L858 472a11 11 0 01-9-9c-1-6-2-13-3-19a11 11 0 015-12l46-25a21 21 0 0010-26l-8-22a21 21 0 00-24-13l-51 10a11 11 0 01-12-6c-3-6-6-11-10-17a11 11 0 011-13l34-39a21 21 0 001-28l-15-18a20 20 0 00-27-4l-45 27a11 11 0 01-13-1c-5-4-10-9-15-12a11 11 0 01-3-12l19-49a21 21 0 00-9-26l-20-12a21 21 0 00-27 6L650 193a9 9 0 01-11 3c-1-1-12-5-20-7a11 11 0 01-7-10l1-52a21 21 0 00-17-22l-23-4a21 21 0 00-24 14L532 164a11 11 0 01-11 7h-20a11 11 0 01-11-7l-17-49a21 21 0 00-24-15l-23 4a21 21 0 00-17 22l1 52a11 11 0 01-8 11c-5 2-15 6-19 7c-4 1-8 0-12-4l-33-40A21 21 0 00313 146l-20 12A21 21 0 00285 184l19 49a11 11 0 01-3 12c-5 4-10 8-15 12a11 11 0 01-13 1L228 231a21 21 0 00-27 4L186 253a21 21 0 001 28L221 320a11 11 0 011 13c-3 5-7 11-10 17a11 11 0 01-12 6l-51-10a21 21 0 00-24 13l-8 22a21 21 0 0010 26l46 25a11 11 0 015 12l0 3c-1 6-2 11-3 16a11 11 0 01-9 9l-51 8A21 21 0 0096 500v23A21 21 0 00114 544l51 8a11 11 0 019 9c1 6 2 13 3 19a11 11 0 01-5 12l-46 25a21 21 0 00-10 26l8 22a21 21 0 0024 13l51-10a11 11 0 0112 6c3 6 6 11 10 17a11 11 0 01-1 13l-34 39a21 21 0 00-1 28l15 18a20 20 0 0027 4l45-27a11 11 0 0113 1c5 4 10 9 15 12a11 11 0 013 12l-19 49a21 21 0 009 26l20 12a21 21 0 0027-6L374 832c3-3 7-5 10-4c7 3 12 5 20 7a11 11 0 018 10l-1 52a21 21 0 0017 22l23 4a21 21 0 0024-14l17-50a11 11 0 0111-7h20a11 11 0 0111 7l17 49a21 21 0 0020 15a19 19 0 004 0l23-4a21 21 0 0017-22l-1-52a11 11 0 018-10c8-3 13-5 18-7l1 0c6-2 9 0 11 3l34 41A21 21 0 00710 878l20-12a21 21 0 009-26l-18-49a11 11 0 013-12c5-4 10-8 15-12a11 11 0 0113-1l45 27a21 21 0 0027-4l15-18a21 21 0 00-1-28l-34-39a11 11 0 01-1-13c3-5 7-11 10-17a11 11 0 0112-6l51 10a21 21 0 0024-13l8-22a21 21 0 00-10-26l-46-25a11 11 0 01-5-12l0-3c1-6 2-11 3-16a11 11 0 019-9l51-8a21 21 0 0018-21v-23zm-565 188a32 32 0 01-51 5a270 270 0 011-363a32 32 0 0151 6l91 161a32 32 0 010 31zM512 782a270 270 0 01-57-6a32 32 0 01-20-47l92-160a32 32 0 0127-16h184a32 32 0 0130 41c-35 109-137 188-257 188zm15-328L436 294a32 32 0 0121-47a268 268 0 0155-6c120 0 222 79 257 188a32 32 0 01-30 41h-184a32 32 0 01-28-16z</Geometry>
<Geometry x:Key="Icon.Statistics">M296 912H120c-4.4 0-8-3.6-8-8V520c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v384c0 4.4-3.6 8-8 8zM600 912H424c-4.4 0-8-3.6-8-8V121c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v783c0 4.4-3.6 8-8 8zM904 912H728c-4.4 0-8-3.6-8-8V280c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v624c0 4.4-3.6 8-8 8z</Geometry> <Geometry x:Key="Icon.Statistics">M296 912H120c-4.4 0-8-3.6-8-8V520c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v384c0 4.4-3.6 8-8 8zM600 912H424c-4.4 0-8-3.6-8-8V121c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v783c0 4.4-3.6 8-8 8zM904 912H728c-4.4 0-8-3.6-8-8V280c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v624c0 4.4-3.6 8-8 8z</Geometry>

View file

@ -433,6 +433,7 @@
<sys:String x:Key="Text.WorkingCopy.CommitAndPush">COMMIT &amp; PUSH</sys:String> <sys:String x:Key="Text.WorkingCopy.CommitAndPush">COMMIT &amp; PUSH</sys:String>
<sys:String x:Key="Text.WorkingCopy.NoCommitHistories">NO RECENT INPUT MESSAGES</sys:String> <sys:String x:Key="Text.WorkingCopy.NoCommitHistories">NO RECENT INPUT MESSAGES</sys:String>
<sys:String x:Key="Text.WorkingCopy.HasCommitHistories">RECENT INPUT MESSAGES</sys:String> <sys:String x:Key="Text.WorkingCopy.HasCommitHistories">RECENT INPUT MESSAGES</sys:String>
<sys:String x:Key="Text.WorkingCopy.IncludeUntracked">INCLUDE UNTRACKED FILES</sys:String>
<sys:String x:Key="Text.Conflict.CherryPick">Cherry-Pick merge request detected! Press 'Abort' to restore original HEAD</sys:String> <sys:String x:Key="Text.Conflict.CherryPick">Cherry-Pick merge request detected! Press 'Abort' to restore original HEAD</sys:String>
<sys:String x:Key="Text.Conflict.Rebase">Rebase merge request detected! Press 'Abort' to restore original HEAD</sys:String> <sys:String x:Key="Text.Conflict.Rebase">Rebase merge request detected! Press 'Abort' to restore original HEAD</sys:String>

View file

@ -432,6 +432,7 @@
<sys:String x:Key="Text.WorkingCopy.CommitAndPush">提交并推送</sys:String> <sys:String x:Key="Text.WorkingCopy.CommitAndPush">提交并推送</sys:String>
<sys:String x:Key="Text.WorkingCopy.NoCommitHistories">没有提交信息记录</sys:String> <sys:String x:Key="Text.WorkingCopy.NoCommitHistories">没有提交信息记录</sys:String>
<sys:String x:Key="Text.WorkingCopy.HasCommitHistories">最近输入的提交信息</sys:String> <sys:String x:Key="Text.WorkingCopy.HasCommitHistories">最近输入的提交信息</sys:String>
<sys:String x:Key="Text.WorkingCopy.IncludeUntracked">显示未跟踪文件</sys:String>
<sys:String x:Key="Text.Conflict.CherryPick">检测到挑选提交冲突! </sys:String> <sys:String x:Key="Text.Conflict.CherryPick">检测到挑选提交冲突! </sys:String>
<sys:String x:Key="Text.Conflict.Rebase">检测到变基冲突!</sys:String> <sys:String x:Key="Text.Conflict.Rebase">检测到变基冲突!</sys:String>

View file

@ -149,4 +149,35 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style x:Key="Style.ToggleButton.Eye" TargetType="{x:Type ToggleButton}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Opacity" Value=".8"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Grid Background="Transparent">
<Path
x:Name="Icon"
Height="14"
Style="{DynamicResource Style.Icon}"
Fill="{DynamicResource Brush.FG1}"
Data="{DynamicResource Icon.EyeClose}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="Icon" Property="Data" Value="{DynamicResource Icon.Eye}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Opacity" Value="1"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary> </ResourceDictionary>

View file

@ -245,7 +245,7 @@ namespace SourceGit.Views.Widgets {
if (!isFirstLoaded) return; if (!isFirstLoaded) return;
Task.Run(() => { Task.Run(() => {
var changes = new Commands.LocalChanges(repo.Path).Result(); var changes = new Commands.LocalChanges(repo.Path, Models.Preference.Instance.Git.IncludeUntrackedInWC).Result();
Dispatcher.Invoke(() => { Dispatcher.Invoke(() => {
badgeLocalChanges.Label = $"{changes.Count}"; badgeLocalChanges.Label = $"{changes.Count}";
(pages.Get("working_copy") as WorkingCopy).SetData(changes); (pages.Get("working_copy") as WorkingCopy).SetData(changes);

View file

@ -40,6 +40,7 @@
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<controls:ChangeDisplaySwitcher <controls:ChangeDisplaySwitcher
@ -60,15 +61,23 @@
x:Name="iconStaging" x:Name="iconStaging"
IsAnimating="{Binding ElementName=unstagedContainer, Path=IsStaging}" IsAnimating="{Binding ElementName=unstagedContainer, Path=IsStaging}"
Visibility="{Binding ElementName=unstagedContainer, Path=IsStaging, Converter={StaticResource BoolToCollapsed}}"/> Visibility="{Binding ElementName=unstagedContainer, Path=IsStaging, Converter={StaticResource BoolToCollapsed}}"/>
<controls:IconButton <ToggleButton
Grid.Column="4" Grid.Column="4"
Width="14" Height="14"
Margin="4,0"
Style="{StaticResource Style.ToggleButton.Eye}"
ToolTip="{DynamicResource Text.WorkingCopy.IncludeUntracked}"
IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=Git.IncludeUntrackedInWC, Mode=TwoWay}"
Checked="ToggleIncludeUntracked" Unchecked="ToggleIncludeUntracked"/>
<controls:IconButton
Grid.Column="5"
Click="StageSelected" Click="StageSelected"
Width="14" Height="14" Width="14" Height="14"
Margin="4,0" Margin="4,0"
Icon="{StaticResource Icon.Down}" Icon="{StaticResource Icon.Down}"
ToolTip="{DynamicResource Text.WorkingCopy.Unstaged.Stage}"/> ToolTip="{DynamicResource Text.WorkingCopy.Unstaged.Stage}"/>
<controls:IconButton <controls:IconButton
Grid.Column="5" Grid.Column="6"
Click="StageAll" Click="StageAll"
Width="14" Height="14" Width="14" Height="14"
Margin="4,0" Margin="4,0"

View file

@ -82,6 +82,11 @@ namespace SourceGit.Views.Widgets {
Validation.ClearInvalid(txtCommitMessage.GetBindingExpression(TextBox.TextProperty)); Validation.ClearInvalid(txtCommitMessage.GetBindingExpression(TextBox.TextProperty));
} }
public void ToggleIncludeUntracked(object sender, RoutedEventArgs e) {
var watcher = Models.Watcher.Get(repo.Path);
if (watcher != null) watcher.RefreshWC();
}
#region STAGE_UNSTAGE #region STAGE_UNSTAGE
private void StageSelected(object sender, RoutedEventArgs e) { private void StageSelected(object sender, RoutedEventArgs e) {
unstagedContainer.StageSelected(); unstagedContainer.StageSelected();

View file

@ -140,7 +140,13 @@ namespace SourceGit.Views.Widgets {
} }
public void StageAll() { public void StageAll() {
DoStage(null); if (Models.Preference.Instance.Git.IncludeUntrackedInWC) {
DoStage(null);
} else {
var changes = new List<string>();
foreach (var c in Changes) changes.Add(c.Path);
DoStage(changes);
}
} }
public void UnstageSelected() { public void UnstageSelected() {