Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a ContentManager helper #14851

Merged
merged 149 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 145 commits
Commits
Show all changes
149 commits
Select commit Hold shift + click to select a range
581acd4
I definitely want all of this. But I started down a path for refactor…
zadjii-msft Jan 30, 2023
a5255ba
I don't think I want any of these
zadjii-msft Jan 30, 2023
e6220b7
Revert "I don't think I want any of these"
zadjii-msft Jan 30, 2023
936c01f
Start splitting AppLogic into AppLogic and Window logic
zadjii-msft Jan 30, 2023
439b21f
this is dangerously close to compiling
zadjii-msft Jan 30, 2023
99bc280
It doesn't crash on launch. That's something. There's no startupActio…
zadjii-msft Jan 31, 2023
2195515
it launches
zadjii-msft Jan 31, 2023
5116ca1
I think the todo's that are left, we can move on without them for now.
zadjii-msft Jan 31, 2023
ef7e2ed
Merge branch 'dev/migrie/oop/3/foreword' into dev/migrie/oop/3/ainuli…
zadjii-msft Jan 31, 2023
af14c2b
[TO PARENT] Move the page ctor call, so that it can happen after the …
zadjii-msft Jan 31, 2023
d456210
Use the single AppLogic for all windows. Remove the _app references. …
zadjii-msft Jan 31, 2023
f5b030c
it runs!
zadjii-msft Jan 31, 2023
2c4613a
wow it just... worked
zadjii-msft Feb 1, 2023
7a3e2e0
Start rewriting WindowManager to facilitate the new process model
zadjii-msft Feb 1, 2023
f655296
This does successfully get a window on the screen, which is pretty im…
zadjii-msft Feb 1, 2023
274d62d
it's working
zadjii-msft Feb 1, 2023
e623299
notes
zadjii-msft Feb 1, 2023
1b4f1ef
I literally think this is the whole thing
zadjii-msft Feb 1, 2023
47336c0
[ainulindale] Clean tear down the `App` when the process exits
zadjii-msft Feb 3, 2023
9924e23
[ainulindale] "fix" hot reload
zadjii-msft Feb 3, 2023
f06e484
[ainulindale] This I'm confident fixes some of the x-thread errors, b…
zadjii-msft Feb 7, 2023
2822c36
[ainulindale] Expand commands in the AppLogic, not on each page
zadjii-msft Feb 7, 2023
f27db59
Merge branch 'dev/migrie/oop/3/ainulindale' into dev/migrie/oop/3/val…
zadjii-msft Feb 7, 2023
2332f0c
Don't try to snap on create if we're not prepared to snap
zadjii-msft Feb 8, 2023
4e7da2e
I guess this is just dead now
zadjii-msft Feb 8, 2023
23c4d4c
Move the initialization of the showHide Throttler after we init the d…
zadjii-msft Feb 8, 2023
761bd6a
This one was dead code, 34 TODOs left
zadjii-msft Feb 8, 2023
93e9dc5
I guess we need to just hardcode these sizes. Sad, but okay.
zadjii-msft Feb 8, 2023
d5396d1
UWP is dead
zadjii-msft Feb 8, 2023
07ff418
Plumb initial load result into the window on startup
zadjii-msft Feb 8, 2023
40fdbc1
Hey this comment was TODOne, 29 TODOs left
zadjii-msft Feb 8, 2023
4db381e
not totally happy with this, but I understand why. 29 TODOs left
zadjii-msft Feb 8, 2023
64257d8
This straight up isn't even used in main anymore, 26 TODOs left
zadjii-msft Feb 8, 2023
3026922
Fix the window name not updating as it changed. Added some notes, so,…
zadjii-msft Feb 8, 2023
84e228f
Start to move window restoration into the Emperor
zadjii-msft Feb 8, 2023
dc1ae9a
Starting to move these things to the right places
zadjii-msft Feb 8, 2023
8bb8391
move more window persist code around.
zadjii-msft Feb 8, 2023
0f4c4d8
It persists, but it doesn't restore yet.
zadjii-msft Feb 8, 2023
a5a9930
Hey look I brought two windows back into existence!...
zadjii-msft Feb 8, 2023
6e6d14e
We're getting closer to loading up the previous state, but it doesn't…
zadjii-msft Feb 8, 2023
3fb8e8c
Hey this worked!
zadjii-msft Feb 8, 2023
4d5f6d2
cleanup. 18 TODOs remain
zadjii-msft Feb 8, 2023
a7379ca
It so SO works
zadjii-msft Feb 9, 2023
0b79e81
Summoning works, except for making new windows, but DANG
zadjii-msft Feb 9, 2023
950ce6c
make pane brushes a member variable, which is good enough
zadjii-msft Feb 7, 2023
055da35
Readd ShouldImmediatelyHandoffToElevated
zadjii-msft Feb 9, 2023
b0726c2
Handle Quit actions
zadjii-msft Feb 9, 2023
e214624
Re-add support for the notification icon.
zadjii-msft Feb 9, 2023
c69f0bc
Quake logic seems to work again.
zadjii-msft Feb 9, 2023
7e91bdb
This actually seems to make the lifetime management worse - we just d…
zadjii-msft Feb 9, 2023
0395dc4
Revert "This actually seems to make the lifetime management worse - w…
zadjii-msft Feb 9, 2023
f904e5d
I give up and am moving on to the next TODOs. 8 TODOs remain
zadjii-msft Feb 10, 2023
4548729
Some additional cleanup of the WindowManager code
zadjii-msft Feb 10, 2023
7660937
and with that, we're ready to cleanup for review.
zadjii-msft Feb 10, 2023
0ad5b59
I think it's ready for review
zadjii-msft Feb 10, 2023
cfa6108
Merge remote-tracking branch 'origin/main' into dev/migrie/oop/3/fore…
zadjii-msft Feb 10, 2023
e40575b
let's do it
zadjii-msft Feb 10, 2023
dffb416
Merge branch 'dev/migrie/oop/3/foreword' into dev/migrie/oop/3/ainuli…
zadjii-msft Feb 10, 2023
a769933
merges are hard some times
zadjii-msft Feb 10, 2023
c065897
Merge branch 'dev/migrie/oop/3/ainulindale' into dev/migrie/oop/3/val…
zadjii-msft Feb 11, 2023
33685d9
bwahahahahaha
zadjii-msft Feb 13, 2023
a4f19a9
spel
zadjii-msft Feb 13, 2023
1ec8c0d
Merge branch 'dev/migrie/oop/3/foreword' into dev/migrie/oop/3/ainuli…
zadjii-msft Feb 13, 2023
2621519
cleanup for review
zadjii-msft Feb 13, 2023
603a2ce
spel
zadjii-msft Feb 13, 2023
a9ac218
runformat
zadjii-msft Feb 13, 2023
82224bc
this was usnused
zadjii-msft Feb 13, 2023
d9d4d2e
get the tests to build, at least
zadjii-msft Feb 13, 2023
3f9deca
Merge branch 'dev/migrie/oop/3/foreword' into dev/migrie/oop/3/ainuli…
zadjii-msft Feb 13, 2023
0f0316f
Merge branch 'dev/migrie/oop/3/ainulindale' into dev/migrie/oop/3/val…
zadjii-msft Feb 13, 2023
7734600
[valaquenta] Lifetime manage controls
zadjii-msft Feb 13, 2023
2873511
Don't add multiple event handlers for the core
zadjii-msft Feb 7, 2023
855a79d
Add auto_revokers to all TermControl ev handlers, but that wasn't wha…
zadjii-msft Feb 7, 2023
4b22963
notes
zadjii-msft Feb 14, 2023
d06ad8b
spel
zadjii-msft Feb 14, 2023
118bffa
fix the tests
zadjii-msft Feb 14, 2023
aa8b0c5
Merge branch 'dev/migrie/oop/3/foreword' into dev/migrie/oop/3/ainuli…
zadjii-msft Feb 14, 2023
bc80943
the tests all...pass?
zadjii-msft Feb 14, 2023
667b658
I'm committing everything just in case, but I'm gonna revert and just…
zadjii-msft Feb 15, 2023
2bc578b
Revert "I'm committing everything just in case, but I'm gonna revert …
zadjii-msft Feb 15, 2023
62a4ee0
https://media.tenor.com/knFWHfkiwoUAAAAC/im-fine-hades.gif
zadjii-msft Feb 15, 2023
091f32c
a comment to go with the parent commit
zadjii-msft Feb 15, 2023
ecab57f
that was quite silly
zadjii-msft Feb 16, 2023
13257da
0 TODOs remain
zadjii-msft Feb 16, 2023
f9caf19
Merge branch 'dev/migrie/oop/3/ainulindale' into dev/migrie/oop/3/val…
zadjii-msft Feb 16, 2023
9a47396
[ainulindale] The Terminal shouldn't crash on a WM_SETTINGCHANGE
zadjii-msft Feb 23, 2023
273f2a8
Merge remote-tracking branch 'origin/main' into dev/migrie/oop/3/fore…
zadjii-msft Feb 23, 2023
c79f27c
std::vectors are better
zadjii-msft Feb 27, 2023
b75fb24
Merge branch 'dev/migrie/oop/3/foreword' into dev/migrie/oop/3/ainuli…
zadjii-msft Feb 27, 2023
cacb822
Dustin wanted a setting to opt-in to isolated mode, and this seems to…
zadjii-msft Feb 27, 2023
6934bc8
Merge branch 'dev/migrie/oop/3/ainulindale' into dev/migrie/oop/3/val…
zadjii-msft Feb 27, 2023
b589d09
Lots of PR nits
zadjii-msft Feb 28, 2023
0199aba
the last nits, I think
zadjii-msft Feb 28, 2023
5e23a72
Merge branch 'dev/migrie/oop/3/foreword' into dev/migrie/oop/3/ainuli…
zadjii-msft Feb 28, 2023
ada3f42
well that is an underwhelming codeformat commit. Thanks VS
zadjii-msft Feb 28, 2023
5164bff
hey that's a good point carlos
zadjii-msft Feb 28, 2023
7e2eb0d
Apply suggestions from code review
zadjii-msft Mar 2, 2023
5c852c3
some smaller nits
zadjii-msft Mar 2, 2023
1e331a0
Merge branch 'dev/migrie/oop/3/ainulindale' of https://github.com/mic…
zadjii-msft Mar 2, 2023
8e2c7a7
some cleanup
zadjii-msft Mar 2, 2023
08f6a53
This is gross but reduces the number of redundant copies of these bru…
zadjii-msft Mar 2, 2023
8803324
spelling is hard
zadjii-msft Mar 2, 2023
b983c69
Merge branch 'dev/migrie/oop/3/foreword' into dev/migrie/oop/3/ainuli…
zadjii-msft Mar 2, 2023
48aa555
Merge branch 'dev/migrie/oop/3/ainulindale' into dev/migrie/oop/3/val…
zadjii-msft Mar 2, 2023
3aa083b
sure. It doesn't matter'
zadjii-msft Mar 2, 2023
9a9fa43
[ainulindale] Prevent a race between the Emperor and the window logic…
zadjii-msft Mar 6, 2023
11ef8ef
Merge branch 'dev/migrie/oop/3/ainulindale' into dev/migrie/oop/3/val…
zadjii-msft Mar 6, 2023
b24cf61
some of the more minor cleanup elements
zadjii-msft Mar 7, 2023
3fa1017
one fewer IReference, thank gods
zadjii-msft Mar 7, 2023
5fe3fa5
some cleanup around expanding commands
zadjii-msft Mar 8, 2023
b0ca581
.detach so we don't std::explode()
zadjii-msft Mar 8, 2023
74af809
mmmm fresh cut code
zadjii-msft Mar 8, 2023
547b2c9
you never get used either
zadjii-msft Mar 8, 2023
6f6880c
this is more idomatic locking cause it's actually locking
zadjii-msft Mar 8, 2023
1dc2436
weak refs for fun and profit
zadjii-msft Mar 8, 2023
6e4b2e1
Guess what's LOAD BEARING
zadjii-msft Mar 9, 2023
7721813
pr nits
zadjii-msft Mar 9, 2023
6dead99
PR nits
zadjii-msft Mar 9, 2023
434abc2
Remove the need for TerminalPage to know the number of open windows
zadjii-msft Mar 9, 2023
1b59eb9
save this for later, we should only need ot look it up once
zadjii-msft Mar 9, 2023
39a9450
to wit, also make sure that there is a tablayout
zadjii-msft Mar 9, 2023
44b238e
Redo how ownership of WindowProperties works. This is cleaner by a go…
zadjii-msft Mar 9, 2023
073350e
fix the tests too
zadjii-msft Mar 10, 2023
ca511c9
this is why I don't use VS
zadjii-msft Mar 10, 2023
f70775a
I don't trust you phyllis
zadjii-msft Mar 10, 2023
81140a5
Merge branch 'dev/migrie/oop/3/foreword' into dev/migrie/oop/3/ainuli…
zadjii-msft Mar 10, 2023
339972e
tests build and pass again
zadjii-msft Mar 10, 2023
6d04353
yea we can fold this in
zadjii-msft Mar 10, 2023
1138416
hey let's make sure it still works
zadjii-msft Mar 10, 2023
9957e5c
I think that's the last of the nits
zadjii-msft Mar 10, 2023
c8ce5b4
Merge branch 'dev/migrie/oop/3/ainulindale' into dev/migrie/oop/3/val…
zadjii-msft Mar 10, 2023
6aec80b
A hotfix for the selfhost build
zadjii-msft Mar 13, 2023
9316f5b
These are pretty minor for what is a pretty minor PR
zadjii-msft Mar 13, 2023
0808f94
Merge remote-tracking branch 'origin/main' into dev/migrie/oop/3/fore…
zadjii-msft Mar 17, 2023
5b3dc08
last nits, let's do this
zadjii-msft Mar 17, 2023
59b07f1
Merge branch 'dev/migrie/oop/3/foreword' into dev/migrie/oop/3/ainuli…
zadjii-msft Mar 17, 2023
7142ae8
[ainulindale] fix defterm
zadjii-msft Mar 16, 2023
d55bb43
[ainulindale] windows should get activated when they're created
zadjii-msft Mar 16, 2023
11f9957
[ainulindale] Friendship ended with callbacks
zadjii-msft Mar 17, 2023
55ee49b
Merge remote-tracking branch 'origin/main' into dev/migrie/oop/3/ainu…
zadjii-msft Mar 17, 2023
fe2ee91
Merge remote-tracking branch 'origin/dev/migrie/oop/3/ainulindale' in…
zadjii-msft Mar 17, 2023
1e4cc33
Merge remote-tracking branch 'origin/main' into dev/migrie/oop/3/ainu…
zadjii-msft Mar 17, 2023
5a420d8
Merge remote-tracking branch 'origin/dev/migrie/oop/3/ainulindale' in…
zadjii-msft Mar 20, 2023
24da827
Merge branch 'main' into dev/migrie/oop/3/valaquenta
zadjii-msft Mar 20, 2023
b02b935
easier nits
zadjii-msft Mar 21, 2023
f73ec9a
fix the tests
zadjii-msft Mar 21, 2023
3659744
why not just use uints?
zadjii-msft Mar 21, 2023
3af4d94
I don't know how to stl
zadjii-msft Mar 21, 2023
697b420
notes from PR
zadjii-msft Mar 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ namespace winrt::TerminalApp::implementation
warnings,
_settings);

