2023-06-30 10:55:56 +02:00
/* eslint-disable multiline-comment-style */
2020-10-09 19:35:46 +02:00
import { ToolbarButtonLocation } from './types' ;
import Plugin from '../Plugin' ;
import ToolbarButtonController from '../ToolbarButtonController' ;
import createViewHandle from '../utils/createViewHandle' ;
/ * *
* Allows creating and managing toolbar buttons .
*
2020-11-05 18:58:23 +02:00
* [ View the demo plugin ] ( https : //github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/register_command)
2020-10-09 19:35:46 +02:00
* /
export default class JoplinViewsToolbarButtons {
2024-04-05 13:16:49 +02:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
2020-10-09 19:35:46 +02:00
private store : any ;
private plugin : Plugin ;
2024-04-05 13:16:49 +02:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
2023-03-06 16:22:01 +02:00
public constructor ( plugin : Plugin , store : any ) {
2020-10-09 19:35:46 +02:00
this . store = store ;
this . plugin = plugin ;
}
/ * *
* Creates a new toolbar button and associate it with the given command .
* /
2023-03-06 16:22:01 +02:00
public async create ( id : string , commandName : string , location : ToolbarButtonLocation ) {
2020-11-13 19:09:28 +02:00
if ( arguments . length < 3 ) {
2021-08-05 13:02:03 +02:00
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 ) ;
2024-04-05 13:16:49 +02:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
2020-11-13 19:09:28 +02:00
location = commandName as any ;
2024-04-05 13:16:49 +02:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
2020-11-13 19:09:28 +02:00
commandName = id as any ;
id = ` ${ this . plugin . viewCount } ` ;
}
const handle = createViewHandle ( this . plugin , id ) ;
2020-10-09 19:35:46 +02:00
const controller = new ToolbarButtonController ( handle , this . plugin . id , this . store , commandName , location ) ;
this . plugin . addViewController ( controller ) ;
}
}