mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
added a "script executor" ribbon widget
This commit is contained in:
parent
7a46159539
commit
ea006993f6
@ -76,6 +76,7 @@ import NoteRevisionsButton from "../widgets/buttons/note_revisions_button.js";
|
|||||||
import CodeButtonsWidget from "../widgets/floating_buttons/code_buttons.js";
|
import CodeButtonsWidget from "../widgets/floating_buttons/code_buttons.js";
|
||||||
import ApiLogWidget from "../widgets/api_log.js";
|
import ApiLogWidget from "../widgets/api_log.js";
|
||||||
import HideFloatingButtonsButton from "../widgets/floating_buttons/hide_floating_buttons_button.js";
|
import HideFloatingButtonsButton from "../widgets/floating_buttons/hide_floating_buttons_button.js";
|
||||||
|
import ScriptExecutorWidget from "../widgets/ribbon_widgets/script_executor.js";
|
||||||
|
|
||||||
export default class DesktopLayout {
|
export default class DesktopLayout {
|
||||||
constructor(customWidgets) {
|
constructor(customWidgets) {
|
||||||
@ -129,6 +130,7 @@ export default class DesktopLayout {
|
|||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
new RibbonContainer()
|
new RibbonContainer()
|
||||||
|
.ribbon(new ScriptExecutorWidget())
|
||||||
.ribbon(new SearchDefinitionWidget())
|
.ribbon(new SearchDefinitionWidget())
|
||||||
.ribbon(new EditedNotesWidget())
|
.ribbon(new EditedNotesWidget())
|
||||||
.ribbon(new BookPropertiesWidget())
|
.ribbon(new BookPropertiesWidget())
|
||||||
|
@ -82,7 +82,12 @@ function updateDisplayedShortcuts($container) {
|
|||||||
if (action) {
|
if (action) {
|
||||||
const title = $(el).attr('title');
|
const title = $(el).attr('title');
|
||||||
const shortcuts = action.effectiveShortcuts.join(', ');
|
const shortcuts = action.effectiveShortcuts.join(', ');
|
||||||
const newTitle = !title || !title.trim() ? shortcuts : `${title} (${shortcuts})`;
|
|
||||||
|
if (title?.includes(shortcuts)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newTitle = !title?.trim() ? shortcuts : `${title} (${shortcuts})`;
|
||||||
|
|
||||||
$(el).attr('title', newTitle);
|
$(el).attr('title', newTitle);
|
||||||
}
|
}
|
||||||
|
65
src/public/app/widgets/ribbon_widgets/script_executor.js
Normal file
65
src/public/app/widgets/ribbon_widgets/script_executor.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
||||||
|
import keyboardActionService from "../../services/keyboard_actions.js";
|
||||||
|
|
||||||
|
const TPL = `
|
||||||
|
<div class="script-runner-widget">
|
||||||
|
<style>
|
||||||
|
.script-runner-widget {
|
||||||
|
padding: 12px;
|
||||||
|
color: var(--muted-text-color);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="execute-description"></div>
|
||||||
|
|
||||||
|
<div style="display: flex; justify-content: space-around">
|
||||||
|
<button data-trigger-command="runActiveNote" class="execute-button btn btn-sm"></button>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
export default class ScriptExecutorWidget extends NoteContextAwareWidget {
|
||||||
|
isEnabled() {
|
||||||
|
return super.isEnabled()
|
||||||
|
&& this.note
|
||||||
|
&& (this.note.mime.startsWith('application/javascript') || this.isTriliumSqlite())
|
||||||
|
&& (this.note.hasLabel('executeDescription') || this.note.hasLabel('executeButton'));
|
||||||
|
}
|
||||||
|
|
||||||
|
isTriliumSqlite() {
|
||||||
|
return this.note.mime === 'text/x-sqlite;schema=trilium';
|
||||||
|
}
|
||||||
|
|
||||||
|
getTitle() {
|
||||||
|
return {
|
||||||
|
show: this.isEnabled(),
|
||||||
|
activate: true,
|
||||||
|
title: this.isTriliumSqlite() ? 'Query' : 'Script',
|
||||||
|
icon: 'bx bx-run'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
doRender() {
|
||||||
|
this.$widget = $(TPL);
|
||||||
|
this.contentSized();
|
||||||
|
|
||||||
|
this.$executeButton = this.$widget.find('.execute-button');
|
||||||
|
this.$executeDescription = this.$widget.find('.execute-description');
|
||||||
|
}
|
||||||
|
|
||||||
|
async refreshWithNote(note) {
|
||||||
|
const executeTitle = note.getLabelValue('executeButton')
|
||||||
|
|| (this.isTriliumSqlite() ? 'Execute Query' : 'Execute Script');
|
||||||
|
|
||||||
|
this.$executeButton.text(executeTitle);
|
||||||
|
this.$executeButton.attr('title', executeTitle);
|
||||||
|
keyboardActionService.updateDisplayedShortcuts(this.$widget);console.trace("ZZZ");
|
||||||
|
|
||||||
|
const executeDescription = note.getLabelValue('executeDescription');
|
||||||
|
|
||||||
|
if (executeDescription) {
|
||||||
|
this.$executeDescription.show().html(executeDescription);
|
||||||
|
} else {
|
||||||
|
this.$executeDescription.empty().hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -61,6 +61,8 @@ module.exports = [
|
|||||||
{ type: 'label', name: 'toc' },
|
{ type: 'label', name: 'toc' },
|
||||||
{ type: 'label', name: 'color' },
|
{ type: 'label', name: 'color' },
|
||||||
{ type: 'label', name: 'keepCurrentHoisting'},
|
{ type: 'label', name: 'keepCurrentHoisting'},
|
||||||
|
{ type: 'label', name: 'executeButton'},
|
||||||
|
{ type: 'label', name: 'executeDescription'},
|
||||||
|
|
||||||
// relation names
|
// relation names
|
||||||
{ type: 'relation', name: 'internalLink' },
|
{ type: 'relation', name: 'internalLink' },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user