mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
find & replace
This commit is contained in:
parent
139048ad3f
commit
3855183213
4 changed files with 84 additions and 72 deletions
|
@ -116,6 +116,7 @@ class DeckModel(QAbstractTableModel):
|
|||
|
||||
def beginReset(self):
|
||||
self.browser.editor.saveNow()
|
||||
self.browser.editor.setFact(None, hide=False)
|
||||
self.browser.mw.progress.start()
|
||||
self.saveSelection()
|
||||
self.beginResetModel()
|
||||
|
@ -740,6 +741,7 @@ where id in %s""" % ids2str(sf))
|
|||
ChangeModel(self, fids)
|
||||
|
||||
def cram(self):
|
||||
return showInfo("not yet implemented")
|
||||
self.close()
|
||||
self.mw.onCram(self.selectedCards())
|
||||
|
||||
|
@ -822,6 +824,7 @@ where id in %s""" % ids2str(sf))
|
|||
######################################################################
|
||||
|
||||
def reschedule(self):
|
||||
return showInfo("not yet implemented")
|
||||
n = _("Reschedule")
|
||||
d = QDialog(self)
|
||||
frm = aqt.forms.reschedule.Ui_Dialog()
|
||||
|
@ -911,52 +914,46 @@ where id in %s""" % ids2str(sf))
|
|||
sf = self.selectedFacts()
|
||||
if not sf:
|
||||
return
|
||||
mods = self.deck.db.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
|
||||
import anki.find
|
||||
fields = sorted(anki.find.fieldNames(self.deck, downcase=False))
|
||||
d = QDialog(self)
|
||||
frm = aqt.forms.findreplace.Ui_Dialog()
|
||||
frm.setupUi(d)
|
||||
fields = sorted(self.card.fact.model.fieldModels, key=attrgetter("name"))
|
||||
frm.field.addItems(QStringList(
|
||||
[_("All Fields")] + [f.name for f in fields]))
|
||||
frm.field.addItems(QStringList([_("All Fields")] + fields))
|
||||
self.connect(frm.buttonBox, SIGNAL("helpRequested()"),
|
||||
self.onFindReplaceHelp)
|
||||
if not d.exec_():
|
||||
return
|
||||
n = _("Find and Replace")
|
||||
self.deck.startProgress(2)
|
||||
self.deck.updateProgress(_("Replacing..."))
|
||||
self.deck.setUndoStart(n)
|
||||
self.deck.updateProgress()
|
||||
changed = None
|
||||
try:
|
||||
if frm.field.currentIndex() == 0:
|
||||
field = None
|
||||
else:
|
||||
field = fields[frm.field.currentIndex()-1].id
|
||||
field = fields[frm.field.currentIndex()-1]
|
||||
self.mw.checkpoint(_("Find and Replace"))
|
||||
self.mw.progress.start()
|
||||
self.model.beginReset()
|
||||
try:
|
||||
changed = self.deck.findReplace(sf,
|
||||
unicode(frm.find.text()),
|
||||
unicode(frm.replace.text()),
|
||||
frm.re.isChecked(),
|
||||
field)
|
||||
field,
|
||||
frm.ignoreCase.isChecked())
|
||||
except sre_constants.error:
|
||||
ui.utils.showInfo(_("Invalid regular expression."),
|
||||
parent=self)
|
||||
self.deck.setUndoEnd(n)
|
||||
self.deck.finishProgress()
|
||||
self.mw.reset()
|
||||
return
|
||||
else:
|
||||
self.onSearch()
|
||||
if changed is not None:
|
||||
ui.utils.showInfo(ngettext("%(a)d of %(b)d fact updated", "%(a)d of %(b)d facts updated", len(sf)) % {
|
||||
self.resetDeck()
|
||||
finally:
|
||||
self.model.endReset()
|
||||
self.mw.progress.finish()
|
||||
showInfo(ngettext(
|
||||
"%(a)d of %(b)d fact updated",
|
||||
"%(a)d of %(b)d facts updated", len(sf)) % {
|
||||
'a': changed,
|
||||
'b': len(sf),
|
||||
}, parent=self)
|
||||
})
|
||||
|
||||
def onFindReplaceHelp(self):
|
||||
aqt.openHelp("Browser#FindReplace")
|
||||
|
|
|
@ -350,7 +350,7 @@ class Editor(object):
|
|||
if self.fact:
|
||||
self.loadFact()
|
||||
|
||||
def setFact(self, fact):
|
||||
def setFact(self, fact, hide=True):
|
||||
"Make FACT the current fact."
|
||||
self.fact = fact
|
||||
# change timer
|
||||
|
@ -359,7 +359,7 @@ class Editor(object):
|
|||
loadCB=self._loadFinished)
|
||||
self.updateTagsAndGroup()
|
||||
self.updateKeyboard()
|
||||
else:
|
||||
elif hide:
|
||||
self.widget.hide()
|
||||
|
||||
def loadFact(self, field=0):
|
||||
|
|
|
@ -457,6 +457,9 @@
|
|||
<property name="text">
|
||||
<string>Find and Re&place...</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Alt+F</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCram">
|
||||
<property name="icon">
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
|
@ -5,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>322</width>
|
||||
<height>159</height>
|
||||
<width>367</width>
|
||||
<height>209</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -18,40 +19,50 @@
|
|||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string><b>Find</b>:</string>
|
||||
<string><b>Find</b>:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="find"/>
|
||||
</item>
|
||||
<item row="2" column="0" >
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string><b>Replace With</b>:</string>
|
||||
<string><b>Replace With</b>:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="replace"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string><b>In</b>:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="replace" />
|
||||
<widget class="QComboBox" name="field"/>
|
||||
</item>
|
||||
<item row="3" column="1" >
|
||||
<item row="4" 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" >
|
||||
<item row="3" column="1">
|
||||
<widget class="QCheckBox" name="ignoreCase">
|
||||
<property name="text">
|
||||
<string><b>In</b>:</string>
|
||||
<string>Ignore case</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" >
|
||||
<widget class="QComboBox" name="field" />
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -81,8 +92,9 @@
|
|||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>find</tabstop>
|
||||
<tabstop>field</tabstop>
|
||||
<tabstop>replace</tabstop>
|
||||
<tabstop>field</tabstop>
|
||||
<tabstop>ignoreCase</tabstop>
|
||||
<tabstop>re</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
</tabstops>
|
||||
|
|
Loading…
Reference in a new issue