diff --git a/ankiqt/ui/cardlist.py b/ankiqt/ui/cardlist.py index ad39d9ba9..544faa18c 100644 --- a/ankiqt/ui/cardlist.py +++ b/ankiqt/ui/cardlist.py @@ -2,6 +2,7 @@ # Copyright: Damien Elmes # License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html +import sre_constants from PyQt4.QtGui import * from PyQt4.QtCore import * import time, types, sys, re @@ -499,6 +500,7 @@ class EditDeck(QMainWindow): self.connect(self.dialog.actionInvertSelection, SIGNAL("triggered()"), self.invertSelection) self.connect(self.dialog.actionReverseOrder, SIGNAL("triggered()"), self.reverseOrder) self.connect(self.dialog.actionSelectFacts, SIGNAL("triggered()"), self.selectFacts) + self.connect(self.dialog.actionFindReplace, SIGNAL("triggered()"), self.onFindReplace) # jumps self.connect(self.dialog.actionFirstCard, SIGNAL("triggered()"), self.onFirstCard) self.connect(self.dialog.actionLastCard, SIGNAL("triggered()"), self.onLastCard) @@ -771,6 +773,40 @@ where id in %s""" % ids2str(sf)) def onRedo(self): self.deck.redo() + # Edit: replacing + ###################################################################### + + def onFindReplace(self): + d = QDialog(self) + frm = ankiqt.forms.findreplace.Ui_Dialog() + frm.setupUi(d) + frm.type.insertItems(0, [ + _("Fields"), + _("Tags")]) + if not d.exec_(): + return + n = _("Find and Replace") + self.parent.setProgressParent(self) + self.deck.startProgress(2) + self.deck.updateProgress(_("Replacing...")) + self.deck.setUndoStart(n) + sf = self.selectedFacts() + self.deck.updateProgress() + try: + self.deck.findReplace(self.selectedFacts(), + unicode(frm.find.text()), + unicode(frm.replace.text()), + frm.type.currentIndex(), + frm.re.isChecked()) + except sre_constants.error: + ui.utils.showInfo(_("Invalid regexp."), + parent=self) + self.deck.setUndoEnd(n) + self.deck.finishProgress() + self.parent.setProgressParent(None) + self.updateSearch() + self.updateAfterCardChange() + # Jumping ###################################################################### diff --git a/designer/cardlist.ui b/designer/cardlist.ui index e1f3d0bc4..c78865163 100644 --- a/designer/cardlist.ui +++ b/designer/cardlist.ui @@ -13,14 +13,6 @@ Edit Items - - - 0 - 23 - 599 - 439 - - 0 @@ -170,7 +162,7 @@ 0 0 599 - 23 + 25 @@ -184,6 +176,8 @@ + + @@ -402,6 +396,11 @@ Select &Facts + + + Find and Re&place... + + diff --git a/designer/findreplace.ui b/designer/findreplace.ui new file mode 100644 index 000000000..5854e043d --- /dev/null +++ b/designer/findreplace.ui @@ -0,0 +1,122 @@ + + Dialog + + + + 0 + 0 + 322 + 159 + + + + Find and Replace + + + + + + + + Find + + + + + + + + + + Replace + + + + + + + + + + + + + Search + + + + + + + Treat input as regular expression + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok + + + + + + + find + replace + buttonBox + + + + + buttonBox + accepted() + Dialog + accept() + + + 252 + 127 + + + 157 + 274 + + + + + buttonBox + rejected() + Dialog + reject() + + + 286 + 127 + + + 286 + 274 + + + + +