9412:45e7bb09c120 | 9413:80c06d472826 |
---|---|
29 QToolButton, | 29 QToolButton, |
30 QMenu, | 30 QMenu, |
31 QLabel, | 31 QLabel, |
32 ) | 32 ) |
33 | 33 |
34 from EricWidgets.EricApplication import ericApp | 34 from eric7.EricWidgets.EricApplication import ericApp |
35 | 35 |
36 from ViewManager.ViewManager import ViewManager | 36 from eric7.ViewManager.ViewManager import ViewManager |
37 | 37 |
38 import QScintilla.Editor | 38 from eric7.QScintilla.Editor import Editor |
39 from QScintilla.Editor import Editor | 39 from eric7.QScintilla.EditorAssembly import EditorAssembly |
40 from QScintilla.EditorAssembly import EditorAssembly | 40 |
41 | 41 from eric7.EricGui import EricPixmapCache |
42 import UI.PixmapCache | 42 |
43 | 43 from eric7.EricWidgets.EricTabWidget import EricTabWidget, EricWheelTabBar |
44 from EricWidgets.EricTabWidget import EricTabWidget, EricWheelTabBar | 44 from eric7.EricWidgets.EricLed import EricLed |
45 from EricWidgets.EricLed import EricLed | 45 |
46 | 46 from eric7 import Preferences |
47 import Preferences | 47 from eric7.Globals import isMacPlatform |
48 from Globals import isMacPlatform | |
49 | 48 |
50 from eric7config import getConfig | 49 from eric7config import getConfig |
51 | 50 |
52 | 51 |
53 class TabBar(EricWheelTabBar): | 52 class TabBar(EricWheelTabBar): |
218 self.__navigationMenu = QMenu(self) | 217 self.__navigationMenu = QMenu(self) |
219 self.__navigationMenu.aboutToShow.connect(self.__showNavigationMenu) | 218 self.__navigationMenu.aboutToShow.connect(self.__showNavigationMenu) |
220 self.__navigationMenu.triggered.connect(self.__navigationMenuTriggered) | 219 self.__navigationMenu.triggered.connect(self.__navigationMenuTriggered) |
221 | 220 |
222 self.navigationButton = QToolButton(self) | 221 self.navigationButton = QToolButton(self) |
223 self.navigationButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) | 222 self.navigationButton.setIcon(EricPixmapCache.getIcon("1downarrow")) |
224 self.navigationButton.setToolTip(self.tr("Show a navigation menu")) | 223 self.navigationButton.setToolTip(self.tr("Show a navigation menu")) |
225 self.navigationButton.setPopupMode(QToolButton.ToolButtonPopupMode.InstantPopup) | 224 self.navigationButton.setPopupMode(QToolButton.ToolButtonPopupMode.InstantPopup) |
226 self.navigationButton.setMenu(self.__navigationMenu) | 225 self.navigationButton.setMenu(self.__navigationMenu) |
227 self.navigationButton.setEnabled(False) | 226 self.navigationButton.setEnabled(False) |
228 self.rightCornerWidgetLayout.addWidget(self.navigationButton) | 227 self.rightCornerWidgetLayout.addWidget(self.navigationButton) |
242 self.emptyLabel = QLabel() | 241 self.emptyLabel = QLabel() |
243 self.emptyLabel.setPixmap(ericPic) | 242 self.emptyLabel.setPixmap(ericPic) |
244 self.emptyLabel.setAlignment( | 243 self.emptyLabel.setAlignment( |
245 Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignHCenter | 244 Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignHCenter |
246 ) | 245 ) |
247 super().addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty"), "") | 246 super().addTab(self.emptyLabel, EricPixmapCache.getIcon("empty"), "") |
248 | 247 |
249 def __initMenu(self): | 248 def __initMenu(self): |
250 """ | 249 """ |
251 Private method to initialize the tab context menu. | 250 Private method to initialize the tab context menu. |
252 """ | 251 """ |
253 self.__startMenu = QMenu(self.tr("Start"), self) | 252 self.__startMenu = QMenu(self.tr("Start"), self) |
254 self.__startMenu.addAction( | 253 self.__startMenu.addAction( |
255 UI.PixmapCache.getIcon("runScript"), | 254 EricPixmapCache.getIcon("runScript"), |
256 self.tr("Run Script..."), | 255 self.tr("Run Script..."), |
257 self.__contextMenuRunScript, | 256 self.__contextMenuRunScript, |
258 ) | 257 ) |
259 self.__startMenu.addAction( | 258 self.__startMenu.addAction( |
260 UI.PixmapCache.getIcon("debugScript"), | 259 EricPixmapCache.getIcon("debugScript"), |
261 self.tr("Debug Script..."), | 260 self.tr("Debug Script..."), |
262 self.__contextMenuDebugScript, | 261 self.__contextMenuDebugScript, |
263 ) | 262 ) |
264 self.__startMenu.addAction( | 263 self.__startMenu.addAction( |
265 UI.PixmapCache.getIcon("profileScript"), | 264 EricPixmapCache.getIcon("profileScript"), |
266 self.tr("Profile Script..."), | 265 self.tr("Profile Script..."), |
267 self.__contextMenuProfileScript, | 266 self.__contextMenuProfileScript, |
268 ) | 267 ) |
269 self.__startMenu.addAction( | 268 self.__startMenu.addAction( |
270 UI.PixmapCache.getIcon("coverageScript"), | 269 EricPixmapCache.getIcon("coverageScript"), |
271 self.tr("Coverage run of Script..."), | 270 self.tr("Coverage run of Script..."), |
272 self.__contextMenuCoverageScript, | 271 self.__contextMenuCoverageScript, |
273 ) | 272 ) |
274 | 273 |
275 self.__menu = QMenu(self) | 274 self.__menu = QMenu(self) |
276 self.leftMenuAct = self.__menu.addAction( | 275 self.leftMenuAct = self.__menu.addAction( |
277 UI.PixmapCache.getIcon("1leftarrow"), | 276 EricPixmapCache.getIcon("1leftarrow"), |
278 self.tr("Move Left"), | 277 self.tr("Move Left"), |
279 self.__contextMenuMoveLeft, | 278 self.__contextMenuMoveLeft, |
280 ) | 279 ) |
281 self.rightMenuAct = self.__menu.addAction( | 280 self.rightMenuAct = self.__menu.addAction( |
282 UI.PixmapCache.getIcon("1rightarrow"), | 281 EricPixmapCache.getIcon("1rightarrow"), |
283 self.tr("Move Right"), | 282 self.tr("Move Right"), |
284 self.__contextMenuMoveRight, | 283 self.__contextMenuMoveRight, |
285 ) | 284 ) |
286 self.firstMenuAct = self.__menu.addAction( | 285 self.firstMenuAct = self.__menu.addAction( |
287 UI.PixmapCache.getIcon("2leftarrow"), | 286 EricPixmapCache.getIcon("2leftarrow"), |
288 self.tr("Move First"), | 287 self.tr("Move First"), |
289 self.__contextMenuMoveFirst, | 288 self.__contextMenuMoveFirst, |
290 ) | 289 ) |
291 self.lastMenuAct = self.__menu.addAction( | 290 self.lastMenuAct = self.__menu.addAction( |
292 UI.PixmapCache.getIcon("2rightarrow"), | 291 EricPixmapCache.getIcon("2rightarrow"), |
293 self.tr("Move Last"), | 292 self.tr("Move Last"), |
294 self.__contextMenuMoveLast, | 293 self.__contextMenuMoveLast, |
295 ) | 294 ) |
296 self.__menu.addSeparator() | 295 self.__menu.addSeparator() |
297 self.__menu.addAction( | 296 self.__menu.addAction( |
298 UI.PixmapCache.getIcon("tabClose"), | 297 EricPixmapCache.getIcon("tabClose"), |
299 self.tr("Close"), | 298 self.tr("Close"), |
300 self.__contextMenuClose, | 299 self.__contextMenuClose, |
301 ) | 300 ) |
302 self.closeOthersMenuAct = self.__menu.addAction( | 301 self.closeOthersMenuAct = self.__menu.addAction( |
303 UI.PixmapCache.getIcon("tabCloseOther"), | 302 EricPixmapCache.getIcon("tabCloseOther"), |
304 self.tr("Close Others"), | 303 self.tr("Close Others"), |
305 self.__contextMenuCloseOthers, | 304 self.__contextMenuCloseOthers, |
306 ) | 305 ) |
307 self.__menu.addAction(self.tr("Close All"), self.__contextMenuCloseAll) | 306 self.__menu.addAction(self.tr("Close All"), self.__contextMenuCloseAll) |
308 self.__menu.addSeparator() | 307 self.__menu.addSeparator() |
309 self.saveMenuAct = self.__menu.addAction( | 308 self.saveMenuAct = self.__menu.addAction( |
310 UI.PixmapCache.getIcon("fileSave"), self.tr("Save"), self.__contextMenuSave | 309 EricPixmapCache.getIcon("fileSave"), self.tr("Save"), self.__contextMenuSave |
311 ) | 310 ) |
312 self.__menu.addAction( | 311 self.__menu.addAction( |
313 UI.PixmapCache.getIcon("fileSaveAs"), | 312 EricPixmapCache.getIcon("fileSaveAs"), |
314 self.tr("Save As..."), | 313 self.tr("Save As..."), |
315 self.__contextMenuSaveAs, | 314 self.__contextMenuSaveAs, |
316 ) | 315 ) |
317 self.__menu.addAction( | 316 self.__menu.addAction( |
318 UI.PixmapCache.getIcon("fileSaveAll"), | 317 EricPixmapCache.getIcon("fileSaveAll"), |
319 self.tr("Save All"), | 318 self.tr("Save All"), |
320 self.__contextMenuSaveAll, | 319 self.__contextMenuSaveAll, |
321 ) | 320 ) |
322 self.__menu.addSeparator() | 321 self.__menu.addSeparator() |
323 self.openRejectionsMenuAct = self.__menu.addAction( | 322 self.openRejectionsMenuAct = self.__menu.addAction( |
325 ) | 324 ) |
326 self.__menu.addSeparator() | 325 self.__menu.addSeparator() |
327 self.__startAct = self.__menu.addMenu(self.__startMenu) | 326 self.__startAct = self.__menu.addMenu(self.__startMenu) |
328 self.__menu.addSeparator() | 327 self.__menu.addSeparator() |
329 self.__menu.addAction( | 328 self.__menu.addAction( |
330 UI.PixmapCache.getIcon("printPreview"), | 329 EricPixmapCache.getIcon("printPreview"), |
331 self.tr("Print Preview"), | 330 self.tr("Print Preview"), |
332 self.__contextMenuPrintPreviewFile, | 331 self.__contextMenuPrintPreviewFile, |
333 ) | 332 ) |
334 self.__menu.addAction( | 333 self.__menu.addAction( |
335 UI.PixmapCache.getIcon("print"), | 334 EricPixmapCache.getIcon("print"), |
336 self.tr("Print"), | 335 self.tr("Print"), |
337 self.__contextMenuPrintFile, | 336 self.__contextMenuPrintFile, |
338 ) | 337 ) |
339 self.__menu.addSeparator() | 338 self.__menu.addSeparator() |
340 self.copyPathAct = self.__menu.addAction( | 339 self.copyPathAct = self.__menu.addAction( |
424 @type QScintilla.EditorAssembly.EditorAssembly | 423 @type QScintilla.EditorAssembly.EditorAssembly |
425 @param title title for the new tab | 424 @param title title for the new tab |
426 @type str | 425 @type str |
427 """ | 426 """ |
428 editor = assembly.getEditor() | 427 editor = assembly.getEditor() |
429 super().addTab(assembly, UI.PixmapCache.getIcon("empty"), title) | 428 super().addTab(assembly, EricPixmapCache.getIcon("empty"), title) |
430 self.setTabsClosable(True) | 429 self.setTabsClosable(True) |
431 self.navigationButton.setEnabled(True) | 430 self.navigationButton.setEnabled(True) |
432 | 431 |
433 if editor not in self.editors: | 432 if editor not in self.editors: |
434 self.editors.append(editor) | 433 self.editors.append(editor) |
454 @return index of the inserted tab | 453 @return index of the inserted tab |
455 @rtype int | 454 @rtype int |
456 """ | 455 """ |
457 editor = assembly.getEditor() | 456 editor = assembly.getEditor() |
458 newIndex = super().insertTab( | 457 newIndex = super().insertTab( |
459 index, assembly, UI.PixmapCache.getIcon("empty"), title | 458 index, assembly, EricPixmapCache.getIcon("empty"), title |
460 ) | 459 ) |
461 self.setTabsClosable(True) | 460 self.setTabsClosable(True) |
462 self.navigationButton.setEnabled(True) | 461 self.navigationButton.setEnabled(True) |
463 | 462 |
464 if editor not in self.editors: | 463 if editor not in self.editors: |
511 @param lineno line number of the editor's cursor (zero based) | 510 @param lineno line number of the editor's cursor (zero based) |
512 @type int | 511 @type int |
513 @param editor reference to the editor | 512 @param editor reference to the editor |
514 @type Editor | 513 @type Editor |
515 """ | 514 """ |
516 if editor and isinstance(editor, QScintilla.Editor.Editor): | 515 if editor and isinstance(editor, Editor): |
517 fn = editor.getFileName() | 516 fn = editor.getFileName() |
518 if fn: | 517 if fn: |
519 self.vm.editorLineChanged.emit(fn, lineno + 1) | 518 self.vm.editorLineChanged.emit(fn, lineno + 1) |
520 self.vm.editorLineChangedEd.emit(editor, lineno + 1) | 519 self.vm.editorLineChangedEd.emit(editor, lineno + 1) |
521 | 520 |
524 Public method to remove a widget. | 523 Public method to remove a widget. |
525 | 524 |
526 @param widget widget to be removed | 525 @param widget widget to be removed |
527 @type QWidget | 526 @type QWidget |
528 """ | 527 """ |
529 if isinstance(widget, QScintilla.Editor.Editor): | 528 if isinstance(widget, Editor): |
530 widget.cursorLineChanged.disconnect() | 529 widget.cursorLineChanged.disconnect() |
531 widget.captionChanged.disconnect() | 530 widget.captionChanged.disconnect() |
532 self.editors.remove(widget) | 531 self.editors.remove(widget) |
533 index = self.indexOf(widget.parent()) | 532 index = self.indexOf(widget.parent()) |
534 else: | 533 else: |
535 index = self.indexOf(widget) | 534 index = self.indexOf(widget) |
536 if index > -1: | 535 if index > -1: |
537 self.removeTab(index) | 536 self.removeTab(index) |
538 | 537 |
539 if not self.editors: | 538 if not self.editors: |
540 super().addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty"), "") | 539 super().addTab(self.emptyLabel, EricPixmapCache.getIcon("empty"), "") |
541 self.emptyLabel.show() | 540 self.emptyLabel.show() |
542 self.setTabsClosable(False) | 541 self.setTabsClosable(False) |
543 self.navigationButton.setEnabled(False) | 542 self.navigationButton.setEnabled(False) |
544 | 543 |
545 def __relocateTab(self, sourceId, sourceIndex, targetIndex): | 544 def __relocateTab(self, sourceId, sourceIndex, targetIndex): |
640 @param widget widget to get the index for | 639 @param widget widget to get the index for |
641 @type QLabel or Editor | 640 @type QLabel or Editor |
642 @return tab index of the editor | 641 @return tab index of the editor |
643 @rtype int | 642 @rtype int |
644 """ | 643 """ |
645 if isinstance(widget, QScintilla.Editor.Editor): | 644 if isinstance(widget, Editor): |
646 widget = widget.parent() | 645 widget = widget.parent() |
647 return super().indexOf(widget) | 646 return super().indexOf(widget) |
648 | 647 |
649 def hasEditor(self, editor): | 648 def hasEditor(self, editor): |
650 """ | 649 """ |
1222 keys.append("syntaxError22") | 1221 keys.append("syntaxError22") |
1223 elif editor.hasWarnings(): | 1222 elif editor.hasWarnings(): |
1224 keys.append("warning22") | 1223 keys.append("warning22") |
1225 if not keys: | 1224 if not keys: |
1226 keys.append("empty") | 1225 keys.append("empty") |
1227 tw.setTabIcon(index, UI.PixmapCache.getCombinedIcon(keys)) | 1226 tw.setTabIcon(index, EricPixmapCache.getCombinedIcon(keys)) |
1228 self._checkActions(editor) | 1227 self._checkActions(editor) |
1229 | 1228 |
1230 def _syntaxErrorToggled(self, editor): | 1229 def _syntaxErrorToggled(self, editor): |
1231 """ | 1230 """ |
1232 Protected slot to handle the syntaxerrorToggled signal. | 1231 Protected slot to handle the syntaxerrorToggled signal. |
1245 keys.append("syntaxError22") | 1244 keys.append("syntaxError22") |
1246 elif editor.hasWarnings(): | 1245 elif editor.hasWarnings(): |
1247 keys.append("warning22") | 1246 keys.append("warning22") |
1248 if not keys: | 1247 if not keys: |
1249 keys.append("empty") | 1248 keys.append("empty") |
1250 tw.setTabIcon(index, UI.PixmapCache.getCombinedIcon(keys)) | 1249 tw.setTabIcon(index, EricPixmapCache.getCombinedIcon(keys)) |
1251 | 1250 |
1252 ViewManager._syntaxErrorToggled(self, editor) | 1251 ViewManager._syntaxErrorToggled(self, editor) |
1253 | 1252 |
1254 def addSplit(self): | 1253 def addSplit(self): |
1255 """ | 1254 """ |
1458 if switched: | 1457 if switched: |
1459 index = self.currentTabWidget.selectTab(event.position().toPoint()) | 1458 index = self.currentTabWidget.selectTab(event.position().toPoint()) |
1460 switched = ( | 1459 switched = ( |
1461 self.currentTabWidget.widget(index) is self.activeWindow() | 1460 self.currentTabWidget.widget(index) is self.activeWindow() |
1462 ) | 1461 ) |
1463 elif isinstance(watched, QScintilla.Editor.Editor): | 1462 elif isinstance(watched, Editor): |
1464 for tw in self.tabWidgets: | 1463 for tw in self.tabWidgets: |
1465 if tw.hasEditor(watched): | 1464 if tw.hasEditor(watched): |
1466 switched = tw is not self.currentTabWidget | 1465 switched = tw is not self.currentTabWidget |
1467 self.currentTabWidget = tw | 1466 self.currentTabWidget = tw |
1468 break | 1467 break |
1494 self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly") | 1493 self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly") |
1495 | 1494 |
1496 for tabWidget in self.tabWidgets: | 1495 for tabWidget in self.tabWidgets: |
1497 for index in range(tabWidget.count()): | 1496 for index in range(tabWidget.count()): |
1498 editor = tabWidget.widget(index) | 1497 editor = tabWidget.widget(index) |
1499 if isinstance(editor, QScintilla.Editor.Editor): | 1498 if isinstance(editor, Editor): |
1500 fn = editor.getFileName() | 1499 fn = editor.getFileName() |
1501 if fn: | 1500 if fn: |
1502 if self.filenameOnly: | 1501 if self.filenameOnly: |
1503 txt = os.path.basename(fn) | 1502 txt = os.path.basename(fn) |
1504 else: | 1503 else: |