1. TortoiseHg
  2. TortoiseHg
  3. thg

Commits

Steve Borho  committed 3cf112b

status: use local filename as partials key, prevent update loops

Made the toggle function aware of the partial state, in order to avoid having
to adjust the check state while a file is represented in the partials
dictionary. This avoids chunk state event loops

  • Participants
  • Parent commits 8f62b20
  • Branches default

Comments (0)

Files changed (3)

File tortoisehg/hgqt/fileview.py

View file
  • Ignore whitespace
     revisionSelected = pyqtSignal(int)
     shelveToolExited = pyqtSignal()
     newChunkList = pyqtSignal(QString, object)
-    chunkSelectionChanged = pyqtSignal(QString, bool)
+    chunkSelectionChanged = pyqtSignal()
 
     grepRequested = pyqtSignal(unicode, dict)
     """Emitted (pattern, opts) when user request to search changelog"""
 
     def updateChunk(self, chunk, exclude):
         'change chunk exclusion state, update display when necessary'
-        # TODO: create a decent QsciStyle for these annotations
+        # returns True if the chunk state was changed
         if exclude:
             if self.changes.excludecount == 0:
+                # TODO: create a decent QsciStyle for these annotations
                 self.sci.annotate(chunk.lineno,
                                 _('folded changes are excluded from commit'), 4)
             if chunk.excluded:
-                return
+                return False
             chunk.excluded = True
             self.changes.excludecount += 1
-            uf = hglib.tounicode(self._filename)
-            state = self.changes.excludecount < len(self.changes.hunks)
-            self.chunkSelectionChanged.emit(uf, state)
+            return True
         else:
             self.sci.clearAnnotations(chunk.lineno)
             if not chunk.excluded:
-                return
+                return False
             chunk.excluded = False
             self.changes.excludecount -= 1
-            uf = hglib.tounicode(self._filename)
-            self.chunkSelectionChanged.emit(uf, True)
+            return True
 
     def updateFolds(self):
         'should be called after chunk states are modified programatically'
             return
         assert margin == 3 and index == 0
         chunk = self.chunkatline[line]
-        self.updateChunk(chunk, not chunk.excluded)
+        if self.updateChunk(chunk, not chunk.excluded):
+            self.chunkSelectionChanged.emit()
 
     def displayFile(self, filename=None, status=None):
         if isinstance(filename, (unicode, QString)):

File tortoisehg/hgqt/status.py

View file
  • Ignore whitespace
         self.fileview.fileDisplayed.connect(self.fileDisplayed)
         self.fileview.shelveToolExited.connect(self.refreshWctx)
         self.fileview.newChunkList.connect(self.updatePartials)
-        self.fileview.chunkSelectionChanged.connect(self.updateCheckbox)
+        self.fileview.chunkSelectionChanged.connect(self.chunkSelectionChanged)
         self.fileview.setContext(self.repo[None])
         self.fileview.setMinimumSize(QSize(16, 16))
         vbox.addWidget(self.fileview, 1)
         if not wfile or not changes:
             return
 
-        wfile = unicode(wfile)
+        wfile = hglib.fromunicode(wfile)
         if wfile in self.partials:
             # merge selection state from old hunk list to new hunk list
             oldhunks = self.partials[wfile].hunks
                 for chunk in changes.hunks:
                     self.fileview.updateChunk(chunk, True)
         self.fileview.updateFolds()
+        self.chunkSelectionChanged()
         self.partials[wfile] = changes
 
-    @pyqtSlot(QString, bool)
-    def updateCheckbox(self, wfile, state):
+    @pyqtSlot()
+    def chunkSelectionChanged(self):
         'checkbox state has changed via chunk selection'
-        # mark row as checked if any chunks are enabled
-        wfile = unicode(wfile)
-        self.tv.model().check([wfile], state, False)
+        # inform filelist view that the file selection state may have changed
+        model = self.tv.model()
+        if model:
+            model.layoutChanged.emit()
+            model.checkCountChanged.emit()
 
     @pyqtSlot(QPoint, object)
     def onMenuRequest(self, point, selected):
     @pyqtSlot(QString, bool)
     def checkToggled(self, wfile, checked):
         'user has toggled a checkbox, update partial chunk selection status'
-        wfile = unicode(wfile)
+        wfile = hglib.fromunicode(wfile)
         if wfile in self.partials:
-            if wfile == hglib.tounicode(self.fileview._filename):
+            if wfile == self.fileview._filename:
                 for chunk in self.partials[wfile].hunks:
                     self.fileview.updateChunk(chunk, not checked)
                 self.fileview.updateFolds()
             return 0 # no child
         return len(self.rows)
 
-    def check(self, files, state=True, emit=True):
+    def check(self, files, state):
         for f in files:
             self.checked[f] = state
-            if emit:
-                self.checkToggled.emit(f, state)
+            self.checkToggled.emit(f, state)
         self.layoutChanged.emit()
         self.checkCountChanged.emit()
 
         path, status, mst, upath, ext, sz = self.rows[index.row()]
         if index.column() == COL_PATH:
             if role == Qt.CheckStateRole and self.checkable:
-                if upath in self.partials:
-                    changes = self.partials[upath]
+                if path in self.partials:
+                    changes = self.partials[path]
                     if changes.excludecount == 0:
                         return Qt.Checked
                     elif changes.excludecount == len(changes.hunks):
             assert index.isValid()
             fname = self.rows[index.row()][COL_PATH]
             uname = self.rows[index.row()][COL_PATH_DISPLAY]
-            self.checked[fname] = not self.checked[fname]
+            if fname in self.partials:
+                checked = 0
+                changes = self.partials[fname]
+                if changes.excludecount < len(changes.hunks):
+                    checked = 1
+            else:
+                checked = self.checked[fname]
+            self.checked[fname] = not checked
             self.checkToggled.emit(uname, self.checked[fname])
         self.layoutChanged.emit()
         self.checkCountChanged.emit()

File tortoisehg/hgqt/wctxactions.py

View file
  • Ignore whitespace
     return True
 
 def check(parent, ui, repo, files):
-    parent.tv.model().check(files)
+    parent.tv.model().check(files, True)
     return True
 
 def uncheck(parent, ui, repo, files):