Browse Source

refactor(RevisionDiffControl): Use simpler types

Refs: #12160
pull/12160/head
Michael Seibt 6 months ago
parent
commit
262271318d
  1. 1
      Directory.Packages.props
  2. 4
      setup/installer/Product.wxs
  3. 10
      src/app/GitExtensions.Extensibility/Git/RelativePath.cs
  4. 1
      src/app/GitExtensions.Extensibility/GitExtensions.Extensibility.csproj
  5. 16
      src/app/GitUI/CommandsDialogs/RevisionDiffControl.cs

1
Directory.Packages.props

@ -14,6 +14,7 @@
<PackageVersion Include="LibGit2Sharp" Version="0.27.2" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="Microsoft.Toolkit.HighPerformance" Version="7.1.2" />
<PackageVersion Include="StrongOf" Version="1.2.4" />
<PackageVersion Include="System.ComponentModel.Composition" Version="6.0.0" /> <!-- Required by GitExtensions.PluginManager -->
<PackageVersion Include="Microsoft.VisualStudio.Composition" Version="17.2.41" />
<PackageVersion Include="Microsoft.VisualStudio.Threading" Version="17.4.27" />

4
setup/installer/Product.wxs

@ -197,6 +197,9 @@
<Component Id="SpellChecker.dll" Guid="*">
<File Source="$(var.ArtifactsPublishPath)\SpellChecker.dll" />
</Component>
<Component Id="StrongOf.dll" Guid="*">
<File Source="$(var.ArtifactsPublishPath)\BenjaminAbt.StrongOf.dll" />
</Component>
<Component Id="System.ComponentModel.Composition.dll" Guid="*">
<File Source="$(var.ArtifactsPublishPath)\System.ComponentModel.Composition.dll" />
</Component>
@ -674,6 +677,7 @@
<ComponentRef Id="SmartFormat.dll" />
<ComponentRef Id="SmartFormat.ZString.dll" />
<ComponentRef Id="SpellChecker.dll" />
<ComponentRef Id="StrongOf.dll" />
<ComponentRef Id="System.ComponentModel.Composition.dll" />
<ComponentRef Id="System.Composition.AttributedModel.dll" />
<ComponentRef Id="System.Composition.Convention.dll" />

10
src/app/GitExtensions.Extensibility/Git/RelativePath.cs

@ -0,0 +1,10 @@
using StrongOf;
namespace GitExtensions.Extensibility.Git;
/// <summary>
/// Contains a path relative to the root of a repository (with POSIX path separators).
/// </summary>
public sealed class RelativePath(string value) : StrongString<RelativePath>(value)
{
}

1
src/app/GitExtensions.Extensibility/GitExtensions.Extensibility.csproj

@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="AdysTech.CredentialManager" />
<PackageReference Include="StrongOf" />
</ItemGroup>
<ItemGroup>

16
src/app/GitUI/CommandsDialogs/RevisionDiffControl.cs

@ -46,9 +46,9 @@ namespace GitUI.CommandsDialogs
private readonly RememberFileContextMenuController _rememberFileContextMenuController
= RememberFileContextMenuController.Default;
private Action? _refreshGitStatus;
private FileStatusItem? _selectedBlameItem;
private GitItemStatus? _selectedBlameItem;
private string? _fallbackFollowedFile;
private FileStatusItem? _lastExplicitlySelectedItem;
private RelativePath? _lastExplicitlySelectedItem;
private bool _isImplicitListSelection = false;
public RevisionDiffControl()
@ -310,7 +310,7 @@ namespace GitUI.CommandsDialogs
// First try the last item explicitly selected
if (_lastExplicitlySelectedItem is not null
&& firstGroupItems.FirstOrDefault(i => i.Item.Name.Equals(_lastExplicitlySelectedItem.Item.Name))?.Item is GitItemStatus explicitItem)
&& firstGroupItems.FirstOrDefault(i => i.Item.Name.Equals(_lastExplicitlySelectedItem.Value))?.Item is GitItemStatus explicitItem)
{
DiffFiles.SelectedGitItem = explicitItem;
return;
@ -628,17 +628,17 @@ namespace GitUI.CommandsDialogs
private void DiffFiles_SelectedIndexChanged(object sender, EventArgs e)
{
// Switch to diff if the selection changes
FileStatusItem? item = DiffFiles.SelectedItem;
if (item is not null && blameToolStripMenuItem.Checked && item.Item.Name != _selectedBlameItem?.Item.Name)
GitItemStatus? item = DiffFiles.SelectedGitItem;
if (item is not null && blameToolStripMenuItem.Checked && item.Name != _selectedBlameItem?.Name)
{
blameToolStripMenuItem.Checked = false;
}
// If this is not occurring after a revision change (implicit selection)
// save the selected item so it can be the "preferred" selection
if (!_isImplicitListSelection && item is not null && !item.Item.IsRangeDiff)
if (!_isImplicitListSelection && item is not null && !item.IsRangeDiff)
{
_lastExplicitlySelectedItem = item;
_lastExplicitlySelectedItem = RelativePath.From(item.Name);
_selectedBlameItem = null;
}
@ -785,7 +785,7 @@ namespace GitUI.CommandsDialogs
{
int? line = DiffText.Visible ? DiffText.CurrentFileLine : BlameControl.CurrentFileLine;
blameToolStripMenuItem.Checked = !blameToolStripMenuItem.Checked;
_selectedBlameItem = blameToolStripMenuItem.Checked ? DiffFiles.SelectedItem : null;
_selectedBlameItem = blameToolStripMenuItem.Checked ? DiffFiles.SelectedItem.Item : null;
ShowSelectedFile(ensureNoSwitchToFilter: true, line);
return;
}

Loading…
Cancel
Save