Commits

Yuya Nishihara  committed 98f4e1e

mq: reorder patches by drag-and-drop in MQ dock widget (refs #441)

This will supersede QReorderDialog.

  • Participants
  • Parent commits a0dac59

Comments (0)

Files changed (1)

File tortoisehg/hgqt/mq.py

     def flags(self, index):
         flags = super(PatchQueueModel, self).flags(index)
         if not index.isValid():
-            return flags
+            return flags | Qt.ItemIsDropEnabled  # insertion point
+        patch = self._series[index.row()]
+        if self._statusmap.get(patch) != 'applied':
+            flags |= Qt.ItemIsDragEnabled
         return flags
 
     def rowCount(self, parent=QModelIndex()):
                                guards and ', '.join(guards) or _('no guards'),
                                ctx.longsummary())
 
+    def mimeTypes(self):
+        return ['application/vnd.thg.mq.series', 'text/uri-list']
+
+    def mimeData(self, indexes):
+        repo = self._repoagent.rawRepo()
+        patches = [self._series[i.row()] for i in indexes]
+        data = QMimeData()
+        data.setData('application/vnd.thg.mq.series',
+                     QByteArray('\n'.join(patches) + '\n'))
+        data.setUrls([QUrl.fromLocalFile(hglib.tounicode(repo.mq.join(p)))
+                      for p in patches])
+        return data
+
+    def dropMimeData(self, data, action, row, column, parent):
+        if (action != Qt.MoveAction
+            or not data.hasFormat('application/vnd.thg.mq.series')
+            or row < 0 or parent.isValid()):
+            return False
+
+        repo = self._repoagent.rawRepo()
+        qtiprow = len(self._series) - repo.mq.seriesend(True)
+        if row > qtiprow:
+            return False
+        if row < len(self._series):
+            after = self._series[row]
+        else:
+            after = None  # next to working rev
+        patches = str(data.data('application/vnd.thg.mq.series')).splitlines()
+        if hglib.movemqpatches(repo, after, patches):
+            self._repoagent.pollStatus()
+        return True
+
+    def supportedDropActions(self):
+        return Qt.MoveAction
+
 
 class MQPatchesWidget(QDockWidget):
     patchSelected = pyqtSignal(unicode)
         self.qqueueConfigBtn.setMenu(self.qqueueActions.createMenu(self))
 
         self.queueListWidget = QListView(self)
+        self.queueListWidget.setDragDropMode(QAbstractItemView.InternalMove)
         self.queueListWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
         self.queueListWidget.setIconSize(QSize(12, 12))
         self.queueListWidget.setContextMenuPolicy(Qt.CustomContextMenu)