Skip to content

Commit

Permalink
Added dirty flag (right and left) Asterix display for unsaved changes…
Browse files Browse the repository at this point in the history
… (edit text without saving)
  • Loading branch information
Dirkster99 committed Jun 14, 2020
1 parent ea627fd commit b106e42
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 104 deletions.
1 change: 1 addition & 0 deletions source/AehnlichLib/AehnlichLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Compile Include="Enums\HashType.cs" />
<Compile Include="Enums\DiffDirFileMode.cs" />
<Compile Include="Files\AsyncPump.cs" />
<Compile Include="Files\FileContentInfo.cs" />
<Compile Include="Files\FileEx.cs" />
<Compile Include="Interfaces\Dir\IDataSource.cs" />
<Compile Include="Interfaces\Dir\IDataSourceFactory.cs" />
Expand Down
75 changes: 75 additions & 0 deletions source/AehnlichLib/Files/FileContentInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
namespace AehnlichLib.Files
{
using System;
using System.Collections.Generic;
using System.Text;

/// <summary>
/// Implements a text content container class for the text, lines an other
/// related content specific to computing diffs from texts.
/// </summary>
public class FileContentInfo
{
#region constructors
/// <summary>Class constructor</summary>
/// <param name="isBinary"></param>
/// <param name="lines"></param>
/// <param name="filePath"></param>
public FileContentInfo(bool isBinary, IList<string> lines, string filePath)
: this(isBinary, lines)
{
FilePath = filePath;
}

/// <summary>Class constructor</summary>
/// <param name="isBinary"></param>
/// <param name="lines"></param>
public FileContentInfo(bool isBinary, IList<string> lines)
: this()
{
TextContent = null;
Lines = lines;
}
/// <summary>Class constructor</summary>
/// <param name="filePath"></param>
public FileContentInfo(string filePath)
: this()
{
// Just use a different constructor if a valid path was not required.
if (string.IsNullOrEmpty(filePath))
throw new NotSupportedException("This constructor should not be used without valid path.");

FilePath = filePath;
}

/// <summary>Class constructor</summary>
public FileContentInfo()
{
IsBinary = false;
TextEncoding = Encoding.Default;
TextContent = string.Empty;
Lines = new List<string>();
}
#endregion constructors

#region properties
/// <summary>Gets the detected encoding of the text file content</summary>
public Encoding TextEncoding { get; set; }

/// <summary>Gets the text file content</summary>
public string TextContent { get; set; }

public IList<string> Lines { get; set; }

/// <summary>Gets the full path to file A</summary>
public string FilePath { get; }

/// <summary>Get whether the content should be treated as binary or not.</summary>
public bool IsBinary { get; }

/// <summary>Gets/sets whether the currently shown text in the textedior has been changed
/// without saving or not.</summary>
public bool IsDirty { get; set; }
#endregion properties
}
}
64 changes: 0 additions & 64 deletions source/AehnlichLib/Files/FileEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,6 @@
using System.Text;
using System.Threading.Tasks;

public class FileContentInfo
{
#region constructors
/// <summary>Class constructor</summary>
/// <param name="isBinary"></param>
/// <param name="lines"></param>
/// <param name="filePath"></param>
public FileContentInfo(bool isBinary, IList<string> lines, string filePath)
: this(isBinary, lines)
{
FilePath = filePath;
}

/// <summary>Class constructor</summary>
/// <param name="isBinary"></param>
/// <param name="lines"></param>
public FileContentInfo(bool isBinary, IList<string> lines)
: this()
{
TextContent = null;
Lines = lines;
}
/// <summary>Class constructor</summary>
/// <param name="filePath"></param>
public FileContentInfo(string filePath)
: this()
{
// Just use a different constructor if a valid path was not required.
if (string.IsNullOrEmpty(filePath))
throw new NotSupportedException("This constructor should not be used without valid path.");

FilePath = filePath;
}

/// <summary>Class constructor</summary>
public FileContentInfo()
{
IsBinary = false;
TextEncoding = Encoding.Default;
TextContent = string.Empty;
Lines = new List<string>();
}
#endregion constructors

#region properties
/// <summary>Gets the detected encoding of the text file content</summary>
public Encoding TextEncoding { get; set; }

/// <summary>Gets the text file content</summary>
public string TextContent { get; set; }

public IList<string> Lines { get; set; }

/// <summary>Gets the full path to file A</summary>
public string FilePath { get; }

/// <summary>Gets the full path to file B</summary>
public string FilePathB { get; }

/// <summary>Get whether the content should be treated as binary or not.</summary>
public bool IsBinary { get; }
#endregion properties
}

