mirror of
https://github.com/microsoft/terminal.git
synced 2026-05-19 03:10:49 +00:00
add keychord
This commit is contained in:
@@ -160,15 +160,27 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
DeleteRequested.raise(*this, *this);
|
||||
}
|
||||
|
||||
void CommandViewModel::AddKeybinding_Click()
|
||||
{
|
||||
auto kbdVM{ make_self<KeyChordViewModel>(nullptr) };
|
||||
kbdVM->IsInEditMode(true);
|
||||
_RegisterEvents(*kbdVM);
|
||||
KeyChordViewModelList().Append(*kbdVM);
|
||||
}
|
||||
|
||||
void CommandViewModel::_RegisterEvents(Editor::KeyChordViewModel kcVM)
|
||||
{
|
||||
if (const auto actionsPageVM{ _actionsPageVM.get() })
|
||||
{
|
||||
const auto id = ID();
|
||||
kcVM.AddKeyChordRequested([actionsPageVM, id](const Editor::KeyChordViewModel& /*sender*/, const Control::KeyChord& args) {
|
||||
actionsPageVM.AttemptAddKeyChord(args, id);
|
||||
});
|
||||
kcVM.ModifyKeyChordRequested([actionsPageVM](const Editor::KeyChordViewModel& sender, const Editor::ModifyKeyChordEventArgs& args) {
|
||||
actionsPageVM.AttemptModifyKeyChord(sender, args);
|
||||
});
|
||||
kcVM.DeleteKeyChordRequested([actionsPageVM](const Editor::KeyChordViewModel& /*sender*/, const Control::KeyChord& args) {
|
||||
// todo: remove the sender from our list
|
||||
// todo: remove the sender from our list, remove flyout
|
||||
actionsPageVM.AttemptDeleteKeyChord(args);
|
||||
});
|
||||
}
|
||||
@@ -204,7 +216,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
|
||||
void KeyChordViewModel::AttemptAcceptChanges()
|
||||
{
|
||||
if (_currentKeys.Modifiers() != _ProposedKeys.Modifiers() || _currentKeys.Vkey() != _ProposedKeys.Vkey())
|
||||
if (!_currentKeys)
|
||||
{
|
||||
AddKeyChordRequested.raise(*this, _ProposedKeys);
|
||||
}
|
||||
else if (_currentKeys.Modifiers() != _ProposedKeys.Modifiers() || _currentKeys.Vkey() != _ProposedKeys.Vkey())
|
||||
{
|
||||
const auto args{ make_self<ModifyKeyChordEventArgs>(_currentKeys, // OldKeys
|
||||
_ProposedKeys) }; // NewKeys
|
||||
@@ -436,6 +452,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
_Settings.ActionMap().DeleteKeyBinding(keys);
|
||||
}
|
||||
|
||||
void ActionsViewModel::AttemptAddKeyChord(const Control::KeyChord& keys, const winrt::hstring& cmdID)
|
||||
{
|
||||
// Update the settings model
|
||||
_Settings.ActionMap().AddKeyBinding(keys, cmdID);
|
||||
}
|
||||
|
||||
void ActionsViewModel::_KeyBindingViewModelPropertyChangedHandler(const IInspectable& sender, const Windows::UI::Xaml::Data::PropertyChangedEventArgs& args)
|
||||
{
|
||||
const auto senderVM{ sender.as<Editor::KeyBindingViewModel>() };
|
||||
|
||||
@@ -143,6 +143,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
void Delete_Click();
|
||||
til::typed_event<Editor::CommandViewModel, IInspectable> DeleteRequested;
|
||||
|
||||
void AddKeybinding_Click();
|
||||
|
||||
VIEW_MODEL_OBSERVABLE_PROPERTY(IInspectable, ProposedAction);
|
||||
VIEW_MODEL_OBSERVABLE_PROPERTY(hstring, CurrentAction);
|
||||
WINRT_PROPERTY(Windows::Foundation::Collections::IObservableVector<hstring>, AvailableActions, nullptr);
|
||||
@@ -173,6 +175,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
VIEW_MODEL_OBSERVABLE_PROPERTY(Windows::UI::Xaml::Controls::Flyout, AcceptChangesFlyout, nullptr);
|
||||
|
||||
public:
|
||||
til::typed_event<Editor::KeyChordViewModel, Terminal::Control::KeyChord> AddKeyChordRequested;
|
||||
til::typed_event<Editor::KeyChordViewModel, Editor::ModifyKeyChordEventArgs> ModifyKeyChordRequested;
|
||||
til::typed_event<Editor::KeyChordViewModel, Terminal::Control::KeyChord> DeleteKeyChordRequested;
|
||||
|
||||
@@ -194,6 +197,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
|
||||
void AttemptModifyKeyChord(const Editor::KeyChordViewModel& senderVM, const Editor::ModifyKeyChordEventArgs& args);
|
||||
void AttemptDeleteKeyChord(const Control::KeyChord& keys);
|
||||
void AttemptAddKeyChord(const Control::KeyChord& keys, const winrt::hstring& cmdID);
|
||||
|
||||
til::typed_event<IInspectable, IInspectable> FocusContainer;
|
||||
til::typed_event<IInspectable, IInspectable> UpdateBackground;
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace Microsoft.Terminal.Settings.Editor
|
||||
void CancelChanges();
|
||||
void DeleteKeyBinding();
|
||||
|
||||
|
||||
event Windows.Foundation.TypedEventHandler<KeyBindingViewModel, ModifyKeyBindingEventArgs> ModifyKeyBindingRequested;
|
||||
event Windows.Foundation.TypedEventHandler<KeyBindingViewModel, Microsoft.Terminal.Control.KeyChord> DeleteKeyBindingRequested;
|
||||
}
|
||||
@@ -66,6 +67,7 @@ namespace Microsoft.Terminal.Settings.Editor
|
||||
Object ProposedAction;
|
||||
void Edit_Click();
|
||||
void Delete_Click();
|
||||
void AddKeybinding_Click();
|
||||
IObservableVector<String> AvailableActions { get; };
|
||||
}
|
||||
|
||||
@@ -82,6 +84,7 @@ namespace Microsoft.Terminal.Settings.Editor
|
||||
void CancelChanges();
|
||||
void DeleteKeyChord();
|
||||
|
||||
event Windows.Foundation.TypedEventHandler<KeyChordViewModel, Microsoft.Terminal.Control.KeyChord> AddKeyChordRequested;
|
||||
event Windows.Foundation.TypedEventHandler<KeyChordViewModel, ModifyKeyChordEventArgs> ModifyKeyChordRequested;
|
||||
event Windows.Foundation.TypedEventHandler<KeyChordViewModel, Microsoft.Terminal.Control.KeyChord> DeleteKeyChordRequested;
|
||||
}
|
||||
@@ -107,6 +110,7 @@ namespace Microsoft.Terminal.Settings.Editor
|
||||
ActionsSubPage CurrentPage;
|
||||
CommandViewModel CurrentCommand;
|
||||
|
||||
void AttemptAddKeyChord(Microsoft.Terminal.Control.KeyChord keys, String cmdID);
|
||||
void AttemptModifyKeyChord(KeyChordViewModel senderVM, ModifyKeyChordEventArgs args);
|
||||
void AttemptDeleteKeyChord(Microsoft.Terminal.Control.KeyChord keys);
|
||||
|
||||
|
||||
@@ -238,14 +238,20 @@
|
||||
IsEnabled="{x:Bind ViewModel.IsUserAction}"/>
|
||||
<ListView ItemTemplate="{StaticResource KeyChordTemplate}"
|
||||
ItemsSource="{x:Bind ViewModel.KeyChordViewModelList, Mode=OneWay}"
|
||||
SelectionMode="None" />
|
||||
SelectionMode="None">
|
||||
<ListView.Header>
|
||||
<Button Click="{x:Bind ViewModel.AddKeybinding_Click}">
|
||||
<TextBlock x:Uid="Actions_AddKeyChord" />
|
||||
</Button>
|
||||
</ListView.Header>
|
||||
</ListView>
|
||||
<Button Style="{StaticResource DeleteButtonStyle}"
|
||||
IsEnabled="{x:Bind ViewModel.IsUserAction}">
|
||||
<Button.Content>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<FontIcon FontSize="{StaticResource StandardIconSize}"
|
||||
Glyph="" />
|
||||
<TextBlock x:Uid="Actions_DeleteButton"
|
||||
<TextBlock x:Uid="Actions_DeleteButton2"
|
||||
Style="{StaticResource IconButtonTextBlockStyle}" />
|
||||
</StackPanel>
|
||||
</Button.Content>
|
||||
|
||||
@@ -1703,10 +1703,14 @@
|
||||
<value>Delete the unfocused appearance for this profile.</value>
|
||||
<comment>A description for what the delete unfocused appearance button does.</comment>
|
||||
</data>
|
||||
<data name="Actions_DeleteButton.Text" xml:space="preserve">
|
||||
<data name="Actions_DeleteButton2.Text" xml:space="preserve">
|
||||
<value>Delete action</value>
|
||||
<comment>Button label that deletes the selected action.</comment>
|
||||
</data>
|
||||
<data name="Actions_AddKeyChord.Text" xml:space="preserve">
|
||||
<value>Add keybinding</value>
|
||||
<comment>Button label that adds a keybinding to the current action.</comment>
|
||||
</data>
|
||||
<data name="Actions_DeleteConfirmationButton.Content" xml:space="preserve">
|
||||
<value>Yes, delete key binding</value>
|
||||
<comment>Button label that confirms deletion of a key binding entry.</comment>
|
||||
|
||||
@@ -741,6 +741,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
||||
}
|
||||
}
|
||||
|
||||
void ActionMap::AddKeyBinding(Control::KeyChord keys, const winrt::hstring& cmdID)
|
||||
{
|
||||
_KeyMap.insert_or_assign(keys, cmdID);
|
||||
_RefreshKeyBindingCaches();
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Add a new key binding
|
||||
// - If the key chord is already in use, the conflicting command is overwritten.
|
||||
|
||||
@@ -78,6 +78,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
||||
// modification
|
||||
bool RebindKeys(const Control::KeyChord& oldKeys, const Control::KeyChord& newKeys);
|
||||
void DeleteKeyBinding(const Control::KeyChord& keys);
|
||||
void AddKeyBinding(Control::KeyChord keys, const winrt::hstring& cmdID);
|
||||
void RegisterKeyBinding(Control::KeyChord keys, Model::ActionAndArgs action);
|
||||
void DeleteUserCommand(const winrt::hstring& cmdID);
|
||||
void AddSendInputAction(winrt::hstring name, winrt::hstring input, const Control::KeyChord keys);
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace Microsoft.Terminal.Settings.Model
|
||||
void RebindKeys(Microsoft.Terminal.Control.KeyChord oldKeys, Microsoft.Terminal.Control.KeyChord newKeys);
|
||||
void DeleteKeyBinding(Microsoft.Terminal.Control.KeyChord keys);
|
||||
void DeleteUserCommand(String cmdID);
|
||||
void AddKeyBinding(Microsoft.Terminal.Control.KeyChord keys, String cmdID);
|
||||
void RegisterKeyBinding(Microsoft.Terminal.Control.KeyChord keys, ActionAndArgs action);
|
||||
void AddSendInputAction(String name, String input, Microsoft.Terminal.Control.KeyChord keys);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user