Plugins/ViewManagerPlugins/Tabview/Tabview.py

changeset 3190
a9a94491c4fd
parent 3160
209a07d7e401
child 3201
0f115f6db6cb
equal deleted inserted replaced
3189:9a21c547de5f 3190:a9a94491c4fd
187 self.__navigationMenu.aboutToShow.connect(self.__showNavigationMenu) 187 self.__navigationMenu.aboutToShow.connect(self.__showNavigationMenu)
188 self.__navigationMenu.triggered.connect(self.__navigationMenuTriggered) 188 self.__navigationMenu.triggered.connect(self.__navigationMenuTriggered)
189 189
190 self.navigationButton = QToolButton(self) 190 self.navigationButton = QToolButton(self)
191 self.navigationButton.setIcon(UI.PixmapCache.getIcon("1downarrow.png")) 191 self.navigationButton.setIcon(UI.PixmapCache.getIcon("1downarrow.png"))
192 self.navigationButton.setToolTip(self.trUtf8("Show a navigation menu")) 192 self.navigationButton.setToolTip(self.tr("Show a navigation menu"))
193 self.navigationButton.setPopupMode(QToolButton.InstantPopup) 193 self.navigationButton.setPopupMode(QToolButton.InstantPopup)
194 self.navigationButton.setMenu(self.__navigationMenu) 194 self.navigationButton.setMenu(self.__navigationMenu)
195 self.navigationButton.setEnabled(False) 195 self.navigationButton.setEnabled(False)
196 self.rightCornerWidgetLayout.addWidget(self.navigationButton) 196 self.rightCornerWidgetLayout.addWidget(self.navigationButton)
197 197
198 if Preferences.getUI("SingleCloseButton") or \ 198 if Preferences.getUI("SingleCloseButton") or \
199 not hasattr(self, 'setTabsClosable'): 199 not hasattr(self, 'setTabsClosable'):
200 self.closeButton = QToolButton(self) 200 self.closeButton = QToolButton(self)
201 self.closeButton.setIcon(UI.PixmapCache.getIcon("close.png")) 201 self.closeButton.setIcon(UI.PixmapCache.getIcon("close.png"))
202 self.closeButton.setToolTip( 202 self.closeButton.setToolTip(
203 self.trUtf8("Close the current editor")) 203 self.tr("Close the current editor"))
204 self.closeButton.setEnabled(False) 204 self.closeButton.setEnabled(False)
205 self.closeButton.clicked[bool].connect(self.__closeButtonClicked) 205 self.closeButton.clicked[bool].connect(self.__closeButtonClicked)
206 self.rightCornerWidgetLayout.addWidget(self.closeButton) 206 self.rightCornerWidgetLayout.addWidget(self.closeButton)
207 else: 207 else:
208 self.tabCloseRequested.connect(self.__closeRequested) 208 self.tabCloseRequested.connect(self.__closeRequested)
230 Private method to initialize the tab context menu. 230 Private method to initialize the tab context menu.
231 """ 231 """
232 self.__menu = QMenu(self) 232 self.__menu = QMenu(self)
233 self.leftMenuAct = self.__menu.addAction( 233 self.leftMenuAct = self.__menu.addAction(
234 UI.PixmapCache.getIcon("1leftarrow.png"), 234 UI.PixmapCache.getIcon("1leftarrow.png"),
235 self.trUtf8('Move Left'), self.__contextMenuMoveLeft) 235 self.tr('Move Left'), self.__contextMenuMoveLeft)
236 self.rightMenuAct = self.__menu.addAction( 236 self.rightMenuAct = self.__menu.addAction(
237 UI.PixmapCache.getIcon("1rightarrow.png"), 237 UI.PixmapCache.getIcon("1rightarrow.png"),
238 self.trUtf8('Move Right'), self.__contextMenuMoveRight) 238 self.tr('Move Right'), self.__contextMenuMoveRight)
239 self.firstMenuAct = self.__menu.addAction( 239 self.firstMenuAct = self.__menu.addAction(
240 UI.PixmapCache.getIcon("2leftarrow.png"), 240 UI.PixmapCache.getIcon("2leftarrow.png"),
241 self.trUtf8('Move First'), self.__contextMenuMoveFirst) 241 self.tr('Move First'), self.__contextMenuMoveFirst)
242 self.lastMenuAct = self.__menu.addAction( 242 self.lastMenuAct = self.__menu.addAction(
243 UI.PixmapCache.getIcon("2rightarrow.png"), 243 UI.PixmapCache.getIcon("2rightarrow.png"),
244 self.trUtf8('Move Last'), self.__contextMenuMoveLast) 244 self.tr('Move Last'), self.__contextMenuMoveLast)
245 self.__menu.addSeparator() 245 self.__menu.addSeparator()
246 self.__menu.addAction( 246 self.__menu.addAction(
247 UI.PixmapCache.getIcon("tabClose.png"), 247 UI.PixmapCache.getIcon("tabClose.png"),
248 self.trUtf8('Close'), self.__contextMenuClose) 248 self.tr('Close'), self.__contextMenuClose)
249 self.closeOthersMenuAct = self.__menu.addAction( 249 self.closeOthersMenuAct = self.__menu.addAction(
250 UI.PixmapCache.getIcon("tabCloseOther.png"), 250 UI.PixmapCache.getIcon("tabCloseOther.png"),
251 self.trUtf8("Close Others"), self.__contextMenuCloseOthers) 251 self.tr("Close Others"), self.__contextMenuCloseOthers)
252 self.__menu.addAction( 252 self.__menu.addAction(
253 self.trUtf8('Close All'), self.__contextMenuCloseAll) 253 self.tr('Close All'), self.__contextMenuCloseAll)
254 self.__menu.addSeparator() 254 self.__menu.addSeparator()
255 self.saveMenuAct = self.__menu.addAction( 255 self.saveMenuAct = self.__menu.addAction(
256 UI.PixmapCache.getIcon("fileSave.png"), 256 UI.PixmapCache.getIcon("fileSave.png"),
257 self.trUtf8('Save'), self.__contextMenuSave) 257 self.tr('Save'), self.__contextMenuSave)
258 self.__menu.addAction( 258 self.__menu.addAction(
259 UI.PixmapCache.getIcon("fileSaveAs.png"), 259 UI.PixmapCache.getIcon("fileSaveAs.png"),
260 self.trUtf8('Save As...'), self.__contextMenuSaveAs) 260 self.tr('Save As...'), self.__contextMenuSaveAs)
261 self.__menu.addAction( 261 self.__menu.addAction(
262 UI.PixmapCache.getIcon("fileSaveAll.png"), 262 UI.PixmapCache.getIcon("fileSaveAll.png"),
263 self.trUtf8('Save All'), self.__contextMenuSaveAll) 263 self.tr('Save All'), self.__contextMenuSaveAll)
264 self.__menu.addSeparator() 264 self.__menu.addSeparator()
265 self.openRejectionsMenuAct = self.__menu.addAction( 265 self.openRejectionsMenuAct = self.__menu.addAction(
266 self.trUtf8("Open 'rejection' file"), 266 self.tr("Open 'rejection' file"),
267 self.__contextMenuOpenRejections) 267 self.__contextMenuOpenRejections)
268 self.__menu.addSeparator() 268 self.__menu.addSeparator()
269 self.__menu.addAction( 269 self.__menu.addAction(
270 UI.PixmapCache.getIcon("print.png"), 270 UI.PixmapCache.getIcon("print.png"),
271 self.trUtf8('Print'), self.__contextMenuPrintFile) 271 self.tr('Print'), self.__contextMenuPrintFile)
272 self.__menu.addSeparator() 272 self.__menu.addSeparator()
273 self.copyPathAct = self.__menu.addAction( 273 self.copyPathAct = self.__menu.addAction(
274 self.trUtf8("Copy Path to Clipboard"), 274 self.tr("Copy Path to Clipboard"),
275 self.__contextMenuCopyPathToClipboard) 275 self.__contextMenuCopyPathToClipboard)
276 276
277 def __showContextMenu(self, coord, index): 277 def __showContextMenu(self, coord, index):
278 """ 278 """
279 Private slot to show the tab context menu. 279 Private slot to show the tab context menu.
411 maxFileNameChars = Preferences.getUI( 411 maxFileNameChars = Preferences.getUI(
412 "TabViewManagerFilenameLength") 412 "TabViewManagerFilenameLength")
413 if len(txt) > maxFileNameChars: 413 if len(txt) > maxFileNameChars:
414 txt = "...{0}".format(txt[-maxFileNameChars:]) 414 txt = "...{0}".format(txt[-maxFileNameChars:])
415 if editor.isReadOnly(): 415 if editor.isReadOnly():
416 txt = self.trUtf8("{0} (ro)").format(txt) 416 txt = self.tr("{0} (ro)").format(txt)
417 417
418 assembly = editor.parent() 418 assembly = editor.parent()
419 index = self.indexOf(assembly) 419 index = self.indexOf(assembly)
420 if index > -1: 420 if index > -1:
421 self.setTabText(index, txt) 421 self.setTabText(index, txt)
852 """ 852 """
853 editor = win.getEditor() 853 editor = win.getEditor()
854 if fn is None: 854 if fn is None:
855 if not noName: 855 if not noName:
856 self.untitledCount += 1 856 self.untitledCount += 1
857 noName = self.trUtf8("Untitled {0}").format(self.untitledCount) 857 noName = self.tr("Untitled {0}").format(self.untitledCount)
858 self.currentTabWidget.addTab(win, noName) 858 self.currentTabWidget.addTab(win, noName)
859 editor.setNoName(noName) 859 editor.setNoName(noName)
860 else: 860 else:
861 if self.filenameOnly: 861 if self.filenameOnly:
862 txt = os.path.basename(fn) 862 txt = os.path.basename(fn)
863 else: 863 else:
864 txt = e5App().getObject("Project").getRelativePath(fn) 864 txt = e5App().getObject("Project").getRelativePath(fn)
865 if len(txt) > self.maxFileNameChars: 865 if len(txt) > self.maxFileNameChars:
866 txt = "...{0}".format(txt[-self.maxFileNameChars:]) 866 txt = "...{0}".format(txt[-self.maxFileNameChars:])
867 if not QFileInfo(fn).isWritable(): 867 if not QFileInfo(fn).isWritable():
868 txt = self.trUtf8("{0} (ro)").format(txt) 868 txt = self.tr("{0} (ro)").format(txt)
869 self.currentTabWidget.addTab(win, txt) 869 self.currentTabWidget.addTab(win, txt)
870 index = self.currentTabWidget.indexOf(win) 870 index = self.currentTabWidget.indexOf(win)
871 self.currentTabWidget.setTabToolTip(index, fn) 871 self.currentTabWidget.setTabToolTip(index, fn)
872 self.currentTabWidget.setCurrentWidget(win) 872 self.currentTabWidget.setCurrentWidget(win)
873 win.show() 873 win.show()
893 """ 893 """
894 editor = win.getEditor() 894 editor = win.getEditor()
895 if fn is None: 895 if fn is None:
896 if not noName: 896 if not noName:
897 self.untitledCount += 1 897 self.untitledCount += 1
898 noName = self.trUtf8("Untitled {0}").format(self.untitledCount) 898 noName = self.tr("Untitled {0}").format(self.untitledCount)
899 tabWidget.insertWidget(index, win, noName) 899 tabWidget.insertWidget(index, win, noName)
900 editor.setNoName(noName) 900 editor.setNoName(noName)
901 else: 901 else:
902 if self.filenameOnly: 902 if self.filenameOnly:
903 txt = os.path.basename(fn) 903 txt = os.path.basename(fn)
904 else: 904 else:
905 txt = e5App().getObject("Project").getRelativePath(fn) 905 txt = e5App().getObject("Project").getRelativePath(fn)
906 if len(txt) > self.maxFileNameChars: 906 if len(txt) > self.maxFileNameChars:
907 txt = "...{0}".format(txt[-self.maxFileNameChars:]) 907 txt = "...{0}".format(txt[-self.maxFileNameChars:])
908 if not QFileInfo(fn).isWritable(): 908 if not QFileInfo(fn).isWritable():
909 txt = self.trUtf8("{0} (ro)").format(txt) 909 txt = self.tr("{0} (ro)").format(txt)
910 nindex = tabWidget.insertWidget(index, win, txt) 910 nindex = tabWidget.insertWidget(index, win, txt)
911 tabWidget.setTabToolTip(nindex, fn) 911 tabWidget.setTabToolTip(nindex, fn)
912 tabWidget.setCurrentWidget(win) 912 tabWidget.setCurrentWidget(win)
913 win.show() 913 win.show()
914 editor.setFocus() 914 editor.setFocus()
1231 txt = e5App().getObject("Project")\ 1231 txt = e5App().getObject("Project")\
1232 .getRelativePath(fn) 1232 .getRelativePath(fn)
1233 if len(txt) > self.maxFileNameChars: 1233 if len(txt) > self.maxFileNameChars:
1234 txt = "...{0}".format(txt[-self.maxFileNameChars:]) 1234 txt = "...{0}".format(txt[-self.maxFileNameChars:])
1235 if not QFileInfo(fn).isWritable(): 1235 if not QFileInfo(fn).isWritable():
1236 txt = self.trUtf8("{0} (ro)").format(txt) 1236 txt = self.tr("{0} (ro)").format(txt)
1237 tabWidget.setTabText(index, txt) 1237 tabWidget.setTabText(index, txt)
1238 1238
1239 def getTabWidgetById(self, id_): 1239 def getTabWidgetById(self, id_):
1240 """ 1240 """
1241 Public method to get a reference to a tab widget knowing its ID. 1241 Public method to get a reference to a tab widget knowing its ID.

eric ide

mercurial