October 9, 2013 at 10:52 pm #14020
Hi, I am using a Modal Window based of Atom’s demo panel. However the function attached to it runs regardless of whether I select OK or cancel.
I have tried various lines of code to try to capture the return values but with no success. Here’s the method:
function renamePatch() if panel:getRestoreState() == true or panel:getProgramState() == true then return end -- ////////// Get Name For Rename Dialogue ////////// nameData = L(PatchLabel:getProperty("uiLabelText")) function trim (s) return (string.gsub(s, "^%s*(.-)%s*$", "%1")) end nameTrim = (trim(nameData)) -- //////////////////////////////////////////// -- ////////// Create Rename Dialogue ////////// modalWindow = AlertWindow("\n\nRename the Editor patch,\nup to 16 characters long.", "Please remember to save the\namended patch and name to\nyour Kiwi-3P synthesizer.", AlertWindow.InfoIcon) modalWindow:addButton("Cancel", 0, KeyPress(KeyPress.escapeKey), KeyPress()) modalWindow:addButton(" OK ", 1, KeyPress(KeyPress.returnKey), KeyPress()) modalWindow:addTextEditor ("renameTextEditor", (nameTrim), "Rename As:", false) modalWindow:setModalHandler(windowCallback) modalWindow:runModalLoop() textEditor = modalWindow:getTextEditor("renameTextEditor"):getText() if textEditor ~= nil then PatchLabel:setProperty("uiLabelText", (textEditor), false) end if textEditor == "" then PatchLabel:setProperty("uiLabelText", "Untitled Patch ", false) end end -- ////////// End Rename Dialogue ////////// -- ////////////////////////////////////////////
So the question is two part; What code do I need to capture the OK & Cancel values? Should it go in the windowCallback method or in the method above?October 9, 2013 at 11:13 pm #14021
runModalLoop() returns a number that indicates what button was pressed to dismiss the window.October 9, 2013 at 11:19 pm #14022
Cheers Atom, so something like:
if runModalLoop == 1 then textEditor = modalWindow:getTextEditor blah blah blah
Should do it then.October 9, 2013 at 11:25 pm #14023
ret = modalWindow:runModalLoop() if ret == 1 then -- i think this is OK button end if ret == 0 then -- this should be cancel end -- but it might be the other way aroundOctober 9, 2013 at 11:27 pm #14024
Excellent, indeed the values are the correct way around. Thanks again : )October 10, 2013 at 12:18 am #14025
OK that works, however it requires each button to be pressed twice before dismissing the window. Same if I use keystrokes.October 10, 2013 at 3:02 pm #14041
The double stuff might be caused bu the modal callbacks subsystem, If you want just a simple window that displays a messages and has a OK/Cancel button this will work
ret = utils.questionWindow("title", "message", "OK", "Cancel") if ret then console ("true") else console("false") end
Of if you want to get a text response from the user, you can use the other method in the utils
askForTextInputWindow (const String title, const String message, const String initialInputContent, const String onScreenLabel, const bool isPassword, const String button1Text, const String button2Text);October 12, 2013 at 11:01 am #14097
Hi Atom, I have finally found some time to sit down and look at this. I have opted for the ‘askForTextInputWindow’ as a text response is required.
I have been trying to get the return values from the buttons in this window with no success… also I will need to get the initialInputContent. Any pointers gratefully received.
I have been trawling the Juce site for info, but to no avail.October 12, 2013 at 11:09 am #14098
This method will never return anything except a string that is typed in the window. You won’t know what button was pressed i’m afraid you only get the string inside the window, this is a very simple “get a line of text from user” method with no error checking.October 12, 2013 at 11:24 am #14099
Fair enough, so I can set button2 to false and just have an OK button then.October 12, 2013 at 12:31 pm #14102
MMMMmmmm that didn’t work, so I have window two buttons that in effect do the same thing and I cannot remove of one of them.
I think in this instance it would be better of use the Model Window with only one button and no return callbacks. : )October 12, 2013 at 9:31 pm #14109
Hi Atom, it seems I have resolved my issue with the Modal Window…
A silly misunderstanding on my part, which became obvious when I revisited the method. When you instructed me to add
ret = modalWindow:runModalLoop()to get the button return values. I added the whole statement to the method.
This meant that I ended up with
modalWindow:runModalLoop() ret = modalWindow:runModalLoop()
hence why the buttons required two presses before dismissing the window.
Amateurs eh!! I realise now that I only needed to add
Thanks for your patience as always.
- This reply was modified 3 years, 11 months ago by lfo2vco.
You must be logged in to reply to this topic.