diff --git a/kicad/tree_project_frame.cpp b/kicad/tree_project_frame.cpp index 6a5a04e718..ee826e9420 100644 --- a/kicad/tree_project_frame.cpp +++ b/kicad/tree_project_frame.cpp @@ -131,6 +131,7 @@ BEGIN_EVENT_TABLE( TREE_PROJECT_FRAME, wxSashLayoutWindow ) EVT_MENU( ID_PROJECT_DELETE, TREE_PROJECT_FRAME::OnDeleteFile ) EVT_MENU( ID_PROJECT_PRINT, TREE_PROJECT_FRAME::OnPrintFile ) EVT_MENU( ID_PROJECT_RENAME, TREE_PROJECT_FRAME::OnRenameFile ) + EVT_IDLE( TREE_PROJECT_FRAME::OnIdle ) END_EVENT_TABLE() @@ -141,6 +142,7 @@ TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ) : m_Parent = parent; m_TreeProject = NULL; m_isRenaming = false; + m_selectedItem = nullptr; m_watcher = NULL; Connect( wxEVT_FSWATCHER, @@ -905,7 +907,22 @@ void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event ) if( tree_data.size() != 1 ) return; - tree_data[0]->Activate( this ); + // Bookmark the selected item but don't try and activate it until later + // if we do it now, there will be more events at least on Windows in this frame + // that will steal focus from any newly launched windows + m_selectedItem = tree_data[0]; +} + + +void TREE_PROJECT_FRAME::OnIdle( wxIdleEvent& aEvent ) +{ + // Idle executes once all other events finished processing + // This makes it ideal to launch a new window without starting Focus wars. + if( m_selectedItem != nullptr ) + { + m_selectedItem->Activate( this ); + m_selectedItem = nullptr; + } } diff --git a/kicad/tree_project_frame.h b/kicad/tree_project_frame.h index 7a807dfe1d..d8bdfc0dc7 100644 --- a/kicad/tree_project_frame.h +++ b/kicad/tree_project_frame.h @@ -57,6 +57,7 @@ private: wxTreeItemId m_root; std::vector m_filters; wxFileSystemWatcher* m_watcher; // file system watcher + TREEPROJECT_ITEM* m_selectedItem; public: TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ); @@ -158,6 +159,12 @@ private: */ void OnSwitchToSelectedProject( wxCommandEvent& event ); + /** + * Idle event handler, used process the selected items at a point in time + * when all other events have been consumed + */ + void OnIdle( wxIdleEvent &aEvent ); + /** * Function AddItemToTreeProject * @brief Add the file or directory aName to the project tree