diff --git a/src/calibre/gui2/preferences/coloring.py b/src/calibre/gui2/preferences/coloring.py
index ca30563703..d1acd0d6d8 100644
--- a/src/calibre/gui2/preferences/coloring.py
+++ b/src/calibre/gui2/preferences/coloring.py
@@ -836,6 +836,10 @@ class RulesModel(QAbstractListModel): # {{{
else:
continue
break
+ if action_name == Rule.INVALID_CONDITION:
+ return (
+ _('
The condition using column %(col)s is invalid')
+ % dict(col=c))
return (
_('If the %(col)s column %(action)s value: %(val)s') % dict(
col=c, action=action_name, val=prepare_string_for_xml(v)))
@@ -864,7 +868,7 @@ class EditRules(QWidget): # {{{
self.add_button = QPushButton(QIcon(I('plus.png')), _('Add Rule'),
self)
self.remove_button = QPushButton(QIcon(I('minus.png')),
- _('Remove Rule'), self)
+ _('Remove Rule(s)'), self)
self.add_button.clicked.connect(self.add_rule)
self.remove_button.clicked.connect(self.remove_rule)
l.addWidget(self.add_button, l.rowCount(), 0)
@@ -873,7 +877,7 @@ class EditRules(QWidget): # {{{
self.g = g = QGridLayout()
self.rules_view = QListView(self)
self.rules_view.doubleClicked.connect(self.edit_rule)
- self.rules_view.setSelectionMode(self.rules_view.SingleSelection)
+ self.rules_view.setSelectionMode(self.rules_view.ExtendedSelection)
self.rules_view.setAlternatingRowColors(True)
self.rtfd = RichTextDelegate(parent=self.rules_view, max_width=400)
self.rules_view.setItemDelegate(self.rtfd)
@@ -1003,12 +1007,13 @@ class EditRules(QWidget): # {{{
error_dialog(self, _('No rule selected'),
_('No rule selected for %s.')%txt, show=True)
return None
- return rows[0]
+ return sorted(rows, reverse=True)
def remove_rule(self):
- row = self.get_selected_row(_('removal'))
- if row is not None:
- self.model.remove_rule(row)
+ rows = self.get_selected_row(_('removal'))
+ if rows is not None:
+ for row in rows:
+ self.model.remove_rule(row)
self.changed.emit()
def move_up(self):
diff --git a/src/calibre/library/coloring.py b/src/calibre/library/coloring.py
index ab8551b0d7..ef48508233 100644
--- a/src/calibre/library/coloring.py
+++ b/src/calibre/library/coloring.py
@@ -17,6 +17,8 @@ class Rule(object): # {{{
SIGNATURE = '# BasicColorRule():'
+ INVALID_CONDITION = _('INVALID CONDITION')
+
def __init__(self, fm, color=None):
self.color = color
self.fm = fm
@@ -28,6 +30,8 @@ class Rule(object): # {{{
v = self.validate_condition(col, action, val)
if v:
raise ValueError(v)
+ if self.apply_condition((col, action, val)) is None:
+ action = self.INVALID_CONDITION
self.conditions.append((col, action, val))
def validate_condition(self, col, action, val):