Unset values properly
This commit is contained in:
parent
74a7676111
commit
2a7998847f
@ -93,6 +93,13 @@ class Base:
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def unset(self, settings=None):
|
||||||
|
"""Unset a customized setting.
|
||||||
|
|
||||||
|
Must be overridden by subclasses.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class Attribute(Base):
|
class Attribute(Base):
|
||||||
|
|
||||||
@ -118,6 +125,11 @@ class Attribute(Base):
|
|||||||
for attribute in self._attributes:
|
for attribute in self._attributes:
|
||||||
obj.setAttribute(attribute, value)
|
obj.setAttribute(attribute, value)
|
||||||
|
|
||||||
|
def unset(self, settings=None):
|
||||||
|
for obj in self._get_settings(settings):
|
||||||
|
for attribute in self._attributes:
|
||||||
|
obj.resetAttribute(attribute)
|
||||||
|
|
||||||
|
|
||||||
class Setter(Base):
|
class Setter(Base):
|
||||||
|
|
||||||
@ -211,12 +223,23 @@ def update_mappings(mappings, option):
|
|||||||
def update_for_tab(mappings, tab, url):
|
def update_for_tab(mappings, tab, url):
|
||||||
"""Update settings customized for the given tab."""
|
"""Update settings customized for the given tab."""
|
||||||
for opt, values in config.instance:
|
for opt, values in config.instance:
|
||||||
|
if opt.name not in mappings:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# FIXME:conf handle settings != None with global/static setters
|
||||||
|
mapping = mappings[opt.name]
|
||||||
|
|
||||||
value = values.get_for_url(url, fallback=False)
|
value = values.get_for_url(url, fallback=False)
|
||||||
if value is not configutils.UNSET and opt.name in mappings:
|
# FIXME:conf have a proper API for this.
|
||||||
# FIXME:conf handle settings != None with global/static setters
|
settings = tab._widget.settings()
|
||||||
mapping = mappings[opt.name]
|
|
||||||
# FIXME:conf have a proper API for this.
|
if value is configutils.UNSET:
|
||||||
mapping.set(value, settings=tab._widget.settings())
|
try:
|
||||||
|
mapping.unset(settings=settings)
|
||||||
|
except NotImplementedError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
mapping.set(value, settings=settings)
|
||||||
|
|
||||||
|
|
||||||
def init(args):
|
def init(args):
|
||||||
|
Loading…
Reference in New Issue
Block a user