mirror of
https://github.com/laurent22/joplin.git
synced 2026-06-06 20:10:22 +00:00
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import BaseCommand from './base-command';
|
|
import app from './app';
|
|
import { _ } from '@joplin/lib/locale';
|
|
import { ModelType } from '@joplin/lib/BaseModel';
|
|
import Folder from '@joplin/lib/models/Folder';
|
|
|
|
class Command extends BaseCommand {
|
|
public override usage() {
|
|
return 'use <notebook>';
|
|
}
|
|
|
|
public override description() {
|
|
return _('Switches to [notebook] - all further operations will happen within this notebook.');
|
|
}
|
|
|
|
public override compatibleUis() {
|
|
return ['cli'];
|
|
}
|
|
|
|
public override async action(args: { 'notebook': string }) {
|
|
const folder = await app().loadItem(ModelType.Folder, args['notebook']);
|
|
if (!folder) throw new Error(_('Cannot find "%s".', args['notebook']));
|
|
|
|
// Auto-expand parent folders in GUI if present
|
|
if (app().gui() && app().gui().widget && app().gui().widget('folderList')) {
|
|
const folderListWidget = app().gui().widget('folderList');
|
|
if (folderListWidget.expandToFolder) {
|
|
// Get all folders to pass to expandToFolder
|
|
const folders = await Folder.all();
|
|
folderListWidget.folders = folders; // Ensure widget has current folders
|
|
folderListWidget.expandToFolder(folder.id);
|
|
}
|
|
}
|
|
|
|
app().switchCurrentFolder(folder);
|
|
}
|
|
}
|
|
|
|
module.exports = Command;
|