mmanela / diffplex

DiffPlex is Netstandard 1.0+ C# library to generate textual diffs.
Apache License 2.0
990 stars 183 forks source link

Next / Previous commands for WPF controls? #106

Closed jskeet closed 1 year ago

jskeet commented 1 year ago

I'm using DiffPlex to show side-by-side differences in config files to a non-technical audience. I'd love to be able to have "next" and "previous" buttons to jump between differences. I can't see anything supporting this, but I may have just missed it.

Is it already actually available - and if not, would it be difficult to add?

mmanela commented 1 year ago

@jskeet Sorry for the slow reply. That is an interesting ask. I assume you are using one of the UI components? Which one are you using?

jskeet commented 1 year ago

Currently I'm just using DiffViewer:

<Window x:Class="AtYourService.CloudStorage.InternalDiffDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        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:diffplex="clr-namespace:DiffPlex.Wpf.Controls;assembly=DiffPlex.Wpf"
        mc:Ignorable="d"
        Title="Diff" Height="450" Width="800">
    <diffplex:DiffViewer IsSideBySide="True" OldTextHeader="Cloud file" NewTextHeader="Local file"
                        IgnoreCase="False" IgnoreWhiteSpace="False"
                        OldText="{Binding OldText}" NewText="{Binding NewText}"
                        x:Name="viewer" />
</Window>
mmanela commented 1 year ago

@kingcean did much of the work here. I don't think the functionality is there today but seems reasonable.

@kingcean curious on how much work you think it is and how you would approach it

kingcean commented 1 year ago

Hi @jskeet next/previous (and also go-to) commands are available in DiffWindow currently now. You can show the window by following sample.

DiffWindow win = new();
win.OldText = oldText;
win.NewText = newText;
win.Show();

Screenshot

But no such functionality to use the DiffViewer element in your control/page/window. I will bring it there soon so you can set property IsCommandBarVisible as true to enable the default UI or call PreviewDiff/NextDiff method.

jskeet commented 1 year ago

Thanks - will have a look. For my particular use case I really don't want "Open file" or (probably) "Switch mode" - but it's possible that this information will be enough for me to implement the necessary bits anyway. Will have a look. Thanks so much for replying :)

jskeet commented 1 year ago

Having looked at the DiffWindow code more closely, it turned out to be easy.

The "move to next diff" and "move to previous" diff could probably be moved from DiffWindow to DiffViewer (and exposed publicly) very easily, which would be somewhat useful for me to avoid the code duplication, but I have all the functionality I need now.

Thanks so much :)

I won't close this issue now in case you want to leave it as a prompt to move the code, but feel free to close it if you don't want to do the move.

kingcean commented 1 year ago

Hi @jskeet #107 has moved these methods into DiffViewer class.

Hi @mmanela could you please upload the packages to NuGet? I have attached them in the PR and you can find them in the last line of the description.

jskeet commented 1 year ago

@kingcean: That's fabulous, thank you :)

Will look forward to updating the NuGet package, but it's really not urgent!

mmanela commented 1 year ago

@jskeet @kingcean I uploaded the new package! Thanks for the suggestion @jskeet and thanks for the quick work @kingcean