一些检查失败了
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
41 行
1.4 KiB
TypeScript
41 行
1.4 KiB
TypeScript
/* eslint-disable multiline-comment-style */
|
|
|
|
import { ToolbarButtonLocation } from './types';
|
|
import Plugin from '../Plugin';
|
|
import ToolbarButtonController from '../ToolbarButtonController';
|
|
import createViewHandle from '../utils/createViewHandle';
|
|
import { PluginStore } from '../ViewController';
|
|
|
|
/**
|
|
* Allows creating and managing toolbar buttons.
|
|
*
|
|
* [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/register_command)
|
|
*/
|
|
export default class JoplinViewsToolbarButtons {
|
|
|
|
private store: PluginStore;
|
|
private plugin: Plugin;
|
|
|
|
public constructor(plugin: Plugin, store: PluginStore) {
|
|
this.store = store;
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
/**
|
|
* Creates a new toolbar button and associate it with the given command.
|
|
*/
|
|
public async create(id: string, commandName: string, location: ToolbarButtonLocation) {
|
|
if (arguments.length < 3) {
|
|
this.plugin.deprecationNotice('1.5', 'Creating a view without an ID is deprecated. To fix it, change your call to `joplin.views.toolbarButtons.create("my-unique-id", ...)`', true);
|
|
location = commandName as ToolbarButtonLocation;
|
|
commandName = id;
|
|
id = `${this.plugin.viewCount}`;
|
|
}
|
|
|
|
const handle = createViewHandle(this.plugin, id);
|
|
const controller = new ToolbarButtonController(handle, this.plugin.id, this.store, commandName, location);
|
|
this.plugin.addViewController(controller);
|
|
}
|
|
|
|
}
|