auto window = winrt::make_self<implementation::TerminalWindow>(*ev);
auto window = winrt::make_self<implementation::TerminalWindow>(*ev, _contentManager);

this->SettingsChanged({ window->get_weak(), &implementation::TerminalWindow::UpdateSettingsHandler });
if (_hasSettingsStartupActions)
Expand All @@ -731,6 +731,11 @@ namespace winrt::TerminalApp::implementation
return *window;
}

winrt::TerminalApp::ContentManager AppLogic::ContentManager()
{
return _contentManager;
}

bool AppLogic::ShouldUsePersistedLayout() const
{
return _settings.GlobalSettings().ShouldUsePersistedLayout();
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "LanguageProfileNotifier.h"
#include "AppCommandlineArgs.h"
#include "TerminalWindow.h"
#include "ContentManager.h"

#include <inc/cppwinrt_utils.h>
#include <ThrottledFunc.h>
Expand Down Expand Up @@ -70,6 +71,8 @@ namespace winrt::TerminalApp::implementation

TerminalApp::TerminalWindow CreateNewWindow();

winrt::TerminalApp::ContentManager ContentManager();

TerminalApp::ParseCommandlineResult GetParseCommandlineMessage(array_view<const winrt::hstring> args);

TYPED_EVENT(SettingsChanged, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::SettingsLoadEventArgs);
Expand Down Expand Up @@ -98,6 +101,8 @@ namespace winrt::TerminalApp::implementation
winrt::com_ptr<LanguageProfileNotifier> _languageProfileNotifier;
wil::unique_folder_change_reader_nothrow _reader;

TerminalApp::ContentManager _contentManager{ *winrt::make_self<implementation::ContentManager>() };
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved

static TerminalApp::FindTargetWindowResult _doFindTargetWindow(winrt::array_view<const hstring> args,
const Microsoft::Terminal::Settings::Model::WindowingMode& windowingBehavior);

Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.idl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace TerminalApp
Boolean IsRunningElevated();
Boolean CanDragDrop();

ContentManager ContentManager { get; };

Boolean HasSettingsStartupActions();

Boolean ShouldUsePersistedLayout();
Expand Down
53 changes: 53 additions & 0 deletions src/cascadia/TerminalApp/ContentManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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
{
namespace MUX = Microsoft::UI::Xaml;
using IInspectable = Windows::Foundation::IInspectable;
}
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
namespace winrt::TerminalApp::implementation
{
ControlInteractivity ContentManager::CreateCore(Microsoft::Terminal::Control::IControlSettings settings,
IControlAppearance unfocusedAppearance,
TerminalConnection::ITerminalConnection connection)
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
{
auto content = ControlInteractivity{ settings, unfocusedAppearance, connection };
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
content.Closed({ get_weak(), &ContentManager::_closedHandler });
Copy link
Member

@DHowett DHowett Mar 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qq on weak: is the content manager going away after before the control a real concern?

Copy link
Member

@lhecker lhecker Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But is there any benefit to using this over get_weak() in our UI code? Because get_weak() does have the benefit of being safer to use if lifetimes aren't easily visible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm cool with leaning towards safety here. Who knows, maybe there's a "the window closes, so we start tearing down, but the controls only get released after the rest of the app does" situation. I suppose that's covered by our PeekMessage loop in App::Close, but still, this can't hurt, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's all fair; there is some overhead inherent in get_weak, mostly the construction and maintenance of a proxy weak ref object and the need to resolve the weak every time it's dispatched... but that is likely to be small.

_content.insert(std::make_pair(content.Id(), content));
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
return content;
}

ControlInteractivity ContentManager::LookupCore(winrt::guid id)
{
return _content.at(id);
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
}

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& contentGuid{ content.Id() };
_content.erase(contentGuid);
}
}
}
44 changes: 44 additions & 0 deletions src/cascadia/TerminalApp/ContentManager.h
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(Microsoft::Terminal::Control::IControlSettings settings,
Microsoft::Terminal::Control::IControlAppearance unfocusedAppearance,
Microsoft::Terminal::TerminalConnection::ITerminalConnection connection);
Microsoft::Terminal::Control::ControlInteractivity LookupCore(winrt::guid id);

