Formatting and naming conventions.

This commit is contained in:
Jeff Young 2020-12-02 12:35:19 +00:00
parent 71ab42e60a
commit 4a0543c099
11 changed files with 315 additions and 327 deletions

View File

@ -24,9 +24,9 @@ set( KICAD_SRCS
kicad_settings.cpp kicad_settings.cpp
menubar.cpp menubar.cpp
project_template.cpp project_template.cpp
tree_project_frame.cpp project_tree_pane.cpp
treeprojectfiles.cpp project_tree.cpp
treeproject_item.cpp project_tree_item.cpp
tools/kicad_manager_actions.cpp tools/kicad_manager_actions.cpp
tools/kicad_manager_control.cpp tools/kicad_manager_control.cpp
) )

View File

@ -25,7 +25,7 @@
#include "kicad_id.h" #include "kicad_id.h"
#include "pgm_kicad.h" #include "pgm_kicad.h"
#include "tree_project_frame.h" #include "project_tree_pane.h"
#include <bitmaps.h> #include <bitmaps.h>
#include <build_version.h> #include <build_version.h>
#include <eda_base_frame.h> #include <eda_base_frame.h>
@ -117,7 +117,7 @@ KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& titl
LoadSettings( config() ); LoadSettings( config() );
// Left window: is the box which display tree project // 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: // Add the wxTextCtrl showing all messages from KiCad:
m_messagesBox = new wxTextCtrl( this, wxID_ANY, wxEmptyString, m_messagesBox = new wxTextCtrl( this, wxID_ANY, wxEmptyString,

View File

@ -29,8 +29,8 @@
#include <wx/process.h> #include <wx/process.h>
#include <kiway_player.h> #include <kiway_player.h>
class TREEPROJECTFILES; class PROJECT_TREE;
class TREE_PROJECT_FRAME; class PROJECT_TREE_PANE;
class ACTION_TOOLBAR; class ACTION_TOOLBAR;
class KICAD_SETTINGS; class KICAD_SETTINGS;
class EDA_BASE_FRAME; class EDA_BASE_FRAME;
@ -185,7 +185,7 @@ private:
bool m_openSavedWindows; bool m_openSavedWindows;
private: private:
TREE_PROJECT_FRAME* m_leftWin; PROJECT_TREE_PANE* m_leftWin;
ACTION_TOOLBAR* m_launcher; ACTION_TOOLBAR* m_launcher;
wxTextCtrl* m_messagesBox; wxTextCtrl* m_messagesBox;
ACTION_TOOLBAR* m_mainToolBar; ACTION_TOOLBAR* m_mainToolBar;

114
kicad/project_tree.cpp Normal file
View File

@ -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 <bitmaps.h>
#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<int>( 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() );
}

View File

@ -22,43 +22,36 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
/* #ifndef PROJECT_TREE_H
* file treeprojectfiles.h #define PROJECT_TREE_H
*/
#ifndef TREEPROJECTFILES_H
#define TREEPROJECTFILES_H
#include <wx/treectrl.h> #include <wx/treectrl.h>
#include "tree_file_type.h" #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 * 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: private:
TREE_PROJECT_FRAME* m_Parent; PROJECT_TREE_PANE* m_projectTreePane;
wxImageList* m_ImageList; wxImageList* m_imageList;
public: public:
PROJECT_TREE_PANE* GetProjectTreePane() const { return m_projectTreePane; }
TREE_PROJECT_FRAME* GetParent() const PROJECT_TREE( PROJECT_TREE_PANE* parent );
{ ~PROJECT_TREE();
return m_Parent;
}
TREEPROJECTFILES( TREE_PROJECT_FRAME* parent );
~TREEPROJECTFILES();
private: private:
/* overridden sort function */ /* overridden sort function */
int OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 ) override; int OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 ) override;
}; };
#endif // TREEPROJECTFILES_H #endif // PROJECT_TREE_H

View File

