diff --git a/example-script/info.json b/example-script/info.json index b691408..f7d10ce 100644 --- a/example-script/info.json +++ b/example-script/info.json @@ -3,5 +3,5 @@ "identifier": "example-script", "script": "example-script.qml", "version": "0.0.1", - "description" : "Use this script to start a new script you want to submit to the script repository.\n\nJust copy the whole example-script folder from the git-repository on GitHub and rename both the folder and example-script.qml." + "description" : "Use this script to start a new script you want to submit to the script repository.\n\nJust copy the whole example-script folder from the git-repository on GitHub and rename both the folder and example-script.qml." } diff --git a/favorite-note/favorite-note.qml b/favorite-note/favorite-note.qml new file mode 100644 index 0000000..268e870 --- /dev/null +++ b/favorite-note/favorite-note.qml @@ -0,0 +1,29 @@ +import QtQml 2.0 + +/** + * This script creates a menu item and a button that adds a "favorite" tag to the current note + */ +QtObject { + /** + * Initializes the custom action + */ + function init() { + // create the menu entry + script.registerCustomAction("favoriteNote", "Favorite note", "fav", "bookmark-new"); + } + + /** + * 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) { + switch (identifier) { + // add a "favorite" tag to the current note + case "favoriteNote": + script.tagCurrentNote("favorite"); + break; + } + } +} diff --git a/favorite-note/info.json b/favorite-note/info.json new file mode 100644 index 0000000..16d5795 --- /dev/null +++ b/favorite-note/info.json @@ -0,0 +1,7 @@ +{ + "name": "Favorite note", + "identifier": "favorite-note", + "script": "favorite-note.qml", + "version": "0.1", + "description" : "This script creates a menu item and a button that adds a \"favorite\" tag to the current note." +} diff --git a/journal-entry/info.json b/journal-entry/info.json new file mode 100644 index 0000000..f84ed73 --- /dev/null +++ b/journal-entry/info.json @@ -0,0 +1,7 @@ +{ + "name": "Journal entry", + "identifier": "journal-entry", + "script": "journal-entry.qml", + "version": "0.1", + "description" : "This script creates a menu item and a button to create or jump to the current date's journal entry." +} diff --git a/journal-entry/journal-entry.qml b/journal-entry/journal-entry.qml new file mode 100644 index 0000000..ef089b6 --- /dev/null +++ b/journal-entry/journal-entry.qml @@ -0,0 +1,45 @@ +import QtQml 2.0 +import com.qownnotes.noteapi 1.0 + +/** + * This script creates a menu item and a button to create or jump to the current date's journal entry + */ +QtObject { + /** + * Initializes the custom action + */ + function init() { + script.registerCustomAction("journalEntry", "Create or open a journal entry", "Journal", "document-new"); + } + + /** + * 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 != "journalEntry") { + return; + } + + // get the date headline + var m = new Date(); + var headline = m.getFullYear() + ("0" + (m.getMonth()+1)).slice(-2) + ("0" + m.getDate()).slice(-2); + + var fileName = headline + ".md"; + var note = script.fetchNoteByFileName(fileName); + + // check if note was found + if (note.id > 0) { + // jump to the note if it was found + script.log("found journal entry: " + headline); + script.setCurrentNote(note); + } else { + // create a new journal entry note if it wasn't found + // keep in mind that the note will not be created instantly on the disk + script.log("creating new journal entry: " + headline); + script.createNote(headline + "\n========\n\n"); + } + } +}