1. TortoiseHg
  2. TortoiseHg
  3. thg

Commits

Angel Ezquerra  committed 0e6a0b8

reporegistry: allow dragging groups into groups

In order to still be able to drag groups to top level, dragging groups
behaves differently depending on whether you drag the group into another
group or into a repo inside a group.

Dragging a group into an repo inside a group will put the repo inside
the corresponding group (as could be expected).

Dragging a group into a group will place the group _at the same level_
as the target group (i.e. it will not drag the group _inside_ the
target group). This may be a bit counter-intuitive, but is the only
way I've found to still allow dragging a group to the top level.

  • Participants
  • Parent commits dc2816c
  • Branches default

Comments (0)

Files changed (2)

File tortoisehg/hgqt/reporegistry.py

View file
  • Ignore whitespace
         index = self.indexAt(event.pos())
 
         # Determine where the item was dropped.
-        # Depth in tree: 1 = group, 2 = repo, and (eventually) 3+ = subrepo
-        depth = self.model().depth(index)
-        if depth == 1:
+        target = index.internalPointer()
+        if not target.isRepo():
             group = index
             row = -1
-        elif depth == 2:
+        else:
             indicator = self.dropIndicatorPosition()
             group = index.parent()
             row = index.row()
             if indicator == QAbstractItemView.BelowItem:
                 row = index.row() + 1
-        else:
-            index = group = row = None
 
         return index, group, row
 

File tortoisehg/hgqt/repotreemodel.py

View file
  • Ignore whitespace
         group = parent.internalPointer()
         d = str(data.data(repoRegMimeType))
         if not data.hasUrls():
-            # don't allow nesting of groups
-            row = parent.row()
-            group = self.rootItem
-            parent = QModelIndex()
+            # The source is a group
+            if row < 0:
+                # The group has been dropped on a group
+                # In that case, place the group at the same level as the target
+                # group
+                row = parent.row()
+                parent = parent.parent()
+                group = parent.internalPointer()
+                if row < 0 or not isinstance(group, RepoGroupItem):
+                    # The group was dropped at the top level
+                    group = self.rootItem
+                    parent = QModelIndex()
         itemread = readXml(d, extractXmlElementName)
         if itemread is None:
             return False