Page 1 of 1

How to reload the dialog or the script itself after using the SimpleDialog

Posted: Wed Nov 08, 2023 5:23 am
by 570295535
I use SimpleDialog and DoModeless () to create the modeless dialog box, and then when I append or delete a button, I have to manually close script and reopen script .

Is there a function to reload SimpleDialog?Alternatively, there are other ways to reload the script itself?

Using XXX:Run(moho) causes multiple dialog boxes, and the old dialog box does not close.

Re: How to reload the dialog or the script itself after using the SimpleDialog

Posted: Wed Nov 08, 2023 6:10 pm
by SimplSam
There is currently no built-in function to dynamically update the structure of open dialogs - like adding or removing widgets, so a work-around would be to close and reopen the dialog. However - there is currently no built-in mechanism to close dialogs, so ...

Something derived from @Rai Lopez

Add a textlist which sends Cancel when an item is selected.

Code: Select all

  d.cancelTextList = LM.GUI.ImageTextList(0, 1, LM.GUI.MSG_CANCEL)
  d.cancelTextList:AddItem("", false)
  l:AddChild(d.cancelTextList, LM.GUI.ALIGN_LEFT, 0)
Then in your HandleMessage code, you will trigger the cancelTextList by selecting an item to close the dialog, then open a new one.

Code: Select all

  self.cancelTextList:SetSelItem(self.cancelTextList:GetItem(0), false) -- Close
  
  myScript.myDlog = myScriptDialog:new(moho) -- ReCreate
  myScript.myDlog:DoModeless() -- ReOpen
Also ensure that you are using moho 14.1 (latest) as it is a lot more stable with modeless dialogs that 14.0

Re: How to reload the dialog or the script itself after using the SimpleDialog

Posted: Thu Nov 09, 2023 1:43 pm
by 570295535
SimplSam wrote: Wed Nov 08, 2023 6:10 pm

Code: Select all

  d.close = LM.GUI.ImageTextList(0, 1, LM.GUI.MSG_CANCEL)
  l:AddChild(d.close, LM.GUI.ALIGN_LEFT, 0)

Code: Select all

  self.close:SetSelItem(false) -- Close
  myScript.dlog = nil
  myScript.dlog = myScript:new(moho) -- ReCreate
  myScript.dlog:DoModeless() -- ReOpen
Thank you SimplSam, I have referenced Lukas' LK_LayerFinder script, combined with the code you provided, successfully added new buttons to the control dynamically, but the window coordinates after reloading the script are always in the middle of the screen. I hope the official can add the API for saving the location coordinates of the modeless dialog box, as well as other APIs such as delayed execution.