diff --git a/kicad/CMakeLists.txt b/kicad/CMakeLists.txt index c24cec7b21..cf005779e1 100644 --- a/kicad/CMakeLists.txt +++ b/kicad/CMakeLists.txt @@ -24,9 +24,9 @@ set( KICAD_SRCS kicad_settings.cpp menubar.cpp project_template.cpp - tree_project_frame.cpp - treeprojectfiles.cpp - treeproject_item.cpp + project_tree_pane.cpp + project_tree.cpp + project_tree_item.cpp tools/kicad_manager_actions.cpp tools/kicad_manager_control.cpp ) diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index c1f35ecd19..f6916ff9ac 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -25,7 +25,7 @@ #include "kicad_id.h" #include "pgm_kicad.h" -#include "tree_project_frame.h" +#include "project_tree_pane.h" #include #include #include @@ -117,7 +117,7 @@ KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& titl LoadSettings( config() ); // Left window: is the box which display tree project - m_leftWin = new TREE_PROJECT_FRAME( this ); + m_leftWin = new PROJECT_TREE_PANE( this ); // Add the wxTextCtrl showing all messages from KiCad: m_messagesBox = new wxTextCtrl( this, wxID_ANY, wxEmptyString, diff --git a/kicad/kicad_manager_frame.h b/kicad/kicad_manager_frame.h index 2131207571..31c68390ef 100644 --- a/kicad/kicad_manager_frame.h +++ b/kicad/kicad_manager_frame.h @@ -29,8 +29,8 @@ #include #include -class TREEPROJECTFILES; -class TREE_PROJECT_FRAME; +class PROJECT_TREE; +class PROJECT_TREE_PANE; class ACTION_TOOLBAR; class KICAD_SETTINGS; class EDA_BASE_FRAME; @@ -185,7 +185,7 @@ private: bool m_openSavedWindows; private: - TREE_PROJECT_FRAME* m_leftWin; + PROJECT_TREE_PANE* m_leftWin; ACTION_TOOLBAR* m_launcher; wxTextCtrl* m_messagesBox; ACTION_TOOLBAR* m_mainToolBar; diff --git a/kicad/project_tree.cpp b/kicad/project_tree.cpp new file mode 100644 index 0000000000..d22c6c7236 --- /dev/null +++ b/kicad/project_tree.cpp @@ -0,0 +1,114 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2004-2012 Jean-Pierre Charras + * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + + +#include + +#include "project_tree_item.h" +#include "project_tree_pane.h" +#include "project_tree.h" +#include "kicad_id.h" + + +IMPLEMENT_ABSTRACT_CLASS( PROJECT_TREE, wxTreeCtrl ) + + +PROJECT_TREE::PROJECT_TREE( PROJECT_TREE_PANE* parent ) : + wxTreeCtrl( parent, ID_PROJECT_TREE, wxDefaultPosition, wxDefaultSize, + wxTR_HAS_BUTTONS | wxTR_MULTIPLE, wxDefaultValidator, + wxT( "EDATreeCtrl" ) ) +{ + m_projectTreePane = parent; + + // icons size is not know (depending on they are built) + // so get it: + wxSize iconsize; + wxBitmap dummy = KiBitmap( eeschema_xpm ); + iconsize.x = dummy.GetWidth(); + iconsize.y = dummy.GetHeight(); + + // Make an image list containing small icons + m_imageList = new wxImageList( iconsize.x, iconsize.y, true, + static_cast( TREE_FILE_TYPE::MAX ) ); + + m_imageList->Add( KiBitmap( new_project_xpm ) ); // TREE_LEGACY_PROJECT + m_imageList->Add( KiBitmap( new_project_xpm ) ); // TREE_JSON_PROJECT + m_imageList->Add( KiBitmap( eeschema_xpm ) ); // TREE_LEGACY_SCHEMATIC + m_imageList->Add( KiBitmap( eeschema_xpm ) ); // TREE_SEXPR_SCHEMATIC + m_imageList->Add( KiBitmap( pcbnew_xpm ) ); // TREE_LEGACY_PCB + m_imageList->Add( KiBitmap( pcbnew_xpm ) ); // TREE_SEXPR_PCB + m_imageList->Add( KiBitmap( icon_gerbview_small_xpm ) ); // TREE_GERBER + m_imageList->Add( KiBitmap( gerber_job_file_xpm ) ); // TREE_GERBER_JOB_FILE (.gbrjob) + m_imageList->Add( KiBitmap( html_xpm ) ); // TREE_HTML + m_imageList->Add( KiBitmap( datasheet_xpm ) ); // TREE_PDF + m_imageList->Add( KiBitmap( editor_xpm ) ); // TREE_TXT + m_imageList->Add( KiBitmap( netlist_xpm ) ); // TREE_NET + m_imageList->Add( KiBitmap( unknown_xpm ) ); // TREE_UNKNOWN + m_imageList->Add( KiBitmap( directory_xpm ) ); // TREE_DIRECTORY + m_imageList->Add( KiBitmap( icon_cvpcb_small_xpm ) ); // TREE_CMP_LINK + m_imageList->Add( KiBitmap( tools_xpm ) ); // TREE_REPORT + m_imageList->Add( KiBitmap( post_compo_xpm ) ); // TREE_POS + m_imageList->Add( KiBitmap( post_drill_xpm ) ); // TREE_DRILL + m_imageList->Add( KiBitmap( post_drill_xpm ) ); // TREE_DRILL_NC (similar TREE_DRILL) + m_imageList->Add( KiBitmap( post_drill_xpm ) ); // TREE_DRILL_XNC (similar TREE_DRILL) + m_imageList->Add( KiBitmap( svg_file_xpm ) ); // TREE_SVG + m_imageList->Add( KiBitmap( pagelayout_load_xpm ) ); // TREE_PAGE_LAYOUT_DESCR + m_imageList->Add( KiBitmap( module_xpm ) ); // TREE_FOOTPRINT_FILE + m_imageList->Add( KiBitmap( library_xpm ) ); // TREE_SCHEMATIC_LIBFILE + m_imageList->Add( KiBitmap( library_xpm ) ); // TREE_SEXPR_SYMBOL_LIB_FILE + + SetImageList( m_imageList ); +} + + +PROJECT_TREE::~PROJECT_TREE() +{ + delete m_imageList; +} + + +int PROJECT_TREE::OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 ) +{ + PROJECT_TREE_ITEM* myitem1 = (PROJECT_TREE_ITEM*) GetItemData( item1 ); + PROJECT_TREE_ITEM* myitem2 = (PROJECT_TREE_ITEM*) GetItemData( item2 ); + + if( !myitem1 || !myitem2 ) + return 0; + + if( myitem1->GetType() == TREE_FILE_TYPE::DIRECTORY + && myitem2->GetType() != TREE_FILE_TYPE::DIRECTORY ) + return -1; + + if( myitem2->GetType() == TREE_FILE_TYPE::DIRECTORY + && myitem1->GetType() != TREE_FILE_TYPE::DIRECTORY ) + return 1; + + if( myitem1->IsRootFile() && !myitem2->IsRootFile() ) + return -1; + + if( myitem2->IsRootFile() && !myitem1->IsRootFile() ) + return 1; + + return myitem1->GetFileName().CmpNoCase( myitem2->GetFileName() ); +} diff --git a/kicad/treeprojectfiles.h b/kicad/project_tree.h similarity index 74% rename from kicad/treeprojectfiles.h rename to kicad/project_tree.h index 1aade8337c..39a5f0a6fc 100644 --- a/kicad/treeprojectfiles.h +++ b/kicad/project_tree.h @@ -22,43 +22,36 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/* - * file treeprojectfiles.h - */ - -#ifndef TREEPROJECTFILES_H -#define TREEPROJECTFILES_H +#ifndef PROJECT_TREE_H +#define PROJECT_TREE_H #include #include "tree_file_type.h" -class TREE_PROJECT_FRAME; +class PROJECT_TREE_PANE; -/** TREEPROJECTFILES +/** PROJECT_TREE * This is the class to show (as a tree) the files in the project directory */ -class TREEPROJECTFILES : public wxTreeCtrl +class PROJECT_TREE : public wxTreeCtrl { - DECLARE_DYNAMIC_CLASS( TREEPROJECTFILES ) + DECLARE_DYNAMIC_CLASS( PROJECT_TREE ) + private: - TREE_PROJECT_FRAME* m_Parent; - wxImageList* m_ImageList; + PROJECT_TREE_PANE* m_projectTreePane; + wxImageList* m_imageList; public: + PROJECT_TREE_PANE* GetProjectTreePane() const { return m_projectTreePane; } - TREE_PROJECT_FRAME* GetParent() const - { - return m_Parent; - } + PROJECT_TREE( PROJECT_TREE_PANE* parent ); + ~PROJECT_TREE(); - - TREEPROJECTFILES( TREE_PROJECT_FRAME* parent ); - ~TREEPROJECTFILES(); private: /* overridden sort function */ int OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 ) override; }; -#endif // TREEPROJECTFILES_H +#endif // PROJECT_TREE_H diff --git a/kicad/treeproject_item.cpp b/kicad/project_tree_item.cpp similarity index 88% rename from kicad/treeproject_item.cpp rename to kicad/project_tree_item.cpp index 9b4eba643c..a0f91e2b32 100644 --- a/kicad/treeproject_item.cpp +++ b/kicad/project_tree_item.cpp @@ -22,9 +22,7 @@ */ /** - * @file treeproject_item.cpp - * - * @brief Class TREEPROJECT_ITEM is a derived class from wxTreeItemData and + * @brief Class PROJECT_TREE_ITEM is a derived class from wxTreeItemData and * store info about a file or directory shown in the KiCad tree project files */ @@ -39,15 +37,15 @@ #include #include "kicad_manager_frame.h" -#include "treeprojectfiles.h" +#include "project_tree.h" #include "pgm_kicad.h" -#include "tree_project_frame.h" -#include "treeproject_item.h" +#include "project_tree_pane.h" +#include "project_tree_item.h" #include "kicad_id.h" -TREEPROJECT_ITEM::TREEPROJECT_ITEM( TREE_FILE_TYPE type, const wxString& data, - wxTreeCtrl* parent ) : +PROJECT_TREE_ITEM::PROJECT_TREE_ITEM( TREE_FILE_TYPE type, const wxString& data, + wxTreeCtrl* parent ) : wxTreeItemData() { m_parent = parent; @@ -59,7 +57,7 @@ TREEPROJECT_ITEM::TREEPROJECT_ITEM( TREE_FILE_TYPE type, const wxString& data, } -void TREEPROJECT_ITEM::SetState( int state ) +void PROJECT_TREE_ITEM::SetState( int state ) { wxImageList* imglist = m_parent->GetImageList(); int treeEnumMax = static_cast( TREE_FILE_TYPE::MAX ); @@ -68,25 +66,25 @@ void TREEPROJECT_ITEM::SetState( int state ) return; m_state = state; - int imgid = static_cast( m_Type ) - 1 + state * ( treeEnumMax - 1 ); + int imgid = static_cast( m_type ) - 1 + state * ( treeEnumMax - 1 ); m_parent->SetItemImage( GetId(), imgid ); m_parent->SetItemImage( GetId(), imgid, wxTreeItemIcon_Selected ); } -const wxString TREEPROJECT_ITEM::GetDir() const +const wxString PROJECT_TREE_ITEM::GetDir() const { - if( TREE_FILE_TYPE::DIRECTORY == m_Type ) + if( TREE_FILE_TYPE::DIRECTORY == m_type ) return GetFileName(); return wxFileName( GetFileName() ).GetPath(); } -bool TREEPROJECT_ITEM::Rename( const wxString& name, bool check ) +bool PROJECT_TREE_ITEM::Rename( const wxString& name, bool check ) { // this is broken & unsafe to use on linux. - if( m_Type == TREE_FILE_TYPE::DIRECTORY ) + if( m_type == TREE_FILE_TYPE::DIRECTORY ) return false; if( name.IsEmpty() ) @@ -104,9 +102,8 @@ bool TREEPROJECT_ITEM::Rename( const wxString& name, bool check ) if( newFile == GetFileName() ) return false; - wxString ext = TREE_PROJECT_FRAME::GetFileExt( GetType() ); - - wxRegEx reg( wxT( "^.*\\" ) + ext + wxT( "$" ), wxRE_ICASE ); + wxString ext = PROJECT_TREE_PANE::GetFileExt( GetType() ); + wxRegEx reg( wxT( "^.*\\" ) + ext + wxT( "$" ), wxRE_ICASE ); if( check && !ext.IsEmpty() && !reg.Matches( newFile ) ) { @@ -129,7 +126,7 @@ bool TREEPROJECT_ITEM::Rename( const wxString& name, bool check ) } -void TREEPROJECT_ITEM::Delete() +void PROJECT_TREE_ITEM::Delete() { wxString errMsg; @@ -144,13 +141,13 @@ void TREEPROJECT_ITEM::Delete() } -void TREEPROJECT_ITEM::Print() +void PROJECT_TREE_ITEM::Print() { PrintFile( GetFileName() ); } -void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* aTreePrjFrame ) +void PROJECT_TREE_ITEM::Activate( PROJECT_TREE_PANE* aTreePrjFrame ) { wxString sep = wxFileName::GetPathSeparator(); wxString fullFileName = GetFileName(); diff --git a/kicad/treeproject_item.h b/kicad/project_tree_item.h similarity index 61% rename from kicad/treeproject_item.h rename to kicad/project_tree_item.h index 4b8bcce802..a947735ec1 100644 --- a/kicad/treeproject_item.h +++ b/kicad/project_tree_item.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2010-2014 Jean-Pierre Charras - * Copyright (C) 2004-2014 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,48 +22,51 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef TREEPROJECT_ITEM_H_ -#define TREEPROJECT_ITEM_H_ +#ifndef PROJECT_TREE_ITEM_H +#define PROJECT_TREE_ITEM_H #include #include "tree_file_type.h" -class TREE_PROJECT_FRAME; +class PROJECT_TREE_PANE; class wxTreeCtrl; /** - * TREEPROJECT_ITEM + * PROJECT_TREE_ITEM * handles one item (a file or a directory name) for the tree file */ -class TREEPROJECT_ITEM : public wxTreeItemData +class PROJECT_TREE_ITEM : public wxTreeItemData { public: - TREEPROJECT_ITEM( TREE_FILE_TYPE type, const wxString& data, - wxTreeCtrl* parent ); + PROJECT_TREE_ITEM( TREE_FILE_TYPE type, const wxString& data, wxTreeCtrl* parent ); - TREEPROJECT_ITEM() : m_parent( NULL ) { } + PROJECT_TREE_ITEM() : + m_parent( NULL ) + { } - TREEPROJECT_ITEM( const TREEPROJECT_ITEM& src ) : - m_Type( src.m_Type ), m_file_name( src.m_file_name ), m_parent( src.m_parent ) + PROJECT_TREE_ITEM( const PROJECT_TREE_ITEM& src ) : + m_type( src.m_type ), + m_file_name( src.m_file_name ), + m_parent( src.m_parent ) { SetState( src.m_state ); - m_IsPopulated = false; + m_isPopulated = false; } - TREE_FILE_TYPE GetType() const { return m_Type; } - void SetType( TREE_FILE_TYPE aType ) { m_Type = aType; } + TREE_FILE_TYPE GetType() const { return m_type; } + void SetType( TREE_FILE_TYPE aType ) { m_type = aType; } const wxString& GetFileName() const { return m_file_name; } void SetFileName( const wxString& name ) { m_file_name = name; } - bool IsRootFile() const { return m_IsRootFile; } - void SetRootFile( bool aValue ) { m_IsRootFile = aValue; } + bool IsRootFile() const { return m_isRootFile; } + void SetRootFile( bool aValue ) { m_isRootFile = aValue; } - bool IsPopulated() const { return m_IsPopulated; } - void SetPopulated( bool aValue ) { m_IsPopulated = aValue; } + bool IsPopulated() const { return m_isPopulated; } + void SetPopulated( bool aValue ) { m_isPopulated = aValue; } /** * @return the path of an item. @@ -75,17 +78,17 @@ public: bool Rename( const wxString& name, bool check = true ); void Delete(); void Print(); - void Activate( TREE_PROJECT_FRAME* aTreePrjFrame ); + void Activate( PROJECT_TREE_PANE* aTreePrjFrame ); void SetState( int state ); private: - TREE_FILE_TYPE m_Type; // = TREE_PROJECT, TREE_DIRECTORY ... + TREE_FILE_TYPE m_type; // = TREE_PROJECT, TREE_DIRECTORY ... wxString m_file_name; // Filename for a file, or directory name - bool m_IsRootFile; // True if m_Filename is a root schematic (same name as project) - bool m_IsPopulated; // True if the name is a directory, and its content was read + bool m_isRootFile; // True if m_Filename is a root schematic (same name as project) + bool m_isPopulated; // True if the name is a directory, and its content was read wxTreeCtrl* m_parent; int m_state; }; -#endif // TREEPROJECT_ITEM_H_ +#endif // PROJECT_TREE_ITEM_H diff --git a/kicad/tree_project_frame.cpp b/kicad/project_tree_pane.cpp similarity index 83% rename from kicad/tree_project_frame.cpp rename to kicad/project_tree_pane.cpp index 726a372d8e..a0c3752340 100644 --- a/kicad/tree_project_frame.cpp +++ b/kicad/project_tree_pane.cpp @@ -23,12 +23,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file tree_project_frame.cpp - * @brief Function to build the tree of files in the current project directory - */ - - #include #include @@ -43,24 +37,24 @@ #include #include -#include "treeproject_item.h" -#include "treeprojectfiles.h" +#include "project_tree_item.h" +#include "project_tree.h" #include "pgm_kicad.h" #include "kicad_id.h" #include "kicad_manager_frame.h" -#include "tree_project_frame.h" +#include "project_tree_pane.h" -/* Note about the tree project build process: - * Building the tree project can be *very* long if there are a lot of subdirectories - * in the working directory. - * Unfortunately, this happens easily if the project file *.pro is in the home directory +/* Note about the project tree build process: + * Building the project tree can be *very* long if there are a lot of subdirectories in the + * working directory. Unfortunately, this happens easily if the project file *.pro is in the + * user's home directory. * So the tree project is built "on demand": * First the tree is built from the current directory and shows files and subdirs. * > First level subdirs trees are built (i.e subdirs contents are not read) - * > When expanding a subdir, each subdir contains is read, - * and the corresponding sub tree is populated on the fly. + * > When expanding a subdir, each subdir contains is read, and the corresponding sub tree is + * populated on the fly. */ // list of files extensions listed in the tree project window @@ -116,30 +110,30 @@ const wxString GerberFileExtensionWildCard( ".((gbr|gbrjob|(gb|gt)[alops])|pho)" /** - * @brief class TREE_PROJECT_FRAME is the frame that shows the tree list of files and subdirs + * @brief class PROJECT_TREE_PANE is the frame that shows the tree list of files and subdirs * inside the working directory. Files are filtered (see s_allowedExtensionsToList) so * only useful files are shown. */ -BEGIN_EVENT_TABLE( TREE_PROJECT_FRAME, wxSashLayoutWindow ) - EVT_TREE_ITEM_ACTIVATED( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnSelect ) - 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_OPEN_DIR, TREE_PROJECT_FRAME::OnOpenDirectory ) - 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 ) +BEGIN_EVENT_TABLE( PROJECT_TREE_PANE, wxSashLayoutWindow ) + EVT_TREE_ITEM_ACTIVATED( ID_PROJECT_TREE, PROJECT_TREE_PANE::OnSelect ) + EVT_TREE_ITEM_EXPANDED( ID_PROJECT_TREE, PROJECT_TREE_PANE::OnExpand ) + EVT_TREE_ITEM_RIGHT_CLICK( ID_PROJECT_TREE, PROJECT_TREE_PANE::OnRight ) + EVT_MENU( ID_PROJECT_TXTEDIT, PROJECT_TREE_PANE::OnOpenSelectedFileWithTextEditor ) + EVT_MENU( ID_PROJECT_SWITCH_TO_OTHER, PROJECT_TREE_PANE::OnSwitchToSelectedProject ) + EVT_MENU( ID_PROJECT_NEWDIR, PROJECT_TREE_PANE::OnCreateNewDirectory ) + EVT_MENU( ID_PROJECT_OPEN_DIR, PROJECT_TREE_PANE::OnOpenDirectory ) + EVT_MENU( ID_PROJECT_DELETE, PROJECT_TREE_PANE::OnDeleteFile ) + EVT_MENU( ID_PROJECT_PRINT, PROJECT_TREE_PANE::OnPrintFile ) + EVT_MENU( ID_PROJECT_RENAME, PROJECT_TREE_PANE::OnRenameFile ) + EVT_IDLE( PROJECT_TREE_PANE::OnIdle ) END_EVENT_TABLE() -TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ) : - wxSashLayoutWindow( parent, ID_LEFT_FRAME, wxDefaultPosition, wxDefaultSize, - wxNO_BORDER | wxTAB_TRAVERSAL ) +PROJECT_TREE_PANE::PROJECT_TREE_PANE( KICAD_MANAGER_FRAME* parent ) : + wxSashLayoutWindow( parent, ID_LEFT_FRAME, wxDefaultPosition, wxDefaultSize, + wxNO_BORDER | wxTAB_TRAVERSAL ) { m_Parent = parent; m_TreeProject = NULL; @@ -148,7 +142,7 @@ TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ) : m_watcher = NULL; Connect( wxEVT_FSWATCHER, - wxFileSystemWatcherEventHandler( TREE_PROJECT_FRAME::OnFileSystemEvent ) ); + wxFileSystemWatcherEventHandler( PROJECT_TREE_PANE::OnFileSystemEvent ) ); /* * Filtering is now inverted: the filters are actually used to _enable_ support @@ -163,7 +157,7 @@ TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ) : } -TREE_PROJECT_FRAME::~TREE_PROJECT_FRAME() +PROJECT_TREE_PANE::~PROJECT_TREE_PANE() { if( m_watcher ) { @@ -174,9 +168,9 @@ TREE_PROJECT_FRAME::~TREE_PROJECT_FRAME() } -void TREE_PROJECT_FRAME::OnSwitchToSelectedProject( wxCommandEvent& event ) +void PROJECT_TREE_PANE::OnSwitchToSelectedProject( wxCommandEvent& event ) { - std::vector tree_data = GetSelectedData(); + std::vector tree_data = GetSelectedData(); if( tree_data.size() != 1 ) return; @@ -187,12 +181,12 @@ void TREE_PROJECT_FRAME::OnSwitchToSelectedProject( wxCommandEvent& event ) } -void TREE_PROJECT_FRAME::OnOpenDirectory( wxCommandEvent& event ) +void PROJECT_TREE_PANE::OnOpenDirectory( wxCommandEvent& event ) { // Get the root directory name: - std::vector tree_data = GetSelectedData(); + std::vector tree_data = GetSelectedData(); - for( TREEPROJECT_ITEM* item_data : tree_data ) + for( PROJECT_TREE_ITEM* item_data : tree_data ) { // Ask for the new sub directory name wxString curr_dir = item_data->GetDir(); @@ -227,12 +221,12 @@ void TREE_PROJECT_FRAME::OnOpenDirectory( wxCommandEvent& event ) } -void TREE_PROJECT_FRAME::OnCreateNewDirectory( wxCommandEvent& event ) +void PROJECT_TREE_PANE::OnCreateNewDirectory( wxCommandEvent& event ) { // Get the root directory name: - std::vector tree_data = GetSelectedData(); + std::vector tree_data = GetSelectedData(); - for( TREEPROJECT_ITEM* item_data : tree_data ) + for( PROJECT_TREE_ITEM* item_data : tree_data ) { wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() ); @@ -266,7 +260,7 @@ void TREE_PROJECT_FRAME::OnCreateNewDirectory( wxCommandEvent& event ) } -wxString TREE_PROJECT_FRAME::GetFileExt( TREE_FILE_TYPE type ) +wxString PROJECT_TREE_PANE::GetFileExt( TREE_FILE_TYPE type ) { switch( type ) { @@ -293,17 +287,17 @@ wxString TREE_PROJECT_FRAME::GetFileExt( TREE_FILE_TYPE type ) case TREE_FILE_TYPE::FOOTPRINT_FILE: return KiCadFootprintFileExtension; case TREE_FILE_TYPE::SCHEMATIC_LIBFILE: return LegacySymbolLibFileExtension; case TREE_FILE_TYPE::SEXPR_SYMBOL_LIB_FILE: return KiCadSymbolLibFileExtension; - default: return wxEmptyString; + default: return wxEmptyString; } } -wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject( - const wxString& aName, wxTreeItemId& aRoot, bool aCanResetFileWatcher, bool aRecurse ) +wxTreeItemId PROJECT_TREE_PANE::AddItemToProjectTree( const wxString& aName, wxTreeItemId& aRoot, + bool aCanResetFileWatcher, bool aRecurse ) { - wxTreeItemId newItemId; + wxTreeItemId newItemId; TREE_FILE_TYPE type = TREE_FILE_TYPE::UNKNOWN; - wxFileName fn( aName ); + wxFileName fn( aName ); // Files/dirs names starting by "." are not visible files under unices. // Skip them also under Windows @@ -349,9 +343,9 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject( // This is an ugly fix. if( fn.GetExt() == "sch" || fn.GetExt() == "kicad_sch" ) { - wxString fullFileName = aName.BeforeLast( '.' ); - wxString rootName; - TREEPROJECT_ITEM* itemData = GetItemIdData( m_root ); + wxString fullFileName = aName.BeforeLast( '.' ); + wxString rootName; + PROJECT_TREE_ITEM* itemData = GetItemIdData( m_root ); if( itemData ) rootName = itemData->GetFileName().BeforeLast( '.' ); @@ -413,11 +407,12 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject( if( ext == wxT( "" ) ) continue; - if( i == static_cast( TREE_FILE_TYPE::GERBER ) ) // For gerber files, the official ext is gbr + // For gerber files, the official ext is gbr + if( i == static_cast( TREE_FILE_TYPE::GERBER ) ) ext = "gbr"; - reg.Compile( wxString::FromAscii( "^.*\\." ) + ext + - wxString::FromAscii( "$" ), wxRE_ICASE ); + reg.Compile( wxString::FromAscii( "^.*\\." ) + ext + wxString::FromAscii( "$" ), + wxRE_ICASE ); if( reg.Matches( aName ) ) { @@ -434,7 +429,9 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject( // Ignore legacy projects with the same name as the current project if( ( type == TREE_FILE_TYPE::LEGACY_PROJECT ) && ( currfile.GetName().CmpNoCase( project.GetName() ) == 0 ) ) + { return newItemId; + } // also check to see if it is already there. wxTreeItemIdValue cookie; @@ -442,13 +439,10 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject( while( kid.IsOk() ) { - TREEPROJECT_ITEM* itemData = GetItemIdData( kid ); + PROJECT_TREE_ITEM* itemData = GetItemIdData( kid ); - if( itemData ) - { - if( itemData->GetFileName() == aName ) - return itemData->GetId(); // well, we would have added it, but it is already here! - } + if( itemData && itemData->GetFileName() == aName ) + return itemData->GetId(); // well, we would have added it, but it is already here! kid = m_TreeProject->GetNextChild( aRoot, cookie ); } @@ -460,7 +454,7 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject( while( kid.IsOk() ) { - TREEPROJECT_ITEM* itemData = GetItemIdData( kid ); + PROJECT_TREE_ITEM* itemData = GetItemIdData( kid ); if( itemData ) { @@ -489,7 +483,7 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject( // Append the item (only appending the filename not the full path): newItemId = m_TreeProject->AppendItem( aRoot, file ); - TREEPROJECT_ITEM* data = new TREEPROJECT_ITEM( type, aName, m_TreeProject ); + PROJECT_TREE_ITEM* data = new PROJECT_TREE_ITEM( type, aName, m_TreeProject ); m_TreeProject->SetItemData( newItemId, data ); data->SetState( 0 ); @@ -523,7 +517,7 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject( do // Add name in tree, but do not recurse { wxString path = aName + wxFileName::GetPathSeparator() + dir_filename; - AddItemToTreeProject( path, newItemId, false, false ); + AddItemToProjectTree( path, newItemId, false, false ); } while( dir.GetNext( &dir_filename ) ); } } @@ -541,16 +535,16 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject( } -void TREE_PROJECT_FRAME::ReCreateTreePrj() +void PROJECT_TREE_PANE::ReCreateTreePrj() { wxString pro_dir = m_Parent->GetProjectFileName(); if( !m_TreeProject ) - m_TreeProject = new TREEPROJECTFILES( this ); + m_TreeProject = new PROJECT_TREE( this ); else m_TreeProject->DeleteAllItems(); - if( !pro_dir ) // This is empty from TREE_PROJECT_FRAME constructor + if( !pro_dir ) // This is empty from PROJECT_TREE_PANE constructor return; wxFileName fn = pro_dir; @@ -580,12 +574,12 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj() // root tree: m_root = m_TreeProject->AddRoot( fn.GetFullName(), static_cast( TREE_FILE_TYPE::ROOT ), - static_cast( TREE_FILE_TYPE::ROOT ) ); + static_cast( TREE_FILE_TYPE::ROOT ) ); m_TreeProject->SetItemBold( m_root, true ); // The main project file is now a JSON file - m_TreeProject->SetItemData( m_root, - new TREEPROJECT_ITEM( TREE_FILE_TYPE::JSON_PROJECT, fn.GetFullPath(), m_TreeProject ) ); + m_TreeProject->SetItemData( m_root, new PROJECT_TREE_ITEM( TREE_FILE_TYPE::JSON_PROJECT, + fn.GetFullPath(), m_TreeProject ) ); // Now adding all current files if available if( prjOpened ) @@ -595,15 +589,15 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj() if( dir.IsOpened() ) // protected dirs will not open, see "man opendir()" { - wxString filename; - bool cont = dir.GetFirst( &filename ); + wxString filename; + bool cont = dir.GetFirst( &filename ); while( cont ) { if( filename != fn.GetFullName() ) { wxString name = dir.GetName() + wxFileName::GetPathSeparator() + filename; - AddItemToTreeProject( name, m_root, false ); + AddItemToProjectTree( name, m_root, false ); } cont = dir.GetNext( &filename ); @@ -622,14 +616,14 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj() } -void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event ) +void PROJECT_TREE_PANE::OnRight( wxTreeEvent& Event ) { - wxTreeItemId curr_item = Event.GetItem(); + wxTreeItemId curr_item = Event.GetItem(); // Ensure item is selected (Under Windows right click does not select the item) m_TreeProject->SelectItem( curr_item ); - std::vector selection = GetSelectedData(); + std::vector selection = GetSelectedData(); bool can_switch_to_project = true; bool can_create_new_directory = true; @@ -652,7 +646,7 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event ) can_print = false; } - for( TREEPROJECT_ITEM* item : selection ) + for( PROJECT_TREE_ITEM* item : selection ) { // Check for empty project if( !item ) @@ -784,12 +778,17 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event ) else help_text = _( "Delete the files and their contents" ); - if( can_switch_to_project || can_create_new_directory || can_open_this_directory || can_edit + if( can_switch_to_project + || can_create_new_directory + || can_open_this_directory + || can_edit || can_rename ) + { popup_menu.AppendSeparator(); + } - AddMenuItem( - &popup_menu, ID_PROJECT_DELETE, _( "Delete" ), help_text, KiBitmap( delete_xpm ) ); + AddMenuItem( &popup_menu, ID_PROJECT_DELETE, _( "Delete" ), help_text, + KiBitmap( delete_xpm ) ); } if( can_print ) @@ -809,18 +808,18 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event ) } -void TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor( wxCommandEvent& event ) +void PROJECT_TREE_PANE::OnOpenSelectedFileWithTextEditor( wxCommandEvent& event ) { wxString editorname = Pgm().GetEditorName(); if( editorname.IsEmpty() ) return; - std::vector tree_data = GetSelectedData(); + std::vector tree_data = GetSelectedData(); wxString files; - for( TREEPROJECT_ITEM* item_data : tree_data ) + for( PROJECT_TREE_ITEM* item_data : tree_data ) { wxString fullFileName = item_data->GetFileName(); AddDelimiterString( fullFileName ); @@ -835,22 +834,22 @@ void TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor( wxCommandEvent& event } -void TREE_PROJECT_FRAME::OnDeleteFile( wxCommandEvent& ) +void PROJECT_TREE_PANE::OnDeleteFile( wxCommandEvent& ) { - std::vector tree_data = GetSelectedData(); - wxString msg, caption; + std::vector tree_data = GetSelectedData(); + wxString msg, caption; if( tree_data.size() == 1 ) { bool is_directory = wxDirExists( tree_data[0]->GetFileName() ); - msg = wxString::Format( - _( "Are you sure you want to delete '%s'?" ), tree_data[0]->GetFileName() ); caption = is_directory ? _( "Delete Directory" ) : _( "Delete File" ); + msg = wxString::Format( _( "Are you sure you want to delete '%s'?" ), + tree_data[0]->GetFileName() ); } else { - msg = wxString::Format( - _( "Are you sure you want to delete %lu items?" ), tree_data.size() ); + msg = wxString::Format( _( "Are you sure you want to delete %lu items?" ), + tree_data.size() ); caption = _( "Delete Multiple Items" ); } @@ -858,25 +857,25 @@ void TREE_PROJECT_FRAME::OnDeleteFile( wxCommandEvent& ) if( dialog.ShowModal() == wxID_YES ) { - for( TREEPROJECT_ITEM* item_data : tree_data ) + for( PROJECT_TREE_ITEM* item_data : tree_data ) item_data->Delete(); } } -void TREE_PROJECT_FRAME::OnPrintFile( wxCommandEvent& ) +void PROJECT_TREE_PANE::OnPrintFile( wxCommandEvent& ) { - std::vector tree_data = GetSelectedData(); + std::vector tree_data = GetSelectedData(); - for( TREEPROJECT_ITEM* item_data : tree_data ) + for( PROJECT_TREE_ITEM* item_data : tree_data ) item_data->Print(); } -void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& ) +void PROJECT_TREE_PANE::OnRenameFile( wxCommandEvent& ) { - wxTreeItemId curr_item = m_TreeProject->GetFocusedItem(); - std::vector tree_data = GetSelectedData(); + wxTreeItemId curr_item = m_TreeProject->GetFocusedItem(); + std::vector tree_data = GetSelectedData(); // XXX: Unnecessary? if( tree_data.size() != 1 ) @@ -902,9 +901,9 @@ void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& ) } -void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event ) +void PROJECT_TREE_PANE::OnSelect( wxTreeEvent& Event ) { - std::vector tree_data = GetSelectedData(); + std::vector tree_data = GetSelectedData(); if( tree_data.size() != 1 ) return; @@ -916,7 +915,7 @@ void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event ) } -void TREE_PROJECT_FRAME::OnIdle( wxIdleEvent& aEvent ) +void PROJECT_TREE_PANE::OnIdle( wxIdleEvent& aEvent ) { // Idle executes once all other events finished processing // This makes it ideal to launch a new window without starting Focus wars. @@ -928,10 +927,10 @@ void TREE_PROJECT_FRAME::OnIdle( wxIdleEvent& aEvent ) } -void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event ) +void PROJECT_TREE_PANE::OnExpand( wxTreeEvent& Event ) { - wxTreeItemId itemId = Event.GetItem(); - TREEPROJECT_ITEM* tree_data = GetItemIdData( itemId ); + wxTreeItemId itemId = Event.GetItem(); + PROJECT_TREE_ITEM* tree_data = GetItemIdData( itemId ); if( !tree_data ) return; @@ -949,7 +948,7 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event ) for( ; kid.IsOk(); kid = m_TreeProject->GetNextChild( itemId, cookie ) ) { - TREEPROJECT_ITEM* itemData = GetItemIdData( kid ); + PROJECT_TREE_ITEM* itemData = GetItemIdData( kid ); if( !itemData || itemData->GetType() != TREE_FILE_TYPE::DIRECTORY ) continue; @@ -969,7 +968,7 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event ) do // Add name to tree item, but do not recurse in subdirs: { wxString name = fileName + wxFileName::GetPathSeparator() + dir_filename; - AddItemToTreeProject( name, kid, false ); + AddItemToProjectTree( name, kid, false ); } while( dir.GetNext( &dir_filename ) ); } @@ -990,10 +989,10 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event ) } -std::vector TREE_PROJECT_FRAME::GetSelectedData() +std::vector PROJECT_TREE_PANE::GetSelectedData() { wxArrayTreeItemIds selection; - std::vector data; + std::vector data; m_TreeProject->GetSelections( selection ); @@ -1004,13 +1003,13 @@ std::vector TREE_PROJECT_FRAME::GetSelectedData() } -TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetItemIdData( wxTreeItemId aId ) +PROJECT_TREE_ITEM* PROJECT_TREE_PANE::GetItemIdData( wxTreeItemId aId ) { - return dynamic_cast( m_TreeProject->GetItemData( aId ) ); + return dynamic_cast( m_TreeProject->GetItemData( aId ) ); } -wxTreeItemId TREE_PROJECT_FRAME::findSubdirTreeItem( const wxString& aSubDir ) +wxTreeItemId PROJECT_TREE_PANE::findSubdirTreeItem( const wxString& aSubDir ) { wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() ); @@ -1046,7 +1045,7 @@ wxTreeItemId TREE_PROJECT_FRAME::findSubdirTreeItem( const wxString& aSubDir ) } } - TREEPROJECT_ITEM* itemData = GetItemIdData( kid ); + PROJECT_TREE_ITEM* itemData = GetItemIdData( kid ); if( itemData && ( itemData->GetType() == TREE_FILE_TYPE::DIRECTORY ) ) { @@ -1068,7 +1067,7 @@ wxTreeItemId TREE_PROJECT_FRAME::findSubdirTreeItem( const wxString& aSubDir ) } -void TREE_PROJECT_FRAME::OnFileSystemEvent( wxFileSystemWatcherEvent& event ) +void PROJECT_TREE_PANE::OnFileSystemEvent( wxFileSystemWatcherEvent& event ) { const wxFileName& pathModified = event.GetPath(); wxString subdir = pathModified.GetPath(); @@ -1099,7 +1098,7 @@ void TREE_PROJECT_FRAME::OnFileSystemEvent( wxFileSystemWatcherEvent& event ) { case wxFSW_EVENT_CREATE: { - wxTreeItemId newitem = AddItemToTreeProject( pathModified.GetFullPath(), root_id ); + wxTreeItemId newitem = AddItemToProjectTree( pathModified.GetFullPath(), root_id ); // If we are in the process of renaming a file, select the new one // This is needed for MSW and OSX, since we don't get RENAME events from them, just a @@ -1115,7 +1114,7 @@ void TREE_PROJECT_FRAME::OnFileSystemEvent( wxFileSystemWatcherEvent& event ) case wxFSW_EVENT_DELETE: while( kid.IsOk() ) { - TREEPROJECT_ITEM* itemData = GetItemIdData( kid ); + PROJECT_TREE_ITEM* itemData = GetItemIdData( kid ); if( itemData && itemData->GetFileName() == fn ) { @@ -1134,7 +1133,7 @@ void TREE_PROJECT_FRAME::OnFileSystemEvent( wxFileSystemWatcherEvent& event ) while( kid.IsOk() ) { - TREEPROJECT_ITEM* itemData = GetItemIdData( kid ); + PROJECT_TREE_ITEM* itemData = GetItemIdData( kid ); if( itemData && itemData->GetFileName() == fn ) { @@ -1152,12 +1151,12 @@ void TREE_PROJECT_FRAME::OnFileSystemEvent( wxFileSystemWatcherEvent& event ) // exists on the file system before it is readded. On Linux, moving a file to the trash // can cause the same path to be returned in both the old and new paths of the event, // even though the file isn't there anymore. - TREEPROJECT_ITEM* rootData = GetItemIdData( root_id ); + PROJECT_TREE_ITEM* rootData = GetItemIdData( root_id ); if( newpath.Exists() && ( newfn != rootData->GetFileName() ) ) { wxTreeItemId newroot_id = findSubdirTreeItem( newdir ); - wxTreeItemId newitem = AddItemToTreeProject( newfn, newroot_id ); + wxTreeItemId newitem = AddItemToProjectTree( newfn, newroot_id ); // If the item exists, select it if( newitem.IsOk() ) @@ -1174,7 +1173,7 @@ void TREE_PROJECT_FRAME::OnFileSystemEvent( wxFileSystemWatcherEvent& event ) } -void TREE_PROJECT_FRAME::FileWatcherReset() +void PROJECT_TREE_PANE::FileWatcherReset() { // Prepare file watcher: if( m_watcher ) @@ -1220,7 +1219,9 @@ void TREE_PROJECT_FRAME::FileWatcherReset() if( !kid.IsOk() ) { if( subdirs_id.empty() ) // all items were explored + { break; + } else { root_id = subdirs_id.top(); @@ -1232,7 +1233,7 @@ void TREE_PROJECT_FRAME::FileWatcherReset() } } - TREEPROJECT_ITEM* itemData = GetItemIdData( kid ); + PROJECT_TREE_ITEM* itemData = GetItemIdData( kid ); if( itemData && itemData->GetType() == TREE_FILE_TYPE::DIRECTORY ) { @@ -1267,7 +1268,7 @@ void TREE_PROJECT_FRAME::FileWatcherReset() } -void TREE_PROJECT_FRAME::EmptyTreePrj() +void PROJECT_TREE_PANE::EmptyTreePrj() { m_TreeProject->DeleteAllItems(); } diff --git a/kicad/tree_project_frame.h b/kicad/project_tree_pane.h similarity index 88% rename from kicad/tree_project_frame.h rename to kicad/project_tree_pane.h index d8bdfc0dc7..c05833929e 100644 --- a/kicad/tree_project_frame.h +++ b/kicad/project_tree_pane.h @@ -23,7 +23,7 @@ */ /** - * @file tree_project_frame.h + * @file PROJECT_TREE_PANE.h */ @@ -39,29 +39,30 @@ class KICAD_MANAGER_FRAME; -class TREEPROJECT_ITEM; -class TREEPROJECTFILES; +class PROJECT_TREE_ITEM; +class PROJECT_TREE; -/** TREE_PROJECT_FRAME +/** PROJECT_TREE_PANE * Window to display the tree files */ -class TREE_PROJECT_FRAME : public wxSashLayoutWindow +class PROJECT_TREE_PANE : public wxSashLayoutWindow { - friend class TREEPROJECT_ITEM; + friend class PROJECT_TREE_ITEM; + public: KICAD_MANAGER_FRAME* m_Parent; - TREEPROJECTFILES* m_TreeProject; + PROJECT_TREE* m_TreeProject; private: bool m_isRenaming; // Are we in the process of renaming a file wxTreeItemId m_root; std::vector m_filters; wxFileSystemWatcher* m_watcher; // file system watcher - TREEPROJECT_ITEM* m_selectedItem; + PROJECT_TREE_ITEM* m_selectedItem; public: - TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ); - ~TREE_PROJECT_FRAME(); + PROJECT_TREE_PANE( KICAD_MANAGER_FRAME* parent ); + ~PROJECT_TREE_PANE(); /** * Create or modify the tree showing project file names @@ -90,15 +91,15 @@ protected: * Note this is not necessary the "clicked" item, * because when expanding, collapsing an item this item is not selected */ - std::vector GetSelectedData(); + std::vector GetSelectedData(); /** * Function GetItemIdData * return the item data corresponding to a wxTreeItemId identifier * @param aId = the wxTreeItemId identifier. - * @return a TREEPROJECT_ITEM pointer corresponding to item id aId + * @return a PROJECT_TREE_ITEM pointer corresponding to item id aId */ - TREEPROJECT_ITEM* GetItemIdData( wxTreeItemId aId ); + PROJECT_TREE_ITEM* GetItemIdData( wxTreeItemId aId ); private: /** @@ -166,7 +167,7 @@ private: void OnIdle( wxIdleEvent &aEvent ); /** - * Function AddItemToTreeProject + * Function AddItemToProjectTree * @brief Add the file or directory aName to the project tree * @param aName = the filename or the directory name to add in tree * @param aRoot = the wxTreeItemId item where to add sub tree items @@ -175,8 +176,8 @@ private: * false to stop file add. * @return the Id for the new tree item */ - wxTreeItemId AddItemToTreeProject( const wxString& aName, wxTreeItemId& aRoot, - bool aCanResetFileWatcher = true, bool aRecurse = true ); + wxTreeItemId AddItemToProjectTree( const wxString& aName, wxTreeItemId& aRoot, + bool aCanResetFileWatcher = true, bool aRecurse = true ); /** * Function findSubdirTreeItem diff --git a/kicad/tree_file_type.h b/kicad/tree_file_type.h index 509e9ae083..b8f78467e1 100644 --- a/kicad/tree_file_type.h +++ b/kicad/tree_file_type.h @@ -21,10 +21,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file tree_file_types.h - */ - #ifndef TREE_FILE_TYPE_H #define TREE_FILE_TYPE_H @@ -32,7 +28,7 @@ // Identify the type of files handled by KiCad manager // // When changing this enum please verify (and perhaps update) -// TREE_PROJECT_FRAME::GetFileExt(), +// PROJECT_TREE_PANE::GetFileExt(), // s_AllowedExtensionsToList[] enum class TREE_FILE_TYPE { diff --git a/kicad/treeprojectfiles.cpp b/kicad/treeprojectfiles.cpp deleted file mode 100644 index 4a1a3900ce..0000000000 --- a/kicad/treeprojectfiles.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2004-2012 Jean-Pierre Charras - * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -/** - * @file class_treeprojectfiles.cpp - * this is the wxTreeCtrl that shows a KiCad tree project files - */ - - -#include - -#include "treeproject_item.h" -#include "tree_project_frame.h" -#include "treeprojectfiles.h" -#include "kicad_id.h" - - -IMPLEMENT_ABSTRACT_CLASS( TREEPROJECTFILES, wxTreeCtrl ) - - -TREEPROJECTFILES::TREEPROJECTFILES( TREE_PROJECT_FRAME* parent ) - : wxTreeCtrl( parent, ID_PROJECT_TREE, wxDefaultPosition, wxDefaultSize, - wxTR_HAS_BUTTONS | wxTR_MULTIPLE, wxDefaultValidator, wxT( "EDATreeCtrl" ) ) -{ - m_Parent = parent; - - // icons size is not know (depending on they are built) - // so get it: - wxSize iconsize; - wxBitmap dummy = KiBitmap( eeschema_xpm ); - iconsize.x = dummy.GetWidth(); - iconsize.y = dummy.GetHeight(); - - // Make an image list containing small icons - m_ImageList = new wxImageList( iconsize.x, iconsize.y, true, static_cast( TREE_FILE_TYPE::MAX ) ); - - m_ImageList->Add( KiBitmap( new_project_xpm ) ); // TREE_LEGACY_PROJECT - m_ImageList->Add( KiBitmap( new_project_xpm ) ); // TREE_JSON_PROJECT - m_ImageList->Add( KiBitmap( eeschema_xpm ) ); // TREE_LEGACY_SCHEMATIC - m_ImageList->Add( KiBitmap( eeschema_xpm ) ); // TREE_SEXPR_SCHEMATIC - m_ImageList->Add( KiBitmap( pcbnew_xpm ) ); // TREE_LEGACY_PCB - m_ImageList->Add( KiBitmap( pcbnew_xpm ) ); // TREE_SEXPR_PCB - m_ImageList->Add( KiBitmap( icon_gerbview_small_xpm ) ); // TREE_GERBER - m_ImageList->Add( KiBitmap( gerber_job_file_xpm ) ); // TREE_GERBER_JOB_FILE (.gbrjob) - m_ImageList->Add( KiBitmap( html_xpm ) ); // TREE_HTML - m_ImageList->Add( KiBitmap( datasheet_xpm ) ); // TREE_PDF - m_ImageList->Add( KiBitmap( editor_xpm ) ); // TREE_TXT - m_ImageList->Add( KiBitmap( netlist_xpm ) ); // TREE_NET - m_ImageList->Add( KiBitmap( unknown_xpm ) ); // TREE_UNKNOWN - m_ImageList->Add( KiBitmap( directory_xpm ) ); // TREE_DIRECTORY - m_ImageList->Add( KiBitmap( icon_cvpcb_small_xpm ) ); // TREE_CMP_LINK - m_ImageList->Add( KiBitmap( tools_xpm ) ); // TREE_REPORT - m_ImageList->Add( KiBitmap( post_compo_xpm ) ); // TREE_POS - m_ImageList->Add( KiBitmap( post_drill_xpm ) ); // TREE_DRILL - m_ImageList->Add( KiBitmap( post_drill_xpm ) ); // TREE_DRILL_NC (similar TREE_DRILL) - m_ImageList->Add( KiBitmap( post_drill_xpm ) ); // TREE_DRILL_XNC (similar TREE_DRILL) - m_ImageList->Add( KiBitmap( svg_file_xpm ) ); // TREE_SVG - m_ImageList->Add( KiBitmap( pagelayout_load_xpm ) ); // TREE_PAGE_LAYOUT_DESCR - m_ImageList->Add( KiBitmap( module_xpm ) ); // TREE_FOOTPRINT_FILE - m_ImageList->Add( KiBitmap( library_xpm ) ); // TREE_SCHEMATIC_LIBFILE - m_ImageList->Add( KiBitmap( library_xpm ) ); // TREE_SEXPR_SYMBOL_LIB_FILE - - SetImageList( m_ImageList ); -} - - -TREEPROJECTFILES::~TREEPROJECTFILES() -{ - delete m_ImageList; -} - - -int TREEPROJECTFILES::OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 ) -{ - TREEPROJECT_ITEM* myitem1 = (TREEPROJECT_ITEM*) GetItemData( item1 ); - TREEPROJECT_ITEM* myitem2 = (TREEPROJECT_ITEM*) GetItemData( item2 ); - - if( !myitem1 || !myitem2 ) - return 0; - - if( myitem1->GetType() == TREE_FILE_TYPE::DIRECTORY - && myitem2->GetType() != TREE_FILE_TYPE::DIRECTORY ) - return -1; - - if( myitem2->GetType() == TREE_FILE_TYPE::DIRECTORY - && myitem1->GetType() != TREE_FILE_TYPE::DIRECTORY ) - return 1; - - if( myitem1->IsRootFile() && !myitem2->IsRootFile() ) - return -1; - - if( myitem2->IsRootFile() && !myitem1->IsRootFile() ) - return 1; - - return myitem1->GetFileName().CmpNoCase( myitem2->GetFileName() ); -}