Skip to content

Commit

Permalink
plumb the action through to the task pane
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Feb 20, 2024
1 parent d7a6b18 commit 2f3ecf1
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,8 @@ namespace winrt::TerminalApp::implementation
// handle.
scratchPane->GetRoot().KeyDown({ this, &TerminalPage::_KeyDownHandler });

scratchPane->DispatchCommandRequested({ this, &TerminalPage::_OnDispatchCommandRequested });

const auto resultPane = std::make_shared<Pane>(*scratchPane);
_SplitPane(_senderOrFocusedTab(sender), SplitDirection::Automatic, 0.5f, resultPane);
args.Handled(true);
Expand Down
10 changes: 10 additions & 0 deletions src/cascadia/TerminalApp/TabManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ namespace winrt::TerminalApp::implementation
// for it. The Title change will be propagated upwards through the tab's
// PropertyChanged event handler.
newTabImpl->ActivePaneChanged([weakTab, weakThis{ get_weak() }]() {
// TODO!
//
// * Make this a method on TerminalPage.
// * Convert ActivePaneChanged to a typed event, so it sends the sender (so we don't need to make all these lambdas)
// * Stash the task pane as a member on the Terminal? if one was opened.
// * If the tab does have a taskpane, then tell the taskpane the active pane changed
//
// wait don't do any of that. just do that in TerminalTab directly
// before we even raise the event you donkey

auto page{ weakThis.get() };
auto tab{ weakTab.get() };

Expand Down
22 changes: 22 additions & 0 deletions src/cascadia/TerminalApp/TasksPaneContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,26 @@ namespace winrt::TerminalApp::implementation
{
return Background();
}

void TasksPaneContent::SetLastActiveControl(const Microsoft::Terminal::Control::TermControl& control)
{
_control = control;
}

void TasksPaneContent::_runCommandButtonClicked(const Windows::Foundation::IInspectable& sender,
const Windows::UI::Xaml::RoutedEventArgs&)
{

if (const auto& taskVM{ sender.try_as<WUX::Controls::Button>().DataContext().try_as<TaskViewModel>() })
{
if (const auto& strongControl{ _control.get() })
{
// By using the last active control as the sender here, the
// actiopn dispatch will send this to the active control,
// thinking that it is the control that requested this event.
DispatchCommandRequested.raise(strongControl, taskVM->Command());
}
}
}

}
8 changes: 8 additions & 0 deletions src/cascadia/TerminalApp/TasksPaneContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace winrt::TerminalApp::implementation
Windows::Foundation::IReference<winrt::Windows::UI::Color> TabColor() const noexcept { return nullptr; }
winrt::Windows::UI::Xaml::Media::Brush BackgroundBrush();

void SetLastActiveControl(const Microsoft::Terminal::Control::TermControl& control);

til::typed_event<> CloseRequested;
til::typed_event<winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::BellEventArgs> BellRequested;
til::typed_event<> TitleChanged;
Expand All @@ -37,8 +39,14 @@ namespace winrt::TerminalApp::implementation
til::typed_event<> ReadOnlyChanged;
til::typed_event<> FocusRequested;

til::typed_event<winrt::Windows::Foundation::IInspectable, Microsoft::Terminal::Settings::Model::Command> DispatchCommandRequested;

private:
friend struct TasksPaneContentT<TasksPaneContent>; // for Xaml to bind events

winrt::weak_ref<Microsoft::Terminal::Control::TermControl> _control;

void _runCommandButtonClicked(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs&);
};

struct TaskViewModel : TaskViewModelT<TaskViewModel>
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalApp/TasksPaneContent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
HorizontalAlignment="Center"
Fill="{ThemeResource SystemControlBackgroundBaseMediumBrush}"/>-->
<Button Grid.Row="0"
Grid.Column="0">
Grid.Column="0"
Click="_runCommandButtonClicked">
<FontIcon FontFamily="Segoe Fluent Icons, Segoe MDL2 Assets"
FontSize="12"
Glyph="&#xE768;" />
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,10 @@ namespace winrt::TerminalApp::implementation
// - command - command to dispatch
// Return Value:
// - <none>
void TerminalPage::_OnDispatchCommandRequested(const IInspectable& /*sender*/, const Microsoft::Terminal::Settings::Model::Command& command)
void TerminalPage::_OnDispatchCommandRequested(const IInspectable& sender, const Microsoft::Terminal::Settings::Model::Command& command)
{
const auto& actionAndArgs = command.ActionAndArgs();
_actionDispatch->DoAction(actionAndArgs);
_actionDispatch->DoAction(sender, actionAndArgs);
}

// Method Description:
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalApp/TerminalPaneContent.idl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ namespace TerminalApp
[default_interface] runtimeclass TasksPaneContent : Windows.UI.Xaml.Controls.UserControl, IPaneContent
{
TasksPaneContent();
void SetLastActiveControl(Microsoft.Terminal.Control.TermControl control);

event Windows.Foundation.TypedEventHandler<Object, Microsoft.Terminal.Settings.Model.Command> DispatchCommandRequested;

}

}
12 changes: 12 additions & 0 deletions src/cascadia/TerminalApp/TerminalTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,18 @@ namespace winrt::TerminalApp::implementation

// Raise our own ActivePaneChanged event.
_ActivePaneChangedHandlers();

const auto content{ pane->GetContent() };
if (const auto termContent{ content.try_as<winrt::TerminalApp::TerminalPaneContent>() })
{
const auto& termControl{ termContent.GetTerminal() };
_rootPane->WalkTree([termControl](const auto& p) {
if (const auto& taskPane{ p->GetContent().try_as<TasksPaneContent>() })
{
taskPane.SetLastActiveControl(termControl);
}
});
}
}

// Method Description:
Expand Down

0 comments on commit 2f3ecf1

Please sign in to comment.