Commits

Yuya Nishihara committed a4be395

mq multiselect

Comments (0)

Files changed (2)

mq-multiselect.diff

+# HG changeset patch
+# Date 1381934030 -32400
+# Parent b544b88f762a6b0392d4d3b28a7890a2a98c275e
+mqdock: allow to delete and reorder more than one patches
+
+_updatePatchActions is removed from onPatchSelected, which is actually the
+handler of currentRowChanged signal, because currentRowChanged is followed
+by selectionChanged.
+
+diff --git a/tortoisehg/hgqt/mq.py b/tortoisehg/hgqt/mq.py
+--- a/tortoisehg/hgqt/mq.py
++++ b/tortoisehg/hgqt/mq.py
+@@ -10,6 +10,8 @@ import os
+ from PyQt4.QtCore import *
+ from PyQt4.QtGui import *
+ 
++from mercurial import util
++
+ from tortoisehg.util import hglib
+ from tortoisehg.hgqt.i18n import _
+ from tortoisehg.hgqt import cmdcore, qtlib, cmdui, thgrepo
+@@ -461,7 +463,9 @@ class PatchQueueModel(QAbstractListModel
+ 
+     def mimeData(self, indexes):
+         repo = self._repoagent.rawRepo()
+-        patches = [self._series[i.row()] for i in indexes]
++        # in the same order as series file
++        patches = [self._series[i.row()]
++                   for i in sorted(indexes, reverse=True)]
+         data = QMimeData()
+         data.setData('application/vnd.thg.mq.series',
+                      QByteArray('\n'.join(patches) + '\n'))
+@@ -578,6 +582,8 @@ class MQPatchesWidget(QDockWidget):
+         self.queueListWidget.setDragDropMode(QAbstractItemView.InternalMove)
+         self.queueListWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
+         self.queueListWidget.setIconSize(QSize(12, 12))
++        self.queueListWidget.setSelectionMode(
++            QAbstractItemView.ExtendedSelection)
+         self.queueListWidget.setContextMenuPolicy(Qt.CustomContextMenu)
+         self.queueListWidget.customContextMenuRequested.connect(
+             self.onMenuRequested)
+@@ -636,6 +642,7 @@ class MQPatchesWidget(QDockWidget):
+             newmodel.dataChanged.connect(self._updatePatchActions)
+             selmodel = self.queueListWidget.selectionModel()
+             selmodel.currentRowChanged.connect(self.onPatchSelected)
++            selmodel.selectionChanged.connect(self._updatePatchActions)
+             self._updatePatchActions()
+         else:
+             self.queueListWidget.setModel(None)
+@@ -674,9 +681,10 @@ class MQPatchesWidget(QDockWidget):
+ 
+     @pyqtSlot()
+     def onDelete(self):
+-        index = self.queueListWidget.currentIndex()
+-        patch = self.queueListWidget.model().patchName(index)
+-        self.patchActions.deletePatches([patch])
++        model = self.queueListWidget.model()
++        selmodel = self.queueListWidget.selectionModel()
++        patches = map(model.patchName, selmodel.selectedRows())
++        self.patchActions.deletePatches(patches)
+ 
+     #@pyqtSlot(QModelIndex)
+     def onGotoPatch(self, index):
+@@ -692,8 +700,6 @@ class MQPatchesWidget(QDockWidget):
+ 
+     #@pyqtSlot(QModelIndex)
+     def onPatchSelected(self, index):
+-        'Patch has been selected, update buttons'
+-        self._updatePatchActions()
+         if index.isValid():
+             model = self.queueListWidget.model()
+             self.patchSelected.emit(model.patchName(index))
+@@ -701,6 +707,7 @@ class MQPatchesWidget(QDockWidget):
+     @pyqtSlot()
+     def _updatePatchActions(self):
+         model = self.queueListWidget.model()
++        selmodel = self.queueListWidget.selectionModel()
+ 
+         appliedcnt = model.appliedCount()
+         seriescnt = model.rowCount()
+@@ -709,11 +716,11 @@ class MQPatchesWidget(QDockWidget):
+         self.qpopAct.setEnabled(appliedcnt > 0)
+         self.qpopAllAct.setEnabled(appliedcnt > 0)
+ 
+-        index = self.queueListWidget.currentIndex()
+-        self.qdeleteAct.setEnabled(index.isValid()
+-                                   and not model.isApplied(index))
+-        self.setGuardsAct.setEnabled(index.isValid())
+-        self.qrenameAct.setEnabled(index.isValid())
++        indexes = selmodel.selectedRows()
++        anyapplied = util.any(model.isApplied(i) for i in indexes)
++        self.qdeleteAct.setEnabled(len(indexes) > 0 and not anyapplied)
++        self.setGuardsAct.setEnabled(len(indexes) == 1)
++        self.qrenameAct.setEnabled(len(indexes) == 1)
+ 
+     @pyqtSlot(QString)
+     def onQQueueActivated(self, text):
 repow-mqstatus.diff
+mq-multiselect.diff
 ci-checked.diff
 cmdui-height.diff
 cmdui-mark-setlogvisible.diff
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.