Source

thg-qt-mq / trying-open-in-new-window.diff

# HG changeset patch
# Parent 28d826012bc0418d8f670c328d189fec91f475ab

diff --git a/tortoisehg/hgqt/workbench.py b/tortoisehg/hgqt/workbench.py
--- a/tortoisehg/hgqt/workbench.py
+++ b/tortoisehg/hgqt/workbench.py
@@ -76,7 +76,19 @@ class Workbench(QMainWindow):
 
         self.setWindowIcon(geticon('log'))
 
-        self.repoTabsWidget = tw = QTabWidget()
+        # XXX: quick hack to get middle-button click
+        class RepoTabWidget(QTabWidget):
+            tabMidClicked = pyqtSignal(int)
+            def mousePressEvent(self, event):
+                if event.button() == Qt.MidButton:
+                    i = self.tabBar().tabAt(event.pos())
+                    if i >= 0:
+                        self.tabMidClicked.emit(i)
+                        event.accept()
+                        return
+                super(RepoTabWidget, self).mousePressEvent(event)
+
+        self.repoTabsWidget = tw = RepoTabWidget()
         tw.setDocumentMode(True)
         tw.setTabsClosable(True)
         tw.setMovable(True)
@@ -89,6 +101,18 @@ class Workbench(QMainWindow):
         tw.tabCloseRequested.connect(self.repoTabCloseRequested)
         tw.currentChanged.connect(self.repoTabChanged)
 
+        # XXX: open the specified tab in new window
+        def openinnewwindow(i):
+            from tortoisehg.hgqt import run
+            def newwindow(ui, *pats, **opts):
+                wb = Workbench()
+                rw = tw.widget(i)
+                self.detachRepoWidget(rw)
+                wb.attachRepoWidget(rw)
+                return wb
+            run.qtrun(newwindow, tw.widget(i).repo.ui)
+        tw.tabMidClicked.connect(openinnewwindow)
+
         self.setCentralWidget(tw)
         self.statusbar = cmdui.ThgStatusBar(self)
         self.setStatusBar(self.statusbar)
@@ -451,10 +475,14 @@ class Workbench(QMainWindow):
     def addRepoTab(self, repo):
         '''opens the given repo in a new tab'''
         rw = RepoWidget(repo, self)
+        self.attachRepoWidget(rw)
+        self.reporegistry.addRepo(repo.root)
+
+    def attachRepoWidget(self, rw):
         rw.showMessageSignal.connect(self.showMessage)
         rw.closeSelfSignal.connect(self.repoTabCloseSelf)
         rw.progress.connect(lambda tp, p, i, u, tl:
-            self.statusbar.progress(tp, p, i, u, tl, repo.root))
+            self.statusbar.progress(tp, p, i, u, tl, rw.repo.root))
         rw.output.connect(self.log.output)
         rw.makeLogVisible.connect(self.log.setShown)
         rw.revisionSelected.connect(self.updateHistoryActions)
@@ -466,10 +494,20 @@ class Workbench(QMainWindow):
         tw.setCurrentIndex(index)
         rw.titleChanged.connect(
             lambda title: tw.setTabText(tw.indexOf(rw), title))
-        self.reporegistry.addRepo(repo.root)
 
         self.updateMenu()
 
+    def detachRepoWidget(self, rw):
+        rw.showMessageSignal.disconnect()
+        rw.closeSelfSignal.disconnect()
+        rw.progress.disconnect()
+        rw.output.disconnect()
+        rw.makeLogVisible.disconnect()
+        rw.revisionSelected.disconnect()
+        rw.repoLinkClicked.disconnect()
+        rw.taskTabsWidget.currentChanged.disconnect()
+        rw.titleChanged.disconnect()
+        self.repoTabsWidget.removeTab(self.repoTabsWidget.indexOf(rw))
 
     def showMessage(self, msg):
         self.statusbar.showMessage(msg)