2021-01-22 19:41:11 +02:00
|
|
|
const Note = require('@joplin/lib/models/Note').default;
|
2017-10-08 00:17:10 +02:00
|
|
|
const ListWidget = require('tkwidgets/ListWidget.js');
|
|
|
|
|
|
|
|
class NoteListWidget extends ListWidget {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.selectedNoteId_ = 0;
|
2022-09-05 13:37:51 +02:00
|
|
|
this.showIds = false;
|
2017-10-08 00:17:10 +02:00
|
|
|
|
2017-10-09 21:57:00 +02:00
|
|
|
this.updateIndexFromSelectedNoteId_ = false;
|
|
|
|
|
2020-05-21 10:14:33 +02:00
|
|
|
this.itemRenderer = note => {
|
2022-09-05 13:37:51 +02:00
|
|
|
let label = Note.displayTitle(note);
|
|
|
|
if (this.showIds) {
|
|
|
|
label = `${Note.shortId(note.id)} ${Note.displayTitle(note)}`;
|
|
|
|
}
|
2017-10-09 21:57:00 +02:00
|
|
|
if (note.is_todo) {
|
2019-09-19 23:51:18 +02:00
|
|
|
label = `[${note.todo_completed ? 'X' : ' '}] ${label}`;
|
2017-10-09 21:57:00 +02:00
|
|
|
}
|
|
|
|
return label;
|
|
|
|
};
|
2017-10-08 00:17:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
set selectedNoteId(v) {
|
2017-10-09 21:57:00 +02:00
|
|
|
this.updateIndexFromSelectedNoteId_ = true;
|
2017-10-08 00:17:10 +02:00
|
|
|
this.selectedNoteId_ = v;
|
2017-10-09 21:57:00 +02:00
|
|
|
}
|
|
|
|
|
2022-09-05 13:37:51 +02:00
|
|
|
toggleShowIds() {
|
|
|
|
this.showIds = !this.showIds;
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
|
2017-10-09 21:57:00 +02:00
|
|
|
render() {
|
|
|
|
if (this.updateIndexFromSelectedNoteId_) {
|
|
|
|
const index = this.itemIndexByKey('id', this.selectedNoteId_);
|
|
|
|
this.currentIndex = index >= 0 ? index : 0;
|
|
|
|
this.updateIndexFromSelectedNoteId_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
super.render();
|
2017-10-08 00:17:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
module.exports = NoteListWidget;
|