/* readme
create one javascript front type code note in your trilium which contain
below javascript code , and add the #widget attribute to it .
*/
async function OpenLocalPath(event) {
// Check if the event was a Ctrl+double click.
if (event.ctrlKey) {
var path = event.target.innerText;
console.log(`>> ctrl + double_click get line content:\n${path}`)
//------ Check if the text content contain a file path. ------
if (/[A-Z]:\\.*/.test(path)) {
var path = path.match(/[A-Z]:\\.*/)[0]
console.log(`>> Open local path: ${path}`)
// Use the PathLinkerApi to open the file at the path.
await document.PathLinkerApi.runAsyncOnBackendWithManualTransactionHandling(async (path) => {
const shell = require('electron').shell;
await shell.openPath(path);
return;
}, [path]);
}
}
}
const TEMPLATE = `
<div style="padding: 10px; border-top: 1px solid var(--main-border-color); contain: none;">
<script>
${OpenLocalPath.toString()}
document.addEventListener('dblclick', OpenLocalPath);
</script>
</div>`;
class PathLinkerWidget extends api.NoteContextAwareWidget {
constructor(...args) {
super(...args);
this.balloonEditorCreate = null;
}
get position() {
// higher value means position towards the bottom/right
return 100;
}
get parentWidget() { return 'center-pane'; }
doRender() {
this.$widget = $(TEMPLATE);
this.$widget.hide();
// store API in document to access it from callback
document.PathLinkerApi = api;
return this.$widget;
}
}
let widget = new PathLinkerWidget();
console.log(">> Loaded PathLinkerWidget");
module.exports = widget;