70 @signal umlFile(filename) emitted to open an eric UML file (str) |
88 @signal umlFile(filename) emitted to open an eric UML file (str) |
71 @signal binaryFile(filename) emitted to open a file as binary (str) |
89 @signal binaryFile(filename) emitted to open a file as binary (str) |
72 @signal testFile(filename) emitted to open a Python file for a |
90 @signal testFile(filename) emitted to open a Python file for a |
73 unit test (str) |
91 unit test (str) |
74 """ |
92 """ |
75 sourceFile = pyqtSignal((str, ), (str, int), (str, list), (str, int, str)) |
93 |
|
94 sourceFile = pyqtSignal((str,), (str, int), (str, list), (str, int, str)) |
76 designerFile = pyqtSignal(str) |
95 designerFile = pyqtSignal(str) |
77 linguistFile = pyqtSignal(str) |
96 linguistFile = pyqtSignal(str) |
78 trpreview = pyqtSignal((list, ), (list, bool)) |
97 trpreview = pyqtSignal((list,), (list, bool)) |
79 projectFile = pyqtSignal(str) |
98 projectFile = pyqtSignal(str) |
80 multiProjectFile = pyqtSignal(str) |
99 multiProjectFile = pyqtSignal(str) |
81 pixmapFile = pyqtSignal(str) |
100 pixmapFile = pyqtSignal(str) |
82 pixmapEditFile = pyqtSignal(str) |
101 pixmapEditFile = pyqtSignal(str) |
83 svgFile = pyqtSignal(str) |
102 svgFile = pyqtSignal(str) |
84 umlFile = pyqtSignal(str) |
103 umlFile = pyqtSignal(str) |
85 binaryFile = pyqtSignal(str) |
104 binaryFile = pyqtSignal(str) |
86 testFile = pyqtSignal(str) |
105 testFile = pyqtSignal(str) |
87 |
106 |
88 def __init__(self, parent=None): |
107 def __init__(self, parent=None): |
89 """ |
108 """ |
90 Constructor |
109 Constructor |
91 |
110 |
92 @param parent parent widget (QWidget) |
111 @param parent parent widget (QWidget) |
93 """ |
112 """ |
94 super().__init__(parent) |
113 super().__init__(parent) |
95 |
114 |
96 self.setWindowTitle(QCoreApplication.translate('Browser', |
115 self.setWindowTitle(QCoreApplication.translate("Browser", "File-Browser")) |
97 'File-Browser')) |
|
98 self.setWindowIcon(UI.PixmapCache.getIcon("eric")) |
116 self.setWindowIcon(UI.PixmapCache.getIcon("eric")) |
99 |
117 |
100 self.__model = BrowserModel() |
118 self.__model = BrowserModel() |
101 self.__sortModel = BrowserSortFilterProxyModel() |
119 self.__sortModel = BrowserSortFilterProxyModel() |
102 self.__sortModel.setSourceModel(self.__model) |
120 self.__sortModel.setSourceModel(self.__model) |
103 self.setModel(self.__sortModel) |
121 self.setModel(self.__sortModel) |
104 |
122 |
105 self.selectedItemsFilter = [BrowserFileItem] |
123 self.selectedItemsFilter = [BrowserFileItem] |
106 |
124 |
107 self._activating = False |
125 self._activating = False |
108 |
126 |
109 self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) |
127 self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) |
110 self.customContextMenuRequested.connect(self._contextMenuRequested) |
128 self.customContextMenuRequested.connect(self._contextMenuRequested) |
111 self.activated.connect(self._openItem) |
129 self.activated.connect(self._openItem) |
112 self.expanded.connect(self._resizeColumns) |
130 self.expanded.connect(self._resizeColumns) |
113 self.collapsed.connect(self._resizeColumns) |
131 self.collapsed.connect(self._resizeColumns) |
114 |
132 |
115 self.setWhatsThis(QCoreApplication.translate( |
133 self.setWhatsThis( |
116 'Browser', |
134 QCoreApplication.translate( |
117 """<b>The Browser Window</b>""" |
135 "Browser", |
118 """<p>This allows you to easily navigate the hierarchy of""" |
136 """<b>The Browser Window</b>""" |
119 """ directories and files on your system, identify the Python""" |
137 """<p>This allows you to easily navigate the hierarchy of""" |
120 """ programs and open them up in a Source Viewer window. The""" |
138 """ directories and files on your system, identify the Python""" |
121 """ window displays several separate hierarchies.</p>""" |
139 """ programs and open them up in a Source Viewer window. The""" |
122 """<p>The first hierarchy is only shown if you have opened a""" |
140 """ window displays several separate hierarchies.</p>""" |
123 """ program for debugging and its root is the directory""" |
141 """<p>The first hierarchy is only shown if you have opened a""" |
124 """ containing that program. Usually all of the separate files""" |
142 """ program for debugging and its root is the directory""" |
125 """ that make up a Python application are held in the same""" |
143 """ containing that program. Usually all of the separate files""" |
126 """ directory, so this hierarchy gives you easy access to most""" |
144 """ that make up a Python application are held in the same""" |
127 """ of what you will need.</p>""" |
145 """ directory, so this hierarchy gives you easy access to most""" |
128 """<p>The next hierarchy is used to easily navigate the""" |
146 """ of what you will need.</p>""" |
129 """ directories that are specified in the Python""" |
147 """<p>The next hierarchy is used to easily navigate the""" |
130 """ <tt>sys.path</tt> variable.</p>""" |
148 """ directories that are specified in the Python""" |
131 """<p>The remaining hierarchies allow you navigate your system""" |
149 """ <tt>sys.path</tt> variable.</p>""" |
132 """ as a whole. On a UNIX system there will be a hierarchy with""" |
150 """<p>The remaining hierarchies allow you navigate your system""" |
133 """ <tt>/</tt> at its root and another with the user home""" |
151 """ as a whole. On a UNIX system there will be a hierarchy with""" |
134 """ directory. On a Windows system there will be a hierarchy for""" |
152 """ <tt>/</tt> at its root and another with the user home""" |
135 """ each drive on the""" |
153 """ directory. On a Windows system there will be a hierarchy for""" |
136 """ system.</p>""" |
154 """ each drive on the""" |
137 """<p>Python programs (i.e. those with a <tt>.py</tt> file name""" |
155 """ system.</p>""" |
138 """ suffix) are identified in the hierarchies with a Python""" |
156 """<p>Python programs (i.e. those with a <tt>.py</tt> file name""" |
139 """ icon. The right mouse button will popup a menu which lets""" |
157 """ suffix) are identified in the hierarchies with a Python""" |
140 """ you open the file in a Source Viewer window, open the file""" |
158 """ icon. The right mouse button will popup a menu which lets""" |
141 """ for debugging or use it for a test run.</p>""" |
159 """ you open the file in a Source Viewer window, open the file""" |
142 """<p>The context menu of a class, function or method allows you""" |
160 """ for debugging or use it for a test run.</p>""" |
143 """ to open the file defining this class, function or method and""" |
161 """<p>The context menu of a class, function or method allows you""" |
144 """ will ensure, that the correct source line is visible.</p>""" |
162 """ to open the file defining this class, function or method and""" |
145 """<p>Qt-Designer files (i.e. those with a <tt>.ui</tt> file""" |
163 """ will ensure, that the correct source line is visible.</p>""" |
146 """ name suffix) are shown with a Designer icon. The context""" |
164 """<p>Qt-Designer files (i.e. those with a <tt>.ui</tt> file""" |
147 """ menu of these files allows you to start Qt-Designer with""" |
165 """ name suffix) are shown with a Designer icon. The context""" |
148 """ that file.</p>""" |
166 """ menu of these files allows you to start Qt-Designer with""" |
149 """<p>Qt-Linguist files (i.e. those with a <tt>.ts</tt> file""" |
167 """ that file.</p>""" |
150 """ name suffix) are shown with a Linguist icon. The context""" |
168 """<p>Qt-Linguist files (i.e. those with a <tt>.ts</tt> file""" |
151 """ menu of these files allows you to start Qt-Linguist with""" |
169 """ name suffix) are shown with a Linguist icon. The context""" |
152 """ that file.</p>""" |
170 """ menu of these files allows you to start Qt-Linguist with""" |
153 )) |
171 """ that file.</p>""", |
154 |
172 ) |
|
173 ) |
|
174 |
155 self.__createPopupMenus() |
175 self.__createPopupMenus() |
156 |
176 |
157 self._init() # perform common initialization tasks |
177 self._init() # perform common initialization tasks |
158 |
178 |
159 self._keyboardSearchString = "" |
179 self._keyboardSearchString = "" |
160 self._keyboardSearchTimer = QElapsedTimer() |
180 self._keyboardSearchTimer = QElapsedTimer() |
161 self._keyboardSearchTimer.invalidate() |
181 self._keyboardSearchTimer.invalidate() |
162 |
182 |
163 def _init(self): |
183 def _init(self): |
164 """ |
184 """ |
165 Protected method to perform initialization tasks common to this |
185 Protected method to perform initialization tasks common to this |
166 base class and all derived classes. |
186 base class and all derived classes. |
167 """ |
187 """ |
168 self.setRootIsDecorated(True) |
188 self.setRootIsDecorated(True) |
169 self.setAlternatingRowColors(True) |
189 self.setAlternatingRowColors(True) |
170 |
190 |
171 header = self.header() |
191 header = self.header() |
172 header.setSortIndicator(0, Qt.SortOrder.AscendingOrder) |
192 header.setSortIndicator(0, Qt.SortOrder.AscendingOrder) |
173 header.setSortIndicatorShown(True) |
193 header.setSortIndicatorShown(True) |
174 header.setSectionsClickable(True) |
194 header.setSectionsClickable(True) |
175 |
195 |
176 self.setSortingEnabled(True) |
196 self.setSortingEnabled(True) |
177 |
197 |
178 self.setSelectionMode( |
198 self.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection) |
179 QAbstractItemView.SelectionMode.ExtendedSelection) |
199 self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) |
180 self.setSelectionBehavior( |
200 |
181 QAbstractItemView.SelectionBehavior.SelectRows) |
|
182 |
|
183 self.header().setStretchLastSection(True) |
201 self.header().setStretchLastSection(True) |
184 self.headerSize0 = 0 |
202 self.headerSize0 = 0 |
185 self.layoutDisplay() |
203 self.layoutDisplay() |
186 |
204 |
187 def layoutDisplay(self): |
205 def layoutDisplay(self): |
188 """ |
206 """ |
189 Public slot to perform a layout operation. |
207 Public slot to perform a layout operation. |
190 """ |
208 """ |
191 self._resizeColumns(QModelIndex()) |
209 self._resizeColumns(QModelIndex()) |
192 self._resort() |
210 self._resort() |
193 |
211 |
194 def _resizeColumns(self, index): |
212 def _resizeColumns(self, index): |
195 """ |
213 """ |
196 Protected slot to resize the view when items get expanded or collapsed. |
214 Protected slot to resize the view when items get expanded or collapsed. |
197 |
215 |
198 @param index index of item (QModelIndex) |
216 @param index index of item (QModelIndex) |
199 """ |
217 """ |
200 w = max(100, self.sizeHintForColumn(0)) |
218 w = max(100, self.sizeHintForColumn(0)) |
201 if w != self.headerSize0: |
219 if w != self.headerSize0: |
202 self.header().resizeSection(0, w) |
220 self.header().resizeSection(0, w) |
203 self.headerSize0 = w |
221 self.headerSize0 = w |
204 |
222 |
205 def _resort(self): |
223 def _resort(self): |
206 """ |
224 """ |
207 Protected slot to resort the tree. |
225 Protected slot to resort the tree. |
208 """ |
226 """ |
209 self.model().sort(self.header().sortIndicatorSection(), |
227 self.model().sort( |
210 self.header().sortIndicatorOrder()) |
228 self.header().sortIndicatorSection(), self.header().sortIndicatorOrder() |
211 |
229 ) |
|
230 |
212 def __createPopupMenus(self): |
231 def __createPopupMenus(self): |
213 """ |
232 """ |
214 Private method to generate the various popup menus. |
233 Private method to generate the various popup menus. |
215 """ |
234 """ |
216 self.showHiddenFilesAct = QAction( |
235 self.showHiddenFilesAct = QAction( |
217 QCoreApplication.translate('Browser', 'Show Hidden Files')) |
236 QCoreApplication.translate("Browser", "Show Hidden Files") |
|
237 ) |
218 self.showHiddenFilesAct.setCheckable(True) |
238 self.showHiddenFilesAct.setCheckable(True) |
219 self.showHiddenFilesAct.toggled.connect(self._showHidden) |
239 self.showHiddenFilesAct.toggled.connect(self._showHidden) |
220 self.showHiddenFilesAct.setChecked( |
240 self.showHiddenFilesAct.setChecked(Preferences.getUI("BrowsersListHiddenFiles")) |
221 Preferences.getUI("BrowsersListHiddenFiles")) |
241 |
222 |
242 self.__newMenu = QMenu(QCoreApplication.translate("Browser", "New"), self) |
223 self.__newMenu = QMenu(QCoreApplication.translate('Browser', "New"), |
|
224 self) |
|
225 self.__newMenu.addAction( |
243 self.__newMenu.addAction( |
226 QCoreApplication.translate('Browser', 'Directory'), |
244 QCoreApplication.translate("Browser", "Directory"), self._newDirectory |
227 self._newDirectory) |
245 ) |
228 self.__newMenu.addAction( |
246 self.__newMenu.addAction( |
229 QCoreApplication.translate('Browser', 'File'), self._newFile) |
247 QCoreApplication.translate("Browser", "File"), self._newFile |
230 |
248 ) |
|
249 |
231 # create the popup menu for source files |
250 # create the popup menu for source files |
232 self.sourceMenu = QMenu(self) |
251 self.sourceMenu = QMenu(self) |
233 self.sourceMenu.addAction( |
252 self.sourceMenu.addAction( |
234 QCoreApplication.translate('Browser', 'Open'), self._openItem) |
253 QCoreApplication.translate("Browser", "Open"), self._openItem |
|
254 ) |
235 self.testingAct = self.sourceMenu.addAction( |
255 self.testingAct = self.sourceMenu.addAction( |
236 QCoreApplication.translate('Browser', 'Run Test...'), |
256 QCoreApplication.translate("Browser", "Run Test..."), self.handleTesting |
237 self.handleTesting) |
257 ) |
238 self.sourceMenu.addSeparator() |
258 self.sourceMenu.addSeparator() |
239 self.mimeTypeAct = self.sourceMenu.addAction( |
259 self.mimeTypeAct = self.sourceMenu.addAction( |
240 QCoreApplication.translate('Browser', 'Show Mime-Type'), |
260 QCoreApplication.translate("Browser", "Show Mime-Type"), self.__showMimeType |
241 self.__showMimeType) |
261 ) |
242 self.sourceMenu.addSeparator() |
262 self.sourceMenu.addSeparator() |
243 self.sourceMenu.addAction( |
263 self.sourceMenu.addAction( |
244 QCoreApplication.translate('Browser', 'Refresh Source File'), |
264 QCoreApplication.translate("Browser", "Refresh Source File"), |
245 self.__refreshSource) |
265 self.__refreshSource, |
|
266 ) |
246 self.sourceMenu.addSeparator() |
267 self.sourceMenu.addSeparator() |
247 self.sourceMenu.addAction( |
268 self.sourceMenu.addAction( |
248 QCoreApplication.translate('Browser', 'Copy Path to Clipboard'), |
269 QCoreApplication.translate("Browser", "Copy Path to Clipboard"), |
249 self._copyToClipboard) |
270 self._copyToClipboard, |
|
271 ) |
250 self.sourceMenu.addSeparator() |
272 self.sourceMenu.addSeparator() |
251 self.sourceMenu.addAction(self.showHiddenFilesAct) |
273 self.sourceMenu.addAction(self.showHiddenFilesAct) |
252 self.sourceMenu.addSeparator() |
274 self.sourceMenu.addSeparator() |
253 self.sourceMenu.addMenu(self.__newMenu) |
275 self.sourceMenu.addMenu(self.__newMenu) |
254 self.sourceMenu.addAction( |
276 self.sourceMenu.addAction( |
255 QCoreApplication.translate('Browser', 'Delete'), |
277 QCoreApplication.translate("Browser", "Delete"), self._deleteFileOrDirectory |
256 self._deleteFileOrDirectory) |
278 ) |
257 |
279 |
258 # create the popup menu for general use |
280 # create the popup menu for general use |
259 self.menu = QMenu(self) |
281 self.menu = QMenu(self) |
260 self.menu.addAction( |
282 self.menu.addAction( |
261 QCoreApplication.translate('Browser', 'Open'), self._openItem) |
283 QCoreApplication.translate("Browser", "Open"), self._openItem |
|
284 ) |
262 self.menu.addAction( |
285 self.menu.addAction( |
263 QCoreApplication.translate('Browser', 'Open in Hex Editor'), |
286 QCoreApplication.translate("Browser", "Open in Hex Editor"), |
264 self._openHexEditor) |
287 self._openHexEditor, |
|
288 ) |
265 self.editPixmapAct = self.menu.addAction( |
289 self.editPixmapAct = self.menu.addAction( |
266 QCoreApplication.translate('Browser', 'Open in Icon Editor'), |
290 QCoreApplication.translate("Browser", "Open in Icon Editor"), |
267 self._editPixmap) |
291 self._editPixmap, |
|
292 ) |
268 self.openInEditorAct = self.menu.addAction( |
293 self.openInEditorAct = self.menu.addAction( |
269 QCoreApplication.translate('Browser', 'Open in Editor'), |
294 QCoreApplication.translate("Browser", "Open in Editor"), |
270 self._openFileInEditor) |
295 self._openFileInEditor, |
|
296 ) |
271 self.menu.addSeparator() |
297 self.menu.addSeparator() |
272 self.mimeTypeAct = self.menu.addAction( |
298 self.mimeTypeAct = self.menu.addAction( |
273 QCoreApplication.translate('Browser', 'Show Mime-Type'), |
299 QCoreApplication.translate("Browser", "Show Mime-Type"), self.__showMimeType |
274 self.__showMimeType) |
300 ) |
275 self.menu.addSeparator() |
301 self.menu.addSeparator() |
276 self.menu.addAction( |
302 self.menu.addAction( |
277 QCoreApplication.translate('Browser', 'Copy Path to Clipboard'), |
303 QCoreApplication.translate("Browser", "Copy Path to Clipboard"), |
278 self._copyToClipboard) |
304 self._copyToClipboard, |
|
305 ) |
279 self.menu.addSeparator() |
306 self.menu.addSeparator() |
280 self.menu.addAction(self.showHiddenFilesAct) |
307 self.menu.addAction(self.showHiddenFilesAct) |
281 self.menu.addSeparator() |
308 self.menu.addSeparator() |
282 self.menu.addMenu(self.__newMenu) |
309 self.menu.addMenu(self.__newMenu) |
283 self.menu.addAction( |
310 self.menu.addAction( |
284 QCoreApplication.translate('Browser', 'Delete'), |
311 QCoreApplication.translate("Browser", "Delete"), self._deleteFileOrDirectory |
285 self._deleteFileOrDirectory) |
312 ) |
286 |
313 |
287 # create the menu for multiple selected files |
314 # create the menu for multiple selected files |
288 self.multiMenu = QMenu(self) |
315 self.multiMenu = QMenu(self) |
289 self.multiMenu.addAction( |
316 self.multiMenu.addAction( |
290 QCoreApplication.translate('Browser', 'Open'), self._openItem) |
317 QCoreApplication.translate("Browser", "Open"), self._openItem |
|
318 ) |
291 self.multiMenu.addSeparator() |
319 self.multiMenu.addSeparator() |
292 self.multiMenu.addAction(self.showHiddenFilesAct) |
320 self.multiMenu.addAction(self.showHiddenFilesAct) |
293 self.multiMenu.addSeparator() |
321 self.multiMenu.addSeparator() |
294 self.multiMenu.addAction( |
322 self.multiMenu.addAction( |
295 QCoreApplication.translate('Browser', 'Delete'), |
323 QCoreApplication.translate("Browser", "Delete"), self.__deleteMultiple |
296 self.__deleteMultiple) |
324 ) |
297 |
325 |
298 # create the directory menu |
326 # create the directory menu |
299 self.dirMenu = QMenu(self) |
327 self.dirMenu = QMenu(self) |
300 self.dirMenu.addAction( |
328 self.dirMenu.addAction( |
301 QCoreApplication.translate('Browser', 'New toplevel directory...'), |
329 QCoreApplication.translate("Browser", "New toplevel directory..."), |
302 self.__newToplevelDir) |
330 self.__newToplevelDir, |
|
331 ) |
303 self.addAsTopLevelAct = self.dirMenu.addAction( |
332 self.addAsTopLevelAct = self.dirMenu.addAction( |
304 QCoreApplication.translate('Browser', 'Add as toplevel directory'), |
333 QCoreApplication.translate("Browser", "Add as toplevel directory"), |
305 self.__addAsToplevelDir) |
334 self.__addAsToplevelDir, |
|
335 ) |
306 self.removeFromToplevelAct = self.dirMenu.addAction( |
336 self.removeFromToplevelAct = self.dirMenu.addAction( |
307 QCoreApplication.translate('Browser', 'Remove from toplevel'), |
337 QCoreApplication.translate("Browser", "Remove from toplevel"), |
308 self.__removeToplevel) |
338 self.__removeToplevel, |
|
339 ) |
309 self.dirMenu.addSeparator() |
340 self.dirMenu.addSeparator() |
310 self.dirMenu.addAction( |
341 self.dirMenu.addAction( |
311 QCoreApplication.translate('Browser', 'Refresh directory'), |
342 QCoreApplication.translate("Browser", "Refresh directory"), |
312 self.__refreshDirectory) |
343 self.__refreshDirectory, |
|
344 ) |
313 self.dirMenu.addSeparator() |
345 self.dirMenu.addSeparator() |
314 self.dirMenu.addAction( |
346 self.dirMenu.addAction( |
315 QCoreApplication.translate('Browser', 'Find in this directory'), |
347 QCoreApplication.translate("Browser", "Find in this directory"), |
316 self.__findInDirectory) |
348 self.__findInDirectory, |
|
349 ) |
317 self.dirMenu.addAction( |
350 self.dirMenu.addAction( |
318 QCoreApplication.translate( |
351 QCoreApplication.translate("Browser", "Find && Replace in this directory"), |
319 'Browser', 'Find && Replace in this directory'), |
352 self.__replaceInDirectory, |
320 self.__replaceInDirectory) |
353 ) |
321 self.dirMenu.addAction( |
354 self.dirMenu.addAction( |
322 QCoreApplication.translate('Browser', 'Copy Path to Clipboard'), |
355 QCoreApplication.translate("Browser", "Copy Path to Clipboard"), |
323 self._copyToClipboard) |
356 self._copyToClipboard, |
|
357 ) |
324 self.dirMenu.addSeparator() |
358 self.dirMenu.addSeparator() |
325 self.dirMenu.addAction(self.showHiddenFilesAct) |
359 self.dirMenu.addAction(self.showHiddenFilesAct) |
326 self.dirMenu.addSeparator() |
360 self.dirMenu.addSeparator() |
327 self.dirMenu.addMenu(self.__newMenu) |
361 self.dirMenu.addMenu(self.__newMenu) |
328 self.dirMenu.addAction( |
362 self.dirMenu.addAction( |
329 QCoreApplication.translate('Browser', 'Delete'), |
363 QCoreApplication.translate("Browser", "Delete"), self._deleteFileOrDirectory |
330 self._deleteFileOrDirectory) |
364 ) |
331 |
365 |
332 # create the attribute menu |
366 # create the attribute menu |
333 self.gotoMenu = QMenu(QCoreApplication.translate('Browser', "Goto"), |
367 self.gotoMenu = QMenu(QCoreApplication.translate("Browser", "Goto"), self) |
334 self) |
|
335 self.gotoMenu.aboutToShow.connect(self._showGotoMenu) |
368 self.gotoMenu.aboutToShow.connect(self._showGotoMenu) |
336 self.gotoMenu.triggered.connect(self._gotoAttribute) |
369 self.gotoMenu.triggered.connect(self._gotoAttribute) |
337 |
370 |
338 self.attributeMenu = QMenu(self) |
371 self.attributeMenu = QMenu(self) |
339 self.attributeMenu.addAction( |
372 self.attributeMenu.addAction( |
340 QCoreApplication.translate('Browser', 'New toplevel directory...'), |
373 QCoreApplication.translate("Browser", "New toplevel directory..."), |
341 self.__newToplevelDir) |
374 self.__newToplevelDir, |
|
375 ) |
342 self.attributeMenu.addSeparator() |
376 self.attributeMenu.addSeparator() |
343 self.attributeMenu.addMenu(self.gotoMenu) |
377 self.attributeMenu.addMenu(self.gotoMenu) |
344 |
378 |
345 # create the background menu |
379 # create the background menu |
346 self.backMenu = QMenu(self) |
380 self.backMenu = QMenu(self) |
347 self.backMenu.addAction( |
381 self.backMenu.addAction( |
348 QCoreApplication.translate('Browser', 'New toplevel directory...'), |
382 QCoreApplication.translate("Browser", "New toplevel directory..."), |
349 self.__newToplevelDir) |
383 self.__newToplevelDir, |
|
384 ) |
350 self.backMenu.addSeparator() |
385 self.backMenu.addSeparator() |
351 self.backMenu.addAction(self.showHiddenFilesAct) |
386 self.backMenu.addAction(self.showHiddenFilesAct) |
352 |
387 |
353 def mouseDoubleClickEvent(self, mouseEvent): |
388 def mouseDoubleClickEvent(self, mouseEvent): |
354 """ |
389 """ |
355 Protected method of QAbstractItemView. |
390 Protected method of QAbstractItemView. |
356 |
391 |
357 Reimplemented to disable expanding/collapsing of items when |
392 Reimplemented to disable expanding/collapsing of items when |
358 double-clicking. Instead the double-clicked entry is opened. |
393 double-clicking. Instead the double-clicked entry is opened. |
359 |
394 |
360 @param mouseEvent the mouse event (QMouseEvent) |
395 @param mouseEvent the mouse event (QMouseEvent) |
361 """ |
396 """ |
362 index = self.indexAt(mouseEvent.position().toPoint()) |
397 index = self.indexAt(mouseEvent.position().toPoint()) |
363 if index.isValid(): |
398 if index.isValid(): |
364 itm = self.model().item(index) |
399 itm = self.model().item(index) |
365 if isinstance(itm, ( |
400 if isinstance( |
366 BrowserDirectoryItem, BrowserImportsItem, |
401 itm, |
367 ProjectBrowserSimpleDirectoryItem, BrowserSysPathItem, |
402 ( |
368 BrowserGlobalsItem)): |
403 BrowserDirectoryItem, |
|
404 BrowserImportsItem, |
|
405 ProjectBrowserSimpleDirectoryItem, |
|
406 BrowserSysPathItem, |
|
407 BrowserGlobalsItem, |
|
408 ), |
|
409 ): |
369 self.setExpanded(index, not self.isExpanded(index)) |
410 self.setExpanded(index, not self.isExpanded(index)) |
370 else: |
411 else: |
371 self._openItem() |
412 self._openItem() |
372 |
413 |
373 def _contextMenuRequested(self, coord): |
414 def _contextMenuRequested(self, coord): |
374 """ |
415 """ |
375 Protected slot to show the context menu of the listview. |
416 Protected slot to show the context menu of the listview. |
376 |
417 |
377 @param coord the position of the mouse pointer (QPoint) |
418 @param coord the position of the mouse pointer (QPoint) |
378 """ |
419 """ |
379 categories = self.getSelectedItemsCountCategorized( |
420 categories = self.getSelectedItemsCountCategorized( |
380 [BrowserDirectoryItem, BrowserFileItem, |
421 [BrowserDirectoryItem, BrowserFileItem, BrowserClassItem, BrowserMethodItem] |
381 BrowserClassItem, BrowserMethodItem]) |
422 ) |
382 cnt = categories["sum"] |
423 cnt = categories["sum"] |
383 bfcnt = categories[str(BrowserFileItem)] |
424 bfcnt = categories[str(BrowserFileItem)] |
384 if cnt > 1 and cnt == bfcnt: |
425 if cnt > 1 and cnt == bfcnt: |
385 self.multiMenu.popup(self.mapToGlobal(coord)) |
426 self.multiMenu.popup(self.mapToGlobal(coord)) |
386 else: |
427 else: |
387 index = self.indexAt(coord) |
428 index = self.indexAt(coord) |
388 |
429 |
389 if index.isValid(): |
430 if index.isValid(): |
390 self.setCurrentIndex(index) |
431 self.setCurrentIndex(index) |
391 flags = ( |
432 flags = ( |
392 QItemSelectionModel.SelectionFlag.ClearAndSelect | |
433 QItemSelectionModel.SelectionFlag.ClearAndSelect |
393 QItemSelectionModel.SelectionFlag.Rows |
434 | QItemSelectionModel.SelectionFlag.Rows |
394 ) |
435 ) |
395 self.selectionModel().select(index, flags) |
436 self.selectionModel().select(index, flags) |
396 |
437 |
397 itm = self.model().item(index) |
438 itm = self.model().item(index) |
398 coord = self.mapToGlobal(coord) |
439 coord = self.mapToGlobal(coord) |
399 if isinstance(itm, BrowserFileItem): |
440 if isinstance(itm, BrowserFileItem): |
400 if itm.isPython3File(): |
441 if itm.isPython3File(): |
401 if itm.fileName().endswith('.py'): |
442 if itm.fileName().endswith(".py"): |
402 self.testingAct.setEnabled(True) |
443 self.testingAct.setEnabled(True) |
403 else: |
444 else: |
404 self.testingAct.setEnabled(False) |
445 self.testingAct.setEnabled(False) |
405 self.sourceMenu.popup(coord) |
446 self.sourceMenu.popup(coord) |
406 else: |
447 else: |
407 self.editPixmapAct.setVisible(itm.isPixmapFile()) |
448 self.editPixmapAct.setVisible(itm.isPixmapFile()) |
408 self.openInEditorAct.setVisible(itm.isSvgFile()) |
449 self.openInEditorAct.setVisible(itm.isSvgFile()) |
409 self.menu.popup(coord) |
450 self.menu.popup(coord) |
410 elif isinstance( |
451 elif isinstance( |
411 itm, |
452 itm, (BrowserClassItem, BrowserMethodItem, BrowserImportItem) |
412 (BrowserClassItem, BrowserMethodItem, BrowserImportItem) |
|
413 ): |
453 ): |
414 self.editPixmapAct.setVisible(False) |
454 self.editPixmapAct.setVisible(False) |
415 self.menu.popup(coord) |
455 self.menu.popup(coord) |
416 elif isinstance(itm, BrowserClassAttributeItem): |
456 elif isinstance(itm, BrowserClassAttributeItem): |
417 self.attributeMenu.popup(coord) |
457 self.attributeMenu.popup(coord) |
508 self.sourceFile[str].emit(itm.fileName()) |
551 self.sourceFile[str].emit(itm.fileName()) |
509 else: |
552 else: |
510 QDesktopServices.openUrl(QUrl(itm.fileName())) |
553 QDesktopServices.openUrl(QUrl(itm.fileName())) |
511 elif isinstance(itm, BrowserClassItem): |
554 elif isinstance(itm, BrowserClassItem): |
512 self.sourceFile[str, int].emit( |
555 self.sourceFile[str, int].emit( |
513 itm.fileName(), itm.classObject().lineno) |
556 itm.fileName(), itm.classObject().lineno |
|
557 ) |
514 elif isinstance(itm, BrowserMethodItem): |
558 elif isinstance(itm, BrowserMethodItem): |
515 self.sourceFile[str, int].emit( |
559 self.sourceFile[str, int].emit( |
516 itm.fileName(), itm.functionObject().lineno) |
560 itm.fileName(), itm.functionObject().lineno |
|
561 ) |
517 elif isinstance(itm, BrowserClassAttributeItem): |
562 elif isinstance(itm, BrowserClassAttributeItem): |
518 self.sourceFile[str, int].emit( |
563 self.sourceFile[str, int].emit( |
519 itm.fileName(), itm.attributeObject().lineno) |
564 itm.fileName(), itm.attributeObject().lineno |
|
565 ) |
520 elif isinstance(itm, BrowserImportItem): |
566 elif isinstance(itm, BrowserImportItem): |
521 self.sourceFile[str, list].emit( |
567 self.sourceFile[str, list].emit(itm.fileName(), itm.linenos()) |
522 itm.fileName(), itm.linenos()) |
|
523 self._activating = False |
568 self._activating = False |
524 |
569 |
525 def __showMimeType(self): |
570 def __showMimeType(self): |
526 """ |
571 """ |
527 Private slot to show the mime type of the selected entry. |
572 Private slot to show the mime type of the selected entry. |
528 """ |
573 """ |
529 itmList = self.getSelectedItems( |
574 itmList = self.getSelectedItems( |
530 [BrowserFileItem, BrowserClassItem, |
575 [ |
531 BrowserMethodItem, BrowserClassAttributeItem, |
576 BrowserFileItem, |
532 BrowserImportItem]) |
577 BrowserClassItem, |
|
578 BrowserMethodItem, |
|
579 BrowserClassAttributeItem, |
|
580 BrowserImportItem, |
|
581 ] |
|
582 ) |
533 if itmList: |
583 if itmList: |
534 mimetype = Utilities.MimeTypes.mimeType(itmList[0].fileName()) |
584 mimetype = Utilities.MimeTypes.mimeType(itmList[0].fileName()) |
535 if mimetype is None: |
585 if mimetype is None: |
536 EricMessageBox.warning( |
586 EricMessageBox.warning( |
537 self, |
587 self, |
538 QCoreApplication.translate('Browser', "Show Mime-Type"), |
588 QCoreApplication.translate("Browser", "Show Mime-Type"), |
539 QCoreApplication.translate( |
589 QCoreApplication.translate( |
540 'Browser', |
590 "Browser", |
541 """The mime type of the file could not be""" |
591 """The mime type of the file could not be""" """ determined.""", |
542 """ determined.""")) |
592 ), |
|
593 ) |
543 elif mimetype.split("/")[0] == "text": |
594 elif mimetype.split("/")[0] == "text": |
544 EricMessageBox.information( |
595 EricMessageBox.information( |
545 self, |
596 self, |
546 QCoreApplication.translate('Browser', "Show Mime-Type"), |
597 QCoreApplication.translate("Browser", "Show Mime-Type"), |
547 QCoreApplication.translate( |
598 QCoreApplication.translate( |
548 'Browser', |
599 "Browser", """The file has the mime type <b>{0}</b>.""" |
549 """The file has the mime type <b>{0}</b>.""") |
600 ).format(mimetype), |
550 .format(mimetype)) |
601 ) |
551 else: |
602 else: |
552 textMimeTypesList = Preferences.getUI("TextMimeTypes") |
603 textMimeTypesList = Preferences.getUI("TextMimeTypes") |
553 if mimetype in textMimeTypesList: |
604 if mimetype in textMimeTypesList: |
554 EricMessageBox.information( |
605 EricMessageBox.information( |
555 self, |
606 self, |
|
607 QCoreApplication.translate("Browser", "Show Mime-Type"), |
556 QCoreApplication.translate( |
608 QCoreApplication.translate( |
557 'Browser', "Show Mime-Type"), |
609 "Browser", """The file has the mime type <b>{0}</b>.""" |
558 QCoreApplication.translate( |
610 ).format(mimetype), |
559 'Browser', |
611 ) |
560 """The file has the mime type <b>{0}</b>.""") |
|
561 .format(mimetype)) |
|
562 else: |
612 else: |
563 ok = EricMessageBox.yesNo( |
613 ok = EricMessageBox.yesNo( |
564 self, |
614 self, |
|
615 QCoreApplication.translate("Browser", "Show Mime-Type"), |
565 QCoreApplication.translate( |
616 QCoreApplication.translate( |
566 'Browser', "Show Mime-Type"), |
617 "Browser", |
567 QCoreApplication.translate( |
|
568 'Browser', |
|
569 """The file has the mime type <b>{0}</b>.""" |
618 """The file has the mime type <b>{0}</b>.""" |
570 """<br/> Shall it be added to the list of""" |
619 """<br/> Shall it be added to the list of""" |
571 """ text mime types?""").format(mimetype)) |
620 """ text mime types?""", |
|
621 ).format(mimetype), |
|
622 ) |
572 if ok: |
623 if ok: |
573 textMimeTypesList.append(mimetype) |
624 textMimeTypesList.append(mimetype) |
574 Preferences.setUI("TextMimeTypes", textMimeTypesList) |
625 Preferences.setUI("TextMimeTypes", textMimeTypesList) |
575 |
626 |
576 def __refreshSource(self): |
627 def __refreshSource(self): |
577 """ |
628 """ |
578 Private slot to refresh the structure of a source file. |
629 Private slot to refresh the structure of a source file. |
579 """ |
630 """ |
580 itmList = self.getSelectedItems([BrowserFileItem]) |
631 itmList = self.getSelectedItems([BrowserFileItem]) |
581 if itmList: |
632 if itmList: |
582 self.__model.repopulateFileItem(itmList[0]) |
633 self.__model.repopulateFileItem(itmList[0]) |
583 |
634 |
584 def _editPixmap(self): |
635 def _editPixmap(self): |
585 """ |
636 """ |
586 Protected slot to handle the open in icon editor popup menu entry. |
637 Protected slot to handle the open in icon editor popup menu entry. |
587 """ |
638 """ |
588 itmList = self.getSelectedItems([BrowserFileItem]) |
639 itmList = self.getSelectedItems([BrowserFileItem]) |
589 |
640 |
590 for itm in itmList: |
641 for itm in itmList: |
591 if isinstance(itm, BrowserFileItem) and itm.isPixmapFile(): |
642 if isinstance(itm, BrowserFileItem) and itm.isPixmapFile(): |
592 self.pixmapEditFile.emit(itm.fileName()) |
643 self.pixmapEditFile.emit(itm.fileName()) |
593 |
644 |
594 def _openHexEditor(self): |
645 def _openHexEditor(self): |
595 """ |
646 """ |
596 Protected slot to handle the open in hex editor popup menu entry. |
647 Protected slot to handle the open in hex editor popup menu entry. |
597 """ |
648 """ |
598 itmList = self.getSelectedItems([BrowserFileItem]) |
649 itmList = self.getSelectedItems([BrowserFileItem]) |
599 |
650 |
600 for itm in itmList: |
651 for itm in itmList: |
601 if isinstance(itm, BrowserFileItem): |
652 if isinstance(itm, BrowserFileItem): |
602 self.binaryFile.emit(itm.fileName()) |
653 self.binaryFile.emit(itm.fileName()) |
603 |
654 |
604 def _openFileInEditor(self): |
655 def _openFileInEditor(self): |
605 """ |
656 """ |
606 Protected slot to handle the Open in Editor menu action. |
657 Protected slot to handle the Open in Editor menu action. |
607 """ |
658 """ |
608 itmList = self.getSelectedItems([BrowserFileItem]) |
659 itmList = self.getSelectedItems([BrowserFileItem]) |
609 |
660 |
610 for itm in itmList: |
661 for itm in itmList: |
611 if Utilities.MimeTypes.isTextFile(itm.fileName()): |
662 if Utilities.MimeTypes.isTextFile(itm.fileName()): |
612 self.sourceFile.emit(itm.fileName()) |
663 self.sourceFile.emit(itm.fileName()) |
613 |
664 |
614 def _copyToClipboard(self): |
665 def _copyToClipboard(self): |
615 """ |
666 """ |
616 Protected method to copy the text shown for an entry to the clipboard. |
667 Protected method to copy the text shown for an entry to the clipboard. |
617 """ |
668 """ |
618 itm = self.model().item(self.currentIndex()) |
669 itm = self.model().item(self.currentIndex()) |