* Added new command wrapper, abstracts static and dynamic commands - All uses of the `Command` are replaced with either `AppCommand`, for a command that is static to the scope of the application, or a reference to an ICommand (specifically, an `EnumCommand<AppCommand>()` instance), which provides the abstract wrapper. - Functionality seems intact. - Next step is to have the MainViewModel add the per-shell commands via SettingsService.CreateShellKeyboardShortcuts(), and have the SettingsService.ParseCommandString() function parse the command strings passed around properly. - Finally, add the keyboard chord input to each shell's settings page. * First kick at adding a new terminal keyboard command. - It isn't presented anywhere, but references to keybindings should be using the ICommand key as their identifier for recognizing anything, and when xterm passes back a keyboard command event, the SettingsService is asked to convert the string into an ICommand. * Renaming ICommand to Command. It's not longer an interface, so this makes more sense. * Renaming back to Command, and new class is AbstractCommand. Going to simplify the PR diff considerably. * Shortcuts for default shells work. Need to get the shell profile edit UI elements working. * Added keyboard shortcut UI elements to shell profile pages. * New and deleted shell profiles propagate to all terminal views. * A bit of cleanup. * Camel-casing command text to fix Ctrl+C and copy behaviour. * Fixed failing test. The new on disk store uses a .ToString(), not the Enum description, since the command isn't an Enum, it's a class now in general, and those semantics make more sense. * Adding default value for null keybindings in shell profiles. * Merge branch 'shell_commands' of https://github.com/Riebart/FluentTerminal into pr/85 Improved default value for keybinding property * Renamed KeyBinding collection to KeyBindings * Use strings as Command parameter of KeyBinding * Added missing Commands to keyBindings of default shellProfiles * fix build and unit tests after merge with master * improve UI * Split OnShellProfileCollectionChanged event
129 lines
3.2 KiB
C#
129 lines
3.2 KiB
C#
using FluentTerminal.App.Services;
|
|
using FluentTerminal.App.ViewModels.Infrastructure;
|
|
using FluentTerminal.Models;
|
|
using GalaSoft.MvvmLight;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace FluentTerminal.App.ViewModels.Settings
|
|
{
|
|
public class KeyBindingViewModel : ViewModelBase
|
|
{
|
|
private readonly IDialogService _dialogService;
|
|
|
|
public KeyBindingViewModel(KeyBinding keyBinding, IDialogService dialogService, KeyBindingsViewModel parent)
|
|
{
|
|
Model = keyBinding;
|
|
Parent = parent;
|
|
_dialogService = dialogService;
|
|
EditCommand = new AsyncCommand(Edit);
|
|
DeleteCommand = new AsyncCommand(Delete);
|
|
}
|
|
|
|
public event EventHandler Deleted;
|
|
|
|
public event EventHandler Edited;
|
|
|
|
public KeyBindingsViewModel Parent { get; }
|
|
|
|
public bool Meta
|
|
{
|
|
get => Model.Meta;
|
|
set
|
|
{
|
|
if (Model.Meta != value)
|
|
{
|
|
Model.Meta = value;
|
|
RaisePropertyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool Alt
|
|
{
|
|
get => Model.Alt;
|
|
set
|
|
{
|
|
if (Model.Alt != value)
|
|
{
|
|
Model.Alt = value;
|
|
RaisePropertyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool Ctrl
|
|
{
|
|
get => Model.Ctrl;
|
|
set
|
|
{
|
|
if (Model.Ctrl != value)
|
|
{
|
|
Model.Ctrl = value;
|
|
RaisePropertyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public IAsyncCommand DeleteCommand { get; }
|
|
public IAsyncCommand EditCommand { get; }
|
|
|
|
public int Key
|
|
{
|
|
get => Model.Key;
|
|
set
|
|
{
|
|
if (Model.Key != value)
|
|
{
|
|
Model.Key = value;
|
|
RaisePropertyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public KeyBinding Model { get; }
|
|
|
|
public bool Shift
|
|
{
|
|
get => Model.Shift;
|
|
set
|
|
{
|
|
if (Model.Shift != value)
|
|
{
|
|
Model.Shift = value;
|
|
RaisePropertyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public async Task<bool> Edit()
|
|
{
|
|
var keyBinding = await _dialogService.ShowCreateKeyBindingDialog().ConfigureAwait(true);
|
|
|
|
if (keyBinding != null)
|
|
{
|
|
Alt = keyBinding.Alt;
|
|
Ctrl = keyBinding.Ctrl;
|
|
Shift = keyBinding.Shift;
|
|
Meta = keyBinding.Meta;
|
|
Key = keyBinding.Key;
|
|
|
|
Edited?.Invoke(this, EventArgs.Empty);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private async Task Delete()
|
|
{
|
|
var result = await _dialogService.ShowMessageDialogAsnyc("Please confirm", "Are you sure you want to delete this keybinding?", DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true);
|
|
|
|
if (result == DialogButton.OK)
|
|
{
|
|
Deleted?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
}
|
|
} |