Skip to content

Commit 5b3aa54

Browse files
committed
move GetNewTerminalArgs into IPaneContent
1 parent ef6bb8a commit 5b3aa54

File tree

4 files changed

+58
-56
lines changed

4 files changed

+58
-56
lines changed

src/cascadia/TerminalApp/IPaneContent.idl

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace TerminalApp
1414
UInt64 TaskbarProgress { get; };
1515
Boolean ReadOnly { get; };
1616

17+
Microsoft.Terminal.Settings.Model.NewTerminalArgs GetNewTerminalArgs(Boolean asContent);
18+
1719
void Focus();
1820

1921
void Close();

src/cascadia/TerminalApp/Pane.cpp

+1-56
Original file line numberDiff line numberDiff line change
@@ -132,62 +132,7 @@ NewTerminalArgs Pane::GetTerminalArgsForPane(const bool asContent) const
132132
// Leaves are the only things that have controls
133133
assert(_IsLeaf());
134134

135-
// TODO! this should be in the IPaneContent interface
136-
if (const auto& terminalPane{ _getTerminalContent() }; !terminalPane)
137-
{
138-
return nullptr;
139-
}
140-
auto termControl{ _content.GetRoot().try_as<TermControl>() };
141-
142-
NewTerminalArgs args{};
143-
auto controlSettings = termControl.Settings();
144-
145-
args.Profile(controlSettings.ProfileName());
146-
// If we know the user's working directory use it instead of the profile.
147-
if (const auto dir = termControl.WorkingDirectory(); !dir.empty())
148-
{
149-
args.StartingDirectory(dir);
150-
}
151-
else
152-
{
153-
args.StartingDirectory(controlSettings.StartingDirectory());
154-
}
155-
args.TabTitle(controlSettings.StartingTitle());
156-
args.Commandline(controlSettings.Commandline());
157-
args.SuppressApplicationTitle(controlSettings.SuppressApplicationTitle());
158-
if (controlSettings.TabColor() || controlSettings.StartingTabColor())
159-
{
160-
til::color c;
161-
// StartingTabColor is prioritized over other colors
162-
if (const auto color = controlSettings.StartingTabColor())
163-
{
164-
c = til::color(color.Value());
165-
}
166-
else
167-
{
168-
c = til::color(controlSettings.TabColor().Value());
169-
}
170-
171-
args.TabColor(winrt::Windows::Foundation::IReference<winrt::Windows::UI::Color>{ static_cast<winrt::Windows::UI::Color>(c) });
172-
}
173-
174-
// TODO:GH#9800 - we used to be able to persist the color scheme that a
175-
// TermControl was initialized with, by name. With the change to having the
176-
// control own its own copy of its settings, this isn't possible anymore.
177-
//
178-
// We may be able to get around this by storing the Name in the Core::Scheme
179-
// object. That would work for schemes set by the Terminal, but not ones set
180-
// by VT, but that seems good enough.
181-
182-
// Only fill in the ContentId if absolutely needed. If you fill in a number
183-
// here (even 0), we'll serialize that number, AND treat that action as an
184-
// "attach existing" rather than a "create"
185-
if (asContent)
186-
{
187-
args.ContentId(termControl.ContentId());
188-
}
189-
190-
return args;
135+
return _content.GetNewTerminalArgs(asContent);
191136
}
192137

193138
// Method Description:

src/cascadia/TerminalApp/TerminalPaneContent.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,59 @@ namespace winrt::TerminalApp::implementation
6767
}
6868
}
6969

70+
NewTerminalArgs TerminalPaneContent::GetNewTerminalArgs(const bool asContent) const
71+
{
72+
NewTerminalArgs args{};
73+
auto controlSettings = _control.Settings();
74+
75+
args.Profile(controlSettings.ProfileName());
76+
// If we know the user's working directory use it instead of the profile.
77+
if (const auto dir = _control.WorkingDirectory(); !dir.empty())
78+
{
79+
args.StartingDirectory(dir);
80+
}
81+
else
82+
{
83+
args.StartingDirectory(controlSettings.StartingDirectory());
84+
}
85+
args.TabTitle(controlSettings.StartingTitle());
86+
args.Commandline(controlSettings.Commandline());
87+
args.SuppressApplicationTitle(controlSettings.SuppressApplicationTitle());
88+
if (controlSettings.TabColor() || controlSettings.StartingTabColor())
89+
{
90+
til::color c;
91+
// StartingTabColor is prioritized over other colors
92+
if (const auto color = controlSettings.StartingTabColor())
93+
{
94+
c = til::color(color.Value());
95+
}
96+
else
97+
{
98+
c = til::color(controlSettings.TabColor().Value());
99+
}
100+
101+
args.TabColor(winrt::Windows::Foundation::IReference<winrt::Windows::UI::Color>{ static_cast<winrt::Windows::UI::Color>(c) });
102+
}
103+
104+
// TODO:GH#9800 - we used to be able to persist the color scheme that a
105+
// TermControl was initialized with, by name. With the change to having the
106+
// control own its own copy of its settings, this isn't possible anymore.
107+
//
108+
// We may be able to get around this by storing the Name in the Core::Scheme
109+
// object. That would work for schemes set by the Terminal, but not ones set
110+
// by VT, but that seems good enough.
111+
112+
// Only fill in the ContentId if absolutely needed. If you fill in a number
113+
// here (even 0), we'll serialize that number, AND treat that action as an
114+
// "attach existing" rather than a "create"
115+
if (asContent)
116+
{
117+
args.ContentId(_control.ContentId());
118+
}
119+
120+
return args;
121+
}
122+
70123
// Method Description:
71124
// - Called when our attached control is closed. Triggers listeners to our close
72125
// event, if we're a leaf pane.

src/cascadia/TerminalApp/TerminalPaneContent.h

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace winrt::TerminalApp::implementation
1919
void Focus();
2020
void Close();
2121

22+
winrt::Microsoft::Terminal::Settings::Model::NewTerminalArgs GetNewTerminalArgs(const bool asContent) const;
23+
2224
void UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult& settings,
2325
const winrt::Microsoft::Terminal::Settings::Model::Profile& profile);
2426

0 commit comments

Comments
 (0)