You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-23 22:36:32 +02:00
Desktop: Add dialog to select a note and link to it (#11891)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
|
||||
import { _ } from '@joplin/lib/locale';
|
||||
import { GotoAnythingUserData, Mode, UserDataCallbackReject, UserDataCallbackResolve } from '../../../plugins/GotoAnything';
|
||||
const PluginManager = require('@joplin/lib/services/PluginManager');
|
||||
|
||||
export enum UiType {
|
||||
@@ -8,6 +9,10 @@ export enum UiType {
|
||||
ControlledApi = 'controlledApi',
|
||||
}
|
||||
|
||||
export interface GotoAnythingOptions {
|
||||
mode?: Mode;
|
||||
}
|
||||
|
||||
export const declaration: CommandDeclaration = {
|
||||
name: 'gotoAnything',
|
||||
label: () => _('Goto Anything...'),
|
||||
@@ -24,19 +29,26 @@ function menuItemById(id: string) {
|
||||
// calling the click() handler.
|
||||
export const runtime = (): CommandRuntime => {
|
||||
return {
|
||||
execute: async (_context: CommandContext, uiType: UiType = UiType.GotoAnything) => {
|
||||
execute: async (_context: CommandContext, uiType: UiType = UiType.GotoAnything, options: GotoAnythingOptions = null) => {
|
||||
options = {
|
||||
mode: Mode.Default,
|
||||
...options,
|
||||
};
|
||||
|
||||
if (uiType === UiType.GotoAnything) {
|
||||
menuItemById('gotoAnything').click();
|
||||
} else if (uiType === UiType.CommandPalette) {
|
||||
menuItemById('commandPalette').click();
|
||||
} else if (uiType === UiType.ControlledApi) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
|
||||
return new Promise((resolve: Function, reject: Function) => {
|
||||
return new Promise((resolve: UserDataCallbackResolve, reject: UserDataCallbackReject) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||
const menuItem = PluginManager.instance().menuItems().find((i: any) => i.id === 'controlledApi');
|
||||
menuItem.userData = {
|
||||
const userData: GotoAnythingUserData = {
|
||||
callback: { resolve, reject },
|
||||
mode: options.mode,
|
||||
};
|
||||
menuItem.userData = userData;
|
||||
menuItem.click();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user