-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
When the profile icon is set to null, fall back to the icon of the commandline #15843
Conversation
Why can't we make it so that there's a differentiation between |
Discussion notes:
|
…he icon of the commandline
if (cmdline.empty()) | ||
{ | ||
return {}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW you can remove this check. An empty wstring
still returns a valid string via .c_str()
(""
) and so all the code below should still work.
const size_t beforeNull{ ::wcslen(cmdline.c_str()) }; | ||
const std::wstring_view exe{ cmdline.c_str(), beforeNull }; | ||
return winrt::hstring{ exe }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just passing cmdline.c_str()
to the hstring
constructor will be fine. It has a hstring(wchar_t const* c)
constructor, which calls wcslen
for you. With the above comment this turns into:
const auto cmdline{ NormalizeCommandLine(Commandline().c_str()) };
// NormalizeCommandLine will return a string with embedded
// nulls after each arg. We just want the first one.
return winrt::hstring{ cmdline.c_str() };
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree generally that we should move from a smart string type to an hstring by using c_str
. String types know their length; winrt::hstring(wchar_t*)
must use wcslen
to re-derive the length. Why do extra work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only want to return the first segment of the double-null terminated string. (See the comment 😅)
…ult-to-commandline
…hub.com/microsoft/terminal into dev/migrie/b/705-default-to-commandline
<comment>A supplementary setting to the "icon" setting.</comment> | ||
</data> | ||
<data name="Profile_HideIconCheckbox.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve"> | ||
<value>If enabled, this will have no icon.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<value>If enabled, this will have no icon.</value> | |
<value>If enabled, this profile will have no icon.</value> |
this what?
winrt::hstring Profile::EvaluatedIcon() | ||
{ | ||
// We cache the result here, so we don't search the path for the exe every time. | ||
if (!_evaluatedIcon.has_value()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey, setting Icon doesn't invalidate this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we never really set directly on a Profile tho do we? We instantiate a new one when we build a new settings object, but that'd come with an empty cached _evaluatedIcon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, the settings UI writes directly to Icon. It then fires local "Icon Changed" notifications and any listeners will probably re-call EvaluatedIcon (ugh)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which may mean that setting an icon in the SUI doesn't update IN THE UI until you mash Save and it re-loads the entire tree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but like, is that okay?
winrt::hstring Profile::_evaluateIcon() const | ||
{ | ||
// If the profile has an icon, return it. | ||
if (!Icon().empty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we not use our own member here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, we can't because profile is layered so _Icon
isn't the actual icon necessarily
…ult-to-commandline
…ult-to-commandline
…ult-to-commandline
The settings UI and settings model allow you to set the icon to "none" to hide the icon (you can actually see this effect in the settings UI when changing the value of the profile icon). However, during settings validation, "none" is considered a file path, which is then failed to be parsed, resulting in the icon being marked as invalid and immediately clearing the value. This PR fixes this issue by considering "none" to be an accepted value during validation. Related to #15843 Closes #17943 ## Validation Steps Performed When an icon is set to "none", ... ✅ no more warning ✅ the icon is hidden
The settings UI and settings model allow you to set the icon to "none" to hide the icon (you can actually see this effect in the settings UI when changing the value of the profile icon). However, during settings validation, "none" is considered a file path, which is then failed to be parsed, resulting in the icon being marked as invalid and immediately clearing the value. This PR fixes this issue by considering "none" to be an accepted value during validation. Related to #15843 Closes #17943 ## Validation Steps Performed When an icon is set to "none", ... ✅ no more warning ✅ the icon is hidden (cherry picked from commit 36f064c) Service-Card-Id: PVTI_lADOAF3p4s4AmhmszgTyV8A Service-Version: 1.21
The settings UI and settings model allow you to set the icon to "none" to hide the icon (you can actually see this effect in the settings UI when changing the value of the profile icon). However, during settings validation, "none" is considered a file path, which is then failed to be parsed, resulting in the icon being marked as invalid and immediately clearing the value. This PR fixes this issue by considering "none" to be an accepted value during validation. Related to #15843 Closes #17943 ## Validation Steps Performed When an icon is set to "none", ... ✅ no more warning ✅ the icon is hidden (cherry picked from commit 36f064c) Service-Card-Id: PVTI_lADOAF3p4s4AmhmQzgTyV8E Service-Version: 1.22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be corrected
Basically, title. If you null out the icon, we'll automatically try to use the
commandline
as an icon (because we can now). We'll even be smart about it -cmd.exe /k echo wassup
will still just use the ico ofcmd.exe
.This doesn't work for
ubuntu.exe
(et. al), because that commandline is technically a reparse point, that doesn't actually have an icon associated with it.Closes #705
"none"
becomes our sentinel value for "no icon".This will also use the same
NormalizeCommandLine
we use for commandline matching for finding the full path to the exe.