mirror of
https://github.com/microsoft/terminal.git
synced 2026-04-06 14:19:45 +00:00
Compare commits
1 Commits
dev/cazamo
...
dev/duhowe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ecb89e380d |
@@ -26,35 +26,23 @@ namespace winrt::TerminalApp::implementation
|
||||
const TerminalConnection::ITerminalConnection& connection)
|
||||
{
|
||||
ControlInteractivity content{ settings, unfocusedAppearance, connection };
|
||||
content.Closed({ get_weak(), &ContentManager::_closedHandler });
|
||||
|
||||
_content.emplace(content.Id(), content);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
ControlInteractivity ContentManager::TryLookupCore(uint64_t id)
|
||||
{
|
||||
const auto it = _content.find(id);
|
||||
return it != _content.end() ? it->second : ControlInteractivity{ nullptr };
|
||||
(void)id;
|
||||
return ControlInteractivity{ nullptr };
|
||||
}
|
||||
|
||||
void ContentManager::Detach(const Microsoft::Terminal::Control::TermControl& control)
|
||||
{
|
||||
const auto contentId{ control.ContentId() };
|
||||
if (const auto& content{ TryLookupCore(contentId) })
|
||||
{
|
||||
control.Detach();
|
||||
}
|
||||
(void)control;
|
||||
}
|
||||
|
||||
void ContentManager::_closedHandler(const winrt::Windows::Foundation::IInspectable& sender,
|
||||
const winrt::Windows::Foundation::IInspectable&)
|
||||
{
|
||||
if (const auto& content{ sender.try_as<winrt::Microsoft::Terminal::Control::ControlInteractivity>() })
|
||||
{
|
||||
const auto& contentId{ content.Id() };
|
||||
_content.erase(contentId);
|
||||
}
|
||||
(void)sender;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,8 +101,6 @@ namespace winrt::TerminalApp::implementation
|
||||
// - insertPosition: Optional parameter to indicate the position of tab.
|
||||
void TerminalPage::_InitializeTab(winrt::com_ptr<TerminalTab> newTabImpl, uint32_t insertPosition)
|
||||
{
|
||||
newTabImpl->Initialize();
|
||||
|
||||
// If insert position is not passed, calculate it
|
||||
if (insertPosition == -1)
|
||||
{
|
||||
@@ -211,6 +209,7 @@ namespace winrt::TerminalApp::implementation
|
||||
if (pane)
|
||||
{
|
||||
auto newTabImpl = winrt::make_self<TerminalTab>(pane);
|
||||
newTabImpl->Initialize();
|
||||
_InitializeTab(newTabImpl, insertPosition);
|
||||
return *newTabImpl;
|
||||
}
|
||||
@@ -443,7 +442,7 @@ namespace winrt::TerminalApp::implementation
|
||||
|
||||
// Removing the tab from the collection should destroy its control and disconnect its connection,
|
||||
// but it doesn't always do so. The UI tree may still be holding the control and preventing its destruction.
|
||||
tab.Shutdown();
|
||||
// DH TODO DH TODO tab.Shutdown();
|
||||
|
||||
uint32_t mruIndex{};
|
||||
if (_mruTabs.IndexOf(tab, mruIndex))
|
||||
|
||||
@@ -2112,8 +2112,8 @@ namespace winrt::TerminalApp::implementation
|
||||
{
|
||||
auto startupActions = pane->BuildStartupActions(0, 1, BuildStartupKind::MovePane);
|
||||
_DetachPaneFromWindow(pane);
|
||||
_MoveContent(std::move(startupActions.args), windowId, tabIdx);
|
||||
focusedTab->DetachPane();
|
||||
//_MoveContent(std::move(startupActions.args), windowId, tabIdx);
|
||||
|
||||
if (auto autoPeer = Automation::Peers::FrameworkElementAutomationPeer::FromElement(*this))
|
||||
{
|
||||
@@ -2214,15 +2214,13 @@ namespace winrt::TerminalApp::implementation
|
||||
// this.
|
||||
// - `actions` will be emptied into a winrt IVector as a part of this method
|
||||
// and should be expected to be empty after this call.
|
||||
void TerminalPage::_MoveContent(std::vector<Settings::Model::ActionAndArgs>&& actions,
|
||||
void TerminalPage::_MoveContent(const winrt::IInspectable& content,
|
||||
const winrt::hstring& windowName,
|
||||
const uint32_t tabIndex,
|
||||
const std::optional<winrt::Windows::Foundation::Point>& dragPoint)
|
||||
{
|
||||
const auto winRtActions{ winrt::single_threaded_vector<ActionAndArgs>(std::move(actions)) };
|
||||
const auto str{ ActionAndArgs::Serialize(winRtActions) };
|
||||
const auto request = winrt::make_self<RequestMoveContentArgs>(windowName,
|
||||
str,
|
||||
content,
|
||||
tabIndex);
|
||||
if (dragPoint.has_value())
|
||||
{
|
||||
@@ -2252,10 +2250,9 @@ namespace winrt::TerminalApp::implementation
|
||||
|
||||
if (tab)
|
||||
{
|
||||
auto startupActions = tab->BuildStartupActions(BuildStartupKind::Content);
|
||||
_DetachTabFromWindow(tab);
|
||||
_MoveContent(std::move(startupActions), windowId, 0);
|
||||
_RemoveTab(*tab);
|
||||
_MoveContent(tab.as<ITabBase>(), windowId, 0);
|
||||
if (auto autoPeer = Automation::Peers::FrameworkElementAutomationPeer::FromElement(*this))
|
||||
{
|
||||
const auto tabTitle = tab->Title();
|
||||
@@ -2334,51 +2331,17 @@ namespace winrt::TerminalApp::implementation
|
||||
// reattach instead of create new content, so this method simply needs to
|
||||
// parse the JSON and pump it into our action handler. Almost the same as
|
||||
// doing something like `wt -w 0 nt`.
|
||||
void TerminalPage::AttachContent(IVector<Settings::Model::ActionAndArgs> args, uint32_t tabIndex)
|
||||
void TerminalPage::AttachContent(const winrt::IInspectable& content, uint32_t tabIndex)
|
||||
{
|
||||
if (args == nullptr ||
|
||||
args.Size() == 0)
|
||||
if (!content)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& firstAction = args.GetAt(0);
|
||||
const bool firstIsSplitPane{ firstAction.Action() == ShortcutAction::SplitPane };
|
||||
|
||||
// `splitPane` allows the user to specify which tab to split. In that
|
||||
// case, split specifically the requested pane.
|
||||
//
|
||||
// If there's not enough tabs, then just turn this pane into a new tab.
|
||||
//
|
||||
// If the first action is `newTab`, the index is always going to be 0,
|
||||
// so don't do anything in that case.
|
||||
if (firstIsSplitPane && tabIndex < _tabs.Size())
|
||||
if (auto tab{ content.try_as<TabBase>() }; tab)
|
||||
{
|
||||
_SelectTab(tabIndex);
|
||||
}
|
||||
|
||||
for (const auto& action : args)
|
||||
{
|
||||
_actionDispatch->DoAction(action);
|
||||
}
|
||||
|
||||
// After handling all the actions, then re-check the tabIndex. We might
|
||||
// have been called as a part of a tab drag/drop. In that case, the
|
||||
// tabIndex is actually relevant, and we need to move the tab we just
|
||||
// made into position.
|
||||
if (!firstIsSplitPane && tabIndex != -1)
|
||||
{
|
||||
// Move the currently active tab to the requested index Use the
|
||||
// currently focused tab index, because we don't know if the new tab
|
||||
// opened at the end of the list, or adjacent to the previously
|
||||
// active tab. This is affected by the user's "newTabPosition"
|
||||
// setting.
|
||||
if (const auto focusedTabIndex = _GetFocusedTabIndex())
|
||||
{
|
||||
const auto source = *focusedTabIndex;
|
||||
_TryMoveTab(source, tabIndex);
|
||||
}
|
||||
// else: This shouldn't really be possible, because the tab we _just_ opened should be active.
|
||||
auto impl = _GetTerminalTabImpl(*tab);
|
||||
_InitializeTab(impl, tabIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5286,12 +5249,13 @@ namespace winrt::TerminalApp::implementation
|
||||
const uint32_t tabIndex,
|
||||
std::optional<winrt::Windows::Foundation::Point> dragPoint)
|
||||
{
|
||||
auto startupActions = _stashed.draggedTab->BuildStartupActions(BuildStartupKind::Content);
|
||||
ITabBase tab = *_stashed.draggedTab;
|
||||
|
||||
_DetachTabFromWindow(_stashed.draggedTab);
|
||||
|
||||
_MoveContent(std::move(startupActions), windowId, tabIndex, dragPoint);
|
||||
// _RemoveTab will make sure to null out the _stashed.draggedTab
|
||||
_RemoveTab(*_stashed.draggedTab);
|
||||
_MoveContent(tab, windowId, tabIndex, dragPoint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -57,12 +57,12 @@ namespace winrt::TerminalApp::implementation
|
||||
struct RequestMoveContentArgs : RequestMoveContentArgsT<RequestMoveContentArgs>
|
||||
{
|
||||
WINRT_PROPERTY(winrt::hstring, Window);
|
||||
WINRT_PROPERTY(winrt::hstring, Content);
|
||||
WINRT_PROPERTY(winrt::Windows::Foundation::IInspectable, Content);
|
||||
WINRT_PROPERTY(uint32_t, TabIndex);
|
||||
WINRT_PROPERTY(Windows::Foundation::IReference<Windows::Foundation::Point>, WindowPosition);
|
||||
|
||||
public:
|
||||
RequestMoveContentArgs(const winrt::hstring window, const winrt::hstring content, uint32_t tabIndex) :
|
||||
RequestMoveContentArgs(const winrt::hstring window, const winrt::Windows::Foundation::IInspectable& content, uint32_t tabIndex) :
|
||||
_Window{ window },
|
||||
_Content{ content },
|
||||
_TabIndex{ tabIndex } {};
|
||||
@@ -161,7 +161,7 @@ namespace winrt::TerminalApp::implementation
|
||||
|
||||
bool OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down);
|
||||
|
||||
void AttachContent(Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::ActionAndArgs> args, uint32_t tabIndex);
|
||||
void AttachContent(const winrt::Windows::Foundation::IInspectable& content, uint32_t tabIndex);
|
||||
void SendContentToOther(winrt::TerminalApp::RequestReceiveContentArgs args);
|
||||
|
||||
uint32_t NumberOfTabs() const;
|
||||
@@ -539,7 +539,7 @@ namespace winrt::TerminalApp::implementation
|
||||
|
||||
void _DetachPaneFromWindow(std::shared_ptr<Pane> pane);
|
||||
void _DetachTabFromWindow(const winrt::com_ptr<TabBase>& terminalTab);
|
||||
void _MoveContent(std::vector<winrt::Microsoft::Terminal::Settings::Model::ActionAndArgs>&& actions,
|
||||
void _MoveContent(const winrt::Windows::Foundation::IInspectable& content,
|
||||
const winrt::hstring& windowName,
|
||||
const uint32_t tabIndex,
|
||||
const std::optional<winrt::Windows::Foundation::Point>& dragPoint = std::nullopt);
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace TerminalApp
|
||||
[default_interface] runtimeclass RequestMoveContentArgs
|
||||
{
|
||||
String Window { get; };
|
||||
String Content { get; };
|
||||
Object Content { get; };
|
||||
UInt32 TabIndex { get; };
|
||||
Windows.Foundation.IReference<Windows.Foundation.Point> WindowPosition { get; };
|
||||
};
|
||||
|
||||
@@ -1253,7 +1253,7 @@ namespace winrt::TerminalApp::implementation
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TerminalWindow::AttachContent(winrt::hstring content, uint32_t tabIndex)
|
||||
void TerminalWindow::AttachContent(const winrt::IInspectable& content, uint32_t tabIndex)
|
||||
{
|
||||
if (_root)
|
||||
{
|
||||
@@ -1265,11 +1265,8 @@ namespace winrt::TerminalApp::implementation
|
||||
// If the first action is `newTab`, the index is always going to be 0,
|
||||
// so don't do anything in that case.
|
||||
|
||||
const bool replaceFirstWithNewTab = tabIndex >= _root->NumberOfTabs();
|
||||
|
||||
auto args = _contentStringToActions(content, replaceFirstWithNewTab);
|
||||
|
||||
_root->AttachContent(std::move(args), tabIndex);
|
||||
//const bool replaceFirstWithNewTab = tabIndex >= _root->NumberOfTabs();
|
||||
_root->AttachContent(content, tabIndex);
|
||||
}
|
||||
}
|
||||
void TerminalWindow::SendContentToOther(winrt::TerminalApp::RequestReceiveContentArgs args)
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace winrt::TerminalApp::implementation
|
||||
bool IsQuakeWindow() const noexcept { return _WindowProperties->IsQuakeWindow(); }
|
||||
TerminalApp::WindowProperties WindowProperties() { return *_WindowProperties; }
|
||||
|
||||
void AttachContent(winrt::hstring content, uint32_t tabIndex);
|
||||
void AttachContent(const winrt::Windows::Foundation::IInspectable& content, uint32_t tabIndex);
|
||||
void SendContentToOther(winrt::TerminalApp::RequestReceiveContentArgs args);
|
||||
|
||||
// -------------------------------- WinRT Events ---------------------------------
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace TerminalApp
|
||||
event Windows.Foundation.TypedEventHandler<Object, RequestReceiveContentArgs> RequestReceiveContent;
|
||||
event Windows.Foundation.TypedEventHandler<Object, LaunchPositionRequest> RequestLaunchPosition;
|
||||
|
||||
void AttachContent(String content, UInt32 tabIndex);
|
||||
void AttachContent(Object content, UInt32 tabIndex);
|
||||
void SendContentToOther(RequestReceiveContentArgs args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2720,6 +2720,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
void TermControl::Detach()
|
||||
{
|
||||
#if 0
|
||||
_revokers = {};
|
||||
|
||||
Control::ControlInteractivity old{ nullptr };
|
||||
@@ -2727,6 +2728,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
old.Detach();
|
||||
|
||||
_detached = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
|
||||
@@ -1317,7 +1317,7 @@ void AppHost::_handleMoveContent(const winrt::Windows::Foundation::IInspectable&
|
||||
}
|
||||
else
|
||||
{
|
||||
_windowManager->CreateNewWindow(winrt::TerminalApp::WindowRequestedArgs{ sanitizedWindowName, args.Content(), windowBoundsReference });
|
||||
//_windowManager->CreateNewWindow(winrt::TerminalApp::WindowRequestedArgs{ sanitizedWindowName, args.Content(), windowBoundsReference });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user