2017-11-03 02:09:34 +02:00
|
|
|
const { BaseCommand } = require('./base-command.js');
|
2020-11-07 17:59:37 +02:00
|
|
|
const { _ } = require('@joplin/lib/locale');
|
|
|
|
const BaseModel = require('@joplin/lib/BaseModel').default;
|
2021-01-22 19:41:11 +02:00
|
|
|
const Folder = require('@joplin/lib/models/Folder').default;
|
2020-11-07 17:59:37 +02:00
|
|
|
const uuid = require('@joplin/lib/uuid').default;
|
2017-07-17 21:56:14 +02:00
|
|
|
|
|
|
|
class Command extends BaseCommand {
|
|
|
|
usage() {
|
2017-07-28 20:13:07 +02:00
|
|
|
return 'search <pattern> [notebook]';
|
2017-07-17 21:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
description() {
|
2017-07-18 20:21:03 +02:00
|
|
|
return _('Searches for the given <pattern> in all the notes.');
|
2017-07-17 21:56:14 +02:00
|
|
|
}
|
|
|
|
|
2017-10-24 23:37:36 +02:00
|
|
|
compatibleUis() {
|
|
|
|
return ['gui'];
|
|
|
|
}
|
|
|
|
|
2017-07-17 21:56:14 +02:00
|
|
|
async action(args) {
|
2020-03-14 01:46:14 +02:00
|
|
|
const pattern = args['pattern'];
|
|
|
|
const folderTitle = args['notebook'];
|
2017-07-17 21:56:14 +02:00
|
|
|
|
|
|
|
let folder = null;
|
|
|
|
if (folderTitle) {
|
|
|
|
folder = await Folder.loadByTitle(folderTitle);
|
2017-07-18 20:21:03 +02:00
|
|
|
if (!folder) throw new Error(_('Cannot find "%s".', folderTitle));
|
2017-07-17 21:56:14 +02:00
|
|
|
}
|
|
|
|
|
2017-10-23 22:34:04 +02:00
|
|
|
const searchId = uuid.create();
|
|
|
|
|
|
|
|
this.dispatch({
|
|
|
|
type: 'SEARCH_ADD',
|
|
|
|
search: {
|
|
|
|
id: searchId,
|
|
|
|
title: pattern,
|
|
|
|
query_pattern: pattern,
|
|
|
|
query_folder_id: folder ? folder.id : '',
|
|
|
|
type_: BaseModel.TYPE_SEARCH,
|
|
|
|
},
|
2017-07-17 21:56:14 +02:00
|
|
|
});
|
|
|
|
|
2017-10-23 22:34:04 +02:00
|
|
|
this.dispatch({
|
|
|
|
type: 'SEARCH_SELECT',
|
2017-10-23 23:48:29 +02:00
|
|
|
id: searchId,
|
2017-10-23 22:34:04 +02:00
|
|
|
});
|
2017-07-17 21:56:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
module.exports = Command;
|