1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Fixed updating view when note is deleted

This commit is contained in:
Laurent Cozic 2017-10-09 20:57:00 +01:00
parent 30480a8029
commit 8c7cd8de88
7 changed files with 74 additions and 29 deletions

View File

@ -21,6 +21,7 @@ const WindowWidget = require('tkwidgets/WindowWidget.js');
const NoteWidget = require('./gui/NoteWidget.js'); const NoteWidget = require('./gui/NoteWidget.js');
const FolderListWidget = require('./gui/FolderListWidget.js'); const FolderListWidget = require('./gui/FolderListWidget.js');
const NoteListWidget = require('./gui/NoteListWidget.js');
class AppGui { class AppGui {
@ -49,7 +50,7 @@ class AppGui {
this.inputMode_ = AppGui.INPUT_MODE_NORMAL; this.inputMode_ = AppGui.INPUT_MODE_NORMAL;
this.currentShortcutKeys_ = ''; this.currentShortcutKeys_ = [];
this.lastShortcutKeyTime_ = 0; this.lastShortcutKeyTime_ = 0;
} }
@ -75,15 +76,7 @@ class AppGui {
}; };
}); });
const noteList = new ListWidget(); const noteList = new NoteListWidget();
noteList.items = [];
noteList.itemRenderer = (note) => {
let label = note.title;
if (note.is_todo) {
label = '[' + (note.todo_completed ? 'X' : ' ') + '] ' + label;
}
return label;
};
noteList.name = 'noteList'; noteList.name = 'noteList';
noteList.vStretch = true; noteList.vStretch = true;
noteList.style = { noteList.style = {
@ -329,6 +322,7 @@ class AppGui {
this.widget('noteText').text = text; this.widget('noteText').text = text;
} }
// Any key after which a shortcut is not possible.
isSpecialKey(name) { isSpecialKey(name) {
return ['ENTER', 'DOWN', 'UP', 'LEFT', 'RIGHT', 'DELETE', 'BACKSPACE', 'ESCAPE', 'TAB', 'SHIFT_TAB'].indexOf(name) >= 0; return ['ENTER', 'DOWN', 'UP', 'LEFT', 'RIGHT', 'DELETE', 'BACKSPACE', 'ESCAPE', 'TAB', 'SHIFT_TAB'].indexOf(name) >= 0;
} }
@ -356,23 +350,30 @@ class AppGui {
const now = (new Date()).getTime(); const now = (new Date()).getTime();
if (now - this.lastShortcutKeyTime_ > 1000 || this.isSpecialKey(name)) { if (now - this.lastShortcutKeyTime_ > 800 || this.isSpecialKey(name)) {
this.currentShortcutKeys_ = name; this.currentShortcutKeys_ = [name];
} else { } else {
this.currentShortcutKeys_ += name; // If the previous key was a special key (eg. up, down arrow), this new key
// starts a new shortcut.
if (this.currentShortcutKeys_.length && this.isSpecialKey(this.currentShortcutKeys_[0])) {
this.currentShortcutKeys_ = [name];
} else {
this.currentShortcutKeys_.push(name);
}
} }
this.lastShortcutKeyTime_ = now; this.lastShortcutKeyTime_ = now;
// Don't process shortcut keys if the console is active, except if the shortcut // Don't process shortcut keys if the console is active, except if the shortcut
// starts with CTRL (eg. CTRL+J CTRL+Z to maximize the console window). // starts with CTRL (eg. CTRL+J CTRL+Z to maximize the console window).
if (!consoleWidget.hasFocus || this.currentShortcutKeys_.indexOf('CTRL') === 0) { if (!consoleWidget.hasFocus || (this.currentShortcutKeys_.length && this.currentShortcutKeys_[0].indexOf('CTRL') === 0)) {
this.logger().debug('Now: ' + name + ', Keys: ' + this.currentShortcutKeys_); this.logger().debug('Now: ' + name + ', Keys: ', this.currentShortcutKeys_);
if (this.currentShortcutKeys_ in this.shortcuts_) { const shortcutKey = this.currentShortcutKeys_.join('');
const cmd = this.shortcuts_[this.currentShortcutKeys_].action; if (shortcutKey in this.shortcuts_) {
const cmd = this.shortcuts_[shortcutKey].action;
if (!cmd.isDocOnly) { if (!cmd.isDocOnly) {
this.currentShortcutKeys_ = ''; this.currentShortcutKeys_ = [];
if (typeof cmd === 'function') { if (typeof cmd === 'function') {
cmd(); cmd();
} else { } else {

View File

@ -408,7 +408,7 @@ class Application {
generalMiddleware() { generalMiddleware() {
const middleware = store => next => async (action) => { const middleware = store => next => async (action) => {
this.logger().info('Middleware reducer action', action.type); this.logger().info('Reducer action', action.type);
const result = next(action); const result = next(action);
const newState = store.getState(); const newState = store.getState();

View File

@ -1,4 +1,5 @@
import { _ } from 'lib/locale.js'; import { _ } from 'lib/locale.js';
import { reg } from 'lib/registry.js';
class BaseCommand { class BaseCommand {
@ -75,6 +76,10 @@ class BaseCommand {
}; };
} }
logger() {
return reg.logger();
}
} }
export { BaseCommand }; export { BaseCommand };

View File

@ -6,20 +6,32 @@ class NoteListWidget extends ListWidget {
constructor() { constructor() {
super(); super();
this.selectedNoteId_ = 0; this.selectedNoteId_ = 0;
this.itemRenderer = (item) => {
return item.title;
};
}
get selectedNoteId() { this.updateIndexFromSelectedNoteId_ = false;
return this.selectedNoteId_;
this.itemRenderer = (note) => {
let label = note.title + ' ' + note.id;
if (note.is_todo) {
label = '[' + (note.todo_completed ? 'X' : ' ') + '] ' + label;
}
return label;
};
} }
set selectedNoteId(v) { set selectedNoteId(v) {
if (v === this.selectedNoteId_) return; if (v === this.selectedNoteId_) return;
this.updateIndexFromSelectedNoteId_ = true;
this.selectedNoteId_ = v; this.selectedNoteId_ = v;
const index = this.itemIndexByKey('id', this.selectedNoteId_); }
this.currentIndex = index >= 0 ? index : 0;
render() {
if (this.updateIndexFromSelectedNoteId_) {
const index = this.itemIndexByKey('id', this.selectedNoteId_);
this.currentIndex = index >= 0 ? index : 0;
this.updateIndexFromSelectedNoteId_ = false;
}
super.render();
} }
} }

View File

@ -77,6 +77,12 @@ class Folder extends BaseItem {
}); });
} }
static batchDelete(ids, options = null) {
for (let i = 0; i < ids.length; i++) {
this.delete(ids[i], options);
}
}
static conflictFolderTitle() { static conflictFolderTitle() {
return _('Conflicts'); return _('Conflicts');
} }

View File

@ -345,6 +345,17 @@ class Note extends BaseItem {
}); });
} }
static batchDelete(ids, options = null) {
const result = super.batchDelete(ids, options);
for (let i = 0; i < ids.length; i++) {
this.dispatch({
type: 'NOTES_DELETE',
noteId: ids[i],
});
}
return result;
}
} }
Note.updateGeolocationEnabled_ = true; Note.updateGeolocationEnabled_ = true;

View File

@ -191,15 +191,25 @@ const reducer = (state = defaultState, action) => {
case 'NOTES_DELETE': case 'NOTES_DELETE':
var previousIndex = 0;
var newNotes = []; var newNotes = [];
for (let i = 0; i < state.notes.length; i++) { for (let i = 0; i < state.notes.length; i++) {
let f = state.notes[i]; let f = state.notes[i];
if (f.id == action.noteId) continue; if (f.id == action.noteId) {
previousIndex = i;
continue;
}
newNotes.push(f); newNotes.push(f);
} }
newState = Object.assign({}, state); newState = Object.assign({}, state);
newState.notes = newNotes; newState.notes = newNotes;
if (previousIndex >= newNotes.length) {
previousIndex = newNotes.length - 1;
}
newState.selectedNoteId = previousIndex >= 0 ? newNotes[previousIndex].id : null;
break; break;
case 'FOLDERS_UPDATE_ALL': case 'FOLDERS_UPDATE_ALL':