Skip to content

Commit

Permalink
Serialize the pane to a Content string, instead of just the guid.
Browse files Browse the repository at this point in the history
There's a lot of renaming, signature changes here. But StartupActions is a good mechanism for passing panes around, more or less.
  • Loading branch information
zadjii-msft committed Jul 14, 2022
1 parent ac62de7 commit cfe879d
Show file tree
Hide file tree
Showing 23 changed files with 159 additions and 94 deletions.
16 changes: 9 additions & 7 deletions src/cascadia/Remoting/Monarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<implementation::AttachRequest>(contentGuid, tabIndex);
targetPeasant.AttachPaneToWindow(*request);
auto request = winrt::make_self<implementation::AttachRequest>(content, tabIndex);
targetPeasant.AttachContentToWindow(*request);
}
else
{ /*TODO! log */
{
/*TODO! log */
}
}
}
2 changes: 1 addition & 1 deletion src/cascadia/Remoting/Monarch.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
Windows::Foundation::Collections::IVectorView<winrt::Microsoft::Terminal::Remoting::PeasantInfo> GetPeasantInfos();
Windows::Foundation::Collections::IVector<winrt::hstring> 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);
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/Remoting/Monarch.idl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace Microsoft.Terminal.Remoting
Windows.Foundation.Collections.IVectorView<PeasantInfo> GetPeasantInfos { get; };
Windows.Foundation.Collections.IVector<String> GetAllWindowLayouts();

void RequestMovePane(String window, Guid contentGuid, UInt32 tabIndex);
void RequestMoveContent(String window, String content, UInt32 tabIndex);

event Windows.Foundation.TypedEventHandler<Object, FindTargetWindowArgs> FindTargetWindowRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> ShowNotificationIconRequested;
Expand Down
5 changes: 2 additions & 3 deletions src/cascadia/Remoting/Peasant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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));
}
Expand Down
9 changes: 5 additions & 4 deletions src/cascadia/Remoting/Peasant.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
{
struct AttachRequest : public AttachRequestT<AttachRequest>
{
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<Peasant>
Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/Remoting/Peasant.idl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace Microsoft.Terminal.Remoting
}

[default_interface] runtimeclass AttachRequest {
Guid ContentGuid { get; };
String Content { get; };
UInt32 TabIndex { get; };
}

Expand Down Expand Up @@ -82,7 +82,7 @@ namespace Microsoft.Terminal.Remoting
void Quit();
String GetWindowLayout();

void AttachPaneToWindow(AttachRequest request);
void AttachContentToWindow(AttachRequest request);


event Windows.Foundation.TypedEventHandler<Object, WindowActivatedArgs> WindowActivated;
Expand Down
8 changes: 4 additions & 4 deletions src/cascadia/Remoting/WindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
2 changes: 1 addition & 1 deletion src/cascadia/Remoting/WindowManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
void UpdateActiveTabTitle(winrt::hstring title);
Windows::Foundation::Collections::IVector<winrt::hstring> 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);
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/Remoting/WindowManager.idl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Microsoft.Terminal.Remoting

Windows.Foundation.Collections.IVectorView<PeasantInfo> GetPeasantInfos();

void RequestMovePane(String window, Guid contentGuid, UInt32 tabIndex);
void RequestMoveContent(String window, String content, UInt32 tabIndex);

event Windows.Foundation.TypedEventHandler<Object, FindTargetWindowArgs> FindTargetWindowRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> BecameMonarch;
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> ShowDialog(winrt::Windows::UI::Xaml::Controls::ContentDialog dialog);
void DismissDialog();
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/AppLogic.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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<Microsoft.Terminal.Control.KeyChord, Microsoft.Terminal.Settings.Model.Command> GlobalHotkeys();

Expand Down Expand Up @@ -140,7 +140,7 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<Object, TerminalApp.SystemMenuChangeArgs> SystemMenuChangeRequested;
event Windows.Foundation.TypedEventHandler<Object, Microsoft.Terminal.Control.ShowWindowArgs> ShowWindowChanged;

event Windows.Foundation.TypedEventHandler<Object, RequestMovePaneArgs> RequestMovePane;
event Windows.Foundation.TypedEventHandler<Object, RequestMoveContentArgs> RequestMoveContent;

}
}
19 changes: 15 additions & 4 deletions src/cascadia/TerminalApp/Pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Pane::Pane(std::shared_ptr<Pane> first,
// - <none>
// 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());
Expand Down Expand Up @@ -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;
}

Expand All @@ -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)
{
Expand All @@ -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;
Expand All @@ -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 };

Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/Pane.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class Pane : public std::enable_shared_from_this<Pane>
std::optional<uint32_t> 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);
Expand Down
Loading

0 comments on commit cfe879d

Please sign in to comment.