run multiple NATCommands

This commit is contained in:
2022-10-09 00:33:58 +00:00
parent 98cbd9e28e
commit 9c76eebe28
3 changed files with 18 additions and 6 deletions

View File

@@ -128,16 +128,20 @@
(lambda :Void []
(_collectAndValidateArg arg stream ->:Void [:Dynamic argValue] {(collectedArgs.push argValue) (lastCollector)})))
(method :Void tryRunCommand [:String command]
(method :Void tryRunCommand [:String command &opt :Void->Void doAfter]
(let [parts (command.split " ")
commandName (parts.shift)
stream (Stream.fromString (parts.join " "))
lowerCommandName (commandName.toLowerCase)]
(if (commands.exists lowerCommandName)
(_runCommand (dictGet commands lowerCommandName) stream)
(_runCommand (dictGet commands lowerCommandName) stream doAfter)
(ui.reportError "$commandName is not a valid command"))))
(method :Void _runCommand [:Command command :Stream stream]
(method :Void tryRunCommands [:Array<String> commands]
(when commands
(tryRunCommand (commands.shift) ->:Void (tryRunCommands commands))))
(method :Void _runCommand [:Command command :Stream stream &opt :Void->Void doAfter]
(let [collectedArgs
[]
&mut lastCollector
@@ -149,7 +153,8 @@
(when lastChangeSet
(doFor e lastChangeSet
(assert (and e (isEntry e)) "Lib function forgot to return the Entry that was modified"))
(ui.handleChanges archive lastChangeSet))))]
(ui.handleChanges archive lastChangeSet)
(when doAfter (doAfter)))))]
// To facilitate asynchronous arg input via UI, we need to construct an insanely complicated nested callback to give the UI
(doFor arg (reverse command.args)
(set lastCollector (_composeArgCollector collectedArgs arg stream lastCollector)))
@@ -321,6 +326,12 @@
(AddKeyShortcut e description)
(AddNATCommand [e] command)})])
(defCommand CreateMultiCommandShortcut [description (Text null) commands (VarText null)]
[(archive.createEntry ->e {
(addComponent archive e Name description)
(AddKeyShortcut e description)
(AddNATCommands [e] commands)})])
(defCommand AddFiles [entries (SelectedEntries 1 null)
// TODO add File and Files as an argument type for commands, ArchiveUI
// TODO make tkinter file browser externs and use tkinter as the file picking mechanism for CLI

View File

@@ -32,6 +32,5 @@
((hasComponent e NATCommand)
(controller.tryRunCommand (readComponent e NATCommand)) 0)
((hasComponent e NATCommands)
// TODO chain them together asynchronously (they may be partial)
0)
(controller.tryRunCommands (readComponent e NATCommands)) 0)
(true (ui.displayMessage "tried to invoke ${e.id} but it has no available actions"))) 0)