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 menu shortcut texts for non-darwin OS #5248

Merged
merged 2 commits into from
Nov 27, 2024

Conversation

ErikKalkoken
Copy link
Contributor

Description:

The current implementation renders menu shortcuts exclusively in macOS style, which might be confusing for users on Windows and Linux (see also #5108).

This PR adds a new generic style for rending menu shortcut texts on non-Darwin OS, while keeping the existing macOS style for Darwin OS. The generic style is mostly spelling out the names of keys instead of using symbols and should be much easier to understand for Windows and Linux users. The style is based on the VS Code shortcut documentation for Windows and Linux.

Additional changes

  • Refactored existing code
  • Added unit tests for function that generates shortcut texts

Example screenshot

Screenshot from 2024-11-09 14-23-03

Fixes #5108

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

Where applicable:

N/A

@coveralls
Copy link

coveralls commented Nov 9, 2024

Coverage Status

coverage: 59.991% (+0.01%) from 59.98%
when pulling 64fda1b on ErikKalkoken:feature-5108
into b529a32 on fyne-io:develop.

Copy link
Member

@Jacalz Jacalz left a comment

Choose a reason for hiding this comment

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

Nice idea. Thanks for this. I've left some of my own ideas on the code but I think it would be wise to have @toaster have a look as well.

@@ -37,6 +41,25 @@ var keySymbols = map[fyne.KeyName]rune{
fyne.KeyUp: '↑',
}

// key default text
Copy link
Member

Choose a reason for hiding this comment

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

This comment does not add any value over the variable name. Either remove it or write something more helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for taking the time to review my PR.

I will rework the comments.

widget/menu_item.go Outdated Show resolved Hide resolved
widget/menu_item.go Outdated Show resolved Hide resolved
widget/menu_item.go Outdated Show resolved Hide resolved
widget/menu_item.go Outdated Show resolved Hide resolved
widget/menu_item.go Outdated Show resolved Hide resolved
@andydotxyz
Copy link
Member

Yes a runtime check might seem simpler (not sure how using runtime checks is easier to unit test TBH).
But for efficiency the build flags are preferable because there is less code to compile and the compiler can eliminate or inline the static const/var declarations etc.
I don't think that Jacob was asking for the "2) hybrid" I would have thought that using A) for all of them matches the current code style most effectively.

P.S. do check that the font must be different before coding that in - I think that if you choose symbol it would fall back to the normal font if the item is not in fact a symbol.

@Jacalz
Copy link
Member

Jacalz commented Nov 15, 2024

I entirely agree that A matches what we already have the best. It is good to be consistent with that and also not compiling in unnecessary code can be a win (sometimes also for readability).

To be fair, I did actually suggest B initially because that better described what I meant with "moving out the four if-statements" and because it was a smaller change from the existing code in the PR. However, I do agree that A is more consistent with what we already have and likely is the better path forward.

@ErikKalkoken
Copy link
Contributor Author

tyvm both for the clarification and your patience. I will rework the solution to exclusively use build flags.

@andydotxyz

Yes a runtime check might seem simpler (not sure how using runtime checks is easier to unit test TBH).

With runtime checks you can make the current OS a parameter of the textsForShortcuts() function and then test all OS cases with unit tests (see also my initial commit for an example). This works here, because the "platform specific" code is just some different texts and formatting and runs on all platforms. But I fully understand your point about consistency; this was just to answer your question.

@andydotxyz
Copy link
Member

Thanks, A helpful answer. It is indeed true that with the build flags the unit tests cannot cover all systems on one run, but CI provides the checks for those systems - so overall we get the optimised path but get the test runs too.
You'll find that on this path some tests /have/ to run on the target system (such as visual confirmation that symbols render in menus) - so the infrastructure is already set up that way.

@ErikKalkoken
Copy link
Contributor Author

Here is my new attempt ready for review.

@Jacalz
Copy link
Member

Jacalz commented Nov 20, 2024

Thanks. I had a very quick look through the code on my phone and it looked great. Will follow up with a proper review later in the week when I have more time :)

Copy link
Member

@Jacalz Jacalz left a comment

Choose a reason for hiding this comment

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

Thanks. Sorry for the late review; I've been quite busy recently. This looks great. Just one minor comment about modifying the window size of one of the test images :)

Copy link
Member

@Jacalz Jacalz left a comment

Choose a reason for hiding this comment

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

Perfect. Thanks for working on this 👍

@ErikKalkoken
Copy link
Contributor Author

Perfect. Thanks for working on this 👍

Thank you again for your review and patience with my PR. This is my first feature submission for Fyne and I am still learning how everything works.

The tests are now passing on my branch. Seams to be those flaky tests again acting up.

@Jacalz
Copy link
Member

Jacalz commented Nov 27, 2024

Thank you again for your review and patience with my PR. This is my first feature submission for Fyne and I am still learning how everything works.

No worries. Glad we all got to the same page in the end. Congratulations on your first PR then :)

The tests are now passing on my branch. Seams to be those flaky tests again acting up.

Yeah, sorry about that. Seems like the coverage upload is a bit flakey. Strange. Either way, kicking the tests made it all pass now so I'll merge 👍

@Jacalz Jacalz merged commit 9db3dfe into fyne-io:develop Nov 27, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants