Preferences/ConfigurationPages/EditorHighlightingStylesPage.py

branch
sub_styles
changeset 6864
7837ab17f079
parent 6862
6f4237ccf576
child 6867
97e86d2426a9
--- a/Preferences/ConfigurationPages/EditorHighlightingStylesPage.py	Sat Mar 16 14:11:43 2019 +0100
+++ b/Preferences/ConfigurationPages/EditorHighlightingStylesPage.py	Sat Mar 16 18:38:01 2019 +0100
@@ -12,15 +12,18 @@
 from PyQt5.QtCore import pyqtSlot, Qt, QFileInfo, QFile, QIODevice
 from PyQt5.QtGui import QPalette, QFont
 from PyQt5.QtWidgets import QColorDialog, QFontDialog, QInputDialog, QMenu, \
-    QTreeWidgetItem
+    QTreeWidgetItem, QDialog
 
 from .ConfigurationPageBase import ConfigurationPageBase
 from .Ui_EditorHighlightingStylesPage import Ui_EditorHighlightingStylesPage
+from ..SubstyleDefinitionDialog import SubstyleDefinitionDialog
 
 from E5Gui import E5MessageBox, E5FileDialog
 
 from Globals import qVersionTuple
 
+import UI.PixmapCache
+
 try:
     MonospacedFontsOption = QFontDialog.MonospacedFonts
 except AttributeError:
@@ -51,6 +54,11 @@
         self.setupUi(self)
         self.setObjectName("EditorHighlightingStylesPage")
         
+        self.addSubstyleButton.setIcon(UI.PixmapCache.getIcon("plus"))
+        self.deleteSubstyleButton.setIcon(UI.PixmapCache.getIcon("minus"))
+        self.editSubstyleButton.setIcon(UI.PixmapCache.getIcon("edit"))
+        self.copySubstyleButton.setIcon(UI.PixmapCache.getIcon("editCopy"))
+        
         if qVersionTuple() < (5, 0, 0):
             self.monospacedButton.setChecked(False)
             self.monospacedButton.hide()
@@ -229,6 +237,13 @@
         self.sampleText.setPalette(pl)
         self.sampleText.repaint()
         self.eolfillCheckBox.setChecked(eolfill)
+        
+        selectedOne = len(self.styleElementList.selectedItems()) == 1
+        self.addSubstyleButton.setEnabled(
+            selectedOne and substyle < 0 and self.lexer.isBaseStyle(style))
+        self.deleteSubstyleButton.setEnabled(selectedOne and substyle >= 0)
+        self.editSubstyleButton.setEnabled(selectedOne and substyle >= 0)
+        self.copySubstyleButton.setEnabled(selectedOne and substyle >= 0)
     
     @pyqtSlot()
     def on_foregroundButton_clicked(self):
@@ -633,6 +648,100 @@
             parent = self.styleElementList.topLevelItem(parentIndex)
             itm = parent.child(index)
         self.styleElementList.setCurrentItem(itm)
+    
+    #######################################################################
+    ## Methods to add, delete and edit sub-styles and their definitions
+    #######################################################################
+    
+    @pyqtSlot()
+    def on_addSubstyleButton_clicked(self):
+        """
+        Private slot to add a new sub-style.
+        """
+        style, substyle = self.__currentStyles()
+        dlg = SubstyleDefinitionDialog(
+            self.lexer, style, substyle, parent=self)
+        if dlg.exec_() == QDialog.Accepted:
+            description, words = dlg.getData()
+            substyle = self.lexer.addSubstyle(style)
+            self.lexer.setDescription(description, style, substyle)
+            self.lexer.setWords(words, style, substyle)
+            
+            parent = self.styleElementList.findItems(
+                self.lexer.description(style), Qt.MatchExactly)[0]
+            parent.setExpanded(True)
+            itm = QTreeWidgetItem(parent, [description])
+            itm.setData(0, self.StyleRole, style)
+            itm.setData(0, self.SubstyleRole, substyle)
+            self.__styleOneItem(itm, style, substyle)
+    
+    @pyqtSlot()
+    def on_deleteSubstyleButton_clicked(self):
+        """
+        Private slot to delete the selected sub-style.
+        """
+        style, substyle = self.__currentStyles()
+        ok = E5MessageBox.yesNo(
+            self,
+            self.tr("Delete Sub-Style"),
+            self.tr("""<p>Shall the sub-style <b>{0}</b> really be"""
+                    """ deleted?</p>""").format(
+                self.lexer.description(style, substyle))
+        )
+        if ok:
+            self.lexer.delSubstyle(style, substyle)
+            
+            itm =  self.styleElementList.currentItem()
+            parent = itm.parent()
+            index = parent.indexOfChild(itm)
+            parent.takeChild(index)
+            del itm
+    
+    @pyqtSlot()
+    def on_editSubstyleButton_clicked(self):
+        """
+        Private slot to edit the selected sub-style entry.
+        """
+        style, substyle = self.__currentStyles()
+        dlg = SubstyleDefinitionDialog(
+            self.lexer, style, substyle, parent=self)
+        if dlg.exec_() == QDialog.Accepted:
+            description, words = dlg.getData()
+            self.lexer.setDescription(description, style, substyle)
+            self.lexer.setWords(words, style, substyle)
+            
+            itm =  self.styleElementList.currentItem()
+            itm.setText(0, description)
+    
+    @pyqtSlot()
+    def on_copySubstyleButton_clicked(self):
+        """
+        Private slot to copy the selected sub-style.
+        """
+        style, substyle = self.__currentStyles()
+        newSubstyle = self.lexer.addSubstyle(style)
+        
+        description = self.tr("{0} - Copy").format(
+            self.lexer.description(style, substyle))
+        self.lexer.setDescription(description, style, newSubstyle)
+        self.lexer.setWords(self.lexer.words(style, substyle),
+                            style, newSubstyle)
+        self.lexer.setColor(self.lexer.color(style, substyle),
+                            style, newSubstyle)
+        self.lexer.setPaper(self.lexer.paper(style, substyle),
+                            style, newSubstyle)
+        self.lexer.setFont(self.lexer.font(style, substyle),
+                           style, newSubstyle)
+        self.lexer.setEolFill(self.lexer.eolFill(style, substyle),
+                              style, newSubstyle)
+        
+        parent = self.styleElementList.findItems(
+            self.lexer.description(style), Qt.MatchExactly)[0]
+        parent.setExpanded(True)
+        itm = QTreeWidgetItem(parent, [description])
+        itm.setData(0, self.StyleRole, style)
+        itm.setData(0, self.SubstyleRole, newSubstyle)
+        self.__styleOneItem(itm, style, newSubstyle)
 
 
 def create(dlg):

eric ide

mercurial