Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to new-note-namer, to underline the heading instead of highlighting it with # #249

Merged
merged 5 commits into from
Nov 28, 2024
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
4 changes: 2 additions & 2 deletions new-note-namer/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "New note namer",
"identifier": "new-note-namer",
"script": "new-note-namer.qml",
"authors": ["@diegovskytl"],
"authors": ["@diegovskytl", "@Mystechry"],
"platforms": ["linux", "macos", "windows"],
"version": "0.0.1",
"version": "0.0.2",
"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 :)"
}
26 changes: 20 additions & 6 deletions new-note-namer/new-note-namer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import QOwnNotesTypes 1.0
*/
QtObject {
property bool extraDialogForFileName;
property bool underlineHeading;
property variant settingsVariables: [
{
'identifier': 'extraDialogForFileName',
Expand All @@ -16,6 +17,13 @@ QtObject {
'type': 'boolean',
'default': 'false',
},
{
'identifier': 'underlineHeading',
'name': 'Underline heading',
'description': 'Highlight the first line by underlining it with =, if not checked, use a preceding # instead.',
'type': 'boolean',
'default': 'false',
},
];

function init() {
Expand All @@ -41,7 +49,11 @@ QtObject {
script.log(note.fileCreated)
script.log(note.fileLastModified)

return "# " + newName;
if (underlineHeading) {
return newName + "\n" + "=".repeat(newName.length);
} else {
return "# " + newName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please adapt the amount of whitespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed my portion of the code. The original script is not properly consistent with its use of whitespace in the first place. Please let me know if I shall unify the whitespacing throughout the whole script.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole script is a mess, you are right. Please do so in another PR.

}
}

function handleNoteTextFileNameHook(note) {
Expand All @@ -52,7 +64,10 @@ QtObject {

var noteLines = note.noteText.split("\n");
var firstLine = noteLines[0];
var noteTitle = firstLine.slice(2)
var noteTitle = firstLine.slice(2) // Remove the preceding "# "
if (underlineHeading){ // Underlined headings use the entire first line
noteTitle = firstLine;
}

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

Expand All @@ -62,10 +77,9 @@ QtObject {
return ""
}

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