Commits

Yuya Nishihara committed c5ea2d5

resolve: use built-in drag-and-drop infrastructure

See also #744 and 9ee2f07c7e5d.

  • Participants
  • Parent commits e0eb53c

Comments (0)

Files changed (1)

tortoisehg/hgqt/resolve.py

     def __init__(self, repo, parent):
         QTreeView.__init__(self, parent)
         self.repo = repo
+        self.setDragDropMode(QTreeView.DragOnly)
         self.setSelectionMode(QTreeView.ExtendedSelection)
         self.setSortingEnabled(True)
 
-    def dragObject(self):
-        urls = []
-        for index in self.selectionModel().selectedRows():
-            root, path = self.model().getPathForIndex(index)
-            urls.append(QUrl.fromLocalFile(os.path.join(root, path)))
-        if urls:
-            d = QDrag(self)
-            m = QMimeData()
-            m.setUrls(urls)
-            d.setMimeData(m)
-            d.start(Qt.CopyAction)
-
-    def mousePressEvent(self, event):
-        self.pressPos = event.pos()
-        self.pressTime = QTime.currentTime()
-        return QTreeView.mousePressEvent(self, event)
-
-    def mouseMoveEvent(self, event):
-        d = event.pos() - self.pressPos
-        if d.manhattanLength() < QApplication.startDragDistance():
-            return QTreeView.mouseMoveEvent(self, event)
-        elapsed = self.pressTime.msecsTo(QTime.currentTime())
-        if elapsed < QApplication.startDragTime():
-            return QTreeView.mouseMoveEvent(self, event)
-        self.dragObject()
-        return QTreeView.mouseMoveEvent(self, event)
 
 class PathsModel(QAbstractTableModel):
     def __init__(self, pathlist, parent):
             return QVariant(hglib.tounicode(data))
         return QVariant()
 
+    def flags(self, index):
+        flags = super(PathsModel, self).flags(index)
+        if not index.isValid():
+            return flags
+        flags |= Qt.ItemIsDragEnabled
+        return flags
+
     def headerData(self, col, orientation, role=Qt.DisplayRole):
         if role != Qt.DisplayRole or orientation != Qt.Horizontal:
             return QVariant()
         row = index.row()
         return self.rows[row][2], self.rows[row][0]
 
+    def mimeTypes(self):
+        return ['text/uri-list']
+
+    def mimeData(self, indexes):
+        paths = [hglib.tounicode(os.path.join(*self.getPathForIndex(i)))
+                 for i in indexes if i.column() == 0]
+        data = QMimeData()
+        data.setUrls([QUrl.fromLocalFile(p) for p in paths])
+        return data
+
 
 class ActionPushButton(QPushButton):
     def __init__(self, action, parent=None):