/// <summary>
/// File Utility Class
/// https://stackoverflow.com/questions/13167934/how-to-async-files-readalllines-and-await-for-results
Expand Down
9 changes: 9 additions & 0 deletions source/AehnlichLib/Text/ProcessTextDiff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ protected ProcessTextDiff()

/// <summary>Gets the original text encoding for the left side of the comparison.</summary>
public Encoding TextEncodingA { get; private set; }

/// <summary>Gets/sets whether Text A has been changed without saving to disk or not.</summary>
public bool TextIsDirtyA { get; private set; }

public string TextOriginalB { get; private set; }

/// <summary>Gets a list of lines (text or binary rendered as text) for the right side of the comparison.</summary>
Expand All @@ -67,6 +71,9 @@ protected ProcessTextDiff()
/// <summary>Gets the original text encoding for the right side of the comparison.</summary>
public Encoding TextEncodingB { get; private set; }

/// <summary>Gets/sets whether Text B has been changed without saving to disk or not.</summary>
public bool TextIsDirtyB { get; private set; }

/// <summary>Gets whether the returned data was interpreted as binary, text, or XML.</summary>
public CompareType IsComparedAs { get; private set; }

Expand Down Expand Up @@ -346,10 +353,12 @@ public void SetupForTextComparison(FileContentInfo fileA, FileContentInfo fileB)
this.TextOriginalA = fileA.TextContent;
this.TextContentA = fileA.TextContent;
this.TextEncodingA = fileA.TextEncoding;
this.TextIsDirtyA = fileA.IsDirty;

