Queue typing changes and wait for saved selections
This commit is contained in:
1 parent
e210b47e33
commit
fbc6daea8b
2 files changed
+51
-20
No files matched your search
@@ -3,7 +3,7 @@
|
|||||||
# omarchy:summary=Pick one or multiple options from a menu
|
# omarchy:summary=Pick one or multiple options from a menu
|
||||||
# omarchy:group=menu
|
# omarchy:group=menu
|
||||||
# omarchy:name=select
|
# omarchy:name=select
|
||||||
# omarchy:args=prompt [option...] [-- --multiple --selected <value> --width <pixels> --maxheight <pixels>]
|
# omarchy:args=prompt [option...] [-- --multiple --selected <value> --on-change <command-json> --width <pixels> --maxheight <pixels>]
|
||||||
# omarchy:examples=omarchy menu select Format jpg png|omarchy-menu-select Resolution 4k 1080p 720p -- --width 400
|
# omarchy:examples=omarchy menu select Format jpg png|omarchy-menu-select Resolution 4k 1080p 720p -- --width 400
|
||||||
|
|
||||||
# An option may lead with an icon, as "<glyph><TAB><label>", and may trail a
|
# An option may lead with an icon, as "<glyph><TAB><label>", and may trail a
|
||||||
@@ -14,7 +14,8 @@
|
|||||||
|
|
||||||
# With --multiple, clicking/Enter toggles rows and Apply returns a JSON array.
|
# With --multiple, clicking/Enter toggles rows and Apply returns a JSON array.
|
||||||
# --on-change takes a JSON command array; each toggle runs it with the selection
|
# --on-change takes a JSON command array; each toggle runs it with the selection
|
||||||
# JSON appended, applies immediately, and needs no Apply row.
|
# JSON appended, applies immediately, and needs no Apply row. A successful
|
||||||
|
# command may print a JSON array of actual selections to update the checkmarks.
|
||||||
# --selected takes a returned value (label plus any subtext), and can be repeated.
|
# --selected takes a returned value (label plus any subtext), and can be repeated.
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|||||||
+48
-18
@@ -797,14 +797,9 @@ Item {
|
|||||||
root.applyDmenuSelection(JSON.stringify(MenuModel.dmenuSelections(root.dmenuOptions, root.dmenuSelected)))
|
root.applyDmenuSelection(JSON.stringify(MenuModel.dmenuSelections(root.dmenuOptions, root.dmenuSelected)))
|
||||||
} else {
|
} else {
|
||||||
var value = MenuModel.dmenuValue(root.dmenuOptions[Number(picked.itemId.substring(6))])
|
var value = MenuModel.dmenuValue(root.dmenuOptions[Number(picked.itemId.substring(6))])
|
||||||
var selected = MenuModel.toggleDmenuSelection(root.dmenuSelected, value)
|
var selected = MenuModel.toggleDmenuSelection(selectionProc.requestedSelection(), value)
|
||||||
if (root.dmenuOnChange.length > 0) {
|
if (root.dmenuOnChange.length > 0) {
|
||||||
if (selectionProc.running) return
|
selectionProc.enqueue(selected)
|
||||||
selectionProc.collected = ""
|
|
||||||
selectionProc.serial = root.requestSerial
|
|
||||||
selectionProc.selected = MenuModel.dmenuSelections(root.dmenuOptions, selected, true)
|
|
||||||
selectionProc.command = root.dmenuOnChange.concat([JSON.stringify(selectionProc.selected)])
|
|
||||||
selectionProc.running = true
|
|
||||||
} else {
|
} else {
|
||||||
root.dmenuSelected = selected
|
root.dmenuSelected = selected
|
||||||
root.updateDmenuChecks()
|
root.updateDmenuChecks()
|
||||||
@@ -994,19 +989,54 @@ Item {
|
|||||||
id: selectionProc
|
id: selectionProc
|
||||||
property int serial: 0
|
property int serial: 0
|
||||||
property var selected: []
|
property var selected: []
|
||||||
|
property var queue: []
|
||||||
property string collected: ""
|
property string collected: ""
|
||||||
stdout: StdioCollector { onStreamFinished: selectionProc.collected = text }
|
|
||||||
onExited: function(exitCode) {
|
function requestedSelection() {
|
||||||
if (serial !== root.requestSerial || !root.dmenuActive) return
|
for (var i = queue.length - 1; i >= 0; i--) {
|
||||||
if (exitCode === 0) {
|
if (queue[i].serial === root.requestSerial) return queue[i].selected
|
||||||
var applied = selected
|
|
||||||
if (collected.trim()) {
|
|
||||||
try { applied = JSON.parse(collected) } catch (error) { return }
|
|
||||||
if (!Array.isArray(applied)) return
|
|
||||||
}
|
|
||||||
root.dmenuSelected = MenuModel.dmenuSelections(root.dmenuOptions, applied, true)
|
|
||||||
}
|
}
|
||||||
root.updateDmenuChecks()
|
if (running && serial === root.requestSerial) return selected
|
||||||
|
return root.dmenuSelected
|
||||||
|
}
|
||||||
|
|
||||||
|
function enqueue(values) {
|
||||||
|
var selected = MenuModel.dmenuSelections(root.dmenuOptions, values, true)
|
||||||
|
queue = queue.concat([{
|
||||||
|
serial: root.requestSerial, selected: selected,
|
||||||
|
command: root.dmenuOnChange.concat([JSON.stringify(selected)])
|
||||||
|
}])
|
||||||
|
if (!running) startNext()
|
||||||
|
}
|
||||||
|
|
||||||
|
function startNext() {
|
||||||
|
if (queue.length === 0) return
|
||||||
|
var change = queue[0]
|
||||||
|
queue = queue.slice(1)
|
||||||
|
serial = change.serial
|
||||||
|
selected = change.selected
|
||||||
|
collected = ""
|
||||||
|
command = change.command
|
||||||
|
running = true
|
||||||
|
}
|
||||||
|
|
||||||
|
stdout: StdioCollector {
|
||||||
|
waitForEnd: true
|
||||||
|
onStreamFinished: selectionProc.collected = text
|
||||||
|
}
|
||||||
|
onExited: function(exitCode) {
|
||||||
|
if (serial === root.requestSerial && root.dmenuActive) {
|
||||||
|
if (exitCode === 0) {
|
||||||
|
var applied = selected
|
||||||
|
if (collected.trim()) {
|
||||||
|
try { applied = JSON.parse(collected) } catch (error) { applied = root.dmenuSelected }
|
||||||
|
}
|
||||||
|
if (Array.isArray(applied))
|
||||||
|
root.dmenuSelected = MenuModel.dmenuSelections(root.dmenuOptions, applied, true)
|
||||||
|
}
|
||||||
|
root.updateDmenuChecks()
|
||||||
|
}
|
||||||
|
startNext()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user