21 |
21 |
22 from ViewManager.ViewManager import ViewManager |
22 from ViewManager.ViewManager import ViewManager |
23 |
23 |
24 import QScintilla.Editor |
24 import QScintilla.Editor |
25 from QScintilla.Editor import Editor |
25 from QScintilla.Editor import Editor |
|
26 from QScintilla.EditorAssembly import EditorAssembly |
26 |
27 |
27 import UI.PixmapCache |
28 import UI.PixmapCache |
28 |
29 |
29 from E5Gui.E5TabWidget import E5TabWidget, E5WheelTabBar |
30 from E5Gui.E5TabWidget import E5TabWidget, E5WheelTabBar |
30 from E5Gui.E5Led import E5Led |
31 from E5Gui.E5Led import E5Led |
56 |
57 |
57 def __init__(self, parent=None): |
58 def __init__(self, parent=None): |
58 """ |
59 """ |
59 Constructor |
60 Constructor |
60 |
61 |
61 @param parent reference to the parent widget (QWidget) |
62 @param parent reference to the parent widget |
|
63 @type QWidget |
62 """ |
64 """ |
63 super(TabBar, self).__init__(parent) |
65 super(TabBar, self).__init__(parent) |
64 self.setAcceptDrops(True) |
66 self.setAcceptDrops(True) |
65 |
67 |
66 self.__dragStartPos = QPoint() |
68 self.__dragStartPos = QPoint() |
67 |
69 |
68 def mousePressEvent(self, event): |
70 def mousePressEvent(self, event): |
69 """ |
71 """ |
70 Protected method to handle mouse press events. |
72 Protected method to handle mouse press events. |
71 |
73 |
72 @param event reference to the mouse press event (QMouseEvent) |
74 @param event reference to the mouse press event |
|
75 @type QMouseEvent |
73 """ |
76 """ |
74 if event.button() == Qt.LeftButton: |
77 if event.button() == Qt.LeftButton: |
75 self.__dragStartPos = QPoint(event.pos()) |
78 self.__dragStartPos = QPoint(event.pos()) |
76 super(TabBar, self).mousePressEvent(event) |
79 super(TabBar, self).mousePressEvent(event) |
77 |
80 |
78 def mouseMoveEvent(self, event): |
81 def mouseMoveEvent(self, event): |
79 """ |
82 """ |
80 Protected method to handle mouse move events. |
83 Protected method to handle mouse move events. |
81 |
84 |
82 @param event reference to the mouse move event (QMouseEvent) |
85 @param event reference to the mouse move event |
|
86 @type QMouseEvent |
83 """ |
87 """ |
84 if event.buttons() == Qt.MouseButtons(Qt.LeftButton) and \ |
88 if event.buttons() == Qt.MouseButtons(Qt.LeftButton) and \ |
85 (event.pos() - self.__dragStartPos).manhattanLength() > \ |
89 (event.pos() - self.__dragStartPos).manhattanLength() > \ |
86 QApplication.startDragDistance(): |
90 QApplication.startDragDistance(): |
87 drag = QDrag(self) |
91 drag = QDrag(self) |
105 |
109 |
106 def dragEnterEvent(self, event): |
110 def dragEnterEvent(self, event): |
107 """ |
111 """ |
108 Protected method to handle drag enter events. |
112 Protected method to handle drag enter events. |
109 |
113 |
110 @param event reference to the drag enter event (QDragEnterEvent) |
114 @param event reference to the drag enter event |
|
115 @type QDragEnterEvent |
111 """ |
116 """ |
112 mimeData = event.mimeData() |
117 mimeData = event.mimeData() |
113 formats = mimeData.formats() |
118 formats = mimeData.formats() |
114 if "action" in formats and \ |
119 if "action" in formats and \ |
115 mimeData.data("action") == b"tab-reordering" and \ |
120 mimeData.data("action") == b"tab-reordering" and \ |
121 |
126 |
122 def dropEvent(self, event): |
127 def dropEvent(self, event): |
123 """ |
128 """ |
124 Protected method to handle drop events. |
129 Protected method to handle drop events. |
125 |
130 |
126 @param event reference to the drop event (QDropEvent) |
131 @param event reference to the drop event |
|
132 @type QDropEvent |
127 """ |
133 """ |
128 mimeData = event.mimeData() |
134 mimeData = event.mimeData() |
129 oldID = int(mimeData.data("tabbar-id")) |
135 oldID = int(mimeData.data("tabbar-id")) |
130 fromIndex = int(mimeData.data("source-index")) |
136 fromIndex = int(mimeData.data("source-index")) |
131 toIndex = self.tabAt(event.pos()) |
137 toIndex = self.tabAt(event.pos()) |
284 |
291 |
285 def __showContextMenu(self, coord, index): |
292 def __showContextMenu(self, coord, index): |
286 """ |
293 """ |
287 Private slot to show the tab context menu. |
294 Private slot to show the tab context menu. |
288 |
295 |
289 @param coord the position of the mouse pointer (QPoint) |
296 @param coord the position of the mouse pointer |
290 @param index index of the tab the menu is requested for (integer) |
297 @type QPoint |
|
298 @param index index of the tab the menu is requested for |
|
299 @type int |
291 """ |
300 """ |
292 if self.editors: |
301 if self.editors: |
293 self.contextMenuEditor = self.widget(index).getEditor() |
302 self.contextMenuEditor = self.widget(index).getEditor() |
294 if self.contextMenuEditor: |
303 if self.contextMenuEditor: |
295 self.saveMenuAct.setEnabled( |
304 self.saveMenuAct.setEnabled( |
325 |
334 |
326 def __navigationMenuTriggered(self, act): |
335 def __navigationMenuTriggered(self, act): |
327 """ |
336 """ |
328 Private slot called to handle the navigation button menu selection. |
337 Private slot called to handle the navigation button menu selection. |
329 |
338 |
330 @param act reference to the selected action (QAction) |
339 @param act reference to the selected action |
|
340 @type QAction |
331 """ |
341 """ |
332 index = act.data() |
342 index = act.data() |
333 if index is not None: |
343 if index is not None: |
334 self.setCurrentIndex(index) |
344 self.setCurrentIndex(index) |
335 |
345 |
336 def showIndicator(self, on): |
346 def showIndicator(self, on): |
337 """ |
347 """ |
338 Public slot to set the indicator on or off. |
348 Public slot to set the indicator on or off. |
339 |
349 |
340 @param on flag indicating the dtate of the indicator (boolean) |
350 @param on flag indicating the state of the indicator |
|
351 @type bool |
341 """ |
352 """ |
342 if on: |
353 if on: |
343 self.indicator.setColor(QColor("green")) |
354 self.indicator.setColor(QColor("green")) |
344 else: |
355 else: |
345 self.indicator.setColor(QColor("red")) |
356 self.indicator.setColor(QColor("red")) |
347 def addTab(self, assembly, title): |
358 def addTab(self, assembly, title): |
348 """ |
359 """ |
349 Public method to add a new tab. |
360 Public method to add a new tab. |
350 |
361 |
351 @param assembly editor assembly object to be added |
362 @param assembly editor assembly object to be added |
352 (QScintilla.EditorAssembly.EditorAssembly) |
363 @type QScintilla.EditorAssembly.EditorAssembly |
353 @param title title for the new tab (string) |
364 @param title title for the new tab |
|
365 @type str |
354 """ |
366 """ |
355 editor = assembly.getEditor() |
367 editor = assembly.getEditor() |
356 super(TabWidget, self).addTab( |
368 super(TabWidget, self).addTab( |
357 assembly, UI.PixmapCache.getIcon("empty.png"), title) |
369 assembly, UI.PixmapCache.getIcon("empty.png"), title) |
358 if self.closeButton: |
370 if self.closeButton: |
372 |
384 |
373 def insertWidget(self, index, assembly, title): |
385 def insertWidget(self, index, assembly, title): |
374 """ |
386 """ |
375 Public method to insert a new tab. |
387 Public method to insert a new tab. |
376 |
388 |
377 @param index index position for the new tab (integer) |
389 @param index index position for the new tab |
|
390 @type int |
378 @param assembly editor assembly object to be added |
391 @param assembly editor assembly object to be added |
379 (QScintilla.EditorAssembly.EditorAssembly) |
392 @type QScintilla.EditorAssembly.EditorAssembly |
380 @param title title for the new tab (string) |
393 @param title title for the new tab |
381 @return index of the inserted tab (integer) |
394 @type str |
|
395 @return index of the inserted tab |
|
396 @rtype int |
382 """ |
397 """ |
383 editor = assembly.getEditor() |
398 editor = assembly.getEditor() |
384 newIndex = super(TabWidget, self).insertTab( |
399 newIndex = super(TabWidget, self).insertTab( |
385 index, assembly, |
400 index, assembly, |
386 UI.PixmapCache.getIcon("empty.png"), |
401 UI.PixmapCache.getIcon("empty.png"), |
407 |
422 |
408 Updates the tab text and tooltip text to reflect the new caption |
423 Updates the tab text and tooltip text to reflect the new caption |
409 information. |
424 information. |
410 |
425 |
411 @param cap Caption for the editor |
426 @param cap Caption for the editor |
|
427 @type str |
412 @param editor Editor to update the caption for |
428 @param editor Editor to update the caption for |
|
429 @type Editor |
413 """ |
430 """ |
414 fn = editor.getFileName() |
431 fn = editor.getFileName() |
415 if fn: |
432 if fn: |
416 if Preferences.getUI("TabViewManagerFilenameOnly"): |
433 if Preferences.getUI("TabViewManagerFilenameOnly"): |
417 txt = os.path.basename(fn) |
434 txt = os.path.basename(fn) |
434 def __cursorLineChanged(self, lineno): |
451 def __cursorLineChanged(self, lineno): |
435 """ |
452 """ |
436 Private slot to handle a change of the current editor's cursor line. |
453 Private slot to handle a change of the current editor's cursor line. |
437 |
454 |
438 @param lineno line number of the current editor's cursor (zero based) |
455 @param lineno line number of the current editor's cursor (zero based) |
|
456 @type int |
439 """ |
457 """ |
440 editor = self.sender() |
458 editor = self.sender() |
441 if editor and isinstance(editor, QScintilla.Editor.Editor): |
459 if editor and isinstance(editor, QScintilla.Editor.Editor): |
442 fn = editor.getFileName() |
460 fn = editor.getFileName() |
443 if fn: |
461 if fn: |
445 |
463 |
446 def removeWidget(self, widget): |
464 def removeWidget(self, widget): |
447 """ |
465 """ |
448 Public method to remove a widget. |
466 Public method to remove a widget. |
449 |
467 |
450 @param widget widget to be removed (QWidget) |
468 @param widget widget to be removed |
|
469 @type QWidget |
451 """ |
470 """ |
452 if isinstance(widget, QScintilla.Editor.Editor): |
471 if isinstance(widget, QScintilla.Editor.Editor): |
453 widget.cursorLineChanged.disconnect(self.__cursorLineChanged) |
472 widget.cursorLineChanged.disconnect(self.__cursorLineChanged) |
454 widget.captionChanged.disconnect(self.__captionChange) |
473 widget.captionChanged.disconnect(self.__captionChange) |
455 self.editors.remove(widget) |
474 self.editors.remove(widget) |
471 |
490 |
472 def __relocateTab(self, sourceId, sourceIndex, targetIndex): |
491 def __relocateTab(self, sourceId, sourceIndex, targetIndex): |
473 """ |
492 """ |
474 Private method to relocate an editor from another TabWidget. |
493 Private method to relocate an editor from another TabWidget. |
475 |
494 |
476 @param sourceId id of the TabWidget to get the editor from (string) |
495 @param sourceId id of the TabWidget to get the editor from |
477 @param sourceIndex index of the tab in the old tab widget (integer) |
496 @type str |
478 @param targetIndex index position to place it to (integer) |
497 @param sourceIndex index of the tab in the old tab widget |
|
498 @type int |
|
499 @param targetIndex index position to place it to |
|
500 @type int |
479 """ |
501 """ |
480 tw = self.vm.getTabWidgetById(int(sourceId)) |
502 tw = self.vm.getTabWidgetById(int(sourceId)) |
481 if tw is not None: |
503 if tw is not None: |
482 # step 1: get data of the tab of the source |
504 # step 1: get data of the tab of the source |
483 toolTip = tw.tabToolTip(sourceIndex) |
505 toolTip = tw.tabToolTip(sourceIndex) |
500 |
522 |
501 def __copyTabOther(self, sourceId, sourceIndex, targetIndex): |
523 def __copyTabOther(self, sourceId, sourceIndex, targetIndex): |
502 """ |
524 """ |
503 Private method to copy an editor from another TabWidget. |
525 Private method to copy an editor from another TabWidget. |
504 |
526 |
505 @param sourceId id of the TabWidget to get the editor from (string) |
527 @param sourceId id of the TabWidget to get the editor from |
506 @param sourceIndex index of the tab in the old tab widget (integer) |
528 @type str |
507 @param targetIndex index position to place it to (integer) |
529 @param sourceIndex index of the tab in the old tab widget |
|
530 @type int |
|
531 @param targetIndex index position to place it to |
|
532 @type int |
508 """ |
533 """ |
509 tw = self.vm.getTabWidgetById(int(sourceId)) |
534 tw = self.vm.getTabWidgetById(int(sourceId)) |
510 if tw is not None: |
535 if tw is not None: |
511 editor = tw.widget(sourceIndex).getEditor() |
536 editor = tw.widget(sourceIndex).getEditor() |
512 newEditor, assembly = self.vm.cloneEditor( |
537 newEditor, assembly = self.vm.cloneEditor( |
516 |
541 |
517 def __copyTab(self, sourceIndex, targetIndex): |
542 def __copyTab(self, sourceIndex, targetIndex): |
518 """ |
543 """ |
519 Private method to copy an editor. |
544 Private method to copy an editor. |
520 |
545 |
521 @param sourceIndex index of the tab (integer) |
546 @param sourceIndex index of the tab |
522 @param targetIndex index position to place it to (integer) |
547 @type int |
|
548 @param targetIndex index position to place it to |
|
549 @type int |
523 """ |
550 """ |
524 editor = self.widget(sourceIndex).getEditor() |
551 editor = self.widget(sourceIndex).getEditor() |
525 newEditor, assembly = self.vm.cloneEditor( |
552 newEditor, assembly = self.vm.cloneEditor( |
526 editor, editor.getFileType(), editor.getFileName()) |
553 editor, editor.getFileType(), editor.getFileName()) |
527 self.vm.insertView(assembly, self, targetIndex, |
554 self.vm.insertView(assembly, self, targetIndex, |
541 def setCurrentWidget(self, assembly): |
569 def setCurrentWidget(self, assembly): |
542 """ |
570 """ |
543 Public method to set the current tab by the given editor assembly. |
571 Public method to set the current tab by the given editor assembly. |
544 |
572 |
545 @param assembly editor assembly to determine current tab from |
573 @param assembly editor assembly to determine current tab from |
546 (EditorAssembly.EditorAssembly) |
574 @type EditorAssembly.EditorAssembly |
547 """ |
575 """ |
548 super(TabWidget, self).setCurrentWidget(assembly) |
576 super(TabWidget, self).setCurrentWidget(assembly) |
549 |
577 |
550 def indexOf(self, widget): |
578 def indexOf(self, widget): |
551 """ |
579 """ |
552 Public method to get the tab index of the given editor. |
580 Public method to get the tab index of the given editor. |
553 |
581 |
554 @param widget widget to get the index for (QLabel or Editor) |
582 @param widget widget to get the index for |
555 @return tab index of the editor (integer) |
583 @type QLabel or Editor |
|
584 @return tab index of the editor |
|
585 @rtype int |
556 """ |
586 """ |
557 if isinstance(widget, QScintilla.Editor.Editor): |
587 if isinstance(widget, QScintilla.Editor.Editor): |
558 widget = widget.parent() |
588 widget = widget.parent() |
559 return super(TabWidget, self).indexOf(widget) |
589 return super(TabWidget, self).indexOf(widget) |
560 |
590 |
561 def hasEditor(self, editor): |
591 def hasEditor(self, editor): |
562 """ |
592 """ |
563 Public method to check for an editor. |
593 Public method to check for an editor. |
564 |
594 |
565 @param editor editor object to check for |
595 @param editor editor object to check for |
|
596 @type Editor |
566 @return flag indicating, whether the editor to be checked belongs |
597 @return flag indicating, whether the editor to be checked belongs |
567 to the list of editors managed by this tab widget. |
598 to the list of editors managed by this tab widget. |
|
599 @rtype bool |
568 """ |
600 """ |
569 return editor in self.editors |
601 return editor in self.editors |
570 |
602 |
571 def hasEditors(self): |
603 def hasEditors(self): |
572 """ |
604 """ |
573 Public method to test, if any editor is managed. |
605 Public method to test, if any editor is managed. |
574 |
606 |
575 @return flag indicating editors are managed |
607 @return flag indicating editors are managed |
|
608 @rtype bool |
576 """ |
609 """ |
577 return len(self.editors) > 0 |
610 return len(self.editors) > 0 |
578 |
611 |
579 def __contextMenuClose(self): |
612 def __contextMenuClose(self): |
580 """ |
613 """ |
794 def canCascade(self): |
828 def canCascade(self): |
795 """ |
829 """ |
796 Public method to signal if cascading of managed windows is available. |
830 Public method to signal if cascading of managed windows is available. |
797 |
831 |
798 @return flag indicating cascading of windows is available |
832 @return flag indicating cascading of windows is available |
|
833 @rtype bool |
799 """ |
834 """ |
800 return False |
835 return False |
801 |
836 |
802 def canTile(self): |
837 def canTile(self): |
803 """ |
838 """ |
804 Public method to signal if tiling of managed windows is available. |
839 Public method to signal if tiling of managed windows is available. |
805 |
840 |
806 @return flag indicating tiling of windows is available |
841 @return flag indicating tiling of windows is available |
|
842 @rtype bool |
807 """ |
843 """ |
808 return False |
844 return False |
809 |
845 |
810 def canSplit(self): |
846 def canSplit(self): |
811 """ |
847 """ |
812 public method to signal if splitting of the view is available. |
848 public method to signal if splitting of the view is available. |
813 |
849 |
814 @return flag indicating splitting of the view is available. |
850 @return flag indicating splitting of the view is available. |
|
851 @rtype bool |
815 """ |
852 """ |
816 return True |
853 return True |
817 |
854 |
818 def tile(self): |
855 def tile(self): |
819 """ |
856 """ |
837 def _removeView(self, win): |
874 def _removeView(self, win): |
838 """ |
875 """ |
839 Protected method to remove a view (i.e. window). |
876 Protected method to remove a view (i.e. window). |
840 |
877 |
841 @param win editor window to be removed |
878 @param win editor window to be removed |
|
879 @type Editor |
842 """ |
880 """ |
843 self.__inRemoveView = True |
881 self.__inRemoveView = True |
844 for tw in self.tabWidgets: |
882 for tw in self.tabWidgets: |
845 if tw.hasEditor(win): |
883 if tw.hasEditor(win): |
846 tw.removeWidget(win) |
884 tw.removeWidget(win) |
868 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1) |
906 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1) |
869 else: |
907 else: |
870 self.changeCaption.emit("") |
908 self.changeCaption.emit("") |
871 self.editorChangedEd.emit(aw) |
909 self.editorChangedEd.emit(aw) |
872 |
910 |
873 def _addView(self, win, fn=None, noName="", addNext=False): |
911 def _addView(self, win, fn=None, noName="", addNext=False, indexes=None): |
874 """ |
912 """ |
875 Protected method to add a view (i.e. window). |
913 Protected method to add a view (i.e. window). |
876 |
914 |
877 @param win editor assembly to be added |
915 @param win editor assembly to be added |
878 @param fn filename of this editor (string) |
916 @type EditorAssembly |
879 @param noName name to be used for an unnamed editor (string) |
917 @param fn filename of this editor |
|
918 @type str |
|
919 @param noName name to be used for an unnamed editor |
|
920 @type str |
880 @param addNext flag indicating to add the view next to the current |
921 @param addNext flag indicating to add the view next to the current |
881 view (bool) |
922 view |
|
923 @type bool |
|
924 @param indexes of the editor, first the split view index, second the |
|
925 index within the view |
|
926 @type tuple of two int |
882 """ |
927 """ |
883 editor = win.getEditor() |
928 editor = win.getEditor() |
884 if fn is None: |
929 if fn is None: |
885 if not noName: |
930 if not noName: |
886 self.untitledCount += 1 |
931 self.untitledCount += 1 |
887 noName = self.tr("Untitled {0}").format(self.untitledCount) |
932 noName = self.tr("Untitled {0}").format(self.untitledCount) |
888 if addNext: |
933 if addNext: |
889 index = self.currentTabWidget.currentIndex() + 1 |
934 index = self.currentTabWidget.currentIndex() + 1 |
890 self.currentTabWidget.insertWidget(index, win, noName) |
935 self.currentTabWidget.insertWidget(index, win, noName) |
|
936 elif indexes: |
|
937 if indexes[0] < len(self.tabWidgets): |
|
938 tw = self.tabWidgets[indexes[0]] |
|
939 else: |
|
940 tw = self.tabWidgets[-1] |
|
941 tw.insertWidget(indexes[1], win, noName) |
891 else: |
942 else: |
892 self.currentTabWidget.addTab(win, noName) |
943 self.currentTabWidget.addTab(win, noName) |
893 editor.setNoName(noName) |
944 editor.setNoName(noName) |
894 else: |
945 else: |
895 if self.filenameOnly: |
946 if self.filenameOnly: |
901 if not QFileInfo(fn).isWritable(): |
952 if not QFileInfo(fn).isWritable(): |
902 txt = self.tr("{0} (ro)").format(txt) |
953 txt = self.tr("{0} (ro)").format(txt) |
903 if addNext: |
954 if addNext: |
904 index = self.currentTabWidget.currentIndex() + 1 |
955 index = self.currentTabWidget.currentIndex() + 1 |
905 self.currentTabWidget.insertWidget(index, win, txt) |
956 self.currentTabWidget.insertWidget(index, win, txt) |
|
957 elif indexes: |
|
958 if indexes[0] < len(self.tabWidgets): |
|
959 tw = self.tabWidgets[indexes[0]] |
|
960 else: |
|
961 tw = self.tabWidgets[-1] |
|
962 tw.insertWidget(indexes[1], win, txt) |
906 else: |
963 else: |
907 self.currentTabWidget.addTab(win, txt) |
964 self.currentTabWidget.addTab(win, txt) |
908 index = self.currentTabWidget.indexOf(win) |
965 index = self.currentTabWidget.indexOf(win) |
909 self.currentTabWidget.setTabToolTip(index, fn) |
966 self.currentTabWidget.setTabToolTip(index, fn) |
910 self.currentTabWidget.setCurrentWidget(win) |
967 self.currentTabWidget.setCurrentWidget(win) |
921 def insertView(self, win, tabWidget, index, fn=None, noName=""): |
978 def insertView(self, win, tabWidget, index, fn=None, noName=""): |
922 """ |
979 """ |
923 Public method to add a view (i.e. window). |
980 Public method to add a view (i.e. window). |
924 |
981 |
925 @param win editor assembly to be inserted |
982 @param win editor assembly to be inserted |
|
983 @type EditorAssembly |
926 @param tabWidget reference to the tab widget to insert the editor into |
984 @param tabWidget reference to the tab widget to insert the editor into |
927 (TabWidget) |
985 @type TabWidget |
928 @param index index position to insert at (integer) |
986 @param index index position to insert at |
929 @param fn filename of this editor (string) |
987 @type int |
930 @param noName name to be used for an unnamed editor (string) |
988 @param fn filename of this editor |
|
989 @type str |
|
990 @param noName name to be used for an unnamed editor |
|
991 @type str |
931 """ |
992 """ |
932 editor = win.getEditor() |
993 editor = win.getEditor() |
933 if fn is None: |
994 if fn is None: |
934 if not noName: |
995 if not noName: |
935 self.untitledCount += 1 |
996 self.untitledCount += 1 |
964 def _showView(self, win, fn=None): |
1025 def _showView(self, win, fn=None): |
965 """ |
1026 """ |
966 Protected method to show a view (i.e. window). |
1027 Protected method to show a view (i.e. window). |
967 |
1028 |
968 @param win editor assembly to be shown |
1029 @param win editor assembly to be shown |
969 @param fn filename of this editor (string) |
1030 @type EditorAssembly |
|
1031 @param fn filename of this editor |
|
1032 @type str |
970 """ |
1033 """ |
971 win.show() |
1034 win.show() |
972 editor = win.getEditor() |
1035 editor = win.getEditor() |
973 for tw in self.tabWidgets: |
1036 for tw in self.tabWidgets: |
974 if tw.hasEditor(editor): |
1037 if tw.hasEditor(editor): |
1009 def setEditorName(self, editor, newName): |
1074 def setEditorName(self, editor, newName): |
1010 """ |
1075 """ |
1011 Public method to change the displayed name of the editor. |
1076 Public method to change the displayed name of the editor. |
1012 |
1077 |
1013 @param editor editor window to be changed |
1078 @param editor editor window to be changed |
1014 @param newName new name to be shown (string) |
1079 @type Editor |
|
1080 @param newName new name to be shown |
|
1081 @type str |
1015 """ |
1082 """ |
1016 if newName: |
1083 if newName: |
1017 if self.filenameOnly: |
1084 if self.filenameOnly: |
1018 tabName = os.path.basename(newName) |
1085 tabName = os.path.basename(newName) |
1019 else: |
1086 else: |
1027 |
1094 |
1028 def _modificationStatusChanged(self, m, editor): |
1095 def _modificationStatusChanged(self, m, editor): |
1029 """ |
1096 """ |
1030 Protected slot to handle the modificationStatusChanged signal. |
1097 Protected slot to handle the modificationStatusChanged signal. |
1031 |
1098 |
1032 @param m flag indicating the modification status (boolean) |
1099 @param m flag indicating the modification status |
|
1100 @type bool |
1033 @param editor editor window changed |
1101 @param editor editor window changed |
|
1102 @type Editor |
1034 """ |
1103 """ |
1035 for tw in self.tabWidgets: |
1104 for tw in self.tabWidgets: |
1036 if tw.hasEditor(editor): |
1105 if tw.hasEditor(editor): |
1037 break |
1106 break |
1038 index = tw.indexOf(editor) |
1107 index = tw.indexOf(editor) |
1051 def _syntaxErrorToggled(self, editor): |
1120 def _syntaxErrorToggled(self, editor): |
1052 """ |
1121 """ |
1053 Protected slot to handle the syntaxerrorToggled signal. |
1122 Protected slot to handle the syntaxerrorToggled signal. |
1054 |
1123 |
1055 @param editor editor that sent the signal |
1124 @param editor editor that sent the signal |
|
1125 @type Editor |
1056 """ |
1126 """ |
1057 for tw in self.tabWidgets: |
1127 for tw in self.tabWidgets: |
1058 if tw.hasEditor(editor): |
1128 if tw.hasEditor(editor): |
1059 break |
1129 break |
1060 index = tw.indexOf(editor) |
1130 index = tw.indexOf(editor) |
1093 [int(size / len(self.tabWidgets))] * len(self.tabWidgets)) |
1163 [int(size / len(self.tabWidgets))] * len(self.tabWidgets)) |
1094 self.splitRemoveAct.setEnabled(True) |
1164 self.splitRemoveAct.setEnabled(True) |
1095 self.nextSplitAct.setEnabled(True) |
1165 self.nextSplitAct.setEnabled(True) |
1096 self.prevSplitAct.setEnabled(True) |
1166 self.prevSplitAct.setEnabled(True) |
1097 |
1167 |
1098 def removeSplit(self): |
1168 def removeSplit(self, index=-1): |
1099 """ |
1169 """ |
1100 Public method used to remove the current split view. |
1170 Public method used to remove the current split view or a split view |
1101 |
1171 by index. |
1102 @return flag indicating successfull removal |
1172 |
|
1173 @param index index of the split to be removed (-1 means to |
|
1174 delete the current split) |
|
1175 @type int |
|
1176 @return flag indicating successful deletion |
|
1177 @rtype bool |
1103 """ |
1178 """ |
1104 if len(self.tabWidgets) > 1: |
1179 if len(self.tabWidgets) > 1: |
1105 tw = self.currentTabWidget |
1180 if index == -1: |
|
1181 tw = self.currentTabWidget |
|
1182 else: |
|
1183 if index < len(self.tabWidgets): |
|
1184 tw = self.tabWidgets[index] |
|
1185 else: |
|
1186 tw = self.tabWidgets[-1] |
1106 res = True |
1187 res = True |
1107 savedEditors = tw.editors[:] |
1188 savedEditors = tw.editors[:] |
1108 for editor in savedEditors: |
1189 for editor in savedEditors: |
1109 res &= self.closeEditor(editor) |
1190 res &= self.closeEditor(editor) |
1110 if res: |
1191 if res: |
1131 self.prevSplitAct.setEnabled(False) |
1212 self.prevSplitAct.setEnabled(False) |
1132 return True |
1213 return True |
1133 |
1214 |
1134 return False |
1215 return False |
1135 |
1216 |
|
1217 def splitCount(self): |
|
1218 """ |
|
1219 Public method to get the number of splitted views. |
|
1220 |
|
1221 @return number of splitted views |
|
1222 @rtype int |
|
1223 """ |
|
1224 return len(self.tabWidgets) |
|
1225 |
|
1226 def setSplitCount(self, count): |
|
1227 """ |
|
1228 Public method to set the number of split views. |
|
1229 |
|
1230 @param count number of split views |
|
1231 @type int |
|
1232 """ |
|
1233 if count > self.splitCount(): |
|
1234 while self.splitCount() < count: |
|
1235 self.addSplit() |
|
1236 elif count < self.splitCount(): |
|
1237 while self.splitCount() > count: |
|
1238 # use an arbitrarily large index to remove the last one |
|
1239 self.removeSplit(index=100) |
|
1240 |
1136 def getSplitOrientation(self): |
1241 def getSplitOrientation(self): |
1137 """ |
1242 """ |
1138 Public method to get the orientation of the split view. |
1243 Public method to get the orientation of the split view. |
1139 |
1244 |
1140 @return orientation of the split (Qt.Horizontal or Qt.Vertical) |
1245 @return orientation of the split |
|
1246 @rtype Qt.Horizontal or Qt.Vertical |
1141 """ |
1247 """ |
1142 return self.__splitter.orientation() |
1248 return self.__splitter.orientation() |
1143 |
1249 |
1144 def setSplitOrientation(self, orientation): |
1250 def setSplitOrientation(self, orientation): |
1145 """ |
1251 """ |
1146 Public method used to set the orientation of the split view. |
1252 Public method used to set the orientation of the split view. |
1147 |
1253 |
1148 @param orientation orientation of the split |
1254 @param orientation orientation of the split |
1149 (Qt.Horizontal or Qt.Vertical) |
1255 @type Qt.Horizontal or Qt.Vertical |
1150 """ |
1256 """ |
1151 self.__splitter.setOrientation(orientation) |
1257 self.__splitter.setOrientation(orientation) |
1152 |
1258 |
1153 def nextSplit(self): |
1259 def nextSplit(self): |
1154 """ |
1260 """ |
1214 |
1321 |
1215 def eventFilter(self, watched, event): |
1322 def eventFilter(self, watched, event): |
1216 """ |
1323 """ |
1217 Public method called to filter the event queue. |
1324 Public method called to filter the event queue. |
1218 |
1325 |
1219 @param watched the QObject being watched (QObject) |
1326 @param watched the QObject being watched |
1220 @param event the event that occurred (QEvent) |
1327 @type QObject |
|
1328 @param event the event that occurred |
|
1329 @type QEvent |
1221 @return always False |
1330 @return always False |
|
1331 @rtype bool |
1222 """ |
1332 """ |
1223 if event.type() == QEvent.MouseButtonPress and \ |
1333 if event.type() == QEvent.MouseButtonPress and \ |
1224 not event.button() == Qt.RightButton: |
1334 not event.button() == Qt.RightButton: |
1225 switched = True |
1335 switched = True |
1226 self.currentTabWidget.showIndicator(False) |
1336 self.currentTabWidget.showIndicator(False) |
1288 |
1398 |
1289 def getTabWidgetById(self, id_): |
1399 def getTabWidgetById(self, id_): |
1290 """ |
1400 """ |
1291 Public method to get a reference to a tab widget knowing its ID. |
1401 Public method to get a reference to a tab widget knowing its ID. |
1292 |
1402 |
1293 @param id_ id of the tab widget (long) |
1403 @param id_ id of the tab widget |
1294 @return reference to the tab widget (TabWidget) |
1404 @type int |
|
1405 @return reference to the tab widget |
|
1406 @rtype TabWidget |
1295 """ |
1407 """ |
1296 for tw in self.tabWidgets: |
1408 for tw in self.tabWidgets: |
1297 if id(tw) == id_: |
1409 if id(tw) == id_: |
1298 return tw |
1410 return tw |
1299 return None |
1411 return None |
|
1412 |
|
1413 def getOpenEditorsForSession(self): |
|
1414 """ |
|
1415 Public method to get a lists of all open editors. |
|
1416 |
|
1417 The returned list contains one list per split view. If the view manager |
|
1418 cannot split the view, only one list of editors is returned. |
|
1419 |
|
1420 @return list of list of editor references |
|
1421 @rtype list of list of Editor |
|
1422 """ |
|
1423 editorLists = [] |
|
1424 for tabWidget in self.tabWidgets: |
|
1425 editors = [] |
|
1426 for index in range(tabWidget.count()): |
|
1427 widget = tabWidget.widget(index) |
|
1428 if isinstance(widget, EditorAssembly): |
|
1429 editor = widget.getEditor() |
|
1430 editors.append(editor) |
|
1431 editorLists.append(editors) |
|
1432 return editorLists |