diff --git a/src/calibre/gui2/dialogs/metadata_bulk.py b/src/calibre/gui2/dialogs/metadata_bulk.py index f8177b7680..f2a2394e9e 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.py +++ b/src/calibre/gui2/dialogs/metadata_bulk.py @@ -6,7 +6,7 @@ import re from PyQt4.Qt import Qt, QDialog, QGridLayout, QVBoxLayout, QFont, QLabel, \ - pyqtSignal + pyqtSignal, QDialogButtonBox from PyQt4 import QtGui 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): + self.model = model + self.db = self.model.db + self.ids = [self.db.id(r) for r in rows] QDialog.__init__(self, window) 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.model = model - self.db = model.db - self.ids = [self.db.id(r) for r in rows] + self.button_box.clicked.connect(self.button_clicked) + self.button_box.button(QDialogButtonBox.Apply).setToolTip(_( + 'Immediately make all changes without closing the dialog. ' + 'This operation cannot be canceled or undone')) + self.box_title.setText('
' +
_('Editing meta information for %d books') %
- len(rows))
+ len(self.ids))
+
self.write_series = False
self.changed = False
@@ -232,7 +247,11 @@ def __init__(self, window, rows, model):
self.create_custom_column_editors()
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):
self.search_for.initialize('bulk_edit_search_for')
@@ -627,10 +646,7 @@ def auto_number_changed(self, state):
self.series_start_number.setEnabled(False)
self.series_start_number.setValue(1)
- def accept(self):
- if len(self.ids) < 1:
- return QDialog.accept(self)
-
+ def _do_the_work(self):
if self.s_r_error is not None:
error_dialog(self, _('Search/replace invalid'),
_('Search pattern is invalid: %s')%self.s_r_error.message,
@@ -690,8 +706,14 @@ def accept(self):
dynamic['s_r_search_mode'] = self.search_mode.currentIndex()
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):
self.write_series = True
diff --git a/src/calibre/gui2/dialogs/metadata_bulk.ui b/src/calibre/gui2/dialogs/metadata_bulk.ui
index 44839bbacd..344bde0fa0 100644
--- a/src/calibre/gui2/dialogs/metadata_bulk.ui
+++ b/src/calibre/gui2/dialogs/metadata_bulk.ui
@@ -710,7 +710,7 @@ nothing should be put between the original text and the inserted text