mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
feature: allow swap in branch compare
This commit is contained in:
parent
3ef703c65d
commit
ad3eeabb83
3 changed files with 60 additions and 36 deletions
|
@ -14,14 +14,14 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
public Models.Branch Base
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
get => _based;
|
||||
private set => SetProperty(ref _based, value);
|
||||
}
|
||||
|
||||
public Models.Branch To
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
get => _to;
|
||||
private set => SetProperty(ref _to, value);
|
||||
}
|
||||
|
||||
public Models.Commit BaseHead
|
||||
|
@ -50,7 +50,7 @@ namespace SourceGit.ViewModels
|
|||
if (SetProperty(ref _selectedChanges, value))
|
||||
{
|
||||
if (value != null && value.Count == 1)
|
||||
DiffContext = new DiffContext(_repo, new Models.DiffOption(Base.Head, To.Head, value[0]), _diffContext);
|
||||
DiffContext = new DiffContext(_repo, new Models.DiffOption(_based.Head, _to.Head, value[0]), _diffContext);
|
||||
else
|
||||
DiffContext = null;
|
||||
}
|
||||
|
@ -78,34 +78,10 @@ namespace SourceGit.ViewModels
|
|||
public BranchCompare(string repo, Models.Branch baseBranch, Models.Branch toBranch)
|
||||
{
|
||||
_repo = repo;
|
||||
_based = baseBranch;
|
||||
_to = toBranch;
|
||||
|
||||
Base = baseBranch;
|
||||
To = toBranch;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
var baseHead = new Commands.QuerySingleCommit(_repo, Base.Head).Result();
|
||||
var toHead = new Commands.QuerySingleCommit(_repo, To.Head).Result();
|
||||
_changes = new Commands.CompareRevisions(_repo, Base.Head, To.Head).Result();
|
||||
|
||||
var visible = _changes;
|
||||
if (!string.IsNullOrWhiteSpace(_searchFilter))
|
||||
{
|
||||
visible = new List<Models.Change>();
|
||||
foreach (var c in _changes)
|
||||
{
|
||||
if (c.Path.Contains(_searchFilter, StringComparison.OrdinalIgnoreCase))
|
||||
visible.Add(c);
|
||||
}
|
||||
}
|
||||
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
BaseHead = baseHead;
|
||||
ToHead = toHead;
|
||||
VisibleChanges = visible;
|
||||
});
|
||||
});
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void NavigateTo(string commitSHA)
|
||||
|
@ -114,6 +90,17 @@ namespace SourceGit.ViewModels
|
|||
repo?.NavigateToCommit(commitSHA);
|
||||
}
|
||||
|
||||
public void Swap()
|
||||
{
|
||||
(Base, To) = (_to, _based);
|
||||
SelectedChanges = [];
|
||||
|
||||
if (_baseHead != null)
|
||||
(BaseHead, ToHead) = (_toHead, _baseHead);
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void ClearSearchFilter()
|
||||
{
|
||||
SearchFilter = string.Empty;
|
||||
|
@ -134,7 +121,7 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
var toolType = Preference.Instance.ExternalMergeToolType;
|
||||
var toolPath = Preference.Instance.ExternalMergeToolPath;
|
||||
var opt = new Models.DiffOption(Base.Head, To.Head, change);
|
||||
var opt = new Models.DiffOption(_based.Head, _to.Head, change);
|
||||
|
||||
Task.Run(() => Commands.MergeTool.OpenForDiff(_repo, toolType, toolPath, opt));
|
||||
ev.Handled = true;
|
||||
|
@ -179,6 +166,38 @@ namespace SourceGit.ViewModels
|
|||
return menu;
|
||||
}
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
if (_baseHead == null)
|
||||
{
|
||||
var baseHead = new Commands.QuerySingleCommit(_repo, _based.Head).Result();
|
||||
var toHead = new Commands.QuerySingleCommit(_repo, _to.Head).Result();
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
BaseHead = baseHead;
|
||||
ToHead = toHead;
|
||||
});
|
||||
}
|
||||
|
||||
_changes = new Commands.CompareRevisions(_repo, _based.Head, _to.Head).Result();
|
||||
|
||||
var visible = _changes;
|
||||
if (!string.IsNullOrWhiteSpace(_searchFilter))
|
||||
{
|
||||
visible = new List<Models.Change>();
|
||||
foreach (var c in _changes)
|
||||
{
|
||||
if (c.Path.Contains(_searchFilter, StringComparison.OrdinalIgnoreCase))
|
||||
visible.Add(c);
|
||||
}
|
||||
}
|
||||
|
||||
Dispatcher.UIThread.Invoke(() => VisibleChanges = visible);
|
||||
});
|
||||
}
|
||||
|
||||
private void RefreshVisible()
|
||||
{
|
||||
if (_changes == null)
|
||||
|
@ -202,6 +221,8 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
|
||||
private string _repo;
|
||||
private Models.Branch _based = null;
|
||||
private Models.Branch _to = null;
|
||||
private Models.Commit _baseHead = null;
|
||||
private Models.Commit _toHead = null;
|
||||
private List<Models.Change> _changes = null;
|
||||
|
|
|
@ -69,7 +69,10 @@
|
|||
</Grid>
|
||||
</Border>
|
||||
|
||||
<Path Grid.Column="1" Width="16" Height="16" Fill="{DynamicResource Brush.FG2}" Data="{DynamicResource Icons.Down}" RenderTransformOrigin="50%,50%" RenderTransform="rotate(270deg)"/>
|
||||
<!-- Swap Button -->
|
||||
<Button Grid.Column="1" Classes="icon_button" Command="{Binding Swap}" HorizontalAlignment="Center" ToolTip.Tip="{DynamicResource Text.Diff.SwapCommits}">
|
||||
<Path Width="16" Height="16" Fill="{DynamicResource Brush.FG2}" Data="{DynamicResource Icons.Compare}"/>
|
||||
</Button>
|
||||
|
||||
<Border Grid.Column="2" BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="1" Background="{DynamicResource Brush.Contents}" CornerRadius="4" Padding="4">
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
|
|
|
@ -47,8 +47,8 @@
|
|||
</Border>
|
||||
|
||||
<!-- Swap Button -->
|
||||
<Button Classes="icon_button" Command="{Binding Swap}" Grid.Column="1" HorizontalAlignment="Center" ToolTip.Tip="{DynamicResource Text.Diff.SwapCommits}">
|
||||
<Path Grid.Column="1" Width="16" Height="16" Fill="{DynamicResource Brush.FG2}" Data="{DynamicResource Icons.Compare}"/>
|
||||
<Button Grid.Column="1" Classes="icon_button" Command="{Binding Swap}" HorizontalAlignment="Center" ToolTip.Tip="{DynamicResource Text.Diff.SwapCommits}">
|
||||
<Path Width="16" Height="16" Fill="{DynamicResource Brush.FG2}" Data="{DynamicResource Icons.Compare}"/>
|
||||
</Button>
|
||||
|
||||
<!-- Right Revision -->
|
||||
|
|
Loading…
Reference in a new issue