Skip to content

Commit

Permalink
Add buttons to clear current transform rules
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed May 11, 2024
1 parent 258a979 commit 981f3c6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/calibre/gui2/dialogs/metadata_bulk.py
Expand Up @@ -16,6 +16,7 @@
QDialogButtonBox,
QFont,
QGridLayout,
QIcon,
QInputDialog,
QLabel,
QLineEdit,
Expand Down Expand Up @@ -644,6 +645,10 @@ def __init__(self, window, rows, model, tab, refresh_books):
self.button_transform_authors.clicked.connect(self.transform_authors)
self.button_transform_publishers.clicked.connect(self.transform_publishers)
self.tag_map_rules = self.author_map_rules = self.publisher_map_rules = ()
tuple(map(lambda b: (b.clicked.connect(self.clear_transform_rules_for), b.setIcon(QIcon.ic('clear_left.png')), b.setToolTip(_(
'Clear the rules'))),
(self.button_clear_tags_rules, self.button_clear_authors_rules, self.button_clear_publishers_rules)
))
self.update_transform_labels()
self.central_widget.setCurrentIndex(tab)
self.exec()
Expand All @@ -657,6 +662,19 @@ def f(label, count):
f(self.label_transform_tags, len(self.tag_map_rules))
f(self.label_transform_authors, len(self.author_map_rules))
f(self.label_transform_publishers, len(self.publisher_map_rules))
self.button_clear_tags_rules.setVisible(bool(self.tag_map_rules))
self.button_clear_authors_rules.setVisible(bool(self.author_map_rules))
self.button_clear_publishers_rules.setVisible(bool(self.publisher_map_rules))

def clear_transform_rules_for(self):
n = self.sender().objectName()
if 'tags' in n:
self.tag_map_rules = ()
elif 'authors' in n:
self.author_map_rules = ()
elif 'publisher' in n:
self.publisher_map_rules = ()
self.update_transform_labels()

def _change_transform_rules(self, RulesDialog, which):
d = RulesDialog(self)
Expand Down
24 changes: 21 additions & 3 deletions src/calibre/gui2/dialogs/metadata_bulk.ui
Expand Up @@ -1344,7 +1344,13 @@ not multiple and the destination field is multiple</string>
</widget>
</item>
<item>
<widget class="QLabel" name="label_transform_tags">
<widget class="QLabel" name="label_transform_tags"/>
</item>
<item>
<widget class="QToolButton" name="button_clear_tags_rules">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
Expand Down Expand Up @@ -1372,7 +1378,13 @@ not multiple and the destination field is multiple</string>
</widget>
</item>
<item>
<widget class="QLabel" name="label_transform_authors">
<widget class="QLabel" name="label_transform_authors"/>
</item>
<item>
<widget class="QToolButton" name="button_clear_authors_rules">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
Expand Down Expand Up @@ -1400,7 +1412,13 @@ not multiple and the destination field is multiple</string>
</widget>
</item>
<item>
<widget class="QLabel" name="label_transform_publishers">
<widget class="QLabel" name="label_transform_publishers"/>
</item>
<item>
<widget class="QToolButton" name="button_clear_publishers_rules">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
Expand Down

0 comments on commit 981f3c6

Please sign in to comment.