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): 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) d = QDialog(self)
frm = ankiqt.forms.findreplace.Ui_Dialog() frm = ankiqt.forms.findreplace.Ui_Dialog()
frm.setupUi(d) 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.connect(frm.buttonBox, SIGNAL("helpRequested()"),
self.onFindReplaceHelp) self.onFindReplaceHelp)
if not d.exec_(): if not d.exec_():
@ -833,14 +847,18 @@ where id in %s""" % ids2str(sf))
self.deck.startProgress(2) self.deck.startProgress(2)
self.deck.updateProgress(_("Replacing...")) self.deck.updateProgress(_("Replacing..."))
self.deck.setUndoStart(n) self.deck.setUndoStart(n)
sf = self.selectedFacts()
self.deck.updateProgress() self.deck.updateProgress()
changed = None changed = None
try: try:
changed = self.deck.findReplace(self.selectedFacts(), if frm.field.currentIndex() == 0:
unicode(frm.find.text()), field = None
unicode(frm.replace.text()), else:
frm.re.isChecked()) 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: except sre_constants.error:
ui.utils.showInfo(_("Invalid regular expression."), ui.utils.showInfo(_("Invalid regular expression."),
parent=self) parent=self)

View file

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