backward compatibility, space, combinations
This commit is contained in:
parent
0305dedbfb
commit
dfa276a20c
@ -1233,32 +1233,19 @@ class ConfirmQuit(List):
|
|||||||
valid_values = ValidValues(('always', "Always show a confirmation."),
|
valid_values = ValidValues(('always', "Always show a confirmation."),
|
||||||
('multiple-tabs', "Show a confirmation if "
|
('multiple-tabs', "Show a confirmation if "
|
||||||
"multiple tabs are opened."),
|
"multiple tabs are opened."),
|
||||||
('downloads', "show a confirmation if downloads"
|
('downloads', "show a confirmation if downloads "
|
||||||
"are running"),
|
"are running"),
|
||||||
('never', "Never show a confirmation."))
|
('never', "Never show a confirmation."))
|
||||||
# Values that can be combined with commas
|
# Values that can be combined with commas
|
||||||
combinable_values = ('multiple-tabs', 'downloads')
|
combinable_values = ('multiple-tabs', 'downloads')
|
||||||
|
|
||||||
def transform(self, value):
|
|
||||||
# Backward compatible
|
|
||||||
if value == 'never':
|
|
||||||
return value
|
|
||||||
# Split configuration string into list
|
|
||||||
else:
|
|
||||||
return super().transform(value)
|
|
||||||
|
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
values = self.transform(value)
|
values = self.transform(value)
|
||||||
# Backward compatibility
|
|
||||||
if values == 'never':
|
|
||||||
return
|
|
||||||
# Never can't be set with other options
|
# Never can't be set with other options
|
||||||
elif 'never' in values and isinstance(values,
|
if 'never' in values and len(values) > 1:
|
||||||
list) and len(values) > 1:
|
|
||||||
raise configexc.ValidationError(value, "List cannot contain never!")
|
raise configexc.ValidationError(value, "List cannot contain never!")
|
||||||
# Always can't be set with other options
|
# Always can't be set with other options
|
||||||
elif 'always' in values and isinstance(values,
|
elif 'always' in values and len(values) > 1:
|
||||||
list) and len(values) > 1:
|
|
||||||
raise configexc.ValidationError(value,
|
raise configexc.ValidationError(value,
|
||||||
"List cannot contain always!")
|
"List cannot contain always!")
|
||||||
# Values have to be valid
|
# Values have to be valid
|
||||||
@ -1271,17 +1258,17 @@ class ConfirmQuit(List):
|
|||||||
" values!")
|
" values!")
|
||||||
|
|
||||||
def complete(self):
|
def complete(self):
|
||||||
permutations = []
|
combinations = []
|
||||||
# Generate combinations of the options that can be combined
|
# Generate combinations of the options that can be combined
|
||||||
for size in range(2, len(self.combinable_values) + 1):
|
for size in range(2, len(self.combinable_values) + 1):
|
||||||
permutations = permutations + list(
|
combinations = combinations + list(
|
||||||
itertools.permutations(self.combinable_values, size))
|
itertools.combinations(self.combinable_values, size))
|
||||||
out = []
|
out = []
|
||||||
# Add valid single values
|
# Add valid single values
|
||||||
for val in self.valid_values:
|
for val in self.valid_values:
|
||||||
out.append((val, self.valid_values.descriptions[val]))
|
out.append((val, self.valid_values.descriptions[val]))
|
||||||
# Add combinations to list of options
|
# Add combinations to list of options
|
||||||
for val in permutations:
|
for val in combinations:
|
||||||
desc = ''
|
desc = ''
|
||||||
val = ','.join(val)
|
val = ','.join(val)
|
||||||
out.append((val, desc))
|
out.append((val, desc))
|
||||||
|
Loading…
Reference in New Issue
Block a user