1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-18 09:35:20 +02:00
joplin/packages/app-desktop/gui/Sidebar/commands/focusElementSideBar.ts
Henry Heino 4a88d6ff7a
Desktop: Multiple window support (#11181)
Co-authored-by: Laurent Cozic <laurent22@users.noreply.github.com>
2024-11-08 15:32:05 +00:00

29 lines
954 B
TypeScript

import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
import { _ } from '@joplin/lib/locale';
import layoutItemProp from '../../ResizableLayout/utils/layoutItemProp';
import { AppState } from '../../../app.reducer';
import { SidebarCommandRuntimeProps } from '../types';
import bridge from '../../../services/bridge';
export const declaration: CommandDeclaration = {
name: 'focusElementSideBar',
label: () => _('Sidebar'),
parentLabel: () => _('Focus'),
};
export const runtime = (props: SidebarCommandRuntimeProps): CommandRuntime => {
return {
execute: async (context: CommandContext) => {
const sidebarVisible = layoutItemProp((context.state as AppState).mainLayout, 'sideBar', 'visible');
if (sidebarVisible) {
props.focusSidebar();
// The sidebar is only present in the main window:
bridge().switchToMainWindow();
}
},
enabledCondition: 'sideBarVisible',
};
};