diff --git a/kicad/kicad.h b/kicad/kicad.h index fd67c84df6..1dcfb14013 100644 --- a/kicad/kicad.h +++ b/kicad/kicad.h @@ -99,6 +99,7 @@ enum id_kicad_frm { ID_PROJECT_TREE, ID_PROJECT_TXTEDIT, ID_PROJECT_TREE_REFRESH, + ID_PROJECT_SWITCH_TO_OTHER, ID_PROJECT_NEWDIR, ID_PROJECT_DELETE, ID_PROJECT_RENAME, diff --git a/kicad/tree_project_frame.cpp b/kicad/tree_project_frame.cpp index ac4167d7c0..eebabe184d 100644 --- a/kicad/tree_project_frame.cpp +++ b/kicad/tree_project_frame.cpp @@ -117,6 +117,7 @@ BEGIN_EVENT_TABLE( TREE_PROJECT_FRAME, wxSashLayoutWindow ) EVT_TREE_ITEM_EXPANDED( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnExpand ) EVT_TREE_ITEM_RIGHT_CLICK( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnRight ) EVT_MENU( ID_PROJECT_TXTEDIT, TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor ) + EVT_MENU( ID_PROJECT_SWITCH_TO_OTHER, TREE_PROJECT_FRAME::OnSwitchToSelectedProject ) 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 ) @@ -176,6 +177,19 @@ void TREE_PROJECT_FRAME::RemoveFilter( const wxString& filter ) } +void TREE_PROJECT_FRAME::OnSwitchToSelectedProject( wxCommandEvent& event ) +{ + TREEPROJECT_ITEM* tree_data = GetSelectedData(); + + if( !tree_data ) + return; + + wxString prj_filename = tree_data->GetFileName(); + + m_Parent->LoadProject( prj_filename ); +} + + void TREE_PROJECT_FRAME::OnCreateNewDirectory( wxCommandEvent& event ) { // Get the root directory name: @@ -678,6 +692,16 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event ) switch( tree_id ) { case TREE_PROJECT: + // Add a swith to an other project option only if the selected item + // is not the root item (current project) + if( curr_item != m_TreeProject->GetRootItem() ) + { + AddMenuItem( &popupMenu, ID_PROJECT_SWITCH_TO_OTHER, + _( "&Switch to this Project" ), + _( "Close all editors, and switch to the selected project" ), + KiBitmap( open_project_xpm ) ); + popupMenu.AppendSeparator(); + } AddMenuItem( &popupMenu, ID_PROJECT_NEWDIR, _( "New D&irectory..." ), _( "Create a New Directory" ), @@ -777,12 +801,12 @@ void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& ) void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event ) { - TREEPROJECT_ITEM* tree_data = GetSelectedData(); + TREEPROJECT_ITEM* selected_item = GetSelectedData(); - if( !tree_data ) + if( !selected_item ) return; - tree_data->Activate( this ); + selected_item->Activate( this ); } diff --git a/kicad/tree_project_frame.h b/kicad/tree_project_frame.h index 1ed774244b..43d06fc5b3 100644 --- a/kicad/tree_project_frame.h +++ b/kicad/tree_project_frame.h @@ -140,6 +140,12 @@ private: */ void OnCreateNewDirectory( wxCommandEvent& event ); + /** + * Switch to a other project selected from the tree project + * (by selecting an other .pro file inside the current project folder) + */ + void OnSwitchToSelectedProject( wxCommandEvent& event ); + void ClearFilters() { m_filters.clear(); diff --git a/kicad/treeproject_item.cpp b/kicad/treeproject_item.cpp index 1de55f646e..0b9bbeb150 100644 --- a/kicad/treeproject_item.cpp +++ b/kicad/treeproject_item.cpp @@ -164,18 +164,21 @@ bool TREEPROJECT_ITEM::Delete( bool check ) } -void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe ) +void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* aTreePrjFrame ) { wxString sep = wxFileName().GetPathSeparator(); wxString fullFileName = GetFileName(); wxTreeItemId id = GetId(); - KICAD_MANAGER_FRAME* frame = prjframe->m_Parent; + KICAD_MANAGER_FRAME* frame = aTreePrjFrame->m_Parent; wxASSERT( frame ); switch( GetType() ) { case TREE_PROJECT: + // Select a new project if this is not the current project: + if( id != aTreePrjFrame->m_TreeProject->GetRootItem() ) + frame->LoadProject( fullFileName ); break; case TREE_DIRECTORY: diff --git a/kicad/treeproject_item.h b/kicad/treeproject_item.h index 902393977e..b2f4cc691e 100644 --- a/kicad/treeproject_item.h +++ b/kicad/treeproject_item.h @@ -74,7 +74,7 @@ public: bool Rename( const wxString& name, bool check = true ); bool Delete( bool check = true ); - void Activate( TREE_PROJECT_FRAME* prjframe ); + void Activate( TREE_PROJECT_FRAME* aTreePrjFrame ); void SetState( int state );