Use last focused window for download errors and other stuff.
When the event happens, it's possible we don't have any window focused yet, so we display it in the window which was last focused. Fixes #191.
This commit is contained in:
parent
348bc7147f
commit
b54151f206
@ -314,7 +314,7 @@ class Application(QApplication):
|
|||||||
quickstart_done = False
|
quickstart_done = False
|
||||||
if not quickstart_done:
|
if not quickstart_done:
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window='current')
|
window='last-focused')
|
||||||
tabbed_browser.tabopen(
|
tabbed_browser.tabopen(
|
||||||
QUrl('http://www.qutebrowser.org/quickstart.html'))
|
QUrl('http://www.qutebrowser.org/quickstart.html'))
|
||||||
try:
|
try:
|
||||||
@ -342,6 +342,7 @@ class Application(QApplication):
|
|||||||
config_obj = objreg.get('config')
|
config_obj = objreg.get('config')
|
||||||
self.lastWindowClosed.connect(self.shutdown)
|
self.lastWindowClosed.connect(self.shutdown)
|
||||||
config_obj.style_changed.connect(style.get_stylesheet.cache_clear)
|
config_obj.style_changed.connect(style.get_stylesheet.cache_clear)
|
||||||
|
self.focusChanged.connect(self.on_focus_changed)
|
||||||
|
|
||||||
def _get_widgets(self):
|
def _get_widgets(self):
|
||||||
"""Get a string list of all widgets."""
|
"""Get a string list of all widgets."""
|
||||||
@ -542,7 +543,7 @@ class Application(QApplication):
|
|||||||
out = traceback.format_exc()
|
out = traceback.format_exc()
|
||||||
qutescheme.pyeval_output = out
|
qutescheme.pyeval_output = out
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window='current')
|
window='last-focused')
|
||||||
tabbed_browser.openurl(QUrl('qute:pyeval'), newtab=True)
|
tabbed_browser.openurl(QUrl('qute:pyeval'), newtab=True)
|
||||||
|
|
||||||
@cmdutils.register(instance='app')
|
@cmdutils.register(instance='app')
|
||||||
@ -706,6 +707,20 @@ class Application(QApplication):
|
|||||||
# segfaults.
|
# segfaults.
|
||||||
QTimer.singleShot(0, functools.partial(self.exit, status))
|
QTimer.singleShot(0, functools.partial(self.exit, status))
|
||||||
|
|
||||||
|
def on_focus_changed(self, _old, new):
|
||||||
|
"""Register currently focused main window in the object registry."""
|
||||||
|
if new is None:
|
||||||
|
window = None
|
||||||
|
else:
|
||||||
|
window = new.window()
|
||||||
|
if window is None or not isinstance(window, mainwindow.MainWindow):
|
||||||
|
try:
|
||||||
|
objreg.delete('last-focused-main-window')
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
objreg.register('last-focused-main-window', window, update=True)
|
||||||
|
|
||||||
def exit(self, status):
|
def exit(self, status):
|
||||||
"""Extend QApplication::exit to log the event."""
|
"""Extend QApplication::exit to log the event."""
|
||||||
log.destroy.debug("Now calling QApplication::exit.")
|
log.destroy.debug("Now calling QApplication::exit.")
|
||||||
|
@ -352,7 +352,7 @@ class DownloadManager(QAbstractListModel):
|
|||||||
page: The QWebPage to get the download from.
|
page: The QWebPage to get the download from.
|
||||||
"""
|
"""
|
||||||
if not url.isValid():
|
if not url.isValid():
|
||||||
urlutils.invalid_url_error('current', url, "start download")
|
urlutils.invalid_url_error('last-focused', url, "start download")
|
||||||
return
|
return
|
||||||
req = QNetworkRequest(url)
|
req = QNetworkRequest(url)
|
||||||
reply = page.networkAccessManager().get(req)
|
reply = page.networkAccessManager().get(req)
|
||||||
@ -407,7 +407,7 @@ class DownloadManager(QAbstractListModel):
|
|||||||
self.questions.append(q)
|
self.questions.append(q)
|
||||||
download.cancelled.connect(q.abort)
|
download.cancelled.connect(q.abort)
|
||||||
message_bridge = objreg.get('message-bridge', scope='window',
|
message_bridge = objreg.get('message-bridge', scope='window',
|
||||||
window='current')
|
window='last-focused')
|
||||||
message_bridge.ask(q, blocking=False)
|
message_bridge.ask(q, blocking=False)
|
||||||
|
|
||||||
@pyqtSlot(DownloadItem)
|
@pyqtSlot(DownloadItem)
|
||||||
@ -431,7 +431,7 @@ class DownloadManager(QAbstractListModel):
|
|||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def on_error(self, msg):
|
def on_error(self, msg):
|
||||||
"""Display error message on download errors."""
|
"""Display error message on download errors."""
|
||||||
message.error('current', "Download error: {}".format(msg))
|
message.error('last-focused', "Download error: {}".format(msg))
|
||||||
|
|
||||||
def last_index(self):
|
def last_index(self):
|
||||||
"""Get the last index in the model.
|
"""Get the last index in the model.
|
||||||
|
@ -59,7 +59,7 @@ class HelpAction(argparse.Action):
|
|||||||
|
|
||||||
def __call__(self, parser, _namespace, _values, _option_string=None):
|
def __call__(self, parser, _namespace, _values, _option_string=None):
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window='current')
|
window='last-focused')
|
||||||
tabbed_browser.tabopen(
|
tabbed_browser.tabopen(
|
||||||
QUrl('qute://help/commands.html#{}'.format(parser.name)))
|
QUrl('qute://help/commands.html#{}'.format(parser.name)))
|
||||||
parser.exit()
|
parser.exit()
|
||||||
|
@ -136,6 +136,15 @@ def _get_window_registry(window):
|
|||||||
win = app.activeWindow()
|
win = app.activeWindow()
|
||||||
if win is None or not hasattr(win, 'win_id'):
|
if win is None or not hasattr(win, 'win_id'):
|
||||||
raise RegistryUnavailableError('window')
|
raise RegistryUnavailableError('window')
|
||||||
|
elif window == 'last-focused':
|
||||||
|
try:
|
||||||
|
win = get('last-focused-main-window')
|
||||||
|
except KeyError:
|
||||||
|
try:
|
||||||
|
win = get('last-main-window')
|
||||||
|
except KeyError:
|
||||||
|
raise RegistryUnavailableError('window')
|
||||||
|
assert hasattr(win, 'registry')
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
win = window_registry[window]
|
win = window_registry[window]
|
||||||
|
Loading…
Reference in New Issue
Block a user