--- a/eric6/Preferences/ConfigurationPages/EditorHighlightingStylesPage.py Fri Jan 29 19:30:59 2021 +0100 +++ b/eric6/Preferences/ConfigurationPages/EditorHighlightingStylesPage.py Fri Jan 29 19:31:47 2021 +0100 @@ -30,7 +30,6 @@ NoFontsOption = QFontDialog.FontDialogOptions(0) -# TODO: add capability to export a list of selected highlighter styles class EditorHighlightingStylesPage(ConfigurationPageBase, Ui_EditorHighlightingStylesPage): """ @@ -119,9 +118,6 @@ self.styleGroup.setEnabled(False) self.lexer = None - self.exportCurrentButton.setEnabled(language != "") - self.importCurrentButton.setEnabled(language != "") - if not language: return @@ -493,43 +489,62 @@ ####################################################################### @pyqtSlot() - def on_importCurrentButton_clicked(self): + def on_importButton_clicked(self): """ - Private slot to import the styles of the current lexer. + Private slot to import styles to be selected. """ - self.__importStyles({self.lexer.language(): self.lexer}) + self.__importStyles(importAll=False) @pyqtSlot() - def on_exportCurrentButton_clicked(self): + def on_exportButton_clicked(self): """ - Private slot to export the styles of the current lexer. + Private slot to export styles to be selected. """ - self.__exportStyles([self.lexer]) + self.__exportStyles(exportAll=False) @pyqtSlot() def on_importAllButton_clicked(self): """ Private slot to import the styles of all lexers. """ - self.__importStyles(self.lexers) + self.__importStyles(importAll=True) @pyqtSlot() def on_exportAllButton_clicked(self): """ Private slot to export the styles of all lexers. """ - self.__exportStyles(list(self.lexers.values())) + self.__exportStyles(exportAll=True) - def __exportStyles(self, lexers): + def __exportStyles(self, exportAll=False): """ - Private method to export the styles of the given lexers. + Private method to export the styles of selectable lexers. - @param lexers list of lexer objects for which to export the styles - @type list of PreferencesLexer + @param exportAll flag indicating to export all styles without asking + (defaults to False) + @type bool (optional) """ from eric6config import getConfig stylesDir = getConfig("ericStylesDir") + lexerNames = list(self.lexers.keys()) + if not exportAll: + if self.lexer: + preselect = [self.lexer.language()] + else: + preselect = [] + from .EditorHighlightingStylesSelectionDialog import ( + EditorHighlightingStylesSelectionDialog) + dlg = EditorHighlightingStylesSelectionDialog( + lexerNames, forImport=False, preselect=preselect) + if dlg.exec() == QDialog.Accepted: + lexerNames = dlg.getLexerNames() + else: + # Cancelled by user + return + + lexers = [self.lexers[name] for name in lexerNames] + fn, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( self, self.tr("Export Highlighting Styles"), @@ -581,12 +596,13 @@ .format(fn, f.errorString()) ) - def __importStyles(self, lexers): + def __importStyles(self, importAll=False): """ - Private method to import the styles of the given lexers. + Private method to import the styles of lexers to be selected. - @param lexers dictionary of lexer objects for which to import the - styles + @param importAll flag indicating to import all styles without asking + (defaults to False) + @type bool (optional) """ from eric6config import getConfig stylesDir = getConfig("ericStylesDir") @@ -607,7 +623,7 @@ HighlightingStylesFile ) highlightingStylesFile = HighlightingStylesFile() - styles = highlightingStylesFile.readFile(fn, lexers) + styles = highlightingStylesFile.readFile(fn) if not styles: return else: @@ -617,7 +633,7 @@ from E5XML.HighlightingStylesReader import ( HighlightingStylesReader ) - reader = HighlightingStylesReader(f, lexers) + reader = HighlightingStylesReader(f, self.lexers) styles = reader.readXML() f.close() if not styles: @@ -633,22 +649,38 @@ ) return - self.__applyStyles(styles, lexers) + self.__applyStyles(styles, importAll=importAll) self.on_lexerLanguageComboBox_activated( self.lexerLanguageComboBox.currentText()) - def __applyStyles(self, stylesList, lexersList): + def __applyStyles(self, stylesList, importAll=False): """ Private method to apply the imported styles to this dialog. @param stylesList list of imported lexer styles @type list of dict - @param lexersList list of lexers to apply the styles to - @type list of PreferencesLexer + @param importAll flag indicating to import all styles without asking + (defaults to False) + @type bool (optional) """ + lexerNames = [d["name"] + for d in stylesList + if d["name"] in self.lexers] + + if not importAll: + from .EditorHighlightingStylesSelectionDialog import ( + EditorHighlightingStylesSelectionDialog) + dlg = EditorHighlightingStylesSelectionDialog( + lexerNames, forImport=True) + if dlg.exec() == QDialog.Accepted: + lexerNames = dlg.getLexerNames() + else: + # Cancelled by user + return + for lexerDict in stylesList: - if lexerDict["name"] in lexersList: - lexer = lexersList[lexerDict["name"]] + if lexerDict["name"] in lexerNames: + lexer = self.lexers[lexerDict["name"]] for styleDict in lexerDict["styles"]: style = styleDict["style"] substyle = styleDict["substyle"]