Commits

Peer Sommerlund committed cb42ce0 Merge

merge of stable

Comments (0)

Files changed (3)

.hgpatchinfo/thread-repoview-load.dep

+aec1bf1fa3bb2e0663fdd676711da4e27b75de8c

.hgpatchinfo/thread-repoview-load.desc

+Move initialization of RepoTreeModel into a thread

tortoisehg/hgqt/repotreemodel.py

         self.showNetworkSubrepos = showNetworkSubrepos
         self.showShortPaths = showShortPaths
 
+        self.loader = None
         root = None
         all = None
 
         if filename:
-            f = QFile(filename)
-            if f.open(QIODevice.ReadOnly):
-                root = readXml(f, reporegistryXmlElementName)
-                f.close()
-                if root:
-                    for c in root.childs:
-                        if isinstance(c, AllRepoGroupItem):
-                            all = c
-                            break
-
-                    if self.showSubrepos:
-                        self.loadSubrepos(root)
+            self.loader = RepoTreeModelLoader(filename, self)
+            self.loader.treeModelLoaded.connect(self.loadCompleted)
+            self.loader.start()
 
         if not root:
             root = RepoTreeItem(self)
         self.allrepos = all
         self.updateCommonPaths()
 
+    def loadCompleted(self, root, all):
+        self.beginResetModel()
+        self.rootItem = root
+        self.allrepos = all
+        self.loader = None
+        self.endResetModel()
+        self.updateCommonPaths()
+
     # see http://doc.qt.nokia.com/4.6/model-view-model-subclassing.html
 
     # overrides from QAbstractItemModel
         self.layoutAboutToBeChanged.emit()
         childs.sort(key=keyfunc)
         self.layoutChanged.emit()
+
+
+
+class RepoTreeModelLoader(QThread):
+    "A one-shot thread that loads the model from a file"
+
+    treeModelLoaded = pyqtSignal(object, object)
+
+    def __init__(self, filename, parent):
+        super(RepoTreeModelLoader, self).__init__(parent)
+
+        self.filename = filename
+        self.model = parent
+        self.root = None
+        self.all = None
+        self.finished.connect(self.thread_finished)
+
+    def thread_finished(self):
+        self.treeModelLoaded.emit(self.root, self.all)
+
+    def run(self):
+        root = self.root
+        all = self.all
+        if False:
+            self.root = RepoTreeItem()
+            self.all = AllRepoGroupItem()
+            self.root.appendChild(self.all)
+            self.all.name = 'THREAD WORKS'
+            return
+        f = QFile(self.filename)
+        if f.open(QIODevice.ReadOnly):
+            root = readXml(f, reporegistryXmlElementName)
+            f.close()
+            if root:
+                for c in root.childs:
+                    if isinstance(c, AllRepoGroupItem):
+                        all = c
+                        break
+
+                if self.model.showSubrepos:
+                    self.loadSubrepos(root)
+
+        self.root = root
+        self.all = all
+
+    def loadSubrepos(self, root):
+        # Note that the sub-repo-relation is transient since it 
+        # depends on the workdir cset of the parent repo 
+        for c in getRepoItemList(root):
+            if (self.model.showNetworkSubrepos 
+                or not paths.netdrive_status(c.rootpath()) 
+            ):
+                # Remove listed subrepos, append current subrepos 
+                c.removeRows(0,c.childCount())
+                c.appendSubrepos()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.