Skip to content

Commit

Permalink
Add an action to display toast with the CWD of the Terminal (#15282)
Browse files Browse the repository at this point in the history
Adds an action to display a toast containing the Terminal's "virtual"
CWD.

As described in
#4637 (comment).

Useful for debugging #5506 et. al. I almost left it as a debug-only
feature, but figured it would be helpful for others in the #4637
landscape of things.
  • Loading branch information
zadjii-msft authored Jul 20, 2023
1 parent 7010626 commit 648d240
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,16 @@ namespace winrt::TerminalApp::implementation
args.Handled(true);
}

void TerminalPage::_HandleDisplayWorkingDirectory(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{
if (_settings.GlobalSettings().DebugFeaturesEnabled())
{
ShowTerminalWorkingDirectory();
args.Handled(true);
}
}

void TerminalPage::_HandleSearchForText(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{
Expand Down
27 changes: 27 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4105,6 +4105,33 @@ namespace winrt::TerminalApp::implementation
}
}

winrt::fire_and_forget TerminalPage::ShowTerminalWorkingDirectory()
{
auto weakThis{ get_weak() };
co_await wil::resume_foreground(Dispatcher());
if (auto page{ weakThis.get() })
{
// If we haven't ever loaded the TeachingTip, then do so now and
// create the toast for it.
if (page->_windowCwdToast == nullptr)
{
if (auto tip{ page->FindName(L"WindowCwdToast").try_as<MUX::Controls::TeachingTip>() })
{
page->_windowCwdToast = std::make_shared<Toast>(tip);
// Make sure to use the weak ref when setting up this
// callback.
tip.Closed({ page->get_weak(), &TerminalPage::_FocusActiveControl });
}
}
_UpdateTeachingTipTheme(WindowCwdToast().try_as<winrt::Windows::UI::Xaml::FrameworkElement>());

if (page->_windowCwdToast != nullptr)
{
page->_windowCwdToast->Open();
}
}
}

// Method Description:
// - Called when the user hits the "Ok" button on the WindowRenamer TeachingTip.
// - Will raise an event that will bubble up to the monarch, asking if this
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ namespace winrt::TerminalApp::implementation

winrt::fire_and_forget IdentifyWindow();
winrt::fire_and_forget RenameFailed();
winrt::fire_and_forget ShowTerminalWorkingDirectory();

winrt::fire_and_forget ProcessStartupActions(Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::ActionAndArgs> actions,
const bool initial,
Expand Down Expand Up @@ -256,6 +257,7 @@ namespace winrt::TerminalApp::implementation

std::shared_ptr<Toast> _windowIdToast{ nullptr };
std::shared_ptr<Toast> _windowRenameFailedToast{ nullptr };
std::shared_ptr<Toast> _windowCwdToast{ nullptr };

winrt::Windows::UI::Xaml::Controls::TextBox::LayoutUpdated_revoker _renamerLayoutUpdatedRevoker;
int _renamerLayoutCount{ 0 };
Expand Down
6 changes: 6 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,11 @@
Text="{x:Bind WindowProperties.WindowName, Mode=OneWay}" />
</mux:TeachingTip.Content>
</mux:TeachingTip>

<mux:TeachingTip x:Name="WindowCwdToast"
x:Uid="WindowCwdToast"
Title="{x:Bind WindowProperties.VirtualWorkingDirectory, Mode=OneWay}"
x:Load="False"
IsLightDismissEnabled="True" />
</Grid>
</Page>
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ static constexpr std::string_view IdentifyWindowKey{ "identifyWindow" };
static constexpr std::string_view IdentifyWindowsKey{ "identifyWindows" };
static constexpr std::string_view RenameWindowKey{ "renameWindow" };
static constexpr std::string_view OpenWindowRenamerKey{ "openWindowRenamer" };
static constexpr std::string_view DisplayWorkingDirectoryKey{ "debugTerminalCwd" };
static constexpr std::string_view SearchForTextKey{ "searchWeb" };
static constexpr std::string_view GlobalSummonKey{ "globalSummon" };
static constexpr std::string_view QuakeModeKey{ "quakeMode" };
Expand Down Expand Up @@ -404,6 +405,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{ ShortcutAction::IdentifyWindows, RS_(L"IdentifyWindowsCommandKey") },
{ ShortcutAction::RenameWindow, RS_(L"ResetWindowNameCommandKey") },
{ ShortcutAction::OpenWindowRenamer, RS_(L"OpenWindowRenamerCommandKey") },
{ ShortcutAction::DisplayWorkingDirectory, RS_(L"DisplayWorkingDirectoryCommandKey") },
{ ShortcutAction::GlobalSummon, MustGenerate },
{ ShortcutAction::SearchForText, MustGenerate },
{ ShortcutAction::QuakeMode, RS_(L"QuakeModeCommandKey") },
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/AllShortcutActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
ON_ALL_ACTIONS(IdentifyWindows) \
ON_ALL_ACTIONS(RenameWindow) \
ON_ALL_ACTIONS(OpenWindowRenamer) \
ON_ALL_ACTIONS(DisplayWorkingDirectory) \
ON_ALL_ACTIONS(SearchForText) \
ON_ALL_ACTIONS(GlobalSummon) \
ON_ALL_ACTIONS(QuakeMode) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@
<data name="OpenWindowRenamerCommandKey" xml:space="preserve">
<value>Rename window...</value>
</data>
<data name="DisplayWorkingDirectoryCommandKey" xml:space="preserve">
<value>Display Terminal's current working directory</value>
</data>
<data name="GlobalSummonCommandKey" xml:space="preserve">
<value>Show/Hide the Terminal window</value>
</data>
Expand Down

0 comments on commit 648d240

Please sign in to comment.