Plugins/ViewManagerPlugins/Tabview/Tabview.py

changeset 3005
3953ddfb991d
parent 2964
84b65fb9e780
child 3007
bad2e89047e7
equal deleted inserted replaced
3004:c4bf32c791d0 3005:3953ddfb991d
7 Module implementing a tabbed viewmanager class. 7 Module implementing a tabbed viewmanager class.
8 """ 8 """
9 9
10 import os 10 import os
11 11
12 from PyQt4.QtCore import QPoint, QFileInfo, pyqtSignal, QEvent, QByteArray, QMimeData, Qt 12 from PyQt4.QtCore import QPoint, QFileInfo, pyqtSignal, QEvent, QByteArray, \
13 from PyQt4.QtGui import QWidget, QColor, QHBoxLayout, QDrag, QPixmap, QSplitter, \ 13 QMimeData, Qt
14 QTabBar, QApplication, QToolButton, QMenu, QLabel 14 from PyQt4.QtGui import QWidget, QColor, QHBoxLayout, QDrag, QPixmap, \
15 QSplitter, QTabBar, QApplication, QToolButton, QMenu, QLabel
15 16
16 from E5Gui.E5Application import e5App 17 from E5Gui.E5Application import e5App
17 18
18 from ViewManager.ViewManager import ViewManager 19 from ViewManager.ViewManager import ViewManager
19 20
33 34
34 class TabBar(E5WheelTabBar): 35 class TabBar(E5WheelTabBar):
35 """ 36 """
36 Class implementing a customized tab bar supporting drag & drop. 37 Class implementing a customized tab bar supporting drag & drop.
37 38
38 @signal tabMoveRequested(int, int) emitted to signal a tab move request giving 39 @signal tabMoveRequested(int, int) emitted to signal a tab move request
39 the old and new index position 40 giving the old and new index position
40 @signal tabRelocateRequested(str, int, int) emitted to signal a tab relocation 41 @signal tabRelocateRequested(str, int, int) emitted to signal a tab
41 request giving the string encoded id of the old tab widget, the index in 42 relocation request giving the string encoded id of the old tab widget,
42 the old tab widget and the new index position 43 the index in the old tab widget and the new index position
43 @signal tabCopyRequested(str, int, int) emitted to signal a clone request 44 @signal tabCopyRequested(str, int, int) emitted to signal a clone request
44 giving the string encoded id of the source tab widget, the index in the 45 giving the string encoded id of the source tab widget, the index in the
45 source tab widget and the new index position 46 source tab widget and the new index position
46 @signal tabCopyRequested(int, int) emitted to signal a clone request giving 47 @signal tabCopyRequested(int, int) emitted to signal a clone request giving
47 the old and new index position 48 the old and new index position
84 mimeData = QMimeData() 85 mimeData = QMimeData()
85 index = self.tabAt(event.pos()) 86 index = self.tabAt(event.pos())
86 mimeData.setText(self.tabText(index)) 87 mimeData.setText(self.tabText(index))
87 mimeData.setData("action", "tab-reordering") 88 mimeData.setData("action", "tab-reordering")
88 mimeData.setData("tabbar-id", str(id(self))) 89 mimeData.setData("tabbar-id", str(id(self)))
89 mimeData.setData("source-index", 90 mimeData.setData(
90 QByteArray.number(self.tabAt(self.__dragStartPos))) 91 "source-index",
92 QByteArray.number(self.tabAt(self.__dragStartPos)))
91 mimeData.setData("tabwidget-id", str(id(self.parentWidget()))) 93 mimeData.setData("tabwidget-id", str(id(self.parentWidget())))
92 drag.setMimeData(mimeData) 94 drag.setMimeData(mimeData)
93 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): 95 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier):
94 drag.exec_(Qt.DropActions(Qt.CopyAction)) 96 drag.exec_(Qt.DropActions(Qt.CopyAction))
95 elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier): 97 elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier):
123 fromIndex = mimeData.data("source-index").toInt()[0] 125 fromIndex = mimeData.data("source-index").toInt()[0]
124 toIndex = self.tabAt(event.pos()) 126 toIndex = self.tabAt(event.pos())
125 if oldID != id(self): 127 if oldID != id(self):
126 parentID = int(mimeData.data("tabwidget-id")) 128 parentID = int(mimeData.data("tabwidget-id"))
127 if event.proposedAction() == Qt.MoveAction: 129 if event.proposedAction() == Qt.MoveAction:
128 self.tabRelocateRequested.emit(str(parentID), fromIndex, toIndex) 130 self.tabRelocateRequested.emit(
131 str(parentID), fromIndex, toIndex)
129 event.acceptProposedAction() 132 event.acceptProposedAction()
130 elif event.proposedAction() == Qt.CopyAction: 133 elif event.proposedAction() == Qt.CopyAction:
131 self.tabCopyRequested[str, int, int].emit( 134 self.tabCopyRequested[str, int, int].emit(
132 str(parentID), fromIndex, toIndex) 135 str(parentID), fromIndex, toIndex)
133 event.acceptProposedAction() 136 event.acceptProposedAction()
163 if isMacPlatform(): 166 if isMacPlatform():
164 self.setDocumentMode(True) 167 self.setDocumentMode(True)
165 168
166 self.__tabBar.tabMoveRequested.connect(self.moveTab) 169 self.__tabBar.tabMoveRequested.connect(self.moveTab)
167 self.__tabBar.tabRelocateRequested.connect(self.__relocateTab) 170 self.__tabBar.tabRelocateRequested.connect(self.__relocateTab)
168 self.__tabBar.tabCopyRequested[str, int, int].connect(self.__copyTabOther) 171 self.__tabBar.tabCopyRequested[str, int, int].connect(
172 self.__copyTabOther)
169 self.__tabBar.tabCopyRequested[int, int].connect(self.__copyTab) 173 self.__tabBar.tabCopyRequested[int, int].connect(self.__copyTab)
170 174
171 self.vm = vm 175 self.vm = vm
172 self.editors = [] 176 self.editors = []
173 177
193 197
194 if Preferences.getUI("SingleCloseButton") or \ 198 if Preferences.getUI("SingleCloseButton") or \
195 not hasattr(self, 'setTabsClosable'): 199 not hasattr(self, 'setTabsClosable'):
196 self.closeButton = QToolButton(self) 200 self.closeButton = QToolButton(self)
197 self.closeButton.setIcon(UI.PixmapCache.getIcon("close.png")) 201 self.closeButton.setIcon(UI.PixmapCache.getIcon("close.png"))
198 self.closeButton.setToolTip(self.trUtf8("Close the current editor")) 202 self.closeButton.setToolTip(
203 self.trUtf8("Close the current editor"))
199 self.closeButton.setEnabled(False) 204 self.closeButton.setEnabled(False)
200 self.closeButton.clicked[bool].connect(self.__closeButtonClicked) 205 self.closeButton.clicked[bool].connect(self.__closeButtonClicked)
201 self.rightCornerWidgetLayout.addWidget(self.closeButton) 206 self.rightCornerWidgetLayout.addWidget(self.closeButton)
202 else: 207 else:
203 self.tabCloseRequested.connect(self.__closeRequested) 208 self.tabCloseRequested.connect(self.__closeRequested)
210 self.contextMenuIndex = -1 215 self.contextMenuIndex = -1
211 216
212 self.setTabContextMenuPolicy(Qt.CustomContextMenu) 217 self.setTabContextMenuPolicy(Qt.CustomContextMenu)
213 self.customTabContextMenuRequested.connect(self.__showContextMenu) 218 self.customTabContextMenuRequested.connect(self.__showContextMenu)
214 219
215 ericPic = QPixmap(os.path.join(getConfig('ericPixDir'), 'eric_small.png')) 220 ericPic = QPixmap(
221 os.path.join(getConfig('ericPixDir'), 'eric_small.png'))
216 self.emptyLabel = QLabel() 222 self.emptyLabel = QLabel()
217 self.emptyLabel.setPixmap(ericPic) 223 self.emptyLabel.setPixmap(ericPic)
218 self.emptyLabel.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter) 224 self.emptyLabel.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter)
219 super().addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "") 225 super().addTab(self.emptyLabel,
226 UI.PixmapCache.getIcon("empty.png"), "")
220 227
221 def __initMenu(self): 228 def __initMenu(self):
222 """ 229 """
223 Private method to initialize the tab context menu. 230 Private method to initialize the tab context menu.
224 """ 231 """
237 self.trUtf8('Move Last'), self.__contextMenuMoveLast) 244 self.trUtf8('Move Last'), self.__contextMenuMoveLast)
238 self.__menu.addSeparator() 245 self.__menu.addSeparator()
239 self.__menu.addAction(UI.PixmapCache.getIcon("tabClose.png"), 246 self.__menu.addAction(UI.PixmapCache.getIcon("tabClose.png"),
240 self.trUtf8('Close'), self.__contextMenuClose) 247 self.trUtf8('Close'), self.__contextMenuClose)
241 self.closeOthersMenuAct = self.__menu.addAction( 248 self.closeOthersMenuAct = self.__menu.addAction(
242 UI.PixmapCache.getIcon("tabCloseOther.png"), self.trUtf8("Close Others"), 249 UI.PixmapCache.getIcon("tabCloseOther.png"),
243 self.__contextMenuCloseOthers) 250 self.trUtf8("Close Others"), self.__contextMenuCloseOthers)
244 self.__menu.addAction(self.trUtf8('Close All'), self.__contextMenuCloseAll) 251 self.__menu.addAction(
252 self.trUtf8('Close All'), self.__contextMenuCloseAll)
245 self.__menu.addSeparator() 253 self.__menu.addSeparator()
246 self.saveMenuAct = \ 254 self.saveMenuAct = \
247 self.__menu.addAction(UI.PixmapCache.getIcon("fileSave.png"), 255 self.__menu.addAction(UI.PixmapCache.getIcon("fileSave.png"),
248 self.trUtf8('Save'), self.__contextMenuSave) 256 self.trUtf8('Save'), self.__contextMenuSave)
249 self.__menu.addAction(UI.PixmapCache.getIcon("fileSaveAs.png"), 257 self.__menu.addAction(UI.PixmapCache.getIcon("fileSaveAs.png"),
256 self.__contextMenuOpenRejections) 264 self.__contextMenuOpenRejections)
257 self.__menu.addSeparator() 265 self.__menu.addSeparator()
258 self.__menu.addAction(UI.PixmapCache.getIcon("print.png"), 266 self.__menu.addAction(UI.PixmapCache.getIcon("print.png"),
259 self.trUtf8('Print'), self.__contextMenuPrintFile) 267 self.trUtf8('Print'), self.__contextMenuPrintFile)
260 self.__menu.addSeparator() 268 self.__menu.addSeparator()
261 self.copyPathAct = self.__menu.addAction(self.trUtf8("Copy Path to Clipboard"), 269 self.copyPathAct = self.__menu.addAction(
270 self.trUtf8("Copy Path to Clipboard"),
262 self.__contextMenuCopyPathToClipboard) 271 self.__contextMenuCopyPathToClipboard)
263 272
264 def __showContextMenu(self, coord, index): 273 def __showContextMenu(self, coord, index):
265 """ 274 """
266 Private slot to show the tab context menu. 275 Private slot to show the tab context menu.
269 @param index index of the tab the menu is requested for (integer) 278 @param index index of the tab the menu is requested for (integer)
270 """ 279 """
271 if self.editors: 280 if self.editors:
272 self.contextMenuEditor = self.widget(index).getEditor() 281 self.contextMenuEditor = self.widget(index).getEditor()
273 if self.contextMenuEditor: 282 if self.contextMenuEditor:
274 self.saveMenuAct.setEnabled(self.contextMenuEditor.isModified()) 283 self.saveMenuAct.setEnabled(
284 self.contextMenuEditor.isModified())
275 fileName = self.contextMenuEditor.getFileName() 285 fileName = self.contextMenuEditor.getFileName()
276 self.copyPathAct.setEnabled(bool(fileName)) 286 self.copyPathAct.setEnabled(bool(fileName))
277 if fileName: 287 if fileName:
278 rej = "{0}.rej".format(fileName) 288 rej = "{0}.rej".format(fileName)
279 self.openRejectionsMenuAct.setEnabled(os.path.exists(rej)) 289 self.openRejectionsMenuAct.setEnabled(os.path.exists(rej))
379 389
380 def __captionChange(self, cap, editor): 390 def __captionChange(self, cap, editor):
381 """ 391 """
382 Private slot to handle Caption change signals from the editor. 392 Private slot to handle Caption change signals from the editor.
383 393
384 Updates the tab text and tooltip text to reflect the new caption information. 394 Updates the tab text and tooltip text to reflect the new caption
395 information.
385 396
386 @param cap Caption for the editor 397 @param cap Caption for the editor
387 @param editor Editor to update the caption for 398 @param editor Editor to update the caption for
388 """ 399 """
389 fn = editor.getFileName() 400 fn = editor.getFileName()
391 if Preferences.getUI("TabViewManagerFilenameOnly"): 402 if Preferences.getUI("TabViewManagerFilenameOnly"):
392 txt = os.path.basename(fn) 403 txt = os.path.basename(fn)
393 else: 404 else:
394 txt = e5App().getObject("Project").getRelativePath(fn) 405 txt = e5App().getObject("Project").getRelativePath(fn)
395 406
396 maxFileNameChars = Preferences.getUI("TabViewManagerFilenameLength") 407 maxFileNameChars = Preferences.getUI(
408 "TabViewManagerFilenameLength")
397 if len(txt) > maxFileNameChars: 409 if len(txt) > maxFileNameChars:
398 txt = "...{0}".format(txt[-maxFileNameChars:]) 410 txt = "...{0}".format(txt[-maxFileNameChars:])
399 if editor.isReadOnly(): 411 if editor.isReadOnly():
400 txt = self.trUtf8("{0} (ro)").format(txt) 412 txt = self.trUtf8("{0} (ro)").format(txt)
401 413
432 index = self.indexOf(object) 444 index = self.indexOf(object)
433 if index > -1: 445 if index > -1:
434 self.removeTab(index) 446 self.removeTab(index)
435 447
436 if not self.editors: 448 if not self.editors:
437 super().addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "") 449 super().addTab(
450 self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "")
438 self.emptyLabel.show() 451 self.emptyLabel.show()
439 if self.closeButton: 452 if self.closeButton:
440 self.closeButton.setEnabled(False) 453 self.closeButton.setEnabled(False)
441 else: 454 else:
442 self.setTabsClosable(False) 455 self.setTabsClosable(False)
480 @param targetIndex index position to place it to (integer) 493 @param targetIndex index position to place it to (integer)
481 """ 494 """
482 tw = self.vm.getTabWidgetById(int(sourceId)) 495 tw = self.vm.getTabWidgetById(int(sourceId))
483 if tw is not None: 496 if tw is not None:
484 editor = tw.widget(sourceIndex).getEditor() 497 editor = tw.widget(sourceIndex).getEditor()
485 newEditor, assembly = self.vm.cloneEditor(editor, editor.getFileType(), 498 newEditor, assembly = self.vm.cloneEditor(
486 editor.getFileName()) 499 editor, editor.getFileType(), editor.getFileName())
487 self.vm.insertView(assembly, self, targetIndex, 500 self.vm.insertView(assembly, self, targetIndex,
488 editor.getFileName(), editor.getNoName()) 501 editor.getFileName(), editor.getNoName())
489 502
490 def __copyTab(self, sourceIndex, targetIndex): 503 def __copyTab(self, sourceIndex, targetIndex):
491 """ 504 """
594 """ 607 """
595 self.vm.saveEditorsList(self.editors) 608 self.vm.saveEditorsList(self.editors)
596 609
597 def __contextMenuOpenRejections(self): 610 def __contextMenuOpenRejections(self):
598 """ 611 """
599 Private slot to open a rejections file associated with the selected tab. 612 Private slot to open a rejections file associated with the selected
613 tab.
600 """ 614 """
601 if self.contextMenuEditor: 615 if self.contextMenuEditor:
602 fileName = self.contextMenuEditor.getFileName() 616 fileName = self.contextMenuEditor.getFileName()
603 if fileName: 617 if fileName:
604 rej = "{0}.rej".format(fileName) 618 rej = "{0}.rej".format(fileName)
612 if self.contextMenuEditor: 626 if self.contextMenuEditor:
613 self.vm.printEditor(self.contextMenuEditor) 627 self.vm.printEditor(self.contextMenuEditor)
614 628
615 def __contextMenuCopyPathToClipboard(self): 629 def __contextMenuCopyPathToClipboard(self):
616 """ 630 """
617 Private method to copy the file name of the selected tab to the clipboard. 631 Private method to copy the file name of the selected tab to the
632 clipboard.
618 """ 633 """
619 if self.contextMenuEditor: 634 if self.contextMenuEditor:
620 fn = self.contextMenuEditor.getFileName() 635 fn = self.contextMenuEditor.getFileName()
621 if fn: 636 if fn:
622 cb = QApplication.clipboard() 637 cb = QApplication.clipboard()
679 @signal editorChangedEd(Editor) emitted when the current editor has changed 694 @signal editorChangedEd(Editor) emitted when the current editor has changed
680 @signal lastEditorClosed() emitted after the last editor window was closed 695 @signal lastEditorClosed() emitted after the last editor window was closed
681 @signal editorOpened(str) emitted after an editor window was opened 696 @signal editorOpened(str) emitted after an editor window was opened
682 @signal editorOpenedEd(Editor) emitted after an editor window was opened 697 @signal editorOpenedEd(Editor) emitted after an editor window was opened
683 @signal editorClosed(str) emitted just before an editor window gets closed 698 @signal editorClosed(str) emitted just before an editor window gets closed
684 @signal editorClosedEd(Editor) emitted just before an editor window gets closed 699 @signal editorClosedEd(Editor) emitted just before an editor window gets
700 closed
685 @signal editorSaved(str) emitted after an editor window was saved 701 @signal editorSaved(str) emitted after an editor window was saved
686 @signal checkActions(Editor) emitted when some actions should be checked 702 @signal checkActions(Editor) emitted when some actions should be checked
687 for their status 703 for their status
688 @signal cursorChanged(Editor) emitted after the cursor position of the active 704 @signal cursorChanged(Editor) emitted after the cursor position of the
689 window has changed 705 active window has changed
690 @signal breakpointToggled(Editor) emitted when a breakpoint is toggled. 706 @signal breakpointToggled(Editor) emitted when a breakpoint is toggled.
691 @signal bookmarkToggled(Editor) emitted when a bookmark is toggled. 707 @signal bookmarkToggled(Editor) emitted when a bookmark is toggled.
692 @signal syntaxerrorToggled(Editor) emitted when a syntax error is toggled. 708 @signal syntaxerrorToggled(Editor) emitted when a syntax error is toggled.
693 @signal previewStateChanged(bool) emitted to signal a change in the preview state 709 @signal previewStateChanged(bool) emitted to signal a change in the
710 preview state
694 @signal editorLanguageChanged(Editor) emitted to signal a change of an 711 @signal editorLanguageChanged(Editor) emitted to signal a change of an
695 editors language 712 editors language
696 @signal editorTextChanged(Editor) emitted to signal a change of an editor's text 713 @signal editorTextChanged(Editor) emitted to signal a change of an
697 @signal editorLineChanged(str,int) emitted to signal a change of an editor's 714 editor's text
698 current line (line is given one based) 715 @signal editorLineChanged(str,int) emitted to signal a change of an
716 editor's current line (line is given one based)
699 """ 717 """
700 changeCaption = pyqtSignal(str) 718 changeCaption = pyqtSignal(str)
701 editorChanged = pyqtSignal(str) 719 editorChanged = pyqtSignal(str)
702 editorChangedEd = pyqtSignal(Editor) 720 editorChangedEd = pyqtSignal(Editor)
703 lastEditorClosed = pyqtSignal() 721 lastEditorClosed = pyqtSignal()
735 tw.installEventFilter(self) 753 tw.installEventFilter(self)
736 tw.tabBar().installEventFilter(self) 754 tw.tabBar().installEventFilter(self)
737 self.setOrientation(Qt.Vertical) 755 self.setOrientation(Qt.Vertical)
738 self.__inRemoveView = False 756 self.__inRemoveView = False
739 757
740 self.maxFileNameChars = Preferences.getUI("TabViewManagerFilenameLength") 758 self.maxFileNameChars = Preferences.getUI(
759 "TabViewManagerFilenameLength")
741 self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly") 760 self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly")
742 761
743 def canCascade(self): 762 def canCascade(self):
744 """ 763 """
745 Public method to signal if cascading of managed windows is available. 764 Public method to signal if cascading of managed windows is available.
798 self.__inRemoveView = False 817 self.__inRemoveView = False
799 818
800 # if this was the last editor in this view, switch to the next, that 819 # if this was the last editor in this view, switch to the next, that
801 # still has open editors 820 # still has open editors
802 for i in list(range(self.tabWidgets.index(tw), -1, -1)) + \ 821 for i in list(range(self.tabWidgets.index(tw), -1, -1)) + \
803 list(range(self.tabWidgets.index(tw) + 1, len(self.tabWidgets))): 822 list(range(self.tabWidgets.index(tw) + 1,
823 len(self.tabWidgets))):
804 if self.tabWidgets[i].hasEditors(): 824 if self.tabWidgets[i].hasEditors():
805 self.currentTabWidget.showIndicator(False) 825 self.currentTabWidget.showIndicator(False)
806 self.currentTabWidget = self.tabWidgets[i] 826 self.currentTabWidget = self.tabWidgets[i]
807 self.currentTabWidget.showIndicator(True) 827 self.currentTabWidget.showIndicator(True)
808 self.activeWindow().setFocus() 828 self.activeWindow().setFocus()
859 def insertView(self, win, tabWidget, index, fn=None, noName=""): 879 def insertView(self, win, tabWidget, index, fn=None, noName=""):
860 """ 880 """
861 Protected method to add a view (i.e. window). 881 Protected method to add a view (i.e. window).
862 882
863 @param win editor assembly to be inserted 883 @param win editor assembly to be inserted
864 @param tabWidget reference to the tab widget to insert the editor into (TabWidget) 884 @param tabWidget reference to the tab widget to insert the editor into
885 (TabWidget)
865 @param index index position to insert at (integer) 886 @param index index position to insert at (integer)
866 @param fn filename of this editor (string) 887 @param fn filename of this editor (string)
867 @param noName name to be used for an unnamed editor (string) 888 @param noName name to be used for an unnamed editor (string)
868 """ 889 """
869 editor = win.getEditor() 890 editor = win.getEditor()
936 """ 957 """
937 pass 958 pass
938 959
939 def _initWindowActions(self): 960 def _initWindowActions(self):
940 """ 961 """
941 Protected method to define the user interface actions for window handling. 962 Protected method to define the user interface actions for window
963 handling.
942 """ 964 """
943 pass 965 pass
944 966
945 def setEditorName(self, editor, newName): 967 def setEditorName(self, editor, newName):
946 """ 968 """
1019 tw.tabBar().installEventFilter(self) 1041 tw.tabBar().installEventFilter(self)
1020 if self.orientation() == Qt.Horizontal: 1042 if self.orientation() == Qt.Horizontal:
1021 size = self.width() 1043 size = self.width()
1022 else: 1044 else:
1023 size = self.height() 1045 size = self.height()
1024 self.setSizes([int(size / len(self.tabWidgets))] * len(self.tabWidgets)) 1046 self.setSizes(
1047 [int(size / len(self.tabWidgets))] * len(self.tabWidgets))
1025 self.splitRemoveAct.setEnabled(True) 1048 self.splitRemoveAct.setEnabled(True)
1026 self.nextSplitAct.setEnabled(True) 1049 self.nextSplitAct.setEnabled(True)
1027 self.prevSplitAct.setEnabled(True) 1050 self.prevSplitAct.setEnabled(True)
1028 1051
1029 def removeSplit(self): 1052 def removeSplit(self):
1120 fn = editor.getFileName() 1143 fn = editor.getFileName()
1121 if fn: 1144 if fn:
1122 self.changeCaption.emit(fn) 1145 self.changeCaption.emit(fn)
1123 if not self.__inRemoveView: 1146 if not self.__inRemoveView:
1124 self.editorChanged.emit(fn) 1147 self.editorChanged.emit(fn)
1125 self.editorLineChanged.emit(fn, editor.getCursorPosition()[0] + 1) 1148 self.editorLineChanged.emit(
1149 fn, editor.getCursorPosition()[0] + 1)
1126 else: 1150 else:
1127 self.changeCaption.emit("") 1151 self.changeCaption.emit("")
1128 self.editorChangedEd.emit(editor) 1152 self.editorChangedEd.emit(editor)
1129 1153
1130 def eventFilter(self, watched, event): 1154 def eventFilter(self, watched, event):
1144 elif isinstance(watched, QTabBar): 1168 elif isinstance(watched, QTabBar):
1145 switched = watched.parent() is not self.currentTabWidget 1169 switched = watched.parent() is not self.currentTabWidget
1146 self.currentTabWidget = watched.parent() 1170 self.currentTabWidget = watched.parent()
1147 if switched: 1171 if switched:
1148 index = self.currentTabWidget.selectTab(event.pos()) 1172 index = self.currentTabWidget.selectTab(event.pos())
1149 switched = self.currentTabWidget.widget(index) is self.activeWindow() 1173 switched = self.currentTabWidget.widget(index) is \
1174 self.activeWindow()
1150 elif isinstance(watched, QScintilla.Editor.Editor): 1175 elif isinstance(watched, QScintilla.Editor.Editor):
1151 for tw in self.tabWidgets: 1176 for tw in self.tabWidgets:
1152 if tw.hasEditor(watched): 1177 if tw.hasEditor(watched):
1153 switched = tw is not self.currentTabWidget 1178 switched = tw is not self.currentTabWidget
1154 self.currentTabWidget = tw 1179 self.currentTabWidget = tw
1162 fn = aw.getFileName() 1187 fn = aw.getFileName()
1163 if fn: 1188 if fn:
1164 self.changeCaption.emit(fn) 1189 self.changeCaption.emit(fn)
1165 if switched: 1190 if switched:
1166 self.editorChanged.emit(fn) 1191 self.editorChanged.emit(fn)
1167 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1) 1192 self.editorLineChanged.emit(
1193 fn, aw.getCursorPosition()[0] + 1)
1168 else: 1194 else:
1169 self.changeCaption.emit("") 1195 self.changeCaption.emit("")
1170 self.editorChangedEd.emit(aw) 1196 self.editorChangedEd.emit(aw)
1171 1197
1172 return False 1198 return False
1175 """ 1201 """
1176 Public slot to handle the preferencesChanged signal. 1202 Public slot to handle the preferencesChanged signal.
1177 """ 1203 """
1178 ViewManager.preferencesChanged(self) 1204 ViewManager.preferencesChanged(self)
1179 1205
1180 self.maxFileNameChars = Preferences.getUI("TabViewManagerFilenameLength") 1206 self.maxFileNameChars = Preferences.getUI(
1207 "TabViewManagerFilenameLength")
1181 self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly") 1208 self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly")
1182 1209
1183 for tabWidget in self.tabWidgets: 1210 for tabWidget in self.tabWidgets:
1184 for index in range(tabWidget.count()): 1211 for index in range(tabWidget.count()):
1185 editor = tabWidget.widget(index) 1212 editor = tabWidget.widget(index)
1187 fn = editor.getFileName() 1214 fn = editor.getFileName()
1188 if fn: 1215 if fn:
1189 if self.filenameOnly: 1216 if self.filenameOnly:
1190 txt = os.path.basename(fn) 1217 txt = os.path.basename(fn)
1191 else: 1218 else:
1192 txt = e5App().getObject("Project").getRelativePath(fn) 1219 txt = e5App().getObject("Project")\
1220 .getRelativePath(fn)
1193 if len(txt) > self.maxFileNameChars: 1221 if len(txt) > self.maxFileNameChars:
1194 txt = "...{0}".format(txt[-self.maxFileNameChars:]) 1222 txt = "...{0}".format(txt[-self.maxFileNameChars:])
1195 if not QFileInfo(fn).isWritable(): 1223 if not QFileInfo(fn).isWritable():
1196 txt = self.trUtf8("{0} (ro)").format(txt) 1224 txt = self.trUtf8("{0} (ro)").format(txt)
1197 tabWidget.setTabText(index, txt) 1225 tabWidget.setTabText(index, txt)

eric ide

mercurial