1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Resolves #1752: Added capability to toggle visibility of the Menu Bar from the View menu (#10324)

This commit is contained in:
LightTreasure 2024-05-07 02:57:02 -07:00 committed by GitHub
parent 1ea0c56d7b
commit 548ba7d712
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 42 additions and 0 deletions

View File

@ -242,6 +242,7 @@ packages/app-desktop/gui/MainScreen/commands/showSpellCheckerMenu.test.js
packages/app-desktop/gui/MainScreen/commands/showSpellCheckerMenu.js packages/app-desktop/gui/MainScreen/commands/showSpellCheckerMenu.js
packages/app-desktop/gui/MainScreen/commands/toggleEditors.js packages/app-desktop/gui/MainScreen/commands/toggleEditors.js
packages/app-desktop/gui/MainScreen/commands/toggleLayoutMoveMode.js packages/app-desktop/gui/MainScreen/commands/toggleLayoutMoveMode.js
packages/app-desktop/gui/MainScreen/commands/toggleMenuBar.js
packages/app-desktop/gui/MainScreen/commands/toggleNoteList.js packages/app-desktop/gui/MainScreen/commands/toggleNoteList.js
packages/app-desktop/gui/MainScreen/commands/toggleNoteType.js packages/app-desktop/gui/MainScreen/commands/toggleNoteType.js
packages/app-desktop/gui/MainScreen/commands/toggleNotesSortOrderField.js packages/app-desktop/gui/MainScreen/commands/toggleNotesSortOrderField.js

1
.gitignore vendored
View File

@ -222,6 +222,7 @@ packages/app-desktop/gui/MainScreen/commands/showSpellCheckerMenu.test.js
packages/app-desktop/gui/MainScreen/commands/showSpellCheckerMenu.js packages/app-desktop/gui/MainScreen/commands/showSpellCheckerMenu.js
packages/app-desktop/gui/MainScreen/commands/toggleEditors.js packages/app-desktop/gui/MainScreen/commands/toggleEditors.js
packages/app-desktop/gui/MainScreen/commands/toggleLayoutMoveMode.js packages/app-desktop/gui/MainScreen/commands/toggleLayoutMoveMode.js
packages/app-desktop/gui/MainScreen/commands/toggleMenuBar.js
packages/app-desktop/gui/MainScreen/commands/toggleNoteList.js packages/app-desktop/gui/MainScreen/commands/toggleNoteList.js
packages/app-desktop/gui/MainScreen/commands/toggleNoteType.js packages/app-desktop/gui/MainScreen/commands/toggleNoteType.js
packages/app-desktop/gui/MainScreen/commands/toggleNotesSortOrderField.js packages/app-desktop/gui/MainScreen/commands/toggleNotesSortOrderField.js

View File

