From f8aea249df9d36e120f8c54da7e14154cb1f7c2a Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 15 Nov 2019 23:58:15 +0000 Subject: [PATCH] Be a bit smarter about moving files through a rename. Don't rely on rebuilding the tree as it collapses all open directories. Try and follow the file instead. Fixes: lp:1852431 * https://bugs.launchpad.net/kicad/+bug/1852431 --- kicad/tree_project_frame.cpp | 36 +++++++++++++++++++++++++++--------- kicad/tree_project_frame.h | 4 ++-- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/kicad/tree_project_frame.cpp b/kicad/tree_project_frame.cpp index ab9184fb07..458429f6f9 100644 --- a/kicad/tree_project_frame.cpp +++ b/kicad/tree_project_frame.cpp @@ -292,8 +292,8 @@ wxString TREE_PROJECT_FRAME::GetFileExt( TreeFileType type ) } -bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName, - wxTreeItemId& aRoot, bool aRecurse ) +wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName, wxTreeItemId& aRoot, + bool aRecurse ) { wxTreeItemId cellule; TreeFileType type = TREE_UNKNOWN; @@ -302,7 +302,7 @@ bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName, // Files/dirs names starting by "." are not visible files under unices. // Skip them also under Windows if( fn.GetName().StartsWith( wxT( "." ) ) ) - return false; + return 0; if( wxDirExists( aName ) ) { @@ -333,7 +333,7 @@ bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName, } if( !addFile ) - return false; + return 0; // only show the schematic if it is a top level schematic. Eeschema // cannot open a schematic and display it properly unless it starts @@ -365,7 +365,7 @@ bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName, fp = wxFopen( fullFileName, wxT( "rt" ) ); if( fp == NULL ) - return false; + return 0; addFile = false; @@ -385,7 +385,7 @@ bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName, fclose( fp ); if( !addFile ) - return false; // it is a non-top-level schematic + return 0; // it is a non-top-level schematic } } @@ -418,7 +418,7 @@ bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName, if( itemData ) { if( itemData->GetFileName() == aName ) - return true; // well, we would have added it, but it is already here! + return kid; } kid = m_TreeProject->GetNextChild( aRoot, cookie ); @@ -467,7 +467,7 @@ bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName, m_TreeProject->SortChildren( cellule ); } - return true; + return data->GetId(); } @@ -704,9 +704,27 @@ void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& ) if( tree_data->Rename( buffer, true ) ) { if( tree_data->GetDir() != oldDir ) - ReCreateTreePrj(); + { + wxFileName filename( tree_data->GetFileName() ); + filename.Normalize(); + + wxTreeItemId parent = findSubdirTreeItem( filename.GetPath() ); + m_TreeProject->SelectItem( tree_data->GetId(), false ); + m_TreeProject->Delete( tree_data->GetId() ); + + wxTreeItemId new_item = AddItemToTreeProject( filename.GetFullPath(), parent, false ); + + if( new_item ) + { + m_TreeProject->SortChildren( parent ); + m_TreeProject->ScrollTo( new_item ); + m_TreeProject->SelectItem( new_item, true ); + } + } else + { m_TreeProject->SetItemText( curr_item, buffer ); + } } } diff --git a/kicad/tree_project_frame.h b/kicad/tree_project_frame.h index 80cae29279..57ab6cc45e 100644 --- a/kicad/tree_project_frame.h +++ b/kicad/tree_project_frame.h @@ -158,9 +158,9 @@ private: * @param aRoot = the wxTreeItemId item where to add sub tree items * @param aRecurse = true to add file or subdir names to the current tree item * false to stop file add. - * @return true if the file (or directory) is added. */ - bool AddItemToTreeProject( const wxString& aName, wxTreeItemId& aRoot, bool aRecurse = true ); + wxTreeItemId AddItemToTreeProject( const wxString& aName, wxTreeItemId& aRoot, + bool aRecurse = true ); /** * Function findSubdirTreeItem