From 7ae0d3960ff0799d750006f84360924d292370c9 Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Sun, 23 Feb 2014 20:27:07 -0500 Subject: [PATCH] Eeschema: component selection dialog improvements. * Pressing 'Enter' while the focus is in the tree did not work due to the double-click wxWidgets workaround. Make it work. * More clearly document what is happening and how it can be tested. --- eeschema/dialogs/dialog_choose_component.cpp | 27 ++++++++++++++++++- eeschema/dialogs/dialog_choose_component.h | 3 ++- .../dialogs/dialog_choose_component_base.cpp | 8 +++--- .../dialogs/dialog_choose_component_base.fbp | 4 +-- .../dialogs/dialog_choose_component_base.h | 5 ++-- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/eeschema/dialogs/dialog_choose_component.cpp b/eeschema/dialogs/dialog_choose_component.cpp index 9a65fc42f5..7159623194 100644 --- a/eeschema/dialogs/dialog_choose_component.cpp +++ b/eeschema/dialogs/dialog_choose_component.cpp @@ -138,7 +138,11 @@ void DIALOG_CHOOSE_COMPONENT::OnTreeSelect( wxTreeEvent& aEvent ) } -void DIALOG_CHOOSE_COMPONENT::OnDoubleClickTreeSelect( wxTreeEvent& aEvent ) +// Test strategy for OnDoubleClickTreeActivation()/OnTreeMouseUp() work around wxWidgets bug: +// - search for an item. +// - use the mouse to double-click on an item in the tree. +// -> The dialog should close, and the component should _not_ be immediately placed +void DIALOG_CHOOSE_COMPONENT::OnDoubleClickTreeActivation( wxTreeEvent& aEvent ) { if( !updateSelection() ) return; @@ -159,6 +163,27 @@ void DIALOG_CHOOSE_COMPONENT::OnTreeMouseUp( wxMouseEvent& aMouseEvent ) aMouseEvent.Skip(); // Let upstream handle it. } +// Test strategy to see if OnInterceptTreeEnter() works: +// - search for an item. +// - click into the tree once to set focus on tree; navigate. Press 'Enter' +// -> The dialog should close and the component be available to place. +void DIALOG_CHOOSE_COMPONENT::OnInterceptTreeEnter( wxKeyEvent& aEvent ) +{ + // We have to do some special handling for double-click on a tree-item because + // of some superfluous event delivery bug in wxWidgets (see OnDoubleClickTreeActivation()). + // In tree-activation, we assume we got a double-click and need to take special precaution + // that the mouse-up event is not delivered to the window one level up by going through + // a state-sequence OnDoubleClickTreeActivation() -> OnTreeMouseUp(). + + // Pressing 'Enter' within a tree will also call OnDoubleClickTreeActivation(), + // but since this is not due to the double-click and we have no way of knowing that it is + // not, we need to intercept the 'Enter' key before that to know that it is time to exit. + if ( aEvent.GetKeyCode() == WXK_RETURN ) + EndModal( wxID_OK ); // Dialog is done. + else + aEvent.Skip(); // Let tree handle that key for navigation. +} + void DIALOG_CHOOSE_COMPONENT::OnStartComponentBrowser( wxMouseEvent& aEvent ) { diff --git a/eeschema/dialogs/dialog_choose_component.h b/eeschema/dialogs/dialog_choose_component.h index b2e3a0903f..3884a354d1 100644 --- a/eeschema/dialogs/dialog_choose_component.h +++ b/eeschema/dialogs/dialog_choose_component.h @@ -57,7 +57,8 @@ protected: virtual void OnInterceptSearchBoxKey( wxKeyEvent& aEvent ); virtual void OnTreeSelect( wxTreeEvent& aEvent ); - virtual void OnDoubleClickTreeSelect( wxTreeEvent& aEvent ); + virtual void OnDoubleClickTreeActivation( wxTreeEvent& aEvent ); + virtual void OnInterceptTreeEnter( wxKeyEvent& aEvent ); virtual void OnTreeMouseUp( wxMouseEvent& aMouseEvent ); virtual void OnStartComponentBrowser( wxMouseEvent& aEvent ); diff --git a/eeschema/dialogs/dialog_choose_component_base.cpp b/eeschema/dialogs/dialog_choose_component_base.cpp index af6b6546f2..2d84ff23cd 100644 --- a/eeschema/dialogs/dialog_choose_component_base.cpp +++ b/eeschema/dialogs/dialog_choose_component_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Nov 6 2013) +// C++ code generated with wxFormBuilder (version Feb 22 2014) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -75,8 +75,9 @@ DIALOG_CHOOSE_COMPONENT_BASE::DIALOG_CHOOSE_COMPONENT_BASE( wxWindow* parent, wx m_searchBox->Connect( wxEVT_KEY_DOWN, wxKeyEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnInterceptSearchBoxKey ), NULL, this ); m_searchBox->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnSearchBoxChange ), NULL, this ); m_searchBox->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnSearchBoxEnter ), NULL, this ); + m_libraryComponentTree->Connect( wxEVT_KEY_UP, wxKeyEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnInterceptTreeEnter ), NULL, this ); m_libraryComponentTree->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnTreeMouseUp ), NULL, this ); - m_libraryComponentTree->Connect( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnDoubleClickTreeSelect ), NULL, this ); + m_libraryComponentTree->Connect( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnDoubleClickTreeActivation ), NULL, this ); m_libraryComponentTree->Connect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnTreeSelect ), NULL, this ); m_componentView->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnStartComponentBrowser ), NULL, this ); m_componentView->Connect( wxEVT_PAINT, wxPaintEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnHandlePreviewRepaint ), NULL, this ); @@ -88,8 +89,9 @@ DIALOG_CHOOSE_COMPONENT_BASE::~DIALOG_CHOOSE_COMPONENT_BASE() m_searchBox->Disconnect( wxEVT_KEY_DOWN, wxKeyEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnInterceptSearchBoxKey ), NULL, this ); m_searchBox->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnSearchBoxChange ), NULL, this ); m_searchBox->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnSearchBoxEnter ), NULL, this ); + m_libraryComponentTree->Disconnect( wxEVT_KEY_UP, wxKeyEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnInterceptTreeEnter ), NULL, this ); m_libraryComponentTree->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnTreeMouseUp ), NULL, this ); - m_libraryComponentTree->Disconnect( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnDoubleClickTreeSelect ), NULL, this ); + m_libraryComponentTree->Disconnect( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnDoubleClickTreeActivation ), NULL, this ); m_libraryComponentTree->Disconnect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnTreeSelect ), NULL, this ); m_componentView->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnStartComponentBrowser ), NULL, this ); m_componentView->Disconnect( wxEVT_PAINT, wxPaintEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnHandlePreviewRepaint ), NULL, this ); diff --git a/eeschema/dialogs/dialog_choose_component_base.fbp b/eeschema/dialogs/dialog_choose_component_base.fbp index ee169c8e0c..77cf06af9e 100644 --- a/eeschema/dialogs/dialog_choose_component_base.fbp +++ b/eeschema/dialogs/dialog_choose_component_base.fbp @@ -338,7 +338,7 @@ - + OnInterceptTreeEnter @@ -363,7 +363,7 @@ - OnDoubleClickTreeSelect + OnDoubleClickTreeActivation diff --git a/eeschema/dialogs/dialog_choose_component_base.h b/eeschema/dialogs/dialog_choose_component_base.h index ad588da058..881b5a5ea3 100644 --- a/eeschema/dialogs/dialog_choose_component_base.h +++ b/eeschema/dialogs/dialog_choose_component_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Nov 6 2013) +// C++ code generated with wxFormBuilder (version Feb 22 2014) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -50,8 +50,9 @@ class DIALOG_CHOOSE_COMPONENT_BASE : public DIALOG_SHIM virtual void OnInterceptSearchBoxKey( wxKeyEvent& event ) { event.Skip(); } virtual void OnSearchBoxChange( wxCommandEvent& event ) { event.Skip(); } virtual void OnSearchBoxEnter( wxCommandEvent& event ) { event.Skip(); } + virtual void OnInterceptTreeEnter( wxKeyEvent& event ) { event.Skip(); } virtual void OnTreeMouseUp( wxMouseEvent& event ) { event.Skip(); } - virtual void OnDoubleClickTreeSelect( wxTreeEvent& event ) { event.Skip(); } + virtual void OnDoubleClickTreeActivation( wxTreeEvent& event ) { event.Skip(); } virtual void OnTreeSelect( wxTreeEvent& event ) { event.Skip(); } virtual void OnStartComponentBrowser( wxMouseEvent& event ) { event.Skip(); } virtual void OnHandlePreviewRepaint( wxPaintEvent& event ) { event.Skip(); }