1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-30 10:36:35 +02:00
joplin/CliClient/app/gui/NoteListWidget.js

37 lines
837 B
JavaScript
Raw Normal View History

const Note = require('lib/models/Note.js');
2017-10-08 00:17:10 +02:00
const ListWidget = require('tkwidgets/ListWidget.js');
class NoteListWidget extends ListWidget {
constructor() {
super();
this.selectedNoteId_ = 0;
this.updateIndexFromSelectedNoteId_ = false;
this.itemRenderer = note => {
2017-12-26 12:38:53 +02:00
let label = Note.displayTitle(note); // + ' ' + note.id;
if (note.is_todo) {
2019-09-19 23:51:18 +02:00
label = `[${note.todo_completed ? 'X' : ' '}] ${label}`;
}
return label;
};
2017-10-08 00:17:10 +02:00
}
set selectedNoteId(v) {
this.updateIndexFromSelectedNoteId_ = true;
2017-10-08 00:17:10 +02:00
this.selectedNoteId_ = v;
}
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
}
}
module.exports = NoteListWidget;