21 QTreeWidgetItem, |
21 QTreeWidgetItem, |
22 ) |
22 ) |
23 |
23 |
24 from eric7.EricGui import EricPixmapCache |
24 from eric7.EricGui import EricPixmapCache |
25 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
25 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
26 from eric7.EricXML.HighlightingStylesReader import HighlightingStylesReader |
|
27 from eric7.Preferences.HighlightingStylesFile import HighlightingStylesFile |
26 from eric7.Preferences.HighlightingStylesFile import HighlightingStylesFile |
28 from eric7.QScintilla import Lexers |
27 from eric7.QScintilla import Lexers |
29 |
28 |
30 from ..SubstyleDefinitionDialog import SubstyleDefinitionDialog |
29 from ..SubstyleDefinitionDialog import SubstyleDefinitionDialog |
31 from .ConfigurationPageBase import ConfigurationPageBase |
30 from .ConfigurationPageBase import ConfigurationPageBase |
655 |
654 |
656 fn = EricFileDialog.getOpenFileName( |
655 fn = EricFileDialog.getOpenFileName( |
657 self, |
656 self, |
658 self.tr("Import Highlighting Styles"), |
657 self.tr("Import Highlighting Styles"), |
659 stylesDir, |
658 stylesDir, |
660 self.tr( |
659 self.tr("Highlighting Styles File (*.ehj)"), |
661 "Highlighting Styles File (*.ehj);;" |
|
662 "XML Highlighting Styles File (*.e6h *.e4h)" |
|
663 ), |
|
664 ) |
660 ) |
665 |
661 |
666 if not fn: |
662 if not fn: |
667 return |
663 return |
668 |
664 |
669 if fn.endswith(".ehj"): |
665 highlightingStylesFile = HighlightingStylesFile() |
670 # new JSON based file |
666 styles = highlightingStylesFile.readFile(fn) |
671 highlightingStylesFile = HighlightingStylesFile() |
667 if not styles: |
672 styles = highlightingStylesFile.readFile(fn) |
668 return |
673 if not styles: |
|
674 return |
|
675 else: |
|
676 # old XML based file |
|
677 f = QFile(fn) |
|
678 if f.open(QIODevice.OpenModeFlag.ReadOnly): |
|
679 reader = HighlightingStylesReader(f, self.lexers) |
|
680 styles = reader.readXML() |
|
681 f.close() |
|
682 if not styles: |
|
683 return |
|
684 else: |
|
685 EricMessageBox.critical( |
|
686 self, |
|
687 self.tr("Import Highlighting Styles"), |
|
688 self.tr( |
|
689 "<p>The highlighting styles file <b>{0}</b> could not" |
|
690 " be read.</p><p>Reason: {1}</p>" |
|
691 ).format(fn, f.errorString()), |
|
692 ) |
|
693 return |
|
694 |
669 |
695 self.__applyStyles(styles, importAll=importAll) |
670 self.__applyStyles(styles, importAll=importAll) |
696 self.on_lexerLanguageComboBox_activated( |
671 self.on_lexerLanguageComboBox_activated( |
697 self.lexerLanguageComboBox.currentIndex() |
672 self.lexerLanguageComboBox.currentIndex() |
698 ) |
673 ) |