mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Conversion: Allow easy re-ordering of the search and replace expressions in the conversion dialog. Also apply the expressions in the same order that they were entered when doing the conversion.
This commit is contained in:
commit
d0e4aecba9
@ -538,7 +538,7 @@ class HTMLPreProcessor(object):
|
||||
search_replace = getattr(self.extra_opts, 'search_replace', None)
|
||||
if search_replace:
|
||||
search_replace = json.loads(search_replace)
|
||||
for search_pattern, replace_txt in search_replace:
|
||||
for search_pattern, replace_txt in reversed(search_replace):
|
||||
do_search_replace(search_pattern, replace_txt)
|
||||
|
||||
end_rules = []
|
||||
|
@ -50,8 +50,8 @@ class SearchAndReplaceWidget(Widget, Ui_Form):
|
||||
proto.setFlags(Qt.ItemFlags(Qt.ItemIsSelectable + Qt.ItemIsEnabled))
|
||||
self.search_replace.setItemPrototype(proto)
|
||||
self.search_replace.setColumnCount(2)
|
||||
self.search_replace.setColumnWidth(0, 300)
|
||||
self.search_replace.setColumnWidth(1, 300)
|
||||
self.search_replace.setColumnWidth(0, 320)
|
||||
self.search_replace.setColumnWidth(1, 320)
|
||||
self.search_replace.setHorizontalHeaderLabels([
|
||||
_('Search Regular Expression'), _('Replacement Text')])
|
||||
|
||||
@ -60,6 +60,8 @@ class SearchAndReplaceWidget(Widget, Ui_Form):
|
||||
self.sr_remove.clicked.connect(self.sr_remove_clicked)
|
||||
self.sr_load.clicked.connect(self.sr_load_clicked)
|
||||
self.sr_save.clicked.connect(self.sr_save_clicked)
|
||||
self.sr_up.clicked.connect(self.sr_up_clicked)
|
||||
self.sr_down.clicked.connect(self.sr_down_clicked)
|
||||
self.search_replace.currentCellChanged.connect(self.sr_currentCellChanged)
|
||||
|
||||
self.initialize_options(get_option, get_help, db, book_id)
|
||||
@ -91,7 +93,7 @@ class SearchAndReplaceWidget(Widget, Ui_Form):
|
||||
row = self.search_replace.currentRow()
|
||||
if row >= 0:
|
||||
self.search_replace.removeRow(row)
|
||||
self.search_replace.setCurrentCell(row-1, 0)
|
||||
self.search_replace.setCurrentCell(row if row < self.search_replace.rowCount() else row-1, 0)
|
||||
self.sr_search.clear()
|
||||
self.sr_replace.clear()
|
||||
|
||||
@ -106,6 +108,7 @@ class SearchAndReplaceWidget(Widget, Ui_Form):
|
||||
try:
|
||||
self.set_value(self.opt_search_replace,
|
||||
read_sr_patterns(files[0]))
|
||||
self.search_replace.setCurrentCell(0, 0)
|
||||
except Exception as e:
|
||||
error_dialog(self, _('Failed to read'),
|
||||
_('Failed to load patterns from %s, click Show details'
|
||||
@ -123,15 +126,40 @@ class SearchAndReplaceWidget(Widget, Ui_Form):
|
||||
for search, replace in self.get_definitions():
|
||||
f.write(search + u'\n' + replace + u'\n\n')
|
||||
|
||||
def sr_up_clicked(self):
|
||||
self.cell_rearrange(-1)
|
||||
|
||||
def sr_down_clicked(self):
|
||||
self.cell_rearrange(1)
|
||||
|
||||
def cell_rearrange(self, i):
|
||||
row = self.search_replace.currentRow()
|
||||
for col in xrange(0, self.search_replace.columnCount()):
|
||||
item1 = self.search_replace.item(row, col)
|
||||
item2 = self.search_replace.item(row+i, col)
|
||||
value = item1.text();
|
||||
item1.setText(item2.text())
|
||||
item2.setText(value)
|
||||
self.search_replace.setCurrentCell(row+i, 0)
|
||||
|
||||
def sr_currentCellChanged(self, row, column, previousRow, previousColumn) :
|
||||
if row >= 0:
|
||||
self.sr_change.setEnabled(True)
|
||||
self.sr_remove.setEnabled(True)
|
||||
self.sr_save.setEnabled(True)
|
||||
self.sr_search.set_regex(self.search_replace.item(row, 0).text())
|
||||
self.sr_replace.setText(self.search_replace.item(row, 1).text())
|
||||
# set the up/down buttons
|
||||
self.sr_up.setEnabled(row > 0)
|
||||
self.sr_down.setEnabled(row < self.search_replace.rowCount()-1)
|
||||
else:
|
||||
self.sr_change.setEnabled(False)
|
||||
self.sr_remove.setEnabled(False)
|
||||
self.sr_save.setEnabled(False)
|
||||
self.sr_down.setEnabled(False)
|
||||
self.sr_up.setEnabled(False)
|
||||
|
||||
|
||||
|
||||
def break_cycles(self):
|
||||
Widget.break_cycles(self)
|
||||
|
@ -78,7 +78,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<layout class="QHBoxLayout" name="buttonsLayout">
|
||||
<property name="spacing">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
@ -146,25 +146,94 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="sr_save">
|
||||
<property name="toolTip">
|
||||
<string>Save this list of expressions so that you can re-use it easily</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Save</string>
|
||||
</property>
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Save this list of expressions so that you can re-use it easily</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QTableWidget" name="search_replace">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QHBoxLayout" name="searchReplaceLayout">
|
||||
<property name="spacing">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="search_replace">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="positionLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="sr_up">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Ignored">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Move expression up.</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>:/images/arrow-up.png</normaloff>:/images/arrow-up.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="sr_down">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Ignored">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Move expression down.</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>:/images/arrow-down.png</normaloff>:/images/arrow-down.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
@ -189,6 +258,8 @@
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="../../../../resources/images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
Loading…
x
Reference in New Issue
Block a user