mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-27 10:32:58 +02:00
Handle editing note
This commit is contained in:
parent
e323a86563
commit
9d630ab0ca
@ -200,7 +200,16 @@ commands.push({
|
|||||||
usage: 'edit <title>',
|
usage: 'edit <title>',
|
||||||
description: 'Edit note.',
|
description: 'Edit note.',
|
||||||
action: async function(args, end) {
|
action: async function(args, end) {
|
||||||
try {
|
|
||||||
|
let watcher = null;
|
||||||
|
const onFinishedEditing = () => {
|
||||||
|
if (watcher) watcher.close();
|
||||||
|
vorpal.show();
|
||||||
|
this.log(_('Done editing.'));
|
||||||
|
end();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
let title = args['title'];
|
let title = args['title'];
|
||||||
|
|
||||||
if (!currentFolder) throw new Error(_('No active notebook.'));
|
if (!currentFolder) throw new Error(_('No active notebook.'));
|
||||||
@ -210,44 +219,45 @@ commands.push({
|
|||||||
|
|
||||||
let editorPath = getTextEditorPath();
|
let editorPath = getTextEditorPath();
|
||||||
let editorArgs = editorPath.split(' ');
|
let editorArgs = editorPath.split(' ');
|
||||||
|
|
||||||
editorPath = editorArgs[0];
|
editorPath = editorArgs[0];
|
||||||
editorArgs = [editorArgs[1]];
|
editorArgs = editorArgs.splice(1);
|
||||||
|
|
||||||
let content = await Note.serializeForEdit(note);
|
let content = await Note.serializeForEdit(note);
|
||||||
|
|
||||||
const temp = require('temp');
|
let tempFilePath = Setting.value('profileDir') + '/tmp/' + Note.systemPath(note);
|
||||||
|
editorArgs.push(tempFilePath);
|
||||||
|
|
||||||
const spawn = require('child_process').spawn;
|
const spawn = require('child_process').spawn;
|
||||||
|
|
||||||
this.log(_('Starting to edit note...'));
|
this.log(_('Starting to edit note. Close the editor to get back to the prompt.'));
|
||||||
|
|
||||||
vorpal.hide();
|
vorpal.hide();
|
||||||
|
|
||||||
temp.track();
|
await fs.writeFile(tempFilePath, content);
|
||||||
|
|
||||||
temp.open(Setting.value('appName'), async (error, info) => {
|
let watchTimeout = null;
|
||||||
if (error) throw error;
|
watcher = fs.watch(tempFilePath, (eventType, filename) => {
|
||||||
|
// We need a timeout because for each change to the file, multiple events are generated.
|
||||||
|
|
||||||
await fs.writeFile(info.path, content);
|
if (watchTimeout) return;
|
||||||
|
|
||||||
fs.watch(info.path, (eventType, filename) => {
|
watchTimeout = setTimeout(async () => {
|
||||||
console.info('cHANGE...');
|
let updatedNote = await fs.readFile(tempFilePath, 'utf8');
|
||||||
});
|
updatedNote = await Note.unserializeForEdit(updatedNote);
|
||||||
|
updatedNote.id = note.id;
|
||||||
|
await Note.save(updatedNote);
|
||||||
|
watchTimeout = null;
|
||||||
|
}, 200);
|
||||||
|
});
|
||||||
|
|
||||||
// https://github.com/dthree/vorpal/issues/190
|
const childProcess = spawn(editorPath, editorArgs, { stdio: 'inherit' });
|
||||||
|
childProcess.on('exit', (error, code) => {
|
||||||
editorArgs.push(info.path);
|
onFinishedEditing();
|
||||||
|
|
||||||
const childProcess = spawn(editorPath, editorArgs, { stdio: 'inherit' });
|
|
||||||
|
|
||||||
childProcess.on('exit', (error, code) => {
|
|
||||||
this.log(_('Done editing note.'));
|
|
||||||
vorpal.show();
|
|
||||||
end();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
this.log(error);
|
this.log(error);
|
||||||
end();
|
onFinishedEditing();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
autocomplete: autocompleteItems,
|
autocomplete: autocompleteItems,
|
||||||
@ -853,8 +863,6 @@ function getTextEditorPath() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
process.stdin.on('keypress', (_, key) => {
|
process.stdin.on('keypress', (_, key) => {
|
||||||
console.info(_, key);
|
|
||||||
|
|
||||||
if (key && key.name === 'return') {
|
if (key && key.name === 'return') {
|
||||||
updatePrompt();
|
updatePrompt();
|
||||||
}
|
}
|
||||||
@ -900,12 +908,15 @@ async function main() {
|
|||||||
|
|
||||||
const profileDir = initArgs.profileDir ? initArgs.profileDir : os.homedir() + '/.config/' + Setting.value('appName');
|
const profileDir = initArgs.profileDir ? initArgs.profileDir : os.homedir() + '/.config/' + Setting.value('appName');
|
||||||
const resourceDir = profileDir + '/resources';
|
const resourceDir = profileDir + '/resources';
|
||||||
|
const tempDir = profileDir + '/tmp';
|
||||||
|
|
||||||
Setting.setConstant('profileDir', profileDir);
|
Setting.setConstant('profileDir', profileDir);
|
||||||
Setting.setConstant('resourceDir', resourceDir);
|
Setting.setConstant('resourceDir', resourceDir);
|
||||||
|
Setting.setConstant('tempDir', tempDir);
|
||||||
|
|
||||||
await fs.mkdirp(profileDir, 0o755);
|
await fs.mkdirp(profileDir, 0o755);
|
||||||
await fs.mkdirp(resourceDir, 0o755);
|
await fs.mkdirp(resourceDir, 0o755);
|
||||||
|
await fs.mkdirp(tempDir, 0o755);
|
||||||
|
|
||||||
logger.addTarget('file', { path: profileDir + '/log.txt' });
|
logger.addTarget('file', { path: profileDir + '/log.txt' });
|
||||||
logger.setLevel(logLevel);
|
logger.setLevel(logLevel);
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
"sqlite3": "^3.1.8",
|
"sqlite3": "^3.1.8",
|
||||||
"string-to-stream": "^1.1.0",
|
"string-to-stream": "^1.1.0",
|
||||||
"tcp-port-used": "^0.1.2",
|
"tcp-port-used": "^0.1.2",
|
||||||
"temp": "^0.8.3",
|
|
||||||
"uuid": "^3.0.1",
|
"uuid": "^3.0.1",
|
||||||
"vorpal": "^1.12.0"
|
"vorpal": "^1.12.0"
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
CLIENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CLIENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes2 --stack-trace-enabled --redraw-disabled "$@"
|
bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes2 --stack-trace-enabled --log-level debug --redraw-disabled "$@"
|
||||||
#bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes import-enex --fuzzy-matching /home/laurent/Desktop/afaire.enex afaire
|
#bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes import-enex --fuzzy-matching /home/laurent/Desktop/afaire.enex afaire
|
||||||
#bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes import-enex --fuzzy-matching /home/laurent/Desktop/Laurent.enex laurent
|
#bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes import-enex --fuzzy-matching /home/laurent/Desktop/Laurent.enex laurent
|
@ -35,11 +35,6 @@ class BaseItem extends BaseModel {
|
|||||||
let d = BaseItem.syncItemDefinitions_[i];
|
let d = BaseItem.syncItemDefinitions_[i];
|
||||||
if (Number(item) == d.type) return this.getClass(d.className);
|
if (Number(item) == d.type) return this.getClass(d.className);
|
||||||
}
|
}
|
||||||
// if (Number(item) === BaseModel.TYPE_NOTE) return this.getClass('Note');
|
|
||||||
// if (Number(item) === BaseModel.TYPE_FOLDER) return this.getClass('Folder');
|
|
||||||
// if (Number(item) === BaseModel.TYPE_RESOURCE) return this.getClass('Resource');
|
|
||||||
// if (Number(item) === BaseModel.TYPE_TAG) return this.getClass('Tag');
|
|
||||||
// if (Number(item) === BaseModel.TYPE_NOTE_TAG) return this.getClass('NoteTag');
|
|
||||||
throw new Error('Unknown type: ' + item);
|
throw new Error('Unknown type: ' + item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,7 +139,7 @@ class BaseItem extends BaseModel {
|
|||||||
|
|
||||||
if ('body' in item) {
|
if ('body' in item) {
|
||||||
output.push(item.body);
|
output.push(item.body);
|
||||||
output.push('');
|
if (shownKeys.length) output.push('');
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < shownKeys.length; i++) {
|
for (let i = 0; i < shownKeys.length; i++) {
|
||||||
@ -169,6 +164,7 @@ class BaseItem extends BaseModel {
|
|||||||
let output = {};
|
let output = {};
|
||||||
let state = 'readingProps';
|
let state = 'readingProps';
|
||||||
let body = [];
|
let body = [];
|
||||||
|
|
||||||
for (let i = lines.length - 1; i >= 0; i--) {
|
for (let i = lines.length - 1; i >= 0; i--) {
|
||||||
let line = lines[i];
|
let line = lines[i];
|
||||||
|
|
||||||
|
@ -24,6 +24,11 @@ class Note extends BaseItem {
|
|||||||
return super.serialize(note, 'note', []);
|
return super.serialize(note, 'note', []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async unserializeForEdit(content) {
|
||||||
|
content += "\n\ntype_: " + BaseModel.TYPE_NOTE;
|
||||||
|
return super.unserialize(content);
|
||||||
|
}
|
||||||
|
|
||||||
static modelType() {
|
static modelType() {
|
||||||
return BaseModel.TYPE_NOTE;
|
return BaseModel.TYPE_NOTE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user