1
0
Fork 0
mirror of https://github.com/marty-oehme/scripts.git synced 2024-12-23 00:18:10 +00:00
qownnotes-scripts/scribble/scribble.qml

80 lines
2.8 KiB
QML
Raw Normal View History

2018-03-06 16:16:27 +00:00
import QtQml 2.0
import QOwnNotesTypes 1.0
/**
2018-03-06 17:13:20 +00:00
* This script adds a menu entry to the context menu of the note edit to insert a
* scribble image to the media-folder, that will be edited by an external image editor
*
* The path of the image editor and the image template can be selected in the script settings of the script
2018-03-06 16:16:27 +00:00
*/
Script {
property string executablePath;
property string imagePath;
2018-03-06 17:13:20 +00:00
property bool executeInBackground;
2018-03-06 16:16:27 +00:00
// the path to the script's directory will be set here
property string scriptDirPath;
// register your settings variables so the user can set them in the script settings
property variant settingsVariables: [
{
"identifier": "executablePath",
2018-03-06 17:13:20 +00:00
"name": "Path of external image editor",
2018-03-06 16:16:27 +00:00
"description": "Please select the path of the executable:",
"type": "file",
"default": "gimp",
},
{
"identifier": "imagePath",
"name": "Path of template image",
"description": "Please select the path of the template image:",
"type": "file",
"default": scriptDirPath + "/scribble.png",
2018-03-06 17:13:20 +00:00
},
{
"identifier": "executeInBackground",
"name": "Execute image editor in background",
"description": "If the image editor is executed in the background you will be able to work with QOwnNotes while you are editing the scribble, but the note preview will not be refreshed automatically after you close the image editor.",
"text": "Execute in background",
"type": "boolean",
"default": false,
2018-03-06 16:16:27 +00:00
}
];
/**
* Initializes the custom actions
*/
function init() {
script.registerCustomAction("scribble", "Add scribble", "Scribble", "view-preview", true, false, false);
}
/**
* This function is invoked when a custom action is triggered
* in the menu or via button
*
* @param identifier string the identifier defined in registerCustomAction
*/
function customActionInvoked(identifier) {
if (identifier != "scribble") {
return;
}
// insert the scribble template image as media file
2018-03-06 17:13:20 +00:00
var mediaFile = script.insertMediaFile(imagePath, true);
2018-03-06 16:16:27 +00:00
var mediaFilePath = mediaFile.replace("file://media", script.currentNoteFolderPath() + "/media");
// write the scribble image to the note
2018-03-06 17:13:20 +00:00
script.noteTextEditWrite("![scribble](" + mediaFile + ")\n");
var params = [mediaFilePath];
2018-03-06 16:16:27 +00:00
// edit the scribble image
2018-03-06 17:13:20 +00:00
if (executeInBackground) {
script.startDetachedProcess(executablePath, params);
} else {
script.startSynchronousProcess(executablePath, params);
script.regenerateNotePreview();
}
2018-03-06 16:16:27 +00:00
}
}