Fix plugin API modal manager

This commit is contained in:
Samuel Elliott 2018-03-02 20:48:29 +00:00
parent fdc9330195
commit 2060a41f5d
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
3 changed files with 25 additions and 8 deletions

View File

@ -14,7 +14,8 @@ import ExtModuleManager from './extmodulemanager';
import PluginManager from './pluginmanager'; import PluginManager from './pluginmanager';
import ThemeManager from './thememanager'; import ThemeManager from './thememanager';
import Events from './events'; import Events from './events';
import { DOM } from 'ui'; import { Modals, DOM } from 'ui';
import SettingsModal from '../ui/components/bd/modals/SettingsModal.vue';
class EventsWrapper { class EventsWrapper {
constructor(eventemitter) { constructor(eventemitter) {
@ -141,9 +142,11 @@ export default class PluginApi {
get modalStack() { get modalStack() {
return this._modalStack || (this._modalStack = []); return this._modalStack || (this._modalStack = []);
} }
addModal(modal, component) { addModal(_modal, component) {
const modal = Modals.add(modal); const modal = Modals.add(_modal, component);
modal.close = force => this.closeModal(force); modal.close = force => this.closeModal(modal, force);
this.modalStack.push(modal);
return modal;
} }
async closeModal(modal, force) { async closeModal(modal, force) {
await Modals.close(modal, force); await Modals.close(modal, force);
@ -157,13 +160,23 @@ export default class PluginApi {
if (!this.modalStack.length) return; if (!this.modalStack.length) return;
this.modalStack[this.modalStack.length - 1].close(); this.modalStack[this.modalStack.length - 1].close();
} }
settingsModal(settingsset, headertext, options) {
return this.addModal(Object.assign({
headertext: headertext ? headertext : settingsset.headertext,
settings: settingsset,
schemes: settingsset.schemes
}, options), SettingsModal);
}
get Modals() { get Modals() {
return { return Object.defineProperty({
add: this.addModal.bind(this), add: this.addModal.bind(this),
close: this.closeModal.bind(this), close: this.closeModal.bind(this),
closeAll: this.closeAllModals.bind(this), closeAll: this.closeAllModals.bind(this),
closeLastModal: this.closeLastModal.bind(this) closeLast: this.closeLastModal.bind(this),
}; settings: this.settingsModal.bind(this)
}, 'stack', {
get: () => this.modalStack
});
} }
async getPlugin(plugin_id) { async getPlugin(plugin_id) {

View File

@ -126,7 +126,7 @@ export default class {
return this.add(Object.assign({ return this.add(Object.assign({
headertext: headertext ? headertext : settingsset.headertext, headertext: headertext ? headertext : settingsset.headertext,
settings: settingsset, settings: settingsset,
schemes: settings.schemes schemes: settingsset.schemes
}, options), SettingsModal); }, options), SettingsModal);
} }

View File

@ -4,6 +4,10 @@ module.exports = (Plugin, Api, Vendor, Dependencies) => {
const { Events, Logger, InternalSettings, CssUtils } = Api; const { Events, Logger, InternalSettings, CssUtils } = Api;
return class extends Plugin { return class extends Plugin {
get api() {
return Api;
}
async onStart() { async onStart() {
await this.injectStyles(); await this.injectStyles();