1# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: 2 3# Copyright 2017-2021 Florian Bruhin (The Compiler) <mail@qutebrowser.org> 4# 5# This file is part of qutebrowser. 6# 7# qutebrowser is free software: you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation, either version 3 of the License, or 10# (at your option) any later version. 11# 12# qutebrowser is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with qutebrowser. If not, see <https://www.gnu.org/licenses/>. 19 20"""Navigation (back/forward) indicator displayed in the statusbar.""" 21 22from qutebrowser.mainwindow.statusbar import textbase 23 24 25class Backforward(textbase.TextBase): 26 27 """Shows navigation indicator (if you can go backward and/or forward).""" 28 29 def __init__(self, parent=None): 30 super().__init__(parent) 31 self.enabled = False 32 33 def on_tab_cur_url_changed(self, tabs): 34 """Called on URL changes.""" 35 tab = tabs.widget.currentWidget() 36 if tab is None: # pragma: no cover 37 self.setText('') 38 self.hide() 39 return 40 self.on_tab_changed(tab) 41 42 def on_tab_changed(self, tab): 43 """Update the text based on the given tab.""" 44 text = '' 45 if tab.history.can_go_back(): 46 text += '<' 47 if tab.history.can_go_forward(): 48 text += '>' 49 if text: 50 text = '[' + text + ']' 51 self.setText(text) 52 self.setVisible(bool(text) and self.enabled) 53