Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsEditor/Actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
const auto args = e.Parameter().as<Editor::NavigateToPageArgs>();
_ViewModel = args.ViewModel().as<Editor::ActionsViewModel>();
_ViewModel.ReSortCommandList();
auto vmImpl = get_self<ActionsViewModel>(_ViewModel);
vmImpl->MarkAsVisited();
_layoutUpdatedRevoker = LayoutUpdated(winrt::auto_revoke, [this](auto /*s*/, auto /*e*/) {
Expand Down
48 changes: 42 additions & 6 deletions src/cascadia/TerminalSettingsEditor/ActionsViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -322,7 +321,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
weak->_ReplaceCommandWithUserCopy(false);
}
weak->_NotifyChanges(L"DisplayName");
if (!weak->_command.HasName())
{
weak->_NotifyChanges(L"DisplayName");
}
}
});
}
Expand Down Expand Up @@ -359,7 +361,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) :
Expand Down Expand Up @@ -1241,6 +1246,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;
Expand Down Expand Up @@ -1411,5 +1435,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;
}
}
});
}
}
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsEditor/ActionsViewModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,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();
Expand All @@ -279,6 +280,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);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsEditor/ActionsViewModel.idl
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ namespace Microsoft.Terminal.Settings.Editor
void UpdateSettings(Microsoft.Terminal.Settings.Model.CascadiaSettings settings);

void AddNewCommand();
void ReSortCommandList();

ActionsSubPage CurrentPage;
Boolean DisplayBadge { get; };
Expand Down
Loading