MQ: Implement keyboard shortcut Shift+Enter for "Unapply one patch" from patch queue (or "Unapply up to this patch")
Created originally on Bitbucket by thomasdd (Thomas D.)
As a regular user of MQ aka “Patch Queue” for many years, I often need to unapply the first (and only) applied patch in the queue (qbase = qtip). Pressing Enter comes to mind, but that only stubbornly repeats “Go to patch” although this patch is already qtip. I could not find any other way of doing this with keyboard, because both “Unapply one patch” and “Unapply all patches” are not keyboard accessible. The click targets on the Patch Queue toolbar are very small, and the icons look very similar, so not easy to target.
STR:
- MQ/Patch Queue widget: have exactly one applied patch (qbase = qtip)
- Try to unapply that patch using keyboard only
Actual result
- all ways of unapplying this patch (qbase = qtip) are not keyboard accessible
Expected result
- Pressing plain ENTER on qtip could helpfully unapply qtip (rather than trying and failing to “Go to this patch” which doesn’t make sense because it’s already qtip)
- Pressing Shift+Enter with focus in Patch Queue should at least trigger the existing action “Unapply one patch” (regardless of selection). That’s a very basic solution which requires something like 4 lines of code, @{557058:4b06a480-f21c-438a-ac32-49c7e6bffe0a} has done exactly the same for F2 in issue
#4915 (closed). - If we want to be a bit smarter and more helpful, we could try this:
Shift+Enter → “Unapply up to this patch” (for single selection of an applied patch)
“Unapply selected patches” (for multiple, contiguous selection including qtip)
Pseudo Code for advanced handling of Shift+Enter (3 above):
If ((selectedPatchs.length == 0) OR // focus only on any single patch
(selectedPatches.length == 1 AND selectedPatches.isApplied == false)) // selection of single, unapplied patch
doAction ("Unapply one patch") // same action as clicking on the toolbar icon
Else If (selectedPatches.length == 1 AND selectedPatches(0).isApplied == true) // single applied patch selected
// “Unapply up to this patch”
If (patch(selectedPatch.index - 1).exists == true) // If there’s an applied patch below the selected patch…
doAction (“Go to patch(selectedPatch.index - 1)”) // use existing action to unapply topmost patches
Else // if only qbase is selected,
doAction (“Unapply all patches”) // use existing action: unapply all
End if
Else If (selection.isContiguous == true) // multiple and contiguous selection
For each (selPatch of selectedPatches)
If selPatch.isQtip
selectionContainsQtip = true
If selPatch.isQbase
selectionContainsQbase = true
End for
If (selectionContainsQtip == true AND selectionContainsQbase = true) // all applied patches are selected
doAction(“Unapply all patches”) // use existing action: unapply all
Else if (selectionContainsQtip == true)
doAction(“Go to patch (selectedPatches.length)”) // use existing action to unapply topmost selected patches
// by going to the patch below the selection
Else // contiguous selection excluding qtip
return // do nothing
End if
Else // multiple, con-contiguous selection
return // do nothing
End if
Or by analogy to disable our new command for those cases where the pseudo code has return.