From ce9bd67edc8fd9ff38f5ff0b0c0ac34a189a1c41 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 15 Nov 2013 09:21:25 +0530 Subject: [PATCH] Implement replace and replace-find actions --- src/calibre/gui2/tweak_book/boss.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index 0f3e7a8c18..411b5214ec 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -328,6 +328,7 @@ class Boss(QObject): marked = True def no_match(): + QApplication.restoreOverrideCursor() msg = '

' + _('No matches were found for %s.') % state['find'] if not state['wrap']: msg += '

' + _('You have turned off search wrapping, so all text might not have been searched.' @@ -358,10 +359,29 @@ class Boss(QObject): return return no_match() + def no_replace(prefix=''): + QApplication.restoreOverrideCursor() + error_dialog( + self.gui, _('Cannot replace'), prefix + _( + 'You must first click Find, before trying to replace'), show=True) + return False + + def do_replace(): + if editor is None: + return no_replace() + if not editor.replace(pat, state['replace']): + return no_replace(_( + 'Currently selected text does not match the search query.')) + return True + QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) try: if action == 'find': return do_find() + if action == 'replace': + return do_replace() + if action == 'replace-find' and do_replace(): + return do_find() finally: QApplication.restoreOverrideCursor()