9 |
9 |
10 from __future__ import unicode_literals # __IGNORE_WARNING__ |
10 from __future__ import unicode_literals # __IGNORE_WARNING__ |
11 |
11 |
12 import os |
12 import os |
13 |
13 |
14 from PyQt4.QtCore import QPoint, QFileInfo, pyqtSignal, QEvent, QByteArray, QMimeData, Qt |
14 from PyQt4.QtCore import QPoint, QFileInfo, pyqtSignal, QEvent, QByteArray, \ |
15 from PyQt4.QtGui import QWidget, QColor, QHBoxLayout, QDrag, QPixmap, QSplitter, \ |
15 QMimeData, Qt |
16 QTabBar, QApplication, QToolButton, QMenu, QLabel |
16 from PyQt4.QtGui import QWidget, QColor, QHBoxLayout, QDrag, QPixmap, \ |
|
17 QSplitter, QTabBar, QApplication, QToolButton, QMenu, QLabel |
17 |
18 |
18 from E5Gui.E5Application import e5App |
19 from E5Gui.E5Application import e5App |
19 |
20 |
20 from ViewManager.ViewManager import ViewManager |
21 from ViewManager.ViewManager import ViewManager |
21 |
22 |
35 |
36 |
36 class TabBar(E5WheelTabBar): |
37 class TabBar(E5WheelTabBar): |
37 """ |
38 """ |
38 Class implementing a customized tab bar supporting drag & drop. |
39 Class implementing a customized tab bar supporting drag & drop. |
39 |
40 |
40 @signal tabMoveRequested(int, int) emitted to signal a tab move request giving |
41 @signal tabMoveRequested(int, int) emitted to signal a tab move request |
41 the old and new index position |
42 giving the old and new index position |
42 @signal tabRelocateRequested(str, int, int) emitted to signal a tab relocation |
43 @signal tabRelocateRequested(str, int, int) emitted to signal a tab |
43 request giving the string encoded id of the old tab widget, the index in |
44 relocation request giving the string encoded id of the old tab widget, |
44 the old tab widget and the new index position |
45 the index in the old tab widget and the new index position |
45 @signal tabCopyRequested(str, int, int) emitted to signal a clone request |
46 @signal tabCopyRequested(str, int, int) emitted to signal a clone request |
46 giving the string encoded id of the source tab widget, the index in the |
47 giving the string encoded id of the source tab widget, the index in the |
47 source tab widget and the new index position |
48 source tab widget and the new index position |
48 @signal tabCopyRequested(int, int) emitted to signal a clone request giving |
49 @signal tabCopyRequested(int, int) emitted to signal a clone request giving |
49 the old and new index position |
50 the old and new index position |
86 mimeData = QMimeData() |
87 mimeData = QMimeData() |
87 index = self.tabAt(event.pos()) |
88 index = self.tabAt(event.pos()) |
88 mimeData.setText(self.tabText(index)) |
89 mimeData.setText(self.tabText(index)) |
89 mimeData.setData("action", "tab-reordering") |
90 mimeData.setData("action", "tab-reordering") |
90 mimeData.setData("tabbar-id", str(id(self))) |
91 mimeData.setData("tabbar-id", str(id(self))) |
91 mimeData.setData("source-index", |
92 mimeData.setData( |
92 QByteArray.number(self.tabAt(self.__dragStartPos))) |
93 "source-index", |
|
94 QByteArray.number(self.tabAt(self.__dragStartPos))) |
93 mimeData.setData("tabwidget-id", str(id(self.parentWidget()))) |
95 mimeData.setData("tabwidget-id", str(id(self.parentWidget()))) |
94 drag.setMimeData(mimeData) |
96 drag.setMimeData(mimeData) |
95 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): |
97 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): |
96 drag.exec_(Qt.DropActions(Qt.CopyAction)) |
98 drag.exec_(Qt.DropActions(Qt.CopyAction)) |
97 elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier): |
99 elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier): |
125 fromIndex = mimeData.data("source-index").toInt()[0] |
127 fromIndex = mimeData.data("source-index").toInt()[0] |
126 toIndex = self.tabAt(event.pos()) |
128 toIndex = self.tabAt(event.pos()) |
127 if oldID != id(self): |
129 if oldID != id(self): |
128 parentID = int(mimeData.data("tabwidget-id")) |
130 parentID = int(mimeData.data("tabwidget-id")) |
129 if event.proposedAction() == Qt.MoveAction: |
131 if event.proposedAction() == Qt.MoveAction: |
130 self.tabRelocateRequested.emit(str(parentID), fromIndex, toIndex) |
132 self.tabRelocateRequested.emit( |
|
133 str(parentID), fromIndex, toIndex) |
131 event.acceptProposedAction() |
134 event.acceptProposedAction() |
132 elif event.proposedAction() == Qt.CopyAction: |
135 elif event.proposedAction() == Qt.CopyAction: |
133 self.tabCopyRequested[str, int, int].emit( |
136 self.tabCopyRequested[str, int, int].emit( |
134 str(parentID), fromIndex, toIndex) |
137 str(parentID), fromIndex, toIndex) |
135 event.acceptProposedAction() |
138 event.acceptProposedAction() |
165 if isMacPlatform(): |
168 if isMacPlatform(): |
166 self.setDocumentMode(True) |
169 self.setDocumentMode(True) |
167 |
170 |
168 self.__tabBar.tabMoveRequested.connect(self.moveTab) |
171 self.__tabBar.tabMoveRequested.connect(self.moveTab) |
169 self.__tabBar.tabRelocateRequested.connect(self.__relocateTab) |
172 self.__tabBar.tabRelocateRequested.connect(self.__relocateTab) |
170 self.__tabBar.tabCopyRequested[str, int, int].connect(self.__copyTabOther) |
173 self.__tabBar.tabCopyRequested[str, int, int].connect( |
|
174 self.__copyTabOther) |
171 self.__tabBar.tabCopyRequested[int, int].connect(self.__copyTab) |
175 self.__tabBar.tabCopyRequested[int, int].connect(self.__copyTab) |
172 |
176 |
173 self.vm = vm |
177 self.vm = vm |
174 self.editors = [] |
178 self.editors = [] |
175 |
179 |
195 |
199 |
196 if Preferences.getUI("SingleCloseButton") or \ |
200 if Preferences.getUI("SingleCloseButton") or \ |
197 not hasattr(self, 'setTabsClosable'): |
201 not hasattr(self, 'setTabsClosable'): |
198 self.closeButton = QToolButton(self) |
202 self.closeButton = QToolButton(self) |
199 self.closeButton.setIcon(UI.PixmapCache.getIcon("close.png")) |
203 self.closeButton.setIcon(UI.PixmapCache.getIcon("close.png")) |
200 self.closeButton.setToolTip(self.trUtf8("Close the current editor")) |
204 self.closeButton.setToolTip( |
|
205 self.trUtf8("Close the current editor")) |
201 self.closeButton.setEnabled(False) |
206 self.closeButton.setEnabled(False) |
202 self.closeButton.clicked[bool].connect(self.__closeButtonClicked) |
207 self.closeButton.clicked[bool].connect(self.__closeButtonClicked) |
203 self.rightCornerWidgetLayout.addWidget(self.closeButton) |
208 self.rightCornerWidgetLayout.addWidget(self.closeButton) |
204 else: |
209 else: |
205 self.tabCloseRequested.connect(self.__closeRequested) |
210 self.tabCloseRequested.connect(self.__closeRequested) |
212 self.contextMenuIndex = -1 |
217 self.contextMenuIndex = -1 |
213 |
218 |
214 self.setTabContextMenuPolicy(Qt.CustomContextMenu) |
219 self.setTabContextMenuPolicy(Qt.CustomContextMenu) |
215 self.customTabContextMenuRequested.connect(self.__showContextMenu) |
220 self.customTabContextMenuRequested.connect(self.__showContextMenu) |
216 |
221 |
217 ericPic = QPixmap(os.path.join(getConfig('ericPixDir'), 'eric_small.png')) |
222 ericPic = QPixmap( |
|
223 os.path.join(getConfig('ericPixDir'), 'eric_small.png')) |
218 self.emptyLabel = QLabel() |
224 self.emptyLabel = QLabel() |
219 self.emptyLabel.setPixmap(ericPic) |
225 self.emptyLabel.setPixmap(ericPic) |
220 self.emptyLabel.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter) |
226 self.emptyLabel.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter) |
221 super(TabWidget, self).addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "") |
227 super(TabWidget, self).addTab(self.emptyLabel, |
|
228 UI.PixmapCache.getIcon("empty.png"), "") |
222 |
229 |
223 def __initMenu(self): |
230 def __initMenu(self): |
224 """ |
231 """ |
225 Private method to initialize the tab context menu. |
232 Private method to initialize the tab context menu. |
226 """ |
233 """ |
239 self.trUtf8('Move Last'), self.__contextMenuMoveLast) |
246 self.trUtf8('Move Last'), self.__contextMenuMoveLast) |
240 self.__menu.addSeparator() |
247 self.__menu.addSeparator() |
241 self.__menu.addAction(UI.PixmapCache.getIcon("tabClose.png"), |
248 self.__menu.addAction(UI.PixmapCache.getIcon("tabClose.png"), |
242 self.trUtf8('Close'), self.__contextMenuClose) |
249 self.trUtf8('Close'), self.__contextMenuClose) |
243 self.closeOthersMenuAct = self.__menu.addAction( |
250 self.closeOthersMenuAct = self.__menu.addAction( |
244 UI.PixmapCache.getIcon("tabCloseOther.png"), self.trUtf8("Close Others"), |
251 UI.PixmapCache.getIcon("tabCloseOther.png"), |
245 self.__contextMenuCloseOthers) |
252 self.trUtf8("Close Others"), self.__contextMenuCloseOthers) |
246 self.__menu.addAction(self.trUtf8('Close All'), self.__contextMenuCloseAll) |
253 self.__menu.addAction( |
|
254 self.trUtf8('Close All'), self.__contextMenuCloseAll) |
247 self.__menu.addSeparator() |
255 self.__menu.addSeparator() |
248 self.saveMenuAct = \ |
256 self.saveMenuAct = \ |
249 self.__menu.addAction(UI.PixmapCache.getIcon("fileSave.png"), |
257 self.__menu.addAction(UI.PixmapCache.getIcon("fileSave.png"), |
250 self.trUtf8('Save'), self.__contextMenuSave) |
258 self.trUtf8('Save'), self.__contextMenuSave) |
251 self.__menu.addAction(UI.PixmapCache.getIcon("fileSaveAs.png"), |
259 self.__menu.addAction(UI.PixmapCache.getIcon("fileSaveAs.png"), |
258 self.__contextMenuOpenRejections) |
266 self.__contextMenuOpenRejections) |
259 self.__menu.addSeparator() |
267 self.__menu.addSeparator() |
260 self.__menu.addAction(UI.PixmapCache.getIcon("print.png"), |
268 self.__menu.addAction(UI.PixmapCache.getIcon("print.png"), |
261 self.trUtf8('Print'), self.__contextMenuPrintFile) |
269 self.trUtf8('Print'), self.__contextMenuPrintFile) |
262 self.__menu.addSeparator() |
270 self.__menu.addSeparator() |
263 self.copyPathAct = self.__menu.addAction(self.trUtf8("Copy Path to Clipboard"), |
271 self.copyPathAct = self.__menu.addAction( |
|
272 self.trUtf8("Copy Path to Clipboard"), |
264 self.__contextMenuCopyPathToClipboard) |
273 self.__contextMenuCopyPathToClipboard) |
265 |
274 |
266 def __showContextMenu(self, coord, index): |
275 def __showContextMenu(self, coord, index): |
267 """ |
276 """ |
268 Private slot to show the tab context menu. |
277 Private slot to show the tab context menu. |
271 @param index index of the tab the menu is requested for (integer) |
280 @param index index of the tab the menu is requested for (integer) |
272 """ |
281 """ |
273 if self.editors: |
282 if self.editors: |
274 self.contextMenuEditor = self.widget(index).getEditor() |
283 self.contextMenuEditor = self.widget(index).getEditor() |
275 if self.contextMenuEditor: |
284 if self.contextMenuEditor: |
276 self.saveMenuAct.setEnabled(self.contextMenuEditor.isModified()) |
285 self.saveMenuAct.setEnabled( |
|
286 self.contextMenuEditor.isModified()) |
277 fileName = self.contextMenuEditor.getFileName() |
287 fileName = self.contextMenuEditor.getFileName() |
278 self.copyPathAct.setEnabled(bool(fileName)) |
288 self.copyPathAct.setEnabled(bool(fileName)) |
279 if fileName: |
289 if fileName: |
280 rej = "{0}.rej".format(fileName) |
290 rej = "{0}.rej".format(fileName) |
281 self.openRejectionsMenuAct.setEnabled(os.path.exists(rej)) |
291 self.openRejectionsMenuAct.setEnabled(os.path.exists(rej)) |
381 |
391 |
382 def __captionChange(self, cap, editor): |
392 def __captionChange(self, cap, editor): |
383 """ |
393 """ |
384 Private slot to handle Caption change signals from the editor. |
394 Private slot to handle Caption change signals from the editor. |
385 |
395 |
386 Updates the tab text and tooltip text to reflect the new caption information. |
396 Updates the tab text and tooltip text to reflect the new caption |
|
397 information. |
387 |
398 |
388 @param cap Caption for the editor |
399 @param cap Caption for the editor |
389 @param editor Editor to update the caption for |
400 @param editor Editor to update the caption for |
390 """ |
401 """ |
391 fn = editor.getFileName() |
402 fn = editor.getFileName() |
393 if Preferences.getUI("TabViewManagerFilenameOnly"): |
404 if Preferences.getUI("TabViewManagerFilenameOnly"): |
394 txt = os.path.basename(fn) |
405 txt = os.path.basename(fn) |
395 else: |
406 else: |
396 txt = e5App().getObject("Project").getRelativePath(fn) |
407 txt = e5App().getObject("Project").getRelativePath(fn) |
397 |
408 |
398 maxFileNameChars = Preferences.getUI("TabViewManagerFilenameLength") |
409 maxFileNameChars = Preferences.getUI( |
|
410 "TabViewManagerFilenameLength") |
399 if len(txt) > maxFileNameChars: |
411 if len(txt) > maxFileNameChars: |
400 txt = "...{0}".format(txt[-maxFileNameChars:]) |
412 txt = "...{0}".format(txt[-maxFileNameChars:]) |
401 if editor.isReadOnly(): |
413 if editor.isReadOnly(): |
402 txt = self.trUtf8("{0} (ro)").format(txt) |
414 txt = self.trUtf8("{0} (ro)").format(txt) |
403 |
415 |
412 Private slot to handle a change of the current editor's cursor line. |
424 Private slot to handle a change of the current editor's cursor line. |
413 |
425 |
414 @param lineno line number of the current editor's cursor (zero based) |
426 @param lineno line number of the current editor's cursor (zero based) |
415 """ |
427 """ |
416 editor = self.sender() |
428 editor = self.sender() |
417 if editor: |
429 if editor and isinstance(editor, QScintilla.Editor.Editor): |
418 fn = editor.getFileName() |
430 fn = editor.getFileName() |
419 if fn: |
431 if fn: |
420 self.vm.editorLineChanged.emit(fn, lineno + 1) |
432 self.vm.editorLineChanged.emit(fn, lineno + 1) |
421 |
433 |
422 def removeWidget(self, object): |
434 def removeWidget(self, object): |
434 index = self.indexOf(object) |
446 index = self.indexOf(object) |
435 if index > -1: |
447 if index > -1: |
436 self.removeTab(index) |
448 self.removeTab(index) |
437 |
449 |
438 if not self.editors: |
450 if not self.editors: |
439 super(TabWidget, self).addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "") |
451 super(TabWidget, self).addTab( |
|
452 self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "") |
440 self.emptyLabel.show() |
453 self.emptyLabel.show() |
441 if self.closeButton: |
454 if self.closeButton: |
442 self.closeButton.setEnabled(False) |
455 self.closeButton.setEnabled(False) |
443 else: |
456 else: |
444 self.setTabsClosable(False) |
457 self.setTabsClosable(False) |
482 @param targetIndex index position to place it to (integer) |
495 @param targetIndex index position to place it to (integer) |
483 """ |
496 """ |
484 tw = self.vm.getTabWidgetById(int(sourceId)) |
497 tw = self.vm.getTabWidgetById(int(sourceId)) |
485 if tw is not None: |
498 if tw is not None: |
486 editor = tw.widget(sourceIndex).getEditor() |
499 editor = tw.widget(sourceIndex).getEditor() |
487 newEditor, assembly = self.vm.cloneEditor(editor, editor.getFileType(), |
500 newEditor, assembly = self.vm.cloneEditor( |
488 editor.getFileName()) |
501 editor, editor.getFileType(), editor.getFileName()) |
489 self.vm.insertView(assembly, self, targetIndex, |
502 self.vm.insertView(assembly, self, targetIndex, |
490 editor.getFileName(), editor.getNoName()) |
503 editor.getFileName(), editor.getNoName()) |
491 |
504 |
492 def __copyTab(self, sourceIndex, targetIndex): |
505 def __copyTab(self, sourceIndex, targetIndex): |
493 """ |
506 """ |
596 """ |
609 """ |
597 self.vm.saveEditorsList(self.editors) |
610 self.vm.saveEditorsList(self.editors) |
598 |
611 |
599 def __contextMenuOpenRejections(self): |
612 def __contextMenuOpenRejections(self): |
600 """ |
613 """ |
601 Private slot to open a rejections file associated with the selected tab. |
614 Private slot to open a rejections file associated with the selected |
|
615 tab. |
602 """ |
616 """ |
603 if self.contextMenuEditor: |
617 if self.contextMenuEditor: |
604 fileName = self.contextMenuEditor.getFileName() |
618 fileName = self.contextMenuEditor.getFileName() |
605 if fileName: |
619 if fileName: |
606 rej = "{0}.rej".format(fileName) |
620 rej = "{0}.rej".format(fileName) |
614 if self.contextMenuEditor: |
628 if self.contextMenuEditor: |
615 self.vm.printEditor(self.contextMenuEditor) |
629 self.vm.printEditor(self.contextMenuEditor) |
616 |
630 |
617 def __contextMenuCopyPathToClipboard(self): |
631 def __contextMenuCopyPathToClipboard(self): |
618 """ |
632 """ |
619 Private method to copy the file name of the selected tab to the clipboard. |
633 Private method to copy the file name of the selected tab to the |
|
634 clipboard. |
620 """ |
635 """ |
621 if self.contextMenuEditor: |
636 if self.contextMenuEditor: |
622 fn = self.contextMenuEditor.getFileName() |
637 fn = self.contextMenuEditor.getFileName() |
623 if fn: |
638 if fn: |
624 cb = QApplication.clipboard() |
639 cb = QApplication.clipboard() |
681 @signal editorChangedEd(Editor) emitted when the current editor has changed |
696 @signal editorChangedEd(Editor) emitted when the current editor has changed |
682 @signal lastEditorClosed() emitted after the last editor window was closed |
697 @signal lastEditorClosed() emitted after the last editor window was closed |
683 @signal editorOpened(str) emitted after an editor window was opened |
698 @signal editorOpened(str) emitted after an editor window was opened |
684 @signal editorOpenedEd(Editor) emitted after an editor window was opened |
699 @signal editorOpenedEd(Editor) emitted after an editor window was opened |
685 @signal editorClosed(str) emitted just before an editor window gets closed |
700 @signal editorClosed(str) emitted just before an editor window gets closed |
686 @signal editorClosedEd(Editor) emitted just before an editor window gets closed |
701 @signal editorClosedEd(Editor) emitted just before an editor window gets |
|
702 closed |
687 @signal editorSaved(str) emitted after an editor window was saved |
703 @signal editorSaved(str) emitted after an editor window was saved |
688 @signal checkActions(Editor) emitted when some actions should be checked |
704 @signal checkActions(Editor) emitted when some actions should be checked |
689 for their status |
705 for their status |
690 @signal cursorChanged(Editor) emitted after the cursor position of the active |
706 @signal cursorChanged(Editor) emitted after the cursor position of the |
691 window has changed |
707 active window has changed |
692 @signal breakpointToggled(Editor) emitted when a breakpoint is toggled. |
708 @signal breakpointToggled(Editor) emitted when a breakpoint is toggled. |
693 @signal bookmarkToggled(Editor) emitted when a bookmark is toggled. |
709 @signal bookmarkToggled(Editor) emitted when a bookmark is toggled. |
694 @signal syntaxerrorToggled(Editor) emitted when a syntax error is toggled. |
710 @signal syntaxerrorToggled(Editor) emitted when a syntax error is toggled. |
695 @signal previewStateChanged(bool) emitted to signal a change in the preview state |
711 @signal previewStateChanged(bool) emitted to signal a change in the |
|
712 preview state |
696 @signal editorLanguageChanged(Editor) emitted to signal a change of an |
713 @signal editorLanguageChanged(Editor) emitted to signal a change of an |
697 editors language |
714 editors language |
698 @signal editorTextChanged(Editor) emitted to signal a change of an editor's text |
715 @signal editorTextChanged(Editor) emitted to signal a change of an |
699 @signal editorLineChanged(str,int) emitted to signal a change of an editor's |
716 editor's text |
700 current line (line is given one based) |
717 @signal editorLineChanged(str,int) emitted to signal a change of an |
|
718 editor's current line (line is given one based) |
701 """ |
719 """ |
702 changeCaption = pyqtSignal(str) |
720 changeCaption = pyqtSignal(str) |
703 editorChanged = pyqtSignal(str) |
721 editorChanged = pyqtSignal(str) |
704 editorChangedEd = pyqtSignal(Editor) |
722 editorChangedEd = pyqtSignal(Editor) |
705 lastEditorClosed = pyqtSignal() |
723 lastEditorClosed = pyqtSignal() |
721 def __init__(self, parent): |
739 def __init__(self, parent): |
722 """ |
740 """ |
723 Constructor |
741 Constructor |
724 |
742 |
725 @param parent parent widget (QWidget) |
743 @param parent parent widget (QWidget) |
726 @param ui reference to the main user interface |
|
727 @param dbs reference to the debug server object |
|
728 """ |
744 """ |
729 self.tabWidgets = [] |
745 self.tabWidgets = [] |
730 |
746 |
731 QSplitter.__init__(self, parent) |
747 QSplitter.__init__(self, parent) |
732 ViewManager.__init__(self) |
748 ViewManager.__init__(self) |
739 tw.installEventFilter(self) |
755 tw.installEventFilter(self) |
740 tw.tabBar().installEventFilter(self) |
756 tw.tabBar().installEventFilter(self) |
741 self.setOrientation(Qt.Vertical) |
757 self.setOrientation(Qt.Vertical) |
742 self.__inRemoveView = False |
758 self.__inRemoveView = False |
743 |
759 |
744 self.maxFileNameChars = Preferences.getUI("TabViewManagerFilenameLength") |
760 self.maxFileNameChars = Preferences.getUI( |
|
761 "TabViewManagerFilenameLength") |
745 self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly") |
762 self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly") |
746 |
763 |
747 def canCascade(self): |
764 def canCascade(self): |
748 """ |
765 """ |
749 Public method to signal if cascading of managed windows is available. |
766 Public method to signal if cascading of managed windows is available. |
780 """ |
797 """ |
781 pass |
798 pass |
782 |
799 |
783 def _removeAllViews(self): |
800 def _removeAllViews(self): |
784 """ |
801 """ |
785 Protected method to remove all views (i.e. windows) |
802 Protected method to remove all views (i.e. windows). |
786 """ |
803 """ |
787 for win in self.editors: |
804 for win in self.editors: |
788 self._removeView(win) |
805 self._removeView(win) |
789 |
806 |
790 def _removeView(self, win): |
807 def _removeView(self, win): |
791 """ |
808 """ |
792 Protected method to remove a view (i.e. window) |
809 Protected method to remove a view (i.e. window). |
793 |
810 |
794 @param win editor window to be removed |
811 @param win editor window to be removed |
795 """ |
812 """ |
796 self.__inRemoveView = True |
813 self.__inRemoveView = True |
797 for tw in self.tabWidgets: |
814 for tw in self.tabWidgets: |
802 self.__inRemoveView = False |
819 self.__inRemoveView = False |
803 |
820 |
804 # if this was the last editor in this view, switch to the next, that |
821 # if this was the last editor in this view, switch to the next, that |
805 # still has open editors |
822 # still has open editors |
806 for i in list(range(self.tabWidgets.index(tw), -1, -1)) + \ |
823 for i in list(range(self.tabWidgets.index(tw), -1, -1)) + \ |
807 list(range(self.tabWidgets.index(tw) + 1, len(self.tabWidgets))): |
824 list(range(self.tabWidgets.index(tw) + 1, |
|
825 len(self.tabWidgets))): |
808 if self.tabWidgets[i].hasEditors(): |
826 if self.tabWidgets[i].hasEditors(): |
809 self.currentTabWidget.showIndicator(False) |
827 self.currentTabWidget.showIndicator(False) |
810 self.currentTabWidget = self.tabWidgets[i] |
828 self.currentTabWidget = self.tabWidgets[i] |
811 self.currentTabWidget.showIndicator(True) |
829 self.currentTabWidget.showIndicator(True) |
812 self.activeWindow().setFocus() |
830 self.activeWindow().setFocus() |
822 self.changeCaption.emit("") |
840 self.changeCaption.emit("") |
823 self.editorChangedEd.emit(aw) |
841 self.editorChangedEd.emit(aw) |
824 |
842 |
825 def _addView(self, win, fn=None, noName=""): |
843 def _addView(self, win, fn=None, noName=""): |
826 """ |
844 """ |
827 Protected method to add a view (i.e. window) |
845 Protected method to add a view (i.e. window). |
828 |
846 |
829 @param win editor assembly to be added |
847 @param win editor assembly to be added |
830 @param fn filename of this editor (string) |
848 @param fn filename of this editor (string) |
831 @param noName name to be used for an unnamed editor (string) |
849 @param noName name to be used for an unnamed editor (string) |
832 """ |
850 """ |
860 self.changeCaption.emit("") |
878 self.changeCaption.emit("") |
861 self.editorChangedEd.emit(editor) |
879 self.editorChangedEd.emit(editor) |
862 |
880 |
863 def insertView(self, win, tabWidget, index, fn=None, noName=""): |
881 def insertView(self, win, tabWidget, index, fn=None, noName=""): |
864 """ |
882 """ |
865 Protected method to add a view (i.e. window) |
883 Protected method to add a view (i.e. window). |
866 |
884 |
867 @param win editor assembly to be inserted |
885 @param win editor assembly to be inserted |
868 @param tabWidget reference to the tab widget to insert the editor into (TabWidget) |
886 @param tabWidget reference to the tab widget to insert the editor into |
|
887 (TabWidget) |
869 @param index index position to insert at (integer) |
888 @param index index position to insert at (integer) |
870 @param fn filename of this editor (string) |
889 @param fn filename of this editor (string) |
871 @param noName name to be used for an unnamed editor (string) |
890 @param noName name to be used for an unnamed editor (string) |
872 """ |
891 """ |
873 editor = win.getEditor() |
892 editor = win.getEditor() |
902 self._modificationStatusChanged(editor.isModified(), editor) |
921 self._modificationStatusChanged(editor.isModified(), editor) |
903 self._checkActions(editor) |
922 self._checkActions(editor) |
904 |
923 |
905 def _showView(self, win, fn=None): |
924 def _showView(self, win, fn=None): |
906 """ |
925 """ |
907 Protected method to show a view (i.e. window) |
926 Protected method to show a view (i.e. window). |
908 |
927 |
909 @param win editor assembly to be shown |
928 @param win editor assembly to be shown |
910 @param fn filename of this editor (string) |
929 @param fn filename of this editor (string) |
911 """ |
930 """ |
912 win.show() |
931 win.show() |
1023 tw.tabBar().installEventFilter(self) |
1043 tw.tabBar().installEventFilter(self) |
1024 if self.orientation() == Qt.Horizontal: |
1044 if self.orientation() == Qt.Horizontal: |
1025 size = self.width() |
1045 size = self.width() |
1026 else: |
1046 else: |
1027 size = self.height() |
1047 size = self.height() |
1028 self.setSizes([int(size / len(self.tabWidgets))] * len(self.tabWidgets)) |
1048 self.setSizes( |
|
1049 [int(size / len(self.tabWidgets))] * len(self.tabWidgets)) |
1029 self.splitRemoveAct.setEnabled(True) |
1050 self.splitRemoveAct.setEnabled(True) |
1030 self.nextSplitAct.setEnabled(True) |
1051 self.nextSplitAct.setEnabled(True) |
1031 self.prevSplitAct.setEnabled(True) |
1052 self.prevSplitAct.setEnabled(True) |
1032 |
1053 |
1033 def removeSplit(self): |
1054 def removeSplit(self): |
1124 fn = editor.getFileName() |
1145 fn = editor.getFileName() |
1125 if fn: |
1146 if fn: |
1126 self.changeCaption.emit(fn) |
1147 self.changeCaption.emit(fn) |
1127 if not self.__inRemoveView: |
1148 if not self.__inRemoveView: |
1128 self.editorChanged.emit(fn) |
1149 self.editorChanged.emit(fn) |
1129 self.editorLineChanged.emit(fn, editor.getCursorPosition()[0] + 1) |
1150 self.editorLineChanged.emit( |
|
1151 fn, editor.getCursorPosition()[0] + 1) |
1130 else: |
1152 else: |
1131 self.changeCaption.emit("") |
1153 self.changeCaption.emit("") |
1132 self.editorChangedEd.emit(editor) |
1154 self.editorChangedEd.emit(editor) |
1133 |
1155 |
1134 def eventFilter(self, watched, event): |
1156 def eventFilter(self, watched, event): |
1148 elif isinstance(watched, QTabBar): |
1170 elif isinstance(watched, QTabBar): |
1149 switched = watched.parent() is not self.currentTabWidget |
1171 switched = watched.parent() is not self.currentTabWidget |
1150 self.currentTabWidget = watched.parent() |
1172 self.currentTabWidget = watched.parent() |
1151 if switched: |
1173 if switched: |
1152 index = self.currentTabWidget.selectTab(event.pos()) |
1174 index = self.currentTabWidget.selectTab(event.pos()) |
1153 switched = self.currentTabWidget.widget(index) is self.activeWindow() |
1175 switched = self.currentTabWidget.widget(index) is \ |
|
1176 self.activeWindow() |
1154 elif isinstance(watched, QScintilla.Editor.Editor): |
1177 elif isinstance(watched, QScintilla.Editor.Editor): |
1155 for tw in self.tabWidgets: |
1178 for tw in self.tabWidgets: |
1156 if tw.hasEditor(watched): |
1179 if tw.hasEditor(watched): |
1157 switched = tw is not self.currentTabWidget |
1180 switched = tw is not self.currentTabWidget |
1158 self.currentTabWidget = tw |
1181 self.currentTabWidget = tw |
1166 fn = aw.getFileName() |
1189 fn = aw.getFileName() |
1167 if fn: |
1190 if fn: |
1168 self.changeCaption.emit(fn) |
1191 self.changeCaption.emit(fn) |
1169 if switched: |
1192 if switched: |
1170 self.editorChanged.emit(fn) |
1193 self.editorChanged.emit(fn) |
1171 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1) |
1194 self.editorLineChanged.emit( |
|
1195 fn, aw.getCursorPosition()[0] + 1) |
1172 else: |
1196 else: |
1173 self.changeCaption.emit("") |
1197 self.changeCaption.emit("") |
1174 self.editorChangedEd.emit(aw) |
1198 self.editorChangedEd.emit(aw) |
1175 |
1199 |
1176 return False |
1200 return False |
1179 """ |
1203 """ |
1180 Public slot to handle the preferencesChanged signal. |
1204 Public slot to handle the preferencesChanged signal. |
1181 """ |
1205 """ |
1182 ViewManager.preferencesChanged(self) |
1206 ViewManager.preferencesChanged(self) |
1183 |
1207 |
1184 self.maxFileNameChars = Preferences.getUI("TabViewManagerFilenameLength") |
1208 self.maxFileNameChars = Preferences.getUI( |
|
1209 "TabViewManagerFilenameLength") |
1185 self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly") |
1210 self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly") |
1186 |
1211 |
1187 for tabWidget in self.tabWidgets: |
1212 for tabWidget in self.tabWidgets: |
1188 for index in range(tabWidget.count()): |
1213 for index in range(tabWidget.count()): |
1189 editor = tabWidget.widget(index) |
1214 editor = tabWidget.widget(index) |
1191 fn = editor.getFileName() |
1216 fn = editor.getFileName() |
1192 if fn: |
1217 if fn: |
1193 if self.filenameOnly: |
1218 if self.filenameOnly: |
1194 txt = os.path.basename(fn) |
1219 txt = os.path.basename(fn) |
1195 else: |
1220 else: |
1196 txt = e5App().getObject("Project").getRelativePath(fn) |
1221 txt = e5App().getObject("Project")\ |
|
1222 .getRelativePath(fn) |
1197 if len(txt) > self.maxFileNameChars: |
1223 if len(txt) > self.maxFileNameChars: |
1198 txt = "...{0}".format(txt[-self.maxFileNameChars:]) |
1224 txt = "...{0}".format(txt[-self.maxFileNameChars:]) |
1199 if not QFileInfo(fn).isWritable(): |
1225 if not QFileInfo(fn).isWritable(): |
1200 txt = self.trUtf8("{0} (ro)").format(txt) |
1226 txt = self.trUtf8("{0} (ro)").format(txt) |
1201 tabWidget.setTabText(index, txt) |
1227 tabWidget.setTabText(index, txt) |