E-book viewer: Fix clicking on the back/forward buttons not working in some situations. Fixes #2033118 [E-book viewer: "Back" button stops working under certain conditions](https://bugs.launchpad.net/calibre/+bug/2033118)

This commit is contained in:
Kovid Goyal 2023-08-26 09:47:17 +05:30
parent 522b23db12
commit 18d0422203
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 31 additions and 13 deletions

View File

@ -41,8 +41,8 @@ def all_actions():
if not hasattr(all_actions, 'ans'):
amap = {
'color_scheme': Action('format-fill-color.png', _('Switch color scheme')),
'back': Action('back.png', _('Back')),
'forward': Action('forward.png', _('Forward')),
'back': Action('back.png', _('Back'), 'back'),
'forward': Action('forward.png', _('Forward'), 'forward'),
'open': Action('document_open.png', _('Open e-book')),
'copy': Action('edit-copy.png', _('Copy to clipboard'), 'copy_to_clipboard'),
'increase_font_size': Action('font_size_larger.png', _('Increase font size'), 'increase_font_size'),
@ -66,7 +66,7 @@ def all_actions():
'metadata': Action('metadata.png', _('Show book metadata'), 'metadata'),
'toggle_read_aloud': Action('bullhorn.png', _('Read aloud'), 'toggle_read_aloud'),
'toggle_highlights': Action('highlight_only_on.png', _('Browse highlights in book'), 'toggle_highlights'),
'select_all': Action('edit-select-all.png', _('Select all text in the current file')),
'select_all': Action('edit-select-all.png', _('Select all text in the current file'), 'select_all'),
'edit_book': Action('edit_book.png', _('Edit this book'), 'edit_book'),
'reload_book': Action('view-refresh.png', _('Reload this book'), 'reload_book'),
}
@ -120,8 +120,10 @@ class ActionsToolBar(ToolBar):
self.customContextMenuRequested.connect(self.show_context_menu)
def update_action_state(self, book_open):
exclude = set(self.web_actions.values())
for ac in self.shortcut_actions.values():
ac.setEnabled(book_open)
if ac not in exclude:
ac.setEnabled(book_open)
self.search_action.setEnabled(book_open)
self.color_scheme_action.setEnabled(book_open)
@ -150,14 +152,19 @@ class ActionsToolBar(ToolBar):
web_view.customize_toolbar.connect(self.customize, type=Qt.ConnectionType.QueuedConnection)
web_view.view_created.connect(self.on_view_created)
self.back_action = page.action(QWebEnginePage.WebAction.Back)
self.back_action.setIcon(aa.back.icon)
self.back_action.setText(aa.back.text)
self.forward_action = page.action(QWebEnginePage.WebAction.Forward)
self.forward_action.setIcon(aa.forward.icon)
self.forward_action.setText(aa.forward.text)
self.select_all_action = a = page.action(QWebEnginePage.WebAction.SelectAll)
a.setIcon(aa.select_all.icon), a.setText(aa.select_all.text)
self.web_actions = {}
self.back_action = a = shortcut_action('back')
a.setEnabled(False)
self.web_actions[QWebEnginePage.WebAction.Back] = a
page.action(QWebEnginePage.WebAction.Back).changed.connect(self.update_web_action)
self.forward_action = a = shortcut_action('forward')
a.setEnabled(False)
self.web_actions[QWebEnginePage.WebAction.Forward] = a
page.action(QWebEnginePage.WebAction.Forward).changed.connect(self.update_web_action)
self.select_all_action = a = shortcut_action('select_all')
a.setEnabled(False)
self.web_actions[QWebEnginePage.WebAction.SelectAll] = a
page.action(QWebEnginePage.WebAction.SelectAll).changed.connect(self.update_web_action)
self.open_action = a = QAction(aa.open.icon, aa.open.text, self)
self.open_menu = m = QMenu(self)
@ -211,6 +218,14 @@ class ActionsToolBar(ToolBar):
self.add_actions()
def update_web_action(self):
a = self.sender()
for x, ac in self.web_actions.items():
pa = self.web_view.page().action(x)
if a is pa:
ac.setEnabled(pa.isEnabled())
break
def add_actions(self):
self.clear()
actions = current_actions()

View File

@ -709,7 +709,8 @@ class WebView(RestartingWebEngineView):
self._page.profile().clearHttpCache()
def trigger_shortcut(self, which):
self.execute_when_ready('trigger_shortcut', which)
if which:
self.execute_when_ready('trigger_shortcut', which)
def show_search_result(self, sr):
self.execute_when_ready('show_search_result', sr)

View File

@ -468,6 +468,8 @@ class View:
self.selection_bar.update_position()
def on_handle_shortcut(self, data):
if not data.name:
return
if data.name is 'back':
window.history.back()
elif data.name is 'forward':