The accelerators Ctrl+A, Ctrl+Del and Del were incorrectly captured

globally by being defined in the Edit menu.
These accelerators are now suppressed in the menu (shown on Windows
but inactive, not shown on OSX / Linux),
and they are now captured by the 3D scene widget instead.

Fix of ctrl-A doesn't work well #1753
This commit is contained in:
bubnikv 2019-02-03 14:06:13 +01:00
parent ecdf550e65
commit 0c1f750cba
4 changed files with 60 additions and 64 deletions

View file

@ -3995,6 +3995,7 @@ wxDEFINE_EVENT(EVT_GLCANVAS_VIEWPORT_CHANGED, SimpleEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_RIGHT_CLICK, Vec2dEvent); wxDEFINE_EVENT(EVT_GLCANVAS_RIGHT_CLICK, Vec2dEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_REMOVE_OBJECT, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_REMOVE_OBJECT, SimpleEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_ARRANGE, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_ARRANGE, SimpleEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_SELECT_ALL, SimpleEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_QUESTION_MARK, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_QUESTION_MARK, SimpleEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_INCREASE_INSTANCES, Event<int>); wxDEFINE_EVENT(EVT_GLCANVAS_INCREASE_INSTANCES, Event<int>);
wxDEFINE_EVENT(EVT_GLCANVAS_INSTANCE_MOVED, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_INSTANCE_MOVED, SimpleEvent);
@ -5100,57 +5101,48 @@ void GLCanvas3D::on_idle(wxIdleEvent& evt)
void GLCanvas3D::on_char(wxKeyEvent& evt) void GLCanvas3D::on_char(wxKeyEvent& evt)
{ {
if (evt.HasModifiers()) // see include/wx/defs.h enum wxKeyCode
evt.Skip();
else
{
int keyCode = evt.GetKeyCode(); int keyCode = evt.GetKeyCode();
switch (keyCode - 48) if (evt.GetModifiers() == wxMOD_CONTROL) {
{ switch (keyCode) {
// numerical input case WXK_CONTROL_A: post_event(SimpleEvent(EVT_GLCANVAS_SELECT_ALL)); break;
case 0: { select_view("iso"); break; } #ifdef __APPLE__
case 1: { select_view("top"); break; } case WXK_BACK: // the low cost Apple solutions are not equipped with a Delete key, use Backspace instead.
case 2: { select_view("bottom"); break; } #endif /* __APPLE__ */
case 3: { select_view("front"); break; } case WXK_DELETE: post_event(SimpleEvent(EVT_GLTOOLBAR_DELETE_ALL)); break;
case 4: { select_view("rear"); break; } default: evt.Skip();
case 5: { select_view("left"); break; } }
case 6: { select_view("right"); break; } } else if (evt.HasModifiers()) {
default: evt.Skip();
{ } else {
// text input
switch (keyCode) switch (keyCode)
{ {
// key ESC // key ESC
case 27: { m_gizmos.reset_all_states(); m_dirty = true; break; } case WXK_ESCAPE: { m_gizmos.reset_all_states(); m_dirty = true; break; }
// key + #ifdef __APPLE__
case 43: { post_event(Event<int>(EVT_GLCANVAS_INCREASE_INSTANCES, +1)); break; } case WXK_BACK: // the low cost Apple solutions are not equipped with a Delete key, use Backspace instead.
// key - #endif /* __APPLE__ */
case 45: { post_event(Event<int>(EVT_GLCANVAS_INCREASE_INSTANCES, -1)); break; } case WXK_DELETE: post_event(SimpleEvent(EVT_GLTOOLBAR_DELETE)); break;
// key ? case '0': { select_view("iso"); break; }
case 63: { post_event(SimpleEvent(EVT_GLCANVAS_QUESTION_MARK)); break; } case '1': { select_view("top"); break; }
// key A/a case '2': { select_view("bottom"); break; }
case 65: case '3': { select_view("front"); break; }
case 97: { post_event(SimpleEvent(EVT_GLCANVAS_ARRANGE)); break; } case '4': { select_view("rear"); break; }
// key B/b case '5': { select_view("left"); break; }
case 66: case '6': { select_view("right"); break; }
case 98: { zoom_to_bed(); break; } case '+': { post_event(Event<int>(EVT_GLCANVAS_INCREASE_INSTANCES, +1)); break; }
// key I/i case '-': { post_event(Event<int>(EVT_GLCANVAS_INCREASE_INSTANCES, -1)); break; }
case 73: case '?': { post_event(SimpleEvent(EVT_GLCANVAS_QUESTION_MARK)); break; }
case 105: { set_camera_zoom(1.0f); break; } case 'A':
// key O/o case 'a': { post_event(SimpleEvent(EVT_GLCANVAS_ARRANGE)); break; }
case 79: case 'B':
case 111: { set_camera_zoom(-1.0f); break; } case 'b': { zoom_to_bed(); break; }
// key Z/z case 'I':
case 90: case 'i': { set_camera_zoom(1.0f); break; }
case 122: case 'O':
{ case 'o': { set_camera_zoom(-1.0f); break; }
if (m_selection.is_empty()) case 'Z':
zoom_to_volumes(); case 'z': { m_selection.is_empty() ? zoom_to_volumes() : zoom_to_selection(); break; }
else
zoom_to_selection();
break;
}
default: default:
{ {
if (m_gizmos.handle_shortcut(keyCode, m_selection)) if (m_gizmos.handle_shortcut(keyCode, m_selection))
@ -5165,8 +5157,6 @@ void GLCanvas3D::on_char(wxKeyEvent& evt)
} }
} }
} }
}
}
} }
void GLCanvas3D::on_mouse_wheel(wxMouseEvent& evt) void GLCanvas3D::on_mouse_wheel(wxMouseEvent& evt)

