Skip to content

Modernization #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions DiffPlex.App/DiffPlex.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net9.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<WindowsSdkPackageVersion>10.0.19041.48</WindowsSdkPackageVersion>
<WindowsSdkPackageVersion>10.0.19041.57</WindowsSdkPackageVersion>
<RootNamespace>DiffPlex.UI</RootNamespace>
<AssemblyName>DiffPlex.App</AssemblyName>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Version>1.2.0</Version>
<Version>2.0.0</Version>
<PackageTags>diff</PackageTags>
<Description>Diff files and text.</Description>
<LangVersion>13.0</LangVersion>
<AssemblyVersion>1.2.0.0</AssemblyVersion>
<FileVersion>1.2.0.0</FileVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
<Platforms>x86;x64;arm64</Platforms>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
Expand Down Expand Up @@ -44,7 +44,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.241114003" />
<PackageReference Include="Microsoft.WindowsAppSDK" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion DiffPlex.App/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Identity
Name="ea50cd11-3ec2-4c0f-a744-2ec6e937e6ea"
Publisher="CN=mmanela"
Version="1.0.0.0" />
Version="2.0.0.0" />

<Properties>
<DisplayName>DiffPlex</DisplayName>
Expand Down
4 changes: 2 additions & 2 deletions DiffPlex.Windows/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public object Convert(object value, Type targetType, object parameter, string la
{
if (targetType == typeof(IEnumerable<TextHighlighter>))
{
if (value is not List<DiffPiece> sub)
if (value is not IEnumerable<DiffPiece> sub)
{
if (value is not DiffPiece diffPiece) return null;
sub = diffPiece.SubPieces;
Expand Down Expand Up @@ -144,7 +144,7 @@ public class DiffTextHighlighterConverter(ChangeType defaultChangeType) : IValue
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is FrameworkElement element) value = element.DataContext;
if (value is not List<DiffPiece> sub)
if (value is not IEnumerable<DiffPiece> sub)
{
if (value is DiffPiece p) sub = p.SubPieces;
else return null;
Expand Down
14 changes: 7 additions & 7 deletions DiffPlex.Windows/DiffPlex.Windows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<PackageId>DiffPlex.Windows</PackageId>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
<Version>1.2.0</Version>
<Version>2.0.0</Version>
<PackageTags>diff</PackageTags>
<PackageIcon>diffplex_icon.png</PackageIcon>
<Description>DiffPlex.Windows is a Windows App SDK control library that allows you to programatically render visual text diffs in your application.</Description>
<LangVersion>13.0</LangVersion>
<AssemblyVersion>1.2.0.0</AssemblyVersion>
<FileVersion>1.2.0.0</FileVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
<Authors>Kingcean Tuan; Matthew Manela</Authors>
<Copyright>Copyright (c) 2022 Matthew Manela. All rights reserved.</Copyright>
<ApplicationIcon>../DiffPlex.ico</ApplicationIcon>
Expand All @@ -35,10 +35,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.241114003" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
<PackageReference Include="Trivial.WindowsKit" Version="9.2.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.WindowsAppSDK" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
<PackageReference Include="Trivial.WindowsKit" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions DiffPlex.Windows/DiffTextView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public sealed partial class DiffTextView : UserControl

private readonly DiffTextViewReference reference;
private List<DiffTextViewModel> sideBySide;
private List<DiffPiece> inlines;
private IReadOnlyList<DiffPiece> inlines;
private bool skipRefresh = true;

/// <summary>
Expand Down Expand Up @@ -815,8 +815,8 @@ private void RefreshSplitView(bool forceToUpdate = false)
if (SplitElement.ItemsSource != null && !forceToUpdate) return;
sideBySide = null;
var diff = SideBySideDiffBuilder.Diff(OldText ?? string.Empty, NewText ?? string.Empty, IgnoreWhiteSpace, !IsCaseSensitive);
var left = diff?.OldText?.Lines ?? new();
var right = diff?.NewText?.Lines ?? new();
var left = diff?.OldText?.Lines ?? new List<DiffPiece>();
var right = diff?.NewText?.Lines ?? new List<DiffPiece>();
var count = Math.Max(left.Count, right.Count);
var col = new List<DiffTextViewModel>();
var add = 0;
Expand Down
2 changes: 1 addition & 1 deletion DiffPlex.Windows/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal class InternalUtilities

public static readonly SolidColorBrush GrayBackground = new(Color.FromArgb(32, 128, 128, 128));

public static List<TextHighlighter> GetTextHighlighter(List<DiffPiece> sub, ChangeType modify, Brush foreground)
public static List<TextHighlighter> GetTextHighlighter(IEnumerable<DiffPiece> sub, ChangeType modify, Brush foreground)
{
if (sub == null) return null;
var insert = new TextHighlighter
Expand Down
59 changes: 29 additions & 30 deletions DiffPlex.Windows/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public enum DiffTextViewType : byte
Right = 3,
}

/// <summary>
/// The view info of diff text.
/// </summary>
public struct DiffTextViewInfo
{
private readonly object token;
Expand All @@ -48,12 +51,14 @@ internal DiffTextViewInfo(object token, DiffTextViewType viewType, DiffPiece mod
{
this.token = token ?? new();
ViewType = viewType;
model ??= new();
ChangeType = model.Type;
Position = model.Position;
Text = model.Text;
Model = model ?? new();
}

/// <summary>
/// Gets the data model of source.
/// </summary>
public DiffPiece Model { get; }

/// <summary>
/// Gets the view type.
/// </summary>
Expand All @@ -62,41 +67,27 @@ internal DiffTextViewInfo(object token, DiffTextViewType viewType, DiffPiece mod
/// <summary>
/// Gets the change type.
/// </summary>
public ChangeType ChangeType { get; }
public ChangeType ChangeType => Model.Type;

/// <summary>
/// Gets the line position.
/// </summary>
public int? Position { get; }
public int? Position => Model.Position;

/// <summary>
/// Gets the content text.
/// </summary>
public string Text { get; }
public string Text => Model.Text;

/// <summary>
/// Gets the sub pieces.
/// </summary>
public IReadOnlyList<DiffPiece> SubPieces => Model.SubPieces;

/// <inheritdoc />
public override string ToString()
{
var sb = new StringBuilder();
if (Position.HasValue)
{
sb.Append(Position.Value);
sb.Append(' ');
}

switch (ChangeType)
{
case ChangeType.Inserted:
sb.Append("+ ");
break;
case ChangeType.Deleted:
sb.Append("- ");
break;
}

sb.Append('\t');
sb.Append(Text);
return sb.ToString();
return Model.ToString();
}

/// <summary>
Expand All @@ -105,7 +96,17 @@ public override string ToString()
/// <param name="token">The token to test.</param>
/// <returns>true if the same; otherwise, false.</returns>
internal bool IsToken(object token)
=> token == this.token;
{
return token == this.token;
}

/// <summary>
/// Writes current diff piece into UTF-8 JSON stream.
/// </summary>
/// <param name="writer">The UTF-8 JSON stream writer.</param>
/// <param name="options">The JSON srialization options.</param>
public void Write(System.Text.Json.Utf8JsonWriter writer, System.Text.Json.JsonSerializerOptions options)
=> Model.Write(writer, options);
}

/// <summary>
Expand Down Expand Up @@ -171,8 +172,6 @@ public bool Equals(DiffTextViewInfo other)
/// </summary>
internal class DiffTextViewModel : BaseDiffTextViewModel
{
private object token = new();

/// <summary>
/// Initializes a new instance of the <see cref="DiffTextViewModel"/> class.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net8.0-windows;net48;net46</TargetFrameworks>
<TargetFrameworks>net8.0-windows;net48;net462</TargetFrameworks>
<UseWindowsForms>true</UseWindowsForms>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<ApplicationIcon>..\DiffPlex.ico</ApplicationIcon>
Expand Down
2 changes: 1 addition & 1 deletion DiffPlex.Wpf.Demo/DiffPlex.Wpf.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net9.0-windows;net8.0-windows;net48;net46</TargetFrameworks>
<TargetFrameworks>net9.0-windows;net8.0-windows;net48;net462</TargetFrameworks>
<UseWPF>true</UseWPF>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<StartupObject>DiffPlex.Wpf.Demo.App</StartupObject>
Expand Down
14 changes: 7 additions & 7 deletions DiffPlex.Wpf/Controls/DiffViewer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ private void RenderSideBySideDiffs()
private void RenderInlineDiffs()
{
if (inlineResult?.Lines == null) return;
ICollection<DiffPiece> selectedLines = inlineResult.Lines;
IReadOnlyCollection<DiffPiece> selectedLines = inlineResult.Lines;
Helper.RenderInlineDiffs(InlineContentPanel, selectedLines, this, IgnoreUnchanged ? LinesContext : -1);
}

Expand All @@ -1183,12 +1183,12 @@ private void RightContentPanel_ScrollChanged(object sender, ScrollChangedEventAr

private void ApplyHeaderTextProperties(TextBlock text)
{
text.SetBinding(TextBlock.FontSizeProperty, new Binding("FontSize") { Source = this, Mode = BindingMode.OneWay });
text.SetBinding(TextBlock.FontFamilyProperty, new Binding("FontFamily") { Source = this, Mode = BindingMode.OneWay });
text.SetBinding(TextBlock.FontWeightProperty, new Binding("FontWeight") { Source = this, Mode = BindingMode.OneWay });
text.SetBinding(TextBlock.FontStretchProperty, new Binding("FontStretch") { Source = this, Mode = BindingMode.OneWay });
text.SetBinding(TextBlock.FontStyleProperty, new Binding("FontStyle") { Source = this, Mode = BindingMode.OneWay });
text.SetBinding(TextBlock.ForegroundProperty, new Binding("HeaderForeground") { Source = this, Mode = BindingMode.OneWay, TargetNullValue = Foreground });
text.SetBinding(TextBlock.FontSizeProperty, new Binding(nameof(FontSize)) { Source = this, Mode = BindingMode.OneWay });
text.SetBinding(TextBlock.FontFamilyProperty, new Binding(nameof(FontFamily)) { Source = this, Mode = BindingMode.OneWay });
text.SetBinding(TextBlock.FontWeightProperty, new Binding(nameof(FontWeight)) { Source = this, Mode = BindingMode.OneWay });
text.SetBinding(TextBlock.FontStretchProperty, new Binding(nameof(FontStretch)) { Source = this, Mode = BindingMode.OneWay });
text.SetBinding(TextBlock.FontStyleProperty, new Binding(nameof(FontStyle)) { Source = this, Mode = BindingMode.OneWay });
text.SetBinding(TextBlock.ForegroundProperty, new Binding(nameof(HeaderForeground)) { Source = this, Mode = BindingMode.OneWay, TargetNullValue = Foreground });
}

private void UpdateHeaderText()
Expand Down
8 changes: 4 additions & 4 deletions DiffPlex.Wpf/Controls/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static class Helper
/// <summary>
/// Updates the inline diffs view.
/// </summary>
internal static void RenderInlineDiffs(InternalLinesViewer viewer, ICollection<DiffPiece> lines, UIElement source, int contextLineCount)
internal static void RenderInlineDiffs(InternalLinesViewer viewer, IReadOnlyCollection<DiffPiece> lines, UIElement source, int contextLineCount)
{
viewer.Clear();
if (lines == null) return;
Expand Down Expand Up @@ -84,7 +84,7 @@ internal static void RenderInlineDiffs(InternalLinesViewer viewer, ICollection<D
viewer.AdjustScrollView();
}

internal static void InsertLines(InternalLinesViewer panel, List<DiffPiece> lines, bool isOld, UIElement source, int contextLineCount)
internal static void InsertLines(InternalLinesViewer panel, IReadOnlyCollection<DiffPiece> lines, bool isOld, UIElement source, int contextLineCount)
{
if (lines == null || panel == null) return;
var guid = panel.TrackingId = Guid.NewGuid();
Expand All @@ -98,7 +98,7 @@ internal static void InsertLines(InternalLinesViewer panel, List<DiffPiece> line
_ = InsertLinesAsync(guid, panel, lines, isOld, source, contextLineCount);
}

private static async Task InsertLinesAsync(Guid guid, InternalLinesViewer panel, List<DiffPiece> lines, bool isOld, UIElement source, int contextLineCount)
private static async Task InsertLinesAsync(Guid guid, InternalLinesViewer panel, IReadOnlyCollection<DiffPiece> lines, bool isOld, UIElement source, int contextLineCount)
{ // For performance.
if (lines == null || panel == null) return;
var disablePieces = lines.Count > MaxCount;
Expand Down Expand Up @@ -474,7 +474,7 @@ private static List<KeyValuePair<string, string>> GetSubPiecesInfo(DiffPiece lin
return details;
}

private static void InsertLinesInteral(InternalLinesViewer panel, List<DiffPiece> lines, bool isOld, UIElement source, bool disableSubPieces = false)
private static void InsertLinesInteral(InternalLinesViewer panel, IReadOnlyCollection<DiffPiece> lines, bool isOld, UIElement source, bool disableSubPieces = false)
{
foreach (var line in lines)
{
Expand Down
2 changes: 1 addition & 1 deletion DiffPlex.Wpf/Controls/InlineDiffViewer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public DiffPaneModel DiffModel
/// <summary>
/// Gets the lines in the diff model.
/// </summary>
public IReadOnlyList<DiffPiece> Lines => DiffModel?.Lines?.AsReadOnly();
public IReadOnlyList<DiffPiece> Lines => DiffModel?.Lines;

/// <summary>
/// Gets or sets the foreground brush of the line number.
Expand Down
10 changes: 5 additions & 5 deletions DiffPlex.Wpf/DiffPlex.Wpf.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\NuGet.props" />
<PropertyGroup>
<TargetFrameworks>net9.0-windows;net8.0-windows;net6.0-windows;net46;net48</TargetFrameworks>
<TargetFrameworks>net9.0-windows;net8.0-windows;net6.0-windows;net462;net48</TargetFrameworks>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<Version>1.5.0</Version>
<Version>1.6.0</Version>
<RootNamespace>DiffPlex.Wpf</RootNamespace>
<AssemblyName>DiffPlex.Wpf</AssemblyName>
<PackageTags>diff, wpf</PackageTags>
<Description>DiffPlex.Wpf is a WPF control library that allows you to programatically render visual text diffs in your application. It also provide a diff viewer control used in Windows Forms application.</Description>
<AssemblyVersion>1.5.0.0</AssemblyVersion>
<FileVersion>1.5.0.0</FileVersion>
<AssemblyVersion>1.6.0.0</AssemblyVersion>
<FileVersion>1.6.0.0</FileVersion>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move all versions to 2.0?

<ApplicationIcon>..\DiffPlex.ico</ApplicationIcon>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
</PropertyGroup>
Expand Down Expand Up @@ -41,7 +41,7 @@
</EmbeddedResource>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net8.0-windows' AND '$(TargetFramework)' != 'net6.0-windows' AND '$(TargetFramework)' != 'net46' AND '$(TargetFramework)' != 'net48'" >
<ItemGroup Condition="'$(TargetFramework)' != 'net8.0-windows' AND '$(TargetFramework)' != 'net6.0-windows' AND '$(TargetFramework)' != 'net46' AND '$(TargetFramework)' != 'net462' AND '$(TargetFramework)' != 'net48'" >
<Compile Remove="Forms\*.cs" />
<EmbeddedResource Remove="Forms\*.resx" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions DiffPlex.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitattributes = .gitattributes
.gitignore = .gitignore
azure-pipelines.yml = azure-pipelines.yml
Directory.Packages.props = Directory.Packages.props
.github\workflows\dotnet.yml = .github\workflows\dotnet.yml
global.json = global.json
License.txt = License.txt
Expand Down
Loading
Loading