Plugins/ViewManagerPlugins/Tabview/Tabview.py

changeset 5588
6ba512d9f46a
parent 5389
9b1c800daff3
child 6048
82ad8ec9548c
equal deleted inserted replaced
5587:ea526b78ee6c 5588:6ba512d9f46a
441 if editor and isinstance(editor, QScintilla.Editor.Editor): 441 if editor and isinstance(editor, QScintilla.Editor.Editor):
442 fn = editor.getFileName() 442 fn = editor.getFileName()
443 if fn: 443 if fn:
444 self.vm.editorLineChanged.emit(fn, lineno + 1) 444 self.vm.editorLineChanged.emit(fn, lineno + 1)
445 445
446 def removeWidget(self, object): 446 def removeWidget(self, widget):
447 """ 447 """
448 Public method to remove a widget. 448 Public method to remove a widget.
449 449
450 @param object object to be removed (QWidget) 450 @param widget widget to be removed (QWidget)
451 """ 451 """
452 if isinstance(object, QScintilla.Editor.Editor): 452 if isinstance(widget, QScintilla.Editor.Editor):
453 object.cursorLineChanged.disconnect(self.__cursorLineChanged) 453 widget.cursorLineChanged.disconnect(self.__cursorLineChanged)
454 object.captionChanged.disconnect(self.__captionChange) 454 widget.captionChanged.disconnect(self.__captionChange)
455 self.editors.remove(object) 455 self.editors.remove(widget)
456 index = self.indexOf(object.parent()) 456 index = self.indexOf(widget.parent())
457 else: 457 else:
458 index = self.indexOf(object) 458 index = self.indexOf(widget)
459 if index > -1: 459 if index > -1:
460 self.removeTab(index) 460 self.removeTab(index)
461 461
462 if not self.editors: 462 if not self.editors:
463 super(TabWidget, self).addTab( 463 super(TabWidget, self).addTab(
545 @param assembly editor assembly to determine current tab from 545 @param assembly editor assembly to determine current tab from
546 (EditorAssembly.EditorAssembly) 546 (EditorAssembly.EditorAssembly)
547 """ 547 """
548 super(TabWidget, self).setCurrentWidget(assembly) 548 super(TabWidget, self).setCurrentWidget(assembly)
549 549
550 def indexOf(self, object): 550 def indexOf(self, widget):
551 """ 551 """
552 Public method to get the tab index of the given editor. 552 Public method to get the tab index of the given editor.
553 553
554 @param object object to get the index for (QLabel or Editor) 554 @param widget widget to get the index for (QLabel or Editor)
555 @return tab index of the editor (integer) 555 @return tab index of the editor (integer)
556 """ 556 """
557 if isinstance(object, QScintilla.Editor.Editor): 557 if isinstance(widget, QScintilla.Editor.Editor):
558 object = object.parent() 558 widget = widget.parent()
559 return super(TabWidget, self).indexOf(object) 559 return super(TabWidget, self).indexOf(widget)
560 560
561 def hasEditor(self, editor): 561 def hasEditor(self, editor):
562 """ 562 """
563 Public method to check for an editor. 563 Public method to check for an editor.
564 564
868 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1) 868 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1)
869 else: 869 else:
870 self.changeCaption.emit("") 870 self.changeCaption.emit("")
871 self.editorChangedEd.emit(aw) 871 self.editorChangedEd.emit(aw)
872 872
873 def _addView(self, win, fn=None, noName="", next=False): 873 def _addView(self, win, fn=None, noName="", addNext=False):
874 """ 874 """
875 Protected method to add a view (i.e. window). 875 Protected method to add a view (i.e. window).
876 876
877 @param win editor assembly to be added 877 @param win editor assembly to be added
878 @param fn filename of this editor (string) 878 @param fn filename of this editor (string)
879 @param noName name to be used for an unnamed editor (string) 879 @param noName name to be used for an unnamed editor (string)
880 @param next flag indicating to add the view next to the current 880 @param addNext flag indicating to add the view next to the current
881 view (bool) 881 view (bool)
882 """ 882 """
883 editor = win.getEditor() 883 editor = win.getEditor()
884 if fn is None: 884 if fn is None:
885 if not noName: 885 if not noName:
886 self.untitledCount += 1 886 self.untitledCount += 1
887 noName = self.tr("Untitled {0}").format(self.untitledCount) 887 noName = self.tr("Untitled {0}").format(self.untitledCount)
888 if next: 888 if addNext:
889 index = self.currentTabWidget.currentIndex() + 1 889 index = self.currentTabWidget.currentIndex() + 1
890 self.currentTabWidget.insertWidget(index, win, noName) 890 self.currentTabWidget.insertWidget(index, win, noName)
891 else: 891 else:
892 self.currentTabWidget.addTab(win, noName) 892 self.currentTabWidget.addTab(win, noName)
893 editor.setNoName(noName) 893 editor.setNoName(noName)
898 txt = e5App().getObject("Project").getRelativePath(fn) 898 txt = e5App().getObject("Project").getRelativePath(fn)
899 if len(txt) > self.maxFileNameChars: 899 if len(txt) > self.maxFileNameChars:
900 txt = "...{0}".format(txt[-self.maxFileNameChars:]) 900 txt = "...{0}".format(txt[-self.maxFileNameChars:])
901 if not QFileInfo(fn).isWritable(): 901 if not QFileInfo(fn).isWritable():
902 txt = self.tr("{0} (ro)").format(txt) 902 txt = self.tr("{0} (ro)").format(txt)
903 if next: 903 if addNext:
904 index = self.currentTabWidget.currentIndex() + 1 904 index = self.currentTabWidget.currentIndex() + 1
905 self.currentTabWidget.insertWidget(index, win, txt) 905 self.currentTabWidget.insertWidget(index, win, txt)
906 else: 906 else:
907 self.currentTabWidget.addTab(win, txt) 907 self.currentTabWidget.addTab(win, txt)
908 index = self.currentTabWidget.indexOf(win) 908 index = self.currentTabWidget.indexOf(win)

eric ide

mercurial