Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a success dialog to window renaming #9808

Merged
5 commits merged into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 35 additions & 28 deletions src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: undo changes to this file

<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema

Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple

There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -618,10 +618,17 @@
<data name="RenameFailedToast.Subtitle" xml:space="preserve">
<value>Another window with that name already exists</value>
</data>
<data name="RenameSucceededToast.Title" xml:space="preserve">
<value>Successfully renamed window</value>
</data>
<data name="RenameSucceededText" xml:space="preserve">
<value>Successfully renamed window to "{}"</value>
<comment>{} will be replaced by the new name assigned by the user</comment>
</data>
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
<data name="WindowMaximizeButtonToolTip" xml:space="preserve">
<value>Maximize</value>
</data>
<data name="WindowRestoreDownButtonToolTip" xml:space="preserve">
<value>Restore Down</value>
</data>
</root>
</root>
70 changes: 67 additions & 3 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2601,15 +2601,65 @@ namespace winrt::TerminalApp::implementation
{
return _WindowName;
}
void TerminalPage::WindowName(const winrt::hstring& value)

winrt::fire_and_forget TerminalPage::WindowName(const winrt::hstring& value)
{
if (_WindowName != value)
const bool changed = _WindowName != value;
if (changed)
{
_WindowName = value;
_PropertyChangedHandlers(*this, WUX::Data::PropertyChangedEventArgs{ L"WindowNameForDisplay" });
}
auto weakThis{ get_weak() };
// On the foreground thread, raise property changed notifications, and
// display the success toast.
co_await resume_foreground(Dispatcher());
if (auto page{ weakThis.get() })
{
if (changed)
{
page->_PropertyChangedHandlers(*this, WUX::Data::PropertyChangedEventArgs{ L"WindowNameForDisplay" });
page->_PropertyChangedHandlers(*this, WUX::Data::PropertyChangedEventArgs{ L"RenameSucceededText" });
DHowett marked this conversation as resolved.
Show resolved Hide resolved

// DON'T display the confirmation if this is the name we were
DHowett marked this conversation as resolved.
Show resolved Hide resolved
// given on startup!
if (page->_startupState == StartupState::Initialized)
{
page->_DisplayRenameSuccessToast();
}
}
}
}

// Method Description:
// - Display the rename succeeded toast. If this is the first time we're
// being called, load the TeachingTip manually and wire it up to the Toast
// object.
// - This should be called on the UI thread.
// Arguments:
// - <none>
// Return Value:
// - <none>
void TerminalPage::_DisplayRenameSuccessToast()
{
// If we haven't ever loaded the TeachingTip, then do so now and
// create the toast for it.
if (_windowRenameSucceededToast == nullptr)
{
if (MUX::Controls::TeachingTip tip{ FindName(L"RenameSucceededToast").try_as<MUX::Controls::TeachingTip>() })
{
_windowRenameSucceededToast = std::make_shared<Toast>(tip);
// Make sure to use the weak ref when setting up this
// callback.
tip.Closed({ get_weak(), &TerminalPage::_FocusActiveControl });
}
}
_UpdateTeachingTipTheme(RenameSucceededToast().try_as<winrt::Windows::UI::Xaml::FrameworkElement>());

if (_windowRenameSucceededToast != nullptr)
{
_windowRenameSucceededToast->Open();
}
}
// WindowId is a otherwise generic WINRT_OBSERVABLE_PROPERTY, but it needs
// to raise a PropertyChanged for WindowIdForDisplay, instead of
// WindowId.
Expand Down Expand Up @@ -2652,6 +2702,20 @@ namespace winrt::TerminalApp::implementation
_WindowName;
}

// Method Description:
// - Returns a string of text like "Successfully renamed window to
// "{WindowNameForDisplay()}"". This is used for the RenameSucceededToast
// when a rename is successful.
// Arguments:
// - <none>
// Return Value:
// - a string for displaying the name of the window.
winrt::hstring TerminalPage::RenameSucceededText() const noexcept
{
return winrt::hstring{ fmt::format(std::wstring_view(RS_(L"RenameSucceededText")),
std::wstring_view(WindowNameForDisplay())) };
}

// Method Description:
// - Called when an attempt to rename the window has failed. This will open
// the toast displaying a message to the user that the attempt to rename
Expand Down
5 changes: 4 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ namespace winrt::TerminalApp::implementation
// WINRT_OBSERVABLE_PROPERTY's, but we want them to raise
// WindowNameForDisplay and WindowIdForDisplay instead
winrt::hstring WindowName() const noexcept;
void WindowName(const winrt::hstring& value);
winrt::fire_and_forget WindowName(const winrt::hstring& value);
uint64_t WindowId() const noexcept;
void WindowId(const uint64_t& value);
winrt::hstring WindowIdForDisplay() const noexcept;
winrt::hstring WindowNameForDisplay() const noexcept;
winrt::hstring RenameSucceededText() const noexcept;

WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);

Expand Down Expand Up @@ -175,6 +176,7 @@ namespace winrt::TerminalApp::implementation

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

void _ShowAboutDialog();
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowCloseWarningDialog();
Expand Down Expand Up @@ -327,6 +329,7 @@ namespace winrt::TerminalApp::implementation
void _WindowRenamerActionClick(const IInspectable& sender, const IInspectable& eventArgs);
void _RequestWindowRename(const winrt::hstring& newName);
void _WindowRenamerKeyUp(const IInspectable& sender, winrt::Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e);
void _DisplayRenameSuccessToast();
DHowett marked this conversation as resolved.
Show resolved Hide resolved

void _UpdateTeachingTipTheme(winrt::Windows::UI::Xaml::FrameworkElement element);

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalPage.idl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace TerminalApp
UInt64 WindowId;
String WindowNameForDisplay { get; };
String WindowIdForDisplay { get; };
String RenameSucceededText { get; };
void RenameFailed();

// We cannot use the default XAML APIs because we want to make sure
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 @@ -133,6 +133,12 @@
x:Load="False"
IsLightDismissEnabled="True" />

<mux:TeachingTip x:Name="RenameSucceededToast"
x:Uid="RenameSucceededToast"
x:Load="False"
IsLightDismissEnabled="True"
Subtitle="{x:Bind RenameSucceededText, Mode=OneWay}" />

<mux:TeachingTip x:Name="WindowRenamer"
x:Uid="WindowRenamer"
Title="{x:Bind WindowIdForDisplay}"
Expand Down