Current template implementation in desktop is good and quite versatile. However, I mostly use one single template. This makes me do ctrl+n, then ctrl+alt+i and enter almost every time i create a new note. I would like to propose adding an option to set a template that opens by default when creating a new note.
Maybe by one of the following alternatives.
An “enable default template” checkbox and choose file under Options -> Note
New menu item under file -> templates named “set default template” when disabled and “unset/change default template” when enabled,
Skip new feature and instead add keyboard shortcut to the existing menu item “create new note from template”. This would be slightly faster than now, but would however still give users such as myself an unnecessary prompt for choosing a template most of the time.
My hope is that one of these alternatives would make note-creating simpler and cleaner for users that use a single template most of the times, without creating problems for people satisfied with the current implementation.
I think this has been suggested before, it’s probably not too difficult. I think the best way to do it would be to have a dropdown in settings that lists all template files and an empty option. The user could then select from there. I can look into it.
I’m somewhat new to coding, having dabbled in bash and python for about a year. I’m interested in learning JavaScript, so let me know if i can help out or give it a try myself.
I think the only tricky thing here would be to make a change in Setting.js that loads in templates. Not that it’s technically difficult (see app.js for an example of getting a template list) but I’m not quite sure on how to do it in a clean way. Then you just need to update the createNewNote function in MainScreen.jsx to check for the default template. I won’t get to this right away so feel free to take a crack at it, and ask me if you have any questions!
I made a fish script to do this from the command line. When I run it, a new note is created and added to a certain folder. Happy to share if you are interested. Still working on a way to automatically open Joplin to the newly created noted, but it works pretty well otherwise.
I think you can use the shim for this. You'd create a function that, on desktop, would return all the template and, on mobile, would return an empty array. Even though the setting wouldn't show up on mobile it's best to handle it that way to avoid any hard dependency to a particular platform on Setting.js
I guess one smaller issue is to handle the case where the selected template later gets deleted.
Thanks @CalebJohn. I’ll start going through the code you mentioned, including @laurent proposal using the shim, and see what i can make of it. I might get back to you with some questions.
I’ve managed to create a working dropdown in settings -> note and populate it with the filenames from templatedir. Does the following sound like an acceptable solution to you?
I’ve created two new properties of Setting.metadata().
defaultTemplate, manages the dropdown-menu, which in turn is populated by…
availableTemplates, which is just a container for the array of template files and titles. I’ve added a line to the “Refresh templates” section in app.js, so that every time the templates are refreshed, the resulting array is also pushed to and can later on be read from Setting.value(‘availableTemplates’).
Alright, now i have the feature working on desktop.
Added two new dropdowns under Settings -> Note. One for setting default note template, and one for default todo template. Options for both are read from templateDir and default option is None. Chosen templates appear as expected on ctrl+N and ctrl+T
“File -> Templates -> New note from template” of course overrides this, so that item is still intact even if a default template is chosen. Inserting templates also works like before.
The Setting.value(‘availableTemplates’) is only updated when shim.isElectron = True, and otherwise defaults to an empty array.
As i’m new to the codebase and js in general i guess there are things that could be done more efficient. Not sure how well i’m following conventions etc. It would be much appreciated if someone would take a look at my code at some point. No need to hurry though, I understand there are more high priority issues.
I wasn't sure if I should make a new thread or necro this one. I would really like this feature, and found the related PR:
It got closed because:
Hmm, right I think we have a problem here because the Setting class is now loading the TemplateUtil class, even though that's not needed for the tests (or for the CLI and mobile app).
I think there's some plumbing to do to allow the Setting class to access other classes properly, probably using dependency injection. So could you put this feature on hold for now please, until this is sorted out? Sorry about that, I didn't realize it would be a problem for this pull request.
Is there any progress on the needed plumbing? If so, I'd be interested in trying to see if I can get this PR updated, and into the app.