From b0aa1260e2396023c6039ceb2ff405ec4b9853ab Mon Sep 17 00:00:00 2001
From: Alessandro Ranellucci <aar@cpan.org>
Date: Sat, 13 Dec 2014 15:40:42 +0100
Subject: [PATCH] Bugfix: wxComboBox left blank after menu item selection on
 MSW due to an undocumented wxWidgets issue. #2361

---
 lib/Slic3r/GUI/OptionsGroup/Field.pm | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/lib/Slic3r/GUI/OptionsGroup/Field.pm b/lib/Slic3r/GUI/OptionsGroup/Field.pm
index 76cabb515..fcf97eb3f 100644
--- a/lib/Slic3r/GUI/OptionsGroup/Field.pm
+++ b/lib/Slic3r/GUI/OptionsGroup/Field.pm
@@ -231,7 +231,7 @@ use Moo;
 extends 'Slic3r::GUI::OptionsGroup::Field::wxWindow';
 
 use List::Util qw(first);
-use Wx qw(:misc :combobox);
+use Wx qw(wxTheApp :misc :combobox);
 use Wx::Event qw(EVT_COMBOBOX EVT_TEXT);
 
 sub BUILD {
@@ -258,7 +258,17 @@ sub BUILD {
             $label = $value;
         }
         
-        $field->SetValue($label);
+        # The MSW implementation of wxComboBox will leave the field blank if we call
+        # SetValue() in the EVT_COMBOBOX event handler, so we postpone the call.
+        wxTheApp->CallAfter(sub {
+            my $dce = $self->disable_change_event;
+            $self->disable_change_event(1);
+            
+            # ChangeValue() is not exported in wxPerl
+            $field->SetValue($label);
+            
+            $self->disable_change_event($dce);
+        });
         
         $self->disable_change_event($disable_change_event);
         $self->_on_change($self->option->opt_id);