From fc0bc158693d6c050c3e4df082ffe953119a7518 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Thu, 16 May 2019 10:37:06 +0200 Subject: [PATCH] Fixed a regression, where in the object list when in-place editing the object name, the accelerator keys were still captured and caused weired effects or crashes. --- src/slic3r/GUI/GUI_ObjectList.cpp | 55 +++++++++++++++++-------------- src/slic3r/GUI/GUI_ObjectList.hpp | 6 +++- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 6b309bd57..4f7efb849 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -129,7 +129,31 @@ ObjectList::ObjectList(wxWindow* parent) : #endif //__WXMSW__ }); -// Bind(wxEVT_CHAR, [this](wxKeyEvent& event) { key_event(event); }); // doesn't work on OSX +#ifdef __WXOSX__ + // Key events are not correctly processed by the wxDataViewCtrl on OSX. + // Our patched wxWidgets process the keyboard accelerators. + // On the other hand, using accelerators will break in-place editing on Windows & Linux/GTK (there is no in-place editing working on OSX for wxDataViewCtrl for now). +// Bind(wxEVT_KEY_DOWN, &ObjectList::OnChar, this); + { + // Accelerators + wxAcceleratorEntry entries[6]; + entries[0].Set(wxACCEL_CTRL, (int) 'C', wxID_COPY); + entries[1].Set(wxACCEL_CTRL, (int) 'X', wxID_CUT); + entries[2].Set(wxACCEL_CTRL, (int) 'V', wxID_PASTE); + entries[3].Set(wxACCEL_CTRL, (int) 'A', wxID_SELECTALL); + entries[4].Set(wxACCEL_NORMAL, WXK_DELETE, wxID_DELETE); + entries[5].Set(wxACCEL_NORMAL, WXK_BACK, wxID_DELETE); + wxAcceleratorTable accel(6, entries); + SetAcceleratorTable(accel); + + this->Bind(wxEVT_MENU, [this](wxCommandEvent &evt) { wxPostEvent((wxEvtHandler*)wxGetApp().plater()->canvas3D()->get_wxglcanvas(), SimpleEvent(EVT_GLTOOLBAR_COPY)); }, wxID_COPY); + this->Bind(wxEVT_MENU, [this](wxCommandEvent &evt) { wxPostEvent((wxEvtHandler*)wxGetApp().plater()->canvas3D()->get_wxglcanvas(), SimpleEvent(EVT_GLTOOLBAR_PASTE)); }, wxID_PASTE); + this->Bind(wxEVT_MENU, [this](wxCommandEvent &evt) { this->select_item_all_children(); }, wxID_SELECTALL); + this->Bind(wxEVT_MENU, [this](wxCommandEvent &evt) { this->remove(); }, wxID_DELETE); + } +#else __WXOSX__ + Bind(wxEVT_CHAR, [this](wxKeyEvent& event) { key_event(event); }); // doesn't work on OSX +#endif #ifdef __WXMSW__ GetMainWindow()->Bind(wxEVT_MOTION, [this](wxMouseEvent& event) { @@ -150,28 +174,6 @@ ObjectList::ObjectList(wxWindow* parent) : Bind(wxCUSTOMEVT_LAST_VOLUME_IS_DELETED, [this](wxCommandEvent& e) { last_volume_is_deleted(e.GetInt()); }); -#ifdef __WXOSX__ -// Bind(wxEVT_KEY_DOWN, &ObjectList::OnChar, this); -#endif //__WXOSX__ - - { - // Accelerators - wxAcceleratorEntry entries[6]; - entries[0].Set(wxACCEL_CTRL, (int) 'C', wxID_COPY); - entries[1].Set(wxACCEL_CTRL, (int) 'X', wxID_CUT); - entries[2].Set(wxACCEL_CTRL, (int) 'V', wxID_PASTE); - entries[3].Set(wxACCEL_CTRL, (int) 'A', wxID_SELECTALL); - entries[4].Set(wxACCEL_NORMAL, WXK_DELETE, wxID_DELETE); - entries[5].Set(wxACCEL_NORMAL, WXK_BACK, wxID_DELETE); - wxAcceleratorTable accel(6, entries); - SetAcceleratorTable(accel); - - this->Bind(wxEVT_MENU, [this](wxCommandEvent &evt) { wxPostEvent((wxEvtHandler*)wxGetApp().plater()->canvas3D()->get_wxglcanvas(), SimpleEvent(EVT_GLTOOLBAR_COPY)); }, wxID_COPY); - this->Bind(wxEVT_MENU, [this](wxCommandEvent &evt) { wxPostEvent((wxEvtHandler*)wxGetApp().plater()->canvas3D()->get_wxglcanvas(), SimpleEvent(EVT_GLTOOLBAR_PASTE)); }, wxID_PASTE); - this->Bind(wxEVT_MENU, [this](wxCommandEvent &evt) { this->select_item_all_children(); }, wxID_SELECTALL); - this->Bind(wxEVT_MENU, [this](wxCommandEvent &evt) { this->remove(); }, wxID_DELETE); - } - Bind(wxEVT_SIZE, ([this](wxSizeEvent &e) { this->EnsureVisible(this->GetCurrentItem()); e.Skip(); })); } @@ -623,6 +625,8 @@ void ObjectList::paste_objects_into_list(const std::vector& object_idxs) #endif //no __WXOSX__ //__WXMSW__ } +#ifdef __WXOSX__ +/* void ObjectList::OnChar(wxKeyEvent& event) { if (event.GetKeyCode() == WXK_BACK){ @@ -633,6 +637,8 @@ void ObjectList::OnChar(wxKeyEvent& event) event.Skip(); } +*/ +#endif /* __WXOSX__ */ void ObjectList::OnContextMenu(wxDataViewEvent&) { @@ -701,7 +707,7 @@ void ObjectList::show_context_menu() } } - +#ifndef __WXOSX__ void ObjectList::key_event(wxKeyEvent& event) { if (event.GetKeyCode() == WXK_TAB) @@ -722,6 +728,7 @@ void ObjectList::key_event(wxKeyEvent& event) else event.Skip(); } +#endif /* __WXOSX__ */ void ObjectList::OnBeginDrag(wxDataViewEvent &event) { diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index 2932d86f9..0dcfe2560 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -188,7 +188,9 @@ public: void selection_changed(); void show_context_menu(); +#ifndef __WXOSX__ void key_event(wxKeyEvent& event); +#endif /* __WXOSX__ */ void get_settings_choice(const wxString& category_name); void get_freq_settings_choice(const wxString& bundle_name); @@ -298,7 +300,9 @@ public: void msw_rescale(); private: - void OnChar(wxKeyEvent& event); +#ifdef __WXOSX__ +// void OnChar(wxKeyEvent& event); +#endif /* __WXOSX__ */ void OnContextMenu(wxDataViewEvent &event); void OnBeginDrag(wxDataViewEvent &event);