Rename {Command,Seach}Parser to *Manager

This commit is contained in:
Florian Bruhin 2014-04-25 12:04:11 +02:00
parent 937196e287
commit d4b35b6734
6 changed files with 25 additions and 26 deletions

1
TODO
View File

@ -18,7 +18,6 @@ Refactor completion widget mess (initializing / changing completions)
we probably could replace CompletionModel with QStandardModel... we probably could replace CompletionModel with QStandardModel...
replace foo_bar options with foo-bar replace foo_bar options with foo-bar
reorder options reorder options
rename *Parser to more meaningful names
_foo = QApplication.instance().obj.foo for global singletons? _foo = QApplication.instance().obj.foo for global singletons?
decorators for often-used signals from singletons? decorators for often-used signals from singletons?
- @on_config_changed('colors') - @on_config_changed('colors')

View File

@ -59,7 +59,7 @@ from qutebrowser.widgets.crash import CrashDialog
from qutebrowser.keyinput.normalmode import NormalKeyParser from qutebrowser.keyinput.normalmode import NormalKeyParser
from qutebrowser.keyinput.keyparser import PassthroughKeyParser from qutebrowser.keyinput.keyparser import PassthroughKeyParser
from qutebrowser.keyinput.hintmode import HintKeyParser from qutebrowser.keyinput.hintmode import HintKeyParser
from qutebrowser.commands.parsers import CommandParser, SearchParser from qutebrowser.commands.managers import CommandManager, SearchManager
from qutebrowser.utils.appdirs import AppDirs from qutebrowser.utils.appdirs import AppDirs
from qutebrowser.utils.misc import dotted_getattr from qutebrowser.utils.misc import dotted_getattr
from qutebrowser.utils.debug import set_trace # pylint: disable=unused-import from qutebrowser.utils.debug import set_trace # pylint: disable=unused-import
@ -76,8 +76,8 @@ class QuteBrowser(QApplication):
Attributes: Attributes:
mainwindow: The MainWindow QWidget. mainwindow: The MainWindow QWidget.
commandparser: The main CommandParser instance. commandmanager: The main CommandManager instance.
searchparser: The main SearchParser instance. searchmanager: The main SearchManager instance.
_keyparsers: A mapping from modes to keyparsers. _keyparsers: A mapping from modes to keyparsers.
_dirs: AppDirs instance for config/cache directories. _dirs: AppDirs instance for config/cache directories.
_args: ArgumentParser instance. _args: ArgumentParser instance.
@ -121,8 +121,8 @@ class QuteBrowser(QApplication):
self.config = config.instance self.config = config.instance
websettings.init() websettings.init()
self.commandparser = CommandParser() self.commandmanager = CommandManager()
self.searchparser = SearchParser() self.searchmanager = SearchManager()
self._keyparsers = { self._keyparsers = {
'normal': NormalKeyParser(self), 'normal': NormalKeyParser(self),
'hint': HintKeyParser(self), 'hint': HintKeyParser(self),
@ -224,7 +224,7 @@ class QuteBrowser(QApplication):
for e in self._args.command: for e in self._args.command:
if e.startswith(':'): if e.startswith(':'):
logging.debug('Startup cmd {}'.format(e)) logging.debug('Startup cmd {}'.format(e))
self.commandparser.run(e.lstrip(':')) self.commandmanager.run(e.lstrip(':'))
else: else:
logging.debug('Startup url {}'.format(e)) logging.debug('Startup url {}'.format(e))
self._opened_urls.append(e) self._opened_urls.append(e)
@ -269,11 +269,11 @@ class QuteBrowser(QApplication):
modes.manager.key_pressed.connect(status.on_key_pressed) modes.manager.key_pressed.connect(status.on_key_pressed)
# commands # commands
cmd.got_cmd.connect(self.commandparser.run) cmd.got_cmd.connect(self.commandmanager.run)
cmd.got_search.connect(self.searchparser.search) cmd.got_search.connect(self.searchmanager.search)
cmd.got_search_rev.connect(self.searchparser.search_rev) cmd.got_search_rev.connect(self.searchmanager.search_rev)
cmd.returnPressed.connect(tabs.setFocus) cmd.returnPressed.connect(tabs.setFocus)
self.searchparser.do_search.connect(tabs.cur.search) self.searchmanager.do_search.connect(tabs.cur.search)
kp["normal"].keystring_updated.connect(status.keystring.setText) kp["normal"].keystring_updated.connect(status.keystring.setText)
# hints # hints

View File

@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. # along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""Module containing commandline parsers ( SearchParser and CommandParser).""" """Module containing command managers (SearchManager and CommandManager)."""
from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject
from PyQt5.QtWebKitWidgets import QWebPage from PyQt5.QtWebKitWidgets import QWebPage
@ -36,9 +36,9 @@ def split_cmdline(text):
Return: Return:
A list of strings. A list of strings.
""" """
parser = CommandParser() manager = CommandManager()
try: try:
parts = parser.parse(text) parts = manager.parse(text)
except NoSuchCommandError: except NoSuchCommandError:
parts = text.split(' ') parts = text.split(' ')
if text.endswith(' '): if text.endswith(' '):
@ -46,9 +46,9 @@ def split_cmdline(text):
return parts return parts
class SearchParser(QObject): class SearchManager(QObject):
"""Parse qutebrowser searches. """Manage qutebrowser searches.
Attributes: Attributes:
_text: The text from the last search. _text: The text from the last search.
@ -107,7 +107,7 @@ class SearchParser(QObject):
""" """
self._search(text, rev=True) self._search(text, rev=True)
@cmdutils.register(instance='searchparser', hide=True) @cmdutils.register(instance='searchmanager', hide=True)
def nextsearch(self, count=1): def nextsearch(self, count=1):
"""Continue the search to the ([count]th) next term. """Continue the search to the ([count]th) next term.
@ -122,9 +122,9 @@ class SearchParser(QObject):
self.do_search.emit(self._text, self._flags) self.do_search.emit(self._text, self._flags)
class CommandParser: class CommandManager:
"""Parse qutebrowser commandline commands. """Manage qutebrowser commandline commands.
Attributes: Attributes:
_cmd: The command which was parsed. _cmd: The command which was parsed.

View File

@ -26,8 +26,8 @@ from PyQt5.QtGui import QKeySequence
import qutebrowser.config.config as config import qutebrowser.config.config as config
import qutebrowser.utils.message as message import qutebrowser.utils.message as message
from qutebrowser.commands.parsers import (CommandParser, ArgumentCountError, from qutebrowser.commands.managers import (CommandManager, ArgumentCountError,
NoSuchCommandError) NoSuchCommandError)
class KeyParser(QObject): class KeyParser(QObject):
@ -353,13 +353,13 @@ class CommandKeyParser(KeyParser):
"""KeyChainParser for command bindings. """KeyChainParser for command bindings.
Attributes: Attributes:
commandparser: Commandparser instance. commandmanager: CommandManager instance.
""" """
def __init__(self, parent=None, supports_count=None, def __init__(self, parent=None, supports_count=None,
supports_chains=False): supports_chains=False):
super().__init__(parent, supports_count, supports_chains) super().__init__(parent, supports_count, supports_chains)
self.commandparser = CommandParser() self.commandmanager = CommandManager()
def _run_or_fill(self, cmdstr, count=None, ignore_exc=True): def _run_or_fill(self, cmdstr, count=None, ignore_exc=True):
"""Run the command in cmdstr or fill the statusbar if args missing. """Run the command in cmdstr or fill the statusbar if args missing.
@ -370,7 +370,7 @@ class CommandKeyParser(KeyParser):
ignore_exc: Ignore exceptions. ignore_exc: Ignore exceptions.
""" """
try: try:
self.commandparser.run(cmdstr, count=count, ignore_exc=ignore_exc) self.commandmanager.run(cmdstr, count=count, ignore_exc=ignore_exc)
except NoSuchCommandError: except NoSuchCommandError:
pass pass
except ArgumentCountError: except ArgumentCountError:

View File

@ -36,7 +36,7 @@ import qutebrowser.commands.utils as cmdutils
import qutebrowser.config.configdata as configdata import qutebrowser.config.configdata as configdata
from qutebrowser.models.completion import ROLE_MARKS, NoCompletionsError from qutebrowser.models.completion import ROLE_MARKS, NoCompletionsError
from qutebrowser.config.style import set_register_stylesheet, get_stylesheet from qutebrowser.config.style import set_register_stylesheet, get_stylesheet
from qutebrowser.commands.parsers import split_cmdline from qutebrowser.commands.managers import split_cmdline
from qutebrowser.models.completionfilter import CompletionFilterModel from qutebrowser.models.completionfilter import CompletionFilterModel
from qutebrowser.models.commandcompletion import CommandCompletionModel from qutebrowser.models.commandcompletion import CommandCompletionModel
from qutebrowser.models.settingcompletion import ( from qutebrowser.models.settingcompletion import (

View File

@ -27,7 +27,7 @@ import qutebrowser.commands.utils as cmdutils
from qutebrowser.keyinput.normalmode import STARTCHARS from qutebrowser.keyinput.normalmode import STARTCHARS
from qutebrowser.config.style import set_register_stylesheet, get_stylesheet from qutebrowser.config.style import set_register_stylesheet, get_stylesheet
from qutebrowser.utils.url import urlstring from qutebrowser.utils.url import urlstring
from qutebrowser.commands.parsers import split_cmdline from qutebrowser.commands.managers import split_cmdline
from qutebrowser.models.cmdhistory import (History, HistoryEmptyError, from qutebrowser.models.cmdhistory import (History, HistoryEmptyError,
HistoryEndReachedError) HistoryEndReachedError)