Skip to content

Commit f6303ac

Browse files
Add reflection to the ActionArgs in the settings model (#18915)
Implements reflection to the various ActionArg types in the settings model, which allows these structs to provide information about themselves (i.e. what args they contain and what types they are). This is necessary as a pre-requisite for the Settings Editor to display and modify these arg values. ## Detailed Description of the Pull Request / Additional comments * The `IActionArgs` interface now has additional methods: * Get the number of args * Get/Set an arg at a specific index * Get a vector of arg descriptions; the arg description contains: * name of the arg * type of the arg * whether the arg is required * a tag, this is to cover special cases (for example the ColorScheme argument is technically of type "string", but only allows specific values) * All the macros in `ActionArgsMagic` have been updated to support the new interface * `ActionMap` has been updated to support adding/editing/deleting actions and keybindings from outside the SettingsModel * It also handles ID change requests for commands * EnumMappings have been added to various ActionArg enums that weren't there before ## Validation Steps Performed Bug bashed in conjunction with #18917
1 parent 52e60b9 commit f6303ac

19 files changed

+1065
-277
lines changed

src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp

Lines changed: 1 addition & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -342,107 +342,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
342342

343343
winrt::hstring ActionAndArgs::GenerateName(const winrt::Windows::ApplicationModel::Resources::Core::ResourceContext& context) const
344344
{
345-
// Sentinel used to indicate this command must ALWAYS be generated by GenerateName
346-
static constexpr wil::zwstring_view MustGenerate{};
347-
// Use a magic static to initialize this map, because we won't be able
348-
// to load the resources at _init_, only at runtime.
349-
static const auto GeneratedActionNames = []() {
350-
return std::unordered_map<ShortcutAction, wil::zwstring_view>{
351-
{ ShortcutAction::AdjustFontSize, USES_RESOURCE(L"AdjustFontSizeCommandKey") },
352-
{ ShortcutAction::CloseOtherPanes, USES_RESOURCE(L"CloseOtherPanesCommandKey") },
353-
{ ShortcutAction::CloseOtherTabs, MustGenerate },
354-
{ ShortcutAction::ClosePane, USES_RESOURCE(L"ClosePaneCommandKey") },
355-
{ ShortcutAction::CloseTab, MustGenerate },
356-
{ ShortcutAction::CloseTabsAfter, MustGenerate },
357-
{ ShortcutAction::CloseWindow, USES_RESOURCE(L"CloseWindowCommandKey") },
358-
{ ShortcutAction::CopyText, USES_RESOURCE(L"CopyTextCommandKey") },
359-
{ ShortcutAction::DuplicateTab, USES_RESOURCE(L"DuplicateTabCommandKey") },
360-
{ ShortcutAction::ExecuteCommandline, USES_RESOURCE(L"ExecuteCommandlineCommandKey") },
361-
{ ShortcutAction::Find, USES_RESOURCE(L"FindCommandKey") },
362-
{ ShortcutAction::Invalid, MustGenerate },
363-
{ ShortcutAction::MoveFocus, USES_RESOURCE(L"MoveFocusCommandKey") },
364-
{ ShortcutAction::MovePane, USES_RESOURCE(L"MovePaneCommandKey") },
365-
{ ShortcutAction::SwapPane, USES_RESOURCE(L"SwapPaneCommandKey") },
366-
{ ShortcutAction::NewTab, USES_RESOURCE(L"NewTabCommandKey") },
367-
{ ShortcutAction::NextTab, USES_RESOURCE(L"NextTabCommandKey") },
368-
{ ShortcutAction::OpenNewTabDropdown, USES_RESOURCE(L"OpenNewTabDropdownCommandKey") },
369-
{ ShortcutAction::OpenSettings, USES_RESOURCE(L"OpenSettingsUICommandKey") },
370-
{ ShortcutAction::OpenTabColorPicker, USES_RESOURCE(L"OpenTabColorPickerCommandKey") },
371-
{ ShortcutAction::PasteText, USES_RESOURCE(L"PasteTextCommandKey") },
372-
{ ShortcutAction::PrevTab, USES_RESOURCE(L"PrevTabCommandKey") },
373-
{ ShortcutAction::RenameTab, USES_RESOURCE(L"ResetTabNameCommandKey") },
374-
{ ShortcutAction::OpenTabRenamer, USES_RESOURCE(L"OpenTabRenamerCommandKey") },
375-
{ ShortcutAction::ResetFontSize, USES_RESOURCE(L"ResetFontSizeCommandKey") },
376-
{ ShortcutAction::ResizePane, USES_RESOURCE(L"ResizePaneCommandKey") },
377-
{ ShortcutAction::ScrollDown, USES_RESOURCE(L"ScrollDownCommandKey") },
378-
{ ShortcutAction::ScrollDownPage, USES_RESOURCE(L"ScrollDownPageCommandKey") },
379-
{ ShortcutAction::ScrollUp, USES_RESOURCE(L"ScrollUpCommandKey") },
380-
{ ShortcutAction::ScrollUpPage, USES_RESOURCE(L"ScrollUpPageCommandKey") },
381-
{ ShortcutAction::ScrollToTop, USES_RESOURCE(L"ScrollToTopCommandKey") },
382-
{ ShortcutAction::ScrollToBottom, USES_RESOURCE(L"ScrollToBottomCommandKey") },
383-
{ ShortcutAction::ScrollToMark, USES_RESOURCE(L"ScrollToPreviousMarkCommandKey") },
384-
{ ShortcutAction::AddMark, USES_RESOURCE(L"AddMarkCommandKey") },
385-
{ ShortcutAction::ClearMark, USES_RESOURCE(L"ClearMarkCommandKey") },
386-
{ ShortcutAction::ClearAllMarks, USES_RESOURCE(L"ClearAllMarksCommandKey") },
387-
{ ShortcutAction::SendInput, MustGenerate },
388-
{ ShortcutAction::SetColorScheme, MustGenerate },
389-
{ ShortcutAction::SetTabColor, USES_RESOURCE(L"ResetTabColorCommandKey") },
390-
{ ShortcutAction::SplitPane, USES_RESOURCE(L"SplitPaneCommandKey") },
391-
{ ShortcutAction::SwitchToTab, USES_RESOURCE(L"SwitchToTabCommandKey") },
392-
{ ShortcutAction::TabSearch, USES_RESOURCE(L"TabSearchCommandKey") },
393-
{ ShortcutAction::ToggleAlwaysOnTop, USES_RESOURCE(L"ToggleAlwaysOnTopCommandKey") },
394-
{ ShortcutAction::ToggleCommandPalette, MustGenerate },
395-
{ ShortcutAction::SaveSnippet, MustGenerate },
396-
{ ShortcutAction::Suggestions, MustGenerate },
397-
{ ShortcutAction::ToggleFocusMode, USES_RESOURCE(L"ToggleFocusModeCommandKey") },
398-
{ ShortcutAction::SetFocusMode, MustGenerate },
399-
{ ShortcutAction::ToggleFullscreen, USES_RESOURCE(L"ToggleFullscreenCommandKey") },
400-
{ ShortcutAction::SetFullScreen, MustGenerate },
401-
{ ShortcutAction::SetMaximized, MustGenerate },
402-
{ ShortcutAction::TogglePaneZoom, USES_RESOURCE(L"TogglePaneZoomCommandKey") },
403-
{ ShortcutAction::ToggleSplitOrientation, USES_RESOURCE(L"ToggleSplitOrientationCommandKey") },
404-
{ ShortcutAction::ToggleShaderEffects, USES_RESOURCE(L"ToggleShaderEffectsCommandKey") },
405-
{ ShortcutAction::MoveTab, MustGenerate },
406-
{ ShortcutAction::BreakIntoDebugger, USES_RESOURCE(L"BreakIntoDebuggerCommandKey") },
407-
{ ShortcutAction::FindMatch, MustGenerate },
408-
{ ShortcutAction::TogglePaneReadOnly, USES_RESOURCE(L"TogglePaneReadOnlyCommandKey") },
409-
{ ShortcutAction::EnablePaneReadOnly, USES_RESOURCE(L"EnablePaneReadOnlyCommandKey") },
410-
{ ShortcutAction::DisablePaneReadOnly, USES_RESOURCE(L"DisablePaneReadOnlyCommandKey") },
411-
{ ShortcutAction::NewWindow, USES_RESOURCE(L"NewWindowCommandKey") },
412-
{ ShortcutAction::IdentifyWindow, USES_RESOURCE(L"IdentifyWindowCommandKey") },
413-
{ ShortcutAction::IdentifyWindows, USES_RESOURCE(L"IdentifyWindowsCommandKey") },
414-
{ ShortcutAction::RenameWindow, USES_RESOURCE(L"ResetWindowNameCommandKey") },
415-
{ ShortcutAction::OpenWindowRenamer, USES_RESOURCE(L"OpenWindowRenamerCommandKey") },
416-
{ ShortcutAction::DisplayWorkingDirectory, USES_RESOURCE(L"DisplayWorkingDirectoryCommandKey") },
417-
{ ShortcutAction::GlobalSummon, MustGenerate },
418-
{ ShortcutAction::SearchForText, MustGenerate },
419-
{ ShortcutAction::QuakeMode, USES_RESOURCE(L"QuakeModeCommandKey") },
420-
{ ShortcutAction::FocusPane, MustGenerate },
421-
{ ShortcutAction::OpenSystemMenu, USES_RESOURCE(L"OpenSystemMenuCommandKey") },
422-
{ ShortcutAction::ExportBuffer, MustGenerate },
423-
{ ShortcutAction::ClearBuffer, MustGenerate },
424-
{ ShortcutAction::MultipleActions, MustGenerate },
425-
{ ShortcutAction::Quit, USES_RESOURCE(L"QuitCommandKey") },
426-
{ ShortcutAction::AdjustOpacity, MustGenerate },
427-
{ ShortcutAction::RestoreLastClosed, USES_RESOURCE(L"RestoreLastClosedCommandKey") },
428-
{ ShortcutAction::SelectCommand, MustGenerate },
429-
{ ShortcutAction::SelectOutput, MustGenerate },
430-
{ ShortcutAction::SelectAll, USES_RESOURCE(L"SelectAllCommandKey") },
431-
{ ShortcutAction::MarkMode, USES_RESOURCE(L"MarkModeCommandKey") },
432-
{ ShortcutAction::ToggleBlockSelection, USES_RESOURCE(L"ToggleBlockSelectionCommandKey") },
433-
{ ShortcutAction::SwitchSelectionEndpoint, USES_RESOURCE(L"SwitchSelectionEndpointCommandKey") },
434-
{ ShortcutAction::ColorSelection, MustGenerate },
435-
{ ShortcutAction::ShowContextMenu, USES_RESOURCE(L"ShowContextMenuCommandKey") },
436-
{ ShortcutAction::ExpandSelectionToWord, USES_RESOURCE(L"ExpandSelectionToWordCommandKey") },
437-
{ ShortcutAction::RestartConnection, USES_RESOURCE(L"RestartConnectionKey") },
438-
{ ShortcutAction::ToggleBroadcastInput, USES_RESOURCE(L"ToggleBroadcastInputCommandKey") },
439-
{ ShortcutAction::OpenScratchpad, USES_RESOURCE(L"OpenScratchpadKey") },
440-
{ ShortcutAction::OpenAbout, USES_RESOURCE(L"OpenAboutCommandKey") },
441-
{ ShortcutAction::QuickFix, USES_RESOURCE(L"QuickFixCommandKey") },
442-
{ ShortcutAction::OpenCWD, USES_RESOURCE(L"OpenCWDCommandKey") },
443-
};
444-
}();
445-
446345
if (_Args)
447346
{
448347
auto nameFromArgs = _Args.GenerateName(context);
@@ -452,12 +351,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
452351
}
453352
}
454353

455-
const auto found = GeneratedActionNames.find(_Action);
456-
if (found != GeneratedActionNames.end() && !found->second.empty())
457-
{
458-
return GetLibraryResourceLoader().ResourceMap().GetValue(found->second, context).ValueAsString();
459-
}
460-
return winrt::hstring{};
354+
return ActionArgFactory::GetNameForAction(_Action, context);
461355
}
462356

463357
winrt::hstring ActionAndArgs::GenerateName() const

0 commit comments

Comments
 (0)