Extend add-on API with setConfigUpdatedAction

Allows add-on authors to define an action to be performed upon
manual editing of the add-on configuration through the ConfigEditor
This commit is contained in:
Glutanimate 2018-07-28 09:00:49 +02:00
parent 8325f5b396
commit 8935b99188

View File

@ -204,6 +204,7 @@ When loading '%(name)s':
######################################################################
_configButtonActions = {}
_configUpdatedActions = {}
def addonConfigDefaults(self, dir):
path = os.path.join(self.addonsFolder(dir), "config.json")
@ -227,6 +228,9 @@ When loading '%(name)s':
def configAction(self, addon):
return self._configButtonActions.get(addon)
def configUpdatedAction(self, addon):
return self._configUpdatedActions.get(addon)
# Add-on Config API
######################################################################
@ -246,6 +250,10 @@ When loading '%(name)s':
addon = self.addonFromModule(module)
self._configButtonActions[addon] = fn
def setConfigUpdatedAction(self, module, fn):
addon = self.addonFromModule(module)
self._configUpdatedActions[addon] = fn
def writeConfig(self, module, conf):
addon = self.addonFromModule(module)
meta = self.addonMeta(addon)
@ -484,4 +492,9 @@ class ConfigEditor(QDialog):
return
self.mgr.writeConfig(self.addon, self.conf)
act = self.mgr.configUpdatedAction(self.addon)
if act:
act()
super().accept()