From 156e0970c9f1c30527395a725bbc4b42f60dbbc1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 12 Dec 2011 09:00:38 +0530 Subject: [PATCH] E-book viewer: Add an option to the right click menu to search for the currently selected word --- src/calibre/gui2/viewer/documentview.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/calibre/gui2/viewer/documentview.py b/src/calibre/gui2/viewer/documentview.py index 4661bc4899..170fb936bd 100644 --- a/src/calibre/gui2/viewer/documentview.py +++ b/src/calibre/gui2/viewer/documentview.py @@ -537,6 +537,12 @@ class DocumentView(QWebView): # {{{ self.dictionary_action.setShortcut(Qt.CTRL+Qt.Key_L) self.dictionary_action.triggered.connect(self.lookup) self.addAction(self.dictionary_action) + self.search_action = QAction(QIcon(I('dictionary.png')), + _('&Search for next occurrence'), self) + self.search_action.setShortcut(Qt.CTRL+Qt.Key_S) + self.search_action.triggered.connect(self.search_next) + self.addAction(self.search_action) + self.goto_location_action = QAction(_('Go to...'), self) self.goto_location_menu = m = QMenu(self) self.goto_location_actions = a = { @@ -620,6 +626,7 @@ class DocumentView(QWebView): # {{{ text = unicode(self.selectedText()) if text: menu.insertAction(list(menu.actions())[0], self.dictionary_action) + menu.insertAction(list(menu.actions())[0], self.search_action) menu.addSeparator() menu.addAction(self.goto_location_action) menu.exec_(ev.globalPos()) @@ -630,6 +637,12 @@ class DocumentView(QWebView): # {{{ if t: self.manager.lookup(t.split()[0]) + def search_next(self): + if self.manager is not None: + t = unicode(self.selectedText()).strip() + if t: + self.manager.search.set_search_string(t) + def set_manager(self, manager): self.manager = manager self.scrollbar = manager.horizontal_scrollbar