mirror of
https://github.com/microsoft/terminal.git
synced 2026-02-04 03:05:08 -06:00
top level command list gets updated when new commands are added or existing commands names are changed
This commit is contained in:
parent
b668fd5188
commit
783b07d1cc
@ -21,6 +21,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
void Actions::OnNavigatedTo(const NavigationEventArgs& e)
|
||||
{
|
||||
_ViewModel = e.Parameter().as<Editor::ActionsViewModel>();
|
||||
_ViewModel.ReSortCommandList();
|
||||
_ViewModel.CurrentPage(ActionsSubPage::Base);
|
||||
auto vmImpl = get_self<ActionsViewModel>(_ViewModel);
|
||||
vmImpl->MarkAsVisited();
|
||||
|
||||
@ -126,13 +126,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
|
||||
void CommandViewModel::Name(const winrt::hstring& newName)
|
||||
{
|
||||
_command.Name(newName);
|
||||
if (newName.empty())
|
||||
if (_command.Name() != newName)
|
||||
{
|
||||
// if the name was cleared, refresh the DisplayName
|
||||
_command.Name(newName);
|
||||
_NotifyChanges(L"DisplayName", L"DisplayNameAndKeyChordAutomationPropName");
|
||||
_cachedDisplayName.clear();
|
||||
}
|
||||
_cachedDisplayName.clear();
|
||||
}
|
||||
|
||||
winrt::hstring CommandViewModel::DisplayNameAndKeyChordAutomationPropName()
|
||||
@ -283,7 +282,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
{
|
||||
weak->_ReplaceCommandWithUserCopy(false);
|
||||
}
|
||||
weak->_NotifyChanges(L"DisplayName");
|
||||
if (!weak->_command.HasName())
|
||||
{
|
||||
weak->_NotifyChanges(L"DisplayName");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -320,7 +322,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
_RegisterActionArgsVMEvents(*actionArgsVM);
|
||||
actionArgsVM->Initialize();
|
||||
ActionArgsVM(*actionArgsVM);
|
||||
_NotifyChanges(L"DisplayName");
|
||||
if (!_command.HasName())
|
||||
{
|
||||
_NotifyChanges(L"DisplayName");
|
||||
}
|
||||
}
|
||||
|
||||
ArgWrapper::ArgWrapper(const Model::ArgDescriptor& descriptor, const Windows::Foundation::IInspectable& value) :
|
||||
@ -1186,6 +1191,25 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
CurrentPage(ActionsSubPage::Edit);
|
||||
}
|
||||
|
||||
void ActionsViewModel::ReSortCommandList()
|
||||
{
|
||||
if (_CommandListDirty)
|
||||
{
|
||||
std::vector<Editor::CommandViewModel> commandList;
|
||||
commandList.reserve(_CommandList.Size());
|
||||
for (const auto& cmd : _CommandList)
|
||||
{
|
||||
commandList.push_back(cmd);
|
||||
}
|
||||
std::sort(commandList.begin(), commandList.end(), [](const Editor::CommandViewModel& lhs, const Editor::CommandViewModel& rhs) {
|
||||
return lhs.DisplayName() < rhs.DisplayName();
|
||||
});
|
||||
_CommandList = single_threaded_observable_vector(std::move(commandList));
|
||||
_NotifyChanges(L"CommandList");
|
||||
_CommandListDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ActionsViewModel::CurrentCommand(const Editor::CommandViewModel& newCommand)
|
||||
{
|
||||
_CurrentCommand = newCommand;
|
||||
@ -1356,5 +1380,17 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
cmdVM->DeleteRequested({ this, &ActionsViewModel::_CmdVMDeleteRequestedHandler });
|
||||
cmdVM->PropagateColorSchemeRequested({ this, &ActionsViewModel::_CmdVMPropagateColorSchemeRequestedHandler });
|
||||
cmdVM->PropagateColorSchemeNamesRequested({ this, &ActionsViewModel::_CmdVMPropagateColorSchemeNamesRequestedHandler });
|
||||
cmdVM->PropertyChanged([weakThis{ get_weak() }](const IInspectable& sender, const Windows::UI::Xaml::Data::PropertyChangedEventArgs& args) {
|
||||
if (const auto self{ weakThis.get() })
|
||||
{
|
||||
const auto senderVM{ sender.as<Editor::CommandViewModel>() };
|
||||
const auto propertyName{ args.PropertyName() };
|
||||
if (propertyName == L"DisplayName")
|
||||
{
|
||||
// when a command's name changes, note that we need to re-sort the command list when we navigate back to the actions page
|
||||
self->_CommandListDirty = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,6 +270,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
bool DisplayBadge() const noexcept;
|
||||
|
||||
void AddNewCommand();
|
||||
void ReSortCommandList();
|
||||
|
||||
void CurrentCommand(const Editor::CommandViewModel& newCommand);
|
||||
Editor::CommandViewModel CurrentCommand();
|
||||
@ -291,6 +292,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
Model::CascadiaSettings _Settings;
|
||||
Windows::Foundation::Collections::IMap<Model::ShortcutAction, winrt::hstring> _AvailableActionsAndNamesMap;
|
||||
Windows::Foundation::Collections::IMap<winrt::hstring, Model::ShortcutAction> _NameToActionMap;
|
||||
bool _CommandListDirty{ false };
|
||||
|
||||
void _MakeCommandVMsHelper();
|
||||
void _RegisterCmdVMEvents(com_ptr<implementation::CommandViewModel>& cmdVM);
|
||||
|
||||
@ -170,6 +170,7 @@ namespace Microsoft.Terminal.Settings.Editor
|
||||
void UpdateSettings(Microsoft.Terminal.Settings.Model.CascadiaSettings settings);
|
||||
|
||||
void AddNewCommand();
|
||||
void ReSortCommandList();
|
||||
|
||||
ActionsSubPage CurrentPage;
|
||||
Boolean DisplayBadge { get; };
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user