Skip to content

Commit 2f3ecf1

Browse files
committed
plumb the action through to the task pane
1 parent d7a6b18 commit 2f3ecf1

8 files changed

+62
-3
lines changed

src/cascadia/TerminalApp/AppActionHandlers.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,8 @@ namespace winrt::TerminalApp::implementation
14561456
// handle.
14571457
scratchPane->GetRoot().KeyDown({ this, &TerminalPage::_KeyDownHandler });
14581458

1459+
scratchPane->DispatchCommandRequested({ this, &TerminalPage::_OnDispatchCommandRequested });
1460+
14591461
const auto resultPane = std::make_shared<Pane>(*scratchPane);
14601462
_SplitPane(_senderOrFocusedTab(sender), SplitDirection::Automatic, 0.5f, resultPane);
14611463
args.Handled(true);

src/cascadia/TerminalApp/TabManagement.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ namespace winrt::TerminalApp::implementation
134134
// for it. The Title change will be propagated upwards through the tab's
135135
// PropertyChanged event handler.
136136
newTabImpl->ActivePaneChanged([weakTab, weakThis{ get_weak() }]() {
137+
// TODO!
138+
//
139+
// * Make this a method on TerminalPage.
140+
// * Convert ActivePaneChanged to a typed event, so it sends the sender (so we don't need to make all these lambdas)
141+
// * Stash the task pane as a member on the Terminal? if one was opened.
142+
// * If the tab does have a taskpane, then tell the taskpane the active pane changed
143+
//
144+
// wait don't do any of that. just do that in TerminalTab directly
145+
// before we even raise the event you donkey
146+
137147
auto page{ weakThis.get() };
138148
auto tab{ weakTab.get() };
139149

src/cascadia/TerminalApp/TasksPaneContent.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,26 @@ namespace winrt::TerminalApp::implementation
106106
{
107107
return Background();
108108
}
109+
110+
void TasksPaneContent::SetLastActiveControl(const Microsoft::Terminal::Control::TermControl& control)
111+
{
112+
_control = control;
113+
}
114+
115+
void TasksPaneContent::_runCommandButtonClicked(const Windows::Foundation::IInspectable& sender,
116+
const Windows::UI::Xaml::RoutedEventArgs&)
117+
{
118+
119+
if (const auto& taskVM{ sender.try_as<WUX::Controls::Button>().DataContext().try_as<TaskViewModel>() })
120+
{
121+
if (const auto& strongControl{ _control.get() })
122+
{
123+
// By using the last active control as the sender here, the
124+
// actiopn dispatch will send this to the active control,
125+
// thinking that it is the control that requested this event.
126+
DispatchCommandRequested.raise(strongControl, taskVM->Command());
127+
}
128+
}
129+
}
130+
109131
}

src/cascadia/TerminalApp/TasksPaneContent.h

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ namespace winrt::TerminalApp::implementation
2828
Windows::Foundation::IReference<winrt::Windows::UI::Color> TabColor() const noexcept { return nullptr; }
2929
winrt::Windows::UI::Xaml::Media::Brush BackgroundBrush();
3030

31+
void SetLastActiveControl(const Microsoft::Terminal::Control::TermControl& control);
32+
3133
til::typed_event<> CloseRequested;
3234
til::typed_event<winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::BellEventArgs> BellRequested;
3335
til::typed_event<> TitleChanged;
@@ -37,8 +39,14 @@ namespace winrt::TerminalApp::implementation
3739
til::typed_event<> ReadOnlyChanged;
3840
til::typed_event<> FocusRequested;
3941

42+
til::typed_event<winrt::Windows::Foundation::IInspectable, Microsoft::Terminal::Settings::Model::Command> DispatchCommandRequested;
43+
4044
private:
4145
friend struct TasksPaneContentT<TasksPaneContent>; // for Xaml to bind events
46+
47+
winrt::weak_ref<Microsoft::Terminal::Control::TermControl> _control;
48+
49+
void _runCommandButtonClicked(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs&);
4250
};
4351

4452
struct TaskViewModel : TaskViewModelT<TaskViewModel>

src/cascadia/TerminalApp/TasksPaneContent.xaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
HorizontalAlignment="Center"
5959
Fill="{ThemeResource SystemControlBackgroundBaseMediumBrush}"/>-->
6060
<Button Grid.Row="0"
61-
Grid.Column="0">
61+
Grid.Column="0"
62+
Click="_runCommandButtonClicked">
6263
<FontIcon FontFamily="Segoe Fluent Icons, Segoe MDL2 Assets"
6364
FontSize="12"
6465
Glyph="&#xE768;" />

src/cascadia/TerminalApp/TerminalPage.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,10 @@ namespace winrt::TerminalApp::implementation
451451
// - command - command to dispatch
452452
// Return Value:
453453
// - <none>
454-
void TerminalPage::_OnDispatchCommandRequested(const IInspectable& /*sender*/, const Microsoft::Terminal::Settings::Model::Command& command)
454+
void TerminalPage::_OnDispatchCommandRequested(const IInspectable& sender, const Microsoft::Terminal::Settings::Model::Command& command)
455455
{
456456
const auto& actionAndArgs = command.ActionAndArgs();
457-
_actionDispatch->DoAction(actionAndArgs);
457+
_actionDispatch->DoAction(sender, actionAndArgs);
458458
}
459459

460460
// Method Description:

src/cascadia/TerminalApp/TerminalPaneContent.idl

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ namespace TerminalApp
4242
[default_interface] runtimeclass TasksPaneContent : Windows.UI.Xaml.Controls.UserControl, IPaneContent
4343
{
4444
TasksPaneContent();
45+
void SetLastActiveControl(Microsoft.Terminal.Control.TermControl control);
46+
47+
event Windows.Foundation.TypedEventHandler<Object, Microsoft.Terminal.Settings.Model.Command> DispatchCommandRequested;
48+
4549
}
4650

4751
}

src/cascadia/TerminalApp/TerminalTab.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,18 @@ namespace winrt::TerminalApp::implementation
12031203

12041204
// Raise our own ActivePaneChanged event.
12051205
_ActivePaneChangedHandlers();
1206+
1207+
const auto content{ pane->GetContent() };
1208+
if (const auto termContent{ content.try_as<winrt::TerminalApp::TerminalPaneContent>() })
1209+
{
1210+
const auto& termControl{ termContent.GetTerminal() };
1211+
_rootPane->WalkTree([termControl](const auto& p) {
1212+
if (const auto& taskPane{ p->GetContent().try_as<TasksPaneContent>() })
1213+
{
1214+
taskPane.SetLastActiveControl(termControl);
1215+
}
1216+
});
1217+
}
12061218
}
12071219

12081220
// Method Description:

0 commit comments

Comments
 (0)