Commits

Yuya Nishihara  committed e20572a

mqdock: allow to delete and reorder more than one patches

_updatePatchActions is removed from onPatchSelected, which is actually the
handler of currentRowChanged signal, because currentRowChanged is followed
by selectionChanged.

  • Participants
  • Parent commits 4aa6b6b

Comments (0)

Files changed (1)

File tortoisehg/hgqt/mq.py

 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 
+from mercurial import util
+
 from tortoisehg.util import hglib
 from tortoisehg.hgqt.i18n import _
 from tortoisehg.hgqt import cmdcore, qtlib, cmdui, thgrepo
 
     def mimeData(self, indexes):
         repo = self._repoagent.rawRepo()
-        patches = [self._series[i.row()] for i in indexes]
+        # in the same order as series file
+        patches = [self._series[i.row()]
+                   for i in sorted(indexes, reverse=True)]
         data = QMimeData()
         data.setData('application/vnd.thg.mq.series',
                      QByteArray('\n'.join(patches) + '\n'))
         self.queueListWidget.setDragDropMode(QAbstractItemView.InternalMove)
         self.queueListWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
         self.queueListWidget.setIconSize(QSize(12, 12))
+        self.queueListWidget.setSelectionMode(
+            QAbstractItemView.ExtendedSelection)
         self.queueListWidget.setContextMenuPolicy(Qt.CustomContextMenu)
         self.queueListWidget.customContextMenuRequested.connect(
             self.onMenuRequested)
             newmodel.dataChanged.connect(self._updatePatchActions)
             selmodel = self.queueListWidget.selectionModel()
             selmodel.currentRowChanged.connect(self.onPatchSelected)
+            selmodel.selectionChanged.connect(self._updatePatchActions)
             self._updatePatchActions()
         else:
             self.queueListWidget.setModel(None)
 
     @pyqtSlot()
     def onDelete(self):
-        index = self.queueListWidget.currentIndex()
-        patch = self.queueListWidget.model().patchName(index)
-        self.patchActions.deletePatches([patch])
+        model = self.queueListWidget.model()
+        selmodel = self.queueListWidget.selectionModel()
+        patches = map(model.patchName, selmodel.selectedRows())
+        self.patchActions.deletePatches(patches)
 
     #@pyqtSlot(QModelIndex)
     def onGotoPatch(self, index):
 
     #@pyqtSlot(QModelIndex)
     def onPatchSelected(self, index):
-        'Patch has been selected, update buttons'
-        self._updatePatchActions()
         if index.isValid():
             model = self.queueListWidget.model()
             self.patchSelected.emit(model.patchName(index))
     @pyqtSlot()
     def _updatePatchActions(self):
         model = self.queueListWidget.model()
+        selmodel = self.queueListWidget.selectionModel()
 
         appliedcnt = model.appliedCount()
         seriescnt = model.rowCount()
         self.qpopAct.setEnabled(appliedcnt > 0)
         self.qpopAllAct.setEnabled(appliedcnt > 0)
 
-        index = self.queueListWidget.currentIndex()
-        self.qdeleteAct.setEnabled(index.isValid()
-                                   and not model.isApplied(index))
-        self.setGuardsAct.setEnabled(index.isValid())
-        self.qrenameAct.setEnabled(index.isValid())
+        indexes = selmodel.selectedRows()
+        anyapplied = util.any(model.isApplied(i) for i in indexes)
+        self.qdeleteAct.setEnabled(len(indexes) > 0 and not anyapplied)
+        self.setGuardsAct.setEnabled(len(indexes) == 1)
+        self.qrenameAct.setEnabled(len(indexes) == 1)
 
     @pyqtSlot(QString)
     def onQQueueActivated(self, text):