You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
Plugins: Added joplin.workspace.selectedFolder()
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
import Setting from '@joplin/lib/models/Setting';
|
||||||
import PluginService from '@joplin/lib/services/plugins/PluginService';
|
import PluginService from '@joplin/lib/services/plugins/PluginService';
|
||||||
|
|
||||||
const { newPluginService, newPluginScript, setupDatabaseAndSynchronizer, switchClient, afterEachCleanUp } = require('../../../test-utils');
|
const { newPluginService, newPluginScript, setupDatabaseAndSynchronizer, switchClient, afterEachCleanUp } = require('../../../test-utils');
|
||||||
@ -49,4 +50,26 @@ describe('JoplinWorkspace', () => {
|
|||||||
await service.destroy();
|
await service.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should return the selected folder', async () => {
|
||||||
|
const service = new newPluginService() as PluginService;
|
||||||
|
|
||||||
|
const pluginScript = newPluginScript(`
|
||||||
|
joplin.plugins.register({
|
||||||
|
onStart: async function() {
|
||||||
|
const folder = await joplin.workspace.selectedFolder();
|
||||||
|
await joplin.data.put(['folders', folder.id], null, { title: "changedtitle" });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
`);
|
||||||
|
|
||||||
|
const folder = await Folder.save({ title: 'folder' });
|
||||||
|
Setting.setValue('activeFolderId', folder.id);
|
||||||
|
|
||||||
|
const plugin = await service.loadPluginFromJsBundle('', pluginScript);
|
||||||
|
await service.runPlugin(plugin);
|
||||||
|
|
||||||
|
const modFolder = await Folder.load(folder.id);
|
||||||
|
expect(modFolder.title).toBe('changedtitle');
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { ModelType } from '../../../BaseModel';
|
import { ModelType } from '../../../BaseModel';
|
||||||
import eventManager from '../../../eventManager';
|
import eventManager from '../../../eventManager';
|
||||||
|
import Setting from '../../../models/Setting';
|
||||||
|
import { FolderEntity } from '../../database/types';
|
||||||
import makeListener from '../utils/makeListener';
|
import makeListener from '../utils/makeListener';
|
||||||
import { Disposable } from './types';
|
import { Disposable } from './types';
|
||||||
|
|
||||||
@ -8,6 +10,11 @@ import { Disposable } from './types';
|
|||||||
*/
|
*/
|
||||||
const Note = require('../../../models/Note');
|
const Note = require('../../../models/Note');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
const Folder = require('../../../models/Folder');
|
||||||
|
|
||||||
enum ItemChangeEventType {
|
enum ItemChangeEventType {
|
||||||
Create = 1,
|
Create = 1,
|
||||||
Update = 2,
|
Update = 2,
|
||||||
@ -114,6 +121,17 @@ export default class JoplinWorkspace {
|
|||||||
return Note.load(noteIds[0]);
|
return Note.load(noteIds[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the currently selected folder. In some cases, for example during
|
||||||
|
* search or when viewing a tag, no folder is actually selected in the user
|
||||||
|
* interface. In that case, that function would return the last selected
|
||||||
|
* folder.
|
||||||
|
*/
|
||||||
|
public async selectedFolder(): Promise<FolderEntity> {
|
||||||
|
const folderId = Setting.value('activeFolderId');
|
||||||
|
return folderId ? await Folder.load(folderId) : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the IDs of the selected notes (can be zero, one, or many). Use the data API to retrieve information about these notes.
|
* Gets the IDs of the selected notes (can be zero, one, or many). Use the data API to retrieve information about these notes.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user