private:
std::unordered_map<winrt::guid, Microsoft::Terminal::Control::ControlInteractivity> _content;

void _closedHandler(winrt::Windows::Foundation::IInspectable sender,
winrt::Windows::Foundation::IInspectable e);
};
}
6 changes: 6 additions & 0 deletions src/cascadia/TerminalApp/TerminalAppLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@
<ClInclude Include="AppLogic.h">
<DependentUpon>AppLogic.idl</DependentUpon>
</ClInclude>
<ClInclude Include="ContentManager.h">
<DependentUpon>TerminalPage.idl</DependentUpon>
</ClInclude>
<ClInclude Include="TerminalWindow.h">
<DependentUpon>TerminalWindow.idl</DependentUpon>
</ClInclude>
Expand Down Expand Up @@ -237,6 +240,9 @@
<ClCompile Include="AppLogic.cpp">
<DependentUpon>AppLogic.idl</DependentUpon>
</ClCompile>
<ClCompile Include="ContentManager.cpp">
<DependentUpon>TerminalPage.idl</DependentUpon>
</ClCompile>
<ClCompile Include="TerminalWindow.cpp">
<DependentUpon>TerminalWindow.idl</DependentUpon>
</ClCompile>
Expand Down
8 changes: 6 additions & 2 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ namespace winrt

