20 QTreeWidgetItem, |
20 QTreeWidgetItem, |
21 ) |
21 ) |
22 |
22 |
23 from eric7.EricGui import EricPixmapCache |
23 from eric7.EricGui import EricPixmapCache |
24 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
24 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
|
25 from eric7.EricXML.HighlightingStylesReader import HighlightingStylesReader |
|
26 from eric7.Preferences.HighlightingStylesFile import HighlightingStylesFile |
|
27 from eric7.QScintilla import Lexers |
25 |
28 |
26 from ..SubstyleDefinitionDialog import SubstyleDefinitionDialog |
29 from ..SubstyleDefinitionDialog import SubstyleDefinitionDialog |
27 from .ConfigurationPageBase import ConfigurationPageBase |
30 from .ConfigurationPageBase import ConfigurationPageBase |
28 from .Ui_EditorHighlightingStylesPage import Ui_EditorHighlightingStylesPage |
31 from .Ui_EditorHighlightingStylesPage import Ui_EditorHighlightingStylesPage |
29 |
32 |
87 |
90 |
88 self.lexer = None |
91 self.lexer = None |
89 self.lexers = lexers |
92 self.lexers = lexers |
90 |
93 |
91 # set initial values |
94 # set initial values |
92 from eric7.QScintilla import Lexers |
|
93 |
|
94 languages = sorted([""] + list(self.lexers.keys())) |
95 languages = sorted([""] + list(self.lexers.keys())) |
95 for language in languages: |
96 for language in languages: |
96 self.lexerLanguageComboBox.addItem( |
97 self.lexerLanguageComboBox.addItem( |
97 Lexers.getLanguageIcon(language, False), language |
98 Lexers.getLanguageIcon(language, False), language |
98 ) |
99 ) |
539 (defaults to False) |
540 (defaults to False) |
540 @type bool (optional) |
541 @type bool (optional) |
541 """ |
542 """ |
542 from eric7.Globals import getConfig |
543 from eric7.Globals import getConfig |
543 |
544 |
|
545 from .EditorHighlightingStylesSelectionDialog import ( |
|
546 EditorHighlightingStylesSelectionDialog, |
|
547 ) |
|
548 |
544 stylesDir = getConfig("ericStylesDir") |
549 stylesDir = getConfig("ericStylesDir") |
545 |
550 |
546 lexerNames = list(self.lexers.keys()) |
551 lexerNames = list(self.lexers.keys()) |
547 if not exportAll: |
552 if not exportAll: |
548 if self.lexer: |
553 if self.lexer: |
549 preselect = [self.lexer.language()] |
554 preselect = [self.lexer.language()] |
550 else: |
555 else: |
551 preselect = [] |
556 preselect = [] |
552 from .EditorHighlightingStylesSelectionDialog import ( |
|
553 EditorHighlightingStylesSelectionDialog, |
|
554 ) |
|
555 |
|
556 dlg = EditorHighlightingStylesSelectionDialog( |
557 dlg = EditorHighlightingStylesSelectionDialog( |
557 lexerNames, forImport=False, preselect=preselect |
558 lexerNames, forImport=False, preselect=preselect |
558 ) |
559 ) |
559 if dlg.exec() == QDialog.DialogCode.Accepted: |
560 if dlg.exec() == QDialog.DialogCode.Accepted: |
560 lexerNames = dlg.getLexerNames() |
561 lexerNames = dlg.getLexerNames() |
626 if not fn: |
625 if not fn: |
627 return |
626 return |
628 |
627 |
629 if fn.endswith(".ehj"): |
628 if fn.endswith(".ehj"): |
630 # new JSON based file |
629 # new JSON based file |
631 from eric7.Preferences.HighlightingStylesFile import HighlightingStylesFile |
|
632 |
|
633 highlightingStylesFile = HighlightingStylesFile() |
630 highlightingStylesFile = HighlightingStylesFile() |
634 styles = highlightingStylesFile.readFile(fn) |
631 styles = highlightingStylesFile.readFile(fn) |
635 if not styles: |
632 if not styles: |
636 return |
633 return |
637 else: |
634 else: |
638 # old XML based file |
635 # old XML based file |
639 f = QFile(fn) |
636 f = QFile(fn) |
640 if f.open(QIODevice.OpenModeFlag.ReadOnly): |
637 if f.open(QIODevice.OpenModeFlag.ReadOnly): |
641 from eric7.EricXML.HighlightingStylesReader import ( |
|
642 HighlightingStylesReader, |
|
643 ) |
|
644 |
|
645 reader = HighlightingStylesReader(f, self.lexers) |
638 reader = HighlightingStylesReader(f, self.lexers) |
646 styles = reader.readXML() |
639 styles = reader.readXML() |
647 f.close() |
640 f.close() |
648 if not styles: |
641 if not styles: |
649 return |
642 return |
671 @type list of dict |
664 @type list of dict |
672 @param importAll flag indicating to import all styles without asking |
665 @param importAll flag indicating to import all styles without asking |
673 (defaults to False) |
666 (defaults to False) |
674 @type bool (optional) |
667 @type bool (optional) |
675 """ |
668 """ |
|
669 from .EditorHighlightingStylesSelectionDialog import ( |
|
670 EditorHighlightingStylesSelectionDialog, |
|
671 ) |
|
672 |
676 lexerNames = [d["name"] for d in stylesList if d["name"] in self.lexers] |
673 lexerNames = [d["name"] for d in stylesList if d["name"] in self.lexers] |
677 |
674 |
678 if not importAll: |
675 if not importAll: |
679 from .EditorHighlightingStylesSelectionDialog import ( |
|
680 EditorHighlightingStylesSelectionDialog, |
|
681 ) |
|
682 |
|
683 dlg = EditorHighlightingStylesSelectionDialog(lexerNames, forImport=True) |
676 dlg = EditorHighlightingStylesSelectionDialog(lexerNames, forImport=True) |
684 if dlg.exec() == QDialog.DialogCode.Accepted: |
677 if dlg.exec() == QDialog.DialogCode.Accepted: |
685 lexerNames = dlg.getLexerNames() |
678 lexerNames = dlg.getLexerNames() |
686 else: |
679 else: |
687 # Cancelled by user |
680 # Cancelled by user |