2012-08-29 12:40:09 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2019-06-20 19:18:43 +00:00
|
|
|
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-08-29 12:40:09 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2016-02-24 21:36:52 +00:00
|
|
|
/**
|
|
|
|
* @file tree_project_frame.cpp
|
|
|
|
* @brief Function to build the tree of files in the current project directory
|
|
|
|
*/
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2016-02-24 21:36:52 +00:00
|
|
|
|
|
|
|
#include <stack>
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <wx/regex.h>
|
2015-09-25 19:38:09 +00:00
|
|
|
#include <wx/stdpaths.h>
|
2016-02-24 21:36:52 +00:00
|
|
|
#include <wx/string.h>
|
|
|
|
|
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <gestfich.h>
|
2012-04-09 09:16:47 +00:00
|
|
|
#include <menus_helpers.h>
|
2018-10-17 19:03:33 +00:00
|
|
|
#include <trace_helpers.h>
|
2016-02-24 21:36:52 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
|
|
|
|
2018-02-07 13:16:05 +00:00
|
|
|
#include "treeproject_item.h"
|
|
|
|
#include "treeprojectfiles.h"
|
2016-02-24 21:36:52 +00:00
|
|
|
#include "pgm_kicad.h"
|
2019-05-25 19:39:42 +00:00
|
|
|
#include "kicad_id.h"
|
2016-02-24 21:36:52 +00:00
|
|
|
|
|
|
|
#include "tree_project_frame.h"
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
/* Note about the tree project build process:
|
2010-02-17 17:47:12 +00:00
|
|
|
* Building the tree project can be *very* long if there are a lot of subdirectories
|
|
|
|
* in the working directory.
|
2010-05-29 18:34:18 +00:00
|
|
|
* Unfortunately, this happens easily if the project file *.pro is in the home directory
|
2010-02-20 13:20:55 +00:00
|
|
|
* 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.
|
2010-02-17 17:47:12 +00:00
|
|
|
*/
|
|
|
|
|
2008-05-30 18:06:21 +00:00
|
|
|
// list of files extensions listed in the tree project window
|
2009-02-04 15:25:03 +00:00
|
|
|
// *.sch files are always allowed, do not add here
|
2008-05-30 18:06:21 +00:00
|
|
|
// Add extensions in a compatible regex format to see others files types
|
2012-08-29 12:40:09 +00:00
|
|
|
static const wxChar* s_allowedExtensionsToList[] =
|
2008-05-30 18:06:21 +00:00
|
|
|
{
|
|
|
|
wxT( "^.*\\.pro$" ),
|
|
|
|
wxT( "^.*\\.pdf$" ),
|
2012-04-16 12:56:01 +00:00
|
|
|
wxT( "^[^$].*\\.brd$" ), // Legacy Pcbnew files
|
2014-10-21 16:34:51 +00:00
|
|
|
wxT( "^[^$].*\\.kicad_pcb$" ), // S format Pcbnew board files
|
2013-07-19 18:27:22 +00:00
|
|
|
wxT( "^[^$].*\\.kicad_wks$" ), // S format kicad page layout descr files
|
2014-10-21 16:34:51 +00:00
|
|
|
wxT( "^[^$].*\\.kicad_mod$" ), // S format kicad footprint files, currently not listed
|
2016-09-17 07:34:16 +00:00
|
|
|
wxT( "^.*\\.net$" ), // pcbnew netlist file
|
|
|
|
wxT( "^.*\\.cir$" ), // Spice netlist file
|
2014-10-21 16:34:51 +00:00
|
|
|
wxT( "^.*\\.lib$" ), // Schematic library file
|
2008-05-30 18:06:21 +00:00
|
|
|
wxT( "^.*\\.txt$" ),
|
2014-06-30 10:00:21 +00:00
|
|
|
wxT( "^.*\\.pho$" ), // Gerber file (Old Kicad extension)
|
2011-08-19 13:08:24 +00:00
|
|
|
wxT( "^.*\\.gbr$" ), // Gerber file
|
2017-09-08 18:32:32 +00:00
|
|
|
wxT( "^.*\\.gbrjob$" ), // Gerber job file
|
2017-08-19 16:28:11 +00:00
|
|
|
wxT( "^.*\\.gb[alops]$" ), // Gerber back (or bottom) layer file (deprecated Protel ext)
|
|
|
|
wxT( "^.*\\.gt[alops]$" ), // Gerber front (or top) layer file (deprecated Protel ext)
|
|
|
|
wxT( "^.*\\.g[0-9]{1,2}$" ), // Gerber inner layer file (deprecated Protel ext)
|
2008-05-30 18:06:21 +00:00
|
|
|
wxT( "^.*\\.odt$" ),
|
|
|
|
wxT( "^.*\\.htm$" ),
|
|
|
|
wxT( "^.*\\.html$" ),
|
2015-02-28 19:00:48 +00:00
|
|
|
wxT( "^.*\\.rpt$" ), // Report files
|
|
|
|
wxT( "^.*\\.csv$" ), // Report files in comma separated format
|
|
|
|
wxT( "^.*\\.pos$" ), // Footprint position files
|
|
|
|
wxT( "^.*\\.cmp$" ), // Cvpcb cmp/footprint link files
|
|
|
|
wxT( "^.*\\.drl$" ), // Excellon drill files
|
2019-03-27 15:46:51 +00:00
|
|
|
wxT( "^.*\\.nc$" ), // Excellon NC drill files (alternate file ext)
|
|
|
|
wxT( "^.*\\.xnc$" ), // Excellon NC drill files (alternate file ext)
|
2015-02-28 19:00:48 +00:00
|
|
|
wxT( "^.*\\.svg$" ), // SVG print/plot files
|
2019-08-28 16:01:06 +00:00
|
|
|
wxT( "^.*\\.ps$" ), // Postscript plot files
|
2015-02-28 19:00:48 +00:00
|
|
|
NULL // end of list
|
2008-05-30 18:06:21 +00:00
|
|
|
};
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* TODO: Check if these file extension and wildcard definitions are used
|
2011-09-30 18:15:37 +00:00
|
|
|
* in any of the other KiCad programs and move them into the common
|
2012-08-29 12:40:09 +00:00
|
|
|
* library as required.
|
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2014-07-07 19:49:14 +00:00
|
|
|
// File extension definitions.
|
2014-04-14 18:49:52 +00:00
|
|
|
const wxChar TextFileExtension[] = wxT( "txt" );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2017-08-19 16:28:11 +00:00
|
|
|
// Gerber file extension wildcard.
|
2017-09-08 18:32:32 +00:00
|
|
|
const wxString GerberFileExtensionWildCard( ".((gbr|gbrjob|(gb|gt)[alops])|pho)" );
|
2017-08-19 16:28:11 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
/**
|
2019-07-17 10:57:12 +00:00
|
|
|
* @brief class TREE_PROJECT_FRAME is the frame that shows the tree list of files and subdirs
|
|
|
|
* inside the working directory. Files are filtered (see s_allowedExtensionsToList) so
|
2010-02-20 13:20:55 +00:00
|
|
|
* only useful files are shown.
|
2008-11-02 14:54:53 +00:00
|
|
|
*/
|
2010-02-20 13:20:55 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
BEGIN_EVENT_TABLE( TREE_PROJECT_FRAME, wxSashLayoutWindow )
|
2015-02-28 19:00:48 +00:00
|
|
|
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 )
|
2018-06-21 15:05:08 +00:00
|
|
|
EVT_MENU( ID_PROJECT_SWITCH_TO_OTHER, TREE_PROJECT_FRAME::OnSwitchToSelectedProject )
|
2015-02-28 19:00:48 +00:00
|
|
|
EVT_MENU( ID_PROJECT_NEWDIR, TREE_PROJECT_FRAME::OnCreateNewDirectory )
|
2019-06-17 13:25:49 +00:00
|
|
|
EVT_MENU( ID_PROJECT_OPEN_DIR, TREE_PROJECT_FRAME::OnOpenDirectory )
|
2015-02-28 19:00:48 +00:00
|
|
|
EVT_MENU( ID_PROJECT_DELETE, TREE_PROJECT_FRAME::OnDeleteFile )
|
2019-08-28 16:01:06 +00:00
|
|
|
EVT_MENU( ID_PROJECT_PRINT, TREE_PROJECT_FRAME::OnPrintFile )
|
2015-02-28 19:00:48 +00:00
|
|
|
EVT_MENU( ID_PROJECT_RENAME, TREE_PROJECT_FRAME::OnRenameFile )
|
2010-02-20 13:20:55 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2011-04-17 13:54:17 +00:00
|
|
|
TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ) :
|
2019-07-17 10:57:12 +00:00
|
|
|
wxSashLayoutWindow( parent, ID_LEFT_FRAME, wxDefaultPosition, wxDefaultSize,
|
2017-02-20 11:41:23 +00:00
|
|
|
wxNO_BORDER | wxTAB_TRAVERSAL )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
m_Parent = parent;
|
|
|
|
m_TreeProject = NULL;
|
2014-07-07 19:49:14 +00:00
|
|
|
|
2013-01-01 14:06:49 +00:00
|
|
|
m_watcher = NULL;
|
2012-12-31 08:12:29 +00:00
|
|
|
Connect( wxEVT_FSWATCHER,
|
|
|
|
wxFileSystemWatcherEventHandler( TREE_PROJECT_FRAME::OnFileSystemEvent ) );
|
2014-07-07 19:49:14 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
/*
|
|
|
|
* Filtering is now inverted: the filters are actually used to _enable_ support
|
|
|
|
* for a given file type.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// NOTE: sch filter must be first because of a test in AddFile() below
|
2019-07-17 10:57:12 +00:00
|
|
|
m_filters.emplace_back( wxT( "^.*\\.sch$" ) );
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2012-08-29 12:40:09 +00:00
|
|
|
for( int ii = 0; s_allowedExtensionsToList[ii] != NULL; ii++ )
|
2019-07-17 10:57:12 +00:00
|
|
|
m_filters.emplace_back( s_allowedExtensionsToList[ii] );
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2019-07-17 10:57:12 +00:00
|
|
|
m_filters.emplace_back( wxT( "^no KiCad files found" ) );
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
ReCreateTreePrj();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2011-09-08 05:58:45 +00:00
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
TREE_PROJECT_FRAME::~TREE_PROJECT_FRAME()
|
2009-05-21 17:42:42 +00:00
|
|
|
{
|
2016-06-16 12:38:31 +00:00
|
|
|
if( m_watcher )
|
|
|
|
{
|
|
|
|
m_watcher->RemoveAll();
|
|
|
|
m_watcher->SetOwner( NULL );
|
|
|
|
delete m_watcher;
|
|
|
|
}
|
2009-05-21 17:42:42 +00:00
|
|
|
}
|
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2018-06-21 15:05:08 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnSwitchToSelectedProject( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
|
|
|
|
|
|
|
if( !tree_data )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxString prj_filename = tree_data->GetFileName();
|
|
|
|
|
|
|
|
m_Parent->LoadProject( prj_filename );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-17 13:25:49 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnOpenDirectory( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
// Get the root directory name:
|
|
|
|
TREEPROJECT_ITEM* treeData = GetSelectedData();
|
|
|
|
|
|
|
|
if( !treeData )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Ask for the new sub directory name
|
|
|
|
wxString curr_dir = treeData->GetDir();
|
|
|
|
|
2019-06-20 19:18:43 +00:00
|
|
|
if( curr_dir.IsEmpty() )
|
2019-06-17 13:25:49 +00:00
|
|
|
{
|
2019-06-20 19:18:43 +00:00
|
|
|
// Use project path if the tree view path was empty.
|
|
|
|
curr_dir = wxPathOnly( m_Parent->GetProjectFileName() );
|
|
|
|
|
|
|
|
// As a last resort use the user's documents folder.
|
|
|
|
if( curr_dir.IsEmpty() || !wxFileName::DirExists( curr_dir ) )
|
|
|
|
curr_dir = wxStandardPaths::Get().GetDocumentsDir();
|
2019-06-17 13:25:49 +00:00
|
|
|
|
|
|
|
if( !curr_dir.IsEmpty() )
|
|
|
|
curr_dir += wxFileName::GetPathSeparator();
|
|
|
|
}
|
|
|
|
|
2019-07-17 10:57:12 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
// Quote in case there are spaces in the path.
|
|
|
|
msg.Printf( "open \"%s\"", curr_dir );
|
|
|
|
|
|
|
|
system( msg.c_str() );
|
|
|
|
#else
|
2019-06-17 13:25:49 +00:00
|
|
|
// Quote in case there are spaces in the path.
|
|
|
|
AddDelimiterString( curr_dir );
|
|
|
|
|
|
|
|
wxLaunchDefaultApplication( curr_dir );
|
2019-07-17 10:57:12 +00:00
|
|
|
#endif
|
2019-06-17 13:25:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-16 12:56:01 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnCreateNewDirectory( wxCommandEvent& event )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2012-04-16 12:56:01 +00:00
|
|
|
// Get the root directory name:
|
|
|
|
TREEPROJECT_ITEM* treeData = GetSelectedData();
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( !treeData )
|
|
|
|
return;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2014-10-21 16:34:51 +00:00
|
|
|
wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
|
|
|
|
|
2012-04-16 12:56:01 +00:00
|
|
|
// Ask for the new sub directory name
|
|
|
|
wxString curr_dir = treeData->GetDir();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
if( !curr_dir.IsEmpty() ) // A subdir is selected
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2014-10-21 16:34:51 +00:00
|
|
|
// Make this subdir name relative to the current path.
|
|
|
|
// It will be more easy to read by the user, in the next dialog
|
|
|
|
wxFileName fn;
|
|
|
|
fn.AssignDir( curr_dir );
|
|
|
|
fn.MakeRelativeTo( prj_dir );
|
|
|
|
curr_dir = fn.GetPath();
|
|
|
|
|
|
|
|
if( !curr_dir.IsEmpty() )
|
|
|
|
curr_dir += wxFileName::GetPathSeparator();
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2019-07-17 10:57:12 +00:00
|
|
|
wxString msg = wxString::Format( _( "Current project directory:\n%s" ), GetChars( prj_dir ) );
|
|
|
|
wxString subdir = wxGetTextFromUser( msg, _( "Create New Directory" ), curr_dir );
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2012-04-16 12:56:01 +00:00
|
|
|
if( subdir.IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
2014-10-21 16:34:51 +00:00
|
|
|
wxString full_dirname = prj_dir + wxFileName::GetPathSeparator() + subdir;
|
|
|
|
|
|
|
|
if( wxMkdir( full_dirname ) )
|
2013-01-03 19:25:12 +00:00
|
|
|
{
|
2019-06-20 19:18:43 +00:00
|
|
|
// the new item will be added by the file watcher
|
2015-07-29 18:06:45 +00:00
|
|
|
// AddItemToTreeProject( subdir, root );
|
2013-01-03 19:25:12 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
wxString TREE_PROJECT_FRAME::GetFileExt( TreeFileType type )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
switch( type )
|
|
|
|
{
|
2019-07-17 10:57:12 +00:00
|
|
|
case TREE_PROJECT: return ProjectFileExtension;
|
|
|
|
case TREE_SCHEMA: return SchematicFileExtension;
|
|
|
|
case TREE_LEGACY_PCB: return LegacyPcbFileExtension;
|
|
|
|
case TREE_SEXP_PCB: return KiCadPcbFileExtension;
|
|
|
|
case TREE_GERBER: return GerberFileExtensionWildCard;
|
|
|
|
case TREE_HTML: return HtmlFileExtension;
|
|
|
|
case TREE_PDF: return PdfFileExtension;
|
|
|
|
case TREE_TXT: return TextFileExtension;
|
|
|
|
case TREE_NET: return NetlistFileExtension;
|
|
|
|
case TREE_CMP_LINK: return ComponentFileExtension;
|
|
|
|
case TREE_REPORT: return ReportFileExtension;
|
|
|
|
case TREE_FP_PLACE: return FootprintPlaceFileExtension;
|
|
|
|
case TREE_DRILL: return DrillFileExtension;
|
|
|
|
case TREE_DRILL_NC: return "nc";
|
|
|
|
case TREE_DRILL_XNC: return "xnc";
|
|
|
|
case TREE_SVG: return SVGFileExtension;
|
|
|
|
case TREE_PAGE_LAYOUT_DESCR: return PageLayoutDescrFileExtension;
|
|
|
|
case TREE_FOOTPRINT_FILE: return KiCadFootprintFileExtension;
|
|
|
|
case TREE_SCHEMATIC_LIBFILE: return SchematicLibraryFileExtension;
|
|
|
|
default: return wxEmptyString;
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName,
|
2019-07-17 10:57:12 +00:00
|
|
|
wxTreeItemId& aRoot, bool aRecurse )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-12-31 08:12:29 +00:00
|
|
|
wxTreeItemId cellule;
|
|
|
|
TreeFileType type = TREE_UNKNOWN;
|
|
|
|
wxFileName fn( aName );
|
|
|
|
|
2010-02-17 17:47:12 +00:00
|
|
|
// Files/dirs names starting by "." are not visible files under unices.
|
|
|
|
// Skip them also under Windows
|
2012-12-31 08:12:29 +00:00
|
|
|
if( fn.GetName().StartsWith( wxT( "." ) ) )
|
2010-02-17 17:47:12 +00:00
|
|
|
return false;
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
if( wxDirExists( aName ) )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
type = TREE_DIRECTORY;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
// Filter
|
2009-02-04 15:25:03 +00:00
|
|
|
wxRegEx reg;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
bool isSchematic = false;
|
|
|
|
bool addFile = false;
|
2012-12-31 08:12:29 +00:00
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_filters.size(); i++ )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-12-31 08:12:29 +00:00
|
|
|
wxCHECK2_MSG( reg.Compile( m_filters[i], wxRE_ICASE ), continue,
|
2019-08-28 16:01:06 +00:00
|
|
|
wxString::Format( "Regex %s failed to compile.", m_filters[i] ) );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
if( reg.Matches( aName ) )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
addFile = true;
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2019-08-28 16:01:06 +00:00
|
|
|
if( i == 0 )
|
2007-09-13 11:55:46 +00:00
|
|
|
isSchematic = true;
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2009-10-26 21:25:23 +00:00
|
|
|
break;
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !addFile )
|
modified the treeprj so that, instead of recursively scanning and adding
*all* the nested files and directories within the current working directory, it scans the first
level of files and directories. When a user double-clicks on a folder, *then*
the childeren of that directory are added to the wxTreeCtrl. This means that the little
triangle does not appear until the user opens a directory .. but, i think this is
a worthwile price to pay given below.
This prevents (or at least mitigates) memory overflow in the case that kicad starts in root, or,
in my case, it starts in my home directory, where thanks to wine & other sw,
there are far too many directories.
also modified the TreePrjItemData so that it stores the full pathnames in m_FileName,
not paths relative to the CWD. I'm not sure if this is the correct thing to do,
especially with the python interface, so change it back if it is more complicated.
the move and rename commands threw a segfault on my system
(Debian etch, wxWidgets 2.8.7),
and since there are better ways to rename and move files, this functionality
was disabled until somebody can fix it (alas, I don't have time for this now)
2007-12-16 18:44:12 +00:00
|
|
|
return false;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
// only show the schematic if it is a top level schematic. Eeschema
|
2007-09-13 11:55:46 +00:00
|
|
|
// cannot open a schematic and display it properly unless it starts
|
|
|
|
// at the top of the hierarchy. The schematic is top level only if
|
|
|
|
// there is a line in the header saying:
|
|
|
|
// "Sheet 1 "
|
2013-01-03 19:25:12 +00:00
|
|
|
// However if the file has the same name as the project, it is always
|
|
|
|
// shown, because it is expected the root sheet.
|
|
|
|
// (and to fix an issue (under XP but could exist under other OS),
|
|
|
|
// when a .sch file is created, the file
|
|
|
|
// create is sent to the wxFileSystemWatcher, but the file still has 0 byte
|
|
|
|
// so it cannot detected as root sheet
|
|
|
|
// This is an ugly fix.
|
2007-09-13 11:55:46 +00:00
|
|
|
if( isSchematic )
|
|
|
|
{
|
2019-07-17 10:57:12 +00:00
|
|
|
wxString fullFileName = aName.BeforeLast( '.' );
|
|
|
|
wxString rootName;
|
2013-01-03 19:25:12 +00:00
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( m_root );
|
2018-10-17 19:03:33 +00:00
|
|
|
|
2013-01-03 19:25:12 +00:00
|
|
|
if( itemData )
|
2014-07-07 19:49:14 +00:00
|
|
|
rootName = itemData->GetFileName().BeforeLast( '.' );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2013-01-03 19:25:12 +00:00
|
|
|
if( fullFileName != rootName )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2013-01-03 19:25:12 +00:00
|
|
|
char line[128]; // small because we just need a few bytes from the start of a line
|
|
|
|
FILE* fp;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2013-01-03 19:25:12 +00:00
|
|
|
fullFileName = aName;
|
|
|
|
fp = wxFopen( fullFileName, wxT( "rt" ) );
|
2009-10-26 21:25:23 +00:00
|
|
|
|
2013-01-03 19:25:12 +00:00
|
|
|
if( fp == NULL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
addFile = false;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2013-01-03 19:25:12 +00:00
|
|
|
// check the first 100 lines for the "Sheet 1" string
|
|
|
|
for( int i = 0; i<100; ++i )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2013-01-03 19:25:12 +00:00
|
|
|
if( !fgets( line, sizeof(line), fp ) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( !strncmp( line, "Sheet 1 ", 8 ) )
|
|
|
|
{
|
|
|
|
addFile = true;
|
|
|
|
break;
|
|
|
|
}
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
|
|
|
|
2013-01-03 19:25:12 +00:00
|
|
|
fclose( fp );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2013-01-03 19:25:12 +00:00
|
|
|
if( !addFile )
|
|
|
|
return false; // it is a non-top-level schematic
|
|
|
|
}
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
for( int i = TREE_PROJECT; i < TREE_MAX; i++ )
|
|
|
|
{
|
|
|
|
wxString ext = GetFileExt( (TreeFileType) i );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( ext == wxT( "" ) )
|
|
|
|
continue;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
reg.Compile( wxString::FromAscii( "^.*\\" ) + ext +
|
|
|
|
wxString::FromAscii( "$" ), wxRE_ICASE );
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
if( reg.Matches( aName ) )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
type = (TreeFileType) i;
|
2007-05-28 18:09:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
// also check to see if it is already there.
|
|
|
|
wxTreeItemIdValue cookie;
|
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( aRoot, cookie );
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
while( kid.IsOk() )
|
|
|
|
{
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( itemData )
|
|
|
|
{
|
2014-07-07 19:49:14 +00:00
|
|
|
if( itemData->GetFileName() == aName )
|
2012-12-31 08:12:29 +00:00
|
|
|
return true; // well, we would have added it, but it is already here!
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
kid = m_TreeProject->GetNextChild( aRoot, cookie );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
// Append the item (only appending the filename not the full path):
|
2012-12-31 08:12:29 +00:00
|
|
|
wxString file = wxFileNameFromPath( aName );
|
2010-02-20 13:20:55 +00:00
|
|
|
cellule = m_TreeProject->AppendItem( aRoot, file );
|
2012-12-31 08:12:29 +00:00
|
|
|
TREEPROJECT_ITEM* data = new TREEPROJECT_ITEM( type, aName, m_TreeProject );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
m_TreeProject->SetItemData( cellule, data );
|
|
|
|
data->SetState( 0 );
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// Mark root files (files which have the same aName as the project)
|
2014-07-07 19:49:14 +00:00
|
|
|
wxFileName project( m_Parent->GetProjectFileName() );
|
2012-12-31 08:12:29 +00:00
|
|
|
wxFileName currfile( file );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
if( currfile.GetName().CmpNoCase( project.GetName() ) == 0 )
|
2014-07-07 19:49:14 +00:00
|
|
|
data->SetRootFile( true );
|
2007-09-13 11:55:46 +00:00
|
|
|
else
|
2014-07-07 19:49:14 +00:00
|
|
|
data->SetRootFile( false );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
// This section adds dirs and files found in the subdirs
|
|
|
|
// in this case AddFile is recursive, but for the first level only.
|
|
|
|
if( TREE_DIRECTORY == type && aRecurse )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
wxDir dir( aName );
|
2012-12-31 08:12:29 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( dir.IsOpened() ) // protected dirs will not open properly.
|
2008-05-16 11:38:35 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
wxString dir_filename;
|
|
|
|
|
|
|
|
data->SetPopulated( true );
|
|
|
|
|
|
|
|
if( dir.GetFirst( &dir_filename ) )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
do // Add name in tree, but do not recurse
|
|
|
|
{
|
2014-10-21 16:34:51 +00:00
|
|
|
wxString path = aName + wxFileName::GetPathSeparator() + dir_filename;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
AddItemToTreeProject( path, cellule, false );
|
|
|
|
} while( dir.GetNext( &dir_filename ) );
|
|
|
|
}
|
2008-05-16 11:38:35 +00:00
|
|
|
}
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// Sort filenames by alphabetic order
|
2008-05-16 11:38:35 +00:00
|
|
|
m_TreeProject->SortChildren( cellule );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
return true;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::ReCreateTreePrj()
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2019-07-17 10:57:12 +00:00
|
|
|
wxString pro_dir = m_Parent->GetProjectFileName();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !m_TreeProject )
|
2010-02-19 15:01:32 +00:00
|
|
|
m_TreeProject = new TREEPROJECTFILES( this );
|
2007-09-13 11:55:46 +00:00
|
|
|
else
|
|
|
|
m_TreeProject->DeleteAllItems();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( !pro_dir ) // This is empty from TREE_PROJECT_FRAME constructor
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxFileName fn = pro_dir;
|
2014-07-07 19:49:14 +00:00
|
|
|
|
|
|
|
if( !fn.IsOk() )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
fn.Clear();
|
2015-09-25 19:38:09 +00:00
|
|
|
fn.SetPath( wxStandardPaths::Get().GetDocumentsDir() );
|
2010-02-24 15:33:03 +00:00
|
|
|
fn.SetName( NAMELESS_PROJECT );
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetExt( ProjectFileExtension );
|
|
|
|
}
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2019-07-17 10:57:12 +00:00
|
|
|
bool prjOpened = fn.FileExists();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
// root tree:
|
2019-07-17 10:57:12 +00:00
|
|
|
m_root = m_TreeProject->AddRoot( fn.GetFullName(), TREE_ROOT, TREE_ROOT );
|
|
|
|
m_TreeProject->SetItemBold( m_root, true );
|
|
|
|
m_TreeProject->SetItemData( m_root, new TREEPROJECT_ITEM( TREE_PROJECT, fn.GetFullPath(),
|
|
|
|
m_TreeProject ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
// Now adding all current files if available
|
|
|
|
if( prjOpened )
|
|
|
|
{
|
2016-04-12 15:50:42 +00:00
|
|
|
pro_dir = wxPathOnly( m_Parent->GetProjectFileName() );
|
|
|
|
wxDir dir( pro_dir );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( dir.IsOpened() ) // protected dirs will not open, see "man opendir()"
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
wxString filename;
|
|
|
|
bool cont = dir.GetFirst( &filename );
|
|
|
|
|
|
|
|
while( cont )
|
|
|
|
{
|
|
|
|
if( filename != fn.GetFullName() )
|
|
|
|
{
|
2014-10-21 16:34:51 +00:00
|
|
|
wxString name = dir.GetName() + wxFileName::GetPathSeparator() + filename;
|
|
|
|
AddItemToTreeProject( name, m_root );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
}
|
2009-10-26 21:25:23 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
cont = dir.GetNext( &filename );
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
2012-12-31 08:12:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_TreeProject->AppendItem( m_root, wxT( "Empty project" ) );
|
|
|
|
}
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2019-07-17 10:57:12 +00:00
|
|
|
m_TreeProject->Expand( m_root );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2014-07-07 19:49:14 +00:00
|
|
|
// Sort filenames by alphabetic order
|
2007-09-13 11:55:46 +00:00
|
|
|
m_TreeProject->SortChildren( m_root );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-12-31 08:12:29 +00:00
|
|
|
int tree_id;
|
|
|
|
TREEPROJECT_ITEM* tree_data;
|
2014-07-09 00:52:46 +00:00
|
|
|
wxString fullFileName;
|
2012-12-31 08:12:29 +00:00
|
|
|
wxTreeItemId curr_item = Event.GetItem();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2014-07-07 19:49:14 +00:00
|
|
|
// Ensure item is selected (Under Windows right click does not select the item)
|
2007-09-13 11:55:46 +00:00
|
|
|
m_TreeProject->SelectItem( curr_item );
|
|
|
|
|
|
|
|
tree_data = GetSelectedData();
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !tree_data )
|
|
|
|
return;
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
tree_id = tree_data->GetType();
|
2014-07-09 00:52:46 +00:00
|
|
|
fullFileName = tree_data->GetFileName();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2013-01-03 19:25:12 +00:00
|
|
|
wxMenu popupMenu;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2013-01-03 19:25:12 +00:00
|
|
|
switch( tree_id )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2018-10-17 19:03:33 +00:00
|
|
|
case TREE_PROJECT:
|
|
|
|
// Add a swith to an other project option only if the selected item
|
|
|
|
// is not the root item (current project)
|
|
|
|
if( curr_item != m_TreeProject->GetRootItem() )
|
|
|
|
{
|
|
|
|
AddMenuItem( &popupMenu, ID_PROJECT_SWITCH_TO_OTHER,
|
|
|
|
_( "&Switch to this Project" ),
|
|
|
|
_( "Close all editors, and switch to the selected project" ),
|
|
|
|
KiBitmap( open_project_xpm ) );
|
|
|
|
popupMenu.AppendSeparator();
|
|
|
|
}
|
|
|
|
|
|
|
|
AddMenuItem( &popupMenu, ID_PROJECT_NEWDIR,
|
|
|
|
_( "New D&irectory..." ),
|
|
|
|
_( "Create a New Directory" ),
|
|
|
|
KiBitmap( directory_xpm ) );
|
2019-06-17 13:25:49 +00:00
|
|
|
|
|
|
|
AddMenuItem( &popupMenu, ID_PROJECT_OPEN_DIR,
|
2019-07-17 10:57:12 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
_( "Reveal in Finder" ),
|
|
|
|
_( "Reveals the directory in a Finder window" ),
|
|
|
|
#else
|
|
|
|
_( "&Open Directory in File Explorer" ),
|
2019-06-17 13:25:49 +00:00
|
|
|
_( "Opens the directory in the default system file manager" ),
|
2019-07-17 10:57:12 +00:00
|
|
|
#endif
|
2019-06-17 13:25:49 +00:00
|
|
|
KiBitmap( directory_browser_xpm ) );
|
2018-10-17 19:03:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_DIRECTORY:
|
|
|
|
AddMenuItem( &popupMenu, ID_PROJECT_NEWDIR,
|
|
|
|
_( "New D&irectory..." ),
|
|
|
|
_( "Create a New Directory" ),
|
|
|
|
KiBitmap( directory_xpm ) );
|
2019-06-17 13:25:49 +00:00
|
|
|
AddMenuItem( &popupMenu, ID_PROJECT_OPEN_DIR,
|
2019-07-17 10:57:12 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
_( "Reveal in Finder" ),
|
|
|
|
_( "Reveals the directory in a Finder window" ),
|
|
|
|
#else
|
|
|
|
_( "&Open Directory in File Explorer" ),
|
2019-06-17 13:25:49 +00:00
|
|
|
_( "Opens the directory in the default system file manager" ),
|
2019-07-17 10:57:12 +00:00
|
|
|
#endif
|
2019-06-17 13:25:49 +00:00
|
|
|
KiBitmap( directory_browser_xpm ) );
|
2019-08-28 16:01:06 +00:00
|
|
|
|
|
|
|
popupMenu.AppendSeparator();
|
2018-10-17 19:03:33 +00:00
|
|
|
AddMenuItem( &popupMenu, ID_PROJECT_DELETE,
|
|
|
|
_( "&Delete Directory" ),
|
|
|
|
_( "Delete the Directory and its content" ),
|
|
|
|
KiBitmap( delete_xpm ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
AddMenuItem( &popupMenu, ID_PROJECT_TXTEDIT,
|
|
|
|
_( "&Edit in a Text Editor" ),
|
|
|
|
_( "Open the file in a Text Editor" ),
|
|
|
|
KiBitmap( editor_xpm ) );
|
|
|
|
AddMenuItem( &popupMenu, ID_PROJECT_RENAME,
|
|
|
|
_( "&Rename File..." ),
|
|
|
|
_( "Rename file" ),
|
|
|
|
KiBitmap( right_xpm ) );
|
2019-08-28 16:01:06 +00:00
|
|
|
|
|
|
|
popupMenu.AppendSeparator();
|
2018-10-17 19:03:33 +00:00
|
|
|
AddMenuItem( &popupMenu, ID_PROJECT_DELETE,
|
|
|
|
_( "&Delete File" ),
|
2019-08-28 16:01:06 +00:00
|
|
|
_( "Delete the file and its content" ),
|
2018-10-17 19:03:33 +00:00
|
|
|
KiBitmap( delete_xpm ) );
|
2019-08-28 16:01:06 +00:00
|
|
|
|
|
|
|
popupMenu.AppendSeparator();
|
|
|
|
AddMenuItem( &popupMenu, ID_PROJECT_PRINT,
|
|
|
|
_( "&Print..." ),
|
|
|
|
_( "Print the cotnents of the file" ),
|
|
|
|
KiBitmap( print_button_xpm ) );
|
2018-10-17 19:03:33 +00:00
|
|
|
break;
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
|
|
|
|
2013-01-03 19:25:12 +00:00
|
|
|
PopupMenu( &popupMenu );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2014-07-07 19:49:14 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor( wxCommandEvent& event )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2019-07-17 10:57:12 +00:00
|
|
|
if( !tree_data || tree_data->GetType() == TREE_DIRECTORY )
|
2013-01-03 19:25:12 +00:00
|
|
|
return;
|
|
|
|
|
2014-07-09 00:52:46 +00:00
|
|
|
wxString fullFileName = tree_data->GetFileName();
|
|
|
|
AddDelimiterString( fullFileName );
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
wxString editorname = Pgm().GetEditorName();
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !editorname.IsEmpty() )
|
2014-07-09 00:52:46 +00:00
|
|
|
ExecuteFile( this, editorname, fullFileName );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnDeleteFile( wxCommandEvent& )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2019-08-28 16:01:06 +00:00
|
|
|
if( tree_data )
|
|
|
|
tree_data->Delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TREE_PROJECT_FRAME::OnPrintFile( wxCommandEvent& )
|
|
|
|
{
|
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2019-08-28 16:01:06 +00:00
|
|
|
if( tree_data )
|
|
|
|
tree_data->Print();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-12-31 08:12:29 +00:00
|
|
|
wxTreeItemId curr_item = m_TreeProject->GetSelection();
|
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( !tree_data )
|
|
|
|
return;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2014-07-07 19:49:14 +00:00
|
|
|
wxString buffer = m_TreeProject->GetItemText( curr_item );
|
2019-07-17 10:57:12 +00:00
|
|
|
wxString msg = wxString::Format( _( "Change filename: \"%s\"" ), tree_data->GetFileName() );
|
|
|
|
wxTextEntryDialog dlg( this, msg, _( "Change filename" ), buffer );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2010-07-20 10:30:40 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2015-02-28 19:00:48 +00:00
|
|
|
return; // canceled by user
|
2010-07-20 10:30:40 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
buffer = dlg.GetValue();
|
2010-07-21 08:15:54 +00:00
|
|
|
buffer.Trim( true );
|
|
|
|
buffer.Trim( false );
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2010-07-20 10:30:40 +00:00
|
|
|
if( buffer.IsEmpty() )
|
2012-12-31 08:12:29 +00:00
|
|
|
return; // empty file name not allowed
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( tree_data->Rename( buffer, true ) )
|
|
|
|
m_TreeProject->SetItemText( curr_item, buffer );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2018-06-21 15:05:08 +00:00
|
|
|
TREEPROJECT_ITEM* selected_item = GetSelectedData();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2018-06-21 15:05:08 +00:00
|
|
|
if( !selected_item )
|
2009-02-04 15:25:03 +00:00
|
|
|
return;
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2018-06-21 15:05:08 +00:00
|
|
|
selected_item->Activate( this );
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
2010-02-20 13:20:55 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event )
|
|
|
|
{
|
2012-12-31 08:12:29 +00:00
|
|
|
wxTreeItemId itemId = Event.GetItem();
|
|
|
|
TREEPROJECT_ITEM* tree_data = GetItemIdData( itemId );
|
2010-02-20 13:20:55 +00:00
|
|
|
|
|
|
|
if( !tree_data )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( tree_data->GetType() != TREE_DIRECTORY )
|
|
|
|
return;
|
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
// explore list of non populated subdirs, and populate them
|
|
|
|
wxTreeItemIdValue cookie;
|
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( itemId, cookie );
|
|
|
|
|
2013-01-01 14:06:49 +00:00
|
|
|
bool subdir_populated = false;
|
2015-02-28 19:00:48 +00:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
for( ; kid.IsOk(); kid = m_TreeProject->GetNextChild( itemId, cookie ) )
|
|
|
|
{
|
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
if( !itemData || itemData->GetType() != TREE_DIRECTORY )
|
|
|
|
continue;
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2014-07-07 19:49:14 +00:00
|
|
|
if( itemData->IsPopulated() )
|
2010-02-20 13:20:55 +00:00
|
|
|
continue;
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
wxString fileName = itemData->GetFileName();
|
|
|
|
wxDir dir( fileName );
|
2012-12-31 08:12:29 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( dir.IsOpened() )
|
2010-02-20 13:20:55 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
wxString dir_filename;
|
|
|
|
|
|
|
|
if( dir.GetFirst( &dir_filename ) )
|
2010-02-20 13:20:55 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
do // Add name to tree item, but do not recurse in subdirs:
|
|
|
|
{
|
2014-10-21 16:34:51 +00:00
|
|
|
wxString name = fileName + wxFileName::GetPathSeparator() + dir_filename;
|
|
|
|
AddItemToTreeProject( name, kid, false );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
} while( dir.GetNext( &dir_filename ) );
|
|
|
|
}
|
2012-12-31 08:12:29 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
itemData->SetPopulated( true ); // set state to populated
|
|
|
|
subdir_populated = true;
|
|
|
|
}
|
2010-02-20 13:20:55 +00:00
|
|
|
|
2014-07-07 19:49:14 +00:00
|
|
|
// Sort filenames by alphabetic order
|
2010-02-20 13:20:55 +00:00
|
|
|
m_TreeProject->SortChildren( kid );
|
|
|
|
}
|
2013-01-01 14:06:49 +00:00
|
|
|
|
2019-07-17 10:57:12 +00:00
|
|
|
#ifndef __WINDOWS__
|
2013-01-01 14:06:49 +00:00
|
|
|
if( subdir_populated )
|
2013-01-02 21:49:56 +00:00
|
|
|
FileWatcherReset();
|
2019-07-17 10:57:12 +00:00
|
|
|
#endif
|
2010-02-20 13:20:55 +00:00
|
|
|
}
|
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetSelectedData()
|
|
|
|
{
|
2019-07-17 10:57:12 +00:00
|
|
|
return GetItemIdData( m_TreeProject->GetSelection() );
|
2010-02-20 13:20:55 +00:00
|
|
|
}
|
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
|
|
|
|
TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetItemIdData( wxTreeItemId aId )
|
2010-02-20 13:20:55 +00:00
|
|
|
{
|
|
|
|
return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( aId ) );
|
|
|
|
}
|
|
|
|
|
2014-07-07 19:49:14 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
wxTreeItemId TREE_PROJECT_FRAME::findSubdirTreeItem( const wxString& aSubDir )
|
|
|
|
{
|
2014-10-21 16:34:51 +00:00
|
|
|
wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
|
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
// If the subdir is the current working directory, return m_root
|
|
|
|
// in main list:
|
2014-10-21 16:34:51 +00:00
|
|
|
if( prj_dir == aSubDir )
|
2012-12-31 08:12:29 +00:00
|
|
|
return m_root;
|
|
|
|
|
|
|
|
// The subdir is in the main tree or in a subdir: Locate it
|
|
|
|
wxTreeItemIdValue cookie;
|
|
|
|
wxTreeItemId root_id = m_root;
|
|
|
|
std::stack < wxTreeItemId > subdirs_id;
|
|
|
|
|
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
|
2015-02-28 19:00:48 +00:00
|
|
|
|
2019-07-17 10:57:12 +00:00
|
|
|
while( true )
|
2012-12-31 08:12:29 +00:00
|
|
|
{
|
|
|
|
if( ! kid.IsOk() )
|
|
|
|
{
|
|
|
|
if( subdirs_id.empty() ) // all items were explored
|
|
|
|
{
|
|
|
|
root_id = kid; // Not found: return an invalid wxTreeItemId
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
root_id = subdirs_id.top();
|
|
|
|
subdirs_id.pop();
|
|
|
|
kid = m_TreeProject->GetFirstChild( root_id, cookie );
|
2016-06-16 12:38:31 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
if( ! kid.IsOk() )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
|
|
|
|
2013-01-01 14:06:49 +00:00
|
|
|
if( itemData && ( itemData->GetType() == TREE_DIRECTORY ) )
|
2012-12-31 08:12:29 +00:00
|
|
|
{
|
2014-07-07 19:49:14 +00:00
|
|
|
if( itemData->GetFileName() == aSubDir ) // Found!
|
2012-12-31 08:12:29 +00:00
|
|
|
{
|
|
|
|
root_id = kid;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-01 14:06:49 +00:00
|
|
|
// kid is a subdir, push in list to explore it later
|
2014-07-07 19:49:14 +00:00
|
|
|
if( itemData->IsPopulated() )
|
2012-12-31 08:12:29 +00:00
|
|
|
subdirs_id.push( kid );
|
|
|
|
}
|
2016-06-16 12:38:31 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
kid = m_TreeProject->GetNextChild( root_id, cookie );
|
|
|
|
}
|
|
|
|
|
|
|
|
return root_id;
|
|
|
|
}
|
|
|
|
|
2014-07-07 19:49:14 +00:00
|
|
|
|
|
|
|
void TREE_PROJECT_FRAME::OnFileSystemEvent( wxFileSystemWatcherEvent& event )
|
2012-12-31 08:12:29 +00:00
|
|
|
{
|
2017-09-22 17:11:11 +00:00
|
|
|
const wxFileName& pathModified = event.GetPath();
|
2013-01-02 21:49:56 +00:00
|
|
|
wxString subdir = pathModified.GetPath();
|
|
|
|
wxString fn = pathModified.GetFullPath();
|
2012-12-31 08:12:29 +00:00
|
|
|
|
|
|
|
switch( event.GetChangeType() )
|
|
|
|
{
|
|
|
|
case wxFSW_EVENT_DELETE:
|
|
|
|
case wxFSW_EVENT_CREATE:
|
|
|
|
case wxFSW_EVENT_RENAME:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wxFSW_EVENT_MODIFY:
|
|
|
|
case wxFSW_EVENT_ACCESS:
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxTreeItemId root_id = findSubdirTreeItem( subdir );
|
2014-10-21 16:34:51 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
if( !root_id.IsOk() )
|
|
|
|
return;
|
2010-02-20 13:20:55 +00:00
|
|
|
|
2013-01-02 21:49:56 +00:00
|
|
|
wxTreeItemIdValue cookie; // dummy variable needed by GetFirstChild()
|
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2013-01-02 21:49:56 +00:00
|
|
|
switch( event.GetChangeType() )
|
2012-12-31 08:12:29 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
case wxFSW_EVENT_CREATE:
|
|
|
|
AddItemToTreeProject( pathModified.GetFullPath(), root_id, false );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wxFSW_EVENT_DELETE:
|
|
|
|
while( kid.IsOk() )
|
|
|
|
{
|
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
|
|
|
|
|
|
|
if( itemData && itemData->GetFileName() == fn )
|
|
|
|
{
|
|
|
|
m_TreeProject->Delete( kid );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
kid = m_TreeProject->GetNextChild( root_id, cookie );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wxFSW_EVENT_RENAME :
|
|
|
|
{
|
2017-09-22 17:11:11 +00:00
|
|
|
const wxFileName& newpath = event.GetNewPath();
|
|
|
|
wxString newfn = newpath.GetFullPath();
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2013-01-02 21:49:56 +00:00
|
|
|
while( kid.IsOk() )
|
2012-12-31 08:12:29 +00:00
|
|
|
{
|
2013-01-02 21:49:56 +00:00
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
|
|
|
|
2014-07-07 19:49:14 +00:00
|
|
|
if( itemData && itemData->GetFileName() == fn )
|
2012-12-31 08:12:29 +00:00
|
|
|
{
|
2013-01-02 21:49:56 +00:00
|
|
|
m_TreeProject->Delete( kid );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
break;
|
2012-12-31 08:12:29 +00:00
|
|
|
}
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2013-01-02 21:49:56 +00:00
|
|
|
kid = m_TreeProject->GetNextChild( root_id, cookie );
|
2012-12-31 08:12:29 +00:00
|
|
|
}
|
2013-01-02 21:49:56 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
AddItemToTreeProject( newfn, root_id, false );
|
|
|
|
}
|
|
|
|
break;
|
2012-12-31 08:12:29 +00:00
|
|
|
}
|
|
|
|
|
2014-07-07 19:49:14 +00:00
|
|
|
// Sort filenames by alphabetic order
|
2012-12-31 08:12:29 +00:00
|
|
|
m_TreeProject->SortChildren( root_id );
|
|
|
|
}
|
|
|
|
|
2014-07-07 19:49:14 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
void TREE_PROJECT_FRAME::FileWatcherReset()
|
|
|
|
{
|
|
|
|
// Prepare file watcher:
|
2016-06-16 12:38:31 +00:00
|
|
|
if( m_watcher )
|
|
|
|
{
|
|
|
|
m_watcher->RemoveAll();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_watcher = new wxFileSystemWatcher();
|
|
|
|
m_watcher->SetOwner( this );
|
|
|
|
}
|
2012-12-31 08:12:29 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// We can see wxString under a debugger, not a wxFileName
|
2014-10-21 16:34:51 +00:00
|
|
|
wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
|
|
|
|
wxFileName fn;
|
|
|
|
fn.AssignDir( prj_dir );
|
|
|
|
fn.DontFollowLink();
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2019-07-17 10:57:12 +00:00
|
|
|
// Add directories which should be monitored.
|
|
|
|
// under windows, we add the curr dir and all subdirs
|
|
|
|
// under unix, we add only the curr dir and the populated subdirs
|
|
|
|
// see http://docs.wxwidgets.org/trunk/classwx_file_system_watcher.htm
|
|
|
|
// under unix, the file watcher needs more work to be efficient
|
|
|
|
// moreover, under wxWidgets 2.9.4, AddTree does not work properly.
|
2012-12-31 08:12:29 +00:00
|
|
|
#ifdef __WINDOWS__
|
2014-10-21 16:34:51 +00:00
|
|
|
m_watcher->AddTree( fn );
|
2012-12-31 08:12:29 +00:00
|
|
|
#else
|
2014-10-21 16:34:51 +00:00
|
|
|
m_watcher->Add( fn );
|
2013-01-01 14:06:49 +00:00
|
|
|
|
|
|
|
// Add subdirs
|
|
|
|
wxTreeItemIdValue cookie;
|
|
|
|
wxTreeItemId root_id = m_root;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2013-01-01 14:06:49 +00:00
|
|
|
std::stack < wxTreeItemId > subdirs_id;
|
|
|
|
|
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
|
2015-02-28 19:00:48 +00:00
|
|
|
|
2019-07-17 10:57:12 +00:00
|
|
|
while( true )
|
2013-01-01 14:06:49 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( !kid.IsOk() )
|
2013-01-01 14:06:49 +00:00
|
|
|
{
|
|
|
|
if( subdirs_id.empty() ) // all items were explored
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
root_id = subdirs_id.top();
|
|
|
|
subdirs_id.pop();
|
|
|
|
kid = m_TreeProject->GetFirstChild( root_id, cookie );
|
2016-06-16 12:38:31 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( !kid.IsOk() )
|
2013-01-01 14:06:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( itemData && itemData->GetType() == TREE_DIRECTORY )
|
2013-01-01 14:06:49 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// we can see wxString under a debugger, not a wxFileName
|
2017-09-22 17:11:11 +00:00
|
|
|
const wxString& path = itemData->GetFileName();
|
2013-01-01 14:06:49 +00:00
|
|
|
|
2018-10-17 19:34:46 +00:00
|
|
|
wxLogTrace( tracePathsAndFiles, "%s: add '%s'\n", __func__, TO_UTF8( path ) );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
|
|
|
if( wxFileName::IsDirReadable( path ) ) // linux whines about watching protected dir
|
|
|
|
{
|
2014-10-21 16:34:51 +00:00
|
|
|
fn.AssignDir( path );
|
|
|
|
m_watcher->Add( fn );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
|
|
|
// if kid is a subdir, push in list to explore it later
|
|
|
|
if( itemData->IsPopulated() && m_TreeProject->GetChildrenCount( kid ) )
|
|
|
|
subdirs_id.push( kid );
|
|
|
|
}
|
2013-01-01 14:06:49 +00:00
|
|
|
}
|
2014-07-07 19:49:14 +00:00
|
|
|
|
2013-01-01 14:06:49 +00:00
|
|
|
kid = m_TreeProject->GetNextChild( root_id, cookie );
|
|
|
|
}
|
2012-12-31 08:12:29 +00:00
|
|
|
#endif
|
2013-01-01 14:06:49 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
#if defined(DEBUG) && 1
|
2013-01-01 14:06:49 +00:00
|
|
|
wxArrayString paths;
|
|
|
|
m_watcher->GetWatchedPaths( &paths );
|
2018-10-17 19:03:33 +00:00
|
|
|
wxLogTrace( tracePathsAndFiles, "%s: watched paths:", __func__ );
|
2016-06-16 12:38:31 +00:00
|
|
|
|
2013-01-01 14:06:49 +00:00
|
|
|
for( unsigned ii = 0; ii < paths.GetCount(); ii++ )
|
2018-10-17 19:03:33 +00:00
|
|
|
wxLogTrace( tracePathsAndFiles, " %s\n", TO_UTF8( paths[ii] ) );
|
2013-01-01 14:06:49 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-06-16 12:38:31 +00:00
|
|
|
|
|
|
|
void KICAD_MANAGER_FRAME::OnChangeWatchedPaths( wxCommandEvent& aEvent )
|
2013-01-01 14:06:49 +00:00
|
|
|
{
|
2019-06-10 14:23:37 +00:00
|
|
|
m_leftWin->FileWatcherReset();
|
2012-12-31 08:12:29 +00:00
|
|
|
}
|