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
Desktop: Added options to set default templates #2857
Changes from 6 commits
897d9cc
d33fe5e
693040f
dcf0a4b
b6b53e8
979f8e2
46e6822
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ const { toTitleCase } = require('lib/string-utils.js'); | |
const { rtrimSlashes } = require('lib/path-utils.js'); | ||
const { _, supportedLocalesToLanguages, defaultLocale } = require('lib/locale.js'); | ||
const { shim } = require('lib/shim'); | ||
const TemplateUtils = require('lib/TemplateUtils'); | ||
|
||
class Setting extends BaseModel { | ||
static tableName() { | ||
|
@@ -346,6 +347,40 @@ class Setting extends BaseModel { | |
}; | ||
}, | ||
}, | ||
defaultNote: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rename to |
||
value: '0', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defaults to empty string |
||
type: Setting.TYPE_STRING, | ||
section: 'note', | ||
isEnum: true, | ||
public: true, | ||
appTypes: ['desktop'], | ||
label: () => _('Choose default template for new note:'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
options: () => { | ||
const templates = TemplateUtils.availableTemplates(); | ||
const options = { 0: 'None' }; | ||
for (let i = 0; i < templates.length; i++) { | ||
options[templates[i].label] = templates[i].label; | ||
} | ||
return options; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identifying the template by array index is too fragile because if a template is added or deleted it will break. They should be identified by name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The templates are identified by label in the options array. Label is the same as file name (the index loop is just for iterating through all available template objects). I've played around with this a bit, and if a template file is deleted joplin defaults back to no template on next reload or joplin restart. Adding new template files also does not mess with the currently seleced template. |
||
}, | ||
}, | ||
defaultTodo: { | ||
value: '0', | ||
type: Setting.TYPE_STRING, | ||
section: 'note', | ||
isEnum: true, | ||
public: true, | ||
appTypes: ['desktop'], | ||
label: () => _('Choose default template for new todo:'), | ||
options: () => { | ||
const templates = TemplateUtils.availableTemplates(); | ||
const options = { 0: 'None' }; | ||
for (let i = 0; i < templates.length; i++) { | ||
options[templates[i].label] = templates[i].label; | ||
} | ||
return options; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please refactor to avoid the duplicate code. Maybe create a function |
||
}, | ||
}, | ||
|
||
// Deprecated - use markdown.plugin.* | ||
'markdown.softbreaks': { value: false, type: Setting.TYPE_BOOL, public: false, appTypes: ['mobile', 'desktop'] }, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ought to be simpler:
Please don't set any setting in here, as we don't want side-effects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized the Setting.setValue isn't necessary. I put it there for safety, thinking the set defaultTodo/defaultNote options might remain after (deleting a template) and refreshing. They don't, so i'll remove it.
I'll also cut down line 103 and 104 to one line like you propose. Only the template filename is stored in Setting.value(default****), not the contents, so we still need to get the contents from props. This change was made as Caleb realized storing the template contents in options won't allow the user to edit a template without losing the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, i was wrong about the first part. The settings do remain even after refresh, which leads to a problem when deleting templates and refreshing. I'll see what i can do.