support limiting to single field in find&replace

This commit is contained in:
Damien Elmes 2009-03-20 14:18:31 +09:00
parent f316492135
commit 59204fdbcc
2 changed files with 43 additions and 14 deletions

View file

@ -821,9 +821,23 @@ where id in %s""" % ids2str(sf))
######################################################################
def onFindReplace(self):
sf = self.selectedFacts()
if not sf:
return
mods = self.deck.s.column0("""
select distinct modelId from facts
where id in %s""" % ids2str(sf))
if not len(mods) == 1:
ui.utils.showInfo(
_("Can only operate on one model at a time."),
parent=self)
return
d = QDialog(self)
frm = ankiqt.forms.findreplace.Ui_Dialog()
frm.setupUi(d)
fields = sorted(self.currentCard.fact.model.fieldModels, key=attrgetter("name"))
frm.field.addItems(QStringList(
[_("All Fields")] + [f.name for f in fields]))
self.connect(frm.buttonBox, SIGNAL("helpRequested()"),
self.onFindReplaceHelp)
if not d.exec_():
@ -833,14 +847,18 @@ where id in %s""" % ids2str(sf))
self.deck.startProgress(2)
self.deck.updateProgress(_("Replacing..."))
self.deck.setUndoStart(n)
sf = self.selectedFacts()
self.deck.updateProgress()
changed = None
try:
changed = self.deck.findReplace(self.selectedFacts(),
unicode(frm.find.text()),
unicode(frm.replace.text()),
frm.re.isChecked())
if frm.field.currentIndex() == 0:
field = None
else:
field = fields[frm.field.currentIndex()-1].id
changed = self.deck.findReplace(sf,
unicode(frm.find.text()),
unicode(frm.replace.text()),
frm.re.isChecked(),
field)
except sre_constants.error:
ui.utils.showInfo(_("Invalid regular expression."),
parent=self)

View file

@ -18,30 +18,40 @@
<item row="0" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>Find</string>
<string>&lt;b>Find&lt;/b>:</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QLineEdit" name="find" />
</item>
<item row="1" column="0" >
<item row="2" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Replace</string>
<string>&lt;b>Replace With&lt;/b>:</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<item row="2" column="1" >
<widget class="QLineEdit" name="replace" />
</item>
<item row="2" column="1" >
<item row="3" column="1" >
<widget class="QCheckBox" name="re" >
<property name="text" >
<string>Treat input as regular expression</string>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>&lt;b>In&lt;/b>:</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QComboBox" name="field" />
</item>
</layout>
</item>
<item>
@ -71,6 +81,7 @@
</widget>
<tabstops>
<tabstop>find</tabstop>
<tabstop>field</tabstop>
<tabstop>replace</tabstop>
<tabstop>re</tabstop>
<tabstop>buttonBox</tabstop>
@ -84,8 +95,8 @@
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>252</x>
<y>127</y>
<x>256</x>
<y>154</y>
</hint>
<hint type="destinationlabel" >
<x>157</x>
@ -100,8 +111,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>286</x>
<y>127</y>
<x>290</x>
<y>154</y>
</hint>
<hint type="destinationlabel" >
<x>286</x>