Skip to content

Commit

Permalink
Added explicit File (Binary, XML, Text) Compare option in Context Men…
Browse files Browse the repository at this point in the history
…u of Dir Diff View
  • Loading branch information
Dirkster99 committed Aug 4, 2020
1 parent 6d504c8 commit 78a71dd
Show file tree
Hide file tree
Showing 10 changed files with 725 additions and 480 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Aehnlich.ViewModels.Documents
{
using Aehnlich.Interfaces;
using AehnlichLib.Enums;
using AehnlichViewModelsLib.Enums;
using HL.Interfaces;
using System;
Expand Down Expand Up @@ -35,17 +36,19 @@ internal class DocDiffDocViewViewModel : DocumentBaseViewModel, TextDocDifferenc
/// <param name="docManager"></param>
/// <param name="leftDirPath"></param>
/// <param name="rightDirPath"></param>
/// <param name="compareAs"></param>
public DocDiffDocViewViewModel(IDocumentManagerViewModel docManager,
string leftFilePath,
string rightFilePath)
string rightFilePath,
CompareType compareAs)
: this()
{
_DocumentManager = docManager;
this.ContentId = GetContentId(leftFilePath, rightFilePath);

Title = GetTitle(leftFilePath, rightFilePath, false);
ToolTip = GetTooltip(leftFilePath, rightFilePath);
DocDiffDoc = AehnlichViewModelsLib.ViewModels.Factory.ConstructAppViewModel(leftFilePath, rightFilePath);
DocDiffDoc = AehnlichViewModelsLib.ViewModels.Factory.ConstructAppViewModel(leftFilePath, rightFilePath, compareAs);

DocDiffDoc.DocumentPropertyChanged += DocDiffDoc_DocumentPropertyChanged;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void DocDiffDoc_CompareFilesRequest(object sender, OpenFileDiffEventArgs

if (oldDoc == null) // Add new document and activate it
{
var newDoc = new DocDiffDocViewViewModel(this, e.ItemPathA, e.ItemPathB);
var newDoc = new DocDiffDocViewViewModel(this, e.ItemPathA, e.ItemPathB, e.CompareAs);

// CompareFilesCommand is executed via ViewLoadedCommand()
AddDocument(newDoc, true);
Expand Down
20 changes: 10 additions & 10 deletions source/Aehnlich/Aehnlich/Views/Dir/DirDiffDocView.xaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<UserControl
x:Class="Aehnlich.Views.Dir.DirDiffDocView"
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:views="clr-namespace:AehnlichDirViewModelLib.Views;assembly=AehnlichDirViewModelLib"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
x:Class="Aehnlich.Views.Dir.DirDiffDocView"
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:views="clr-namespace:AehnlichDirViewModelLib.Views;assembly=AehnlichDirViewModelLib"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">

<views:DirDiffView Margin="3" DataContext="{Binding DirDiffDoc}" />
<views:DirDiffView Margin="3" DataContext="{Binding DirDiffDoc}" />
</UserControl>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace AehnlichDirViewModelLib.Events
{
using AehnlichDirViewModelLib.Interfaces;
using AehnlichLib.Enums;
using System;

/// <summary>
Expand All @@ -10,6 +11,17 @@
public class OpenFileDiffEventArgs : EventArgs
{
#region ctors
/// <summary>
/// Class constructor
/// </summary>
/// <param name="pathItem"></param>
/// <param name="compareAs"></param>
public OpenFileDiffEventArgs(IDirEntryViewModel pathItem, CompareType compareAs)
: this(pathItem)
{
CompareAs = compareAs;
}

/// <summary>
/// Class constructor
/// </summary>
Expand All @@ -31,6 +43,7 @@ public OpenFileDiffEventArgs(IDirEntryViewModel pathItem)
/// </summary>
protected OpenFileDiffEventArgs()
{
CompareAs = CompareType.Auto;
}
#endregion ctors

Expand Down Expand Up @@ -65,6 +78,11 @@ protected OpenFileDiffEventArgs()
/// Gets whether this entry represent a file (true), or not (directory or drive).
/// </summary>
public bool IsFile { get; }

/// <summary>
/// Determines the mode of comparison when files are compared (default is Auto).
/// </summary>
public CompareType CompareAs { get; }
#endregion properties
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using AehnlichDirViewModelLib.Models;
using AehnlichDirViewModelLib.ViewModels.Base;
using AehnlichLib.Dir;
using AehnlichLib.Enums;
using AehnlichLib.Interfaces;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -33,6 +34,7 @@ internal class DirDiffDocViewModel : Base.ViewModelBase, IDirDiffDocViewModel
private DiffViewModeEnum _CurrentViewMode = DiffViewModeEnum.DirectoriesAndFiles;

private ICommand _BrowseItemCommand;
private ICommand _CompareFilesCommand;
private ICommand _BrowseUpCommand;
private ICommand _OpenContainingFolderCommand;
private ICommand _OpenInWindowsCommand;
Expand Down Expand Up @@ -350,6 +352,90 @@ public ICommand BrowseItemCommand
}
}

/// <summary>
/// Gets a command to browse the current directory diff view by one level down
/// (if there is a current view and a remaining level down is available).
/// </summary>
public ICommand CompareFilesCommand
{
get
{
if (_CompareFilesCommand == null)
{
_CompareFilesCommand = new RelayCommand<object>((p) =>
{
IDirEntryViewModel param = null;
CompareType compareAs = CompareType.Auto;
bool hasParams = ConvertParameter(p, out param, out compareAs);

if (hasParams == false)
{
bool? fromA;
param = GetSelectedItem(out fromA);

if (param == null)
return;
}

if (param.IsFile == false)
return;

// Send an event to Open a (text) file diff view for this
// If there is a listner doing the open part and view ...
this.CompareFilesRequest?.Invoke(this, new OpenFileDiffEventArgs(param, compareAs));
return;

}, ((p) =>
{
IDirEntryViewModel param = null;
CompareType compareAs = CompareType.Auto;
bool hasParams = ConvertParameter(p, out param, out compareAs);

if (hasParams == false)
{
bool? fromA;
param = GetSelectedItem(out fromA);

if (param == null)
return false;
}

if (param.IsFile == false)
return false;

return true;
}));
}

return _CompareFilesCommand;
}
}

private static bool ConvertParameter(object p, out IDirEntryViewModel param, out CompareType compareAs)
{
param = null;
compareAs = CompareType.Auto;

if (p == null)
return false;

var paras = p as object[];
if (paras == null)
return false;

if (paras.Length != 2)
return false;

if (paras[0] is IDirEntryViewModel == false || paras[1] is CompareType == false)
return false;

param = paras[0] as IDirEntryViewModel;
compareAs = (CompareType)paras[1];

return true;
}


/// <summary>
/// Gets a command to browse the current directory diff view by one level
/// up in the directory hierarchy
Expand Down
Loading

0 comments on commit 78a71dd

Please sign in to comment.