From 6681fe6edefa0330940d3144214884c888926b05 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 27 Oct 2010 21:09:22 -0600 Subject: [PATCH] Fix #7298 (Remove Restriction - Tag editor cannot be used if you have modified tags) --- src/calibre/gui2/__init__.py | 4 ++-- src/calibre/gui2/actions/view.py | 2 +- src/calibre/gui2/dialogs/metadata_single.py | 24 +++++++++++++++------ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 8398257bde..851b94f3a4 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -255,7 +255,7 @@ def error_dialog(parent, title, msg, det_msg='', show=False, return d def question_dialog(parent, title, msg, det_msg='', show_copy_button=True, - buttons=QMessageBox.Yes|QMessageBox.No): + buttons=QMessageBox.Yes|QMessageBox.No, yes_button=QMessageBox.Yes): d = MessageBox(QMessageBox.Question, title, msg, buttons, parent, det_msg) d.setIconPixmap(QPixmap(I('dialog_question.png'))) @@ -263,7 +263,7 @@ def question_dialog(parent, title, msg, det_msg='', show_copy_button=True, if not show_copy_button: d.cb.setVisible(False) - return d.exec_() == QMessageBox.Yes + return d.exec_() == yes_button def info_dialog(parent, title, msg, det_msg='', show=False): d = MessageBox(QMessageBox.Information, title, msg, QMessageBox.Ok, diff --git a/src/calibre/gui2/actions/view.py b/src/calibre/gui2/actions/view.py index 0fbf86c567..758aaa0e0a 100644 --- a/src/calibre/gui2/actions/view.py +++ b/src/calibre/gui2/actions/view.py @@ -111,7 +111,7 @@ class ViewAction(InterfaceAction): 'books at once can be slow and have a negative effect on the ' 'responsiveness of your computer. Once started the process ' 'cannot be stopped until complete. Do you wish to continue?' - ) % num) + ) % num, show_copy_button=False) def view_folder(self, *args): rows = self.gui.current_view().selectionModel().selectedRows() diff --git a/src/calibre/gui2/dialogs/metadata_single.py b/src/calibre/gui2/dialogs/metadata_single.py index ef1bddca0c..668239f941 100644 --- a/src/calibre/gui2/dialogs/metadata_single.py +++ b/src/calibre/gui2/dialogs/metadata_single.py @@ -9,11 +9,11 @@ add/remove formats import os, re, time, traceback, textwrap from PyQt4.Qt import SIGNAL, QObject, Qt, QTimer, QThread, QDate, \ - QPixmap, QListWidgetItem, QDialog, pyqtSignal + QPixmap, QListWidgetItem, QDialog, pyqtSignal, QMessageBox from calibre.gui2 import error_dialog, file_icon_provider, dynamic, \ choose_files, choose_images, ResizableDialog, \ - warning_dialog + warning_dialog, question_dialog from calibre.gui2.dialogs.metadata_single_ui import Ui_MetadataSingleDialog from calibre.gui2.dialogs.fetch_metadata import FetchMetadata from calibre.gui2.dialogs.tag_editor import TagEditor @@ -608,9 +608,16 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): def edit_tags(self): if self.tags.text() != self.original_tags: - error_dialog(self, _('Cannot use tag editor'), - _('The tags editor cannot be used if you have modified the tags')).exec_() - return + if question_dialog(self, _('Tags changed'), + _('You have changed the tags. In order to use the tags' + ' editor, you must either discard or apply these ' + 'changes'), show_copy_button=False, + buttons=QMessageBox.Apply|QMessageBox.Discard, + yes_button=QMessageBox.Apply): + self.apply_tags(commit=True, notify=True) + self.original_tags = unicode(self.tags.text()) + else: + self.tags.setText(self.original_tags) d = TagEditor(self, self.db, self.row) d.exec_() if d.result() == QDialog.Accepted: @@ -764,6 +771,10 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): self.series.setCurrentIndex(i) break + def apply_tags(self, commit=False, notify=False): + self.db.set_tags(self.id, [x.strip() for x in + unicode(self.tags.text()).split(',')], + notify=notify, commit=commit) def accept(self): cf = getattr(self, 'cover_fetcher', None) @@ -787,11 +798,10 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): notify=False, commit=False) self.db.set_rating(self.id, 2*self.rating.value(), notify=False, commit=False) + self.apply_tags() self.db.set_publisher(self.id, unicode(self.publisher.currentText()).strip(), notify=False, commit=False) - self.db.set_tags(self.id, [x.strip() for x in - unicode(self.tags.text()).split(',')], notify=False, commit=False) self.db.set_series(self.id, unicode(self.series.currentText()).strip(), notify=False, commit=False)