diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 3defd3061..a55bd4d46 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -5,7 +5,9 @@ from PyQt5.QtWidgets import QWidget, QApplication from PyQt5.QtCore import QUrl from qutebrowser.widgets.mainwindow import MainWindow from qutebrowser.commands.keys import KeyParser +from qutebrowser.utils.config import Config import qutebrowser.commands.utils as cmdutils +from qutebrowser.utils.appdirs import AppDirs class QuteBrowser(QApplication): def __init__(self): @@ -13,6 +15,9 @@ class QuteBrowser(QApplication): args = self.parseopts() self.initlog() + self.dirs = AppDirs('qutebrowser') + self.config = Config(self.dirs.user_data_dir) + self.mainwindow = MainWindow() self.commandparser = cmdutils.CommandParser() self.keyparser = KeyParser(self.mainwindow) @@ -54,7 +59,7 @@ class QuteBrowser(QApplication): cmds = cmdutils.cmd_dict for cmd in cmds.values(): cmd.signal.connect(self.cmd_handler) - self.keyparser.from_cmd_dict(cmdutils.cmd_dict) + self.keyparser.from_config_sect(self.config['keybind']) def cmd_handler(self, tpl): (count, argv) = tpl @@ -64,7 +69,7 @@ class QuteBrowser(QApplication): handlers = { 'open': self.mainwindow.tabs.openurl, 'tabopen': self.mainwindow.tabs.tabopen, - 'quit': QApplication.closeAllWindows, # FIXME + 'quit': self.exit, 'tabclose': self.mainwindow.tabs.close_act, 'tabprev': self.mainwindow.tabs.switch_prev, 'tabnext': self.mainwindow.tabs.switch_next, @@ -103,3 +108,7 @@ class QuteBrowser(QApplication): tab.setUrl(QUrl('about:pyeval')) tab.setContent(out.encode('UTF-8'), 'text/plain') + def exit(self, status=0): + self.config.save() + QApplication.closeAllWindows() + # FIXME do this right diff --git a/qutebrowser/commands/commands.py b/qutebrowser/commands/commands.py index 412deca49..afb069f76 100644 --- a/qutebrowser/commands/commands.py +++ b/qutebrowser/commands/commands.py @@ -3,78 +3,63 @@ from qutebrowser.commands.utils import Command class Open(Command): nargs = 1 - key = 'o' split_args = False class TabOpen(Command): nargs = 1 - key = 'O' split_args = False class TabClose(Command): nargs = 0 - key = 'd' class TabNext(Command): nargs = 0 - key = 'J' class TabPrev(Command): nargs = 0 - key = 'K' class Quit(Command): nargs = 0 class Reload(Command): nargs = 0 - key = 'r' class Stop(Command): nargs = 0 class Back(Command): nargs = 0 - key = 'H' class Forward(Command): nargs = 0 - key = 'L' class Print(Command): nargs = 0 class ScrollLeft(Command): nargs = 0 - key = 'h' count = True class ScrollDown(Command): nargs = 0 - key = 'j' count = True class ScrollUp(Command): nargs = 0 - key = 'k' count = True class ScrollRight(Command): nargs = 0 - key = 'l' count = True class Undo(Command): nargs = 0 - key = 'u' class ScrollStart(Command): nargs = 0 - key = 'gg' class ScrollEnd(Command): nargs = 0 - key = 'G' class PyEval(Command): nargs = 1 diff --git a/qutebrowser/commands/keys.py b/qutebrowser/commands/keys.py index 289d41e7f..73a6ce2a7 100644 --- a/qutebrowser/commands/keys.py +++ b/qutebrowser/commands/keys.py @@ -1,6 +1,7 @@ from PyQt5.QtCore import QObject, Qt, pyqtSignal from PyQt5.QtWidgets import QShortcut from PyQt5.QtGui import QKeySequence +import qutebrowser.commands.utils as cmdutils import logging import re @@ -10,11 +11,10 @@ class KeyParser(QObject): keystring_updated = pyqtSignal(str) key_to_cmd = {} - def from_cmd_dict(self, d): - for cmd in d.values(): - if cmd.key is not None: - logging.debug('registered: {} -> {}'.format(cmd.name, cmd.key)) - self.key_to_cmd[cmd.key] = cmd + def from_config_sect(self, sect): + for (key, cmd) in sect.items(): + logging.debug('registered: {} -> {}'.format(key, cmd)) + self.key_to_cmd[key] = cmdutils.cmd_dict[cmd] def handle(self, e): self._handle(e) diff --git a/qutebrowser/commands/utils.py b/qutebrowser/commands/utils.py index ac467551e..925ee4a85 100644 --- a/qutebrowser/commands/utils.py +++ b/qutebrowser/commands/utils.py @@ -50,7 +50,6 @@ class CommandParser(QObject): class Command(QObject): nargs = 0 name = None - key = None signal = None count = False bind = True