Add live adding schemes and fix PluginApi.Settings
This commit is contained in:
parent
e67c08ff02
commit
07dde5b1fa
|
@ -106,7 +106,7 @@ export default class PluginApi {
|
||||||
}
|
}
|
||||||
get Settings() {
|
get Settings() {
|
||||||
return {
|
return {
|
||||||
createSet: this.createSet.bind(this),
|
createSet: this.createSettingsSet.bind(this),
|
||||||
createCategory: this.createSettingsCategory.bind(this),
|
createCategory: this.createSettingsCategory.bind(this),
|
||||||
createSetting: this.createSetting.bind(this),
|
createSetting: this.createSetting.bind(this),
|
||||||
createScheme: this.createSettingsScheme.bind(this)
|
createScheme: this.createSettingsScheme.bind(this)
|
||||||
|
|
|
@ -181,6 +181,50 @@ export default class SettingsSet {
|
||||||
await this.emit('removed-category', event);
|
await this.emit('removed-category', event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dynamically adds a scheme to this set.
|
||||||
|
* @param {SettingsScheme} scheme The scheme to add to this set
|
||||||
|
* @param {Number} index The index to add the scheme at (optional)
|
||||||
|
* @return {Promise}
|
||||||
|
*/
|
||||||
|
async addScheme(scheme, index) {
|
||||||
|
if (this.schemes.find(c => c === scheme)) return;
|
||||||
|
|
||||||
|
if (!(scheme instanceof SettingsScheme))
|
||||||
|
scheme = new SettingsScheme(scheme);
|
||||||
|
|
||||||
|
if (this.schemes.find(s => s.id === scheme.id))
|
||||||
|
throw {message: 'A scheme with this ID already exists.'};
|
||||||
|
|
||||||
|
if (index === undefined) index = this.schemes.length;
|
||||||
|
this.schemes.splice(index, 0, scheme);
|
||||||
|
|
||||||
|
await this.emit('added-scheme', {
|
||||||
|
set: this, set_id: this.id,
|
||||||
|
scheme, scheme_id: scheme.id,
|
||||||
|
at_index: index
|
||||||
|
});
|
||||||
|
return scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dynamically removes a scheme from this set.
|
||||||
|
* @param {SettingsScheme} scheme The scheme to remove from this set
|
||||||
|
* @return {Promise}
|
||||||
|
*/
|
||||||
|
async removeScheme(scheme) {
|
||||||
|
let index;
|
||||||
|
while ((index = this.schemes.findIndex(s => s === scheme)) > -1) {
|
||||||
|
this.schemes.splice(index, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.emit('removed-scheme', {
|
||||||
|
set: this, set_id: this.id,
|
||||||
|
scheme, scheme_id: scheme.id,
|
||||||
|
from_index: index
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the first category where calling {function} returns true.
|
* Returns the first category where calling {function} returns true.
|
||||||
* @param {Function} function A function to call to filter categories
|
* @param {Function} function A function to call to filter categories
|
||||||
|
|
Loading…
Reference in New Issue