Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions new-note-namer/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "New note namer",
"identifier": "new-note-namer",
"script": "new-note-namer.qml",
"authors": ["@diegovskytl"],
"platforms": ["linux", "macos", "windows"],
"version": "0.0.1",
"minAppVersion": "17.06.2",
"description": "Enables a dialog window (or two) so the user can choose the note title and file name at the moment of creation. <br> Specially useful when the 'Allow note file name to be different to note title. \n No more cumbersome renaming :)"
}
73 changes: 73 additions & 0 deletions new-note-namer/new-note-namer.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import QtQml 2.0
import QOwnNotesTypes 1.0

/**
* This script allows to set both the title and headline of a new note.
Recommended for when "headline == file name" option is enabled.
Avoids cumbersome renaming and title editing.
*/
QtObject {
property bool extraDialogForFileName;
property variant settingsVariables: [
{
'identifier': 'extraDialogForFileName',
'name': 'Extra dialog for note title',
'description': 'Show an additional dialog window so user can write a file name different to the note title.',
'type': 'boolean',
'default': 'false',
},
];

function init() {
script.log("New-note-namer active");
}

function newNamer(title, message, defaultText) {
var name = script.inputDialogGetText(
title, message, defaultText);

script.log("input name: " + name);

if (name == "" || name == null){
name = defaultText;
}

return name;
}

function handleNewNoteHeadlineHook(note) {

var newName = newNamer("New note", "New note title", "Title");
script.log(note.fileCreated)
script.log(note.fileLastModified)

return "# " + newName;
}

function handleNoteTextFileNameHook(note) {
script.log("note name: " + note.name);
script.log("file name: "+ note.fileName);
script.log(note.fileCreated)
script.log(note.fileLastModified)

var noteLines = note.noteText.split("\n");
var firstLine = noteLines[0];
var noteTitle = firstLine.slice(2)

script.log("note title: " + noteTitle)

// right when a note is created, the fileCreated property value is 'Invald Date'
// this blocks the hook to further change the note file name if the note title is changed
if (note.fileCreated != "Invalid Date"){
return ""
}

if (extraDialogForFileName){
return newNamer("New note", "New file name", "File name")
}
else{
return noteTitle
}
}

}