namespace winrt::TerminalApp::implementation
{
TerminalPage::TerminalPage(TerminalApp::WindowProperties properties) :
TerminalPage::TerminalPage(TerminalApp::WindowProperties properties, const TerminalApp::ContentManager& manager) :
_tabs{ winrt::single_threaded_observable_vector<TerminalApp::TabBase>() },
_mruTabs{ winrt::single_threaded_observable_vector<TerminalApp::TabBase>() },
_startupActions{ winrt::single_threaded_vector<ActionAndArgs>() },
_manager{ manager },
_hostingHwnd{},
_WindowProperties{ std::move(properties) }
{
Expand Down Expand Up @@ -2593,7 +2594,10 @@ namespace winrt::TerminalApp::implementation
// Do any initialization that needs to apply to _every_ TermControl we
// create here.
// TermControl will copy the settings out of the settings passed to it.
TermControl term{ settings.DefaultSettings(), settings.UnfocusedSettings(), connection };

const auto content = _manager.CreateCore(settings.DefaultSettings(), settings.UnfocusedSettings(), connection);

TermControl term{ content };

// GH#12515: ConPTY assumes it's hidden at the start. If we're not, let it know now.
if (_visible)
Expand Down
5 changes: 3 additions & 2 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace winrt::TerminalApp::implementation
struct TerminalPage : TerminalPageT<TerminalPage>
{
public:
TerminalPage(TerminalApp::WindowProperties properties);
TerminalPage(TerminalApp::WindowProperties properties, const TerminalApp::ContentManager& manager);

// This implements shobjidl's IInitializeWithWindow, but due to a XAML Compiler bug we cannot
// put it in our inheritance graph. https://github.com/microsoft/microsoft-ui-xaml/issues/3331
Expand Down Expand Up @@ -224,9 +224,10 @@ namespace winrt::TerminalApp::implementation
bool _renamerPressedEnter{ false };

TerminalApp::WindowProperties _WindowProperties{ nullptr };

PaneResources _paneResources;

TerminalApp::ContentManager _manager{ nullptr };

winrt::Microsoft::Terminal::TerminalConnection::ConptyConnection::NewConnection_revoker _newConnectionRevoker;

winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowDialogHelper(const std::wstring_view& name);
Expand Down
12 changes: 11 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.idl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import "IDirectKeyListener.idl";
namespace TerminalApp
{

// See IDialogPresenter and TerminalPage's DialogPresenter for more
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
// information.
[default_interface] runtimeclass ContentManager
{
Microsoft.Terminal.Control.ControlInteractivity CreateCore(Microsoft.Terminal.Control.IControlSettings settings,
Microsoft.Terminal.Control.IControlAppearance unfocusedAppearance,
Microsoft.Terminal.TerminalConnection.ITerminalConnection connection);
Microsoft.Terminal.Control.ControlInteractivity LookupCore(Guid id);
}

[default_interface] runtimeclass LastTabClosedEventArgs
{
Boolean ClearPersistedState { get; };
Expand Down Expand Up @@ -33,7 +43,7 @@ namespace TerminalApp

[default_interface] runtimeclass TerminalPage : Windows.UI.Xaml.Controls.Page, Windows.UI.Xaml.Data.INotifyPropertyChanged, IDirectKeyListener
{
TerminalPage(WindowProperties properties);
TerminalPage(WindowProperties properties, ContentManager manager);

// XAML bound properties
String ApplicationDisplayName { get; };
Expand Down
6 changes: 4 additions & 2 deletions src/cascadia/TerminalApp/TerminalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ static Documents::Run _BuildErrorRun(const winrt::hstring& text, const ResourceD

namespace winrt::TerminalApp::implementation
{
TerminalWindow::TerminalWindow(const TerminalApp::SettingsLoadEventArgs& settingsLoadedResult) :
TerminalWindow::TerminalWindow(const TerminalApp::SettingsLoadEventArgs& settingsLoadedResult,
const TerminalApp::ContentManager& manager) :
_settings{ settingsLoadedResult.NewSettings() },
_manager{ manager },
_initialLoadResult{ settingsLoadedResult },
_WindowProperties{ winrt::make_self<TerminalApp::implementation::WindowProperties>() }
{
Expand All @@ -138,7 +140,7 @@ namespace winrt::TerminalApp::implementation
HRESULT TerminalWindow::Initialize(HWND hwnd)
{
// Now that we know we can do XAML, build our page.
_root = winrt::make_self<TerminalPage>(*_WindowProperties);
_root = winrt::make_self<TerminalPage>(*_WindowProperties, _manager);
_dialog = ContentDialog{};

// Pass commandline args into the TerminalPage. If we were supposed to
Expand Down
4 changes: 3 additions & 1 deletion src/cascadia/TerminalApp/TerminalWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace winrt::TerminalApp::implementation
struct TerminalWindow : TerminalWindowT<TerminalWindow, IInitializeWithWindow>
{
public:
TerminalWindow(const TerminalApp::SettingsLoadEventArgs& settingsLoadedResult);
TerminalWindow(const TerminalApp::SettingsLoadEventArgs& settingsLoadedResult, const TerminalApp::ContentManager& manager);
~TerminalWindow() = default;

STDMETHODIMP Initialize(HWND hwnd);
Expand Down Expand Up @@ -177,6 +177,8 @@ namespace winrt::TerminalApp::implementation
Microsoft::Terminal::Settings::Model::CascadiaSettings _settings{ nullptr };
TerminalApp::SettingsLoadEventArgs _initialLoadResult{ nullptr };

TerminalApp::ContentManager _manager{ nullptr };

void _ShowLoadErrorsDialog(const winrt::hstring& titleKey,
const winrt::hstring& contentKey,
HRESULT settingsLoadedResult,
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/TerminalWindow.idl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace TerminalApp
// information.
[default_interface] runtimeclass TerminalWindow : IDirectKeyListener, IDialogPresenter, Windows.UI.Xaml.Data.INotifyPropertyChanged
{
TerminalWindow(SettingsLoadEventArgs result);
TerminalWindow(SettingsLoadEventArgs result, ContentManager manager);

// For your own sanity, it's better to do setup outside the ctor.
// If you do any setup in the ctor that ends up throwing an exception,
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalControl/ControlCore.idl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ namespace Microsoft.Terminal.Control
String HoveredUriText { get; };
Windows.Foundation.IReference<Microsoft.Terminal.Core.Point> HoveredCell { get; };

void Close();
void BlinkCursor();
Boolean IsInReadOnlyMode { get; };
Boolean CursorOn;
Expand Down
16 changes: 16 additions & 0 deletions src/cascadia/TerminalControl/ControlInteractivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_lastMouseClickPos{},
_selectionNeedsToBeCopied{ false }
{
_guid = ::Microsoft::Console::Utils::CreateGuid();
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved

_core = winrt::make_self<ControlCore>(settings, unfocusedAppearance, connection);
}

winrt::guid ControlInteractivity::Id()
{
return _guid;
}

// Method Description:
// - Updates our internal settings. These settings should be
// interactivity-specific. Right now, we primarily update _rowsToScroll
Expand All @@ -73,6 +80,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return *_core;
}

void ControlInteractivity::Close()
{
_ClosedHandlers(*this, nullptr);
if (_core)
{
_core->Close();
}
}

// Method Description:
// - Returns the number of clicks that occurred (double and triple click support).
// Every call to this function registers a click.
Expand Down
8 changes: 8 additions & 0 deletions src/cascadia/TerminalControl/ControlInteractivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void Initialize();
Control::ControlCore Core();

void Close();

Control::InteractivityAutomationPeer OnCreateAutomationPeer();
::Microsoft::Console::Render::IRenderData* GetRenderData() const;

Expand Down Expand Up @@ -85,11 +87,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void SetEndSelectionPoint(const Core::Point pixelPosition);
bool ManglePathsForWsl();

winrt::guid Id();

TYPED_EVENT(OpenHyperlink, IInspectable, Control::OpenHyperlinkEventArgs);
TYPED_EVENT(PasteFromClipboard, IInspectable, Control::PasteFromClipboardEventArgs);
TYPED_EVENT(ScrollPositionChanged, IInspectable, Control::ScrollPositionChangedArgs);
TYPED_EVENT(ContextMenuRequested, IInspectable, Control::ContextMenuRequestedEventArgs);

TYPED_EVENT(Closed, IInspectable, IInspectable);

private:
// NOTE: _uiaEngine must be ordered before _core.
//
Expand Down Expand Up @@ -130,6 +136,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation

std::optional<interval_tree::IntervalTree<til::point, size_t>::interval> _lastHoveredInterval{ std::nullopt };

winrt::guid _guid;

unsigned int _numberOfClicks(Core::Point clickPos, Timestamp clickTime);
void _updateSystemParameterSettings() noexcept;

Expand Down
6 changes: 6 additions & 0 deletions src/cascadia/TerminalControl/ControlInteractivity.idl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ namespace Microsoft.Terminal.Control
void GotFocus();
void LostFocus();

Guid Id { get; };

void Close();

InteractivityAutomationPeer OnCreateAutomationPeer();

Boolean CopySelectionToClipboard(Boolean singleLine, Windows.Foundation.IReference<CopyFormat> formats);
Expand Down Expand Up @@ -65,6 +69,8 @@ namespace Microsoft.Terminal.Control
event Windows.Foundation.TypedEventHandler<Object, ScrollPositionChangedArgs> ScrollPositionChanged;
event Windows.Foundation.TypedEventHandler<Object, PasteFromClipboardEventArgs> PasteFromClipboard;

event Windows.Foundation.TypedEventHandler<Object, Object> Closed;

// Used to communicate to the TermControl, but not necessarily higher up in the stack
event Windows.Foundation.TypedEventHandler<Object, ContextMenuRequestedEventArgs> ContextMenuRequested;

Expand Down
Loading