mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Enhancement #7732: add an 'apply' button to bulk edit
This commit is contained in:
parent
05e09def8b
commit
2791f02c3d
@ -6,7 +6,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from PyQt4.Qt import Qt, QDialog, QGridLayout, QVBoxLayout, QFont, QLabel, \
|
from PyQt4.Qt import Qt, QDialog, QGridLayout, QVBoxLayout, QFont, QLabel, \
|
||||||
pyqtSignal
|
pyqtSignal, QDialogButtonBox
|
||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
|
|
||||||
from calibre.gui2.dialogs.metadata_bulk_ui import Ui_MetadataBulkDialog
|
from calibre.gui2.dialogs.metadata_bulk_ui import Ui_MetadataBulkDialog
|
||||||
@ -198,15 +198,30 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, window, rows, model):
|
def __init__(self, window, rows, model):
|
||||||
|
self.model = model
|
||||||
|
self.db = self.model.db
|
||||||
|
self.ids = [self.db.id(r) for r in rows]
|
||||||
QDialog.__init__(self, window)
|
QDialog.__init__(self, window)
|
||||||
Ui_MetadataBulkDialog.__init__(self)
|
Ui_MetadataBulkDialog.__init__(self)
|
||||||
|
self._initialize()
|
||||||
|
self.exec_()
|
||||||
|
|
||||||
|
def _initialize(self):
|
||||||
|
# Remove all controls from the dialog box by deleting the top layout
|
||||||
|
if self.layout():
|
||||||
|
import sip
|
||||||
|
sip.delete(self.layout())
|
||||||
|
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
self.model = model
|
self.button_box.clicked.connect(self.button_clicked)
|
||||||
self.db = model.db
|
self.button_box.button(QDialogButtonBox.Apply).setToolTip(_(
|
||||||
self.ids = [self.db.id(r) for r in rows]
|
'Immediately make all changes without closing the dialog. '
|
||||||
|
'This operation cannot be canceled or undone'))
|
||||||
|
|
||||||
self.box_title.setText('<p>' +
|
self.box_title.setText('<p>' +
|
||||||
_('Editing meta information for <b>%d books</b>') %
|
_('Editing meta information for <b>%d books</b>') %
|
||||||
len(rows))
|
len(self.ids))
|
||||||
|
|
||||||
self.write_series = False
|
self.write_series = False
|
||||||
self.changed = False
|
self.changed = False
|
||||||
|
|
||||||
@ -232,7 +247,11 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
|||||||
self.create_custom_column_editors()
|
self.create_custom_column_editors()
|
||||||
|
|
||||||
self.prepare_search_and_replace()
|
self.prepare_search_and_replace()
|
||||||
self.exec_()
|
|
||||||
|
def button_clicked(self, which):
|
||||||
|
if which == self.button_box.button(QDialogButtonBox.Apply):
|
||||||
|
self._do_the_work()
|
||||||
|
self._initialize()
|
||||||
|
|
||||||
def prepare_search_and_replace(self):
|
def prepare_search_and_replace(self):
|
||||||
self.search_for.initialize('bulk_edit_search_for')
|
self.search_for.initialize('bulk_edit_search_for')
|
||||||
@ -627,10 +646,7 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
|||||||
self.series_start_number.setEnabled(False)
|
self.series_start_number.setEnabled(False)
|
||||||
self.series_start_number.setValue(1)
|
self.series_start_number.setValue(1)
|
||||||
|
|
||||||
def accept(self):
|
def _do_the_work(self):
|
||||||
if len(self.ids) < 1:
|
|
||||||
return QDialog.accept(self)
|
|
||||||
|
|
||||||
if self.s_r_error is not None:
|
if self.s_r_error is not None:
|
||||||
error_dialog(self, _('Search/replace invalid'),
|
error_dialog(self, _('Search/replace invalid'),
|
||||||
_('Search pattern is invalid: %s')%self.s_r_error.message,
|
_('Search pattern is invalid: %s')%self.s_r_error.message,
|
||||||
@ -690,8 +706,14 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
|||||||
|
|
||||||
dynamic['s_r_search_mode'] = self.search_mode.currentIndex()
|
dynamic['s_r_search_mode'] = self.search_mode.currentIndex()
|
||||||
self.db.clean()
|
self.db.clean()
|
||||||
return QDialog.accept(self)
|
return True
|
||||||
|
|
||||||
|
def accept(self):
|
||||||
|
if len(self.ids) < 1:
|
||||||
|
return QDialog.accept(self)
|
||||||
|
if not self._do_the_work():
|
||||||
|
return False
|
||||||
|
return QDialog.accept(self)
|
||||||
|
|
||||||
def series_changed(self, *args):
|
def series_changed(self, *args):
|
||||||
self.write_series = True
|
self.write_series = True
|
||||||
|
@ -710,7 +710,7 @@ nothing should be put between the original text and the inserted text</string>
|
|||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="standardButtons">
|
<property name="standardButtons">
|
||||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user