Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.1, 2.1.1, and 2.1.2

workbench: add context menu to the tabbar.

The context menu actions are:
- Close
- Close other tabs

Also, if a tab has been closed before:
- Undo close tab

If a group of tabs has been closed before:
- Undo close other tabs

Note that when using "close other tabs" the tabbar is automatically hidden.
In order to get the "Undo close other tabs" option you must first open a second
repo so that the tab bar is shown again.

When clicking a non active tab, the tab will not be activated but the commands
in the context menu will apply to it nevertheless.
When clicking outside of any tab, the context menu will be shown and it will
apply to the current tab.

Changeset 625d1ee30b61

Parent d9f1484734f9

by Angel Ezquerra

Changes to one file · Browse files at 625d1ee30b61 Showing diff from parent d9f1484734f9 Diff from another changeset...

 
74
75
76
 
 
 
 
77
78
79
 
87
88
89
 
 
 
90
91
92
 
331
332
333
334
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
335
336
337
 
460
461
462
 
 
463
464
465
 
466
467
468
469
 
470
471
472
473
 
 
 
 
 
 
474
475
476
 
74
75
76
77
78
79
80
81
82
83
 
91
92
93
94
95
96
97
98
99
 
338
339
340
 
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
 
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
@@ -74,6 +74,10 @@
  self.dockMenu.addAction(_('Open Repository...'),   self.openRepository)   qt_mac_set_dock_menu(self.dockMenu) + + # Create the actions that will be displayed on the context menu + self.createActions() + self.lastClosedRepoRootList = []     def setupUi(self):   desktopgeom = qApp.desktop().availableGeometry() @@ -87,6 +91,9 @@
  tw.setTabsClosable(True)   tw.setMovable(True)   tw.tabBar().hide() + tw.tabBar().setContextMenuPolicy(Qt.CustomContextMenu) + tw.tabBar().customContextMenuRequested.connect(self.tabBarContextMenuRequest) + tw.lastClickedTab = -1 # No tab clicked yet   sp = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)   sp.setHorizontalStretch(1)   sp.setVerticalStretch(1) @@ -331,7 +338,91 @@
    self.updateMenu()   - @pyqtSlot(QAction) + def _action_defs(self): + a = [("closetab", _("Close tab"), '', + _("Close tab"), self.closeLastClickedTab), + ("closeothertabs", _("Close other tabs"), '', + _("Close other tabs"), self.closeNotLastClickedTabs), + ("reopenlastclosed", _("Undo close tab"), '', + _("Reopen last closed tab"), self.reopenLastClosedTabs), + ("reopenlastclosedgroup", _("Undo close other tabs"), '', + _("Reopen last closed tab group"), self.reopenLastClosedTabs), + ] + return a + + def createActions(self): + self._actions = {} + for name, desc, icon, tip, cb in self._action_defs(): + self._actions[name] = QAction(desc, self) + QTimer.singleShot(0, self.configureActions) + + def configureActions(self): + for name, desc, icon, tip, cb in self._action_defs(): + act = self._actions[name] + if icon: + act.setIcon(qtlib.getmenuicon(icon)) + if tip: + act.setStatusTip(tip) + if cb: + act.triggered.connect(cb) + self.addAction(act) + + @pyqtSlot(QPoint) + def tabBarContextMenuRequest(self, point): + # Activate the clicked tab + clickedwidget = qApp.widgetAt(self.repoTabsWidget.mapToGlobal(point)) + if not clickedwidget or \ + not isinstance(clickedwidget, ThgTabBar): + return + self.repoTabsWidget.lastClickedTab = -1 + + clickedtabindex = clickedwidget.tabAt(point) + if clickedtabindex > -1: + self.repoTabsWidget.lastClickedTab = clickedtabindex + + actionlist = ['closetab', 'closeothertabs'] + + existingClosedRepoList = [] + + for reporoot in self.lastClosedRepoRootList: + if os.path.isdir(reporoot): + existingClosedRepoList.append(reporoot) + self.lastClosedRepoRootList = existingClosedRepoList + + if len(self.lastClosedRepoRootList) > 1: + actionlist += ['', 'reopenlastclosedgroup'] + elif len(self.lastClosedRepoRootList) > 0: + actionlist += ['', 'reopenlastclosed'] + + contextmenu = QMenu(self) + for act in actionlist: + if act: + contextmenu.addAction(self._actions[act]) + else: + contextmenu.addSeparator() + + if actionlist: + contextmenu.exec_(self.repoTabsWidget.mapToGlobal(point)) + + def closeLastClickedTab(self): + self.repoTabCloseRequested(self.repoTabsWidget.lastClickedTab) + + def _closeOtherTabs(self, tabIndex): + if tabIndex > -1: + tb = self.repoTabsWidget.tabBar() + tb.setCurrentIndex(tabIndex) + closedRepoRootList = [] + for idx in range(tb.count()-1, -1, -1): + if idx != tabIndex: + self.repoTabCloseRequested(idx) + # repoTabCloseRequested updates self.lastClosedRepoRootList + closedRepoRootList += self.lastClosedRepoRootList + self.lastClosedRepoRootList = closedRepoRootList + + + def closeNotLastClickedTabs(self): + self._closeOtherTabs(self.repoTabsWidget.lastClickedTab) +   def onSwitchRepoTaskTab(self, action):   rw = self.repoTabsWidget.currentWidget()   if rw: @@ -460,17 +551,27 @@
  self.repoTabsWidget.setCurrentWidget(widget)   index = self.repoTabsWidget.currentIndex()   if widget.closeRepoWidget(): + w = self.repoTabsWidget.widget(index) + reporoot = w.repo.root   self.repoTabsWidget.removeTab(index)   widget.deleteLater()   self.updateMenu() + self.lastClosedRepoRootList = [reporoot]     def repoTabCloseRequested(self, index):   tw = self.repoTabsWidget   w = tw.widget(index) + reporoot = w.repo.root   if w and w.closeRepoWidget():   tw.removeTab(index)   w.deleteLater()   self.updateMenu() + self.lastClosedRepoRootList = [reporoot] + + def reopenLastClosedTabs(self): + for reporoot in self.lastClosedRepoRootList: + if os.path.isdir(reporoot): + self.showRepo(reporoot)     def repoTabChanged(self, index=0):   w = self.repoTabsWidget.currentWidget()