View file

@ -121,6 +121,7 @@ wxDECLARE_EVENT(EVT_GLCANVAS_VIEWPORT_CHANGED, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_RIGHT_CLICK, Vec2dEvent); wxDECLARE_EVENT(EVT_GLCANVAS_RIGHT_CLICK, Vec2dEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_REMOVE_OBJECT, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_REMOVE_OBJECT, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_ARRANGE, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_ARRANGE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_SELECT_ALL, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_QUESTION_MARK, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_QUESTION_MARK, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_INCREASE_INSTANCES, Event<int>); // data: +1 => increase, -1 => decrease wxDECLARE_EVENT(EVT_GLCANVAS_INCREASE_INSTANCES, Event<int>); // data: +1 => increase, -1 => decrease
wxDECLARE_EVENT(EVT_GLCANVAS_INSTANCE_MOVED, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_INSTANCE_MOVED, SimpleEvent);

View file

@ -324,12 +324,14 @@ void MainFrame::init_menubar()
if (m_plater != nullptr) if (m_plater != nullptr)
{ {
editMenu = new wxMenu(); editMenu = new wxMenu();
wxMenuItem* item_select_all = append_menu_item(editMenu, wxID_ANY, _(L("&Select all")) + "\tCtrl+A", _(L("Selects all objects")), // \xA0 is a non-breaking space. It is entered here to spoil the automatic accelerators,
// as the simple numeric accelerators spoil all numeric data entry.
wxMenuItem* item_select_all = append_menu_item(editMenu, wxID_ANY, _(L("&Select all")) + "\t\xA0" + "Ctrl+\xA0" + "A", _(L("Selects all objects")),
[this](wxCommandEvent&) { m_plater->select_all(); }, ""); [this](wxCommandEvent&) { m_plater->select_all(); }, "");
editMenu->AppendSeparator(); editMenu->AppendSeparator();
wxMenuItem* item_delete_sel = append_menu_item(editMenu, wxID_ANY, _(L("&Delete selected")) + "\tDel", _(L("Deletes the current selection")), wxMenuItem* item_delete_sel = append_menu_item(editMenu, wxID_ANY, _(L("&Delete selected")) + "\t\xA0" + "Del", _(L("Deletes the current selection")),
[this](wxCommandEvent&) { m_plater->remove_selected(); }, ""); [this](wxCommandEvent&) { m_plater->remove_selected(); }, "");
wxMenuItem* item_delete_all = append_menu_item(editMenu, wxID_ANY, _(L("Delete &all")) + "\tCtrl+Del", _(L("Deletes all objects")), wxMenuItem* item_delete_all = append_menu_item(editMenu, wxID_ANY, _(L("Delete &all")) + "\t\xA0" + "Ctrl+\xA0" + "Del", _(L("Deletes all objects")),
[this](wxCommandEvent&) { m_plater->reset(); }, ""); [this](wxCommandEvent&) { m_plater->reset(); }, "");
Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_select()); }, item_select_all->GetId()); Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_select()); }, item_select_all->GetId());
@ -388,7 +390,7 @@ void MainFrame::init_menubar()
wxMenu* viewMenu = nullptr; wxMenu* viewMenu = nullptr;
if (m_plater) { if (m_plater) {
viewMenu = new wxMenu(); viewMenu = new wxMenu();
// \xA0 is a non-breaing space. It is entered here to spoil the automatic accelerators, // \xA0 is a non-breaking space. It is entered here to spoil the automatic accelerators,
// as the simple numeric accelerators spoil all numeric data entry. // as the simple numeric accelerators spoil all numeric data entry.
// The camera control accelerators are captured by GLCanvas3D::on_char(). // The camera control accelerators are captured by GLCanvas3D::on_char().
wxMenuItem* item_iso = append_menu_item(viewMenu, wxID_ANY, _(L("&Iso")) + "\t\xA0" + "0", _(L("Iso View")), [this](wxCommandEvent&) { select_view("iso"); }); wxMenuItem* item_iso = append_menu_item(viewMenu, wxID_ANY, _(L("&Iso")) + "\t\xA0" + "0", _(L("Iso View")), [this](wxCommandEvent&) { select_view("iso"); });

View file

@ -1171,6 +1171,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
view3D_canvas->Bind(EVT_GLCANVAS_RIGHT_CLICK, &priv::on_right_click, this); view3D_canvas->Bind(EVT_GLCANVAS_RIGHT_CLICK, &priv::on_right_click, this);
view3D_canvas->Bind(EVT_GLCANVAS_REMOVE_OBJECT, [q](SimpleEvent&) { q->remove_selected(); }); view3D_canvas->Bind(EVT_GLCANVAS_REMOVE_OBJECT, [q](SimpleEvent&) { q->remove_selected(); });
view3D_canvas->Bind(EVT_GLCANVAS_ARRANGE, [this](SimpleEvent&) { arrange(); }); view3D_canvas->Bind(EVT_GLCANVAS_ARRANGE, [this](SimpleEvent&) { arrange(); });
view3D_canvas->Bind(EVT_GLCANVAS_SELECT_ALL, [this](SimpleEvent&) { this->q->select_all(); });
view3D_canvas->Bind(EVT_GLCANVAS_QUESTION_MARK, [this](SimpleEvent&) { wxGetApp().keyboard_shortcuts(); }); view3D_canvas->Bind(EVT_GLCANVAS_QUESTION_MARK, [this](SimpleEvent&) { wxGetApp().keyboard_shortcuts(); });
view3D_canvas->Bind(EVT_GLCANVAS_INCREASE_INSTANCES, [this](Event<int> &evt) view3D_canvas->Bind(EVT_GLCANVAS_INCREASE_INSTANCES, [this](Event<int> &evt)
{ if (evt.data == 1) this->q->increase_instances(); else if (this->can_decrease_instances()) this->q->decrease_instances(); }); { if (evt.data == 1) this->q->increase_instances(); else if (this->can_decrease_instances()) this->q->decrease_instances(); });
@ -1736,6 +1737,8 @@ void Plater::priv::arrange()
// Guard the arrange process // Guard the arrange process
arranging.store(true); arranging.store(true);
wxBusyCursor wait;
// Disable the arrange button (to prevent reentrancies, we will call wxYied) // Disable the arrange button (to prevent reentrancies, we will call wxYied)
view3D->enable_toolbar_item("arrange", can_arrange()); view3D->enable_toolbar_item("arrange", can_arrange());