@ -39,6 +39,7 @@ import * as showShareNoteDialog from './showShareNoteDialog';
import * as showSpellCheckerMenu from './showSpellCheckerMenu'; import * as showSpellCheckerMenu from './showSpellCheckerMenu';
import * as toggleEditors from './toggleEditors'; import * as toggleEditors from './toggleEditors';
import * as toggleLayoutMoveMode from './toggleLayoutMoveMode'; import * as toggleLayoutMoveMode from './toggleLayoutMoveMode';
import * as toggleMenuBar from './toggleMenuBar';
import * as toggleNoteList from './toggleNoteList'; import * as toggleNoteList from './toggleNoteList';
import * as toggleNoteType from './toggleNoteType'; import * as toggleNoteType from './toggleNoteType';
import * as toggleNotesSortOrderField from './toggleNotesSortOrderField'; import * as toggleNotesSortOrderField from './toggleNotesSortOrderField';
@ -88,6 +89,7 @@ const index: any[] = [
showSpellCheckerMenu, showSpellCheckerMenu,
toggleEditors, toggleEditors,
toggleLayoutMoveMode, toggleLayoutMoveMode,
toggleMenuBar,
toggleNoteList, toggleNoteList,
toggleNoteType, toggleNoteType,
toggleNotesSortOrderField, toggleNotesSortOrderField,

View File

@ -0,0 +1,16 @@
import { CommandDeclaration, CommandRuntime } from '@joplin/lib/services/CommandService';
import Setting from '@joplin/lib/models/Setting';
import { _ } from '@joplin/lib/locale';
export const declaration: CommandDeclaration = {
name: 'toggleMenuBar',
label: () => _('Toggle menu bar'),
};
export const runtime = (): CommandRuntime => {
return {
execute: async () => {
Setting.toggle('showMenuBar');
},
};
};

View File

@ -172,6 +172,7 @@ interface Props {
pluginSettings: PluginSettings; pluginSettings: PluginSettings;
noteListRendererIds: string[]; noteListRendererIds: string[];
noteListRendererId: string; noteListRendererId: string;
showMenuBar: boolean;
} }
const commandNames: string[] = menuCommandNames(); const commandNames: string[] = menuCommandNames();
@ -190,6 +191,15 @@ function menuItemSetEnabled(id: string, enabled: boolean) {
menuItem.enabled = enabled; menuItem.enabled = enabled;
} }
const applyMenuBarVisibility = (showMenuBar: boolean) => {
// The menu bar cannot be hidden on macOS
if (shim.isMac()) return;
const window = bridge().window();
window.setAutoHideMenuBar(!showMenuBar);
window.setMenuBarVisibility(showMenuBar);
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
function useMenuStates(menu: any, props: Props) { function useMenuStates(menu: any, props: Props) {
useEffect(() => { useEffect(() => {
@ -760,6 +770,7 @@ function useMenu(props: Props) {
menuItemDic.resetLayout, menuItemDic.resetLayout,
separator(), separator(),
menuItemDic.toggleSideBar, menuItemDic.toggleSideBar,
shim.isMac() ? noItem : menuItemDic.toggleMenuBar,
menuItemDic.toggleNoteList, menuItemDic.toggleNoteList,
menuItemDic.toggleVisiblePanes, menuItemDic.toggleVisiblePanes,
{ {
@ -1083,6 +1094,7 @@ function useMenu(props: Props) {
function MenuBar(props: Props): any { function MenuBar(props: Props): any {
const menu = useMenu(props); const menu = useMenu(props);
if (menu) Menu.setApplicationMenu(menu); if (menu) Menu.setApplicationMenu(menu);
applyMenuBarVisibility(props.showMenuBar);
return null; return null;
} }
@ -1112,6 +1124,7 @@ const mapStateToProps = (state: AppState) => {
profileConfig: state.profileConfig, profileConfig: state.profileConfig,
noteListRendererIds: state.noteListRendererIds, noteListRendererIds: state.noteListRendererIds,
noteListRendererId: state.settings['notes.listRendererId'], noteListRendererId: state.settings['notes.listRendererId'],
showMenuBar: state.settings.showMenuBar,
}; };
}; };

View File

@ -34,6 +34,7 @@ export default function() {
'toggleExternalEditing', 'toggleExternalEditing',
'toggleLayoutMoveMode', 'toggleLayoutMoveMode',
'resetLayout', 'resetLayout',
'toggleMenuBar',
'toggleNoteList', 'toggleNoteList',
'toggleNotesSortOrderField', 'toggleNotesSortOrderField',
'toggleNotesSortOrderReverse', 'toggleNotesSortOrderReverse',

View File

@ -1298,6 +1298,13 @@ class Setting extends BaseModel {
isGlobal: true, isGlobal: true,
}, },
showMenuBar: {
value: true, // Show the menu bar by default
type: SettingItemType.Bool,
public: false,
appTypes: [AppType.Desktop],
},
startMinimized: { value: false, type: SettingItemType.Bool, storage: SettingStorage.File, isGlobal: true, section: 'application', public: true, appTypes: [AppType.Desktop], label: () => _('Start application minimised in the tray icon') }, startMinimized: { value: false, type: SettingItemType.Bool, storage: SettingStorage.File, isGlobal: true, section: 'application', public: true, appTypes: [AppType.Desktop], label: () => _('Start application minimised in the tray icon') },
collapsedFolderIds: { value: [], type: SettingItemType.Array, public: false }, collapsedFolderIds: { value: [], type: SettingItemType.Array, public: false },

View File

@ -85,6 +85,7 @@ const defaultKeymapItems = {
{ accelerator: 'Ctrl+Shift+N', command: 'focusElementNoteTitle' }, { accelerator: 'Ctrl+Shift+N', command: 'focusElementNoteTitle' },
{ accelerator: 'Ctrl+Shift+B', command: 'focusElementNoteBody' }, { accelerator: 'Ctrl+Shift+B', command: 'focusElementNoteBody' },
{ accelerator: 'F10', command: 'toggleSideBar' }, { accelerator: 'F10', command: 'toggleSideBar' },
{ accelerator: 'Ctrl+Shift+M', command: 'toggleMenuBar' },
{ accelerator: 'F11', command: 'toggleNoteList' }, { accelerator: 'F11', command: 'toggleNoteList' },
{ accelerator: 'Ctrl+L', command: 'toggleVisiblePanes' }, { accelerator: 'Ctrl+L', command: 'toggleVisiblePanes' },
{ accelerator: 'Ctrl+0', command: 'zoomActualSize' }, { accelerator: 'Ctrl+0', command: 'zoomActualSize' },