From cd26c9242441e180b7eec5c1d156a159967fda4f Mon Sep 17 00:00:00 2001 From: Davide Date: Sun, 17 Jul 2022 22:51:59 +0200 Subject: [PATCH] copy CWD action --- .github/actions/spelling/expect/expect.txt | 1 + doc/cascadia/profiles.schema.json | 1 + .../TerminalApp/AppActionHandlers.cpp | 10 ++ src/cascadia/TerminalControl/ControlCore.cpp | 6 + src/cascadia/TerminalControl/ControlCore.h | 1 + src/cascadia/TerminalControl/ControlCore.idl | 1 + src/cascadia/TerminalControl/TermControl.cpp | 8 + src/cascadia/TerminalControl/TermControl.h | 1 + src/cascadia/TerminalControl/TermControl.idl | 1 + .../TerminalSettingsModel/ActionAndArgs.cpp | 2 + .../AllShortcutActions.h | 149 +++++++++--------- .../Resources/en-US/Resources.resw | 5 +- .../TerminalSettingsModel/defaults.json | 1 + 13 files changed, 112 insertions(+), 75 deletions(-) diff --git a/.github/actions/spelling/expect/expect.txt b/.github/actions/spelling/expect/expect.txt index 507f33cb5cb..67ef7b241c5 100644 --- a/.github/actions/spelling/expect/expect.txt +++ b/.github/actions/spelling/expect/expect.txt @@ -460,6 +460,7 @@ cwch cwchar cwctype cwd +CWDTo cxcy CXFRAME CXFULLSCREEN diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index 600aca2a2fd..3e18bd87b1c 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -307,6 +307,7 @@ "closeWindow", "commandPalette", "copy", + "copyCWD", "duplicateTab", "exportBuffer", "find", diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 10a7f8cfa31..7e07543c938 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -1122,4 +1122,14 @@ namespace winrt::TerminalApp::implementation args.Handled(handled); } } + + void TerminalPage::_HandleCopyCWD(const IInspectable& /*sender*/, + const ActionEventArgs& args) + { + if (const auto& control{ _GetActiveControl() }) + { + control.CopyCWDToClipboard(); + args.Handled(true); + } + } } diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 2ed9f2d7efe..652b55a82e8 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -1078,6 +1078,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation return true; } + void ControlCore::CopyCWDToClipboard() + { + const auto workingDirectory = WorkingDirectory(); + _CopyToClipboardHandlers(*this, winrt::make(winrt::hstring{ workingDirectory })); + } + void ControlCore::SelectAll() { auto lock = _terminal->LockForWriting(); diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h index c8ba9b88d7d..0190cb3cf19 100644 --- a/src/cascadia/TerminalControl/ControlCore.h +++ b/src/cascadia/TerminalControl/ControlCore.h @@ -81,6 +81,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation void SendInput(const winrt::hstring& wstr); void PasteText(const winrt::hstring& hstr); bool CopySelectionToClipboard(bool singleLine, const Windows::Foundation::IReference& formats); + void CopyCWDToClipboard(); void SelectAll(); void ClearSelection(); bool ToggleBlockSelection(); diff --git a/src/cascadia/TerminalControl/ControlCore.idl b/src/cascadia/TerminalControl/ControlCore.idl index ec8230fa180..97b6b16a6f3 100644 --- a/src/cascadia/TerminalControl/ControlCore.idl +++ b/src/cascadia/TerminalControl/ControlCore.idl @@ -88,6 +88,7 @@ namespace Microsoft.Terminal.Control Microsoft.Terminal.Core.ControlKeyStates modifiers); void SendInput(String text); void PasteText(String text); + void CopyCWDToClipboard(); void SelectAll(); void ClearSelection(); Boolean ToggleBlockSelection(); diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index 943190cfaf2..b0c735d2331 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -1926,6 +1926,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation return successfulCopy; } + void TermControl::CopyCWDToClipboard() + { + if (!_IsClosing()) + { + _core.CopyCWDToClipboard(); + } + } + // Method Description: // - Initiate a paste operation. void TermControl::PasteTextFromClipboard() diff --git a/src/cascadia/TerminalControl/TermControl.h b/src/cascadia/TerminalControl/TermControl.h index 655fce03fdb..d47f91352ec 100644 --- a/src/cascadia/TerminalControl/TermControl.h +++ b/src/cascadia/TerminalControl/TermControl.h @@ -36,6 +36,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation hstring GetProfileName() const; bool CopySelectionToClipboard(bool singleLine, const Windows::Foundation::IReference& formats); + void CopyCWDToClipboard(); void PasteTextFromClipboard(); void SelectAll(); bool ToggleBlockSelection(); diff --git a/src/cascadia/TerminalControl/TermControl.idl b/src/cascadia/TerminalControl/TermControl.idl index 101359b30e9..81f296307f4 100644 --- a/src/cascadia/TerminalControl/TermControl.idl +++ b/src/cascadia/TerminalControl/TermControl.idl @@ -50,6 +50,7 @@ namespace Microsoft.Terminal.Control event Windows.Foundation.TypedEventHandler ShowWindowChanged; Boolean CopySelectionToClipboard(Boolean singleLine, Windows.Foundation.IReference formats); + void CopyCWDToClipboard(); void PasteTextFromClipboard(); void SelectAll(); Boolean ToggleBlockSelection(); diff --git a/src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp b/src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp index 8591457e611..4e3a591d14f 100644 --- a/src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp +++ b/src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp @@ -83,6 +83,7 @@ static constexpr std::string_view SelectAllKey{ "selectAll" }; static constexpr std::string_view MarkModeKey{ "markMode" }; static constexpr std::string_view ToggleBlockSelectionKey{ "toggleBlockSelection" }; static constexpr std::string_view SwitchSelectionEndpointKey{ "switchSelectionEndpoint" }; +static constexpr std::string_view CopyCWDKey{ "copyCWD" }; static constexpr std::string_view ActionKey{ "action" }; @@ -402,6 +403,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation { ShortcutAction::MarkMode, RS_(L"MarkModeCommandKey") }, { ShortcutAction::ToggleBlockSelection, RS_(L"ToggleBlockSelectionCommandKey") }, { ShortcutAction::SwitchSelectionEndpoint, RS_(L"SwitchSelectionEndpointCommandKey") }, + { ShortcutAction::CopyCWD, RS_(L"copyCWDCommandKey") }, }; }(); diff --git a/src/cascadia/TerminalSettingsModel/AllShortcutActions.h b/src/cascadia/TerminalSettingsModel/AllShortcutActions.h index 23d4cf2110c..ef8bab2d315 100644 --- a/src/cascadia/TerminalSettingsModel/AllShortcutActions.h +++ b/src/cascadia/TerminalSettingsModel/AllShortcutActions.h @@ -23,80 +23,81 @@ // each action. This is _NOT_ something that should be used when any individual // case should be customized. -#define ALL_SHORTCUT_ACTIONS \ - ON_ALL_ACTIONS(CopyText) \ - ON_ALL_ACTIONS(PasteText) \ - ON_ALL_ACTIONS(OpenNewTabDropdown) \ - ON_ALL_ACTIONS(DuplicateTab) \ - ON_ALL_ACTIONS(NewTab) \ - ON_ALL_ACTIONS(CloseWindow) \ - ON_ALL_ACTIONS(CloseTab) \ - ON_ALL_ACTIONS(ClosePane) \ - ON_ALL_ACTIONS(NextTab) \ - ON_ALL_ACTIONS(PrevTab) \ - ON_ALL_ACTIONS(SendInput) \ - ON_ALL_ACTIONS(SplitPane) \ - ON_ALL_ACTIONS(ToggleSplitOrientation) \ - ON_ALL_ACTIONS(TogglePaneZoom) \ - ON_ALL_ACTIONS(SwitchToTab) \ - ON_ALL_ACTIONS(AdjustFontSize) \ - ON_ALL_ACTIONS(ResetFontSize) \ - ON_ALL_ACTIONS(ScrollUp) \ - ON_ALL_ACTIONS(ScrollDown) \ - ON_ALL_ACTIONS(ScrollUpPage) \ - ON_ALL_ACTIONS(ScrollDownPage) \ - ON_ALL_ACTIONS(ScrollToTop) \ - ON_ALL_ACTIONS(ScrollToBottom) \ - ON_ALL_ACTIONS(ScrollToMark) \ - ON_ALL_ACTIONS(AddMark) \ - ON_ALL_ACTIONS(ClearMark) \ - ON_ALL_ACTIONS(ClearAllMarks) \ - ON_ALL_ACTIONS(ResizePane) \ - ON_ALL_ACTIONS(MoveFocus) \ - ON_ALL_ACTIONS(MovePane) \ - ON_ALL_ACTIONS(SwapPane) \ - ON_ALL_ACTIONS(Find) \ - ON_ALL_ACTIONS(ToggleShaderEffects) \ - ON_ALL_ACTIONS(ToggleFocusMode) \ - ON_ALL_ACTIONS(ToggleFullscreen) \ - ON_ALL_ACTIONS(ToggleAlwaysOnTop) \ - ON_ALL_ACTIONS(OpenSettings) \ - ON_ALL_ACTIONS(SetFocusMode) \ - ON_ALL_ACTIONS(SetFullScreen) \ - ON_ALL_ACTIONS(SetMaximized) \ - ON_ALL_ACTIONS(SetColorScheme) \ - ON_ALL_ACTIONS(SetTabColor) \ - ON_ALL_ACTIONS(OpenTabColorPicker) \ - ON_ALL_ACTIONS(RenameTab) \ - ON_ALL_ACTIONS(OpenTabRenamer) \ - ON_ALL_ACTIONS(ExecuteCommandline) \ - ON_ALL_ACTIONS(ToggleCommandPalette) \ - ON_ALL_ACTIONS(CloseOtherTabs) \ - ON_ALL_ACTIONS(CloseTabsAfter) \ - ON_ALL_ACTIONS(TabSearch) \ - ON_ALL_ACTIONS(MoveTab) \ - ON_ALL_ACTIONS(BreakIntoDebugger) \ - ON_ALL_ACTIONS(TogglePaneReadOnly) \ - ON_ALL_ACTIONS(FindMatch) \ - ON_ALL_ACTIONS(NewWindow) \ - ON_ALL_ACTIONS(IdentifyWindow) \ - ON_ALL_ACTIONS(IdentifyWindows) \ - ON_ALL_ACTIONS(RenameWindow) \ - ON_ALL_ACTIONS(OpenWindowRenamer) \ - ON_ALL_ACTIONS(GlobalSummon) \ - ON_ALL_ACTIONS(QuakeMode) \ - ON_ALL_ACTIONS(FocusPane) \ - ON_ALL_ACTIONS(OpenSystemMenu) \ - ON_ALL_ACTIONS(ExportBuffer) \ - ON_ALL_ACTIONS(ClearBuffer) \ - ON_ALL_ACTIONS(MultipleActions) \ - ON_ALL_ACTIONS(Quit) \ - ON_ALL_ACTIONS(AdjustOpacity) \ - ON_ALL_ACTIONS(RestoreLastClosed) \ - ON_ALL_ACTIONS(SelectAll) \ - ON_ALL_ACTIONS(MarkMode) \ - ON_ALL_ACTIONS(ToggleBlockSelection) \ - ON_ALL_ACTIONS(SwitchSelectionEndpoint) +#define ALL_SHORTCUT_ACTIONS \ + ON_ALL_ACTIONS(CopyText) \ + ON_ALL_ACTIONS(PasteText) \ + ON_ALL_ACTIONS(OpenNewTabDropdown) \ + ON_ALL_ACTIONS(DuplicateTab) \ + ON_ALL_ACTIONS(NewTab) \ + ON_ALL_ACTIONS(CloseWindow) \ + ON_ALL_ACTIONS(CloseTab) \ + ON_ALL_ACTIONS(ClosePane) \ + ON_ALL_ACTIONS(NextTab) \ + ON_ALL_ACTIONS(PrevTab) \ + ON_ALL_ACTIONS(SendInput) \ + ON_ALL_ACTIONS(SplitPane) \ + ON_ALL_ACTIONS(ToggleSplitOrientation) \ + ON_ALL_ACTIONS(TogglePaneZoom) \ + ON_ALL_ACTIONS(SwitchToTab) \ + ON_ALL_ACTIONS(AdjustFontSize) \ + ON_ALL_ACTIONS(ResetFontSize) \ + ON_ALL_ACTIONS(ScrollUp) \ + ON_ALL_ACTIONS(ScrollDown) \ + ON_ALL_ACTIONS(ScrollUpPage) \ + ON_ALL_ACTIONS(ScrollDownPage) \ + ON_ALL_ACTIONS(ScrollToTop) \ + ON_ALL_ACTIONS(ScrollToBottom) \ + ON_ALL_ACTIONS(ScrollToMark) \ + ON_ALL_ACTIONS(AddMark) \ + ON_ALL_ACTIONS(ClearMark) \ + ON_ALL_ACTIONS(ClearAllMarks) \ + ON_ALL_ACTIONS(ResizePane) \ + ON_ALL_ACTIONS(MoveFocus) \ + ON_ALL_ACTIONS(MovePane) \ + ON_ALL_ACTIONS(SwapPane) \ + ON_ALL_ACTIONS(Find) \ + ON_ALL_ACTIONS(ToggleShaderEffects) \ + ON_ALL_ACTIONS(ToggleFocusMode) \ + ON_ALL_ACTIONS(ToggleFullscreen) \ + ON_ALL_ACTIONS(ToggleAlwaysOnTop) \ + ON_ALL_ACTIONS(OpenSettings) \ + ON_ALL_ACTIONS(SetFocusMode) \ + ON_ALL_ACTIONS(SetFullScreen) \ + ON_ALL_ACTIONS(SetMaximized) \ + ON_ALL_ACTIONS(SetColorScheme) \ + ON_ALL_ACTIONS(SetTabColor) \ + ON_ALL_ACTIONS(OpenTabColorPicker) \ + ON_ALL_ACTIONS(RenameTab) \ + ON_ALL_ACTIONS(OpenTabRenamer) \ + ON_ALL_ACTIONS(ExecuteCommandline) \ + ON_ALL_ACTIONS(ToggleCommandPalette) \ + ON_ALL_ACTIONS(CloseOtherTabs) \ + ON_ALL_ACTIONS(CloseTabsAfter) \ + ON_ALL_ACTIONS(TabSearch) \ + ON_ALL_ACTIONS(MoveTab) \ + ON_ALL_ACTIONS(BreakIntoDebugger) \ + ON_ALL_ACTIONS(TogglePaneReadOnly) \ + ON_ALL_ACTIONS(FindMatch) \ + ON_ALL_ACTIONS(NewWindow) \ + ON_ALL_ACTIONS(IdentifyWindow) \ + ON_ALL_ACTIONS(IdentifyWindows) \ + ON_ALL_ACTIONS(RenameWindow) \ + ON_ALL_ACTIONS(OpenWindowRenamer) \ + ON_ALL_ACTIONS(GlobalSummon) \ + ON_ALL_ACTIONS(QuakeMode) \ + ON_ALL_ACTIONS(FocusPane) \ + ON_ALL_ACTIONS(OpenSystemMenu) \ + ON_ALL_ACTIONS(ExportBuffer) \ + ON_ALL_ACTIONS(ClearBuffer) \ + ON_ALL_ACTIONS(MultipleActions) \ + ON_ALL_ACTIONS(Quit) \ + ON_ALL_ACTIONS(AdjustOpacity) \ + ON_ALL_ACTIONS(RestoreLastClosed) \ + ON_ALL_ACTIONS(SelectAll) \ + ON_ALL_ACTIONS(MarkMode) \ + ON_ALL_ACTIONS(ToggleBlockSelection) \ + ON_ALL_ACTIONS(SwitchSelectionEndpoint) \ + ON_ALL_ACTIONS(CopyCWD) #define ALL_SHORTCUT_ACTIONS_WITH_ARGS \ ON_ALL_ACTIONS_WITH_ARGS(AdjustFontSize) \ diff --git a/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw b/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw index ab0befb1533..5d79391ca72 100644 --- a/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw @@ -567,4 +567,7 @@ Switch selection endpoint - + + Copy CWD + + \ No newline at end of file diff --git a/src/cascadia/TerminalSettingsModel/defaults.json b/src/cascadia/TerminalSettingsModel/defaults.json index 7a672723c33..b046839bf62 100644 --- a/src/cascadia/TerminalSettingsModel/defaults.json +++ b/src/cascadia/TerminalSettingsModel/defaults.json @@ -408,6 +408,7 @@ { "command": "markMode", "keys": "ctrl+shift+m" }, { "command": "toggleBlockSelection" }, { "command": "switchSelectionEndpoint" }, + { "command": "copyCWD" }, // Scrollback { "command": "scrollDown", "keys": "ctrl+shift+down" },