mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop: Expose prompt to plugins as a command (#5058)
This commit is contained in:
parent
01e6ca4616
commit
c5c38a323f
@ -278,6 +278,9 @@ packages/app-desktop/gui/MainScreen/commands/showNoteContentProperties.js.map
|
||||
packages/app-desktop/gui/MainScreen/commands/showNoteProperties.d.ts
|
||||
packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js
|
||||
packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js.map
|
||||
packages/app-desktop/gui/MainScreen/commands/showPrompt.d.ts
|
||||
packages/app-desktop/gui/MainScreen/commands/showPrompt.js
|
||||
packages/app-desktop/gui/MainScreen/commands/showPrompt.js.map
|
||||
packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.d.ts
|
||||
packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js
|
||||
packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js.map
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -264,6 +264,9 @@ packages/app-desktop/gui/MainScreen/commands/showNoteContentProperties.js.map
|
||||
packages/app-desktop/gui/MainScreen/commands/showNoteProperties.d.ts
|
||||
packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js
|
||||
packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js.map
|
||||
packages/app-desktop/gui/MainScreen/commands/showPrompt.d.ts
|
||||
packages/app-desktop/gui/MainScreen/commands/showPrompt.js
|
||||
packages/app-desktop/gui/MainScreen/commands/showPrompt.js.map
|
||||
packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.d.ts
|
||||
packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js
|
||||
packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js.map
|
||||
|
@ -74,6 +74,7 @@ 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'),
|
||||
|
@ -135,6 +135,7 @@ const commands = [
|
||||
require('./commands/openNote'),
|
||||
require('./commands/openFolder'),
|
||||
require('./commands/openTag'),
|
||||
require('./commands/showPrompt'),
|
||||
];
|
||||
|
||||
class MainScreenComponent extends React.Component<Props, State> {
|
||||
|
41
packages/app-desktop/gui/MainScreen/commands/showPrompt.ts
Normal file
41
packages/app-desktop/gui/MainScreen/commands/showPrompt.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
|
||||
|
||||
export const declaration: CommandDeclaration = {
|
||||
name: 'showPrompt',
|
||||
};
|
||||
|
||||
enum PromptInputType {
|
||||
Dropdown = 'dropdown',
|
||||
Datetime = 'datetime',
|
||||
Tags = 'tags',
|
||||
Text = 'text',
|
||||
}
|
||||
|
||||
interface PromptConfig {
|
||||
label: string;
|
||||
inputType?: PromptInputType;
|
||||
value?: any;
|
||||
autocomplete?: any[];
|
||||
buttons?: string[];
|
||||
}
|
||||
|
||||
export const runtime = (comp: any): CommandRuntime => {
|
||||
return {
|
||||
execute: async (_context: CommandContext, config: PromptConfig) => {
|
||||
return new Promise((resolve) => {
|
||||
comp.setState({
|
||||
promptOptions: {
|
||||
...config,
|
||||
onClose: async (answer: any, buttonType: string) => {
|
||||
comp.setState({ promptOptions: null });
|
||||
resolve({
|
||||
answer: answer,
|
||||
buttonType: buttonType,
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue
Block a user