Skip to content

Commit

Permalink
Okay the window renamer is pretty slick
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Mar 2, 2021
1 parent aa51c07 commit e818f8d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
16 changes: 15 additions & 1 deletion src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,20 @@
<data name="WindowIdPrefix" xml:space="preserve">
<value>Window: {}</value>
<comment>{} will be replaced with a number identifying this window</comment>

</data>
<data name="WindowRenamer.Subtitle" xml:space="preserve">
<value>Enter a new name:</value>
</data>
<data name="WindowRenamer.ActionButtonContent" xml:space="preserve">
<value>Ok</value>
</data>
<data name="WindowRenamer.CloseButtonContent" xml:space="preserve">
<value>Cancel</value>
</data>
<data name="RenameFailedToast.Title" xml:space="preserve">
<value>Failed to rename window</value>
</data>
<data name="RenameFailedToast.Subtitle" xml:space="preserve">
<value>Another window with that name already exists</value>
</data>
</root>
13 changes: 13 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ namespace winrt::TerminalApp::implementation
};

WindowIdToast().Closed(safeRefocus);
RenameFailedToast().Closed(safeRefocus);
WindowRenamer().Closed(safeRefocus);

// Setup mouse vanish attributes
SystemParametersInfoW(SPI_GETMOUSEVANISH, 0, &_shouldMouseVanish, false);

Expand Down Expand Up @@ -3323,6 +3326,7 @@ namespace winrt::TerminalApp::implementation
page->WindowIdToast().IsOpen(true);
}
}

winrt::fire_and_forget TerminalPage::RenameFailed()
{
auto weakThis{ get_weak() };
Expand All @@ -3333,6 +3337,15 @@ namespace winrt::TerminalApp::implementation
}
}

void TerminalPage::_WindowRenamerActionClick(const IInspectable& /*sender*/,
const IInspectable& /*eventArgs*/)
{
auto newName = WindowRenamerTextBox().Text();
auto request = winrt::make_self<implementation::RenameWindowRequestedArgs>(newName);
WindowRenamer().IsOpen(false);
_RenameWindowRequestedHandlers(*this, *request);
}

// -------------------------------- WinRT Events ---------------------------------
// Winrt events need a method for adding a callback to the event and removing the callback.
// These macros will define them both for you.
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 @@ -294,6 +294,8 @@ namespace winrt::TerminalApp::implementation
void _HidePointerCursorHandler(const IInspectable& sender, const IInspectable& eventArgs);
void _RestorePointerCursorHandler(const IInspectable& sender, const IInspectable& eventArgs);

void _WindowRenamerActionClick(const IInspectable& sender, const IInspectable& eventArgs);

#pragma region ActionHandlers
// These are all defined in AppActionHandlers.cpp
DECLARE_ACTION_HANDLER(OpenNewTabDropdown);
Expand Down
10 changes: 4 additions & 6 deletions src/cascadia/TerminalApp/TerminalPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,14 @@ the MIT License. See LICENSE in the project root for license information. -->
</mux:TeachingTip>

<mux:TeachingTip x:Name="RenameFailedToast"
IsLightDismissEnabled="True"
Title="Failed to rename window"
Subtitle="Another window with that name already exists">
x:Uid="RenameFailedToast"
IsLightDismissEnabled="True">
</mux:TeachingTip>

<mux:TeachingTip x:Name="WindowRenamer"
x:Uid="WindowRenamer"
Title="{x:Bind WindowId, Mode=OneWay, Converter={StaticResource WindowIdConverter}}"
Subtitle="Enter a new name:"
ActionButtonContent="Ok"
CloseButtonContent="Cancel">
ActionButtonClick="_WindowRenamerActionClick">
<mux:TeachingTip.Content>
<TextBox x:Name="WindowRenamerTextBox"
Text="{x:Bind WindowName}">
Expand Down
20 changes: 7 additions & 13 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,17 +631,21 @@ void AppHost::_DisplayWindowId(const winrt::Windows::Foundation::IInspectable& /
winrt::fire_and_forget AppHost::_RenameWindowRequested(const winrt::Windows::Foundation::IInspectable /*sender*/,
const winrt::TerminalApp::RenameWindowRequestedArgs args)
{
winrt::apartment_context ui_thread; // Capture calling context.
// Capture calling context.
winrt::apartment_context ui_thread;

// Switch to the BG thread - anything x-proc must happen on a BG thread
co_await winrt::resume_background();

if (auto peasant{ _windowManager.CurrentWindow() })
{
Remoting::RenameRequestArgs requestArgs{ args.ProposedName() };
// peasant.RequestRename(args.ProposedName());

peasant.RequestRename(requestArgs);

co_await ui_thread; // Switch back to calling context.
// Switch back to the UI thread. Setting the WindowName needs to happen
// on the UI thread, because it'll raise a PropertyChanged event
co_await ui_thread;

if (requestArgs.Succeeded())
{
Expand All @@ -653,13 +657,3 @@ winrt::fire_and_forget AppHost::_RenameWindowRequested(const winrt::Windows::Fou
}
}
}

// void AppHost::_RenameWindow(const winrt::hstring newName)
// {
// _logic.Name(newName);
// }

// void AppHost::_FailToRenameWindow()
// {
// _logic.RenameFailed();
// }

1 comment on commit e818f8d

@github-actions

This comment was marked as outdated.

Please sign in to comment.