Skip to content

When the profile icon is set to null, fall back to the icon of the commandline - #15843

Merged
Mike Griese (zadjii-msft) merged 15 commits into
mainfrom
dev/migrie/b/705-default-to-commandline
Feb 26, 2024
Merged

Mike Griese (zadjii-msft) merged 15 commits into
mainfrom
dev/migrie/b/705-default-to-commandline

Conversation

@zadjii-msft

@zadjii-msft Mike Griese (zadjii-msft) commented Aug 17, 2023 •

Copy link
Copy Markdown
Member

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 of cmd.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.

@zadjii-msft Mike Griese (zadjii-msft) added the Needs-Discussion Something that requires a team discussion before we can proceed label Aug 17, 2023
@microsoft-github-policy-service microsoft-github-policy-service Bot added Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Area-UserInterface Issues pertaining to the user interface of the Console or Terminal Product-Terminal The new Windows Terminal. labels Aug 17, 2023
@lhecker

Copy link
Copy Markdown
Member
  • The only way to hide the icon becomes "icon": " ". That's weird. but passable?

Why can't we make it so that there's a differentiation between null and "empty string"? Empty string to hide the icon seems fine-ish to me...

@zadjii-msft

Copy link
Copy Markdown
Member Author

Discussion notes:

@zadjii-msft

Copy link
Copy Markdown
Member Author

hide-icon-sui

@zadjii-msft Mike Griese (zadjii-msft) removed their assignment Sep 7, 2023
Comment on lines +363 to +366
if (cmdline.empty())
{
return {};
}

Copy link
Copy Markdown
Member

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.

Comment on lines +370 to +372
const size_t beforeNull{ ::wcslen(cmdline.c_str()) };
const std::wstring_view exe{ cmdline.c_str(), beforeNull };
return winrt::hstring{ exe };

@lhecker Leonard Hecker (lhecker) Sep 19, 2023 •

Copy link
Copy Markdown
Member

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() };

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member

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 😅)

Dustin L. Howett (DHowett) added a commit that referenced this pull request Sep 22, 2023
<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>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
<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())

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
Member

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)

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member Author

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())

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member Author

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

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Sep 25, 2023
@microsoft-github-policy-service microsoft-github-policy-service Bot removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Sep 25, 2023
@zadjii-msft
Mike Griese (zadjii-msft) deleted the dev/migrie/b/705-default-to-commandline branch February 26, 2024 21:32
Dustin L. Howett (DHowett) pushed a commit that referenced this pull request Oct 11, 2024
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
Dustin L. Howett (DHowett) pushed a commit that referenced this pull request Oct 17, 2024
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
Dustin L. Howett (DHowett) pushed a commit that referenced this pull request Oct 17, 2024
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

@Jihad85-D Jihad85-D left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Will be corrected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-UserInterface Issues pertaining to the user interface of the Console or Terminal Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Terminal The new Windows Terminal. zBugBash-Consider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically populate icons for the associated profiles

4 participants