Skip to content

Commit

Permalink
fixed focus_out_event not handled properly
Browse files Browse the repository at this point in the history
  • Loading branch information
naxuroqa committed May 21, 2014
1 parent c98d4b4 commit f7e0044
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/ui/EditableLabel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,30 @@ namespace Venom {
label_changed(entry.text);
}

private bool check_focus() {
unowned Gtk.Widget w = get_toplevel();
if(!w.is_toplevel() || !(w is Gtk.Window)) {
//could not get window for some reason, abort
stderr.printf("Could not get reference to toplevel window\n");
return false;
}
unowned Gtk.Widget focus_widget = (w as Gtk.Window).get_focus();
if(focus_widget == null) {
// try again
return true;
}
if(focus_widget != entry && focus_widget != button_ok && focus_widget != button_cancel) {
// other widget focused
on_cancel();
}
return false;
}

private bool on_focus_out(Gdk.EventFocus focus) {
Idle.add(check_focus);
return false;
}

private void init_signals() {
button_press_event.connect((event) => {
if(!box_entry.visible && event.button == Gdk.BUTTON_PRIMARY) {
Expand All @@ -115,10 +139,9 @@ namespace Venom {
}
return false;
});
entry.focus_out_event.connect(() => {
on_cancel();
return false;
});
entry.focus_out_event.connect(on_focus_out);
button_ok.focus_out_event.connect(on_focus_out);
button_cancel.focus_out_event.connect(on_focus_out);
}
}
}

0 comments on commit f7e0044

Please sign in to comment.