this.TextOriginalB = fileA.TextContent;
this.TextContentB = fileB.TextContent;
this.TextEncodingB = fileB.TextEncoding;
this.TextIsDirtyB = fileB.IsDirty;
}
#endregion TextLineConverter
#endregion methods
Expand Down
12 changes: 6 additions & 6 deletions source/Demos/Dir/AehnlichDirDemo/App.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Application
x:Class="AehnlichDirDemo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:AehnlichDirDemo"
StartupUri="MainWindow.xaml">
<Application.Resources />
x:Class="AehnlichDirDemo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:AehnlichDirDemo"
StartupUri="MainWindow.xaml">
<Application.Resources />
</Application>
12 changes: 6 additions & 6 deletions source/Demos/TextFileDemo/AehnlichFileDemo/App.xaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Application
x:Class="AehnlichDemo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:AehnlichDemo"
StartupUri="MainWindow.xaml">
<!--Application.Resources>
x:Class="AehnlichDemo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:AehnlichDemo"
StartupUri="MainWindow.xaml">
<!--Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/AehnlichViewLib;component/Themes/Generic.xaml"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using HL.Interfaces;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -909,6 +908,7 @@ private FileContentInfo GetTextResult(IDiffSideTextViewModel currentDocumentView
{
var result = new FileContentInfo(filePath);
result.TextEncoding = currentDocumentView.TextEncoding;
result.IsDirty = currentDocumentView.IsDirty;

switch (currentDocumentView.ViewMode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using HL.Interfaces;
using ICSharpCode.AvalonEdit;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows.Input;
Expand Down Expand Up @@ -919,10 +918,10 @@ private void SetData(TextBinaryDiffArgs args,
factory.SetData(r.ListA, r.ListB, r.Script);

_ViewA.SetData(args.A, factory.LinesA, factory.TextA
, r.TextEncodingA, r.TextOriginalA, args.SpacesPerTab);
, r.TextEncodingA, r.TextOriginalA, r.TextIsDirtyA, args.SpacesPerTab);

_ViewB.SetData(args.B, factory.LinesB, factory.TextB
, r.TextEncodingB, r.TextOriginalB, args.SpacesPerTab);
, r.TextEncodingB, r.TextOriginalB, r.TextIsDirtyB, args.SpacesPerTab);

NotifyPropertyChanged(() => this.IsDiffDataAvailable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,16 @@ public DiffSideViewModel()
CurrentViewMode = DisplayMode.Comparing;
_DocumentViews = new ObservableCollection<DiffSideTextViewModel>();

SetDocumentViews(string.Empty, string.Empty, Encoding.Default, string.Empty);
SetDocumentViews(string.Empty, string.Empty, Encoding.Default, string.Empty, false);
}
#endregion ctors

#region Events
/// <summary>
/// Event is raised when the cursor position in the attached view is changed.
/// </summary>
/// <summary>Event is raised when the cursor position in the attached view has changed.</summary>
public event EventHandler<CaretPositionChangedEvent> CaretPositionChanged;

/// <summary>
/// Event is raised when newly requested line diff edit script segments
/// have been computed and are available for hightlighting.
///
/// <seealso cref="ILineDiffProvider"/>
/// </summary>
/// <summary>Event is raised when newly requested line diff edit script segments
/// have been computed and are available for hightlighting. <seealso cref="ILineDiffProvider"/></summary>
public event EventHandler<DiffLineInfoChangedEvent> DiffLineInfoChanged;
#endregion Events

Expand Down Expand Up @@ -709,9 +703,11 @@ internal void SwitchHighlightingDefinitionOff()
/// <param name="spacesPerTab"></param>
/// <param name="originalTextEncoding">The encoding of the original text</param>
/// <param name="originalTextContent">The original text as it was available in the file</param>
/// <param name="isDirty">Wether text represents changed unsaved content or not.</param>
internal void SetData(string filename
, IDiffLines lines, string text
, Encoding originalTextEncoding, string originalTextContent
, bool isDirty
, int spacesPerTab)
{
try
Expand Down Expand Up @@ -755,7 +751,7 @@ internal void SetData(string filename
_DocLineDiffs.Clear();
}

SetDocumentViews(text, filename, originalTextEncoding, originalTextContent);
SetDocumentViews(text, filename, originalTextEncoding, originalTextContent, isDirty);
}

/// <summary>
Expand Down Expand Up @@ -797,7 +793,7 @@ internal void SetData(IDiffLineViewModel lineOneVM,
_DocLineDiffs.AddRange(documentLineDiffs, NotifyCollectionChangedAction.Reset);

// Update text document
SetDocumentViews(text, string.Empty, Encoding.Default, string.Empty);
SetDocumentViews(text, string.Empty, Encoding.Default, string.Empty, false);

NotifyPropertyChanged(() => DocLineDiffs);
}
Expand Down Expand Up @@ -999,20 +995,22 @@ protected virtual void Dispose(bool disposing)
#endregion IDisposable

private void SetDocumentViews(string text, string fileName
, Encoding originalTextEncoding, string originalText)
, Encoding originalTextEncoding, string originalText, bool isDirty)
{
CurrentViewMode = DisplayMode.Comparing;

// Initialize collection of different document views
var newDocument = new DiffSideTextViewModel(DisplayMode.Comparing, text, originalTextEncoding, originalText)
{
FileName = fileName
FileName = fileName,
IsDirty = isDirty
};

// Initialize collection of different document views
var newDocumentEditor = new DiffSideTextViewModel(DisplayMode.Editing, originalText, originalTextEncoding, originalText)
{
FileName = fileName
FileName = fileName,
IsDirty = isDirty
};

_DocumentViews.Clear();
Expand Down
Loading

0 comments on commit b106e42

Please sign in to comment.