From cfe879da962726862aae5c4e1fb2e1bac440341b Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 14 Jul 2022 13:01:00 -0500 Subject: [PATCH] Serialize the pane to a Content string, instead of just the guid. There's a lot of renaming, signature changes here. But StartupActions is a good mechanism for passing panes around, more or less. --- src/cascadia/Remoting/Monarch.cpp | 16 +-- src/cascadia/Remoting/Monarch.h | 2 +- src/cascadia/Remoting/Monarch.idl | 2 +- src/cascadia/Remoting/Peasant.cpp | 5 +- src/cascadia/Remoting/Peasant.h | 9 +- src/cascadia/Remoting/Peasant.idl | 4 +- src/cascadia/Remoting/WindowManager.cpp | 8 +- src/cascadia/Remoting/WindowManager.h | 2 +- src/cascadia/Remoting/WindowManager.idl | 2 +- src/cascadia/TerminalApp/AppLogic.cpp | 4 +- src/cascadia/TerminalApp/AppLogic.h | 4 +- src/cascadia/TerminalApp/AppLogic.idl | 4 +- src/cascadia/TerminalApp/Pane.cpp | 19 +++- src/cascadia/TerminalApp/Pane.h | 4 +- src/cascadia/TerminalApp/TerminalPage.cpp | 105 +++++++++++------- src/cascadia/TerminalApp/TerminalPage.h | 21 ++-- src/cascadia/TerminalApp/TerminalPage.idl | 11 +- .../TerminalSettingsModel/ActionAndArgs.cpp | 10 ++ .../TerminalSettingsModel/ActionAndArgs.h | 2 + .../TerminalSettingsModel/ActionArgs.h | 8 +- .../TerminalSettingsModel/ActionArgs.idl | 2 +- .../TerminalSettingsModel/Command.idl | 2 + src/cascadia/WindowsTerminal/AppHost.cpp | 7 +- 23 files changed, 159 insertions(+), 94 deletions(-) diff --git a/src/cascadia/Remoting/Monarch.cpp b/src/cascadia/Remoting/Monarch.cpp index b94ecd57435..a73b24b5007 100644 --- a/src/cascadia/Remoting/Monarch.cpp +++ b/src/cascadia/Remoting/Monarch.cpp @@ -1037,23 +1037,25 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation return winrt::single_threaded_vector(std::move(vec)); } - void Monarch::RequestMovePane(winrt::hstring window, - winrt::guid contentGuid, - uint32_t tabIndex) + void Monarch::RequestMoveContent(winrt::hstring window, + winrt::hstring content, + uint32_t tabIndex) { auto windowId = _lookupPeasantIdForName(window); if (windowId == 0) - { /* TODO! try the name as an integer ID */ + { + /* TODO! try the name as an integer ID */ return; } if (auto targetPeasant{ _getPeasant(windowId) }) { - auto request = winrt::make_self(contentGuid, tabIndex); - targetPeasant.AttachPaneToWindow(*request); + auto request = winrt::make_self(content, tabIndex); + targetPeasant.AttachContentToWindow(*request); } else - { /*TODO! log */ + { + /*TODO! log */ } } } diff --git a/src/cascadia/Remoting/Monarch.h b/src/cascadia/Remoting/Monarch.h index 6edc862e1ef..29c267554ee 100644 --- a/src/cascadia/Remoting/Monarch.h +++ b/src/cascadia/Remoting/Monarch.h @@ -60,7 +60,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation Windows::Foundation::Collections::IVectorView GetPeasantInfos(); Windows::Foundation::Collections::IVector GetAllWindowLayouts(); - void RequestMovePane(winrt::hstring window, winrt::guid contentGuid, uint32_t tabIndex); + void RequestMoveContent(winrt::hstring window, winrt::hstring content, uint32_t tabIndex); TYPED_EVENT(FindTargetWindowRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::FindTargetWindowArgs); TYPED_EVENT(ShowNotificationIconRequested, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable); diff --git a/src/cascadia/Remoting/Monarch.idl b/src/cascadia/Remoting/Monarch.idl index f9a4fe32346..3f04ef11c77 100644 --- a/src/cascadia/Remoting/Monarch.idl +++ b/src/cascadia/Remoting/Monarch.idl @@ -60,7 +60,7 @@ namespace Microsoft.Terminal.Remoting Windows.Foundation.Collections.IVectorView GetPeasantInfos { get; }; Windows.Foundation.Collections.IVector GetAllWindowLayouts(); - void RequestMovePane(String window, Guid contentGuid, UInt32 tabIndex); + void RequestMoveContent(String window, String content, UInt32 tabIndex); event Windows.Foundation.TypedEventHandler FindTargetWindowRequested; event Windows.Foundation.TypedEventHandler ShowNotificationIconRequested; diff --git a/src/cascadia/Remoting/Peasant.cpp b/src/cascadia/Remoting/Peasant.cpp index bb381d0f4d9..e084c8dcc29 100644 --- a/src/cascadia/Remoting/Peasant.cpp +++ b/src/cascadia/Remoting/Peasant.cpp @@ -276,7 +276,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation TraceLoggingKeyword(TIL_KEYWORD_TRACE)); } - void Peasant::AttachPaneToWindow(Remoting::AttachRequest request) + void Peasant::AttachContentToWindow(Remoting::AttachRequest request) { try { @@ -287,8 +287,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation LOG_CAUGHT_EXCEPTION(); } TraceLoggingWrite(g_hRemotingProvider, - "Peasant_AttachPaneToWindow", - + "Peasant_AttachContentToWindow", TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), TraceLoggingKeyword(TIL_KEYWORD_TRACE)); } diff --git a/src/cascadia/Remoting/Peasant.h b/src/cascadia/Remoting/Peasant.h index aa9f37ef87c..a0fb55dce73 100644 --- a/src/cascadia/Remoting/Peasant.h +++ b/src/cascadia/Remoting/Peasant.h @@ -15,13 +15,14 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation { struct AttachRequest : public AttachRequestT { - WINRT_PROPERTY(winrt::guid, ContentGuid); + WINRT_PROPERTY(winrt::hstring, Content); WINRT_PROPERTY(uint32_t, TabIndex); public: - AttachRequest(winrt::guid contentGuid, + AttachRequest(winrt::hstring content, uint32_t tabIndex) : - _ContentGuid{ contentGuid }, _TabIndex{ tabIndex } {}; + _Content{ content }, + _TabIndex{ tabIndex } {}; }; struct Peasant : public PeasantT @@ -44,7 +45,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation void RequestQuitAll(); void Quit(); - void AttachPaneToWindow(Remoting::AttachRequest request); + void AttachContentToWindow(Remoting::AttachRequest request); winrt::Microsoft::Terminal::Remoting::WindowActivatedArgs GetLastActivatedArgs(); diff --git a/src/cascadia/Remoting/Peasant.idl b/src/cascadia/Remoting/Peasant.idl index 588fe004ce1..6b3434f853e 100644 --- a/src/cascadia/Remoting/Peasant.idl +++ b/src/cascadia/Remoting/Peasant.idl @@ -53,7 +53,7 @@ namespace Microsoft.Terminal.Remoting } [default_interface] runtimeclass AttachRequest { - Guid ContentGuid { get; }; + String Content { get; }; UInt32 TabIndex { get; }; } @@ -82,7 +82,7 @@ namespace Microsoft.Terminal.Remoting void Quit(); String GetWindowLayout(); - void AttachPaneToWindow(AttachRequest request); + void AttachContentToWindow(AttachRequest request); event Windows.Foundation.TypedEventHandler WindowActivated; diff --git a/src/cascadia/Remoting/WindowManager.cpp b/src/cascadia/Remoting/WindowManager.cpp index 7d8dfff44c3..e7a67cfb34f 100644 --- a/src/cascadia/Remoting/WindowManager.cpp +++ b/src/cascadia/Remoting/WindowManager.cpp @@ -789,12 +789,12 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation return nullptr; } - winrt::fire_and_forget WindowManager::RequestMovePane(winrt::hstring window, - winrt::guid contentGuid, - uint32_t tabIndex) + winrt::fire_and_forget WindowManager::RequestMoveContent(winrt::hstring window, + winrt::hstring content, + uint32_t tabIndex) { co_await winrt::resume_background(); - _monarch.RequestMovePane(window, contentGuid, tabIndex); + _monarch.RequestMoveContent(window, content, tabIndex); } } diff --git a/src/cascadia/Remoting/WindowManager.h b/src/cascadia/Remoting/WindowManager.h index eb05d1dddef..e40ab8585ab 100644 --- a/src/cascadia/Remoting/WindowManager.h +++ b/src/cascadia/Remoting/WindowManager.h @@ -52,7 +52,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation void UpdateActiveTabTitle(winrt::hstring title); Windows::Foundation::Collections::IVector GetAllWindowLayouts(); - winrt::fire_and_forget RequestMovePane(winrt::hstring window, winrt::guid contentGuid, uint32_t tabIndex); + winrt::fire_and_forget RequestMoveContent(winrt::hstring window, winrt::hstring content, uint32_t tabIndex); TYPED_EVENT(FindTargetWindowRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::FindTargetWindowArgs); TYPED_EVENT(BecameMonarch, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable); diff --git a/src/cascadia/Remoting/WindowManager.idl b/src/cascadia/Remoting/WindowManager.idl index 047dabf777e..1d8f624aec8 100644 --- a/src/cascadia/Remoting/WindowManager.idl +++ b/src/cascadia/Remoting/WindowManager.idl @@ -25,7 +25,7 @@ namespace Microsoft.Terminal.Remoting Windows.Foundation.Collections.IVectorView GetPeasantInfos(); - void RequestMovePane(String window, Guid contentGuid, UInt32 tabIndex); + void RequestMoveContent(String window, String content, UInt32 tabIndex); event Windows.Foundation.TypedEventHandler FindTargetWindowRequested; event Windows.Foundation.TypedEventHandler BecameMonarch; diff --git a/src/cascadia/TerminalApp/AppLogic.cpp b/src/cascadia/TerminalApp/AppLogic.cpp index 85be1e92463..72fb6d3e6fc 100644 --- a/src/cascadia/TerminalApp/AppLogic.cpp +++ b/src/cascadia/TerminalApp/AppLogic.cpp @@ -1660,11 +1660,11 @@ namespace winrt::TerminalApp::implementation return _settings.GlobalSettings().CurrentTheme(); } - void AppLogic::AttachPane(winrt::guid contentGuid, uint32_t tabIndex) + void AppLogic::AttachContent(winrt::hstring content, uint32_t tabIndex) { if (_root) { - _root->AttachPane(contentGuid, tabIndex); + _root->AttachContent(content, tabIndex); } } } diff --git a/src/cascadia/TerminalApp/AppLogic.h b/src/cascadia/TerminalApp/AppLogic.h index 55cba2853d2..639a3811a81 100644 --- a/src/cascadia/TerminalApp/AppLogic.h +++ b/src/cascadia/TerminalApp/AppLogic.h @@ -124,7 +124,7 @@ namespace winrt::TerminalApp::implementation bool GetAlwaysShowNotificationIcon(); bool GetShowTitleInTitlebar(); - void AttachPane(winrt::guid contentGuid, uint32_t tabIndex); + void AttachContent(winrt::hstring content, uint32_t tabIndex); winrt::Windows::Foundation::IAsyncOperation ShowDialog(winrt::Windows::UI::Xaml::Controls::ContentDialog dialog); void DismissDialog(); @@ -224,7 +224,7 @@ namespace winrt::TerminalApp::implementation FORWARDED_TYPED_EVENT(QuitRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, QuitRequested); FORWARDED_TYPED_EVENT(ShowWindowChanged, Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Control::ShowWindowArgs, _root, ShowWindowChanged); - FORWARDED_TYPED_EVENT(RequestMovePane, Windows::Foundation::IInspectable, winrt::TerminalApp::RequestMovePaneArgs, _root, RequestMovePane); + FORWARDED_TYPED_EVENT(RequestMoveContent, Windows::Foundation::IInspectable, winrt::TerminalApp::RequestMoveContentArgs, _root, RequestMoveContent); #ifdef UNIT_TESTING friend class TerminalAppLocalTests::CommandlineTest; diff --git a/src/cascadia/TerminalApp/AppLogic.idl b/src/cascadia/TerminalApp/AppLogic.idl index 9d00e3edf3b..aba83e25cb9 100644 --- a/src/cascadia/TerminalApp/AppLogic.idl +++ b/src/cascadia/TerminalApp/AppLogic.idl @@ -110,7 +110,7 @@ namespace TerminalApp Microsoft.Terminal.Settings.Model.Theme Theme { get; }; FindTargetWindowResult FindTargetWindow(String[] args); - void AttachPane(Guid contentGuid, UInt32 tabIndex); + void AttachContent(String content, UInt32 tabIndex); Windows.Foundation.Collections.IMapView GlobalHotkeys(); @@ -140,7 +140,7 @@ namespace TerminalApp event Windows.Foundation.TypedEventHandler SystemMenuChangeRequested; event Windows.Foundation.TypedEventHandler ShowWindowChanged; - event Windows.Foundation.TypedEventHandler RequestMovePane; + event Windows.Foundation.TypedEventHandler RequestMoveContent; } } diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index ec9cbd6d4c9..bda373ff6c0 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -119,7 +119,7 @@ Pane::Pane(std::shared_ptr first, // - // Return Value: // - Arguments appropriate for a SplitPane or NewTab action -NewTerminalArgs Pane::GetTerminalArgsForPane() const +NewTerminalArgs Pane::GetTerminalArgsForPane(const bool asContent) const { // Leaves are the only things that have controls assert(_IsLeaf()); @@ -164,6 +164,11 @@ NewTerminalArgs Pane::GetTerminalArgsForPane() const // object. That would work for schemes set by the Terminal, but not ones set // by VT, but that seems good enough. + if (asContent) + { + args.ContentGuid(_control.ContentGuid()); + } + return args; } @@ -175,14 +180,15 @@ NewTerminalArgs Pane::GetTerminalArgsForPane() const // Arguments: // - currentId: the id to use for the current/first pane // - nextId: the id to use for a new pane if we split +// - asContent: TODO! // Return Value: // - The state from building the startup actions, includes a vector of commands, // the original root pane, the id of the focused pane, and the number of panes // created. -Pane::BuildStartupState Pane::BuildStartupActions(uint32_t currentId, uint32_t nextId) +Pane::BuildStartupState Pane::BuildStartupActions(uint32_t currentId, uint32_t nextId, const bool asContent) { // if we are a leaf then all there is to do is defer to the parent. - if (_IsLeaf()) + if (!asContent && _IsLeaf()) { if (_lastActive) { @@ -195,7 +201,7 @@ Pane::BuildStartupState Pane::BuildStartupActions(uint32_t currentId, uint32_t n auto buildSplitPane = [&](auto newPane) { ActionAndArgs actionAndArgs; actionAndArgs.Action(ShortcutAction::SplitPane); - const auto terminalArgs{ newPane->GetTerminalArgsForPane() }; + const auto terminalArgs{ newPane->GetTerminalArgsForPane(asContent) }; // When creating a pane the split size is the size of the new pane // and not position. const auto splitDirection = _splitState == SplitState::Horizontal ? SplitDirection::Down : SplitDirection::Right; @@ -205,6 +211,11 @@ Pane::BuildStartupState Pane::BuildStartupActions(uint32_t currentId, uint32_t n return actionAndArgs; }; + if (asContent && _IsLeaf()) + { + return { { buildSplitPane(shared_from_this()) }, shared_from_this(), currentId, 1 }; + } + auto buildMoveFocus = [](auto direction) { MoveFocusArgs args{ direction }; diff --git a/src/cascadia/TerminalApp/Pane.h b/src/cascadia/TerminalApp/Pane.h index 2c1fec243d6..e2df18160fe 100644 --- a/src/cascadia/TerminalApp/Pane.h +++ b/src/cascadia/TerminalApp/Pane.h @@ -91,8 +91,8 @@ class Pane : public std::enable_shared_from_this std::optional focusedPaneId; uint32_t panesCreated; }; - BuildStartupState BuildStartupActions(uint32_t currentId, uint32_t nextId); - winrt::Microsoft::Terminal::Settings::Model::NewTerminalArgs GetTerminalArgsForPane() const; + BuildStartupState BuildStartupActions(uint32_t currentId, uint32_t nextId, const bool asContent = false); + winrt::Microsoft::Terminal::Settings::Model::NewTerminalArgs GetTerminalArgsForPane(const bool asContent = false) const; void UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult& settings, const winrt::Microsoft::Terminal::Settings::Model::Profile& profile); diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index bd554b2a84d..e6869e19cf6 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -6,7 +6,7 @@ #include "TerminalPage.h" #include "TerminalPage.g.cpp" #include "RenameWindowRequestedArgs.g.cpp" -#include "RequestMovePaneArgs.g.cpp" +#include "RequestMoveContentArgs.g.cpp" #include @@ -1829,13 +1829,34 @@ namespace winrt::TerminalApp::implementation if (!windowId.empty()) { - if (const auto& control{ _GetActiveControl() }) + if (const auto terminalTab{ _GetFocusedTabImpl() }) + { - const auto currentContentGuid{ control.ContentGuid() }; - auto request = winrt::make_self(currentContentGuid, args); - _RequestMovePaneHandlers(*this, *request); - return true; + if (const auto pane{ terminalTab->GetActivePane() }) + + { + auto startupActions = pane->BuildStartupActions(0, 1, true); + auto winRtActions{ winrt::single_threaded_vector(std::move(startupActions.args)) }; + // Json::Value json{ Json::objectValue }; + // SetValueForKey(json, "content", winRtActions); + // Json::StreamWriterBuilder wbuilder; + // auto str = Json::writeString(wbuilder, json); + auto str = ActionAndArgs::Serialize(winRtActions); + auto request = winrt::make_self(args.Window(), + str, + args.TabIndex()); + _RequestMoveContentHandlers(*this, *request); + return true; + } } + + //if (const auto& control{ _GetActiveControl() }) + //{ + // const auto currentContentGuid{ control.ContentGuid() }; + // auto request = winrt::make_self(currentContentGuid, args); + // _RequestMovePaneHandlers(*this, *request); + // return true; + //} } // If we are trying to move from the current tab to the current tab do nothing. @@ -1868,47 +1889,55 @@ namespace winrt::TerminalApp::implementation return true; } - winrt::fire_and_forget TerminalPage::AttachPane(winrt::guid contentGuid, uint32_t tabIndex) + winrt::fire_and_forget TerminalPage::AttachContent(winrt::hstring content, uint32_t tabIndex) { - contentGuid; - tabIndex; - co_await winrt::resume_background(); - const auto contentProc = _AttachToContentProcess(contentGuid); - contentProc; + /* + { + contentGuid; + tabIndex; + co_await winrt::resume_background(); + const auto contentProc = _AttachToContentProcess(contentGuid); + contentProc; - Settings::Model::NewTerminalArgs newTerminalArgs{ nullptr }; - auto profile = _settings.GetProfileForArgs(newTerminalArgs); - auto controlSettings = TerminalSettings::CreateWithNewTerminalArgs(_settings, newTerminalArgs, *_bindings); + Settings::Model::NewTerminalArgs newTerminalArgs{ nullptr }; + auto profile = _settings.GetProfileForArgs(newTerminalArgs); + auto controlSettings = TerminalSettings::CreateWithNewTerminalArgs(_settings, newTerminalArgs, *_bindings); - co_await winrt::resume_foreground(Dispatcher()); + co_await winrt::resume_foreground(Dispatcher()); - auto newControl = _InitControl(controlSettings, contentProc.Guid()); - // Hookup our event handlers to the new terminal - _RegisterTerminalEvents(newControl); - auto resultPane = std::make_shared(profile, newControl); + auto newControl = _InitControl(controlSettings, contentProc.Guid()); + // Hookup our event handlers to the new terminal + _RegisterTerminalEvents(newControl); + auto resultPane = std::make_shared(profile, newControl); - _UnZoomIfNeeded(); + _UnZoomIfNeeded(); - uint32_t realIndex = std::min(tabIndex, _tabs.Size() - 1); - // if (_tabs.Size() > tabIndex) - // { - auto targetTab = _GetTerminalTabImpl(_tabs.GetAt(realIndex)); - targetTab->SplitPane(SplitDirection::Automatic, .5f, resultPane); + uint32_t realIndex = std::min(tabIndex, _tabs.Size() - 1); + // if (_tabs.Size() > tabIndex) + // { + auto targetTab = _GetTerminalTabImpl(_tabs.GetAt(realIndex)); + targetTab->SplitPane(SplitDirection::Automatic, .5f, resultPane); - // After GH#6586, the control will no longer focus itself - // automatically when it's finished being laid out. Manually focus - // the control here instead. - if (_startupState == StartupState::Initialized) - { - _GetActiveControl().Focus(FocusState::Programmatic); + // After GH#6586, the control will no longer focus itself + // automatically when it's finished being laid out. Manually focus + // the control here instead. + if (_startupState == StartupState::Initialized) + { + _GetActiveControl().Focus(FocusState::Programmatic); + } + // } + // else + // { + // realSplitType = tab.PreCalculateAutoSplit(availableSpace); + + // tab.SplitPane(realSplitType, splitSize, profile, newControl); + // } } - // } - // else - // { - // realSplitType = tab.PreCalculateAutoSplit(availableSpace); + */ - // tab.SplitPane(realSplitType, splitSize, profile, newControl); - // } + content; + tabIndex; + co_await wil::resume_foreground(Dispatcher()); } // Method Description: // - Split the focused pane either horizontally or vertically, and place the diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index ccb0a0c3907..3b0149285ad 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -8,7 +8,7 @@ #include "AppKeyBindings.h" #include "AppCommandlineArgs.h" #include "RenameWindowRequestedArgs.g.h" -#include "RequestMovePaneArgs.g.h" +#include "RequestMoveContentArgs.g.h" #include "Toast.h" #define DECLARE_ACTION_HANDLER(action) void _Handle##action(const IInspectable& sender, const Microsoft::Terminal::Settings::Model::ActionEventArgs& args); @@ -51,16 +51,17 @@ namespace winrt::TerminalApp::implementation _ProposedName{ name } {}; }; - struct RequestMovePaneArgs : RequestMovePaneArgsT + struct RequestMoveContentArgs : RequestMoveContentArgsT { - WINRT_PROPERTY(winrt::guid, ContentGuid); - WINRT_PROPERTY(Microsoft::Terminal::Settings::Model::MovePaneArgs, Args, nullptr); + WINRT_PROPERTY(winrt::hstring, Window); + WINRT_PROPERTY(winrt::hstring, Content); + WINRT_PROPERTY(uint32_t, TabIndex); public: - RequestMovePaneArgs(const winrt::guid& g, - Microsoft::Terminal::Settings::Model::MovePaneArgs args) : - _ContentGuid{ g }, - _Args{ args } {}; + RequestMoveContentArgs(const winrt::hstring window, const winrt::hstring content, uint32_t tabIndex) : + _Window{ window }, + _Content{ content }, + _TabIndex{ tabIndex } {}; }; struct PreparedContent @@ -157,7 +158,7 @@ namespace winrt::TerminalApp::implementation void OpenSettingsUI(); void WindowActivated(const bool activated); - winrt::fire_and_forget AttachPane(winrt::guid contentGuid, uint32_t tabIndex); + winrt::fire_and_forget AttachContent(winrt::hstring content, uint32_t tabIndex); WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); @@ -182,7 +183,7 @@ namespace winrt::TerminalApp::implementation TYPED_EVENT(QuitRequested, IInspectable, IInspectable); TYPED_EVENT(ShowWindowChanged, IInspectable, winrt::Microsoft::Terminal::Control::ShowWindowArgs) - TYPED_EVENT(RequestMovePane, Windows::Foundation::IInspectable, winrt::TerminalApp::RequestMovePaneArgs); + TYPED_EVENT(RequestMoveContent, Windows::Foundation::IInspectable, winrt::TerminalApp::RequestMoveContentArgs); WINRT_OBSERVABLE_PROPERTY(winrt::Windows::UI::Xaml::Media::Brush, TitlebarBrush, _PropertyChangedHandlers, nullptr); diff --git a/src/cascadia/TerminalApp/TerminalPage.idl b/src/cascadia/TerminalApp/TerminalPage.idl index be8289bd177..32a87bbecf5 100644 --- a/src/cascadia/TerminalApp/TerminalPage.idl +++ b/src/cascadia/TerminalApp/TerminalPage.idl @@ -10,10 +10,11 @@ namespace TerminalApp { String ProposedName { get; }; }; - [default_interface] runtimeclass RequestMovePaneArgs + [default_interface] runtimeclass RequestMoveContentArgs { - Microsoft.Terminal.Settings.Model.MovePaneArgs Args { get; }; - Guid ContentGuid { get; }; + String Window { get; }; + String Content { get; }; + UInt32 TabIndex { get; }; }; interface IDialogPresenter @@ -49,7 +50,7 @@ namespace TerminalApp String KeyboardServiceDisabledText { get; }; TaskbarState TaskbarState{ get; }; - void AttachPane(Guid contentGuid, UInt32 tabIndex); + void AttachContent(String content, UInt32 tabIndex); Windows.UI.Xaml.Media.Brush TitlebarBrush { get; }; void WindowActivated(Boolean activated); @@ -71,7 +72,7 @@ namespace TerminalApp event Windows.Foundation.TypedEventHandler OpenSystemMenu; event Windows.Foundation.TypedEventHandler ShowWindowChanged; - event Windows.Foundation.TypedEventHandler RequestMovePane; + event Windows.Foundation.TypedEventHandler RequestMoveContent; } } diff --git a/src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp b/src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp index 8591457e611..6fbf47e48ea 100644 --- a/src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp +++ b/src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp @@ -417,4 +417,14 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation const auto found = GeneratedActionNames.find(_Action); return found != GeneratedActionNames.end() ? found->second : L""; } + + winrt::hstring ActionAndArgs::Serialize(winrt::Windows::Foundation::Collections::IVector args) + { + Json::Value json{ Json::objectValue }; + JsonUtils::SetValueForKey(json, "actions", args); + Json::StreamWriterBuilder wbuilder; + auto str = Json::writeString(wbuilder, json); + return winrt::to_hstring(str); + } + } diff --git a/src/cascadia/TerminalSettingsModel/ActionAndArgs.h b/src/cascadia/TerminalSettingsModel/ActionAndArgs.h index 055bd1abcd0..b13f60ebc81 100644 --- a/src/cascadia/TerminalSettingsModel/ActionAndArgs.h +++ b/src/cascadia/TerminalSettingsModel/ActionAndArgs.h @@ -16,6 +16,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation std::vector& warnings); static Json::Value ToJson(const Model::ActionAndArgs& val); + static winrt::hstring Serialize(winrt::Windows::Foundation::Collections::IVector args); + ActionAndArgs() = default; ActionAndArgs(ShortcutAction action); ActionAndArgs(ShortcutAction action, IActionArgs args) : diff --git a/src/cascadia/TerminalSettingsModel/ActionArgs.h b/src/cascadia/TerminalSettingsModel/ActionArgs.h index 4c12551eace..45be57757d8 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.h +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.h @@ -281,6 +281,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation static constexpr std::string_view SuppressApplicationTitleKey{ "suppressApplicationTitle" }; static constexpr std::string_view ColorSchemeKey{ "colorScheme" }; static constexpr std::string_view ElevateKey{ "elevate" }; + static constexpr std::string_view ContentKey{ "__content" }; public: hstring GenerateName() const; @@ -299,7 +300,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation otherAsUs->_Profile == _Profile && otherAsUs->_SuppressApplicationTitle == _SuppressApplicationTitle && otherAsUs->_ColorScheme == _ColorScheme && - otherAsUs->_Elevate == _Elevate; + otherAsUs->_Elevate == _Elevate && + otherAsUs->_ContentGuid == _ContentGuid; } return false; }; @@ -316,6 +318,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation JsonUtils::GetValueForKey(json, SuppressApplicationTitleKey, args->_SuppressApplicationTitle); JsonUtils::GetValueForKey(json, ColorSchemeKey, args->_ColorScheme); JsonUtils::GetValueForKey(json, ElevateKey, args->_Elevate); + JsonUtils::GetValueForKey(json, ContentKey, args->_ContentGuid); return *args; } static Json::Value ToJson(const Model::NewTerminalArgs& val) @@ -335,6 +338,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation JsonUtils::SetValueForKey(json, SuppressApplicationTitleKey, args->_SuppressApplicationTitle); JsonUtils::SetValueForKey(json, ColorSchemeKey, args->_ColorScheme); JsonUtils::SetValueForKey(json, ElevateKey, args->_Elevate); + JsonUtils::SetValueForKey(json, ContentKey, args->_ContentGuid); return json; } Model::NewTerminalArgs Copy() const @@ -349,6 +353,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation copy->_SuppressApplicationTitle = _SuppressApplicationTitle; copy->_ColorScheme = _ColorScheme; copy->_Elevate = _Elevate; + copy->_ContentGuid = _ContentGuid; return *copy; } size_t Hash() const @@ -368,6 +373,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation h.write(SuppressApplicationTitle()); h.write(ColorScheme()); h.write(Elevate()); + h.write(ContentGuid()); } }; } diff --git a/src/cascadia/TerminalSettingsModel/ActionArgs.idl b/src/cascadia/TerminalSettingsModel/ActionArgs.idl index 7760cd20b4a..3d7ea66ec18 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.idl +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.idl @@ -132,7 +132,7 @@ namespace Microsoft.Terminal.Settings.Model // not modify whatever the profile's value is (either true or false) Windows.Foundation.IReference Elevate; - Guid ContentGuid{ get; }; + Guid ContentGuid{ get; set; }; Boolean Equals(NewTerminalArgs other); String GenerateName(); diff --git a/src/cascadia/TerminalSettingsModel/Command.idl b/src/cascadia/TerminalSettingsModel/Command.idl index b749a79fb0a..a223945f2cc 100644 --- a/src/cascadia/TerminalSettingsModel/Command.idl +++ b/src/cascadia/TerminalSettingsModel/Command.idl @@ -24,6 +24,8 @@ namespace Microsoft.Terminal.Settings.Model ActionAndArgs(); ActionAndArgs(ShortcutAction action, IActionArgs args); + static String Serialize(IVector args); + IActionArgs Args; ShortcutAction Action; }; diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp index e6d0a65e8a8..8e8b91d1035 100644 --- a/src/cascadia/WindowsTerminal/AppHost.cpp +++ b/src/cascadia/WindowsTerminal/AppHost.cpp @@ -332,7 +332,7 @@ void AppHost::_HandleCommandlineArgs() // TODO! add revoker peasant.AttachRequested([this](auto&&, Remoting::AttachRequest args) { - _logic.AttachPane(args.ContentGuid(), args.TabIndex()); + _logic.AttachContent(args.Content(), args.TabIndex()); }); _logic.WindowName(peasant.WindowName()); @@ -430,8 +430,9 @@ void AppHost::Initialize() _revokers.QuitRequested = _logic.QuitRequested(winrt::auto_revoke, { this, &AppHost::_RequestQuitAll }); _revokers.ShowWindowChanged = _logic.ShowWindowChanged(winrt::auto_revoke, { this, &AppHost::_ShowWindowChanged }); // TODO! revoker - _logic.RequestMovePane([this](auto&&, winrt::TerminalApp::RequestMovePaneArgs args) { - _windowManager.RequestMovePane(args.Args().Window(), args.ContentGuid(), args.Args().TabIndex()); + // TODO! move to member method + _logic.RequestMoveContent([this](auto&&, winrt::TerminalApp::RequestMoveContentArgs args) { + _windowManager.RequestMoveContent(args.Window(), args.Content(), args.TabIndex()); }); // BODGY