-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'New note namer' script: allows note file name renaming at note c…
…reation
- Loading branch information
1 parent
7a8c25f
commit a5885ea
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 :)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
||
} |