8 """ |
8 """ |
9 |
9 |
10 |
10 |
11 import os |
11 import os |
12 |
12 |
13 from PyQt5.QtCore import pyqtSlot, QPoint, QFileInfo, pyqtSignal, QEvent, \ |
13 from PyQt5.QtCore import ( |
14 QByteArray, QMimeData, Qt, QSize |
14 pyqtSlot, QPoint, QFileInfo, pyqtSignal, QEvent, QByteArray, QMimeData, |
|
15 Qt, QSize |
|
16 ) |
15 from PyQt5.QtGui import QColor, QDrag, QPixmap |
17 from PyQt5.QtGui import QColor, QDrag, QPixmap |
16 from PyQt5.QtWidgets import QWidget, QHBoxLayout, QSplitter, QTabBar, \ |
18 from PyQt5.QtWidgets import ( |
17 QApplication, QToolButton, QMenu, QLabel |
19 QWidget, QHBoxLayout, QSplitter, QTabBar, QApplication, QToolButton, |
|
20 QMenu, QLabel |
|
21 ) |
18 |
22 |
19 from E5Gui.E5Application import e5App |
23 from E5Gui.E5Application import e5App |
20 |
24 |
21 from ViewManager.ViewManager import ViewManager |
25 from ViewManager.ViewManager import ViewManager |
22 |
26 |
82 Protected method to handle mouse move events. |
86 Protected method to handle mouse move events. |
83 |
87 |
84 @param event reference to the mouse move event |
88 @param event reference to the mouse move event |
85 @type QMouseEvent |
89 @type QMouseEvent |
86 """ |
90 """ |
87 if event.buttons() == Qt.MouseButtons(Qt.LeftButton) and \ |
91 if ( |
88 (event.pos() - self.__dragStartPos).manhattanLength() > \ |
92 event.buttons() == Qt.MouseButtons(Qt.LeftButton) and |
89 QApplication.startDragDistance(): |
93 (event.pos() - self.__dragStartPos).manhattanLength() > |
|
94 QApplication.startDragDistance() |
|
95 ): |
90 drag = QDrag(self) |
96 drag = QDrag(self) |
91 mimeData = QMimeData() |
97 mimeData = QMimeData() |
92 index = self.tabAt(event.pos()) |
98 index = self.tabAt(event.pos()) |
93 mimeData.setText(self.tabText(index)) |
99 mimeData.setText(self.tabText(index)) |
94 mimeData.setData("action", b"tab-reordering") |
100 mimeData.setData("action", b"tab-reordering") |
113 @param event reference to the drag enter event |
119 @param event reference to the drag enter event |
114 @type QDragEnterEvent |
120 @type QDragEnterEvent |
115 """ |
121 """ |
116 mimeData = event.mimeData() |
122 mimeData = event.mimeData() |
117 formats = mimeData.formats() |
123 formats = mimeData.formats() |
118 if "action" in formats and \ |
124 if ( |
119 mimeData.data("action") == b"tab-reordering" and \ |
125 "action" in formats and |
120 "tabbar-id" in formats and \ |
126 mimeData.data("action") == b"tab-reordering" and |
121 "source-index" in formats and \ |
127 "tabbar-id" in formats and |
122 "tabwidget-id" in formats: |
128 "source-index" in formats and |
|
129 "tabwidget-id" in formats |
|
130 ): |
123 event.acceptProposedAction() |
131 event.acceptProposedAction() |
124 super(TabBar, self).dragEnterEvent(event) |
132 super(TabBar, self).dragEnterEvent(event) |
125 |
133 |
126 def dropEvent(self, event): |
134 def dropEvent(self, event): |
127 """ |
135 """ |
604 def __contextMenuCloseOthers(self): |
612 def __contextMenuCloseOthers(self): |
605 """ |
613 """ |
606 Private method to close the other tabs. |
614 Private method to close the other tabs. |
607 """ |
615 """ |
608 index = self.contextMenuIndex |
616 index = self.contextMenuIndex |
609 for i in list(range(self.count() - 1, index, -1)) + \ |
617 for i in ( |
610 list(range(index - 1, -1, -1)): |
618 list(range(self.count() - 1, index, -1)) + |
|
619 list(range(index - 1, -1, -1)) |
|
620 ): |
611 editor = self.widget(i).getEditor() |
621 editor = self.widget(i).getEditor() |
612 self.vm.closeEditorWindow(editor) |
622 self.vm.closeEditorWindow(editor) |
613 |
623 |
614 def __contextMenuCloseAll(self): |
624 def __contextMenuCloseAll(self): |
615 """ |
625 """ |
876 win.closeIt() |
886 win.closeIt() |
877 self.__inRemoveView = False |
887 self.__inRemoveView = False |
878 |
888 |
879 # if this was the last editor in this view, switch to the next, that |
889 # if this was the last editor in this view, switch to the next, that |
880 # still has open editors |
890 # still has open editors |
881 for i in list(range(self.tabWidgets.index(tw), -1, -1)) + \ |
891 for i in ( |
|
892 list(range(self.tabWidgets.index(tw), -1, -1)) + |
882 list(range(self.tabWidgets.index(tw) + 1, |
893 list(range(self.tabWidgets.index(tw) + 1, |
883 len(self.tabWidgets))): |
894 len(self.tabWidgets))) |
|
895 ): |
884 if self.tabWidgets[i].hasEditors(): |
896 if self.tabWidgets[i].hasEditors(): |
885 self.currentTabWidget.showIndicator(False) |
897 self.currentTabWidget.showIndicator(False) |
886 self.currentTabWidget = self.tabWidgets[i] |
898 self.currentTabWidget = self.tabWidgets[i] |
887 self.currentTabWidget.showIndicator(True) |
899 self.currentTabWidget.showIndicator(True) |
888 self.activeWindow().setFocus() |
900 self.activeWindow().setFocus() |
1319 @param event the event that occurred |
1331 @param event the event that occurred |
1320 @type QEvent |
1332 @type QEvent |
1321 @return always False |
1333 @return always False |
1322 @rtype bool |
1334 @rtype bool |
1323 """ |
1335 """ |
1324 if event.type() == QEvent.MouseButtonPress and \ |
1336 if ( |
1325 not event.button() == Qt.RightButton: |
1337 event.type() == QEvent.MouseButtonPress and |
|
1338 not event.button() == Qt.RightButton |
|
1339 ): |
1326 switched = True |
1340 switched = True |
1327 self.currentTabWidget.showIndicator(False) |
1341 self.currentTabWidget.showIndicator(False) |
1328 if isinstance(watched, E5TabWidget): |
1342 if isinstance(watched, E5TabWidget): |
1329 switched = watched is not self.currentTabWidget |
1343 switched = watched is not self.currentTabWidget |
1330 self.currentTabWidget = watched |
1344 self.currentTabWidget = watched |
1331 elif isinstance(watched, QTabBar): |
1345 elif isinstance(watched, QTabBar): |
1332 switched = watched.parent() is not self.currentTabWidget |
1346 switched = watched.parent() is not self.currentTabWidget |
1333 self.currentTabWidget = watched.parent() |
1347 self.currentTabWidget = watched.parent() |
1334 if switched: |
1348 if switched: |
1335 index = self.currentTabWidget.selectTab(event.pos()) |
1349 index = self.currentTabWidget.selectTab(event.pos()) |
1336 switched = self.currentTabWidget.widget(index) is \ |
1350 switched = ( |
|
1351 self.currentTabWidget.widget(index) is |
1337 self.activeWindow() |
1352 self.activeWindow() |
|
1353 ) |
1338 elif isinstance(watched, QScintilla.Editor.Editor): |
1354 elif isinstance(watched, QScintilla.Editor.Editor): |
1339 for tw in self.tabWidgets: |
1355 for tw in self.tabWidgets: |
1340 if tw.hasEditor(watched): |
1356 if tw.hasEditor(watched): |
1341 switched = tw is not self.currentTabWidget |
1357 switched = tw is not self.currentTabWidget |
1342 self.currentTabWidget = tw |
1358 self.currentTabWidget = tw |
1377 fn = editor.getFileName() |
1393 fn = editor.getFileName() |
1378 if fn: |
1394 if fn: |
1379 if self.filenameOnly: |
1395 if self.filenameOnly: |
1380 txt = os.path.basename(fn) |
1396 txt = os.path.basename(fn) |
1381 else: |
1397 else: |
1382 txt = e5App().getObject("Project")\ |
1398 txt = e5App().getObject( |
1383 .getRelativePath(fn) |
1399 "Project").getRelativePath(fn) |
1384 if len(txt) > self.maxFileNameChars: |
1400 if len(txt) > self.maxFileNameChars: |
1385 txt = "...{0}".format(txt[-self.maxFileNameChars:]) |
1401 txt = "...{0}".format(txt[-self.maxFileNameChars:]) |
1386 if not QFileInfo(fn).isWritable(): |
1402 if not QFileInfo(fn).isWritable(): |
1387 txt = self.tr("{0} (ro)").format(txt) |
1403 txt = self.tr("{0} (ro)").format(txt) |
1388 tabWidget.setTabText(index, txt) |
1404 tabWidget.setTabText(index, txt) |