Pastey dialog with input

include GtkEngine.e
object project_name = "My Project", temp_name =  0  
    win = create(GtkWindow,"size=100x100,border=10,$destroy=Quit"), 
    pan = create(GtkBox,"orientation=vertical"), 
    box = create(GtkButtonBox), 
    btn1 = create(GtkButton,"gtk-quit","Quit"), 
    btn2 = create(GtkButton,"gtk-ok","OK") 
global function OK() 
atom inp = create(GtkEntry,"name=input,$unrealize=Update,text=" & project_name) 
if Custom(,,"Title","New project name:",GTK_BUTTONS_OK_CANCEL,,,,inp) = MB_OK then 
   project_name = temp_name -- update only on OK button 
end if  
return 1 
end function 
global function Update(atom ctl) 
temp_name = get("input","text") -- save the contents 
return 0 
end function

1. Comment by irv 3 weeks ago

How this works:

You can attach one "addon" object to any of the built-in EuGTK dialogs (Info, Error, etc). That addon can be one Gtk widget, or a container with several widgets. This works well for widgets like toggle buttons, check buttons, etc, which can be linked directly to toggle functions "on click".

However, for text widgets, you have to get the updated text before the dialog is dismissed, because all the widgets contained within are destroyed along with the dialog.

One way to do this is to catch the "about to be deleted" event, which emits an "unrealize" signal before the containing window is destroyed. We can then get the current contents before it all goes away.

However, we may sometimes want to cancel the whole thing, and not update the prior value, despite entering some new text into the text widget. To do this, we use the return value from closing the dialog (OK button does an update, other button(s) retain the previous value).