Remove annoying two-word completions
This commit is contained in:
parent
fb4e013007
commit
c26430d08d
@ -17,6 +17,7 @@
|
||||
|
||||
"""Module containing commandline parsers ( SearchParser and CommandParser)."""
|
||||
|
||||
import logging
|
||||
import shlex
|
||||
|
||||
from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject
|
||||
@ -134,10 +135,11 @@ class CommandParser:
|
||||
NoSuchCommandError if a command wasn't found.
|
||||
|
||||
Return:
|
||||
The parts list.
|
||||
A split string commandline, e.g ['open', 'www.google.com']
|
||||
|
||||
"""
|
||||
parts = text.strip().split(maxsplit=1)
|
||||
logging.debug("parts in parser: {}".format(parts))
|
||||
if not parts:
|
||||
raise NoSuchCommandError("No command given")
|
||||
cmdstr = parts[0]
|
||||
@ -161,7 +163,7 @@ class CommandParser:
|
||||
args = [parts[1]]
|
||||
self._cmd = cmd
|
||||
self._args = args
|
||||
return parts
|
||||
return [cmdstr] + args
|
||||
|
||||
def _check(self):
|
||||
"""Check if the argument count for the command is correct."""
|
||||
|
@ -165,24 +165,23 @@ class Config:
|
||||
"""Return True if option is in section."""
|
||||
return option in self.config[section]
|
||||
|
||||
@cmdutils.register(name='get', instance='config', completion=['setting'],
|
||||
split_args=False)
|
||||
def get_wrapper(self, secopt):
|
||||
@cmdutils.register(name='get', instance='config',
|
||||
completion=['section', 'option'])
|
||||
def get_wrapper(self, section, option):
|
||||
"""Get the value from a section/option.
|
||||
|
||||
Wrapper for the get-command to have section/option in one arg.
|
||||
Wrapper for the get-command to output the value in the status bar
|
||||
|
||||
Arguments:
|
||||
secopt: Section and option, delimited by a space.
|
||||
section: Section to get the value from
|
||||
option: The option to get.
|
||||
|
||||
Return:
|
||||
The value of the section/option.
|
||||
The value of the option.
|
||||
|
||||
"""
|
||||
sect, opt = secopt.split()
|
||||
val = self.get(sect, opt)
|
||||
message.info("{} {} = {}".format(sect, opt, val))
|
||||
|
||||
val = self.get(section, option)
|
||||
message.info("{} {} = {}".format(section, option, val))
|
||||
|
||||
def get(self, section, option, fallback=_UNSET, raw=False):
|
||||
"""Get the value from a section/option.
|
||||
@ -213,22 +212,9 @@ class Config:
|
||||
newval = val.typ.transform(newval)
|
||||
return newval
|
||||
|
||||
# FIXME completion for values
|
||||
@cmdutils.register(name='set', instance='config', completion=['setting'],
|
||||
split_args=False, nargs=(3,3))
|
||||
def set_wrapper(self, secopt, val):
|
||||
"""Set the value for a section/option.
|
||||
|
||||
Wrapper for the set-command to have section/option in one arg.
|
||||
|
||||
Arguments:
|
||||
secopt: Section and option, delimited by a space.
|
||||
|
||||
"""
|
||||
sect, opt = secopt.split()
|
||||
self.set(sect, opt, val)
|
||||
|
||||
@cmdutils.register(instance='config', completion=['section', 'option'])
|
||||
def set(self, section, option, value):
|
||||
# FIXME completion for values
|
||||
"""Set an option."""
|
||||
if value:
|
||||
value = self._interpolation.before_set(self, section, option,
|
||||
|
@ -21,7 +21,6 @@ import logging
|
||||
from PyQt5.QtCore import Qt, QVariant, QAbstractItemModel, QModelIndex
|
||||
|
||||
ROLE_MARKS = Qt.UserRole
|
||||
ROLE_FULLTEXT = Qt.UserRole + 1
|
||||
|
||||
|
||||
class CompletionModel(QAbstractItemModel):
|
||||
@ -112,21 +111,19 @@ class CompletionModel(QAbstractItemModel):
|
||||
self._root.children.append(cat)
|
||||
return cat
|
||||
|
||||
def new_item(self, cat, name, desc, completion=None):
|
||||
def new_item(self, cat, name, desc=""):
|
||||
"""Add a new item to a category.
|
||||
|
||||
Args:
|
||||
cat: The parent category.
|
||||
name: The name of the item.
|
||||
desc: The description of the item.
|
||||
completion: The long text to insert for a completion.
|
||||
None if it's the same as name.
|
||||
|
||||
Return:
|
||||
The created CompletionItem.
|
||||
|
||||
"""
|
||||
item = CompletionItem((name, desc), parent=cat, fulltext=completion)
|
||||
item = CompletionItem((name, desc), parent=cat)
|
||||
self._id_map[id(item)] = item
|
||||
cat.children.append(item)
|
||||
return item
|
||||
@ -355,25 +352,21 @@ class CompletionItem():
|
||||
children: The children of this item.
|
||||
_data: The data of this item.
|
||||
_marks: The marks of this item.
|
||||
_fulltext: The full text to insert when completing.
|
||||
None if _data[0] already is the full text.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, data, parent=None, fulltext=None):
|
||||
def __init__(self, data, parent=None):
|
||||
"""Constructor for CompletionItem.
|
||||
|
||||
Args:
|
||||
data: The data for the model, as tuple (columns).
|
||||
parent: An optional parent item.
|
||||
fulltext: The full text to insert when completing.
|
||||
|
||||
"""
|
||||
self.parent = parent
|
||||
self.children = []
|
||||
self._data = data
|
||||
self._marks = []
|
||||
self._fulltext = fulltext
|
||||
|
||||
def data(self, column, role=Qt.DisplayRole):
|
||||
"""Get the data for role/column.
|
||||
@ -393,8 +386,6 @@ class CompletionItem():
|
||||
return self._data[column]
|
||||
elif role == ROLE_MARKS:
|
||||
return self._marks
|
||||
elif role == ROLE_FULLTEXT:
|
||||
return self._fulltext
|
||||
else:
|
||||
raise ValueError("Invalid role {}".format(role))
|
||||
|
||||
@ -414,8 +405,6 @@ class CompletionItem():
|
||||
self._data[column] = value
|
||||
elif role == ROLE_MARKS:
|
||||
self._marks = value
|
||||
elif role == ROLE_FULLTEXT:
|
||||
self._fulltext = value
|
||||
else:
|
||||
raise ValueError("Invalid role {}".format(role))
|
||||
|
||||
|
@ -15,22 +15,38 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""A CompletionModel filled with settings and their descriptions."""
|
||||
"""CompletionModels for settings/sections."""
|
||||
|
||||
from qutebrowser.models.completion import CompletionModel
|
||||
from qutebrowser.config.configdata import configdata
|
||||
|
||||
|
||||
class SettingCompletionModel(CompletionModel):
|
||||
class SettingSectionCompletionModel(CompletionModel):
|
||||
|
||||
"""A CompletionModel filled with settings and their descriptions."""
|
||||
"""A CompletionModel filled with settings sections."""
|
||||
|
||||
# pylint: disable=abstract-method
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
for secname, secdata in configdata().items():
|
||||
cat = self.new_category(secname)
|
||||
for name in secdata.values.keys():
|
||||
self.new_item(cat, name, secdata.descriptions[name],
|
||||
'{} {}'.format(secname, name))
|
||||
cat = self.new_category("Config sections")
|
||||
for name in configdata().keys():
|
||||
self.new_item(cat, name )
|
||||
|
||||
|
||||
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()[section]
|
||||
for name, _ in sectdata.items():
|
||||
try:
|
||||
desc = sectdata.descriptions[name]
|
||||
except (KeyError, AttributeError):
|
||||
desc = ""
|
||||
self.new_item(cat, name, desc)
|
||||
|
@ -34,12 +34,14 @@ from PyQt5.QtGui import (QIcon, QPalette, QTextDocument, QTextOption,
|
||||
|
||||
import qutebrowser.config.config as config
|
||||
import qutebrowser.commands.utils as cmdutils
|
||||
from qutebrowser.models.completion import ROLE_MARKS, ROLE_FULLTEXT
|
||||
from qutebrowser.config.configdata import configdata
|
||||
from qutebrowser.models.completion import ROLE_MARKS
|
||||
from qutebrowser.config.style import get_stylesheet
|
||||
from qutebrowser.commands.parsers import split_cmdline
|
||||
from qutebrowser.models.completionfilter import CompletionFilterModel
|
||||
from qutebrowser.models.commandcompletion import CommandCompletionModel
|
||||
from qutebrowser.models.settingcompletion import SettingCompletionModel
|
||||
from qutebrowser.models.settingcompletion import (
|
||||
SettingSectionCompletionModel, SettingOptionCompletionModel)
|
||||
|
||||
|
||||
class CompletionView(QTreeView):
|
||||
@ -108,8 +110,12 @@ class CompletionView(QTreeView):
|
||||
self._lastmodel = None
|
||||
self._completion_models = {
|
||||
'command': CompletionFilterModel(CommandCompletionModel(self)),
|
||||
'setting': CompletionFilterModel(SettingCompletionModel(self)),
|
||||
'section': CompletionFilterModel(SettingSectionCompletionModel(
|
||||
self)),
|
||||
}
|
||||
for sect in configdata().keys():
|
||||
self._completion_models['option_' + sect] = CompletionFilterModel(
|
||||
SettingOptionCompletionModel(sect, self))
|
||||
self._ignore_next = False
|
||||
self._completing = False
|
||||
|
||||
@ -173,9 +179,15 @@ class CompletionView(QTreeView):
|
||||
if completions is None:
|
||||
return None
|
||||
try:
|
||||
return completions[len(parts) - 2]
|
||||
compl = completions[len(parts) - 2]
|
||||
except IndexError:
|
||||
return None
|
||||
if compl == 'option':
|
||||
compl = 'option_' + parts[-2]
|
||||
if compl in self._completion_models:
|
||||
return compl
|
||||
else:
|
||||
return None
|
||||
|
||||
def set_model(self, model):
|
||||
"""Switch completion to a new model.
|
||||
@ -259,9 +271,7 @@ class CompletionView(QTreeView):
|
||||
idx = self._next_idx(shift)
|
||||
self.selectionModel().setCurrentIndex(
|
||||
idx, QItemSelectionModel.ClearAndSelect)
|
||||
data = self._model.data(idx, role=ROLE_FULLTEXT)
|
||||
if data is None:
|
||||
data = self._model.data(idx)
|
||||
data = self._model.data(idx)
|
||||
if data is not None:
|
||||
self._ignore_next = True
|
||||
self.change_completed_part.emit(data)
|
||||
|
Loading…
Reference in New Issue
Block a user