import NoteContextAwareWidget from "../note_context_aware_widget.js"; import utils from "../../services/utils.js"; const TPL = ` `; export default class NoteActionsWidget extends NoteContextAwareWidget { doRender() { this.$widget = $(TPL); this.$showSourceButton = this.$widget.find('.show-source-button'); this.$renderNoteButton = this.$widget.find('.render-note-button'); this.$exportNoteButton = this.$widget.find('.export-note-button'); this.$exportNoteButton.on("click", () => { if (this.$exportNoteButton.hasClass("disabled")) { return; } import('../../dialogs/export.js').then(d => d.showDialog(this.noteContext.notePath, 'single')); }); this.$importNoteButton = this.$widget.find('.import-files-button'); this.$importNoteButton.on("click", () => import('../../dialogs/import.js').then(d => d.showDialog(this.noteId))); this.$widget.on('click', '.dropdown-item', () => this.$widget.find('.dropdown-menu').dropdown('toggle')); this.$openNoteExternallyButton = this.$widget.find(".open-note-externally-button"); } refreshWithNote(note) { this.toggleDisabled(this.$showSourceButton, ['text', 'relation-map', 'search', 'code'].includes(note.type)); this.$renderNoteButton.toggle(note.type === 'render'); this.$openNoteExternallyButton.toggle(utils.isElectron()); } toggleDisabled($el, enable) { if (enable) { $el.removeAttr('disabled'); } else { $el.attr('disabled', 'disabled'); } } entitiesReloadedEvent({loadResults}) { if (loadResults.isNoteReloaded(this.noteId)) { this.refresh(); } } }