hi,
i have yet another issue i cannot figure out. it is probably purely GTK related, rather than gtkD, but i could not find it covered/explained anywhere. i would greatly appreciate a bit of help here.
so i want to create this dialog for checked input (see code example below), for starters just an int. i don't want to allow the user to leave the Entry field with invalid input, e.g. a string. even the [OK] and [Cancel] buttons shall be no way out. well, i managed to cope with (not) leaving using 'tab' key, but the [OK] and [Cancel] buttons will break my checked input - unless i display an error message as well. this is quite an ugly workaround and i rather do without.
module testfocus;
import gtk.Main, gtk.Widget, gtk.Dialog;
import gtk.MessageDialog, gtk.VBox, gtk.Entry;
import gdk.Event;
import std.stdio, std.conv;
int main(string[] args){
Main.init( args );
int i = 42;
auto dlg = new Dialog( "input values", null,
DialogFlags.MODAL, ["OK", "Cancel"],
[ResponseType.ACCEPT, ResponseType.CANCEL]
);
auto entry = new Entry( "enter an int" );
bool test(Event e, Widget w){
string test = entry.getText();
try{
auto tmp = to!(int)( test );
i = tmp;
}catch{
// comment this back in and it works, i.e.
// even [OK] and [Cancel] won't break checked input:
// auto msgbx = new MessageDialog( dlg,
// DialogFlags.DESTROY_WITH_PARENT+DialogFlags.MODAL,
// MessageType.ERROR, ButtonsType.CLOSE, "invalid value"
// );
// msgbx.run();
// msgbx.destroy();
w.grabFocus(); // works only when losing focus with tab, while
// [OK] and [Cancel] break checked input!
return true;
}
return false;
}
entry.addOnFocusOut(&test, ConnectFlags.AFTER);
auto vbox = dlg.getContentArea();
vbox.add(entry);
dlg.showAll();
if( ResponseType.ACCEPT == dlg.run() ){
writeln( "i = "~to!string(i) );
}
dlg.destroy();
return 0;
}