forked from microsoft/terminal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a ContentManager helper (microsoft#14851)
## Summary _Thus we come to the introduction of a new servant, the `ContentManager`, a singular entity that serves at the behest of the `emperor`. It is its charge to keep track of all `TermControl` instances created by the windows, for each window must seek its blessing before calling forth such an instance._ _With the aid of the `ContentManager`, the `TermControl` shall now be traced by the hand of fate through the use of unique identifying marks, known as `GUID`s. Yet, its purpose remains yet unknown, for it is merely a waypoint upon the journey yet to come._ _This act of bridging also brings a change to the handling of events within the `TermControl`. This change shall see the addition of a revoker, similar to the manner in which the `AppHost` hath employed it, to the `TermControl`. Additionally, there is a new layer of indirection between the `ControlCore` and the `App` layer, making ready for the day when the `TermControl` may be repositioned and re-parented with ease._ _Consider this but a trivial act, a mere shadow of things yet to come, for its impact shall be felt but briefly, like the passing of a gentle breeze._ Related to microsoft#5000 Related to microsoft#1256 # Detailed description This PR is another small bridge PR between the big work in microsoft#14843, and the PR that will enable panes to move between windows. This introduces a new class, called `ContentManager`. This is a global singleton object, owned by the emperor. Whenever a window wants to instantiate a new `TermControl`, it must ask the ContentManager to give it one. This allows the ContentManager to track each "content" by GUID. That's it. We don't do anything with them in this PR by itself, we just track them. This also includes a small change to the way TermControl events are handled. It adds an `AppHost`-like revoker struct, and weak_ref's all the handlers. We also add a layer of indirection between the ControlCore's raising of events and the App layer's handling. This will make reparenting content easier in the future. This is a pretty trivial change which shouldn't have any major side effects. Consider it exposition of the things to come. It's intentionally small to try and keep the reviews more managable.
- Loading branch information
1 parent
e0046a4
commit f3a722e
Showing
21 changed files
with
297 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#include "pch.h" | ||
#include "ContentManager.h" | ||
#include "ContentManager.g.cpp" | ||
|
||
#include <wil/token_helpers.h> | ||
|
||
#include "../../types/inc/utils.hpp" | ||
|
||
using namespace winrt::Windows::ApplicationModel; | ||
using namespace winrt::Windows::ApplicationModel::DataTransfer; | ||
using namespace winrt::Windows::UI::Xaml; | ||
using namespace winrt::Windows::UI::Xaml::Controls; | ||
using namespace winrt::Windows::UI::Core; | ||
using namespace winrt::Windows::System; | ||
using namespace winrt::Microsoft::Terminal; | ||
using namespace winrt::Microsoft::Terminal::Control; | ||
using namespace winrt::Microsoft::Terminal::Settings::Model; | ||
|
||
namespace winrt::TerminalApp::implementation | ||
{ | ||
ControlInteractivity ContentManager::CreateCore(const Microsoft::Terminal::Control::IControlSettings& settings, | ||
const IControlAppearance& unfocusedAppearance, | ||
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 ContentManager::_closedHandler(winrt::Windows::Foundation::IInspectable sender, | ||
winrt::Windows::Foundation::IInspectable e) | ||
{ | ||
if (const auto& content{ sender.try_as<winrt::Microsoft::Terminal::Control::ControlInteractivity>() }) | ||
{ | ||
const auto& contentId{ content.Id() }; | ||
_content.erase(contentId); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/*++ | ||
Copyright (c) Microsoft Corporation | ||
Licensed under the MIT license. | ||
Class Name: | ||
- ContentManager.h | ||
Abstract: | ||
- This is a helper class for tracking all of the terminal "content" instances of | ||
the Terminal. These are all the ControlInteractivity & ControlCore's of each | ||
of our TermControls. These are each assigned a GUID on creation, and stored in | ||
a map for later lookup. | ||
- This is used to enable moving panes between windows. TermControl's are not | ||
thread-agile, so they cannot be reused on other threads. However, the content | ||
is. This helper, which exists as a singleton across all the threads in the | ||
Terminal app, allows each thread to create content, assign it to a | ||
TermControl, detach it from that control, and reattach to new controls on | ||
other threads. | ||
- When you want to create a new TermControl, call CreateCore to instantiate a | ||
new content with a GUID for later reparenting. | ||
--*/ | ||
#pragma once | ||
|
||
#include "ContentManager.g.h" | ||
|
||
#include <inc/cppwinrt_utils.h> | ||
namespace winrt::TerminalApp::implementation | ||
{ | ||
struct ContentManager : ContentManagerT<ContentManager> | ||
{ | ||
public: | ||
ContentManager() = default; | ||
Microsoft::Terminal::Control::ControlInteractivity CreateCore(const Microsoft::Terminal::Control::IControlSettings& settings, | ||
const Microsoft::Terminal::Control::IControlAppearance& unfocusedAppearance, | ||
const Microsoft::Terminal::TerminalConnection::ITerminalConnection& connection); | ||
Microsoft::Terminal::Control::ControlInteractivity TryLookupCore(uint64_t id); | ||
|
||
private: | ||
std::unordered_map<uint64_t, Microsoft::Terminal::Control::ControlInteractivity> _content; | ||
|
||
void _closedHandler(winrt::Windows::Foundation::IInspectable sender, | ||
winrt::Windows::Foundation::IInspectable e); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.