1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-03-20 20:55:18 +02:00

Added ren command

This commit is contained in:
Laurent Cozic 2017-10-26 23:22:36 +01:00
parent 9628d369a3
commit e4435a4fb6
6 changed files with 76 additions and 17 deletions

View File

@ -92,12 +92,12 @@ class Application {
let output = await this.loadItems(type, pattern, options); let output = await this.loadItems(type, pattern, options);
if (output.length > 1) { if (output.length > 1) {
output.sort((a, b) => { return a.user_updated_time < b.user_updated_time ? +1 : -1; }); // output.sort((a, b) => { return a.user_updated_time < b.user_updated_time ? +1 : -1; });
let answers = { 0: _('[Cancel]') }; // let answers = { 0: _('[Cancel]') };
for (let i = 0; i < output.length; i++) { // for (let i = 0; i < output.length; i++) {
answers[i + 1] = output[i].title; // answers[i + 1] = output[i].title;
} // }
// Not really useful with new UI? // Not really useful with new UI?
throw new Error(_('More than one item match "%s". Please narrow down your query.', pattern)); throw new Error(_('More than one item match "%s". Please narrow down your query.', pattern));
@ -113,6 +113,12 @@ class Application {
} }
async loadItems(type, pattern, options = null) { async loadItems(type, pattern, options = null) {
if (type === 'folderOrNote') {
const folders = await this.loadItems(BaseModel.TYPE_FOLDER, pattern, options);
if (folders.length) return folders;
return await this.loadItems(BaseModel.TYPE_NOTE, pattern, options);
}
pattern = pattern ? pattern.toString() : ''; pattern = pattern ? pattern.toString() : '';
if (type == BaseModel.TYPE_FOLDER && (pattern == Folder.conflictFolderTitle() || pattern == Folder.conflictFolderId())) return [Folder.conflictFolder()]; if (type == BaseModel.TYPE_FOLDER && (pattern == Folder.conflictFolderTitle() || pattern == Folder.conflictFolderId())) return [Folder.conflictFolder()];

View File

@ -74,8 +74,6 @@ class Command extends BaseCommand {
this.logger().info('Disabling fullscreen...'); this.logger().info('Disabling fullscreen...');
//this.stdout(_('Starting to edit note. Close the editor to get back to the prompt.'));
app().gui().showModalOverlay(_('Starting to edit note. Close the editor to get back to the prompt.')); app().gui().showModalOverlay(_('Starting to edit note. Close the editor to get back to the prompt.'));
app().gui().forceRender(); app().gui().forceRender();
const termState = app().gui().term().saveState(); const termState = app().gui().term().saveState();

View File

@ -0,0 +1,52 @@
import { BaseCommand } from './base-command.js';
import { app } from './app.js';
import { _ } from 'lib/locale.js';
import { BaseModel } from 'lib/base-model.js';
import { Folder } from 'lib/models/folder.js';
import { Note } from 'lib/models/note.js';
class Command extends BaseCommand {
usage() {
return 'ren <item> <name>';
}
description() {
return _('Renames the given <item> (note or notebook) to <name>.');
}
async action(args) {
const pattern = args['item'];
const name = args['name'];
const item = await app().loadItem('folderOrNote', pattern);
if (!item) throw new Error(_('Cannot find "%s".', pattern));
const newItem = {
id: item.id,
title: name,
type_: item.type_,
};
if (item.type_ === BaseModel.TYPE_FOLDER) {
await Folder.save(newItem);
} else {
await Note.save(newItem);
}
// const folder = await Folder.loadByField('title', destination);
// if (!folder) throw new Error(_('Cannot find "%s".', destination));
// const notes = await app().loadItems(BaseModel.TYPE_NOTE, pattern);
// if (!notes.length) throw new Error(_('Cannot find "%s".', pattern));
// for (let i = 0; i < notes.length; i++) {
// await Note.moveToFolder(notes[i].id, folder.id);
// }
}
}
module.exports = Command;

View File

@ -69,9 +69,6 @@ msgstr ""
msgid "Press Ctrl+D or type \"exit\" to exit the application" msgid "Press Ctrl+D or type \"exit\" to exit the application"
msgstr "" msgstr ""
msgid "[Cancel]"
msgstr ""
#, javascript-format #, javascript-format
msgid "More than one item match \"%s\". Please narrow down your query." msgid "More than one item match \"%s\". Please narrow down your query."
msgstr "" msgstr ""
@ -374,6 +371,9 @@ msgstr ""
msgid "Moves the notes matching <note> to [notebook]." msgid "Moves the notes matching <note> to [notebook]."
msgstr "" msgstr ""
msgid "Renames the given <item> (note or notebook) to <name>."
msgstr ""
msgid "Deletes the given notebook." msgid "Deletes the given notebook."
msgstr "" msgstr ""

View File

@ -78,10 +78,6 @@ msgstr "Impossible de déplacer la note vers le carnet \"%s\""
msgid "Press Ctrl+D or type \"exit\" to exit the application" msgid "Press Ctrl+D or type \"exit\" to exit the application"
msgstr "" msgstr ""
#, fuzzy
msgid "[Cancel]"
msgstr "Annulation..."
#, javascript-format #, javascript-format
msgid "More than one item match \"%s\". Please narrow down your query." msgid "More than one item match \"%s\". Please narrow down your query."
msgstr "" msgstr ""
@ -417,6 +413,9 @@ msgstr "Créer une nouvelle tâche."
msgid "Moves the notes matching <note> to [notebook]." msgid "Moves the notes matching <note> to [notebook]."
msgstr "Supprime les objets correspondants à <motif>." msgstr "Supprime les objets correspondants à <motif>."
msgid "Renames the given <item> (note or notebook) to <name>."
msgstr ""
#, fuzzy #, fuzzy
msgid "Deletes the given notebook." msgid "Deletes the given notebook."
msgstr "Supprime le carnet." msgstr "Supprime le carnet."
@ -859,6 +858,10 @@ msgstr ""
msgid "Welcome" msgid "Welcome"
msgstr "Bienvenue" msgstr "Bienvenue"
#, fuzzy
#~ msgid "[Cancel]"
#~ msgstr "Annulation..."
#~ msgid "Todo filter" #~ msgid "Todo filter"
#~ msgstr "Filtre des tâches" #~ msgstr "Filtre des tâches"

View File

@ -69,9 +69,6 @@ msgstr ""
msgid "Press Ctrl+D or type \"exit\" to exit the application" msgid "Press Ctrl+D or type \"exit\" to exit the application"
msgstr "" msgstr ""
msgid "[Cancel]"
msgstr ""
#, javascript-format #, javascript-format
msgid "More than one item match \"%s\". Please narrow down your query." msgid "More than one item match \"%s\". Please narrow down your query."
msgstr "" msgstr ""
@ -374,6 +371,9 @@ msgstr ""
msgid "Moves the notes matching <note> to [notebook]." msgid "Moves the notes matching <note> to [notebook]."
msgstr "" msgstr ""
msgid "Renames the given <item> (note or notebook) to <name>."
msgstr ""
msgid "Deletes the given notebook." msgid "Deletes the given notebook."
msgstr "" msgstr ""