diff --git a/kicad/tree_project_frame.cpp b/kicad/tree_project_frame.cpp index 2bb7a03df1..8a02cc9faf 100644 --- a/kicad/tree_project_frame.cpp +++ b/kicad/tree_project_frame.cpp @@ -124,6 +124,7 @@ BEGIN_EVENT_TABLE( TREE_PROJECT_FRAME, wxSashLayoutWindow ) EVT_MENU( ID_PROJECT_NEWDIR, TREE_PROJECT_FRAME::OnCreateNewDirectory ) EVT_MENU( ID_PROJECT_DELETE, TREE_PROJECT_FRAME::OnDeleteFile ) EVT_MENU( ID_PROJECT_RENAME, TREE_PROJECT_FRAME::OnRenameFile ) + EVT_IDLE( TREE_PROJECT_FRAME::OnIdle ) END_EVENT_TABLE() @@ -134,6 +135,7 @@ TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ) : { m_Parent = parent; m_TreeProject = NULL; + m_selectedItem = nullptr; m_watcher = NULL; Connect( wxEVT_FSWATCHER, @@ -821,7 +823,22 @@ void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event ) if( !selected_item ) return; - selected_item->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 = selected_item; +} + + +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 43d06fc5b3..986806a82e 100644 --- a/kicad/tree_project_frame.h +++ b/kicad/tree_project_frame.h @@ -55,6 +55,7 @@ private: wxTreeItemId m_root; std::vector m_filters; wxFileSystemWatcher* m_watcher; // file system watcher (since wxWidgets 2.9.2) + TREEPROJECT_ITEM* m_selectedItem; public: TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ); @@ -158,6 +159,12 @@ private: void RemoveFilter( const wxString& filter ); + /** + * 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