# Copyright 2014 Florian Bruhin (The Compiler) # # 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 . """CompletionModels for settings/sections.""" from qutebrowser.models.completion import CompletionModel, NoCompletionsError import qutebrowser.config.configdata as configdata class SettingSectionCompletionModel(CompletionModel): """A CompletionModel filled with settings sections.""" # pylint: disable=abstract-method def __init__(self, parent=None): super().__init__(parent) cat = self.new_category("Config sections") for name in configdata.DATA.keys(): desc = configdata.SECTION_DESC[name].splitlines()[0].strip() self.new_item(cat, name, desc) class SettingOptionCompletionModel(CompletionModel): """A CompletionModel filled with settings and their descriptions.""" # pylint: disable=abstract-method def __init__(self, section, parent=None): super().__init__(parent) cat = self.new_category("Config options for {}".format(section)) sectdata = configdata.DATA[section] for name, _ in sectdata.items(): try: desc = sectdata.descriptions[name] except (KeyError, AttributeError): desc = "" self.new_item(cat, name, desc) class SettingValueCompletionModel(CompletionModel): """A CompletionModel filled with setting values.""" # pylint: disable=abstract-method def __init__(self, section, option, parent=None): super().__init__(parent) cat = self.new_category("Setting values for {}".format(option)) vals = configdata.DATA[section][option].typ.complete() if vals is None: raise NoCompletionsError for (val, desc) in vals: self.new_item(cat, val, desc)