一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
33 行
1.4 KiB
TypeScript
33 行
1.4 KiB
TypeScript
import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
|
|
import { _ } from '@joplin/lib/locale';
|
|
import { stateUtils } from '@joplin/lib/reducer';
|
|
import ExternalEditWatcher from '@joplin/lib/services/ExternalEditWatcher';
|
|
import Note from '@joplin/lib/models/Note';
|
|
import isNoteLockEnabled from '@joplin/lib/services/noteLock/isNoteLockEnabled';
|
|
import bridge from '../services/bridge';
|
|
|
|
export const declaration: CommandDeclaration = {
|
|
name: 'startExternalEditing',
|
|
label: () => _('Open in external editor'),
|
|
iconName: 'icon-share',
|
|
};
|
|
|
|
export const runtime = (): CommandRuntime => {
|
|
return {
|
|
execute: async (context: CommandContext, noteId: string = null) => {
|
|
noteId = noteId || stateUtils.selectedNoteId(context.state);
|
|
|
|
try {
|
|
const note = await Note.load(noteId);
|
|
// The enabled condition can be bypassed when the command is executed directly (e.g. via
|
|
// toggleExternalEditing): the external editor would get ciphertext, or write plaintext to disk.
|
|
if (isNoteLockEnabled() && note.is_locked) throw new Error(_('Locked notes cannot be opened in an external editor'));
|
|
void ExternalEditWatcher.instance().openAndWatch(note);
|
|
} catch (error) {
|
|
bridge().showErrorMessageBox(_('Error opening note in editor: %s', error.message));
|
|
}
|
|
},
|
|
enabledCondition: 'oneNoteSelected && !noteIsReadOnly && !noteIsLocked',
|
|
};
|
|
};
|