46 tabMoveRequested = pyqtSignal(int, int) |
47 tabMoveRequested = pyqtSignal(int, int) |
47 tabRelocateRequested = pyqtSignal(int, int, int) |
48 tabRelocateRequested = pyqtSignal(int, int, int) |
48 tabCopyRequested = pyqtSignal(int, int, int) |
49 tabCopyRequested = pyqtSignal(int, int, int) |
49 tabCopyRequested = pyqtSignal(int, int) |
50 tabCopyRequested = pyqtSignal(int, int) |
50 |
51 |
51 def __init__(self, parent = None): |
52 def __init__(self, parent=None): |
52 """ |
53 """ |
53 Constructor |
54 Constructor |
54 |
55 |
55 @param parent reference to the parent widget (QWidget) |
56 @param parent reference to the parent widget (QWidget) |
56 """ |
57 """ |
82 mimeData = QMimeData() |
83 mimeData = QMimeData() |
83 index = self.tabAt(event.pos()) |
84 index = self.tabAt(event.pos()) |
84 mimeData.setText(self.tabText(index)) |
85 mimeData.setText(self.tabText(index)) |
85 mimeData.setData("action", "tab-reordering") |
86 mimeData.setData("action", "tab-reordering") |
86 mimeData.setData("tabbar-id", QByteArray.number(id(self))) |
87 mimeData.setData("tabbar-id", QByteArray.number(id(self))) |
87 mimeData.setData("source-index", |
88 mimeData.setData("source-index", |
88 QByteArray.number(self.tabAt(self.__dragStartPos))) |
89 QByteArray.number(self.tabAt(self.__dragStartPos))) |
89 mimeData.setData("tabwidget-id", QByteArray.number(id(self.parentWidget()))) |
90 mimeData.setData("tabwidget-id", QByteArray.number(id(self.parentWidget()))) |
90 drag.setMimeData(mimeData) |
91 drag.setMimeData(mimeData) |
91 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): |
92 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): |
92 drag.exec_(Qt.DropActions(Qt.CopyAction)) |
93 drag.exec_(Qt.DropActions(Qt.CopyAction)) |
135 event.acceptProposedAction() |
136 event.acceptProposedAction() |
136 elif event.proposedAction() == Qt.CopyAction: |
137 elif event.proposedAction() == Qt.CopyAction: |
137 self.tabCopyRequested.emit(fromIndex, toIndex) |
138 self.tabCopyRequested.emit(fromIndex, toIndex) |
138 event.acceptProposedAction() |
139 event.acceptProposedAction() |
139 E5WheelTabBar.dropEvent(self, event) |
140 E5WheelTabBar.dropEvent(self, event) |
|
141 |
140 |
142 |
141 class TabWidget(E5TabWidget): |
143 class TabWidget(E5TabWidget): |
142 """ |
144 """ |
143 Class implementing a custimized tab widget. |
145 Class implementing a custimized tab widget. |
144 """ |
146 """ |
228 self.trUtf8('Move Last'), self.__contextMenuMoveLast) |
230 self.trUtf8('Move Last'), self.__contextMenuMoveLast) |
229 self.__menu.addSeparator() |
231 self.__menu.addSeparator() |
230 self.__menu.addAction(UI.PixmapCache.getIcon("tabClose.png"), |
232 self.__menu.addAction(UI.PixmapCache.getIcon("tabClose.png"), |
231 self.trUtf8('Close'), self.__contextMenuClose) |
233 self.trUtf8('Close'), self.__contextMenuClose) |
232 self.closeOthersMenuAct = self.__menu.addAction( |
234 self.closeOthersMenuAct = self.__menu.addAction( |
233 UI.PixmapCache.getIcon("tabCloseOther.png"), self.trUtf8("Close Others"), |
235 UI.PixmapCache.getIcon("tabCloseOther.png"), self.trUtf8("Close Others"), |
234 self.__contextMenuCloseOthers) |
236 self.__contextMenuCloseOthers) |
235 self.__menu.addAction(self.trUtf8('Close All'), self.__contextMenuCloseAll) |
237 self.__menu.addAction(self.trUtf8('Close All'), self.__contextMenuCloseAll) |
236 self.__menu.addSeparator() |
238 self.__menu.addSeparator() |
237 self.saveMenuAct = \ |
239 self.saveMenuAct = \ |
238 self.__menu.addAction(UI.PixmapCache.getIcon("fileSave.png"), |
240 self.__menu.addAction(UI.PixmapCache.getIcon("fileSave.png"), |
243 self.trUtf8('Save All'), self.__contextMenuSaveAll) |
245 self.trUtf8('Save All'), self.__contextMenuSaveAll) |
244 self.__menu.addSeparator() |
246 self.__menu.addSeparator() |
245 self.__menu.addAction(UI.PixmapCache.getIcon("print.png"), |
247 self.__menu.addAction(UI.PixmapCache.getIcon("print.png"), |
246 self.trUtf8('Print'), self.__contextMenuPrintFile) |
248 self.trUtf8('Print'), self.__contextMenuPrintFile) |
247 self.__menu.addSeparator() |
249 self.__menu.addSeparator() |
248 self.copyPathAct = self.__menu.addAction(self.trUtf8("Copy Path to Clipboard"), |
250 self.copyPathAct = self.__menu.addAction(self.trUtf8("Copy Path to Clipboard"), |
249 self.__contextMenuCopyPathToClipboard) |
251 self.__contextMenuCopyPathToClipboard) |
250 |
252 |
251 def __showContextMenu(self, coord, index): |
253 def __showContextMenu(self, coord, index): |
252 """ |
254 """ |
253 Private slot to show the tab context menu. |
255 Private slot to show the tab context menu. |
276 """ |
278 """ |
277 Private slot to show the navigation button menu. |
279 Private slot to show the navigation button menu. |
278 """ |
280 """ |
279 self.__navigationMenu.clear() |
281 self.__navigationMenu.clear() |
280 for index in range(self.count()): |
282 for index in range(self.count()): |
281 act = self.__navigationMenu.addAction(self.tabIcon(index), |
283 act = self.__navigationMenu.addAction(self.tabIcon(index), |
282 self.tabText(index)) |
284 self.tabText(index)) |
283 act.setData(index) |
285 act.setData(index) |
284 |
286 |
285 def __navigationMenuTriggered(self, act): |
287 def __navigationMenuTriggered(self, act): |
286 """ |
288 """ |
332 @param index index position for the new tab (integer) |
334 @param index index position for the new tab (integer) |
333 @param editor the editor object to be added (QScintilla.Editor.Editor) |
335 @param editor the editor object to be added (QScintilla.Editor.Editor) |
334 @param title title for the new tab (string) |
336 @param title title for the new tab (string) |
335 @return index of the inserted tab (integer) |
337 @return index of the inserted tab (integer) |
336 """ |
338 """ |
337 newIndex = E5TabWidget.insertTab(self, index, editor, |
339 newIndex = E5TabWidget.insertTab(self, index, editor, |
338 UI.PixmapCache.getIcon("empty.png"), |
340 UI.PixmapCache.getIcon("empty.png"), |
339 title) |
341 title) |
340 if self.closeButton: |
342 if self.closeButton: |
341 self.closeButton.setEnabled(True) |
343 self.closeButton.setEnabled(True) |
342 else: |
344 else: |
343 self.setTabsClosable(True) |
345 self.setTabsClosable(True) |
353 |
355 |
354 return newIndex |
356 return newIndex |
355 |
357 |
356 def __captionChange(self, cap, editor): |
358 def __captionChange(self, cap, editor): |
357 """ |
359 """ |
358 Private method to handle Caption change signals from the editor. |
360 Private method to handle Caption change signals from the editor. |
359 |
361 |
360 Updates the tab text and tooltip text to reflect the new caption information. |
362 Updates the tab text and tooltip text to reflect the new caption information. |
361 |
363 |
362 @param cap Caption for the editor |
364 @param cap Caption for the editor |
363 @param editor Editor to update the caption for |
365 @param editor Editor to update the caption for |
393 if isinstance(object, QScintilla.Editor.Editor): |
395 if isinstance(object, QScintilla.Editor.Editor): |
394 object.captionChanged.disconnect(self.__captionChange) |
396 object.captionChanged.disconnect(self.__captionChange) |
395 self.editors.remove(object) |
397 self.editors.remove(object) |
396 |
398 |
397 if not self.editors: |
399 if not self.editors: |
398 E5TabWidget.addTab(self, self.emptyLabel, |
400 E5TabWidget.addTab(self, self.emptyLabel, |
399 UI.PixmapCache.getIcon("empty.png"), "") |
401 UI.PixmapCache.getIcon("empty.png"), "") |
400 self.emptyLabel.show() |
402 self.emptyLabel.show() |
401 if self.closeButton: |
403 if self.closeButton: |
402 self.closeButton.setEnabled(False) |
404 self.closeButton.setEnabled(False) |
403 else: |
405 else: |
442 @param targetIndex index position to place it to (integer) |
444 @param targetIndex index position to place it to (integer) |
443 """ |
445 """ |
444 tw = self.vm.getTabWidgetById(sourceId) |
446 tw = self.vm.getTabWidgetById(sourceId) |
445 if tw is not None: |
447 if tw is not None: |
446 editor = tw.widget(sourceIndex) |
448 editor = tw.widget(sourceIndex) |
447 newEditor = self.vm.cloneEditor(editor, editor.getFileType(), |
449 newEditor = self.vm.cloneEditor(editor, editor.getFileType(), |
448 editor.getFileName()) |
450 editor.getFileName()) |
449 self.vm.insertView(newEditor, self, targetIndex, |
451 self.vm.insertView(newEditor, self, targetIndex, |
450 editor.getFileName(), editor.getNoName()) |
452 editor.getFileName(), editor.getNoName()) |
451 |
453 |
452 def copyTab(self, sourceIndex, targetIndex): |
454 def copyTab(self, sourceIndex, targetIndex): |
453 """ |
455 """ |
454 Public method to copy an editor. |
456 Public method to copy an editor. |
455 |
457 |
456 @param sourceIndex index of the tab (integer) |
458 @param sourceIndex index of the tab (integer) |
457 @param targetIndex index position to place it to (integer) |
459 @param targetIndex index position to place it to (integer) |
458 """ |
460 """ |
459 editor = self.widget(sourceIndex) |
461 editor = self.widget(sourceIndex) |
460 newEditor = self.vm.cloneEditor(editor, editor.getFileType(), |
462 newEditor = self.vm.cloneEditor(editor, editor.getFileType(), |
461 editor.getFileName()) |
463 editor.getFileName()) |
462 self.vm.insertView(newEditor, self, targetIndex, |
464 self.vm.insertView(newEditor, self, targetIndex, |
463 editor.getFileName(), editor.getNoName()) |
465 editor.getFileName(), editor.getNoName()) |
464 |
466 |
465 def currentWidget(self): |
467 def currentWidget(self): |
466 """ |
468 """ |
467 Overridden method to return a reference to the current page. |
469 Overridden method to return a reference to the current page. |
733 self.changeCaption.emit(fn) |
736 self.changeCaption.emit(fn) |
734 self.editorChanged.emit(fn) |
737 self.editorChanged.emit(fn) |
735 else: |
738 else: |
736 self.changeCaption.emit("") |
739 self.changeCaption.emit("") |
737 |
740 |
738 def _addView(self, win, fn = None, noName = ""): |
741 def _addView(self, win, fn=None, noName=""): |
739 """ |
742 """ |
740 Protected method to add a view (i.e. window) |
743 Protected method to add a view (i.e. window) |
741 |
744 |
742 @param win editor window to be added |
745 @param win editor window to be added |
743 @param fn filename of this editor (string) |
746 @param fn filename of this editor (string) |
768 self.changeCaption.emit(fn) |
771 self.changeCaption.emit(fn) |
769 self.editorChanged.emit(fn) |
772 self.editorChanged.emit(fn) |
770 else: |
773 else: |
771 self.changeCaption.emit("") |
774 self.changeCaption.emit("") |
772 |
775 |
773 def insertView(self, win, tabWidget, index, fn = None, noName = ""): |
776 def insertView(self, win, tabWidget, index, fn=None, noName=""): |
774 """ |
777 """ |
775 Protected method to add a view (i.e. window) |
778 Protected method to add a view (i.e. window) |
776 |
779 |
777 @param win editor window to be added |
780 @param win editor window to be added |
778 @param tabWidget reference to the tab widget to insert the editor into (TabWidget) |
781 @param tabWidget reference to the tab widget to insert the editor into (TabWidget) |
807 self.changeCaption.emit("") |
810 self.changeCaption.emit("") |
808 |
811 |
809 self._modificationStatusChanged(win.isModified(), win) |
812 self._modificationStatusChanged(win.isModified(), win) |
810 self._checkActions(win) |
813 self._checkActions(win) |
811 |
814 |
812 def _showView(self, win, fn = None): |
815 def _showView(self, win, fn=None): |
813 """ |
816 """ |
814 Protected method to show a view (i.e. window) |
817 Protected method to show a view (i.e. window) |
815 |
818 |
816 @param win editor window to be shown |
819 @param win editor window to be shown |
817 @param fn filename of this editor (string) |
820 @param fn filename of this editor (string) |
923 tw.tabBar().installEventFilter(self) |
926 tw.tabBar().installEventFilter(self) |
924 if self.orientation() == Qt.Horizontal: |
927 if self.orientation() == Qt.Horizontal: |
925 size = self.width() |
928 size = self.width() |
926 else: |
929 else: |
927 size = self.height() |
930 size = self.height() |
928 self.setSizes([int(size/len(self.tabWidgets))] * len(self.tabWidgets)) |
931 self.setSizes([int(size / len(self.tabWidgets))] * len(self.tabWidgets)) |
929 self.splitRemoveAct.setEnabled(True) |
932 self.splitRemoveAct.setEnabled(True) |
930 self.nextSplitAct.setEnabled(True) |
933 self.nextSplitAct.setEnabled(True) |
931 self.prevSplitAct.setEnabled(True) |
934 self.prevSplitAct.setEnabled(True) |
932 |
935 |
933 def removeSplit(self): |
936 def removeSplit(self): |