make the tests compile

HACK adding StubViewPort to revision control (bug in AutoImplement keeps it from generating cleanly)
This commit is contained in:
Benjamin Popp
2018-11-16 21:30:33 -06:00
parent ed402fbdb9
commit 77c9d926cd
9 changed files with 481 additions and 32 deletions

View File

@@ -60,10 +60,12 @@
<Compile Include="Model\IFileSystem.cs" />
<Compile Include="Model\LoadedFile.cs" />
<Compile Include="Model\Point.cs" />
<Compile Include="ViewModel\CompositeViewPort.cs" />
<Compile Include="ViewModel\DataFormats.cs" />
<Compile Include="ViewModel\EditorViewModel.cs" />
<Compile Include="ViewModel\HexElement.cs" />
<Compile Include="ViewModel\ITabContent.cs" />
<Compile Include="ViewModel\IViewPort.cs" />
<Compile Include="ViewModel\ScrollRegion.cs" />
<Compile Include="ViewModel\Selection.cs" />
<Compile Include="ViewModel\ViewModelCore.cs" />

View File

@@ -17,8 +17,8 @@ namespace HavenSoft.Gen3Hex.View {
#region ViewPort
public ViewPort ViewPort {
get { return (ViewPort)GetValue(ViewPortProperty); }
public IViewPort ViewPort {
get { return (IViewPort)GetValue(ViewPortProperty); }
set { SetValue(ViewPortProperty, value); }
}
@@ -50,8 +50,8 @@ namespace HavenSoft.Gen3Hex.View {
private void OnViewPortPropertyChanged(object sender, PropertyChangedEventArgs e) {
var propertyChangesThatRequireRedraw = new[] {
nameof(ViewPort.SelectionStart),
nameof(ViewPort.SelectionEnd),
nameof(ViewModel.ViewPort.SelectionStart),
nameof(ViewModel.ViewPort.SelectionEnd),
};
if (propertyChangesThatRequireRedraw.Contains(e.PropertyName)) {
@@ -74,23 +74,23 @@ namespace HavenSoft.Gen3Hex.View {
InputBindings.Add(keyBinding);
}
AddKeyCommand(nameof(ViewPort.MoveSelectionStart), Direction.Up, Key.Up);
AddKeyCommand(nameof(ViewPort.MoveSelectionStart), Direction.Down, Key.Down);
AddKeyCommand(nameof(ViewPort.MoveSelectionStart), Direction.Left, Key.Left);
AddKeyCommand(nameof(ViewPort.MoveSelectionStart), Direction.Right, Key.Right);
AddKeyCommand(nameof(ViewModel.ViewPort.MoveSelectionStart), Direction.Up, Key.Up);
AddKeyCommand(nameof(ViewModel.ViewPort.MoveSelectionStart), Direction.Down, Key.Down);
AddKeyCommand(nameof(ViewModel.ViewPort.MoveSelectionStart), Direction.Left, Key.Left);
AddKeyCommand(nameof(ViewModel.ViewPort.MoveSelectionStart), Direction.Right, Key.Right);
AddKeyCommand(nameof(ViewPort.MoveSelectionEnd), Direction.Up, Key.Up, ModifierKeys.Shift);
AddKeyCommand(nameof(ViewPort.MoveSelectionEnd), Direction.Down, Key.Down, ModifierKeys.Shift);
AddKeyCommand(nameof(ViewPort.MoveSelectionEnd), Direction.Left, Key.Left, ModifierKeys.Shift);
AddKeyCommand(nameof(ViewPort.MoveSelectionEnd), Direction.Right, Key.Right, ModifierKeys.Shift);
AddKeyCommand(nameof(ViewModel.ViewPort.MoveSelectionEnd), Direction.Up, Key.Up, ModifierKeys.Shift);
AddKeyCommand(nameof(ViewModel.ViewPort.MoveSelectionEnd), Direction.Down, Key.Down, ModifierKeys.Shift);
AddKeyCommand(nameof(ViewModel.ViewPort.MoveSelectionEnd), Direction.Left, Key.Left, ModifierKeys.Shift);
AddKeyCommand(nameof(ViewModel.ViewPort.MoveSelectionEnd), Direction.Right, Key.Right, ModifierKeys.Shift);
AddKeyCommand(nameof(ViewPort.Scroll), Direction.Up, Key.Up, ModifierKeys.Control);
AddKeyCommand(nameof(ViewPort.Scroll), Direction.Down, Key.Down, ModifierKeys.Control);
AddKeyCommand(nameof(ViewPort.Scroll), Direction.Left, Key.Left, ModifierKeys.Control);
AddKeyCommand(nameof(ViewPort.Scroll), Direction.Right, Key.Right, ModifierKeys.Control);
AddKeyCommand(nameof(IViewPort.Scroll), Direction.Up, Key.Up, ModifierKeys.Control);
AddKeyCommand(nameof(IViewPort.Scroll), Direction.Down, Key.Down, ModifierKeys.Control);
AddKeyCommand(nameof(IViewPort.Scroll), Direction.Left, Key.Left, ModifierKeys.Control);
AddKeyCommand(nameof(IViewPort.Scroll), Direction.Right, Key.Right, ModifierKeys.Control);
AddKeyCommand(nameof(ViewPort.Undo), null, Key.Z, ModifierKeys.Control);
AddKeyCommand(nameof(ViewPort.Redo), null, Key.Y, ModifierKeys.Control);
AddKeyCommand(nameof(IViewPort.Undo), null, Key.Z, ModifierKeys.Control);
AddKeyCommand(nameof(IViewPort.Redo), null, Key.Y, ModifierKeys.Control);
}
protected override void OnMouseDown(MouseButtonEventArgs e) {
@@ -99,15 +99,17 @@ namespace HavenSoft.Gen3Hex.View {
if (e.ChangedButton != MouseButton.Left) return;
Focus();
ViewPort.SelectionStart = ControlCoordinatesToModelCoordinates(e);
CaptureMouse();
if (ViewPort is ViewPort editableViewPort) {
editableViewPort.SelectionStart = ControlCoordinatesToModelCoordinates(e);
CaptureMouse();
}
}
protected override void OnMouseMove(MouseEventArgs e) {
base.OnMouseMove(e);
if (!IsMouseCaptured) return;
ViewPort.SelectionEnd = ControlCoordinatesToModelCoordinates(e);
((ViewPort)ViewPort).SelectionEnd = ControlCoordinatesToModelCoordinates(e);
}
protected override void OnMouseUp(MouseButtonEventArgs e) {
@@ -118,7 +120,9 @@ namespace HavenSoft.Gen3Hex.View {
protected override void OnMouseWheel(MouseWheelEventArgs e) {
base.OnMouseWheel(e);
ViewPort.ScrollValue -= Math.Sign(e.Delta);
if (ViewPort is ViewPort editableViewPort) {
editableViewPort.ScrollValue -= Math.Sign(e.Delta);
}
}
protected override void OnRender(DrawingContext drawingContext) {
@@ -147,8 +151,10 @@ namespace HavenSoft.Gen3Hex.View {
}
protected override void OnTextInput(TextCompositionEventArgs e) {
ViewPort.Edit(e.Text);
e.Handled = true;
if (ViewPort is ViewPort editableViewPort) {
editableViewPort.Edit(e.Text);
e.Handled = true;
}
}
private void UpdateViewPortSize() {

View File

@@ -0,0 +1,63 @@
using HavenSoft.Gen3Hex.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Windows.Input;
namespace HavenSoft.Gen3Hex.ViewModel {
public class CompositeViewPort : ViewModelCore, IViewPort {
public HexElement this[int x, int y] => throw new NotImplementedException();
public int Width { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public int Height { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public int MinimumScroll => throw new NotImplementedException();
public int ScrollValue => throw new NotImplementedException();
public int MaximumScroll => throw new NotImplementedException();
public ObservableCollection<string> Headers => throw new NotImplementedException();
public ICommand Scroll => throw new NotImplementedException();
public string Name => throw new NotImplementedException();
public ICommand Save => throw new NotImplementedException();
public ICommand SaveAs => throw new NotImplementedException();
public ICommand Undo => throw new NotImplementedException();
public ICommand Redo => throw new NotImplementedException();
public ICommand Copy => throw new NotImplementedException();
public ICommand Clear => throw new NotImplementedException();
public ICommand Goto => throw new NotImplementedException();
public ICommand Back => throw new NotImplementedException();
public ICommand Forward => throw new NotImplementedException();
public ICommand Close => throw new NotImplementedException();
public event EventHandler<string> OnError;
public event EventHandler Closed;
public event NotifyCollectionChangedEventHandler CollectionChanged;
public IViewPort CreateChildView(int offset) {
throw new NotImplementedException();
}
public IReadOnlyList<int> Find(string search) {
throw new NotImplementedException();
}
public bool IsSelected(Point point) {
throw new NotImplementedException();
}
}
}

View File

@@ -11,9 +11,14 @@ namespace HavenSoft.Gen3Hex.ViewModel {
private readonly IFileSystem fileSystem;
private readonly List<ITabContent> tabs;
private readonly StubCommand newCommand, open, save, saveAs, saveAll, close, closeAll, undo, redo, cut, copy, paste, delete, back, forward, gotoCommand, showGoto, clearError;
private readonly StubCommand newCommand, open, save, saveAs, saveAll, close, closeAll;
private readonly StubCommand undo, redo, cut, copy, paste, delete;
private readonly StubCommand back, forward, gotoCommand, showGoto, find, findPrevious, findNext, showFind, clearError;
private readonly Dictionary<Func<ITabContent, ICommand>, EventHandler> forwardExecuteChangeNotifications;
private (IViewPort tab, int)[] recentFindResults;
private int currentFindResultIndex;
public ICommand New => newCommand;
public ICommand Open => open;
public ICommand Save => save;
@@ -31,6 +36,10 @@ namespace HavenSoft.Gen3Hex.ViewModel {
public ICommand Forward => forward;
public ICommand Goto => gotoCommand;
public ICommand ShowGoto => showGoto;
public ICommand Find => find;
public ICommand FindPrevious => findPrevious;
public ICommand FindNext => findNext;
public ICommand ShowFind => showFind;
public ICommand ClearError => clearError;
private bool gotoControlVisible;
@@ -38,7 +47,22 @@ namespace HavenSoft.Gen3Hex.ViewModel {
get => gotoControlVisible;
private set {
TryUpdate(ref gotoControlVisible, value);
if (value) ClearError.Execute();
if (value) {
ClearError.Execute();
FindControlVisible = false;
}
}
}
private bool findControlVisible;
public bool FindControlVisible {
get => findControlVisible;
private set {
TryUpdate(ref findControlVisible, value);
if (value) {
ClearError.Execute();
GotoControlVisible = false;
}
}
}
@@ -110,6 +134,34 @@ namespace HavenSoft.Gen3Hex.ViewModel {
CanExecute = CanAlwaysExecute,
Execute = arg => GotoControlVisible = (bool)arg,
};
find = new StubCommand {
CanExecute = CanAlwaysExecute,
Execute = arg => FindExecuted((string)arg),
};
findPrevious = new StubCommand {
CanExecute = arg => recentFindResults?.Length != 0,
Execute = arg => {
currentFindResultIndex--;
if (currentFindResultIndex < 0) currentFindResultIndex += recentFindResults.Length;
var (tab, offset) = recentFindResults[currentFindResultIndex];
SelectedIndex = tabs.IndexOf(tab);
tab.Goto.Execute(offset.ToString("X2"));
},
};
findNext = new StubCommand {
CanExecute = arg => recentFindResults?.Length != 0,
Execute = arg => {
currentFindResultIndex++;
if (currentFindResultIndex >= recentFindResults.Length) currentFindResultIndex -= recentFindResults.Length;
var (tab, offset) = recentFindResults[currentFindResultIndex];
SelectedIndex = tabs.IndexOf(tab);
tab.Goto.Execute(offset.ToString("X2"));
},
};
showFind = new StubCommand {
CanExecute = CanAlwaysExecute,
Execute = arg => FindControlVisible = (bool)arg,
};
clearError = new StubCommand {
CanExecute = arg => showError,
Execute = arg => ErrorMessage = string.Empty,
@@ -209,6 +261,10 @@ namespace HavenSoft.Gen3Hex.ViewModel {
return command;
}
private void FindExecuted(string search) {
}
private void RemoveTab(object sender, EventArgs e) {
var tab = (ITabContent)sender;
if (!tabs.Contains(tab)) throw new InvalidOperationException("Cannot remove tab, because tab is not currently in editor.");

View File

@@ -0,0 +1,25 @@
using HavenSoft.Gen3Hex.Model;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Windows.Input;
namespace HavenSoft.Gen3Hex.ViewModel {
public interface IViewPort : ITabContent, INotifyCollectionChanged, INotifyPropertyChanged {
int Width { get; set; }
int Height { get; set; }
int MinimumScroll { get; }
int ScrollValue { get; }
int MaximumScroll { get; }
ObservableCollection<string> Headers { get; }
ICommand Scroll { get; }
HexElement this[int x, int y] { get; }
bool IsSelected(Point point);
IReadOnlyList<int> Find(string search);
IViewPort CreateChildView(int offset);
}
}

View File

@@ -12,10 +12,11 @@ using System.Text;
using System.Windows.Input;
namespace HavenSoft.Gen3Hex.ViewModel {
/// <summary>
/// A range of visible data that should be displayed.
/// </summary>
public class ViewPort : ViewModelCore, ITabContent, INotifyCollectionChanged {
public class ViewPort : ViewModelCore, IViewPort {
private static readonly NotifyCollectionChangedEventArgs ResetArgs = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
private readonly StubCommand
clear = new StubCommand(),
@@ -262,6 +263,15 @@ namespace HavenSoft.Gen3Hex.ViewModel {
for (int i = 0; i < input.Length; i++) Edit(input[i]);
}
public IReadOnlyList<int> Find(string search) {
// TODO
return new int[0];
}
public IViewPort CreateChildView(int offset) {
return null;
}
private void Edit(char input) {
var point = GetEditPoint();
var element = currentView[point.X, point.Y];

View File

@@ -36,7 +36,7 @@ namespace HavenSoft.HexTests {
[Fact]
public void EditorShowsErrorIfNoneFound() {
var tab = new StubTabContent();
var tab = new StubViewPort();
var editor = new EditorViewModel(new StubFileSystem()) { tab };
tab.Find = str => new int[0];
@@ -48,7 +48,7 @@ namespace HavenSoft.HexTests {
[Fact]
public void EditorJumpsToResultIfSingleResult() {
var tab = new StubTabContent();
var tab = new StubViewPort();
var editor = new EditorViewModel(new StubFileSystem()) { tab };
string gotoArg = string.Empty;
@@ -62,7 +62,7 @@ namespace HavenSoft.HexTests {
[Fact]
public void EditorOpensHelperTabIfMultipleResult() {
var tab = new StubTabContent();
var tab = new StubViewPort();
var editor = new EditorViewModel(new StubFileSystem()) { tab };
var count = 0;
@@ -82,7 +82,7 @@ namespace HavenSoft.HexTests {
[Fact]
public void EditorHasShortcutsToGetPreviousOrNextFindResult() {
var tab = new StubTabContent();
var tab = new StubViewPort();
var editor = new EditorViewModel(new StubFileSystem()) { tab };
int gotoCount = 0;

View File

@@ -64,6 +64,7 @@
<Compile Include="GeneralAppTests.cs" />
<Compile Include="generatedCode\StubFileSystem.cs" />
<Compile Include="generatedCode\StubTabContent.cs" />
<Compile Include="generatedCode\StubViewPort.cs" />
<Compile Include="NavigationTests.cs" />
<Compile Include="ViewPortCursorTests.cs" />
<Compile Include="ViewPortEditTests.cs" />
@@ -105,7 +106,7 @@
<PropertyGroup>
<PreBuildEvent>if not exist $(ProjectDir)generatedCode mkdir $(ProjectDir)generatedCode
$(SolutionDir)packages\HavenSoft.AutoImplement.1.0.1\AutoImplement $(SolutionDir)Gen3Hex\$(OutDir)Gen3Hex.exe ITabContent IFileSystem
$(SolutionDir)packages\HavenSoft.AutoImplement.1.0.1\AutoImplement $(SolutionDir)Gen3Hex\$(OutDir)Gen3Hex.exe ITabContent IFileSystem IViewPort
move /Y StubTabContent.cs $(ProjectDir)generatedCode
move /Y StubFileSystem.cs $(ProjectDir)generatedCode

View File

@@ -0,0 +1,286 @@
// this file was created by AutoImplement
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Delegation;
namespace HavenSoft.Gen3Hex.ViewModel
{
public class StubViewPort : IViewPort
{
public Func<HavenSoft.Gen3Hex.Model.Point, bool> IsSelected { get; set; }
bool IViewPort.IsSelected(HavenSoft.Gen3Hex.Model.Point point)
{
if (this.IsSelected != null)
{
return this.IsSelected(point);
}
else
{
return default(bool);
}
}
public Func<string, System.Collections.Generic.IReadOnlyList<int>> Find { get; set; }
System.Collections.Generic.IReadOnlyList<int> IViewPort.Find(string search)
{
if (this.Find != null)
{
return this.Find(search);
}
else
{
return default(System.Collections.Generic.IReadOnlyList<int>);
}
}
public Func<int, IViewPort> CreateChildView { get; set; }
IViewPort IViewPort.CreateChildView(int offset)
{
if (this.CreateChildView != null)
{
return this.CreateChildView(offset);
}
else
{
return default(IViewPort);
}
}
public PropertyImplementation<int> Width = new PropertyImplementation<int>();
int IViewPort.Width
{
get
{
return this.Width.get();
}
set
{
this.Width.set(value);
}
}
public PropertyImplementation<int> Height = new PropertyImplementation<int>();
int IViewPort.Height
{
get
{
return this.Height.get();
}
set
{
this.Height.set(value);
}
}
public PropertyImplementation<int> MinimumScroll = new PropertyImplementation<int>();
int IViewPort.MinimumScroll
{
get
{
return this.MinimumScroll.get();
}
}
public PropertyImplementation<int> ScrollValue = new PropertyImplementation<int>();
int IViewPort.ScrollValue
{
get
{
return this.ScrollValue.get();
}
}
public PropertyImplementation<int> MaximumScroll = new PropertyImplementation<int>();
int IViewPort.MaximumScroll
{
get
{
return this.MaximumScroll.get();
}
}
public PropertyImplementation<System.Collections.ObjectModel.ObservableCollection<string>> Headers = new PropertyImplementation<System.Collections.ObjectModel.ObservableCollection<string>>();
System.Collections.ObjectModel.ObservableCollection<string> IViewPort.Headers
{
get
{
return this.Headers.get();
}
}
public PropertyImplementation<System.Windows.Input.ICommand> Scroll = new PropertyImplementation<System.Windows.Input.ICommand>();
System.Windows.Input.ICommand IViewPort.Scroll
{
get
{
return this.Scroll.get();
}
}
public Func<int, int, HexElement> get_Item = (x, y) => default(HexElement);
HexElement IViewPort.this[int x, int y]
{
get
{
return get_Item(x, y);
}
}
public PropertyImplementation<string> Name = new PropertyImplementation<string>();
string ITabContent.Name
{
get
{
return this.Name.get();
}
}
public PropertyImplementation<System.Windows.Input.ICommand> Save = new PropertyImplementation<System.Windows.Input.ICommand>();
System.Windows.Input.ICommand ITabContent.Save
{
get
{
return this.Save.get();
}
}
public PropertyImplementation<System.Windows.Input.ICommand> SaveAs = new PropertyImplementation<System.Windows.Input.ICommand>();
System.Windows.Input.ICommand ITabContent.SaveAs
{
get
{
return this.SaveAs.get();
}
}
public PropertyImplementation<System.Windows.Input.ICommand> Undo = new PropertyImplementation<System.Windows.Input.ICommand>();
System.Windows.Input.ICommand ITabContent.Undo
{
get
{
return this.Undo.get();
}
}
public PropertyImplementation<System.Windows.Input.ICommand> Redo = new PropertyImplementation<System.Windows.Input.ICommand>();
System.Windows.Input.ICommand ITabContent.Redo
{
get
{
return this.Redo.get();
}
}
public PropertyImplementation<System.Windows.Input.ICommand> Copy = new PropertyImplementation<System.Windows.Input.ICommand>();
System.Windows.Input.ICommand ITabContent.Copy
{
get
{
return this.Copy.get();
}
}
public PropertyImplementation<System.Windows.Input.ICommand> Clear = new PropertyImplementation<System.Windows.Input.ICommand>();
System.Windows.Input.ICommand ITabContent.Clear
{
get
{
return this.Clear.get();
}
}
public PropertyImplementation<System.Windows.Input.ICommand> Goto = new PropertyImplementation<System.Windows.Input.ICommand>();
System.Windows.Input.ICommand ITabContent.Goto
{
get
{
return this.Goto.get();
}
}
public PropertyImplementation<System.Windows.Input.ICommand> Back = new PropertyImplementation<System.Windows.Input.ICommand>();
System.Windows.Input.ICommand ITabContent.Back
{
get
{
return this.Back.get();
}
}
public PropertyImplementation<System.Windows.Input.ICommand> Forward = new PropertyImplementation<System.Windows.Input.ICommand>();
System.Windows.Input.ICommand ITabContent.Forward
{
get
{
return this.Forward.get();
}
}
public PropertyImplementation<System.Windows.Input.ICommand> Close = new PropertyImplementation<System.Windows.Input.ICommand>();
System.Windows.Input.ICommand ITabContent.Close
{
get
{
return this.Close.get();
}
}
public EventImplementation<string> OnError = new EventImplementation<string>();
event System.EventHandler<string> ITabContent.OnError
{
add
{
OnError.add(new EventHandler<string>(value));
}
remove
{
OnError.remove(new EventHandler<string>(value));
}
}
public EventImplementation<System.EventArgs> Closed = new EventImplementation<System.EventArgs>();
event System.EventHandler ITabContent.Closed
{
add
{
Closed.add(new EventHandler<System.EventArgs>(value));
}
remove
{
Closed.remove(new EventHandler<System.EventArgs>(value));
}
}
public EventImplementation<NotifyCollectionChangedEventArgs> CollectionChanged = new EventImplementation<NotifyCollectionChangedEventArgs>();
event NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged
{
add
{
CollectionChanged.add(new EventHandler<NotifyCollectionChangedEventArgs>(value));
}
remove
{
CollectionChanged.remove(new EventHandler<NotifyCollectionChangedEventArgs>(value));
}
}
public EventImplementation<PropertyChangedEventArgs> PropertyChanged = new EventImplementation<PropertyChangedEventArgs>();
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
{
add
{
PropertyChanged.add(new EventHandler<PropertyChangedEventArgs>(value));
}
remove
{
PropertyChanged.remove(new EventHandler<PropertyChangedEventArgs>(value));
}
}
}
}