1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-02-13 19:42:36 +02:00

Desktop: Fix "new notebook" shown in context menu when right-clicking on the "Tags" header (#10378)

This commit is contained in:
Henry Heino 2024-04-27 03:44:01 -07:00 committed by GitHub
parent 1bb3632a70
commit 09216b8b59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 16 deletions

View File

@ -79,17 +79,6 @@ const useOnRenderItem = (props: Props) => {
}
}, []);
const header_contextMenu = useCallback(async () => {
const menu = new Menu();
menu.append(
new MenuItem(menuUtils.commandToStatefulMenuItem('newFolder')),
);
menu.popup({ window: bridge().window() });
}, []);
const onItemContextMenu: ItemContextMenuListener = useCallback(async event => {
const itemId = event.currentTarget.getAttribute('data-id');
if (itemId === Folder.conflictFolderId()) return;
@ -396,7 +385,6 @@ const useOnRenderItem = (props: Props) => {
key={item.id}
item={item}
anchorRef={anchorRefCallback}
contextMenuHandler={header_contextMenu}
onDrop={item.supportsFolderDrop ? onFolderDrop_ : null}
/>;
} else if (item.kind === ListItemType.AllNotes) {
@ -415,7 +403,6 @@ const useOnRenderItem = (props: Props) => {
}
}, [
folderItem_click,
header_contextMenu,
onFolderDragOver_,
onFolderDragStart_,
onFolderDrop_,

View File

@ -2,12 +2,19 @@ import * as React from 'react';
import { useCallback } from 'react';
import { ButtonLevel } from '../../Button/Button';
import { StyledAddButton, StyledHeader, StyledHeaderIcon, StyledHeaderLabel } from '../styles';
import { HeaderListItem, ItemContextMenuListener } from '../types';
import { HeaderId, HeaderListItem } from '../types';
import { _ } from '@joplin/lib/locale';
import bridge from '../../../services/bridge';
import MenuUtils from '@joplin/lib/services/commands/MenuUtils';
import CommandService from '@joplin/lib/services/CommandService';
const Menu = bridge().Menu;
const MenuItem = bridge().MenuItem;
const menuUtils = new MenuUtils(CommandService.instance());
interface Props {
item: HeaderListItem;
contextMenuHandler: ItemContextMenuListener|null;
onDrop: React.DragEventHandler|null;
anchorRef: React.Ref<HTMLElement>;
}
@ -23,6 +30,18 @@ const HeaderItem: React.FC<Props> = props => {
}
}, [onItemClick, itemId]);
const onContextMenu = useCallback(async () => {
if (itemId === HeaderId.FolderHeader) {
const menu = new Menu();
menu.append(
new MenuItem(menuUtils.commandToStatefulMenuItem('newFolder')),
);
menu.popup({ window: bridge().window() });
}
}, [itemId]);
const addButton = <StyledAddButton
iconLabel={_('New')}
onClick={item.onPlusButtonClick}
@ -37,7 +56,7 @@ const HeaderItem: React.FC<Props> = props => {
onDrop={props.onDrop}
>
<StyledHeader
onContextMenu={props.contextMenuHandler}
onContextMenu={onContextMenu}
onClick={onClick}
tabIndex={0}
ref={props.anchorRef}