@@ -493,19 +493,6 @@ function LauncherUI:on_autocomplete(_, option)
493493 end
494494end
495495
496- local function launch (kwargs )
497- view = LauncherUI {parent_focus = dfhack .gui .getCurFocus (true )}
498- view :show ()
499- view :on_edit_input (' ' )
500- if kwargs .initial_help then
501- view .subviews .help :set_help (kwargs .initial_help )
502- end
503- if kwargs .command then
504- view .subviews .edit :set_text (kwargs .command )
505- view :on_edit_input (kwargs .command )
506- end
507- end
508-
509496function LauncherUI :onDismiss ()
510497 view = nil
511498end
@@ -515,10 +502,9 @@ function LauncherUI:run_command(reappear, command)
515502 if # command == 0 then return end
516503 dfhack .addCommandToHistory (HISTORY_ID , HISTORY_FILE , command )
517504 record_command (command )
518- self :dismiss ()
519- -- remove our (dismissed) viewscreen from the stack while we run the
520- -- command. this allows hotkey guards and tools that interact with the top
521- -- viewscreen without checking whether it is active to work reliably.
505+ -- remove our viewscreen from the stack while we run the command. this
506+ -- allows hotkey guards and tools that interact with the top viewscreen
507+ -- without checking whether it is active to work reliably.
522508 local output = dfhack .screen .hideGuard (self , dfhack .run_command_silent ,
523509 command )
524510 if # output > 0 then
@@ -529,14 +515,17 @@ function LauncherUI:run_command(reappear, command)
529515 end
530516 -- if we displayed a new dfhack screen, don't come back up even if reappear
531517 -- is true so the user can interact with the new screen.
532- local parent_focus = dfhack .gui .getCurFocus ( true )
518+ local parent_focus = dfhack .gui .getFocusString ( self . _native . parent )
533519 if not reappear or (parent_focus :startswith (' dfhack/' ) and
534- parent_focus ~= prev_parent_focus ) then
520+ parent_focus ~= self .parent_focus ) then
521+ self :dismiss ()
535522 return
536523 end
537524 -- reappear and show the command output
538- local initial_help = (' > %s\n\n %s' ):format (command , output )
539- launch ({initial_help = initial_help })
525+ self .parent_focus = parent_focus
526+ self .subviews .edit :set_text (' ' )
527+ self :on_edit_input (' ' )
528+ self .subviews .help :set_help ((' > %s\n\n %s' ):format (command , output ))
540529end
541530
542531function LauncherUI :getWantedFrameSize ()
@@ -609,6 +598,9 @@ if view then
609598 -- hotkey a second time) should close the dialog
610599 view :dismiss ()
611600else
612- local args = {... }
613- launch ({command = table.concat (args , ' ' )})
601+ view = LauncherUI {parent_focus = dfhack .gui .getCurFocus (true )}
602+ view :show ()
603+ local initial_command = table.concat ({... }, ' ' )
604+ view .subviews .edit :set_text (initial_command )
605+ view :on_edit_input (initial_command )
614606end
0 commit comments