mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Various gui changes
This commit is contained in:
parent
ef0555f2d8
commit
2b83ddc273
@ -1,9 +1,9 @@
|
||||
import { Logger } from 'lib/logger.js';
|
||||
import { Folder } from 'lib/models/folder.js';
|
||||
import { Note } from 'lib/models/note.js';
|
||||
import { cliUtils } from './cli-utils.js';
|
||||
|
||||
const tk = require('terminal-kit');
|
||||
//const term = tk.terminal;
|
||||
const termutils = require('tkwidgets/framework/termutils.js');
|
||||
const Renderer = require('tkwidgets/framework/Renderer.js');
|
||||
|
||||
@ -22,9 +22,17 @@ class AppGui {
|
||||
this.term_ = tk.terminal;
|
||||
this.renderer_ = null;
|
||||
this.logger_ = new Logger();
|
||||
this.rootWidget_ = this.buildUi();
|
||||
this.renderer_ = new Renderer(this.term(), this.rootWidget_);
|
||||
|
||||
this.rootWidget_ = new RootWidget();
|
||||
this.rootWidget_.setName('rootWidget');
|
||||
this.app_.on('modelAction', async (event) => {
|
||||
await this.handleModelAction(event.action);
|
||||
});
|
||||
}
|
||||
|
||||
buildUi() {
|
||||
const rootWidget = new RootWidget();
|
||||
rootWidget.setName('rootWidget');
|
||||
|
||||
const folderList = new ListWidget();
|
||||
folderList.setItems([]);
|
||||
@ -43,8 +51,12 @@ class AppGui {
|
||||
|
||||
const noteList = new ListWidget();
|
||||
noteList.setItems([]);
|
||||
noteList.setItemRenderer((item) => {
|
||||
return item.title;
|
||||
noteList.setItemRenderer((note) => {
|
||||
let label = note.title;
|
||||
if (note.is_todo) {
|
||||
label = '[' + (note.todo_completed ? 'X' : ' ') + '] ' + label;
|
||||
}
|
||||
return label;
|
||||
});
|
||||
noteList.setName('noteList');
|
||||
noteList.setVStretch(true);
|
||||
@ -54,7 +66,13 @@ class AppGui {
|
||||
borderRightWidth: 1,
|
||||
});
|
||||
noteList.on('currentItemChange', async () => {
|
||||
const note = noteList.currentItem();
|
||||
let note = noteList.currentItem();
|
||||
if (note) {
|
||||
if (!('body' in note)) {
|
||||
note = await Note.load(note.id);
|
||||
}
|
||||
noteList.setCurrentItem(note);
|
||||
}
|
||||
await this.updateNoteText(note);
|
||||
});
|
||||
|
||||
@ -65,23 +83,29 @@ class AppGui {
|
||||
borderBottomWidth: 1,
|
||||
});
|
||||
|
||||
const consoleWidget = new ConsoleWidget();
|
||||
consoleWidget.setHStretch(true);
|
||||
consoleWidget.setName('console');
|
||||
consoleWidget.on('accept', (event) => {
|
||||
this.processCommand(event.input);
|
||||
});
|
||||
|
||||
const hLayout = new HLayoutWidget();
|
||||
hLayout.addChild(folderList, { type: 'stretch', factor: 1 });
|
||||
hLayout.addChild(noteList, { type: 'stretch', factor: 1 });
|
||||
hLayout.addChild(noteText, { type: 'stretch', factor: 1 });
|
||||
|
||||
// const layout2 = new VLayoutWidget();
|
||||
// layout2.addChild(hLayout, { type: 'stretch', factor: 1 });
|
||||
// layout2.addChild(listWidget3, { type: 'fixed', factor: 5 });
|
||||
const vLayout = new VLayoutWidget();
|
||||
vLayout.addChild(hLayout, { type: 'stretch', factor: 1 });
|
||||
vLayout.addChild(consoleWidget, { type: 'fixed', factor: 5 });
|
||||
|
||||
const win1 = new WindowWidget();
|
||||
win1.addChild(hLayout);
|
||||
win1.addChild(vLayout);
|
||||
win1.setName('mainWindow');
|
||||
win1.setLocation(1,1);
|
||||
|
||||
this.rootWidget_.addChild(win1);
|
||||
rootWidget.addChild(win1);
|
||||
|
||||
this.renderer_ = new Renderer(this.term(), this.rootWidget_);
|
||||
return rootWidget;
|
||||
}
|
||||
|
||||
widget(name) {
|
||||
@ -104,13 +128,54 @@ class AppGui {
|
||||
return this.term_;
|
||||
}
|
||||
|
||||
async handleModelAction(action) {
|
||||
this.logger().info(action);
|
||||
|
||||
// "{"action":{"type":"NOTES_UPDATE_ONE","note":{"id":"56d0e2ea61004324b33a307983c9722c","todo_completed":1507306904833,"updated_time":1507306904834,"user_updated_time":1507306904834,"type_":1}}}"
|
||||
switch (action.type) {
|
||||
|
||||
case 'NOTES_UPDATE_ONE':
|
||||
|
||||
const folder = this.widget('folderList').currentItem();
|
||||
if (!folder) return;
|
||||
|
||||
const note = action.note;
|
||||
this.logger().info(folder, note);
|
||||
if (note.parent_id != folder.id) return;
|
||||
|
||||
|
||||
const notes = await Note.previews(folder.id);
|
||||
|
||||
this.widget('noteList').setItems(notes);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async processCommand(cmd) {
|
||||
let note = this.widget('noteList').currentItem();
|
||||
let folder = this.widget('folderList').currentItem();
|
||||
let args = cliUtils.splitCommandString(cmd);
|
||||
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
if (note && args[i] == '%n') args[i] = note.id;
|
||||
if (folder && args[i] == '%b') args[i] = folder.id;
|
||||
}
|
||||
|
||||
await this.app().execCommand(args);
|
||||
|
||||
//this.logger().info(args);
|
||||
}
|
||||
|
||||
async updateFolderList() {
|
||||
const folders = await Folder.all();
|
||||
this.widget('folderList').setItems(folders);
|
||||
}
|
||||
|
||||
async updateNoteList(folderId) {
|
||||
const notes = folderId ? await Note.previews(folderId) : [];
|
||||
const fields = Note.previewFields();
|
||||
fields.splice(fields.indexOf('body'), 1);
|
||||
const notes = folderId ? await Note.previews(folderId, { fields: fields }) : [];
|
||||
this.widget('noteList').setItems(notes);
|
||||
}
|
||||
|
||||
@ -132,23 +197,15 @@ class AppGui {
|
||||
|
||||
term.grabInput();
|
||||
|
||||
term.on('key', function( name , matches , data ) {
|
||||
term.on('key', (name, matches, data) => {
|
||||
if (name === 'CTRL_C' ) {
|
||||
termutils.showCursor(term);
|
||||
term.fullscreen(false);
|
||||
process.exit();
|
||||
}
|
||||
|
||||
if (name === 'CTRL_J') {
|
||||
consoleWidget.focus();
|
||||
}
|
||||
|
||||
if (name == 't') {
|
||||
if (win1.isActiveWindow()) {
|
||||
win2.activate();
|
||||
} else {
|
||||
win1.activate();
|
||||
}
|
||||
if (name == 'c') {
|
||||
this.widget('console').focus();
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
|
@ -16,6 +16,7 @@ import fs from 'fs-extra';
|
||||
import yargParser from 'yargs-parser';
|
||||
import { handleAutocompletion, installAutocompletionFile } from './autocompletion.js';
|
||||
import { cliUtils } from './cli-utils.js';
|
||||
const EventEmitter = require('events');
|
||||
|
||||
class Application {
|
||||
|
||||
@ -30,6 +31,7 @@ class Application {
|
||||
this.allCommandsLoaded_ = false;
|
||||
this.showStackTraces_ = false;
|
||||
this.gui_ = null;
|
||||
this.eventEmitter_ = new EventEmitter();
|
||||
}
|
||||
|
||||
currentFolder() {
|
||||
@ -238,17 +240,23 @@ class Application {
|
||||
}
|
||||
|
||||
baseModelListener(action) {
|
||||
switch (action.type) {
|
||||
this.eventEmitter_.emit('modelAction', { action: action });
|
||||
|
||||
case 'NOTES_UPDATE_ONE':
|
||||
case 'NOTES_DELETE':
|
||||
case 'FOLDERS_UPDATE_ONE':
|
||||
case 'FOLDER_DELETE':
|
||||
// switch (action.type) {
|
||||
|
||||
//reg.scheduleSync();
|
||||
break;
|
||||
// case 'NOTES_UPDATE_ONE':
|
||||
// case 'NOTES_DELETE':
|
||||
// case 'FOLDERS_UPDATE_ONE':
|
||||
// case 'FOLDER_DELETE':
|
||||
|
||||
}
|
||||
// //reg.scheduleSync();
|
||||
// break;
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
on(eventName, callback) {
|
||||
return this.eventEmitter_.on(eventName, callback);
|
||||
}
|
||||
|
||||
commands() {
|
||||
@ -324,10 +332,17 @@ class Application {
|
||||
e.type = 'notFound';
|
||||
throw e;
|
||||
}
|
||||
|
||||
let cmd = new CommandClass();
|
||||
cmd.buffer_ = [];
|
||||
|
||||
cmd.log = (...object) => {
|
||||
return console.log(...object);
|
||||
cmd.buffer_ = cmd.buffer_.concat(object);
|
||||
//return console.log(...object);
|
||||
}
|
||||
|
||||
cmd.buffer = () => {
|
||||
return cmd.buffer_;
|
||||
}
|
||||
|
||||
this.commands_[name] = cmd;
|
||||
|
@ -5,6 +5,17 @@ const stringPadding = require('string-padding');
|
||||
|
||||
const cliUtils = {};
|
||||
|
||||
// Split a command string into an argument array
|
||||
cliUtils.splitCommandString = function(s) {
|
||||
s = s.replace(/--/g, 'JOP_DASH_JOP_DASH');
|
||||
let r = yargParser(s);
|
||||
let output = [];
|
||||
for (let i = 0; i < r._.length; i++) {
|
||||
output.push(r._[i].replace(/JOP_DASH_JOP_DASH/g, '--'));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
cliUtils.printArray = function(logFunction, rows, headers = null) {
|
||||
if (!rows.length) return '';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user