-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Desktop: Resolves #1752: Added capability to toggle visibility of the Menu Bar from the View menu #10324
Desktop: Resolves #1752: Added capability to toggle visibility of the Menu Bar from the View menu #10324
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
packages/tools/locales/en_US.po
Outdated
#: packages/app-desktop/gui/MainScreen/commands/toggleMenuBar.ts:9 | ||
msgid "Toggle menu bar" | ||
msgstr "" | ||
|
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.
You don't need to add this here - that will be done automatically as long as you wrap the translatable strings in _(...)
which you did
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've removed this in the latest commit
// Now apply the setting | ||
electronWindow.setAutoHideMenuBar(Setting.value('hideMenuBar')); | ||
electronWindow.setMenuBarVisibility(!Setting.value('hideMenuBar')); |
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.
Please remove, since you're already doing this in the reducer middleware
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've removed this file and the references to this command in the latest commit
packages/lib/models/Setting.ts
Outdated
hideMenuBar: { | ||
value: false, | ||
type: SettingItemType.Bool, | ||
public: false, | ||
appTypes: [AppType.Desktop], | ||
}, |
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.
Sorry would you mind naming it "showMenuBar" and setting it to true
by default? This is the pattern we try to follow to avoid double-negations.
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.
Agreed, I'll change it.
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.
Changed in the latest commit.
packages/app-desktop/app.ts
Outdated
public updateMenuBar() { | ||
// macOS disallows the removal of the menu bar | ||
if (shim.isMac()) return; | ||
|
||
const window = bridge().window(); | ||
window.setAutoHideMenuBar(Setting.value('hideMenuBar')); | ||
window.setMenuBarVisibility(!Setting.value('hideMenuBar')); | ||
} |
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 have a MenuBar
component to handle the menu. Would you mind moving the logic over there? If you need some help implementing this please let me know.
Essentially you'll need to add this to mapStateToProps
:
showMenuBar: state.settings.showMenuBar,
Then check the value of props.showMenuBar
from the component and hide/show it based on this.
The reason for doing it that way is to encapsulate all menu bar related logic in the same place, and to avoid the need to sync the settings and the state in the middleware.
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.
Thanks for the review! Makes sense - I'll try implementing it this way and reply back 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.
Moved the implementation to the MenuBar
component in the latest commit. That simplifies things a lot!
…omponent, and changed the name of the setting to "showMenuBar"
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.
Nearly there but please bring back the command you had created
packages/app-desktop/gui/MenuBar.tsx
Outdated
@@ -190,6 +191,15 @@ function menuItemSetEnabled(id: string, enabled: boolean) { | |||
menuItem.enabled = enabled; | |||
} | |||
|
|||
function applyMenuBarVisibility(props: Props) { |
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.
const applyMenuBarVisibility = (props:Props => {
(see coding style guide)
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.
And actually only pass to the function that variables that you need - so just "showMenuBar", not the whole props
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.
Whoops. Fixed.
packages/app-desktop/gui/MenuBar.tsx
Outdated
shim.isMac() ? noItem : { | ||
label: _('Toggle menu bar'), | ||
accelerator: keymapService.getAccelerator('toggleMenuBar'), | ||
click: () => { | ||
Setting.setValue('showMenuBar', !Setting.value('showMenuBar')); | ||
applyMenuBarVisibility(props); | ||
}, | ||
}, | ||
// shim.isMac() ? noItem : menuItemDic.toggleMenuBar, |
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.
Hmm, but I'm not sure why you removed your command? That was the correct way to implement this, since it would be a command that can also be triggered from user scripts. It will also automatically register the keyboard shortcut.
Once the command is created, you can add it to menuCommandName.ts
and then add it to the menu using the menuItemDic.xxxx
pattern (see other commands in the menu)
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.
Apologies - I clicked on "View Reviewed changes" in GitHub. For some reason, in that view, GitHub doesn't show which lines the comment applied to. I assumed you meant that I should remove the entire file.
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.
Restored the command and used it for the implementation.
packages/tools/locales/joplin.pot
Outdated
#: packages/app-desktop/gui/MenuBar.tsx:774 | ||
msgid "Toggle menu bar" | ||
msgstr "" | ||
|
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.
Please remove - this will be done automatically
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.
Ah I see. Not very familiar with this style of localization. Removed it.
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.
That looks good now, thanks @LightTreasure. I'd just remove the isMac
check in the command since it's redundant
// Defensive code: macOS disallows hiding the menu bar, so ignore this Command | ||
if (shim.isMac()) 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.
At this stage it's not necessary to handle this, since you already handle it where it matters
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.
Oh yup that makes sense. Removed in the newest commit.
…ince the core implementation has moved
Hi @laurent22, please let me know if you have any further suggestions. Thanks so much! |
That looks good now, thanks @LightTreasure! |
Add menu option and shortcut to toggle visibility of the menu bar
What this does:
This PR adds a new item to the View Menu called "Toggle Menu Bar", and proposes
Ctrl+Shift+M
as its default keyboard shortcut. Clicking on this item or using the shortcut toggles the visibility of the menu bar. Also, when the bar is hidden, pressingAlt
will temporarily show the menu barEDIT: The menu item is not shown on Mac since macOS does not allow for hiding menus.
This feature has been requested via the following issues:
It has also been requested on the Joplin Forum:
How implemented:
Builds on @tinyoverflow's previously submitted pull request to address the same issue. This work incorporates @laurent22's feedback in that PR to add this capability as a View Menu item instead of it being present on the settings page.
Ctrl+Shift+M
(defined inlib/services/KeymapService.ts
), and a localization string added totools/locales/joplin.pot
and english translationtools/locales/en_US.po
hideMenuBar
, a boolean with the default value offalse
, applicable only to the Desktop App (defined inlib/models/Setting.ts
)toggleMenuBar()
, which contains the main implementation. This flips the value of thehideMenuBar
setting and then correspondingly callssetAutoHideMenuBar()
andsetMenuBarVisibility()
on the Electron Window.updateMenuBar()
inapp-desktop/app.ts
- Called during initializatoin, this function callssetAutoHideMenuBar()
andsetMenuBarVisibility()
based on the value of thehideMenuBar
setting.toggleMenuBar()
andupdateMenuBar()
do not do anything on Mac.Usage with screenshots:
The new menu entry:
When the setting is toggled:
Toggling again brings the menu back:
Issues:
Sometimes, after hiding the menu bar, the window is left with a white empty area, indicating that the contents aren't painted correctly. @tinyoverflow also mentioned this issue in their PR. I've tried debugging this, but haven't been able to fix it. My guess is that Electron isn't repainting the window properly after the menu bar is hidden.