Various improvements

pull/41/head
Laurent Cozic 2017-10-08 18:50:43 +01:00
parent dc219141fa
commit 3704f5be27
7 changed files with 64 additions and 32 deletions

View File

@ -49,11 +49,11 @@ class AppGui {
buildUi() { buildUi() {
this.rootWidget_ = new ReduxRootWidget(this.store_); this.rootWidget_ = new ReduxRootWidget(this.store_);
this.rootWidget_.setName('rootWidget'); this.rootWidget_.name = 'rootWidget';
const folderList = new FolderListWidget(); const folderList = new FolderListWidget();
folderList.setStyle({ borderBottomWidth: 1 }); folderList.setStyle({ borderBottomWidth: 1 });
folderList.setName('folderList'); folderList.name = 'folderList';
folderList.setVStretch(true); folderList.setVStretch(true);
folderList.on('currentItemChange', async () => { folderList.on('currentItemChange', async () => {
const folder = folderList.currentItem; const folder = folderList.currentItem;
@ -78,7 +78,7 @@ class AppGui {
} }
return label; return label;
}); });
noteList.setName('noteList'); noteList.name = 'noteList';
noteList.setVStretch(true); noteList.setVStretch(true);
noteList.setStyle({ noteList.setStyle({
borderBottomWidth: 1, borderBottomWidth: 1,
@ -101,7 +101,7 @@ class AppGui {
const noteText = new NoteWidget(); const noteText = new NoteWidget();
noteText.setVStretch(true); noteText.setVStretch(true);
noteText.setName('noteText'); noteText.name = 'noteText';
noteText.setStyle({ borderBottomWidth: 1 }); noteText.setStyle({ borderBottomWidth: 1 });
this.rootWidget_.connect(noteText, (state) => { this.rootWidget_.connect(noteText, (state) => {
return { noteId: state.selectedNoteId }; return { noteId: state.selectedNoteId };
@ -109,25 +109,25 @@ class AppGui {
const consoleWidget = new ConsoleWidget(); const consoleWidget = new ConsoleWidget();
consoleWidget.setHStretch(true); consoleWidget.setHStretch(true);
consoleWidget.setName('console'); consoleWidget.name = 'console';
consoleWidget.on('accept', (event) => { consoleWidget.on('accept', (event) => {
this.processCommand(event.input); this.processCommand(event.input, 'console');
}); });
const hLayout = new HLayoutWidget(); const hLayout = new HLayoutWidget();
hLayout.setName('hLayout'); hLayout.name = 'hLayout';
hLayout.addChild(folderList, { type: 'stretch', factor: 1 }); hLayout.addChild(folderList, { type: 'stretch', factor: 1 });
hLayout.addChild(noteList, { type: 'stretch', factor: 1 }); hLayout.addChild(noteList, { type: 'stretch', factor: 1 });
hLayout.addChild(noteText, { type: 'stretch', factor: 1 }); hLayout.addChild(noteText, { type: 'stretch', factor: 1 });
const vLayout = new VLayoutWidget(); const vLayout = new VLayoutWidget();
vLayout.setName('vLayout'); vLayout.name = 'vLayout';
vLayout.addChild(hLayout, { type: 'stretch', factor: 1 }); vLayout.addChild(hLayout, { type: 'stretch', factor: 1 });
vLayout.addChild(consoleWidget, { type: 'fixed', factor: 5 }); vLayout.addChild(consoleWidget, { type: 'fixed', factor: 5 });
const win1 = new WindowWidget(); const win1 = new WindowWidget();
win1.addChild(vLayout); win1.addChild(vLayout);
win1.setName('mainWindow'); win1.name = 'mainWindow';
this.rootWidget_.addChild(win1); this.rootWidget_.addChild(win1);
} }
@ -135,10 +135,36 @@ class AppGui {
setupShortcuts() { setupShortcuts() {
const shortcuts = {}; const shortcuts = {};
const consoleWidget = this.widget('console');
shortcuts['DELETE'] = 'rm $n'; shortcuts['DELETE'] = 'rm $n';
shortcuts['t'] = 'todo toggle $n';
shortcuts['c'] = () => { this.widget('console').focus(); }; shortcuts[' '] = 'todo toggle $n';
shortcuts[' '] = 'edit $n';
shortcuts['c'] = () => {
consoleWidget.focus();
}
shortcuts['ENTER'] = () => {
const w = this.widget('mainWindow').focusedWidget();
if (w.name == 'folderList') {
this.widget('noteList').focus();
} else if (w.name == 'noteList') {
this.processCommand('edit $n');
}
}
shortcuts[':nn'] = () => {
consoleWidget.focus('mknote ');
}
shortcuts[':nt'] = () => {
consoleWidget.focus('mktodo ');
}
shortcuts[':nb'] = () => {
consoleWidget.focus('mkbook ');
}
return shortcuts; return shortcuts;
} }
@ -167,7 +193,7 @@ class AppGui {
const widget = this.widget('mainWindow').focusedWidget(); const widget = this.widget('mainWindow').focusedWidget();
if (!widget) return null; if (!widget) return null;
if (widget.name() == 'noteList' || widget.name() == 'folderList') { if (widget.name == 'noteList' || widget.name == 'folderList') {
return widget.currentItem; return widget.currentItem;
} }
@ -194,9 +220,7 @@ class AppGui {
const consoleWidget = this.widget('console'); const consoleWidget = this.widget('console');
const metaCmd = cmd.substr(0, 2); if (cmd === ':m') {
if (metaCmd === ':m') {
if (consoleWidget.isMaximized__ === undefined) { if (consoleWidget.isMaximized__ === undefined) {
consoleWidget.isMaximized__ = false; consoleWidget.isMaximized__ = false;
} }
@ -211,6 +235,11 @@ class AppGui {
this.widget('vLayout').setWidgetConstraints(consoleWidget, constraints); this.widget('vLayout').setWidgetConstraints(consoleWidget, constraints);
return; return;
} else if (cmd[0] === ':') {
if (this.shortcuts_[cmd]) {
this.shortcuts_[cmd]();
return;
}
} }
let note = this.widget('noteList').currentItem; let note = this.widget('noteList').currentItem;
@ -218,10 +247,10 @@ class AppGui {
let args = cliUtils.splitCommandString(cmd); let args = cliUtils.splitCommandString(cmd);
for (let i = 0; i < args.length; i++) { for (let i = 0; i < args.length; i++) {
if (note && args[i] == '$n') { if (args[i] == '$n') {
args[i] = note.id; args[i] = note ? note.id : '';
} else if (folder && args[i] == '$b') { } else if (args[i] == '$b') {
args[i] = folder.id; args[i] = folder ? folder.id : '';
} else if (args[i] == '$c') { } else if (args[i] == '$c') {
const item = this.activeListItem(); const item = this.activeListItem();
args[i] = item ? item.id : ''; args[i] = item ? item.id : '';
@ -263,8 +292,6 @@ class AppGui {
const consoleWidget = this.widget('console'); const consoleWidget = this.widget('console');
//await this.updateFolderList();
term.grabInput(); term.grabInput();
term.on('key', async (name, matches, data) => { term.on('key', async (name, matches, data) => {
@ -276,7 +303,9 @@ class AppGui {
} }
if (!consoleWidget.hasFocus()) { if (!consoleWidget.hasFocus()) {
if (name in this.shortcuts_) { if (name == ':') {
consoleWidget.focus(':');
} else if (name in this.shortcuts_) {
const cmd = this.shortcuts_[name]; const cmd = this.shortcuts_[name];
if (typeof cmd === 'function') { if (typeof cmd === 'function') {
cmd(); cmd();

View File

@ -83,9 +83,12 @@ class Application {
answers[i + 1] = output[i].title; answers[i + 1] = output[i].title;
} }
let msg = _('More than one item match "%s". Please select one:', pattern); // Not really useful with new UI?
const response = await cliUtils.promptMcq(msg, answers); throw new Error(_('More than one item match "%s". Please narrow down your query.', pattern));
if (!response) return null;
// let msg = _('More than one item match "%s". Please select one:', pattern);
// const response = await cliUtils.promptMcq(msg, answers);
// if (!response) return null;
return output[response - 1]; return output[response - 1];
} else { } else {

View File

@ -42,7 +42,7 @@ class Command extends BaseCommand {
let note = await app().loadItem(BaseModel.TYPE_NOTE, title); let note = await app().loadItem(BaseModel.TYPE_NOTE, title);
if (!note) { if (!note) {
const ok = await cliUtils.promptConfirm(_('Note does not exist: "%s". Create it?', title)); const ok = await this.prompt(_('Note does not exist: "%s". Create it?', title));
if (!ok) return; if (!ok) return;
newNote = await Note.save({ title: title, parent_id: app().currentFolder().id }); newNote = await Note.save({ title: title, parent_id: app().currentFolder().id });
note = await Note.load(newNote.id); note = await Note.load(newNote.id);
@ -76,7 +76,7 @@ class Command extends BaseCommand {
updatedNote = await Note.unserializeForEdit(updatedNote); updatedNote = await Note.unserializeForEdit(updatedNote);
updatedNote.id = note.id; updatedNote.id = note.id;
await Note.save(updatedNote); await Note.save(updatedNote);
process.stdout.write('.'); //process.stdout.write('.');
watchTimeout = null; watchTimeout = null;
}, 200); }, 200);
}); });

View File

@ -32,7 +32,7 @@ class Command extends BaseCommand {
if (!folderTitle) folderTitle = filename(filePath); if (!folderTitle) folderTitle = filename(filePath);
folder = await Folder.loadByField('title', folderTitle); folder = await Folder.loadByField('title', folderTitle);
const msg = folder ? _('File "%s" will be imported into existing notebook "%s". Continue?', basename(filePath), folderTitle) : _('New notebook "%s" will be created and file "%s" will be imported into it. Continue?', folderTitle, basename(filePath)); const msg = folder ? _('File "%s" will be imported into existing notebook "%s". Continue?', basename(filePath), folderTitle) : _('New notebook "%s" will be created and file "%s" will be imported into it. Continue?', folderTitle, basename(filePath));
const ok = force ? true : await cliUtils.promptConfirm(msg); const ok = force ? true : await this.prompt(msg);
if (!ok) return; if (!ok) return;
let options = { let options = {

View File

@ -19,7 +19,7 @@ msgid "[Cancel]"
msgstr "" msgstr ""
#, javascript-format #, javascript-format
msgid "More than one item match \"%s\". Please select one:" msgid "More than one item match \"%s\". Please narrow down your query."
msgstr "" msgstr ""
msgid "No notebook selected." msgid "No notebook selected."

View File

@ -20,7 +20,7 @@ msgid "[Cancel]"
msgstr "Annulation..." msgstr "Annulation..."
#, javascript-format #, javascript-format
msgid "More than one item match \"%s\". Please select one:" msgid "More than one item match \"%s\". Please narrow down your query."
msgstr "" msgstr ""
msgid "No notebook selected." msgid "No notebook selected."

View File

@ -19,7 +19,7 @@ msgid "[Cancel]"
msgstr "" msgstr ""
#, javascript-format #, javascript-format
msgid "More than one item match \"%s\". Please select one:" msgid "More than one item match \"%s\". Please narrow down your query."
msgstr "" msgstr ""
msgid "No notebook selected." msgid "No notebook selected."