Skip to content

Commit

Permalink
Stop parsing saveSnippets actions in json (#17535)
Browse files Browse the repository at this point in the history
In the spec review, we agreed these didn't really need to be saved to
the user's own settings file. This removes parsing and saving for the
`experimental.saveSnippet` action, but we still have the action
_internally_. This is powered by a new x-macro for "INTERNAL_" actions.

Follow-up from #16513.
  • Loading branch information
zadjii-msft authored Jul 10, 2024
1 parent ae8c868 commit 8b7c73c
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/AppCommandlineArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ void AppCommandlineArgs::_buildFocusPaneParser()

void AppCommandlineArgs::_buildSaveSnippetParser()
{
_saveCommand = _app.add_subcommand("x-save-snippet", RS_A(L"SaveSnippetDesc"));
_saveCommand = _app.add_subcommand("x-save", RS_A(L"SaveSnippetDesc"));

auto setupSubcommand = [this](auto* subcommand) {
subcommand->add_option("--name,-n", _saveInputName, RS_A(L"SaveSnippetArgDesc"));
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/ShortcutActionDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace winrt::TerminalApp::implementation
{
#define ON_ALL_ACTIONS(id) ACTION_CASE(id);
ALL_SHORTCUT_ACTIONS
INTERNAL_SHORTCUT_ACTIONS
#undef ON_ALL_ACTIONS
default:
return false;
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/ShortcutActionDispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace winrt::TerminalApp::implementation

#define ON_ALL_ACTIONS(action) DECLARE_ACTION(action);
ALL_SHORTCUT_ACTIONS
INTERNAL_SHORTCUT_ACTIONS
#undef ON_ALL_ACTIONS

private:
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/ShortcutActionDispatch.idl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace TerminalApp
// When adding a new action, add them to AllShortcutActions.h!
#define ON_ALL_ACTIONS(action) ACTION_EVENT(action);
ALL_SHORTCUT_ACTIONS
INTERNAL_SHORTCUT_ACTIONS
#undef ON_ALL_ACTIONS

}
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,7 @@ namespace winrt::TerminalApp::implementation
// there's an actual keychord for them.
#define ON_ALL_ACTIONS(action) HOOKUP_ACTION(action);
ALL_SHORTCUT_ACTIONS
INTERNAL_SHORTCUT_ACTIONS
#undef ON_ALL_ACTIONS
}

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ namespace winrt::TerminalApp::implementation
// These are all defined in AppActionHandlers.cpp
#define ON_ALL_ACTIONS(action) DECLARE_ACTION_HANDLER(action);
ALL_SHORTCUT_ACTIONS
INTERNAL_SHORTCUT_ACTIONS
#undef ON_ALL_ACTIONS
#pragma endregion

Expand Down
4 changes: 3 additions & 1 deletion src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ static constexpr std::string_view SwitchToTabKey{ "switchToTab" };
static constexpr std::string_view TabSearchKey{ "tabSearch" };
static constexpr std::string_view ToggleAlwaysOnTopKey{ "toggleAlwaysOnTop" };
static constexpr std::string_view ToggleCommandPaletteKey{ "commandPalette" };
static constexpr std::string_view SaveSnippetKey{ "experimental.saveSnippet" };
static constexpr std::string_view SuggestionsKey{ "showSuggestions" };
static constexpr std::string_view ToggleFocusModeKey{ "toggleFocusMode" };
static constexpr std::string_view SetFocusModeKey{ "setFocusMode" };
Expand Down Expand Up @@ -124,12 +123,14 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
const std::map<std::string_view, ShortcutAction, std::less<>> ActionAndArgs::ActionKeyNamesMap{
#define ON_ALL_ACTIONS(action) KEY_TO_ACTION_PAIR(action)
ALL_SHORTCUT_ACTIONS
// Don't include the INTERNAL_SHORTCUT_ACTIONS here
#undef ON_ALL_ACTIONS
};

static const std::map<ShortcutAction, std::string_view, std::less<>> ActionToStringMap{
#define ON_ALL_ACTIONS(action) ACTION_TO_KEY_PAIR(action)
ALL_SHORTCUT_ACTIONS
// Don't include the INTERNAL_SHORTCUT_ACTIONS here
#undef ON_ALL_ACTIONS
};

Expand All @@ -152,6 +153,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

#define ON_ALL_ACTIONS_WITH_ARGS(action) ACTION_TO_SERIALIZERS_PAIR(action)
ALL_SHORTCUT_ACTIONS_WITH_ARGS
// Don't include the INTERNAL_SHORTCUT_ACTIONS here
#undef ON_ALL_ACTIONS_WITH_ARGS
};

Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
break; \
}
ALL_SHORTCUT_ACTIONS_WITH_ARGS
INTERNAL_SHORTCUT_ACTIONS_WITH_ARGS
#undef ON_ALL_ACTIONS_WITH_ARGS
default:
break;
Expand Down Expand Up @@ -192,6 +193,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// now add any ShortcutActions that we might have missed
#define ON_ALL_ACTIONS(action) RegisterShortcutAction(ShortcutAction::action, availableActions, visitedActionIDs);
ALL_SHORTCUT_ACTIONS
// Don't include internal actions here
#undef ON_ALL_ACTIONS

_AvailableActionsCache = single_threaded_map(std::move(availableActions));
Expand Down
11 changes: 9 additions & 2 deletions src/cascadia/TerminalSettingsModel/AllShortcutActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
ON_ALL_ACTIONS(CloseTabsAfter) \
ON_ALL_ACTIONS(TabSearch) \
ON_ALL_ACTIONS(MoveTab) \
ON_ALL_ACTIONS(SaveSnippet) \
ON_ALL_ACTIONS(BreakIntoDebugger) \
ON_ALL_ACTIONS(TogglePaneReadOnly) \
ON_ALL_ACTIONS(EnablePaneReadOnly) \
Expand Down Expand Up @@ -149,7 +148,6 @@
ON_ALL_ACTIONS_WITH_ARGS(SplitPane) \
ON_ALL_ACTIONS_WITH_ARGS(SwitchToTab) \
ON_ALL_ACTIONS_WITH_ARGS(ToggleCommandPalette) \
ON_ALL_ACTIONS_WITH_ARGS(SaveSnippet) \
ON_ALL_ACTIONS_WITH_ARGS(FocusPane) \
ON_ALL_ACTIONS_WITH_ARGS(ExportBuffer) \
ON_ALL_ACTIONS_WITH_ARGS(ClearBuffer) \
Expand All @@ -159,3 +157,12 @@
ON_ALL_ACTIONS_WITH_ARGS(SelectCommand) \
ON_ALL_ACTIONS_WITH_ARGS(SelectOutput) \
ON_ALL_ACTIONS_WITH_ARGS(ColorSelection)

// These two macros here are for actions that we only use as internal currency.
// They don't need to be parsed by the settings model, or saved as actions to
// JSON.
#define INTERNAL_SHORTCUT_ACTIONS \
ON_ALL_ACTIONS(SaveSnippet)

#define INTERNAL_SHORTCUT_ACTIONS_WITH_ARGS \
ON_ALL_ACTIONS_WITH_ARGS(SaveSnippet)\
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/Command.idl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Microsoft.Terminal.Settings.Model
// When adding a new action, add them to AllShortcutActions.h!
#define ON_ALL_ACTIONS(action) action,
ALL_SHORTCUT_ACTIONS
INTERNAL_SHORTCUT_ACTIONS
#undef ON_ALL_ACTIONS
};

Expand Down

0 comments on commit 8b7c73c

Please sign in to comment.