@ -22,9 +22,7 @@
*/ */
/** /**
* @file treeproject_item.cpp * @brief Class PROJECT_TREE_ITEM is a derived class from wxTreeItemData and
*
* @brief Class TREEPROJECT_ITEM is a derived class from wxTreeItemData and
* store info about a file or directory shown in the KiCad tree project files * store info about a file or directory shown in the KiCad tree project files
*/ */
@ -39,15 +37,15 @@
#include <tools/kicad_manager_actions.h> #include <tools/kicad_manager_actions.h>
#include "kicad_manager_frame.h" #include "kicad_manager_frame.h"
#include "treeprojectfiles.h" #include "project_tree.h"
#include "pgm_kicad.h" #include "pgm_kicad.h"
#include "tree_project_frame.h" #include "project_tree_pane.h"
#include "treeproject_item.h" #include "project_tree_item.h"
#include "kicad_id.h" #include "kicad_id.h"
TREEPROJECT_ITEM::TREEPROJECT_ITEM( TREE_FILE_TYPE type, const wxString& data, PROJECT_TREE_ITEM::PROJECT_TREE_ITEM( TREE_FILE_TYPE type, const wxString& data,
wxTreeCtrl* parent ) : wxTreeCtrl* parent ) :
wxTreeItemData() wxTreeItemData()
{ {
m_parent = parent; 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(); wxImageList* imglist = m_parent->GetImageList();
int treeEnumMax = static_cast<int>( TREE_FILE_TYPE::MAX ); int treeEnumMax = static_cast<int>( TREE_FILE_TYPE::MAX );
@ -68,25 +66,25 @@ void TREEPROJECT_ITEM::SetState( int state )
return; return;
m_state = state; m_state = state;
int imgid = static_cast<int>( m_Type ) - 1 + state * ( treeEnumMax - 1 ); int imgid = static_cast<int>( m_type ) - 1 + state * ( treeEnumMax - 1 );
m_parent->SetItemImage( GetId(), imgid ); m_parent->SetItemImage( GetId(), imgid );
m_parent->SetItemImage( GetId(), imgid, wxTreeItemIcon_Selected ); 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 GetFileName();
return wxFileName( GetFileName() ).GetPath(); 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. // this is broken & unsafe to use on linux.
if( m_Type == TREE_FILE_TYPE::DIRECTORY ) if( m_type == TREE_FILE_TYPE::DIRECTORY )
return false; return false;
if( name.IsEmpty() ) if( name.IsEmpty() )
@ -104,9 +102,8 @@ bool TREEPROJECT_ITEM::Rename( const wxString& name, bool check )
if( newFile == GetFileName() ) if( newFile == GetFileName() )
return false; return false;
wxString ext = TREE_PROJECT_FRAME::GetFileExt( GetType() ); wxString ext = PROJECT_TREE_PANE::GetFileExt( GetType() );
wxRegEx reg( wxT( "^.*\\" ) + ext + wxT( "$" ), wxRE_ICASE );
wxRegEx reg( wxT( "^.*\\" ) + ext + wxT( "$" ), wxRE_ICASE );
if( check && !ext.IsEmpty() && !reg.Matches( newFile ) ) 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; wxString errMsg;
@ -144,13 +141,13 @@ void TREEPROJECT_ITEM::Delete()
} }
void TREEPROJECT_ITEM::Print() void PROJECT_TREE_ITEM::Print()
{ {
PrintFile( GetFileName() ); PrintFile( GetFileName() );
} }
void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* aTreePrjFrame ) void PROJECT_TREE_ITEM::Activate( PROJECT_TREE_PANE* aTreePrjFrame )
{ {
wxString sep = wxFileName::GetPathSeparator(); wxString sep = wxFileName::GetPathSeparator();
wxString fullFileName = GetFileName(); wxString fullFileName = GetFileName();

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2010-2014 Jean-Pierre Charras * 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#ifndef TREEPROJECT_ITEM_H_ #ifndef PROJECT_TREE_ITEM_H
#define TREEPROJECT_ITEM_H_ #define PROJECT_TREE_ITEM_H
#include <wx/treebase.h> #include <wx/treebase.h>
#include "tree_file_type.h" #include "tree_file_type.h"
class TREE_PROJECT_FRAME; class PROJECT_TREE_PANE;
class wxTreeCtrl; class wxTreeCtrl;
/** /**
* TREEPROJECT_ITEM * PROJECT_TREE_ITEM
* handles one item (a file or a directory name) for the tree file * 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: public:
TREEPROJECT_ITEM( TREE_FILE_TYPE type, const wxString& data, PROJECT_TREE_ITEM( TREE_FILE_TYPE type, const wxString& data, wxTreeCtrl* parent );
wxTreeCtrl* parent );
TREEPROJECT_ITEM() : m_parent( NULL ) { } PROJECT_TREE_ITEM() :
m_parent( NULL )
{ }
TREEPROJECT_ITEM( const TREEPROJECT_ITEM& src ) : 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 ) m_type( src.m_type ),
m_file_name( src.m_file_name ),
m_parent( src.m_parent )
{ {
SetState( src.m_state ); SetState( src.m_state );
m_IsPopulated = false; m_isPopulated = false;
} }
TREE_FILE_TYPE GetType() const { return m_Type; } TREE_FILE_TYPE GetType() const { return m_type; }
void SetType( TREE_FILE_TYPE aType ) { m_Type = aType; } void SetType( TREE_FILE_TYPE aType ) { m_type = aType; }
const wxString& GetFileName() const { return m_file_name; } const wxString& GetFileName() const { return m_file_name; }
void SetFileName( const wxString& name ) { m_file_name = name; } void SetFileName( const wxString& name ) { m_file_name = name; }
bool IsRootFile() const { return m_IsRootFile; } bool IsRootFile() const { return m_isRootFile; }
void SetRootFile( bool aValue ) { m_IsRootFile = aValue; } void SetRootFile( bool aValue ) { m_isRootFile = aValue; }
bool IsPopulated() const { return m_IsPopulated; } bool IsPopulated() const { return m_isPopulated; }
void SetPopulated( bool aValue ) { m_IsPopulated = aValue; } void SetPopulated( bool aValue ) { m_isPopulated = aValue; }
/** /**
* @return the path of an item. * @return the path of an item.
@ -75,17 +78,17 @@ public:
bool Rename( const wxString& name, bool check = true ); bool Rename( const wxString& name, bool check = true );
void Delete(); void Delete();
void Print(); void Print();
void Activate( TREE_PROJECT_FRAME* aTreePrjFrame ); void Activate( PROJECT_TREE_PANE* aTreePrjFrame );
void SetState( int state ); void SetState( int state );
private: 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 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_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_isPopulated; // True if the name is a directory, and its content was read
wxTreeCtrl* m_parent; wxTreeCtrl* m_parent;
int m_state; int m_state;
}; };
#endif // TREEPROJECT_ITEM_H_ #endif // PROJECT_TREE_ITEM_H

View File

@ -23,12 +23,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 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 <stack> #include <stack>
#include <wx/regex.h> #include <wx/regex.h>
@ -43,24 +37,24 @@
#include <trace_helpers.h> #include <trace_helpers.h>
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
#include "treeproject_item.h" #include "project_tree_item.h"
#include "treeprojectfiles.h" #include "project_tree.h"
#include "pgm_kicad.h" #include "pgm_kicad.h"
#include "kicad_id.h" #include "kicad_id.h"
#include "kicad_manager_frame.h" #include "kicad_manager_frame.h"
#include "tree_project_frame.h" #include "project_tree_pane.h"
/* Note about the tree project build process: /* Note about the project tree build process:
* Building the tree project can be *very* long if there are a lot of subdirectories * Building the project tree can be *very* long if there are a lot of subdirectories in the
* in the working directory. * working directory. Unfortunately, this happens easily if the project file *.pro is in the
* Unfortunately, this happens easily if the project file *.pro is in the home directory * user's home directory.
* So the tree project is built "on demand": * So the tree project is built "on demand":
* First the tree is built from the current directory and shows files and subdirs. * 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) * > First level subdirs trees are built (i.e subdirs contents are not read)
* > When expanding a subdir, each subdir contains is read, * > When expanding a subdir, each subdir contains is read, and the corresponding sub tree is
* and the corresponding sub tree is populated on the fly. * populated on the fly.
*/ */
// list of files extensions listed in the tree project window // 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 * inside the working directory. Files are filtered (see s_allowedExtensionsToList) so
* only useful files are shown. * only useful files are shown.
*/ */
BEGIN_EVENT_TABLE( TREE_PROJECT_FRAME, wxSashLayoutWindow ) BEGIN_EVENT_TABLE( PROJECT_TREE_PANE, wxSashLayoutWindow )
EVT_TREE_ITEM_ACTIVATED( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnSelect ) EVT_TREE_ITEM_ACTIVATED( ID_PROJECT_TREE, PROJECT_TREE_PANE::OnSelect )
EVT_TREE_ITEM_EXPANDED( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnExpand ) EVT_TREE_ITEM_EXPANDED( ID_PROJECT_TREE, PROJECT_TREE_PANE::OnExpand )
EVT_TREE_ITEM_RIGHT_CLICK( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnRight ) EVT_TREE_ITEM_RIGHT_CLICK( ID_PROJECT_TREE, PROJECT_TREE_PANE::OnRight )
EVT_MENU( ID_PROJECT_TXTEDIT, TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor ) EVT_MENU( ID_PROJECT_TXTEDIT, PROJECT_TREE_PANE::OnOpenSelectedFileWithTextEditor )
EVT_MENU( ID_PROJECT_SWITCH_TO_OTHER, TREE_PROJECT_FRAME::OnSwitchToSelectedProject ) EVT_MENU( ID_PROJECT_SWITCH_TO_OTHER, PROJECT_TREE_PANE::OnSwitchToSelectedProject )
EVT_MENU( ID_PROJECT_NEWDIR, TREE_PROJECT_FRAME::OnCreateNewDirectory ) EVT_MENU( ID_PROJECT_NEWDIR, PROJECT_TREE_PANE::OnCreateNewDirectory )
EVT_MENU( ID_PROJECT_OPEN_DIR, TREE_PROJECT_FRAME::OnOpenDirectory ) EVT_MENU( ID_PROJECT_OPEN_DIR, PROJECT_TREE_PANE::OnOpenDirectory )
EVT_MENU( ID_PROJECT_DELETE, TREE_PROJECT_FRAME::OnDeleteFile ) EVT_MENU( ID_PROJECT_DELETE, PROJECT_TREE_PANE::OnDeleteFile )
EVT_MENU( ID_PROJECT_PRINT, TREE_PROJECT_FRAME::OnPrintFile ) EVT_MENU( ID_PROJECT_PRINT, PROJECT_TREE_PANE::OnPrintFile )
EVT_MENU( ID_PROJECT_RENAME, TREE_PROJECT_FRAME::OnRenameFile ) EVT_MENU( ID_PROJECT_RENAME, PROJECT_TREE_PANE::OnRenameFile )
EVT_IDLE( TREE_PROJECT_FRAME::OnIdle ) EVT_IDLE( PROJECT_TREE_PANE::OnIdle )
END_EVENT_TABLE() END_EVENT_TABLE()
TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ) : PROJECT_TREE_PANE::PROJECT_TREE_PANE( KICAD_MANAGER_FRAME* parent ) :
wxSashLayoutWindow( parent, ID_LEFT_FRAME, wxDefaultPosition, wxDefaultSize, wxSashLayoutWindow( parent, ID_LEFT_FRAME, wxDefaultPosition, wxDefaultSize,
wxNO_BORDER | wxTAB_TRAVERSAL ) wxNO_BORDER | wxTAB_TRAVERSAL )
{ {
m_Parent = parent; m_Parent = parent;
m_TreeProject = NULL; m_TreeProject = NULL;
@ -148,7 +142,7 @@ TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ) :
m_watcher = NULL; m_watcher = NULL;
Connect( wxEVT_FSWATCHER, 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 * 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 ) 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<TREEPROJECT_ITEM*> tree_data = GetSelectedData(); std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
if( tree_data.size() != 1 ) if( tree_data.size() != 1 )
return; 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: // Get the root directory name:
std::vector<TREEPROJECT_ITEM*> tree_data = GetSelectedData(); std::vector<PROJECT_TREE_ITEM*> 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 // Ask for the new sub directory name
wxString curr_dir = item_data->GetDir(); 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: // Get the root directory name:
std::vector<TREEPROJECT_ITEM*> tree_data = GetSelectedData(); std::vector<PROJECT_TREE_ITEM*> 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() ); 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 ) 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::FOOTPRINT_FILE: return KiCadFootprintFileExtension;
case TREE_FILE_TYPE::SCHEMATIC_LIBFILE: return LegacySymbolLibFileExtension; case TREE_FILE_TYPE::SCHEMATIC_LIBFILE: return LegacySymbolLibFileExtension;
case TREE_FILE_TYPE::SEXPR_SYMBOL_LIB_FILE: return KiCadSymbolLibFileExtension; case TREE_FILE_TYPE::SEXPR_SYMBOL_LIB_FILE: return KiCadSymbolLibFileExtension;
default: return wxEmptyString; default: return wxEmptyString;
} }
} }
wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject( wxTreeItemId PROJECT_TREE_PANE::AddItemToProjectTree( const wxString& aName, wxTreeItemId& aRoot,
const wxString& aName, wxTreeItemId& aRoot, bool aCanResetFileWatcher, bool aRecurse ) bool aCanResetFileWatcher, bool aRecurse )
{ {
wxTreeItemId newItemId; wxTreeItemId newItemId;
TREE_FILE_TYPE type = TREE_FILE_TYPE::UNKNOWN; 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. // Files/dirs names starting by "." are not visible files under unices.
// Skip them also under Windows // Skip them also under Windows
@ -349,9 +343,9 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
// This is an ugly fix. // This is an ugly fix.
if( fn.GetExt() == "sch" || fn.GetExt() == "kicad_sch" ) if( fn.GetExt() == "sch" || fn.GetExt() == "kicad_sch" )
{ {
wxString fullFileName = aName.BeforeLast( '.' ); wxString fullFileName = aName.BeforeLast( '.' );
wxString rootName; wxString rootName;
TREEPROJECT_ITEM* itemData = GetItemIdData( m_root ); PROJECT_TREE_ITEM* itemData = GetItemIdData( m_root );
if( itemData ) if( itemData )
rootName = itemData->GetFileName().BeforeLast( '.' ); rootName = itemData->GetFileName().BeforeLast( '.' );
@ -413,11 +407,12 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
if( ext == wxT( "" ) ) if( ext == wxT( "" ) )
continue; continue;
if( i == static_cast<int>( TREE_FILE_TYPE::GERBER ) ) // For gerber files, the official ext is gbr // For gerber files, the official ext is gbr
if( i == static_cast<int>( TREE_FILE_TYPE::GERBER ) )
ext = "gbr"; ext = "gbr";
reg.Compile( wxString::FromAscii( "^.*\\." ) + ext + reg.Compile( wxString::FromAscii( "^.*\\." ) + ext + wxString::FromAscii( "$" ),
wxString::FromAscii( "$" ), wxRE_ICASE ); wxRE_ICASE );
if( reg.Matches( aName ) ) if( reg.Matches( aName ) )
{ {
@ -434,7 +429,9 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
// Ignore legacy projects with the same name as the current project // Ignore legacy projects with the same name as the current project
if( ( type == TREE_FILE_TYPE::LEGACY_PROJECT ) if( ( type == TREE_FILE_TYPE::LEGACY_PROJECT )
&& ( currfile.GetName().CmpNoCase( project.GetName() ) == 0 ) ) && ( currfile.GetName().CmpNoCase( project.GetName() ) == 0 ) )
{
return newItemId; return newItemId;
}
// also check to see if it is already there. // also check to see if it is already there.
wxTreeItemIdValue cookie; wxTreeItemIdValue cookie;
@ -442,13 +439,10 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
while( kid.IsOk() ) while( kid.IsOk() )
{ {
TREEPROJECT_ITEM* itemData = GetItemIdData( kid ); PROJECT_TREE_ITEM* itemData = GetItemIdData( kid );
if( itemData ) if( itemData && itemData->GetFileName() == aName )
{ return itemData->GetId(); // well, we would have added it, but it is already here!
if( itemData->GetFileName() == aName )
return itemData->GetId(); // well, we would have added it, but it is already here!
}
kid = m_TreeProject->GetNextChild( aRoot, cookie ); kid = m_TreeProject->GetNextChild( aRoot, cookie );
} }
@ -460,7 +454,7 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
while( kid.IsOk() ) while( kid.IsOk() )
{ {
TREEPROJECT_ITEM* itemData = GetItemIdData( kid ); PROJECT_TREE_ITEM* itemData = GetItemIdData( kid );
if( itemData ) if( itemData )
{ {
@ -489,7 +483,7 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
// Append the item (only appending the filename not the full path): // Append the item (only appending the filename not the full path):
newItemId = m_TreeProject->AppendItem( aRoot, file ); 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 ); m_TreeProject->SetItemData( newItemId, data );
data->SetState( 0 ); data->SetState( 0 );
@ -523,7 +517,7 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
do // Add name in tree, but do not recurse do // Add name in tree, but do not recurse
{ {
wxString path = aName + wxFileName::GetPathSeparator() + dir_filename; wxString path = aName + wxFileName::GetPathSeparator() + dir_filename;
AddItemToTreeProject( path, newItemId, false, false ); AddItemToProjectTree( path, newItemId, false, false );
} while( dir.GetNext( &dir_filename ) ); } 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(); wxString pro_dir = m_Parent->GetProjectFileName();
if( !m_TreeProject ) if( !m_TreeProject )
m_TreeProject = new TREEPROJECTFILES( this ); m_TreeProject = new PROJECT_TREE( this );
else else
m_TreeProject->DeleteAllItems(); 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; return;
wxFileName fn = pro_dir; wxFileName fn = pro_dir;
@ -580,12 +574,12 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj()
// root tree: // root tree:
m_root = m_TreeProject->AddRoot( fn.GetFullName(), static_cast<int>( TREE_FILE_TYPE::ROOT ), m_root = m_TreeProject->AddRoot( fn.GetFullName(), static_cast<int>( TREE_FILE_TYPE::ROOT ),
static_cast<int>( TREE_FILE_TYPE::ROOT ) ); static_cast<int>( TREE_FILE_TYPE::ROOT ) );
m_TreeProject->SetItemBold( m_root, true ); m_TreeProject->SetItemBold( m_root, true );
// The main project file is now a JSON file // The main project file is now a JSON file
m_TreeProject->SetItemData( m_root, m_TreeProject->SetItemData( m_root, new PROJECT_TREE_ITEM( TREE_FILE_TYPE::JSON_PROJECT,
new TREEPROJECT_ITEM( TREE_FILE_TYPE::JSON_PROJECT, fn.GetFullPath(), m_TreeProject ) ); fn.GetFullPath(), m_TreeProject ) );
// Now adding all current files if available // Now adding all current files if available
if( prjOpened ) if( prjOpened )
@ -595,15 +589,15 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj()
if( dir.IsOpened() ) // protected dirs will not open, see "man opendir()" if( dir.IsOpened() ) // protected dirs will not open, see "man opendir()"
{ {
wxString filename; wxString filename;
bool cont = dir.GetFirst( &filename ); bool cont = dir.GetFirst( &filename );
while( cont ) while( cont )
{ {
if( filename != fn.GetFullName() ) if( filename != fn.GetFullName() )
{ {
wxString name = dir.GetName() + wxFileName::GetPathSeparator() + filename; wxString name = dir.GetName() + wxFileName::GetPathSeparator() + filename;
AddItemToTreeProject( name, m_root, false ); AddItemToProjectTree( name, m_root, false );
} }
cont = dir.GetNext( &filename ); 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) // Ensure item is selected (Under Windows right click does not select the item)
m_TreeProject->SelectItem( curr_item ); m_TreeProject->SelectItem( curr_item );
std::vector<TREEPROJECT_ITEM*> selection = GetSelectedData(); std::vector<PROJECT_TREE_ITEM*> selection = GetSelectedData();
bool can_switch_to_project = true; bool can_switch_to_project = true;
bool can_create_new_directory = true; bool can_create_new_directory = true;
@ -652,7 +646,7 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
can_print = false; can_print = false;
} }
for( TREEPROJECT_ITEM* item : selection ) for( PROJECT_TREE_ITEM* item : selection )
{ {
// Check for empty project // Check for empty project
if( !item ) if( !item )
@ -784,12 +778,17 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
else else
help_text = _( "Delete the files and their contents" ); 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 ) || can_rename )
{
popup_menu.AppendSeparator(); popup_menu.AppendSeparator();
}
AddMenuItem( AddMenuItem( &popup_menu, ID_PROJECT_DELETE, _( "Delete" ), help_text,
&popup_menu, ID_PROJECT_DELETE, _( "Delete" ), help_text, KiBitmap( delete_xpm ) ); KiBitmap( delete_xpm ) );
} }
if( can_print ) 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(); wxString editorname = Pgm().GetEditorName();
if( editorname.IsEmpty() ) if( editorname.IsEmpty() )
return; return;
std::vector<TREEPROJECT_ITEM*> tree_data = GetSelectedData(); std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
wxString files; wxString files;
for( TREEPROJECT_ITEM* item_data : tree_data ) for( PROJECT_TREE_ITEM* item_data : tree_data )
{ {
wxString fullFileName = item_data->GetFileName(); wxString fullFileName = item_data->GetFileName();
AddDelimiterString( fullFileName ); 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<TREEPROJECT_ITEM*> tree_data = GetSelectedData(); std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
wxString msg, caption; wxString msg, caption;
if( tree_data.size() == 1 ) if( tree_data.size() == 1 )
{ {
bool is_directory = wxDirExists( tree_data[0]->GetFileName() ); 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" ); caption = is_directory ? _( "Delete Directory" ) : _( "Delete File" );
msg = wxString::Format( _( "Are you sure you want to delete '%s'?" ),
tree_data[0]->GetFileName() );
} }
else else
{ {
msg = wxString::Format( msg = wxString::Format( _( "Are you sure you want to delete %lu items?" ),
_( "Are you sure you want to delete %lu items?" ), tree_data.size() ); tree_data.size() );
caption = _( "Delete Multiple Items" ); caption = _( "Delete Multiple Items" );
} }
@ -858,25 +857,25 @@ void TREE_PROJECT_FRAME::OnDeleteFile( wxCommandEvent& )
if( dialog.ShowModal() == wxID_YES ) if( dialog.ShowModal() == wxID_YES )
{ {
for( TREEPROJECT_ITEM* item_data : tree_data ) for( PROJECT_TREE_ITEM* item_data : tree_data )
item_data->Delete(); item_data->Delete();
} }
} }
void TREE_PROJECT_FRAME::OnPrintFile( wxCommandEvent& ) void PROJECT_TREE_PANE::OnPrintFile( wxCommandEvent& )
{ {
std::vector<TREEPROJECT_ITEM*> tree_data = GetSelectedData(); std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
for( TREEPROJECT_ITEM* item_data : tree_data ) for( PROJECT_TREE_ITEM* item_data : tree_data )
item_data->Print(); item_data->Print();
} }
void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& ) void PROJECT_TREE_PANE::OnRenameFile( wxCommandEvent& )
{ {
wxTreeItemId curr_item = m_TreeProject->GetFocusedItem(); wxTreeItemId curr_item = m_TreeProject->GetFocusedItem();
std::vector<TREEPROJECT_ITEM*> tree_data = GetSelectedData(); std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
// XXX: Unnecessary? // XXX: Unnecessary?
if( tree_data.size() != 1 ) 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<TREEPROJECT_ITEM*> tree_data = GetSelectedData(); std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
if( tree_data.size() != 1 ) if( tree_data.size() != 1 )
return; 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 // Idle executes once all other events finished processing
// This makes it ideal to launch a new window without starting Focus wars. // 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(); wxTreeItemId itemId = Event.GetItem();
TREEPROJECT_ITEM* tree_data = GetItemIdData( itemId ); PROJECT_TREE_ITEM* tree_data = GetItemIdData( itemId );
if( !tree_data ) if( !tree_data )
return; return;
@ -949,7 +948,7 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event )
for( ; kid.IsOk(); kid = m_TreeProject->GetNextChild( itemId, cookie ) ) 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 ) if( !itemData || itemData->GetType() != TREE_FILE_TYPE::DIRECTORY )
continue; continue;
@ -969,7 +968,7 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event )
do // Add name to tree item, but do not recurse in subdirs: do // Add name to tree item, but do not recurse in subdirs:
{ {
wxString name = fileName + wxFileName::GetPathSeparator() + dir_filename; wxString name = fileName + wxFileName::GetPathSeparator() + dir_filename;
AddItemToTreeProject( name, kid, false ); AddItemToProjectTree( name, kid, false );
} while( dir.GetNext( &dir_filename ) ); } while( dir.GetNext( &dir_filename ) );
} }
@ -990,10 +989,10 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event )
} }
std::vector<TREEPROJECT_ITEM*> TREE_PROJECT_FRAME::GetSelectedData() std::vector<PROJECT_TREE_ITEM*> PROJECT_TREE_PANE::GetSelectedData()
{ {
wxArrayTreeItemIds selection; wxArrayTreeItemIds selection;
std::vector<TREEPROJECT_ITEM*> data; std::vector<PROJECT_TREE_ITEM*> data;
m_TreeProject->GetSelections( selection ); m_TreeProject->GetSelections( selection );
@ -1004,13 +1003,13 @@ std::vector<TREEPROJECT_ITEM*> TREE_PROJECT_FRAME::GetSelectedData()
} }
TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetItemIdData( wxTreeItemId aId ) PROJECT_TREE_ITEM* PROJECT_TREE_PANE::GetItemIdData( wxTreeItemId aId )
{ {
return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( aId ) ); return dynamic_cast<PROJECT_TREE_ITEM*>( 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() ); 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 ) ) 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(); const wxFileName& pathModified = event.GetPath();
wxString subdir = pathModified.GetPath(); wxString subdir = pathModified.GetPath();
@ -1099,7 +1098,7 @@ void TREE_PROJECT_FRAME::OnFileSystemEvent( wxFileSystemWatcherEvent& event )
{ {
case wxFSW_EVENT_CREATE: 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 // 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 // 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: case wxFSW_EVENT_DELETE:
while( kid.IsOk() ) while( kid.IsOk() )
{ {
TREEPROJECT_ITEM* itemData = GetItemIdData( kid ); PROJECT_TREE_ITEM* itemData = GetItemIdData( kid );
if( itemData && itemData->GetFileName() == fn ) if( itemData && itemData->GetFileName() == fn )
{ {
@ -1134,7 +1133,7 @@ void TREE_PROJECT_FRAME::OnFileSystemEvent( wxFileSystemWatcherEvent& event )
while( kid.IsOk() ) while( kid.IsOk() )
{ {
TREEPROJECT_ITEM* itemData = GetItemIdData( kid ); PROJECT_TREE_ITEM* itemData = GetItemIdData( kid );
if( itemData && itemData->GetFileName() == fn ) 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 // 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, // 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. // 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() ) ) if( newpath.Exists() && ( newfn != rootData->GetFileName() ) )
{ {
wxTreeItemId newroot_id = findSubdirTreeItem( newdir ); wxTreeItemId newroot_id = findSubdirTreeItem( newdir );
wxTreeItemId newitem = AddItemToTreeProject( newfn, newroot_id ); wxTreeItemId newitem = AddItemToProjectTree( newfn, newroot_id );
// If the item exists, select it // If the item exists, select it
if( newitem.IsOk() ) 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: // Prepare file watcher:
if( m_watcher ) if( m_watcher )
@ -1220,7 +1219,9 @@ void TREE_PROJECT_FRAME::FileWatcherReset()
if( !kid.IsOk() ) if( !kid.IsOk() )
{ {
if( subdirs_id.empty() ) // all items were explored if( subdirs_id.empty() ) // all items were explored
{
break; break;
}
else else
{ {
root_id = subdirs_id.top(); 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 ) 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(); m_TreeProject->DeleteAllItems();
} }

View File

@ -23,7 +23,7 @@
*/ */
/** /**
* @file tree_project_frame.h * @file PROJECT_TREE_PANE.h
*/ */
@ -39,29 +39,30 @@
class KICAD_MANAGER_FRAME; class KICAD_MANAGER_FRAME;
class TREEPROJECT_ITEM; class PROJECT_TREE_ITEM;
class TREEPROJECTFILES; class PROJECT_TREE;
/** TREE_PROJECT_FRAME /** PROJECT_TREE_PANE
* Window to display the tree files * 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: public:
KICAD_MANAGER_FRAME* m_Parent; KICAD_MANAGER_FRAME* m_Parent;
TREEPROJECTFILES* m_TreeProject; PROJECT_TREE* m_TreeProject;
private: private:
bool m_isRenaming; // Are we in the process of renaming a file bool m_isRenaming; // Are we in the process of renaming a file
wxTreeItemId m_root; wxTreeItemId m_root;
std::vector<wxString> m_filters; std::vector<wxString> m_filters;
wxFileSystemWatcher* m_watcher; // file system watcher wxFileSystemWatcher* m_watcher; // file system watcher
TREEPROJECT_ITEM* m_selectedItem; PROJECT_TREE_ITEM* m_selectedItem;
public: public:
TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ); PROJECT_TREE_PANE( KICAD_MANAGER_FRAME* parent );
~TREE_PROJECT_FRAME(); ~PROJECT_TREE_PANE();
/** /**
* Create or modify the tree showing project file names * Create or modify the tree showing project file names
@ -90,15 +91,15 @@ protected:
* Note this is not necessary the "clicked" item, * Note this is not necessary the "clicked" item,
* because when expanding, collapsing an item this item is not selected * because when expanding, collapsing an item this item is not selected
*/ */
std::vector<TREEPROJECT_ITEM*> GetSelectedData(); std::vector<PROJECT_TREE_ITEM*> GetSelectedData();
/** /**
* Function GetItemIdData * Function GetItemIdData
* return the item data corresponding to a wxTreeItemId identifier * return the item data corresponding to a wxTreeItemId identifier
* @param aId = the 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: private:
/** /**
@ -166,7 +167,7 @@ private:
void OnIdle( wxIdleEvent &aEvent ); void OnIdle( wxIdleEvent &aEvent );
/** /**
* Function AddItemToTreeProject * Function AddItemToProjectTree
* @brief Add the file or directory aName to the project tree * @brief Add the file or directory aName to the project tree
* @param aName = the filename or the directory name to add in tree * @param aName = the filename or the directory name to add in tree
* @param aRoot = the wxTreeItemId item where to add sub tree items * @param aRoot = the wxTreeItemId item where to add sub tree items
@ -175,8 +176,8 @@ private:
* false to stop file add. * false to stop file add.
* @return the Id for the new tree item * @return the Id for the new tree item
*/ */
wxTreeItemId AddItemToTreeProject( const wxString& aName, wxTreeItemId& aRoot, wxTreeItemId AddItemToProjectTree( const wxString& aName, wxTreeItemId& aRoot,
bool aCanResetFileWatcher = true, bool aRecurse = true ); bool aCanResetFileWatcher = true, bool aRecurse = true );
/** /**
* Function findSubdirTreeItem * Function findSubdirTreeItem

View File

@ -21,10 +21,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
/**
* @file tree_file_types.h
*/
#ifndef TREE_FILE_TYPE_H #ifndef TREE_FILE_TYPE_H
#define TREE_FILE_TYPE_H #define TREE_FILE_TYPE_H
@ -32,7 +28,7 @@
// Identify the type of files handled by KiCad manager // Identify the type of files handled by KiCad manager
// //
// When changing this enum please verify (and perhaps update) // When changing this enum please verify (and perhaps update)
// TREE_PROJECT_FRAME::GetFileExt(), // PROJECT_TREE_PANE::GetFileExt(),
// s_AllowedExtensionsToList[] // s_AllowedExtensionsToList[]
enum class TREE_FILE_TYPE enum class TREE_FILE_TYPE
{ {

View File

@ -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 <bitmaps.h>
#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<int>( 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() );
}