Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.0.3, 2.0.4, and 2.0.5

stable repowidget: do not open thgimport for dropped files if not patches (fixes #320)

Changeset a34f3284f7f4

Parent b8d1fbd7634a

by Steve Borho

Changes to 2 files · Browse files at a34f3284f7f4 Showing diff from parent b8d1fbd7634a Diff from another changeset...

 
782
783
784
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
785
786
787
788
789
 
 
 
 
790
791
792
793
794
 
 
795
796
797
 
799
800
801
802
 
803
804
805
 
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
 
 
 
 
802
803
804
805
806
807
808
 
 
809
810
811
812
813
 
815
816
817
 
818
819
820
821
@@ -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
10
11
12
 
13
14
15
 
435
436
437
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
438
439
440
 
441
442
443
444
445
446
447
448
449
450
 
 
 
 
 
 
451
452
453
 
9
10
11
 
12
13
14
15
 
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
 
456
457
458
459
460
461
 
 
 
 
 
462
463
464
465
466
467
468
469
470
@@ -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