Skip to content

Commit

Permalink
a toast for showing the CWD of the Terminal. This is for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed May 1, 2023
1 parent 816f8b2 commit 0726206
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,13 @@ namespace winrt::TerminalApp::implementation
args.Handled(true);
}

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

void TerminalPage::_HandleGlobalSummon(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{
Expand Down
5 changes: 4 additions & 1 deletion src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,9 @@
<data name="RenameFailedToast.Subtitle" xml:space="preserve">
<value>Another window with that name already exists</value>
</data>
<data name="WindowCwdToast.Subtitle" xml:space="preserve">
<value>This is the CWD of the Terminal window itself</value>
</data>
<data name="WindowMaximizeButtonToolTip" xml:space="preserve">
<value>Maximize</value>
</data>
Expand Down Expand Up @@ -823,4 +826,4 @@
<data name="ClosePaneToolTip" xml:space="preserve">
<value>Close the active pane if multiple panes are present</value>
</data>
</root>
</root>
27 changes: 27 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4067,6 +4067,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 @@ -149,6 +149,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 @@ -257,6 +258,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
7 changes: 7 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,12 @@
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"
Subtitle="{x:Bind WindowProperties.VirtualWorkingDirectory, Mode=OneWay}" />
</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{ "displayTerminalCwd" };
static constexpr std::string_view GlobalSummonKey{ "globalSummon" };
static constexpr std::string_view QuakeModeKey{ "quakeMode" };
static constexpr std::string_view FocusPaneKey{ "focusPane" };
Expand Down Expand Up @@ -401,6 +402,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, L"Display Terminal's CWD TODO! localize" },
{ ShortcutAction::GlobalSummon, MustGenerate },
{ ShortcutAction::QuakeMode, RS_(L"QuakeModeCommandKey") },
{ ShortcutAction::FocusPane, MustGenerate },
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(GlobalSummon) \
ON_ALL_ACTIONS(QuakeMode) \
ON_ALL_ACTIONS(FocusPane) \
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
{ "command": "openSystemMenu", "keys": "alt+space" },
{ "command": "quit" },
{ "command": "restoreLastClosed"},
{ "command": "displayTerminalCwd"},

// Tab Management
// "command": "closeTab" is unbound by default.
Expand Down

0 comments on commit 0726206

Please sign in to comment.