mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Plugins: Add support for gotoAnything command so that it can be called from plugins
This commit is contained in:
parent
269ec34c83
commit
00b39e4671
@ -224,6 +224,9 @@ packages/app-desktop/gui/MainScreen/commands/editAlarm.js.map
|
||||
packages/app-desktop/gui/MainScreen/commands/exportPdf.d.ts
|
||||
packages/app-desktop/gui/MainScreen/commands/exportPdf.js
|
||||
packages/app-desktop/gui/MainScreen/commands/exportPdf.js.map
|
||||
packages/app-desktop/gui/MainScreen/commands/gotoAnything.d.ts
|
||||
packages/app-desktop/gui/MainScreen/commands/gotoAnything.js
|
||||
packages/app-desktop/gui/MainScreen/commands/gotoAnything.js.map
|
||||
packages/app-desktop/gui/MainScreen/commands/hideModalMessage.d.ts
|
||||
packages/app-desktop/gui/MainScreen/commands/hideModalMessage.js
|
||||
packages/app-desktop/gui/MainScreen/commands/hideModalMessage.js.map
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -210,6 +210,9 @@ packages/app-desktop/gui/MainScreen/commands/editAlarm.js.map
|
||||
packages/app-desktop/gui/MainScreen/commands/exportPdf.d.ts
|
||||
packages/app-desktop/gui/MainScreen/commands/exportPdf.js
|
||||
packages/app-desktop/gui/MainScreen/commands/exportPdf.js.map
|
||||
packages/app-desktop/gui/MainScreen/commands/gotoAnything.d.ts
|
||||
packages/app-desktop/gui/MainScreen/commands/gotoAnything.js
|
||||
packages/app-desktop/gui/MainScreen/commands/gotoAnything.js.map
|
||||
packages/app-desktop/gui/MainScreen/commands/hideModalMessage.d.ts
|
||||
packages/app-desktop/gui/MainScreen/commands/hideModalMessage.js
|
||||
packages/app-desktop/gui/MainScreen/commands/hideModalMessage.js.map
|
||||
|
@ -48,6 +48,7 @@ const CssUtils = require('@joplin/lib/CssUtils');
|
||||
const commands = [
|
||||
require('./gui/MainScreen/commands/editAlarm'),
|
||||
require('./gui/MainScreen/commands/exportPdf'),
|
||||
require('./gui/MainScreen/commands/gotoAnything'),
|
||||
require('./gui/MainScreen/commands/hideModalMessage'),
|
||||
require('./gui/MainScreen/commands/moveToFolder'),
|
||||
require('./gui/MainScreen/commands/newFolder'),
|
||||
@ -59,7 +60,6 @@ const commands = [
|
||||
require('./gui/MainScreen/commands/openTag'),
|
||||
require('./gui/MainScreen/commands/print'),
|
||||
require('./gui/MainScreen/commands/renameFolder'),
|
||||
require('./gui/MainScreen/commands/showShareFolderDialog'),
|
||||
require('./gui/MainScreen/commands/renameTag'),
|
||||
require('./gui/MainScreen/commands/search'),
|
||||
require('./gui/MainScreen/commands/selectTemplate'),
|
||||
@ -67,6 +67,8 @@ const commands = [
|
||||
require('./gui/MainScreen/commands/showModalMessage'),
|
||||
require('./gui/MainScreen/commands/showNoteContentProperties'),
|
||||
require('./gui/MainScreen/commands/showNoteProperties'),
|
||||
require('./gui/MainScreen/commands/showPrompt'),
|
||||
require('./gui/MainScreen/commands/showShareFolderDialog'),
|
||||
require('./gui/MainScreen/commands/showShareNoteDialog'),
|
||||
require('./gui/MainScreen/commands/showSpellCheckerMenu'),
|
||||
require('./gui/MainScreen/commands/toggleEditors'),
|
||||
@ -74,7 +76,6 @@ const commands = [
|
||||
require('./gui/MainScreen/commands/toggleNoteList'),
|
||||
require('./gui/MainScreen/commands/toggleSideBar'),
|
||||
require('./gui/MainScreen/commands/toggleVisiblePanes'),
|
||||
require('./gui/MainScreen/commands/showPrompt'),
|
||||
require('./gui/NoteEditor/commands/focusElementNoteBody'),
|
||||
require('./gui/NoteEditor/commands/focusElementNoteTitle'),
|
||||
require('./gui/NoteEditor/commands/showLocalSearch'),
|
||||
|
@ -111,15 +111,18 @@ const defaultLayout: LayoutItem = {
|
||||
const commands = [
|
||||
require('./commands/editAlarm'),
|
||||
require('./commands/exportPdf'),
|
||||
require('./commands/gotoAnything'),
|
||||
require('./commands/hideModalMessage'),
|
||||
require('./commands/moveToFolder'),
|
||||
require('./commands/newNote'),
|
||||
require('./commands/newFolder'),
|
||||
require('./commands/newNote'),
|
||||
require('./commands/newSubFolder'),
|
||||
require('./commands/newTodo'),
|
||||
require('./commands/openFolder'),
|
||||
require('./commands/openNote'),
|
||||
require('./commands/openTag'),
|
||||
require('./commands/print'),
|
||||
require('./commands/renameFolder'),
|
||||
require('./commands/showShareFolderDialog'),
|
||||
require('./commands/renameTag'),
|
||||
require('./commands/search'),
|
||||
require('./commands/selectTemplate'),
|
||||
@ -127,17 +130,15 @@ const commands = [
|
||||
require('./commands/showModalMessage'),
|
||||
require('./commands/showNoteContentProperties'),
|
||||
require('./commands/showNoteProperties'),
|
||||
require('./commands/showPrompt'),
|
||||
require('./commands/showShareFolderDialog'),
|
||||
require('./commands/showShareNoteDialog'),
|
||||
require('./commands/showSpellCheckerMenu'),
|
||||
require('./commands/toggleEditors'),
|
||||
require('./commands/toggleLayoutMoveMode'),
|
||||
require('./commands/toggleNoteList'),
|
||||
require('./commands/toggleSideBar'),
|
||||
require('./commands/toggleVisiblePanes'),
|
||||
require('./commands/toggleLayoutMoveMode'),
|
||||
require('./commands/openNote'),
|
||||
require('./commands/openFolder'),
|
||||
require('./commands/openTag'),
|
||||
require('./commands/showPrompt'),
|
||||
];
|
||||
|
||||
class MainScreenComponent extends React.Component<Props, State> {
|
||||
|
20
packages/app-desktop/gui/MainScreen/commands/gotoAnything.ts
Normal file
20
packages/app-desktop/gui/MainScreen/commands/gotoAnything.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { CommandRuntime, CommandDeclaration } from '@joplin/lib/services/CommandService';
|
||||
const PluginManager = require('@joplin/lib/services/PluginManager');
|
||||
|
||||
export const declaration: CommandDeclaration = {
|
||||
name: 'gotoAnything',
|
||||
};
|
||||
|
||||
export const runtime = (): CommandRuntime => {
|
||||
return {
|
||||
execute: async () => {
|
||||
return new Promise((resolve: Function, reject: Function) => {
|
||||
const menuItem = PluginManager.instance().menuItems().find((i: any) => i.id === 'controlledApi');
|
||||
menuItem.userData = {
|
||||
callback: { resolve, reject },
|
||||
};
|
||||
menuItem.click();
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
@ -802,6 +802,7 @@ function useMenu(props: Props) {
|
||||
// This is for GotoAnything only - should be refactored since this plugin manager is not used otherwise
|
||||
const pluginMenuItems = PluginManager.instance().menuItems();
|
||||
for (const item of pluginMenuItems) {
|
||||
if (!item.parent) continue;
|
||||
const itemParent = rootMenus[item.parent] ? rootMenus[item.parent] : 'tools';
|
||||
itemParent.submenu.push(separator());
|
||||
itemParent.submenu.push(item);
|
||||
|
@ -79,12 +79,15 @@ class Dialog extends React.PureComponent<Props, State> {
|
||||
private itemListRef: any;
|
||||
private listUpdateIID_: any;
|
||||
private markupToHtml_: any;
|
||||
private userCallback_: any = null;
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
|
||||
const startString = props?.userData?.startString ? props?.userData?.startString : '';
|
||||
|
||||
this.userCallback_ = props?.userData?.callback;
|
||||
|
||||
this.state = {
|
||||
query: startString,
|
||||
results: [],
|
||||
@ -398,6 +401,14 @@ class Dialog extends React.PureComponent<Props, State> {
|
||||
open: false,
|
||||
});
|
||||
|
||||
if (this.userCallback_) {
|
||||
this.userCallback_.resolve({
|
||||
type: this.state.listType,
|
||||
item: { ...item },
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.type === BaseModel.TYPE_COMMAND) {
|
||||
void CommandService.instance().execute(item.id, ...item.commandArgs);
|
||||
void focusEditorIfEditorCommand(item.id, CommandService.instance());
|
||||
@ -593,6 +604,9 @@ GotoAnything.manifest = {
|
||||
startString: ':',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'controlledApi',
|
||||
},
|
||||
],
|
||||
|
||||
};
|
||||
|
@ -96,7 +96,7 @@ class PluginManager {
|
||||
});
|
||||
};
|
||||
|
||||
item.accelerator = menuItems[i].accelerator();
|
||||
if (menuItems[i].accelerator) item.accelerator = menuItems[i].accelerator();
|
||||
|
||||
menuItems[i] = item;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user