2014-06-21 22:41:04 +02:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
2014-06-19 09:04:37 +02:00
|
|
|
|
2017-05-09 21:37:03 +02:00
|
|
|
# Copyright 2014-2017 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
2014-02-06 14:01:23 +01:00
|
|
|
#
|
|
|
|
# This file is part of qutebrowser.
|
|
|
|
#
|
|
|
|
# qutebrowser is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# qutebrowser is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
2014-01-29 15:30:19 +01:00
|
|
|
|
2016-09-16 21:41:54 +02:00
|
|
|
"""Functions that return config-related completion models."""
|
2014-04-17 17:44:27 +02:00
|
|
|
|
2017-02-20 02:58:10 +01:00
|
|
|
from qutebrowser.config import configdata, configexc
|
2017-02-23 04:25:11 +01:00
|
|
|
from qutebrowser.completion.models import completionmodel
|
2017-02-20 02:58:10 +01:00
|
|
|
from qutebrowser.utils import objreg
|
2014-01-27 21:42:00 +01:00
|
|
|
|
|
|
|
|
2016-09-16 21:41:54 +02:00
|
|
|
def section():
|
2014-04-25 12:29:00 +02:00
|
|
|
"""A CompletionModel filled with settings sections."""
|
2017-02-23 04:25:11 +01:00
|
|
|
model = completionmodel.CompletionModel(column_widths=(20, 70, 10))
|
|
|
|
sections = ((name, configdata.SECTION_DESC[name].splitlines()[0].strip())
|
|
|
|
for name in configdata.DATA)
|
|
|
|
model.add_list("Sections", sections)
|
2016-09-16 21:41:54 +02:00
|
|
|
return model
|
2014-02-07 20:21:50 +01:00
|
|
|
|
2014-02-19 10:58:32 +01:00
|
|
|
|
2016-09-16 21:41:54 +02:00
|
|
|
def option(sectname):
|
2014-05-02 16:23:11 +02:00
|
|
|
"""A CompletionModel filled with settings and their descriptions.
|
|
|
|
|
2016-09-16 21:41:54 +02:00
|
|
|
Args:
|
|
|
|
sectname: The name of the config section this model shows.
|
2014-05-02 16:23:11 +02:00
|
|
|
"""
|
2017-02-23 04:25:11 +01:00
|
|
|
model = completionmodel.CompletionModel(column_widths=(20, 70, 10))
|
2016-09-16 21:41:54 +02:00
|
|
|
try:
|
|
|
|
sectdata = configdata.DATA[sectname]
|
|
|
|
except KeyError:
|
|
|
|
return None
|
2017-02-23 04:25:11 +01:00
|
|
|
options = []
|
2016-09-16 21:41:54 +02:00
|
|
|
for name in sectdata:
|
2014-05-02 16:23:51 +02:00
|
|
|
try:
|
2016-09-16 21:41:54 +02:00
|
|
|
desc = sectdata.descriptions[name]
|
|
|
|
except (KeyError, AttributeError):
|
|
|
|
# Some stuff (especially ValueList items) don't have a
|
|
|
|
# description.
|
|
|
|
desc = ""
|
|
|
|
else:
|
|
|
|
desc = desc.splitlines()[0]
|
2017-02-20 02:58:10 +01:00
|
|
|
config = objreg.get('config')
|
2016-09-16 21:41:54 +02:00
|
|
|
val = config.get(sectname, name, raw=True)
|
2017-02-23 04:25:11 +01:00
|
|
|
options.append((name, desc, val))
|
|
|
|
model.add_list(sectname, options)
|
2016-09-16 21:41:54 +02:00
|
|
|
return model
|
2014-02-19 10:58:32 +01:00
|
|
|
|
|
|
|
|
2016-09-16 21:41:54 +02:00
|
|
|
def value(sectname, optname):
|
2014-10-18 19:50:10 +02:00
|
|
|
"""A CompletionModel filled with setting values.
|
|
|
|
|
2016-09-16 21:41:54 +02:00
|
|
|
Args:
|
|
|
|
sectname: The name of the config section this model shows.
|
|
|
|
optname: The name of the config option this model shows.
|
2014-10-18 19:50:10 +02:00
|
|
|
"""
|
2017-02-23 04:25:11 +01:00
|
|
|
model = completionmodel.CompletionModel(column_widths=(20, 70, 10))
|
2017-02-20 02:58:10 +01:00
|
|
|
config = objreg.get('config')
|
2017-02-23 04:25:11 +01:00
|
|
|
|
2016-09-16 21:41:54 +02:00
|
|
|
try:
|
2017-02-23 04:25:11 +01:00
|
|
|
current = config.get(sectname, optname, raw=True) or '""'
|
2016-09-16 21:41:54 +02:00
|
|
|
except (configexc.NoSectionError, configexc.NoOptionError):
|
|
|
|
return None
|
2017-02-23 04:25:11 +01:00
|
|
|
|
|
|
|
default = configdata.DATA[sectname][optname].default() or '""'
|
|
|
|
|
2016-09-16 21:41:54 +02:00
|
|
|
if hasattr(configdata.DATA[sectname], 'valtype'):
|
|
|
|
# Same type for all values (ValueList)
|
|
|
|
vals = configdata.DATA[sectname].valtype.complete()
|
|
|
|
else:
|
|
|
|
if optname is None:
|
|
|
|
raise ValueError("optname may only be None for ValueList "
|
|
|
|
"sections, but {} is not!".format(sectname))
|
|
|
|
# Different type for each value (KeyValue)
|
|
|
|
vals = configdata.DATA[sectname][optname].typ.complete()
|
2017-02-23 04:25:11 +01:00
|
|
|
|
|
|
|
model.add_list("Current/Default", [(current, "Current value"),
|
|
|
|
(default, "Default value")])
|
2016-09-16 21:41:54 +02:00
|
|
|
if vals is not None:
|
2017-02-23 04:25:11 +01:00
|
|
|
model.add_list("Completions", vals)
|
2016-09-16 21:41:54 +02:00
|
|
|
return model
|