Changeset 3058

Show
Ignore:
Timestamp:
04/13/07 10:00:30 (2 years ago)
Author:
ed
Message:

Finally finished the logic I had been futzing around with for some time to support XML syntax coloring. Now all the Dabo XML-based files (.cdxml, .rfxml, etc.) at least appear with XML syntax coloring instead of Python coloring.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/ui/uiwx/dEditor.py

    r3054 r3058  
    6161            if self.Parent: 
    6262                self.Parent.SetLexer(stc.STC_LEX_PYTHON) 
     63            self.mode = "container" 
     64            self.Interval = self.styleTimerInterval 
     65        elif self.mode == "xml": 
     66            if self.Parent: 
     67                self.Parent.SetLexer(stc.STC_LEX_XML) 
    6368            self.mode = "container" 
    6469            self.Interval = self.styleTimerInterval 
     
    98103        self._codeCompletion = True 
    99104        self._syntaxColoring = True 
    100         self._language = "Python
     105        self._language = "
    101106        self._keyWordsSet = False 
    102107        self._defaultsSet = False 
     
    105110        self._useBookmarks = False 
    106111        self._selectionBackColor = None 
    107         self._selectionForeColor = None      
     112        self._selectionForeColor = None 
     113        self._title = "" 
    108114                 
    109115        stc.StyledTextCtrl.__init__(self, parent, -1,  
     
    381387        if not self._syntaxColoring: 
    382388            return 
    383         self._styleTimer.mode = "python" 
     389        self._styleTimer.mode = self.Language.lower() 
    384390        self._styleTimer.start() 
    385391         
     
    775781    def setSyntaxColoring(self, color=None): 
    776782        """Sets the appropriate lexer for syntax coloring.""" 
    777         if color: 
    778            lex = self.Language.lower() 
     783        lex = self.Language.lower() 
     784        if color and lex: 
    779785            if lex == "python": 
    780786                self.SetLexer(stc.STC_LEX_PYTHON) 
     
    782788                    self.SetKeyWords(0, " ".join(keyword.kwlist)) 
    783789                    self._keyWordsSet = True 
    784             self.Colourise(-1, -1) 
     790                self.Colourise(-1, -1) 
     791            elif lex == "xml": 
     792                self.SetLexer(stc.STC_LEX_XML) 
    785793        else: 
    786794            self.ClearDocumentStyle() 
     
    10751083        else: 
    10761084            func = dabo.ui.getFile 
    1077         fname = func("py", "*", message=prompt, defaultPath=drct) 
     1085        fname = func("py", "cdxml", "cnxml", "mnxml", "rfxml", "*", message=prompt, defaultPath=drct) 
    10781086        return fname 
    10791087     
     
    12201228                    return False 
    12211229            self._fileName = fileSpec 
    1222             self._curdir = os.path.split(fileSpec)[0] 
     1230            pth, fname = os.path.split(fileSpec) 
     1231            fext = os.path.splitext(fname)[1] 
     1232            if fext == ".py": 
     1233                self.Language = "Python" 
     1234            elif fext.endswith("xml"): 
     1235                self.Language = "XML" 
     1236            self._curdir = pth 
    12231237            self.SetText(text) 
    12241238            self._clearDocument(clearText=False) 
     
    16921706    def _setLanguage(self, val): 
    16931707        if self._constructed(): 
    1694             if val.lower() == "python": 
    1695                 self._language = val 
    1696             else: 
    1697                 dabo.errorLog.write(_("Currently only Python language is supported")) 
     1708            if val != self._language: 
     1709                if val.lower() in ("python", "xml"): 
     1710                    self._language = val 
     1711                else: 
     1712                    dabo.errorLog.write(_("Currently only Python and XML are supported")) 
     1713                # This forces a refresh of the coloring 
     1714                self.SyntaxColoring = self.SyntaxColoring 
    16981715        else: 
    16991716            self._properties["Language"] = val