Allow removal of custom themes

This commit is contained in:
Kovid Goyal 2014-05-28 11:32:16 +05:30
parent 066e783d17
commit a2342b6c4a

View File

@ -449,7 +449,7 @@ class Property(QWidget):
class ThemeEditor(Dialog):
def __init__(self, parent=None):
Dialog.__init__(self, _('Create/edit custom theme'), 'custom-theme-editor8', parent=parent)
Dialog.__init__(self, _('Create/edit custom theme'), 'custom-theme-editor', parent=parent)
def setup_ui(self):
self.block_show = False
@ -472,6 +472,10 @@ class ThemeEditor(Dialog):
self.add_button = b = QPushButton(QIcon(I('plus.png')), _('Add &new theme'), self)
b.clicked.connect(self.create_new_theme)
h.addWidget(b)
self.remove_button = b = QPushButton(QIcon(I('minus.png')), _('&Remove theme'), self)
b.clicked.connect(self.remove_theme)
h.addWidget(b)
h.addStretch(1)
self.scroll = s = QScrollArea(self)
@ -592,6 +596,8 @@ class ThemeEditor(Dialog):
c.deleteLater()
self.properties = []
name = unicode(self.theme.currentText())
if not name:
return
data = self.update_theme(name)
maxw = 0
for k in sorted(data):
@ -626,6 +632,19 @@ class ThemeEditor(Dialog):
self.block_show = False
self.show_theme()
def remove_theme(self):
name = unicode(self.theme.currentText())
if name:
tprefs['custom_themes'].pop(name, None)
tprefs['custom_themes'] = tprefs['custom_themes']
t = self.theme
self.block_show = True
t.clear(), t.addItems(sorted(custom_theme_names()))
if t.count() > 0:
t.setCurrentIndex(0)
self.block_show = False
self.show_theme()
def sizeHint(self):
g = QApplication.instance().desktop().availableGeometry(self.parent() or self)
return QSize(min(1500, g.width() - 25), 650)