mirror of
https://github.com/zadam/trilium.git
synced 2025-11-15 09:45:52 +01:00
fix "Render note" and "Execute script" buttons + refactoring around data-trigger-command handling
This commit is contained in:
@@ -18,17 +18,14 @@ const WIDGET_TPL = `
|
||||
|
||||
<a data-trigger-command="collapseTree"
|
||||
title="Collapse note tree"
|
||||
data-command="collapseTree"
|
||||
class="icon-action bx bx-layer-minus"></a>
|
||||
|
||||
<a data-trigger-command="scrollToActiveNote"
|
||||
title="Scroll to active note"
|
||||
data-command="scrollToActiveNote"
|
||||
title="Scroll to active note"
|
||||
class="icon-action bx bx-crosshair"></a>
|
||||
|
||||
<a data-trigger-command="searchNotes"
|
||||
title="Search in notes"
|
||||
data-command="searchNotes"
|
||||
class="icon-action bx bx-search"></a>
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -3,10 +3,12 @@ import TabAwareWidget from "./tab_aware_widget.js";
|
||||
const TPL = `
|
||||
<div style="display: inline-flex;">
|
||||
<button class="btn btn-sm icon-button bx bx-play-circle render-button"
|
||||
data-trigger-command="renderActiveNote"
|
||||
title="Render"></button>
|
||||
|
||||
<button class="btn btn-sm icon-button bx bx-play-circle execute-script-button"
|
||||
title="Execute (Ctrl+Enter)"></button>
|
||||
data-trigger-command="runActiveNote"
|
||||
title="Execute"></button>
|
||||
</div>`;
|
||||
|
||||
export default class RunScriptButtonsWidget extends TabAwareWidget {
|
||||
@@ -21,7 +23,7 @@ export default class RunScriptButtonsWidget extends TabAwareWidget {
|
||||
|
||||
refreshWithNote(note) {
|
||||
this.$renderButton.toggle(note.type === 'render');
|
||||
this.$executeScriptButton.toggle(note.mime.startsWith('application/javascript'));
|
||||
this.$executeScriptButton.toggle(note.type === 'code' && note.mime.startsWith('application/javascript'));
|
||||
}
|
||||
|
||||
async entitiesReloadedEvent({loadResults}) {
|
||||
|
||||
@@ -29,11 +29,11 @@ const TAB_TPL = `
|
||||
<div class="note-tab-wrapper">
|
||||
<div class="note-tab-title"></div>
|
||||
<div class="note-tab-drag-handle"></div>
|
||||
<div class="note-tab-close kb-in-title" title="Close tab" data-command="closeActiveTab"><span>×</span></div>
|
||||
<div class="note-tab-close" title="Close tab" data-trigger-command="closeActiveTab"><span>×</span></div>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
const NEW_TAB_BUTTON_TPL = `<div class="note-new-tab kb-in-title" data-command="openNewTab" title="Add new tab">+</div>`;
|
||||
const NEW_TAB_BUTTON_TPL = `<div class="note-new-tab" data-trigger-command="openNewTab" title="Add new tab">+</div>`;
|
||||
const FILLER_TPL = `<div class="tab-row-filler">
|
||||
<div class="tab-row-border"></div>
|
||||
</div>`;
|
||||
@@ -394,10 +394,13 @@ export default class TabRowWidget extends BasicWidget {
|
||||
this.setupDraggabilly();
|
||||
}
|
||||
|
||||
setTabCloseEvent($tab) {
|
||||
$tab.find('.note-tab-close')
|
||||
.on('click', _ => appContext.tabManager.removeTab($tab.attr('data-tab-id')));
|
||||
closeActiveTabCommand({$el}) {
|
||||
const tabId = $el.closest(".note-tab").attr('data-tab-id');
|
||||
|
||||
appContext.tabManager.removeTab(tabId);
|
||||
}
|
||||
|
||||
setTabCloseEvent($tab) {
|
||||
$tab.on('mousedown', e => {
|
||||
if (e.which === 2) {
|
||||
appContext.tabManager.removeTab($tab.attr('data-tab-id'));
|
||||
@@ -558,8 +561,6 @@ export default class TabRowWidget extends BasicWidget {
|
||||
this.$newTab = $(NEW_TAB_BUTTON_TPL);
|
||||
|
||||
this.$tabContainer.append(this.$newTab);
|
||||
|
||||
this.$newTab.on('click', _ => this.triggerCommand('openNewTab'));
|
||||
}
|
||||
|
||||
setupFiller() {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import libraryLoader from "../../services/library_loader.js";
|
||||
import bundleService from "../../services/bundle.js";
|
||||
import toastService from "../../services/toast.js";
|
||||
import server from "../../services/server.js";
|
||||
import keyboardActionService from "../../services/keyboard_actions.js";
|
||||
import TypeWidget from "./type_widget.js";
|
||||
import keyboardActionService from "../../services/keyboard_actions.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="note-detail-code note-detail-printable">
|
||||
@@ -27,11 +24,8 @@ export default class EditableCodeTypeWidget extends TypeWidget {
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.$editor = this.$widget.find('.note-detail-code-editor');
|
||||
this.$executeScriptButton = this.$widget.find(".execute-script-button");
|
||||
|
||||
keyboardActionService.setElementActionHandler(this.$widget, 'runActiveNote', () => this.executeCurrentNote());
|
||||
|
||||
this.$executeScriptButton.on('click', () => this.executeCurrentNote());
|
||||
keyboardActionService.setupActionsForElement('code-detail', this.$widget, this);
|
||||
|
||||
this.initialized = this.initEditor();
|
||||
|
||||
@@ -106,26 +100,6 @@ export default class EditableCodeTypeWidget extends TypeWidget {
|
||||
this.codeEditor.focus();
|
||||
}
|
||||
|
||||
async executeCurrentNote() {
|
||||
// ctrl+enter is also used elsewhere so make sure we're running only when appropriate
|
||||
if (this.note.type !== 'code') {
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure note is saved so we load latest changes
|
||||
await this.spacedUpdate.updateNowIfNecessary();
|
||||
|
||||
if (this.note.mime.endsWith("env=frontend")) {
|
||||
await bundleService.getAndExecuteBundle(this.noteId);
|
||||
}
|
||||
|
||||
if (this.note.mime.endsWith("env=backend")) {
|
||||
await server.post('script/run/' + this.noteId);
|
||||
}
|
||||
|
||||
toastService.showMessage("Note executed");
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
if (this.codeEditor) {
|
||||
this.spacedUpdate.allowUpdateWithoutChange(() => {
|
||||
|
||||
@@ -25,9 +25,6 @@ export default class RenderTypeWidget extends TypeWidget {
|
||||
this.$widget = $(TPL);
|
||||
this.$noteDetailRenderHelp = this.$widget.find('.note-detail-render-help');
|
||||
this.$noteDetailRenderContent = this.$widget.find('.note-detail-render-content');
|
||||
this.$renderButton = this.$widget.find('.render-button');
|
||||
|
||||
this.$renderButton.on('click', () => this.refresh());
|
||||
|
||||
return this.$widget;
|
||||
}
|
||||
@@ -46,4 +43,10 @@ export default class RenderTypeWidget extends TypeWidget {
|
||||
cleanup() {
|
||||
this.$noteDetailRenderContent.empty();
|
||||
}
|
||||
|
||||
renderActiveNoteEvent() {
|
||||
if (this.tabContext.isActive()) {
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user