Changeset a34f3284f7f4…
Parent b8d1fbd7634a…
by
Changes to 2 files · Browse files at a34f3284f7f4 Showing diff from parent b8d1fbd7634a Diff from another changeset...
@@ -782,16 +782,32 @@
# Capture drop events, try to import into current patch queue
+ def detectPatches(self, paths):
+ filepaths = []
+ for p in paths:
+ if not os.path.isfile(p):
+ continue
+ try:
+ pf = open(p, 'rb')
+ filename, message, user, date, branch, node, p1, p2 = \
+ patch.extract(self.repo.ui, pf)
+ if filename:
+ filepaths.append(p)
+ os.unlink(filename)
+ except Exception, e:
+ pass
+ return filepaths
+
def dragEnterEvent(self, event):
- event.acceptProposedAction()
-
- def dragMoveEvent(self, event):
- event.acceptProposedAction()
+ paths = [unicode(u.toLocalFile()) for u in event.mimeData().urls()]
+ if self.detectPatches(paths):
+ event.setDropAction(Qt.CopyAction)
+ event.accept()
def dropEvent(self, event):
paths = [unicode(u.toLocalFile()) for u in event.mimeData().urls()]
- filepaths = [p for p in paths if os.path.isfile(p)]
- if filepaths:
+ patches = self.detectPatches(paths)
+ if patches:
event.setDropAction(Qt.CopyAction)
event.accept()
else:
@@ -799,7 +815,7 @@ return
dlg = thgimport.ImportDialog(self.repo, self, mq=True)
dlg.finished.connect(dlg.deleteLater)
- dlg.setfilepaths(filepaths)
+ dlg.setfilepaths(patches)
dlg.exec_()
# End drop events
|
@@ -9,7 +9,7 @@ import binascii
import os
-from mercurial import util, revset, error
+from mercurial import util, revset, error, patch
from tortoisehg.util import shlib, hglib
@@ -435,19 +435,36 @@ self.generateMultipleSelectionMenu()
self.generateBundleMenu()
+ def detectPatches(self, paths):
+ filepaths = []
+ for p in paths:
+ if not os.path.isfile(p):
+ continue
+ try:
+ pf = open(p, 'rb')
+ filename, message, user, date, branch, node, p1, p2 = \
+ patch.extract(self.repo.ui, pf)
+ if filename:
+ filepaths.append(p)
+ os.unlink(filename)
+ except Exception, e:
+ pass
+ return filepaths
+
def dragEnterEvent(self, event):
paths = [unicode(u.toLocalFile()) for u in event.mimeData().urls()]
- if util.any(os.path.isfile(p) for p in paths):
+ if self.detectPatches(paths):
event.setDropAction(Qt.CopyAction)
event.accept()
def dropEvent(self, event):
paths = [unicode(u.toLocalFile()) for u in event.mimeData().urls()]
- filepaths = [p for p in paths if os.path.isfile(p)]
- if filepaths:
- self.thgimport(filepaths)
- event.setDropAction(Qt.CopyAction)
- event.accept()
+ patches = self.detectPatches(paths)
+ if not patches:
+ return
+ event.setDropAction(Qt.CopyAction)
+ event.accept()
+ self.thgimport(patches)
## Begin Workbench event forwards
|
Loading...