Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.1, 2.1.1, and 2.1.2

reporegistry: add support for drag & drop to subrepo items

SubrepoItems that are at the top level of the repo registry (i.e. whose parent
is a RepoGroupItem) will be moved, while SubrepoItems whose parent is a
RepoItem or another SubrepoItem will be moved.

Changeset bcfafe423cfd

Parent fc40752a5a78

by Angel Ezquerra

Changes to 2 files · Browse files at bcfafe423cfd Showing diff from parent fc40752a5a78 Diff from another changeset...

 
46
47
48
 
49
50
51
 
94
95
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
98
99
 
102
103
104
105
 
106
107
108
109
110
111
 
46
47
48
49
50
51
52
 
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
 
124
125
126
 
127
128
129
 
130
131
132
@@ -46,6 +46,7 @@
  self.setAcceptDrops(True)   self.setAutoScroll(True)   self.setDragDropMode(QAbstractItemView.DragDrop) + self.setDefaultDropAction(Qt.MoveAction)   self.setDropIndicatorShown(True)   self.setEditTriggers(QAbstractItemView.DoubleClicked)   self.setSelectionBehavior(QAbstractItemView.SelectRows) @@ -94,6 +95,27 @@
    return index, group, row   + def startDrag(self, supportedActions): + indexes = self.selectedIndexes() + # Make sure that all selected items are of the same type + if len(indexes) == 0: + # Nothing to drag! + return + + # Make sure that all items that we are dragging are of the same type + firstItem = indexes[0].internalPointer() + selectionInstanceType = type(firstItem) + for idx in indexes[1:]: + if selectionInstanceType != type(idx.internalPointer()): + # Cannot drag mixed type items + return + + # Each item type may support different drag & drop actions + # For instance, suprepo items support Copy actions only + supportedActions = firstItem.getSupportedDragDropActions() + + super(RepoTreeView, self).startDrag(supportedActions) +   def dropEvent(self, event):   data = event.mimeData()   index, group, row = self.dropLocation(event) @@ -102,10 +124,9 @@
  if event.source() is self:   # Event is an internal move, so pass it to the model   col = 0 - drop = self.model().dropMimeData(data, Qt.MoveAction, row, + drop = self.model().dropMimeData(data, event.dropAction(), row,   col, group)   if drop: - event.setDropAction(Qt.MoveAction)   event.accept()   else:   # Event is a drop of an external repo
 
134
135
136
 
 
 
137
138
139
 
319
320
321
322
323
324
325
326
327
328
 
 
 
 
 
 
329
330
331
 
134
135
136
137
138
139
140
141
142
 
322
323
324
 
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
@@ -134,6 +134,9 @@
  def okToDelete(self):   return True   + def getSupportedDragDropActions(self): + return Qt.MoveAction +    class RepoItem(RepoTreeItem):   def __init__(self, root=None, parent=None): @@ -319,13 +322,18 @@
  return super(SubrepoItem, self).data(column, role)     def menulist(self): - print self._parent   if isinstance(self._parent, RepoGroupItem):   return super(SubrepoItem, self).menulist()   else:   return ['open', 'clone', None, 'explore', 'terminal',   None, 'settings']   + def getSupportedDragDropActions(self): + if issubclass(type(self.parent()), RepoGroupItem): + return Qt.MoveAction + else: + return Qt.CopyAction +    class RepoGroupItem(RepoTreeItem):   def __init__(self, name=None, parent=None):