一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
59 行
2.0 KiB
TypeScript
59 行
2.0 KiB
TypeScript
/* eslint-disable multiline-comment-style */
|
|
|
|
import KeymapService from '../../KeymapService';
|
|
import { MenuItem, MenuItemLocation } from './types';
|
|
import MenuController from '../MenuController';
|
|
import Plugin from '../Plugin';
|
|
import createViewHandle from '../utils/createViewHandle';
|
|
import { PluginStore } from '../ViewController';
|
|
|
|
/**
|
|
* Allows creating menus.
|
|
*
|
|
* [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/menu)
|
|
*
|
|
* <span class="platform-desktop">desktop</span>
|
|
*/
|
|
export default class JoplinViewsMenus {
|
|
|
|
private store: PluginStore;
|
|
private plugin: Plugin;
|
|
|
|
public constructor(plugin: Plugin, store: PluginStore) {
|
|
this.store = store;
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
private registerCommandAccelerators(menuItems: MenuItem[]) {
|
|
for (const menuItem of menuItems) {
|
|
if (menuItem.accelerator) {
|
|
KeymapService.instance().registerCommandAccelerator(menuItem.commandName, menuItem.accelerator);
|
|
}
|
|
|
|
if (menuItem.submenu) {
|
|
this.registerCommandAccelerators(menuItem.submenu);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Creates a new menu from the provided menu items and place it at the given location. As of now, it is only possible to place the
|
|
* menu as a sub-menu of the application build-in menus.
|
|
*/
|
|
public async create(id: string, label: string, menuItems: MenuItem[], location: MenuItemLocation = MenuItemLocation.Tools) {
|
|
if (!Array.isArray(menuItems)) {
|
|
this.plugin.deprecationNotice('1.5', 'Creating a view without an ID is deprecated. To fix it, change your call to `joplin.views.menus.create("my-unique-id", ...)`', true);
|
|
location = (menuItems as unknown as MenuItemLocation) || MenuItemLocation.Tools;
|
|
menuItems = label as unknown as MenuItem[];
|
|
label = id;
|
|
id = `${this.plugin.viewCount}`;
|
|
}
|
|
|
|
const handle = createViewHandle(this.plugin, id);
|
|
const controller = new MenuController(handle, this.plugin.id, this.store, label, menuItems, location);
|
|
this.plugin.addViewController(controller);
|
|
this.registerCommandAccelerators(menuItems);
|
|
}
|
|
|
|
}
|