mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
find & replace
This commit is contained in:
parent
7564ddec40
commit
450d4ed354
3 changed files with 166 additions and 9 deletions
|
@ -2,6 +2,7 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
|
import sre_constants
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
import time, types, sys, re
|
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.actionInvertSelection, SIGNAL("triggered()"), self.invertSelection)
|
||||||
self.connect(self.dialog.actionReverseOrder, SIGNAL("triggered()"), self.reverseOrder)
|
self.connect(self.dialog.actionReverseOrder, SIGNAL("triggered()"), self.reverseOrder)
|
||||||
self.connect(self.dialog.actionSelectFacts, SIGNAL("triggered()"), self.selectFacts)
|
self.connect(self.dialog.actionSelectFacts, SIGNAL("triggered()"), self.selectFacts)
|
||||||
|
self.connect(self.dialog.actionFindReplace, SIGNAL("triggered()"), self.onFindReplace)
|
||||||
# jumps
|
# jumps
|
||||||
self.connect(self.dialog.actionFirstCard, SIGNAL("triggered()"), self.onFirstCard)
|
self.connect(self.dialog.actionFirstCard, SIGNAL("triggered()"), self.onFirstCard)
|
||||||
self.connect(self.dialog.actionLastCard, SIGNAL("triggered()"), self.onLastCard)
|
self.connect(self.dialog.actionLastCard, SIGNAL("triggered()"), self.onLastCard)
|
||||||
|
@ -771,6 +773,40 @@ where id in %s""" % ids2str(sf))
|
||||||
def onRedo(self):
|
def onRedo(self):
|
||||||
self.deck.redo()
|
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
|
# Jumping
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,6 @@
|
||||||
<string>Edit Items</string>
|
<string>Edit Items</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget" >
|
<widget class="QWidget" name="centralwidget" >
|
||||||
<property name="geometry" >
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>23</y>
|
|
||||||
<width>599</width>
|
|
||||||
<height>439</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout" >
|
<layout class="QVBoxLayout" name="verticalLayout" >
|
||||||
<property name="spacing" >
|
<property name="spacing" >
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
|
@ -170,7 +162,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>599</width>
|
<width>599</width>
|
||||||
<height>23</height>
|
<height>25</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuEdit" >
|
<widget class="QMenu" name="menuEdit" >
|
||||||
|
@ -184,6 +176,8 @@
|
||||||
<addaction name="actionSelectFacts" />
|
<addaction name="actionSelectFacts" />
|
||||||
<addaction name="actionInvertSelection" />
|
<addaction name="actionInvertSelection" />
|
||||||
<addaction name="separator" />
|
<addaction name="separator" />
|
||||||
|
<addaction name="actionFindReplace" />
|
||||||
|
<addaction name="separator" />
|
||||||
<addaction name="actionReverseOrder" />
|
<addaction name="actionReverseOrder" />
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuActions" >
|
<widget class="QMenu" name="menuActions" >
|
||||||
|
@ -402,6 +396,11 @@
|
||||||
<string>Select &Facts</string>
|
<string>Select &Facts</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionFindReplace" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Find and Re&place...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../icons.qrc" />
|
<include location="../icons.qrc" />
|
||||||
|
|
122
designer/findreplace.ui
Normal file
122
designer/findreplace.ui
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
<ui version="4.0" >
|
||||||
|
<class>Dialog</class>
|
||||||
|
<widget class="QDialog" name="Dialog" >
|
||||||
|
<property name="geometry" >
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>322</width>
|
||||||
|
<height>159</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle" >
|
||||||
|
<string>Find and Replace</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout" >
|
||||||
|
<item>
|
||||||
|
<layout class="QGridLayout" name="gridLayout" >
|
||||||
|
<item row="0" column="0" >
|
||||||
|
<widget class="QLabel" name="label" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Find</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1" >
|
||||||
|
<widget class="QLineEdit" name="find" />
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" >
|
||||||
|
<widget class="QLabel" name="label_2" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Replace</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1" >
|
||||||
|
<widget class="QLineEdit" name="replace" />
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1" >
|
||||||
|
<widget class="QComboBox" name="type" />
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" >
|
||||||
|
<widget class="QLabel" name="label_3" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Search</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1" >
|
||||||
|
<widget class="QCheckBox" name="re" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Treat input as regular expression</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer" >
|
||||||
|
<property name="orientation" >
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0" >
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox" >
|
||||||
|
<property name="orientation" >
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons" >
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>find</tabstop>
|
||||||
|
<tabstop>replace</tabstop>
|
||||||
|
<tabstop>buttonBox</tabstop>
|
||||||
|
</tabstops>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>Dialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel" >
|
||||||
|
<x>252</x>
|
||||||
|
<y>127</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel" >
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>Dialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel" >
|
||||||
|
<x>286</x>
|
||||||
|
<y>127</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel" >
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
Loading…
Reference in a new issue