This commit is contained in:
Kovid Goyal 2025-01-20 22:49:30 +05:30
commit 07c75c21c2
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 57 additions and 4 deletions

View File

@ -62,6 +62,12 @@ class TbIconRulesTab(ConfigTabWidget, Ui_Form):
hh.sectionClicked.connect(self.do_sort) hh.sectionClicked.connect(self.do_sort)
hh.setSortIndicatorShown(True) hh.setSortIndicatorShown(True)
self.delete_button.clicked.connect(self.delete_rule)
self.undo_button.clicked.connect(self.undo_delete)
self.tb_icon_rules_groupbox.setContentsMargins(0, 0, 0, 0)
self.tb_icon_rules_gridlayout.setContentsMargins(2, 2, 2, 2)
v = gprefs['tags_browser_value_icons'] v = gprefs['tags_browser_value_icons']
row = 0 row = 0
for category,vdict in v.items(): for category,vdict in v.items():
@ -112,6 +118,27 @@ class TbIconRulesTab(ConfigTabWidget, Ui_Form):
item.is_deleted = action == 'delete' item.is_deleted = action == 'delete'
self.changed_signal.emit() self.changed_signal.emit()
def keyPressEvent(self, ev):
if ev.key() == Qt.Key.Key_Delete:
self.delete_rule()
ev.accept()
return
return super().keyPressEvent(ev)
def delete_rule(self):
idx = self.rules_table.currentIndex()
if idx.isValid():
item = self.rules_table.item(idx.row(), CATEGORY_COLUMN)
item.is_deleted = True
item.setIcon(QIcon.ic('trash.png'))
def undo_delete(self):
idx = self.rules_table.currentIndex()
if idx.isValid():
item = self.rules_table.item(idx.row(), CATEGORY_COLUMN)
item.is_deleted = False
item.setIcon(QIcon())
def table_column_resized(self, col, old, new): def table_column_resized(self, col, old, new):
self.table_column_widths = [] self.table_column_widths = []
for c in range(0, self.rules_table.columnCount()): for c in range(0, self.rules_table.columnCount()):

View File

@ -37,22 +37,48 @@
<property name="title"> <property name="title">
<string>Icon value rules</string> <string>Icon value rules</string>
</property> </property>
<layout class="QVBoxLayout"> <layout class="QGridLayout" name="tb_icon_rules_gridlayout">
<item> <item row="0" column="0" colspan="2">
<widget class="QLabel" name="l12345"> <widget class="QLabel" name="l12345">
<property name="text"> <property name="text">
<string>&lt;p&gt;View all the defined value icon rules, including template rules. <string>&lt;p&gt;View all the defined value icon rules, including template rules.
Rules are defined and edited in the Tag browser context menus. Rules can be deleted in Rules are defined and edited in the Tag browser context menus. Rules can be deleted in
this dialog using the context menu.&lt;/p&gt;</string> this dialog using the button, the delete key, or the context menu.&lt;/p&gt;</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="1" column="1">
<widget class="QTableWidget" name="rules_table"/> <widget class="QTableWidget" name="rules_table"/>
</item> </item>
<item row="1" column="0">
<layout class="QVBoxLayout">
<item>
<widget class="QToolButton" name="delete_button">
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/trash.png</normaloff>:/images/trash.png</iconset>
</property>
<property name="toolTip">
<string>Delete the selected rule</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="undo_button">
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/edit-undo.png</normaloff>:/images/edit-undo.png</iconset>
</property>
<property name="toolTip">
<string>Undelete the selected rule if it is deleted</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>