21 changed files with 471 additions and 57 deletions
@ -0,0 +1,103 @@ |
|||
using Perspex.Threading; |
|||
|
|||
namespace XamlTestApplication.ViewModels |
|||
{ |
|||
using ReactiveUI; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Collections.ObjectModel; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
public class ShellViewModel : ReactiveObject |
|||
{ |
|||
private ShellViewModel() |
|||
{ |
|||
documents = new ObservableCollection<EditorViewModel>(); |
|||
|
|||
AddDocumentCommand = ReactiveCommand.Create(); |
|||
AddDocumentCommand.Subscribe(_ => |
|||
{ |
|||
Documents.Add(new EditorViewModel()); |
|||
}); |
|||
|
|||
GCCommand = ReactiveCommand.Create(); |
|||
GCCommand.Subscribe(_ => |
|||
{ |
|||
GC.Collect(); |
|||
}); |
|||
} |
|||
|
|||
public static ShellViewModel Instance = new ShellViewModel(); |
|||
|
|||
private ObservableCollection<EditorViewModel> documents; |
|||
public ObservableCollection<EditorViewModel> Documents |
|||
{ |
|||
get { return documents; } |
|||
set { this.RaiseAndSetIfChanged(ref documents, value); } |
|||
} |
|||
|
|||
private EditorViewModel selectedDocument; |
|||
|
|||
public EditorViewModel SelectedDocument |
|||
{ |
|||
get { return selectedDocument; } |
|||
set { this.RaiseAndSetIfChanged(ref selectedDocument, value); } |
|||
} |
|||
|
|||
private int instanceCount; |
|||
|
|||
public int InstanceCount |
|||
{ |
|||
get { return instanceCount; } |
|||
set { this.RaiseAndSetIfChanged(ref instanceCount, value); } |
|||
} |
|||
|
|||
|
|||
|
|||
public ReactiveCommand<object> AddDocumentCommand { get; } |
|||
public ReactiveCommand<object> GCCommand { get; } |
|||
} |
|||
|
|||
public class EditorViewModel : ReactiveObject |
|||
{ |
|||
private static int InstanceCount = 0; |
|||
|
|||
public EditorViewModel() |
|||
{ |
|||
InstanceCount++; |
|||
ShellViewModel.Instance.InstanceCount = InstanceCount; |
|||
text = "This is some text."; |
|||
|
|||
CloseCommand = ReactiveCommand.Create(); |
|||
|
|||
CloseCommand.Subscribe(_ => |
|||
{ |
|||
ShellViewModel.Instance.Documents.Remove(this); |
|||
}); |
|||
} |
|||
|
|||
~EditorViewModel() |
|||
{ |
|||
|
|||
|
|||
//System.Console.WriteLine("EVM Destructed");
|
|||
InstanceCount--; |
|||
Dispatcher.UIThread.InvokeAsync(() => |
|||
{ |
|||
ShellViewModel.Instance.InstanceCount = InstanceCount; |
|||
}); |
|||
|
|||
} |
|||
|
|||
private string text; |
|||
public string Text |
|||
{ |
|||
get { return text; } |
|||
set { this.RaiseAndSetIfChanged(ref text, value); } |
|||
} |
|||
|
|||
public ReactiveCommand<object> CloseCommand { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using Perspex.Controls; |
|||
using Perspex.UnitTests; |
|||
using Xunit; |
|||
|
|||
namespace Perspex.Input.UnitTests |
|||
{ |
|||
public class InputElement_Focus |
|||
{ |
|||
[Fact] |
|||
public void Focus_Should_Set_FocusManager_Current() |
|||
{ |
|||
Button target; |
|||
|
|||
using (UnitTestApplication.Start(TestServices.RealFocus)) |
|||
{ |
|||
var root = new TestRoot |
|||
{ |
|||
Child = target = new Button() |
|||
}; |
|||
|
|||
target.Focus(); |
|||
|
|||
Assert.Same(target, FocusManager.Instance.Current); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void Focus_Should_Be_Cleared_When_Control_Is_Removed_From_VisualTree() |
|||
{ |
|||
Button target; |
|||
|
|||
using (UnitTestApplication.Start(TestServices.RealFocus)) |
|||
{ |
|||
var root = new TestRoot |
|||
{ |
|||
Child = target = new Button() |
|||
}; |
|||
|
|||
target.Focus(); |
|||
root.Child = null; |
|||
|
|||
Assert.Null(FocusManager.Instance.Current); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue