21 |
21 |
22 class LexerAssociationDialog(QDialog, Ui_LexerAssociationDialog): |
22 class LexerAssociationDialog(QDialog, Ui_LexerAssociationDialog): |
23 """ |
23 """ |
24 Class implementing a dialog to enter lexer associations for the project. |
24 Class implementing a dialog to enter lexer associations for the project. |
25 """ |
25 """ |
|
26 |
26 def __init__(self, project, parent=None): |
27 def __init__(self, project, parent=None): |
27 """ |
28 """ |
28 Constructor |
29 Constructor |
29 |
30 |
30 @param project reference to the project object |
31 @param project reference to the project object |
31 @param parent reference to the parent widget (QWidget) |
32 @param parent reference to the parent widget (QWidget) |
32 """ |
33 """ |
33 super().__init__(parent) |
34 super().__init__(parent) |
34 self.setupUi(self) |
35 self.setupUi(self) |
35 |
36 |
36 self.editorLexerList.headerItem().setText( |
37 self.editorLexerList.headerItem().setText( |
37 self.editorLexerList.columnCount(), "") |
38 self.editorLexerList.columnCount(), "" |
|
39 ) |
38 header = self.editorLexerList.header() |
40 header = self.editorLexerList.header() |
39 header.setSectionResizeMode(QHeaderView.ResizeMode.ResizeToContents) |
41 header.setSectionResizeMode(QHeaderView.ResizeMode.ResizeToContents) |
40 header.setSortIndicator(0, Qt.SortOrder.AscendingOrder) |
42 header.setSortIndicator(0, Qt.SortOrder.AscendingOrder) |
41 |
43 |
42 try: |
44 try: |
43 self.extsep = os.extsep |
45 self.extsep = os.extsep |
44 except AttributeError: |
46 except AttributeError: |
45 self.extsep = "." |
47 self.extsep = "." |
46 |
48 |
47 self.extras = ["-----------", self.tr("Alternative")] |
49 self.extras = ["-----------", self.tr("Alternative")] |
48 |
50 |
49 self.editorLexerCombo.addItem("") |
51 self.editorLexerCombo.addItem("") |
50 self.editorLexerCombo.addItem( |
52 self.editorLexerCombo.addItem(UI.PixmapCache.getIcon("fileText"), "Text") |
51 UI.PixmapCache.getIcon("fileText"), |
|
52 "Text" |
|
53 ) |
|
54 for lang in sorted(QScintilla.Lexers.getSupportedLanguages().keys()): |
53 for lang in sorted(QScintilla.Lexers.getSupportedLanguages().keys()): |
55 self.editorLexerCombo.addItem( |
54 self.editorLexerCombo.addItem( |
56 QScintilla.Lexers.getLanguageIcon(lang, False), |
55 QScintilla.Lexers.getLanguageIcon(lang, False), lang |
57 lang) |
56 ) |
58 self.editorLexerCombo.addItems(self.extras) |
57 self.editorLexerCombo.addItems(self.extras) |
59 |
58 |
60 from pygments.lexers import get_all_lexers |
59 from pygments.lexers import get_all_lexers |
61 pygmentsLexers = [''] + sorted(lex[0] for lex in get_all_lexers()) |
60 |
|
61 pygmentsLexers = [""] + sorted(lex[0] for lex in get_all_lexers()) |
62 self.pygmentsLexerCombo.addItems(pygmentsLexers) |
62 self.pygmentsLexerCombo.addItems(pygmentsLexers) |
63 |
63 |
64 # set initial values |
64 # set initial values |
65 self.project = project |
65 self.project = project |
66 for ext, lexer in list(self.project.pdata["LEXERASSOCS"].items()): |
66 for ext, lexer in list(self.project.pdata["LEXERASSOCS"].items()): |
67 QTreeWidgetItem(self.editorLexerList, [ext, lexer]) |
67 QTreeWidgetItem(self.editorLexerList, [ext, lexer]) |
68 self.editorLexerList.sortByColumn(0, Qt.SortOrder.AscendingOrder) |
68 self.editorLexerList.sortByColumn(0, Qt.SortOrder.AscendingOrder) |
69 |
69 |
70 @pyqtSlot() |
70 @pyqtSlot() |
71 def on_addLexerButton_clicked(self): |
71 def on_addLexerButton_clicked(self): |
72 """ |
72 """ |
73 Private slot to add the lexer association displayed to the list. |
73 Private slot to add the lexer association displayed to the list. |
74 """ |
74 """ |
94 self.editorFileExtEdit.clear() |
93 self.editorFileExtEdit.clear() |
95 self.editorLexerCombo.setCurrentIndex(0) |
94 self.editorLexerCombo.setCurrentIndex(0) |
96 self.pygmentsLexerCombo.setCurrentIndex(0) |
95 self.pygmentsLexerCombo.setCurrentIndex(0) |
97 self.editorLexerList.sortItems( |
96 self.editorLexerList.sortItems( |
98 self.editorLexerList.sortColumn(), |
97 self.editorLexerList.sortColumn(), |
99 self.editorLexerList.header().sortIndicatorOrder()) |
98 self.editorLexerList.header().sortIndicatorOrder(), |
100 |
99 ) |
|
100 |
101 @pyqtSlot() |
101 @pyqtSlot() |
102 def on_deleteLexerButton_clicked(self): |
102 def on_deleteLexerButton_clicked(self): |
103 """ |
103 """ |
104 Private slot to delete the currently selected lexer association of the |
104 Private slot to delete the currently selected lexer association of the |
105 list. |
105 list. |
108 if itmList: |
108 if itmList: |
109 index = self.editorLexerList.indexOfTopLevelItem(itmList[0]) |
109 index = self.editorLexerList.indexOfTopLevelItem(itmList[0]) |
110 itm = self.editorLexerList.takeTopLevelItem(index) |
110 itm = self.editorLexerList.takeTopLevelItem(index) |
111 # __IGNORE_WARNING__ |
111 # __IGNORE_WARNING__ |
112 del itm |
112 del itm |
113 |
113 |
114 self.editorLexerList.clearSelection() |
114 self.editorLexerList.clearSelection() |
115 self.editorFileExtEdit.clear() |
115 self.editorFileExtEdit.clear() |
116 self.editorLexerCombo.setCurrentIndex(0) |
116 self.editorLexerCombo.setCurrentIndex(0) |
117 |
117 |
118 def on_editorLexerList_itemClicked(self, itm, column): |
118 def on_editorLexerList_itemClicked(self, itm, column): |
119 """ |
119 """ |
120 Private slot to handle the clicked signal of the lexer association |
120 Private slot to handle the clicked signal of the lexer association |
121 list. |
121 list. |
122 |
122 |
123 @param itm reference to the selecte item (QTreeWidgetItem) |
123 @param itm reference to the selecte item (QTreeWidgetItem) |
124 @param column column the item was clicked or activated (integer) |
124 @param column column the item was clicked or activated (integer) |
125 (ignored) |
125 (ignored) |
126 """ |
126 """ |
127 if itm is None: |
127 if itm is None: |
138 else: |
138 else: |
139 pygmentsIndex = 0 |
139 pygmentsIndex = 0 |
140 index = self.editorLexerCombo.findText(lexer) |
140 index = self.editorLexerCombo.findText(lexer) |
141 self.editorLexerCombo.setCurrentIndex(index) |
141 self.editorLexerCombo.setCurrentIndex(index) |
142 self.pygmentsLexerCombo.setCurrentIndex(pygmentsIndex) |
142 self.pygmentsLexerCombo.setCurrentIndex(pygmentsIndex) |
143 |
143 |
144 def on_editorLexerList_itemActivated(self, itm, column): |
144 def on_editorLexerList_itemActivated(self, itm, column): |
145 """ |
145 """ |
146 Private slot to handle the activated signal of the lexer association |
146 Private slot to handle the activated signal of the lexer association |
147 list. |
147 list. |
148 |
148 |
149 @param itm reference to the selecte item (QTreeWidgetItem) |
149 @param itm reference to the selecte item (QTreeWidgetItem) |
150 @param column column the item was clicked or activated (integer) |
150 @param column column the item was clicked or activated (integer) |
151 (ignored) |
151 (ignored) |
152 """ |
152 """ |
153 self.on_editorLexerList_itemClicked(itm, column) |
153 self.on_editorLexerList_itemClicked(itm, column) |
154 |
154 |
155 @pyqtSlot(int) |
155 @pyqtSlot(int) |
156 def on_editorLexerCombo_currentIndexChanged(self, index): |
156 def on_editorLexerCombo_currentIndexChanged(self, index): |
157 """ |
157 """ |
158 Private slot to handle the selection of a lexer. |
158 Private slot to handle the selection of a lexer. |
159 |
159 |
160 @param index index of the current item |
160 @param index index of the current item |
161 @type int |
161 @type int |
162 """ |
162 """ |
163 text = self.editorLexerCombo.itemText(index) |
163 text = self.editorLexerCombo.itemText(index) |
164 if text in self.extras: |
164 if text in self.extras: |