mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Added View.DefaultCommand etc... Started on dedicated scenario * Fixed un-shifted hotkeys -> Fixed Key Equals. Fixed WindowsDriver passing wrong key. Etc. * Fixed Key Bindings and HotKeys * Fixed Key Bindings and HotKeys * Label now correctly supports hotkey * Disabled unix hot keys because they are annoying and get in the way * Updated nuget. fixed warnings * Trying to fix ci/ci issue * Trying to fix ci/ci issue * Trying to fix ci/ci issue * Changed TextChangingEventArgs to inherit from CancelEventArgs * TextChangingEventArgs -> TextEventArgs * Simplified Text events by having only on args class * Fixed unit tests fail * Simplified by removing TitleEventArgs * POC of Title being primary for hotkey. Label and Button hacked to work * POC of Title being primary for hotkey. Label and Button hacked to work - all unit tests pass * Dropped Microsoft.NETFramework.ReferenceAssemblies * Fixed Dialogs scenario hotkeys * Fixed build warnings * Fixed Border Title render bug * Regiggering default command handling * Regiggering default command handling * Checkbox clean up * Added StateEventArgs POC * Command.Default -> Command.HotKey * Command.Default -> Command.HotKey - fixed TableView * Command.Default -> Command.HotKey - fixed TableView * Updated reactive example * Fixed Toplevel.BringOverlappedTopToFront - was reordering SubViews when it shouldn't * WIP - broke * Finished impl of StateEventArgs * Deleted ToggleEventArgs.cs. Added StateEventArgs.cs * XML doc fix * Removed old code * Removed commented out code * Label.Clicked -> Label.Accept (missed this before) * Removed Labels as Buttons scenario as it's not really useful * Moved SubView tests to own file * Moved SubView tests to own file * Simplified Text test * Added OnAccept test * Deleted DefaultCommand * Modernized CheckBox * New button test * Cleaned up RadioGroup; added tests * KeyCode->Key in ListView * Added ListView unit tests * ListView now does Accept correctly * TreeView now does Accept correctly * Cleaned up some TextField tests * TextView now handles Accept properly; updated CharMap and Adornments scenarios to test * Fixed ComboBox to deal with TextView now handles Accept properly; updated CharMap and Adornments scenarios to test * Removed un-needed using statement
90 lines
3.2 KiB
C#
90 lines
3.2 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Reactive;
|
|
using System.Reactive.Linq;
|
|
using System.Runtime.Serialization;
|
|
using System.Threading.Tasks;
|
|
using ReactiveUI;
|
|
using ReactiveUI.Fody.Helpers;
|
|
|
|
namespace ReactiveExample;
|
|
|
|
//
|
|
// This view model can be easily shared across different UI frameworks.
|
|
// For example, if you have a WPF or XF app with view models written
|
|
// this way, you can easily port your app to Terminal.Gui by implementing
|
|
// the views with Terminal.Gui classes and ReactiveUI bindings.
|
|
//
|
|
// We mark the view model with the [DataContract] attributes and this
|
|
// allows you to save the view model class to the disk, and then to read
|
|
// the view model from the disk, making your app state persistent.
|
|
// See also: https://www.reactiveui.net../docs/handbook/data-persistence/
|
|
//
|
|
[DataContract]
|
|
public class LoginViewModel : ReactiveObject
|
|
{
|
|
private readonly ObservableAsPropertyHelper<bool> _isValid;
|
|
private readonly ObservableAsPropertyHelper<int> _passwordLength;
|
|
private readonly ObservableAsPropertyHelper<int> _usernameLength;
|
|
|
|
public LoginViewModel ()
|
|
{
|
|
IObservable<bool> canLogin = this.WhenAnyValue (
|
|
x => x.Username,
|
|
x => x.Password,
|
|
(username, password) =>
|
|
!string.IsNullOrEmpty (username) && !string.IsNullOrEmpty (password)
|
|
);
|
|
|
|
_isValid = canLogin.ToProperty (this, x => x.IsValid);
|
|
|
|
Login = ReactiveCommand.CreateFromTask<CancelEventArgs> (
|
|
e => Task.Delay (TimeSpan.FromSeconds (1)),
|
|
canLogin
|
|
);
|
|
|
|
_usernameLength = this
|
|
.WhenAnyValue (x => x.Username)
|
|
.Select (name => name.Length)
|
|
.ToProperty (this, x => x.UsernameLength);
|
|
|
|
_passwordLength = this
|
|
.WhenAnyValue (x => x.Password)
|
|
.Select (password => password.Length)
|
|
.ToProperty (this, x => x.PasswordLength);
|
|
|
|
Clear = ReactiveCommand.Create<CancelEventArgs> (e => { });
|
|
|
|
Clear.Subscribe (
|
|
unit =>
|
|
{
|
|
Username = string.Empty;
|
|
Password = string.Empty;
|
|
}
|
|
);
|
|
}
|
|
|
|
[IgnoreDataMember]
|
|
public ReactiveCommand<CancelEventArgs, Unit> Clear { get; }
|
|
|
|
[IgnoreDataMember]
|
|
public bool IsValid => _isValid.Value;
|
|
|
|
[IgnoreDataMember]
|
|
public ReactiveCommand<CancelEventArgs, Unit> Login { get; }
|
|
|
|
[Reactive]
|
|
[DataMember]
|
|
public string Password { get; set; } = string.Empty;
|
|
|
|
[IgnoreDataMember]
|
|
public int PasswordLength => _passwordLength.Value;
|
|
|
|
[Reactive]
|
|
[DataMember]
|
|
public string Username { get; set; } = string.Empty;
|
|
|
|
[IgnoreDataMember]
|
|
public int UsernameLength => _usernameLength.Value;
|
|
}
|