src/eric7/Preferences/ConfigurationPages/EditorHighlightersPage.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
23 23
24 class EditorHighlightersPage(ConfigurationPageBase, Ui_EditorHighlightersPage): 24 class EditorHighlightersPage(ConfigurationPageBase, Ui_EditorHighlightersPage):
25 """ 25 """
26 Class implementing the Editor Highlighter Associations configuration page. 26 Class implementing the Editor Highlighter Associations configuration page.
27 """ 27 """
28
28 def __init__(self, lexers): 29 def __init__(self, lexers):
29 """ 30 """
30 Constructor 31 Constructor
31 32
32 @param lexers reference to the lexers dictionary 33 @param lexers reference to the lexers dictionary
33 """ 34 """
34 super().__init__() 35 super().__init__()
35 self.setupUi(self) 36 self.setupUi(self)
36 self.setObjectName("EditorHighlightersPage") 37 self.setObjectName("EditorHighlightersPage")
37 38
38 self.editorLexerList.headerItem().setText( 39 self.editorLexerList.headerItem().setText(
39 self.editorLexerList.columnCount(), "") 40 self.editorLexerList.columnCount(), ""
41 )
40 header = self.editorLexerList.header() 42 header = self.editorLexerList.header()
41 header.setSectionResizeMode(QHeaderView.ResizeMode.ResizeToContents) 43 header.setSectionResizeMode(QHeaderView.ResizeMode.ResizeToContents)
42 header.setSortIndicator(0, Qt.SortOrder.AscendingOrder) 44 header.setSortIndicator(0, Qt.SortOrder.AscendingOrder)
43 45
44 try: 46 try:
45 self.extsep = os.extsep 47 self.extsep = os.extsep
46 except AttributeError: 48 except AttributeError:
47 self.extsep = "." 49 self.extsep = "."
48 50
49 import QScintilla.Lexers 51 import QScintilla.Lexers
52
50 self.extras = ["-----------", self.tr("Alternative")] 53 self.extras = ["-----------", self.tr("Alternative")]
51 self.editorLexerCombo.addItem("") 54 self.editorLexerCombo.addItem("")
52 self.editorLexerCombo.addItem( 55 self.editorLexerCombo.addItem(UI.PixmapCache.getIcon("fileText"), "Text")
53 UI.PixmapCache.getIcon("fileText"),
54 "Text"
55 )
56 for lang in sorted(lexers.keys()): 56 for lang in sorted(lexers.keys()):
57 self.editorLexerCombo.addItem( 57 self.editorLexerCombo.addItem(
58 QScintilla.Lexers.getLanguageIcon(lang, False), 58 QScintilla.Lexers.getLanguageIcon(lang, False), lang
59 lang
60 ) 59 )
61 self.editorLexerCombo.addItems(self.extras) 60 self.editorLexerCombo.addItems(self.extras)
62 61
63 pygmentsLexers = [''] + sorted(lex[0] for lex in get_all_lexers()) 62 pygmentsLexers = [""] + sorted(lex[0] for lex in get_all_lexers())
64 self.pygmentsLexerCombo.addItems(pygmentsLexers) 63 self.pygmentsLexerCombo.addItems(pygmentsLexers)
65 64
66 # set initial values 65 # set initial values
67 lexerAssocs = Preferences.getEditorLexerAssocs() 66 lexerAssocs = Preferences.getEditorLexerAssocs()
68 for ext in lexerAssocs: 67 for ext in lexerAssocs:
69 QTreeWidgetItem(self.editorLexerList, [ext, lexerAssocs[ext]]) 68 QTreeWidgetItem(self.editorLexerList, [ext, lexerAssocs[ext]])
70 self.editorLexerList.sortByColumn(0, Qt.SortOrder.AscendingOrder) 69 self.editorLexerList.sortByColumn(0, Qt.SortOrder.AscendingOrder)
71 70
72 def save(self): 71 def save(self):
73 """ 72 """
74 Public slot to save the Editor Highlighter Associations configuration. 73 Public slot to save the Editor Highlighter Associations configuration.
75 """ 74 """
76 lexerAssocs = {} 75 lexerAssocs = {}
77 for index in range( 76 for index in range(self.editorLexerList.topLevelItemCount()):
78 self.editorLexerList.topLevelItemCount()):
79 itm = self.editorLexerList.topLevelItem(index) 77 itm = self.editorLexerList.topLevelItem(index)
80 lexerAssocs[itm.text(0)] = itm.text(1) 78 lexerAssocs[itm.text(0)] = itm.text(1)
81 Preferences.setEditorLexerAssocs(lexerAssocs) 79 Preferences.setEditorLexerAssocs(lexerAssocs)
82 80
83 @pyqtSlot() 81 @pyqtSlot()
84 def on_addLexerButton_clicked(self): 82 def on_addLexerButton_clicked(self):
85 """ 83 """
86 Private slot to add the lexer association displayed to the list. 84 Private slot to add the lexer association displayed to the list.
87 """ 85 """
94 if not pygmentsLexer: 92 if not pygmentsLexer:
95 lexer = pygmentsLexer 93 lexer = pygmentsLexer
96 else: 94 else:
97 lexer = "Pygments|{0}".format(pygmentsLexer) 95 lexer = "Pygments|{0}".format(pygmentsLexer)
98 if ext and lexer: 96 if ext and lexer:
99 itmList = self.editorLexerList.findItems( 97 itmList = self.editorLexerList.findItems(ext, Qt.MatchFlag.MatchExactly, 0)
100 ext, Qt.MatchFlag.MatchExactly, 0)
101 if itmList: 98 if itmList:
102 index = self.editorLexerList.indexOfTopLevelItem(itmList[0]) 99 index = self.editorLexerList.indexOfTopLevelItem(itmList[0])
103 itm = self.editorLexerList.takeTopLevelItem(index) 100 itm = self.editorLexerList.takeTopLevelItem(index)
104 # __IGNORE_WARNING__ 101 # __IGNORE_WARNING__
105 del itm 102 del itm
107 self.editorFileExtEdit.clear() 104 self.editorFileExtEdit.clear()
108 self.editorLexerCombo.setCurrentIndex(0) 105 self.editorLexerCombo.setCurrentIndex(0)
109 self.pygmentsLexerCombo.setCurrentIndex(0) 106 self.pygmentsLexerCombo.setCurrentIndex(0)
110 self.editorLexerList.sortItems( 107 self.editorLexerList.sortItems(
111 self.editorLexerList.sortColumn(), 108 self.editorLexerList.sortColumn(),
112 self.editorLexerList.header().sortIndicatorOrder()) 109 self.editorLexerList.header().sortIndicatorOrder(),
113 110 )
111
114 @pyqtSlot() 112 @pyqtSlot()
115 def on_deleteLexerButton_clicked(self): 113 def on_deleteLexerButton_clicked(self):
116 """ 114 """
117 Private slot to delete the currently selected lexer association of the 115 Private slot to delete the currently selected lexer association of the
118 list. 116 list.
121 if itmList: 119 if itmList:
122 index = self.editorLexerList.indexOfTopLevelItem(itmList[0]) 120 index = self.editorLexerList.indexOfTopLevelItem(itmList[0])
123 itm = self.editorLexerList.takeTopLevelItem(index) 121 itm = self.editorLexerList.takeTopLevelItem(index)
124 # __IGNORE_WARNING__ 122 # __IGNORE_WARNING__
125 del itm 123 del itm
126 124
127 self.editorLexerList.clearSelection() 125 self.editorLexerList.clearSelection()
128 self.editorFileExtEdit.clear() 126 self.editorFileExtEdit.clear()
129 self.editorLexerCombo.setCurrentIndex(0) 127 self.editorLexerCombo.setCurrentIndex(0)
130 128
131 def on_editorLexerList_itemClicked(self, itm, column): 129 def on_editorLexerList_itemClicked(self, itm, column):
132 """ 130 """
133 Private slot to handle the clicked signal of the lexer association 131 Private slot to handle the clicked signal of the lexer association
134 list. 132 list.
135 133
136 @param itm reference to the selecte item (QTreeWidgetItem) 134 @param itm reference to the selecte item (QTreeWidgetItem)
137 @param column column the item was clicked or activated (integer) 135 @param column column the item was clicked or activated (integer)
138 (ignored) 136 (ignored)
139 """ 137 """
140 if itm is None: 138 if itm is None:
151 else: 149 else:
152 pygmentsIndex = 0 150 pygmentsIndex = 0
153 index = self.editorLexerCombo.findText(lexer) 151 index = self.editorLexerCombo.findText(lexer)
154 self.editorLexerCombo.setCurrentIndex(index) 152 self.editorLexerCombo.setCurrentIndex(index)
155 self.pygmentsLexerCombo.setCurrentIndex(pygmentsIndex) 153 self.pygmentsLexerCombo.setCurrentIndex(pygmentsIndex)
156 154
157 def on_editorLexerList_itemActivated(self, itm, column): 155 def on_editorLexerList_itemActivated(self, itm, column):
158 """ 156 """
159 Private slot to handle the activated signal of the lexer association 157 Private slot to handle the activated signal of the lexer association
160 list. 158 list.
161 159
162 @param itm reference to the selecte item (QTreeWidgetItem) 160 @param itm reference to the selecte item (QTreeWidgetItem)
163 @param column column the item was clicked or activated (integer) 161 @param column column the item was clicked or activated (integer)
164 (ignored) 162 (ignored)
165 """ 163 """
166 self.on_editorLexerList_itemClicked(itm, column) 164 self.on_editorLexerList_itemClicked(itm, column)
167 165
168 @pyqtSlot(int) 166 @pyqtSlot(int)
169 def on_editorLexerCombo_currentIndexChanged(self, index): 167 def on_editorLexerCombo_currentIndexChanged(self, index):
170 """ 168 """
171 Private slot to handle the selection of a lexer. 169 Private slot to handle the selection of a lexer.
172 170
173 @param index index of the current item 171 @param index index of the current item
174 @type int 172 @type int
175 """ 173 """
176 text = self.editorLexerCombo.itemText(index) 174 text = self.editorLexerCombo.itemText(index)
177 if text in self.extras: 175 if text in self.extras:
183 181
184 182
185 def create(dlg): 183 def create(dlg):
186 """ 184 """
187 Module function to create the configuration page. 185 Module function to create the configuration page.
188 186
189 @param dlg reference to the configuration dialog 187 @param dlg reference to the configuration dialog
190 @return reference to the instantiated page (ConfigurationPageBase) 188 @return reference to the instantiated page (ConfigurationPageBase)
191 """ 189 """
192 page = EditorHighlightersPage(dlg.getLexers()) 190 page = EditorHighlightersPage(dlg.getLexers())
193 return page 191 return page

eric ide

mercurial