Skip to content

Commit

Permalink
boh
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiboz committed Oct 2, 2024
1 parent 4e12406 commit 5c4660d
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 57 deletions.
6 changes: 3 additions & 3 deletions src/Commands/Clean.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ namespace SourceGit.Commands
{
public class Clean : Command
{
public Clean(string repo)
public Clean(string repo, bool includeIgnored)
{
WorkingDirectory = repo;
Context = repo;
Args = "clean -qfd";
Args = includeIgnored ? "clean -qfdx" : "clean -qfd";
}

public Clean(string repo, List<string> files)
{
StringBuilder builder = new StringBuilder();
var builder = new StringBuilder();
builder.Append("clean -qfd --");
foreach (var f in files)
{
Expand Down
11 changes: 0 additions & 11 deletions src/Commands/Diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ protected override void OnReadline(string line)

_oldLine = int.Parse(match.Groups[1].Value);
_newLine = int.Parse(match.Groups[2].Value);

if (_result.TextDiff.Lines.Count > 0)
{
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, "", 0, 0));
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, "", 0, 0));
}
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, line, 0, 0));
}
else
Expand Down Expand Up @@ -163,11 +157,6 @@ protected override void OnReadline(string line)
{
_oldLine = int.Parse(match.Groups[1].Value);
_newLine = int.Parse(match.Groups[2].Value);
if (_result.TextDiff.Lines.Count > 0)
{
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, "", 0, 0));
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, "", 0, 0));
}
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, line, 0, 0));
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Discard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace SourceGit.Commands
{
public static class Discard
{
public static void All(string repo)
public static void All(string repo, bool includeIgnored)
{
new Restore(repo).Exec();
new Clean(repo).Exec();
new Clean(repo, includeIgnored).Exec();
}

public static void Changes(string repo, List<Models.Change> changes)
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@
<x:String x:Key="Text.Discard" xml:space="preserve">Discard Changes</x:String>
<x:String x:Key="Text.Discard.All" xml:space="preserve">All local changes in working copy.</x:String>
<x:String x:Key="Text.Discard.Changes" xml:space="preserve">Changes:</x:String>
<x:String x:Key="Text.Discard.IncludeIgnored" xml:space="preserve">Include ignored files</x:String>
<x:String x:Key="Text.Discard.Total" xml:space="preserve">Total {0} changes will be discard</x:String>
<x:String x:Key="Text.Discard.Warning" xml:space="preserve">You can't undo this action!!!</x:String>
<x:String x:Key="Text.EditRepositoryNode.Bookmark" xml:space="preserve">Bookmark:</x:String>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Locales/zh_CN.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
<x:String x:Key="Text.Discard" xml:space="preserve">放弃更改确认</x:String>
<x:String x:Key="Text.Discard.All" xml:space="preserve">所有本地址未提交的修改。</x:String>
<x:String x:Key="Text.Discard.Changes" xml:space="preserve">变更 :</x:String>
<x:String x:Key="Text.Discard.IncludeIgnored" xml:space="preserve">包括所有已忽略的文件</x:String>
<x:String x:Key="Text.Discard.Total" xml:space="preserve">总计{0}项选中更改</x:String>
<x:String x:Key="Text.Discard.Warning" xml:space="preserve">本操作不支持回退,请确认后继续!!!</x:String>
<x:String x:Key="Text.EditRepositoryNode.Bookmark" xml:space="preserve">书签 :</x:String>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Locales/zh_TW.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
<x:String x:Key="Text.Discard" xml:space="preserve">捨棄變更</x:String>
<x:String x:Key="Text.Discard.All" xml:space="preserve">所有本機未提交的變更。</x:String>
<x:String x:Key="Text.Discard.Changes" xml:space="preserve">變更:</x:String>
<x:String x:Key="Text.Discard.IncludeIgnored" xml:space="preserve">包括所有已忽略的檔案</x:String>
<x:String x:Key="Text.Discard.Total" xml:space="preserve">將捨棄總計 {0} 項已選取的變更</x:String>
<x:String x:Key="Text.Discard.Warning" xml:space="preserve">您無法復原此操作,請確認後再繼續!</x:String>
<x:String x:Key="Text.EditRepositoryNode.Bookmark" xml:space="preserve">書籤:</x:String>
Expand Down
3 changes: 1 addition & 2 deletions src/ViewModels/Checkout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public class Checkout : Popup
public string Branch
{
get;
private set;
}

public Models.DealWithLocalChanges PreAction
Expand Down Expand Up @@ -49,7 +48,7 @@ public override Task<bool> Sure()
else if (PreAction == Models.DealWithLocalChanges.Discard)
{
SetProgressDescription("Discard local changes ...");
Commands.Discard.All(_repo.FullPath);
Commands.Discard.All(_repo.FullPath, false);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/ViewModels/CheckoutCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public class CheckoutCommit : Popup
public Models.Commit Commit
{
get;
private set;
}

public bool AutoStash
Expand Down Expand Up @@ -49,7 +48,7 @@ public override Task<bool> Sure()
else
{
SetProgressDescription("Discard local changes ...");
Commands.Discard.All(_repo.FullPath);
Commands.Discard.All(_repo.FullPath, false);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/ViewModels/CreateBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public string Name
public object BasedOn
{
get;
private set;
}

public Models.DealWithLocalChanges PreAction
Expand Down Expand Up @@ -105,7 +104,7 @@ public override Task<bool> Sure()
else if (PreAction == Models.DealWithLocalChanges.Discard)
{
SetProgressDescription("Discard local changes...");
Commands.Discard.All(_repo.FullPath);
Commands.Discard.All(_repo.FullPath, false);
}
}
Expand Down
40 changes: 33 additions & 7 deletions src/ViewModels/Discard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,45 @@

namespace SourceGit.ViewModels
{
public class DiscardAllMode
{
public bool IncludeIgnored
{
get;
set;
} = false;
}

public class DiscardSingleFile
{
public string Path
{
get;
set;
} = string.Empty;
}

public class DiscardMultipleFiles
{
public int Count
{
get;
set;
} = 0;
}

public class Discard : Popup
{
public object Mode
{
get;
private set;
}

public Discard(Repository repo)
{
_repo = repo;

Mode = new Models.Null();
Mode = new DiscardAllMode();
View = new Views.Discard { DataContext = this };
}

Expand All @@ -25,11 +51,11 @@ public Discard(Repository repo, List<Models.Change> changes)
_changes = changes;

if (_changes == null)
Mode = new Models.Null();
Mode = new DiscardAllMode();
else if (_changes.Count == 1)
Mode = _changes[0].Path;
Mode = new DiscardSingleFile() { Path = _changes[0].Path };
else
Mode = _changes.Count;
Mode = new DiscardMultipleFiles() { Count = _changes.Count };

View = new Views.Discard() { DataContext = this };
}
Expand All @@ -41,8 +67,8 @@ public override Task<bool> Sure()

return Task.Run(() =>
{
if (_changes == null)
Commands.Discard.All(_repo.FullPath);
if (Mode is DiscardAllMode all)
Commands.Discard.All(_repo.FullPath, all.IncludeIgnored);
else
Commands.Discard.Changes(_repo.FullPath, _changes);
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/Pull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public override Task<bool> Sure()
else if (PreAction == Models.DealWithLocalChanges.Discard)
{
SetProgressDescription("Discard local changes ...");
Commands.Discard.All(_repo.FullPath);
Commands.Discard.All(_repo.FullPath, false);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/ViewModels/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,6 @@ public ContextMenu CreateContextMenuForLocalBranch(Models.Branch branch)
var discard = new MenuItem();
discard.Header = App.Text("BranchCM.DiscardAll");
discard.Icon = App.CreateMenuIcon("Icons.Undo");
discard.IsEnabled = _localChangesCount > 0;
discard.Click += (_, e) =>
{
if (PopupHost.CanCreatePopup())
Expand Down
85 changes: 59 additions & 26 deletions src/Views/Discard.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
Expand All @@ -12,35 +11,69 @@
<TextBlock FontSize="18"
Classes="bold"
Text="{DynamicResource Text.Discard}"/>

<Grid Margin="0,16,0,8" RowDefinitions="32,32" ColumnDefinitions="120,*">
<TextBlock Grid.Row="0" Grid.Column="0" Margin="0,0,8,0" HorizontalAlignment="Right" Text="{DynamicResource Text.Discard.Changes}"/>
<ContentControl Grid.Row="0" Grid.Column="1" Content="{Binding Mode}">
<ContentControl.DataTemplates>
<DataTemplate DataType="m:Null">
<StackPanel Orientation="Horizontal">
<Path Width="12" Height="12" Margin="0,2,0,0" Data="{StaticResource Icons.Folder.Open}"/>
<TextBlock Text="{DynamicResource Text.Discard.All}" Margin="4,0,0,0"/>

<ContentControl Margin="0,16,0,8" Content="{Binding Mode}">
<ContentControl.DataTemplates>
<DataTemplate DataType="vm:DiscardAllMode">
<Grid RowDefinitions="Auto,Auto,36" ColumnDefinitions="120,*">
<TextBlock Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
HorizontalAlignment="Right"
Text="{DynamicResource Text.Discard.Changes}"/>
<TextBlock Grid.Row="0" Grid.Column="1"
Text="{DynamicResource Text.Discard.All}"/>

<CheckBox Grid.Row="1" Grid.Column="1"
Content="{DynamicResource Text.Discard.IncludeIgnored}"
IsChecked="{Binding IncludeIgnored, Mode=TwoWay}"/>

<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
<Path Width="14" Height="14"
Data="{StaticResource Icons.Error}"
Fill="DarkOrange"/>
<TextBlock Margin="4,0,0,0"
Text="{DynamicResource Text.Discard.Warning}"
Foreground="{DynamicResource Brush.FG2}"/>
</StackPanel>
</DataTemplate>

<DataTemplate DataType="x:String">
<StackPanel Orientation="Horizontal">
</Grid>
</DataTemplate>

<DataTemplate DataType="vm:DiscardSingleFile">
<Grid RowDefinitions="32,32" ColumnDefinitions="120,*">
<TextBlock Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
HorizontalAlignment="Right"
Text="{DynamicResource Text.Discard.Changes}"/>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
<Path Width="12" Height="12" Data="{StaticResource Icons.File}"/>
<TextBlock Text="{Binding}" Margin="4,0,0,0"/>
<TextBlock Text="{Binding Path}" Margin="4,0,0,0"/>
</StackPanel>
</DataTemplate>

<DataTemplate DataType="x:Int32">
<StackPanel Orientation="Horizontal">

<TextBlock Grid.Row="1" Grid.Column="1"
VerticalAlignment="Center"
Text="{DynamicResource Text.Discard.Warning}"
Foreground="{DynamicResource Brush.FG2}"/>
</Grid>
</DataTemplate>

<DataTemplate DataType="vm:DiscardMultipleFiles">
<Grid RowDefinitions="32,32" ColumnDefinitions="120,*">
<TextBlock Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
HorizontalAlignment="Right"
Text="{DynamicResource Text.Discard.Changes}"/>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
<Path Width="12" Height="12" Data="{StaticResource Icons.File}"/>
<TextBlock Text="{Binding Converter={x:Static c:StringConverters.FormatByResourceKey}, ConverterParameter='Discard.Total'}" Margin="4,0,0,0"/>
<TextBlock Text="{Binding Count, Converter={x:Static c:StringConverters.FormatByResourceKey}, ConverterParameter='Discard.Total'}" Margin="4,0,0,0"/>
</StackPanel>
</DataTemplate>
</ContentControl.DataTemplates>
</ContentControl>

<TextBlock Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Text="{DynamicResource Text.Discard.Warning}" Foreground="{DynamicResource Brush.FG2}"/>
</Grid>

<TextBlock Grid.Row="1" Grid.Column="1"
VerticalAlignment="Center"
Text="{DynamicResource Text.Discard.Warning}"
Foreground="{DynamicResource Brush.FG2}"/>
</Grid>
</DataTemplate>
</ContentControl.DataTemplates>
</ContentControl>
</StackPanel>
</UserControl>

0 comments on commit 5c4660d

Please sign in to comment.