1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00
joplin/packages/app-desktop/gui/NoteEditor/editorCommandDeclarations.ts

166 lines
3.2 KiB
TypeScript
Raw Normal View History

import { CommandDeclaration } from '@joplin/lib/services/CommandService';
import { _ } from '@joplin/lib/locale';
import { joplinCommandToTinyMceCommands } from './NoteBody/TinyMCE/utils/joplinCommandToTinyMceCommands';
const workWithHtmlNotes = [
'attachFile',
];
export const enabledCondition = (commandName: string) => {
const markdownEditorOnly = !Object.keys(joplinCommandToTinyMceCommands).includes(commandName);
const noteMustBeMarkdown = !workWithHtmlNotes.includes(commandName);
const output = [
// gotoAnythingVisible: Enable if the command palette (which is a modal dialog) is visible
'(!modalDialogVisible || gotoAnythingVisible)',
markdownEditorOnly ? 'markdownEditorPaneVisible' : '(markdownEditorPaneVisible || richTextEditorVisible)',
'oneNoteSelected',
noteMustBeMarkdown ? 'noteIsMarkdown' : '',
'!noteIsReadOnly',
];
return output.filter(c => !!c).join(' && ');
};
const declarations: CommandDeclaration[] = [
{
name: 'insertText',
},
{
name: 'scrollToHash',
},
{
name: 'textCopy',
label: () => _('Copy'),
role: 'copy',
},
{
name: 'textCut',
label: () => _('Cut'),
role: 'cut',
},
{
name: 'textPaste',
label: () => _('Paste'),
role: 'paste',
},
{
name: 'textSelectAll',
label: () => _('Select all'),
role: 'selectAll',
},
{
name: 'textBold',
label: () => _('Bold'),
2020-09-15 15:01:07 +02:00
iconName: 'icon-bold',
},
{
name: 'textItalic',
label: () => _('Italic'),
2020-09-15 15:01:07 +02:00
iconName: 'icon-italic',
},
{
name: 'textLink',
label: () => _('Hyperlink'),
2020-09-15 15:01:07 +02:00
iconName: 'icon-link',
},
{
name: 'textCode',
label: () => _('Code'),
2020-09-15 15:01:07 +02:00
iconName: 'icon-code',
},
{
name: 'attachFile',
label: () => _('Attach file'),
2020-09-15 15:01:07 +02:00
iconName: 'icon-attachment',
},
{
name: 'textNumberedList',
label: () => _('Numbered List'),
2020-09-15 15:01:07 +02:00
iconName: 'icon-numbered-list',
},
{
name: 'textBulletedList',
label: () => _('Bulleted List'),
2020-09-15 15:01:07 +02:00
iconName: 'icon-bulleted-list',
},
{
name: 'textCheckbox',
label: () => _('Checkbox'),
2020-09-15 15:01:07 +02:00
iconName: 'icon-to-do-list',
},
{
name: 'textHeading',
label: () => _('Heading'),
2020-09-15 15:01:07 +02:00
iconName: 'icon-heading',
},
{
name: 'textHorizontalRule',
label: () => _('Horizontal Rule'),
2020-09-15 15:01:07 +02:00
iconName: 'fas fa-ellipsis-h',
},
{
name: 'insertDateTime',
label: () => _('Insert time'),
2020-09-15 15:01:07 +02:00
iconName: 'icon-add-date',
},
{
name: 'editor.deleteLine',
label: () => _('Delete line'),
},
{
name: 'editor.duplicateLine',
label: () => _('Duplicate line'),
},
{
name: 'editor.undo',
label: () => _('Editor: %s', _('Undo')),
},
{
name: 'editor.redo',
label: () => _('Editor: %s', _('Redo')),
},
{
name: 'editor.indentLess',
label: () => _('Indent less'),
},
{
name: 'editor.indentMore',
label: () => _('Indent more'),
},
{
name: 'editor.toggleComment',
label: () => _('Toggle comment'),
},
{
name: 'editor.sortSelectedLines',
label: () => _('Sort selected lines'),
},
{
name: 'editor.swapLineUp',
label: () => _('Swap line up'),
},
{
name: 'editor.swapLineDown',
label: () => _('Swap line down'),
},
{
name: 'selectedText',
},
{
name: 'replaceSelection',
},
{
name: 'editor.setText',
},
{
name: 'editor.focus',
},
{
name: 'editor.execCommand',
},
];
export default declarations;