mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +02:00
Plugins: Add the openNote, openFolder and openTag commands
This commit is contained in:
parent
de47cff86d
commit
52d5c32950
@ -106,6 +106,9 @@ ElectronClient/gui/MainScreen/commands/moveToFolder.js
|
||||
ElectronClient/gui/MainScreen/commands/newFolder.js
|
||||
ElectronClient/gui/MainScreen/commands/newNote.js
|
||||
ElectronClient/gui/MainScreen/commands/newTodo.js
|
||||
ElectronClient/gui/MainScreen/commands/openFolder.js
|
||||
ElectronClient/gui/MainScreen/commands/openNote.js
|
||||
ElectronClient/gui/MainScreen/commands/openTag.js
|
||||
ElectronClient/gui/MainScreen/commands/print.js
|
||||
ElectronClient/gui/MainScreen/commands/renameFolder.js
|
||||
ElectronClient/gui/MainScreen/commands/renameTag.js
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -100,6 +100,9 @@ ElectronClient/gui/MainScreen/commands/moveToFolder.js
|
||||
ElectronClient/gui/MainScreen/commands/newFolder.js
|
||||
ElectronClient/gui/MainScreen/commands/newNote.js
|
||||
ElectronClient/gui/MainScreen/commands/newTodo.js
|
||||
ElectronClient/gui/MainScreen/commands/openFolder.js
|
||||
ElectronClient/gui/MainScreen/commands/openNote.js
|
||||
ElectronClient/gui/MainScreen/commands/openTag.js
|
||||
ElectronClient/gui/MainScreen/commands/print.js
|
||||
ElectronClient/gui/MainScreen/commands/renameFolder.js
|
||||
ElectronClient/gui/MainScreen/commands/renameTag.js
|
||||
|
3
.ignore
3
.ignore
@ -49,6 +49,9 @@ ElectronClient/gui/MainScreen/commands/moveToFolder.js
|
||||
ElectronClient/gui/MainScreen/commands/newFolder.js
|
||||
ElectronClient/gui/MainScreen/commands/newNote.js
|
||||
ElectronClient/gui/MainScreen/commands/newTodo.js
|
||||
ElectronClient/gui/MainScreen/commands/openFolder.js
|
||||
ElectronClient/gui/MainScreen/commands/openNote.js
|
||||
ElectronClient/gui/MainScreen/commands/openTag.js
|
||||
ElectronClient/gui/MainScreen/commands/print.js
|
||||
ElectronClient/gui/MainScreen/commands/renameFolder.js
|
||||
ElectronClient/gui/MainScreen/commands/renameTag.js
|
||||
|
@ -61,6 +61,9 @@ const commands = [
|
||||
require('./gui/MainScreen/commands/toggleSideBar'),
|
||||
require('./gui/MainScreen/commands/toggleVisiblePanes'),
|
||||
require('./gui/MainScreen/commands/toggleEditors'),
|
||||
require('./gui/MainScreen/commands/openNote'),
|
||||
require('./gui/MainScreen/commands/openFolder'),
|
||||
require('./gui/MainScreen/commands/openTag'),
|
||||
require('./gui/NoteEditor/commands/focusElementNoteBody'),
|
||||
require('./gui/NoteEditor/commands/focusElementNoteTitle'),
|
||||
require('./gui/NoteEditor/commands/showLocalSearch'),
|
||||
|
@ -63,6 +63,9 @@ const commands = [
|
||||
require('./commands/toggleNoteList'),
|
||||
require('./commands/toggleSideBar'),
|
||||
require('./commands/toggleVisiblePanes'),
|
||||
require('./commands/openNote'),
|
||||
require('./commands/openFolder'),
|
||||
require('./commands/openTag'),
|
||||
];
|
||||
|
||||
class MainScreenComponent extends React.Component<any, any> {
|
||||
|
16
ElectronClient/gui/MainScreen/commands/openFolder.ts
Normal file
16
ElectronClient/gui/MainScreen/commands/openFolder.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { CommandRuntime, CommandDeclaration, CommandContext } from 'lib/services/CommandService';
|
||||
|
||||
export const declaration:CommandDeclaration = {
|
||||
name: 'openFolder',
|
||||
};
|
||||
|
||||
export const runtime = ():CommandRuntime => {
|
||||
return {
|
||||
execute: async (context:CommandContext, folderId:string) => {
|
||||
context.dispatch({
|
||||
type: 'FOLDER_SELECT',
|
||||
id: folderId,
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
26
ElectronClient/gui/MainScreen/commands/openNote.ts
Normal file
26
ElectronClient/gui/MainScreen/commands/openNote.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { CommandRuntime, CommandDeclaration, CommandContext } from 'lib/services/CommandService';
|
||||
const Note = require('lib/models/Note');
|
||||
const Folder = require('lib/models/Folder');
|
||||
|
||||
export const declaration:CommandDeclaration = {
|
||||
name: 'openNote',
|
||||
};
|
||||
|
||||
export const runtime = ():CommandRuntime => {
|
||||
return {
|
||||
execute: async (context:CommandContext, noteId:string, hash:string = null) => {
|
||||
const note = await Note.load(noteId);
|
||||
if (!note) throw new Error(`No such note: ${noteId}`);
|
||||
|
||||
const folder = await Folder.load(note.parent_id);
|
||||
if (!folder) throw new Error(`Note parent notebook does not exist: ${JSON.stringify(note)}`);
|
||||
|
||||
context.dispatch({
|
||||
type: 'FOLDER_AND_NOTE_SELECT',
|
||||
folderId: folder.id,
|
||||
noteId: note.id,
|
||||
hash,
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
16
ElectronClient/gui/MainScreen/commands/openTag.ts
Normal file
16
ElectronClient/gui/MainScreen/commands/openTag.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { CommandRuntime, CommandDeclaration, CommandContext } from 'lib/services/CommandService';
|
||||
|
||||
export const declaration:CommandDeclaration = {
|
||||
name: 'openTag',
|
||||
};
|
||||
|
||||
export const runtime = ():CommandRuntime => {
|
||||
return {
|
||||
execute: async (context:CommandContext, tagId:string) => {
|
||||
context.dispatch({
|
||||
type: 'TAG_SELECT',
|
||||
id: tagId,
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
@ -2,4 +2,5 @@ import { AppState } from '../../app';
|
||||
|
||||
export interface DesktopCommandContext {
|
||||
state: AppState,
|
||||
dispatch: Function,
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ type EnabledCondition = string;
|
||||
export interface CommandContext {
|
||||
// The state may also be of type "AppState" (used by the desktop app), which inherits from "State" (used by all apps)
|
||||
state: State,
|
||||
dispatch: Function,
|
||||
}
|
||||
|
||||
export interface CommandRuntime {
|
||||
@ -203,10 +204,20 @@ export default class CommandService extends BaseService {
|
||||
delete command.runtime;
|
||||
}
|
||||
|
||||
private createContext():CommandContext {
|
||||
return {
|
||||
state: this.store_.getState(),
|
||||
dispatch: (action:any) => {
|
||||
this.store_.dispatch(action);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
public async execute(commandName:string, ...args:any[]):Promise<any | void> {
|
||||
const command = this.commandByName(commandName);
|
||||
this.logger().info('CommandService::execute:', commandName, args);
|
||||
return command.runtime.execute({ state: this.store_.getState() }, ...args);
|
||||
if (!command.runtime) throw new Error(`Cannot execute a command without a runtime: ${commandName}`);
|
||||
return command.runtime.execute(this.createContext(), ...args);
|
||||
}
|
||||
|
||||
public scheduleExecute(commandName:string, args:any) {
|
||||
|
Loading…
Reference in New Issue
Block a user