HighlightingStylesReader, -Writer: added support for sub-styles. sub_styles

Sat, 16 Mar 2019 14:11:43 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 16 Mar 2019 14:11:43 +0100
branch
sub_styles
changeset 6863
e900929889dd
parent 6862
6f4237ccf576
child 6864
7837ab17f079

HighlightingStylesReader, -Writer: added support for sub-styles.

DTDs/HighlightingStyles-4.3.dtd file | annotate | diff | comparison | revisions
DTDs/HighlightingStyles-6.0.dtd file | annotate | diff | comparison | revisions
E5XML/Config.py file | annotate | diff | comparison | revisions
E5XML/HighlightingStylesReader.py file | annotate | diff | comparison | revisions
E5XML/HighlightingStylesWriter.py file | annotate | diff | comparison | revisions
install.py file | annotate | diff | comparison | revisions
--- a/DTDs/HighlightingStyles-4.3.dtd	Sat Mar 16 14:10:51 2019 +0100
+++ b/DTDs/HighlightingStyles-4.3.dtd	Sat Mar 16 14:11:43 2019 +0100
@@ -1,4 +1,4 @@
-<!-- This is the DTD for eric4's highlightings styles file version 4.3 -->
+<!-- This is the DTD for eric4's highlighting styles file version 4.3 -->
 
 <!ELEMENT   Style       (#PCDATA)>
 <!ATTLIST   Style
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DTDs/HighlightingStyles-6.0.dtd	Sat Mar 16 14:11:43 2019 +0100
@@ -0,0 +1,23 @@
+<!-- This is the DTD for eric6's highlighting styles file version 6.0 -->
+
+<!ELEMENT   Description (#PCDATA)>
+
+<!ELEMENT   Words       (#PCDATA)>
+
+<!ELEMENT   Style       (Description,
+                         Words?)>
+<!ATTLIST   Style
+    style       CDATA   #REQUIRED
+    substyle    CDATA   #REQUIRED
+    color       CDATA   #REQUIRED
+    paper       CDATA   #REQUIRED
+    font        CDATA   #REQUIRED
+    eolfill     CDATA   #REQUIRED>
+
+<!ELEMENT   Lexer       (Style+)>
+<!ATTLIST   Lexer
+    name        CDATA   #REQUIRED>
+
+<!ELEMENT   HighlightingStyles   (Lexer+)>
+<!ATTLIST   HighlightingStyles
+    version     CDATA   #REQUIRED>
--- a/E5XML/Config.py	Sat Mar 16 14:10:51 2019 +0100
+++ b/E5XML/Config.py	Sat Mar 16 14:11:43 2019 +0100
@@ -40,7 +40,7 @@
 pluginRepositoryFileFormatVersion = "4.2"
 
 # version number of the highlighting styles file
-highlightingStylesFileFormatVersion = "4.3"
+highlightingStylesFileFormatVersion = "6.0"
 
 # version number of the web browser spell check dictionaries list file
 dictionariesListFileFormatVersion = "1.0"
--- a/E5XML/HighlightingStylesReader.py	Sat Mar 16 14:10:51 2019 +0100
+++ b/E5XML/HighlightingStylesReader.py	Sat Mar 16 14:11:43 2019 +0100
@@ -16,12 +16,11 @@
 from .XMLStreamReaderBase import XMLStreamReaderBase
 
 
-# TODO: add support for sub-styling
 class HighlightingStylesReader(XMLStreamReaderBase):
     """
     Class for reading a highlighting styles XML file.
     """
-    supportedVersions = ["4.3"]
+    supportedVersions = ["4.3", "6.0"]
     
     def __init__(self, device, lexers):
         """
@@ -87,42 +86,65 @@
             style = self.attribute("style")
             if style:
                 style = int(style)
+                substyle = int(self.attribute("substyle", "-1"))
+                # -1 is default for base styles
+                
+                # add sub-style if not already there
+                if not lexer.hasStyle(style, substyle):
+                    substyle = lexer.addSubstyle(style)
                 
                 color = self.attribute("color")
                 if color:
                     color = QColor(color)
                 else:
-                    color = lexer.defaultColor(style)
-                lexer.setColor(color, style)
+                    color = lexer.defaultColor(style, substyle)
+                lexer.setColor(color, style, substyle)
                 
                 paper = self.attribute("paper")
                 if paper:
                     paper = QColor(paper)
                 else:
-                    paper = lexer.defaultPaper(style)
-                lexer.setPaper(paper, style)
+                    paper = lexer.defaultPaper(style, substyle)
+                lexer.setPaper(paper, style, substyle)
                 
                 fontStr = self.attribute("font")
                 if fontStr:
                     font = QFont()
                     font.fromString(fontStr)
                 else:
-                    font = lexer.defaultFont(style)
-                lexer.setFont(font, style)
+                    font = lexer.defaultFont(style, substyle)
+                lexer.setFont(font, style, substyle)
                 
                 eolfill = self.attribute("eolfill")
                 if eolfill:
                     eolfill = self.toBool(eolfill)
                     if eolfill is None:
-                        eolfill = lexer.defaulEolFill(style)
+                        eolfill = lexer.defaulEolFill(style, substyle)
                 else:
-                    eolfill = lexer.defaulEolFill(style)
-                lexer.setEolFill(eolfill, style)
+                    eolfill = lexer.defaulEolFill(style, substyle)
+                lexer.setEolFill(eolfill, style, substyle)
+        
+                while not self.atEnd():
+                    self.readNext()
+                    if self.isStartElement():
+                        if self.name() == "Description" and substyle >= 0:
+                            # description can only be set for sub-styles
+                            description = self.readElementText().strip()
+                            if not description:
+                                description = lexer.defaultDescription(
+                                    style, substyle)
+                            lexer.setDescription(description, style, substyle)
+                        elif self.name() == "Words" and substyle >= 0:
+                            # words can only be set for sub-styles
+                            words = self.readElementText().strip()
+                            if not words:
+                                words = lexer.defaultWords(style, substyle)
+                            lexer.setWords(words, style, substyle)
+                    
+                    if self.isEndElement() and self.name() == "Style":
+                        return
         
         while not self.atEnd():
             self.readNext()
             if self.isEndElement() and self.name() == "Style":
                 break
-            
-            if self.isStartElement():
-                self.raiseUnexpectedStartTag(self.name())
--- a/E5XML/HighlightingStylesWriter.py	Sat Mar 16 14:10:51 2019 +0100
+++ b/E5XML/HighlightingStylesWriter.py	Sat Mar 16 14:11:43 2019 +0100
@@ -18,7 +18,6 @@
 import Preferences
 
 
-# TODO: add support for sub-styling
 class HighlightingStylesWriter(XMLStreamWriterBase):
     """
     Class implementing the writer class for writing a highlighting styles XML
@@ -60,16 +59,27 @@
         for lexer in self.lexers:
             self.writeStartElement("Lexer")
             self.writeAttribute("name", lexer.language())
-            for style in lexer.descriptions:
+            for description, style, substyle in lexer.getStyles():
                 self.writeStartElement("Style")
                 self.writeAttribute("style", str(style))
-                self.writeAttribute("color", lexer.color(style).name())
-                self.writeAttribute("paper", lexer.paper(style).name())
-                self.writeAttribute("font", lexer.font(style).toString())
-                self.writeAttribute("eolfill", str(lexer.eolFill(style)))
-                self.writeCharacters(lexer.description(style))
-                self.writeEndElement()
-            self.writeEndElement()
+                self.writeAttribute("substyle", str(substyle))
+                self.writeAttribute("color",
+                                    lexer.color(style, substyle).name())
+                self.writeAttribute("paper",
+                                    lexer.paper(style, substyle).name())
+                self.writeAttribute("font",
+                                    lexer.font(style, substyle).toString())
+                self.writeAttribute("eolfill",
+                                    str(lexer.eolFill(style, substyle)))
+                self.writeStartElement("Description")
+                self.writeCharacters(lexer.description(style, substyle))
+                self.writeEndElement()      # Description
+                if substyle >= 0:
+                    self.writeStartElement("Words")
+                    self.writeCharacters(lexer.words(style, substyle).strip())
+                    self.writeEndElement()      # Words
+                self.writeEndElement()      # Style
+            self.writeEndElement()          # Lexer
         
-        self.writeEndElement()
+        self.writeEndElement()              # HighlightingStyles
         self.writeEndDocument()
--- a/install.py	Sat Mar 16 14:10:51 2019 +0100
+++ b/install.py	Sat Mar 16 14:11:43 2019 +0100
@@ -869,7 +869,7 @@
             ['*.qss'])
         copyTree(
             '{1}{0}Styles'.format(os.sep, sourceDir), cfg['ericStylesDir'],
-            ['*.e4h'])
+            ['*.e4h', '*.e6h'])
         copyTree(
             '{1}{0}i18n'.format(os.sep, sourceDir), cfg['ericTranslationsDir'],
             ['*.qm'])

eric ide

mercurial