2014-02-06 14:01:23 +01:00
|
|
|
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
"""CompletionModels for different usages."""
|
2014-04-17 17:44:27 +02:00
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
import qutebrowser.config.configdata as configdata
|
|
|
|
from qutebrowser.models.basecompletion import (BaseCompletionModel,
|
|
|
|
NoCompletionsError)
|
|
|
|
from qutebrowser.commands.utils import cmd_dict
|
2014-01-27 21:42:00 +01:00
|
|
|
|
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
class SettingSectionCompletionModel(BaseCompletionModel):
|
2014-01-28 23:04:02 +01:00
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
"""A CompletionModel filled with settings sections."""
|
2014-04-09 17:57:00 +02:00
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
# pylint: disable=abstract-method
|
2014-01-29 15:30:19 +01:00
|
|
|
|
2014-01-27 21:42:00 +01:00
|
|
|
def __init__(self, parent=None):
|
|
|
|
super().__init__(parent)
|
2014-04-25 12:29:00 +02:00
|
|
|
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)
|
2014-02-07 20:21:50 +01:00
|
|
|
|
2014-02-19 10:58:32 +01:00
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
class SettingOptionCompletionModel(BaseCompletionModel):
|
2014-01-27 21:42:00 +01:00
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
"""A CompletionModel filled with settings and their descriptions."""
|
2014-01-29 15:30:19 +01:00
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
# pylint: disable=abstract-method
|
2014-02-07 20:21:50 +01:00
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
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)
|
2014-01-29 15:30:19 +01:00
|
|
|
|
2014-02-19 10:58:32 +01:00
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
class SettingValueCompletionModel(BaseCompletionModel):
|
2014-02-19 10:58:32 +01:00
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
"""A CompletionModel filled with setting values."""
|
2014-01-27 21:42:00 +01:00
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
# pylint: disable=abstract-method
|
2014-01-29 15:30:19 +01:00
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
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)
|
2014-02-19 10:58:32 +01:00
|
|
|
|
2014-01-27 21:42:00 +01:00
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
class CommandCompletionModel(BaseCompletionModel):
|
2014-02-19 10:58:32 +01:00
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
"""A CompletionModel filled with all commands and descriptions."""
|
2014-01-27 21:42:00 +01:00
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
# pylint: disable=abstract-method
|
2014-02-19 10:58:32 +01:00
|
|
|
|
2014-04-25 12:29:00 +02:00
|
|
|
def __init__(self, parent=None):
|
|
|
|
super().__init__(parent)
|
|
|
|
assert cmd_dict
|
|
|
|
cmdlist = []
|
|
|
|
for obj in set(cmd_dict.values()):
|
|
|
|
if not obj.hide:
|
|
|
|
cmdlist.append((obj.name, obj.desc))
|
|
|
|
cat = self.new_category("Commands")
|
|
|
|
for (name, desc) in sorted(cmdlist):
|
|
|
|
self.new_item(cat, name, desc)
|