Add modal manager to plugin API

This commit is contained in:
Samuel Elliott 2018-03-02 20:19:59 +00:00
parent e94a7c50a4
commit fdc9330195
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
4 changed files with 37 additions and 10 deletions

View File

@ -138,6 +138,34 @@ export default class PluginApi {
}; };
} }
get modalStack() {
return this._modalStack || (this._modalStack = []);
}
addModal(modal, component) {
const modal = Modals.add(modal);
modal.close = force => this.closeModal(force);
}
async closeModal(modal, force) {
await Modals.close(modal, force);
this._modalStack = this.modalStack.filter(m => m !== modal);
}
closeAllModals() {
for (let modal of this.modalStack)
modal.close();
}
closeLastModal() {
if (!this.modalStack.length) return;
this.modalStack[this.modalStack.length - 1].close();
}
get Modals() {
return {
add: this.addModal.bind(this),
close: this.closeModal.bind(this),
closeAll: this.closeAllModals.bind(this),
closeLastModal: this.closeLastModal.bind(this)
};
}
async getPlugin(plugin_id) { async getPlugin(plugin_id) {
// This should require extra permissions // This should require extra permissions
return await PluginManager.waitForPlugin(plugin_id); return await PluginManager.waitForPlugin(plugin_id);

View File

@ -55,7 +55,7 @@
this.saving = true; this.saving = true;
try { try {
if (this.modal.saveSettings) await this.modal.saveSettings(this.settings); if (this.modal.saveSettings) await this.modal.saveSettings(this.settings);
else this.modal.settings.merge(this.settings); else await this.modal.settings.merge(this.settings);
} catch (err) { } catch (err) {
// TODO Display error that settings failed to save // TODO Display error that settings failed to save
Logger.err('SettingsModal', ['Failed to save settings:', err]); Logger.err('SettingsModal', ['Failed to save settings:', err]);

View File

@ -122,13 +122,12 @@ export default class {
} }
} }
static settings(settings, headertext, saveSettings) { static settings(settingsset, headertext, options) {
return this.add({ return this.add(Object.assign({
headertext, settings, schemes: settings.schemes, headertext: headertext ? headertext : settingsset.headertext,
saveSettings: saveSettings ? saveSettings : newSettings => { settings: settingsset,
return settings.merge(newSettings); schemes: settings.schemes
} }, options), SettingsModal);
}, SettingsModal);
} }
static internalSettings(set_id) { static internalSettings(set_id) {