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
|
2021-01-08 10:30:33 +00:00
|
|
|
* Copyright (C) 1992-2021 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
|
|
|
#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>
|
2020-10-24 14:45:37 +00:00
|
|
|
#include <common.h>
|
2016-02-24 21:36:52 +00:00
|
|
|
#include <gestfich.h>
|
2020-10-24 14:45:37 +00:00
|
|
|
#include <macros.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>
|
2020-12-16 00:36:12 +00:00
|
|
|
#include <kiplatform/environment.h>
|
2020-12-22 13:51:32 +00:00
|
|
|
#include <core/kicad_algo.h>
|
2021-01-23 04:17:32 +00:00
|
|
|
#include <paths.h>
|
2016-02-24 21:36:52 +00:00
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
#include "project_tree_item.h"
|
|
|
|
#include "project_tree.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"
|
2020-10-12 22:40:17 +00:00
|
|
|
#include "kicad_manager_frame.h"
|
2016-02-24 21:36:52 +00:00
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
#include "project_tree_pane.h"
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
/* Note about the project tree build process:
|
|
|
|
* Building the project tree can be *very* long if there are a lot of subdirectories in the
|
|
|
|
* working directory. Unfortunately, this happens easily if the project file *.pro is in the
|
|
|
|
* user's home directory.
|
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)
|
2020-12-02 12:35:19 +00:00
|
|
|
* > 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
|
|
|
|
// Add extensions in a compatible regex format to see others files types
|
2019-12-05 19:35:37 +00:00
|
|
|
static const wxChar* s_allowedExtensionsToList[] = {
|
2008-05-30 18:06:21 +00:00
|
|
|
wxT( "^.*\\.pro$" ),
|
2020-07-07 00:14:27 +00:00
|
|
|
wxT( "^.*\\.kicad_pro$" ),
|
2008-05-30 18:06:21 +00:00
|
|
|
wxT( "^.*\\.pdf$" ),
|
2020-04-07 14:00:16 +00:00
|
|
|
wxT( "^.*\\.sch$" ), // Legacy Eeschema files
|
|
|
|
wxT( "^.*\\.kicad_sch$" ), // S-expr Eeschema files
|
2019-12-05 19:35:37 +00:00
|
|
|
wxT( "^[^$].*\\.brd$" ), // Legacy Pcbnew files
|
|
|
|
wxT( "^[^$].*\\.kicad_pcb$" ), // S format Pcbnew board files
|
2020-09-25 01:26:23 +00:00
|
|
|
wxT( "^[^$].*\\.kicad_dru$" ), // Design rule files
|
2019-12-05 19:35:37 +00:00
|
|
|
wxT( "^[^$].*\\.kicad_wks$" ), // S format kicad page layout help_textr files
|
|
|
|
wxT( "^[^$].*\\.kicad_mod$" ), // S format kicad footprint files, currently not listed
|
|
|
|
wxT( "^.*\\.net$" ), // pcbnew netlist file
|
|
|
|
wxT( "^.*\\.cir$" ), // Spice netlist file
|
2020-04-07 14:00:16 +00:00
|
|
|
wxT( "^.*\\.lib$" ), // Legacy schematic library file
|
|
|
|
wxT( "^.*\\.kicad_sym$" ), // S-expr symbol libraries
|
2008-05-30 18:06:21 +00:00
|
|
|
wxT( "^.*\\.txt$" ),
|
2019-12-05 19:35:37 +00:00
|
|
|
wxT( "^.*\\.pho$" ), // Gerber file (Old Kicad extension)
|
|
|
|
wxT( "^.*\\.gbr$" ), // Gerber file
|
|
|
|
wxT( "^.*\\.gbrjob$" ), // Gerber job file
|
|
|
|
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$" ),
|
2019-12-05 19:35:37 +00:00
|
|
|
wxT( "^.*\\.rpt$" ), // Report files
|
|
|
|
wxT( "^.*\\.csv$" ), // Report files in comma separated format
|
|
|
|
wxT( "^.*\\.pos$" ), // Footprint position files
|
2020-06-03 20:13:01 +00:00
|
|
|
wxT( "^.*\\.cmp$" ), // CvPcb cmp/footprint link files
|
2019-12-05 19:35:37 +00:00
|
|
|
wxT( "^.*\\.drl$" ), // Excellon drill files
|
|
|
|
wxT( "^.*\\.nc$" ), // Excellon NC drill files (alternate file ext)
|
|
|
|
wxT( "^.*\\.xnc$" ), // Excellon NC drill files (alternate file ext)
|
|
|
|
wxT( "^.*\\.svg$" ), // SVG print/plot files
|
2020-10-20 20:09:13 +00:00
|
|
|
wxT( "^.*\\.ps$" ), // PostScript plot files
|
2019-12-05 19:35:37 +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
|
|
|
/**
|
2020-12-02 12:35:19 +00:00
|
|
|
* @brief class PROJECT_TREE_PANE is the frame that shows the tree list of files and subdirs
|
2019-07-17 10:57:12 +00:00
|
|
|
* 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
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
BEGIN_EVENT_TABLE( PROJECT_TREE_PANE, wxSashLayoutWindow )
|
2020-12-18 15:06:59 +00:00
|
|
|
EVT_TREE_ITEM_ACTIVATED( ID_PROJECT_TREE, PROJECT_TREE_PANE::onSelect )
|
|
|
|
EVT_TREE_ITEM_EXPANDED( ID_PROJECT_TREE, PROJECT_TREE_PANE::onExpand )
|
|
|
|
EVT_TREE_ITEM_RIGHT_CLICK( ID_PROJECT_TREE, PROJECT_TREE_PANE::onRight )
|
|
|
|
EVT_MENU( ID_PROJECT_TXTEDIT, PROJECT_TREE_PANE::onOpenSelectedFileWithTextEditor )
|
|
|
|
EVT_MENU( ID_PROJECT_SWITCH_TO_OTHER, PROJECT_TREE_PANE::onSwitchToSelectedProject )
|
|
|
|
EVT_MENU( ID_PROJECT_NEWDIR, PROJECT_TREE_PANE::onCreateNewDirectory )
|
|
|
|
EVT_MENU( ID_PROJECT_OPEN_DIR, PROJECT_TREE_PANE::onOpenDirectory )
|
|
|
|
EVT_MENU( ID_PROJECT_DELETE, PROJECT_TREE_PANE::onDeleteFile )
|
|
|
|
EVT_MENU( ID_PROJECT_PRINT, PROJECT_TREE_PANE::onPrintFile )
|
|
|
|
EVT_MENU( ID_PROJECT_RENAME, PROJECT_TREE_PANE::onRenameFile )
|
|
|
|
EVT_IDLE( PROJECT_TREE_PANE::onIdle )
|
2010-02-20 13:20:55 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
PROJECT_TREE_PANE::PROJECT_TREE_PANE( KICAD_MANAGER_FRAME* parent ) :
|
|
|
|
wxSashLayoutWindow( parent, ID_LEFT_FRAME, wxDefaultPosition, wxDefaultSize,
|
|
|
|
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;
|
2019-11-17 00:52:43 +00:00
|
|
|
m_isRenaming = false;
|
2020-10-17 03:40:27 +00:00
|
|
|
m_selectedItem = nullptr;
|
2021-01-08 16:40:29 +00:00
|
|
|
m_watcherNeedReset = false;
|
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,
|
2020-12-18 15:06:59 +00:00
|
|
|
wxFileSystemWatcherEventHandler( PROJECT_TREE_PANE::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.
|
|
|
|
*/
|
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
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
PROJECT_TREE_PANE::~PROJECT_TREE_PANE()
|
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
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
void PROJECT_TREE_PANE::onSwitchToSelectedProject( wxCommandEvent& event )
|
2018-06-21 15:05:08 +00:00
|
|
|
{
|
2020-12-02 12:35:19 +00:00
|
|
|
std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
|
2018-06-21 15:05:08 +00:00
|
|
|
|
2019-12-05 19:35:37 +00:00
|
|
|
if( tree_data.size() != 1 )
|
2018-06-21 15:05:08 +00:00
|
|
|
return;
|
|
|
|
|
2019-12-05 19:35:37 +00:00
|
|
|
wxString prj_filename = tree_data[0]->GetFileName();
|
2018-06-21 15:05:08 +00:00
|
|
|
|
|
|
|
m_Parent->LoadProject( prj_filename );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
void PROJECT_TREE_PANE::onOpenDirectory( wxCommandEvent& event )
|
2019-06-17 13:25:49 +00:00
|
|
|
{
|
|
|
|
// Get the root directory name:
|
2020-12-02 12:35:19 +00:00
|
|
|
std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
|
2019-06-17 13:25:49 +00:00
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
for( PROJECT_TREE_ITEM* item_data : tree_data )
|
2019-06-17 13:25:49 +00:00
|
|
|
{
|
2019-12-05 19:35:37 +00:00
|
|
|
// Ask for the new sub directory name
|
|
|
|
wxString curr_dir = item_data->GetDir();
|
|
|
|
|
|
|
|
if( curr_dir.IsEmpty() )
|
|
|
|
{
|
|
|
|
// Use project path if the tree view path was empty.
|
|
|
|
curr_dir = wxPathOnly( m_Parent->GetProjectFileName() );
|
2019-06-20 19:18:43 +00:00
|
|
|
|
2019-12-05 19:35:37 +00:00
|
|
|
// As a last resort use the user's documents folder.
|
|
|
|
if( curr_dir.IsEmpty() || !wxFileName::DirExists( curr_dir ) )
|
2021-01-23 04:17:32 +00:00
|
|
|
curr_dir = PATHS::GetDefaultUserProjectsPath();
|
2019-06-17 13:25:49 +00:00
|
|
|
|
2019-12-05 19:35:37 +00:00
|
|
|
if( !curr_dir.IsEmpty() )
|
|
|
|
curr_dir += wxFileName::GetPathSeparator();
|
|
|
|
}
|
2019-06-17 13:25:49 +00:00
|
|
|
|
2019-07-17 10:57:12 +00:00
|
|
|
#ifdef __WXMAC__
|
2019-12-05 19:35:37 +00:00
|
|
|
wxString msg;
|
2019-07-17 10:57:12 +00:00
|
|
|
|
2019-12-05 19:35:37 +00:00
|
|
|
// Quote in case there are spaces in the path.
|
|
|
|
msg.Printf( "open \"%s\"", curr_dir );
|
2019-07-17 10:57:12 +00:00
|
|
|
|
2019-12-05 19:35:37 +00:00
|
|
|
system( msg.c_str() );
|
2019-07-17 10:57:12 +00:00
|
|
|
#else
|
2021-01-08 10:30:33 +00:00
|
|
|
#if !wxCHECK_VERSION( 3, 1, 0 )
|
2019-12-05 19:35:37 +00:00
|
|
|
// Quote in case there are spaces in the path.
|
2021-01-08 10:30:33 +00:00
|
|
|
// Not needed on 3.1.4, but needed in 3.0 versions
|
|
|
|
// Moreover, on Linux, on 3.1.4 wx version, adding quotes breaks
|
|
|
|
// wxLaunchDefaultApplication
|
2019-12-05 19:35:37 +00:00
|
|
|
AddDelimiterString( curr_dir );
|
2021-01-08 10:30:33 +00:00
|
|
|
#endif
|
2019-06-17 13:25:49 +00:00
|
|
|
|
2019-12-05 19:35:37 +00:00
|
|
|
wxLaunchDefaultApplication( curr_dir );
|
2019-07-17 10:57:12 +00:00
|
|
|
#endif
|
2019-12-05 19:35:37 +00:00
|
|
|
}
|
2019-06-17 13:25:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
void PROJECT_TREE_PANE::onCreateNewDirectory( wxCommandEvent& event )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2012-04-16 12:56:01 +00:00
|
|
|
// Get the root directory name:
|
2020-12-02 12:35:19 +00:00
|
|
|
std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
for( PROJECT_TREE_ITEM* item_data : tree_data )
|
2019-12-05 19:35:37 +00:00
|
|
|
{
|
|
|
|
wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
|
2014-10-21 16:34:51 +00:00
|
|
|
|
2019-12-05 19:35:37 +00:00
|
|
|
// Ask for the new sub directory name
|
|
|
|
wxString curr_dir = item_data->GetDir();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
if( curr_dir.IsEmpty() )
|
|
|
|
curr_dir = prj_dir;
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
wxString new_dir = wxGetTextFromUser( _( "Directory name:" ), _( "Create New Directory" ) );
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
if( new_dir.IsEmpty() )
|
2019-12-05 19:35:37 +00:00
|
|
|
return;
|
2012-04-16 12:56:01 +00:00
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
wxString full_dirname = curr_dir + wxFileName::GetPathSeparator() + new_dir;
|
2014-10-21 16:34:51 +00:00
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
wxMkdir( full_dirname );
|
2020-12-22 13:51:32 +00:00
|
|
|
addItemToProjectTree( full_dirname, item_data->GetId(), nullptr, false );
|
2019-12-05 19:35:37 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
wxString PROJECT_TREE_PANE::GetFileExt( TREE_FILE_TYPE type )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
switch( type )
|
|
|
|
{
|
2020-10-12 22:40:17 +00:00
|
|
|
case TREE_FILE_TYPE::LEGACY_PROJECT: return LegacyProjectFileExtension;
|
|
|
|
case TREE_FILE_TYPE::JSON_PROJECT: return ProjectFileExtension;
|
|
|
|
case TREE_FILE_TYPE::LEGACY_SCHEMATIC: return LegacySchematicFileExtension;
|
|
|
|
case TREE_FILE_TYPE::SEXPR_SCHEMATIC: return KiCadSchematicFileExtension;
|
|
|
|
case TREE_FILE_TYPE::LEGACY_PCB: return LegacyPcbFileExtension;
|
|
|
|
case TREE_FILE_TYPE::SEXPR_PCB: return KiCadPcbFileExtension;
|
|
|
|
case TREE_FILE_TYPE::GERBER: return GerberFileExtensionWildCard;
|
|
|
|
case TREE_FILE_TYPE::GERBER_JOB_FILE: return GerberJobFileExtension;
|
|
|
|
case TREE_FILE_TYPE::HTML: return HtmlFileExtension;
|
|
|
|
case TREE_FILE_TYPE::PDF: return PdfFileExtension;
|
|
|
|
case TREE_FILE_TYPE::TXT: return TextFileExtension;
|
|
|
|
case TREE_FILE_TYPE::NET: return NetlistFileExtension;
|
|
|
|
case TREE_FILE_TYPE::CMP_LINK: return ComponentFileExtension;
|
|
|
|
case TREE_FILE_TYPE::REPORT: return ReportFileExtension;
|
|
|
|
case TREE_FILE_TYPE::FP_PLACE: return FootprintPlaceFileExtension;
|
|
|
|
case TREE_FILE_TYPE::DRILL: return DrillFileExtension;
|
|
|
|
case TREE_FILE_TYPE::DRILL_NC: return "nc";
|
|
|
|
case TREE_FILE_TYPE::DRILL_XNC: return "xnc";
|
|
|
|
case TREE_FILE_TYPE::SVG: return SVGFileExtension;
|
|
|
|
case TREE_FILE_TYPE::PAGE_LAYOUT_DESCR: return PageLayoutDescrFileExtension;
|
|
|
|
case TREE_FILE_TYPE::FOOTPRINT_FILE: return KiCadFootprintFileExtension;
|
|
|
|
case TREE_FILE_TYPE::SCHEMATIC_LIBFILE: return LegacySymbolLibFileExtension;
|
|
|
|
case TREE_FILE_TYPE::SEXPR_SYMBOL_LIB_FILE: return KiCadSymbolLibFileExtension;
|
2020-12-02 12:35:19 +00:00
|
|
|
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
|
|
|
|
2020-12-22 13:51:32 +00:00
|
|
|
std::vector<wxString> getProjects( const wxDir& dir )
|
|
|
|
{
|
|
|
|
std::vector<wxString> projects;
|
|
|
|
wxString dir_filename;
|
|
|
|
bool haveFile = dir.GetFirst( &dir_filename );
|
|
|
|
|
|
|
|
while( haveFile )
|
|
|
|
{
|
|
|
|
wxFileName file( dir_filename );
|
|
|
|
|
|
|
|
if( file.GetExt() == LegacyProjectFileExtension || file.GetExt() == ProjectFileExtension )
|
|
|
|
projects.push_back( file.GetName() );
|
|
|
|
|
|
|
|
haveFile = dir.GetNext( &dir_filename );
|
|
|
|
}
|
|
|
|
|
|
|
|
return projects;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
wxTreeItemId PROJECT_TREE_PANE::addItemToProjectTree( const wxString& aName,
|
2021-01-07 20:53:28 +00:00
|
|
|
const wxTreeItemId& aParent,
|
2020-12-22 13:51:32 +00:00
|
|
|
std::vector<wxString>* aProjectNames,
|
|
|
|
bool aRecurse )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2020-10-12 22:40:17 +00:00
|
|
|
TREE_FILE_TYPE type = TREE_FILE_TYPE::UNKNOWN;
|
2020-12-02 12:35:19 +00:00
|
|
|
wxFileName fn( aName );
|
2012-12-31 08:12:29 +00:00
|
|
|
|
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( "." ) ) )
|
2020-12-22 13:51:32 +00:00
|
|
|
return wxTreeItemId();
|
2010-02-17 17:47:12 +00:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
if( wxDirExists( aName ) )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2020-10-12 22:40:17 +00:00
|
|
|
type = TREE_FILE_TYPE::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;
|
2020-05-12 11:53:45 +00:00
|
|
|
bool addFile = false;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2020-05-12 11:53:45 +00:00
|
|
|
for( const wxString& m_filter : m_filters )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2020-05-12 11:53:45 +00:00
|
|
|
wxCHECK2_MSG( reg.Compile( m_filter, wxRE_ICASE ), continue,
|
|
|
|
wxString::Format( "Regex %s failed to compile.", m_filter ) );
|
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;
|
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 )
|
2020-12-22 13:51:32 +00:00
|
|
|
return wxTreeItemId();
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2020-10-12 22:40:17 +00:00
|
|
|
for( int i = static_cast<int>( TREE_FILE_TYPE::LEGACY_PROJECT );
|
|
|
|
i < static_cast<int>( TREE_FILE_TYPE::MAX ); i++ )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2020-10-12 22:40:17 +00:00
|
|
|
wxString ext = GetFileExt( (TREE_FILE_TYPE) 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
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
// For gerber files, the official ext is gbr
|
|
|
|
if( i == static_cast<int>( TREE_FILE_TYPE::GERBER ) )
|
2020-07-23 12:07:26 +00:00
|
|
|
ext = "gbr";
|
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
reg.Compile( wxString::FromAscii( "^.*\\." ) + ext + wxString::FromAscii( "$" ),
|
|
|
|
wxRE_ICASE );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
if( reg.Matches( aName ) )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2020-10-12 22:40:17 +00:00
|
|
|
type = (TREE_FILE_TYPE) i;
|
2007-05-28 18:09:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2020-07-07 00:14:27 +00:00
|
|
|
wxString file = wxFileNameFromPath( aName );
|
|
|
|
wxFileName currfile( file );
|
|
|
|
wxFileName project( m_Parent->GetProjectFileName() );
|
|
|
|
|
|
|
|
// Ignore legacy projects with the same name as the current project
|
2020-10-12 22:40:17 +00:00
|
|
|
if( ( type == TREE_FILE_TYPE::LEGACY_PROJECT )
|
|
|
|
&& ( currfile.GetName().CmpNoCase( project.GetName() ) == 0 ) )
|
2020-12-02 12:35:19 +00:00
|
|
|
{
|
2020-12-22 13:51:32 +00:00
|
|
|
return wxTreeItemId();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( currfile.GetExt() == GetFileExt( TREE_FILE_TYPE::LEGACY_SCHEMATIC )
|
|
|
|
|| currfile.GetExt() == GetFileExt( TREE_FILE_TYPE::SEXPR_SCHEMATIC ) )
|
|
|
|
{
|
2021-01-07 20:53:28 +00:00
|
|
|
if( aProjectNames )
|
|
|
|
{
|
|
|
|
if( !alg::contains( *aProjectNames, currfile.GetName() ) )
|
|
|
|
return wxTreeItemId();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PROJECT_TREE_ITEM* parentTreeItem = GetItemIdData( aParent );
|
|
|
|
wxDir parentDir( parentTreeItem->GetDir() );
|
|
|
|
std::vector<wxString> projects = getProjects( parentDir );
|
|
|
|
|
|
|
|
if( !alg::contains( projects, currfile.GetName() ) )
|
|
|
|
return wxTreeItemId();
|
|
|
|
}
|
2020-12-02 12:35:19 +00:00
|
|
|
}
|
2020-07-07 00:14:27 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
// also check to see if it is already there.
|
2020-07-07 00:14:27 +00:00
|
|
|
wxTreeItemIdValue cookie;
|
2021-01-07 20:53:28 +00:00
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( aParent, cookie );
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
while( kid.IsOk() )
|
|
|
|
{
|
2020-12-02 12:35:19 +00:00
|
|
|
PROJECT_TREE_ITEM* itemData = GetItemIdData( kid );
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
if( itemData && itemData->GetFileName() == aName )
|
|
|
|
return itemData->GetId(); // well, we would have added it, but it is already here!
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2021-01-07 20:53:28 +00:00
|
|
|
kid = m_TreeProject->GetNextChild( aParent, cookie );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2020-12-22 13:51:32 +00:00
|
|
|
// Only show current files if both legacy and current files are present
|
|
|
|
if( type == TREE_FILE_TYPE::LEGACY_PROJECT || type == TREE_FILE_TYPE::JSON_PROJECT
|
|
|
|
|| type == TREE_FILE_TYPE::LEGACY_SCHEMATIC || type == TREE_FILE_TYPE::SEXPR_SCHEMATIC )
|
2020-07-07 00:14:27 +00:00
|
|
|
{
|
2021-01-07 20:53:28 +00:00
|
|
|
kid = m_TreeProject->GetFirstChild( aParent, cookie );
|
2020-07-07 00:14:27 +00:00
|
|
|
|
|
|
|
while( kid.IsOk() )
|
|
|
|
{
|
2020-12-02 12:35:19 +00:00
|
|
|
PROJECT_TREE_ITEM* itemData = GetItemIdData( kid );
|
2020-07-07 00:14:27 +00:00
|
|
|
|
|
|
|
if( itemData )
|
|
|
|
{
|
|
|
|
wxFileName fname( itemData->GetFileName() );
|
|
|
|
|
|
|
|
if( fname.GetName().CmpNoCase( currfile.GetName() ) == 0 )
|
|
|
|
{
|
2020-12-22 13:51:32 +00:00
|
|
|
switch( type )
|
2020-07-07 00:14:27 +00:00
|
|
|
{
|
2020-12-22 13:51:32 +00:00
|
|
|
case TREE_FILE_TYPE::LEGACY_PROJECT:
|
|
|
|
if( itemData->GetType() == TREE_FILE_TYPE::JSON_PROJECT )
|
|
|
|
return wxTreeItemId();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_FILE_TYPE::LEGACY_SCHEMATIC:
|
|
|
|
if( itemData->GetType() == TREE_FILE_TYPE::SEXPR_SCHEMATIC )
|
|
|
|
return wxTreeItemId();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_FILE_TYPE::JSON_PROJECT:
|
|
|
|
if( itemData->GetType() == TREE_FILE_TYPE::LEGACY_PROJECT )
|
|
|
|
m_TreeProject->Delete( kid );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_FILE_TYPE::SEXPR_SCHEMATIC:
|
|
|
|
if( itemData->GetType() == TREE_FILE_TYPE::LEGACY_SCHEMATIC )
|
|
|
|
m_TreeProject->Delete( kid );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-07-07 00:14:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-07 20:53:28 +00:00
|
|
|
kid = m_TreeProject->GetNextChild( aParent, cookie );
|
2020-07-07 00:14:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
// Append the item (only appending the filename not the full path):
|
2021-01-07 20:53:28 +00:00
|
|
|
wxTreeItemId newItemId = m_TreeProject->AppendItem( aParent, file );
|
2020-12-22 13:51:32 +00:00
|
|
|
PROJECT_TREE_ITEM* data = new PROJECT_TREE_ITEM( type, aName, m_TreeProject );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2019-11-17 00:52:43 +00:00
|
|
|
m_TreeProject->SetItemData( newItemId, data );
|
2007-09-13 11:55:46 +00:00
|
|
|
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)
|
2020-08-20 12:22:05 +00:00
|
|
|
wxString fileName = currfile.GetName().Lower();
|
|
|
|
wxString projName = project.GetName().Lower();
|
|
|
|
data->SetRootFile( fileName == projName || fileName.StartsWith( projName + "-" ) );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2019-12-20 00:34:43 +00:00
|
|
|
#ifndef __WINDOWS__
|
|
|
|
bool subdir_populated = false;
|
|
|
|
#endif
|
|
|
|
|
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.
|
2020-10-12 22:40:17 +00:00
|
|
|
if( TREE_FILE_TYPE::DIRECTORY == type && aRecurse )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2020-07-07 00:14:27 +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
|
|
|
{
|
2020-12-22 13:51:32 +00:00
|
|
|
std::vector<wxString> projects = getProjects( dir );
|
|
|
|
wxString dir_filename;
|
|
|
|
bool haveFile = dir.GetFirst( &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
|
|
|
|
|
|
|
data->SetPopulated( true );
|
2019-12-20 00:34:43 +00:00
|
|
|
#ifndef __WINDOWS__
|
2020-12-22 13:51:32 +00:00
|
|
|
subdir_populated = aRecurse;
|
2019-12-20 00:34:43 +00:00
|
|
|
#endif
|
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
|
|
|
|
2020-12-22 13:51:32 +00:00
|
|
|
while( haveFile )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2020-12-22 13:51:32 +00:00
|
|
|
// Add name in tree, but do not recurse
|
|
|
|
wxString path = aName + wxFileName::GetPathSeparator() + dir_filename;
|
|
|
|
addItemToProjectTree( path, newItemId, &projects, false );
|
|
|
|
|
|
|
|
haveFile = dir.GetNext( &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
|
|
|
}
|
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
|
2019-11-17 00:52:43 +00:00
|
|
|
m_TreeProject->SortChildren( newItemId );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2019-12-20 00:34:43 +00:00
|
|
|
#ifndef __WINDOWS__
|
|
|
|
if( subdir_populated )
|
2021-01-08 16:40:29 +00:00
|
|
|
m_watcherNeedReset = true;
|
2019-12-20 00:34:43 +00:00
|
|
|
#endif
|
|
|
|
|
2019-11-17 00:52:43 +00:00
|
|
|
return newItemId;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
void PROJECT_TREE_PANE::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 )
|
2020-12-02 12:35:19 +00:00
|
|
|
m_TreeProject = new PROJECT_TREE( this );
|
2007-09-13 11:55:46 +00:00
|
|
|
else
|
|
|
|
m_TreeProject->DeleteAllItems();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
if( !pro_dir ) // This is empty from PROJECT_TREE_PANE constructor
|
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
|
|
|
return;
|
|
|
|
|
|
|
|
wxFileName fn = pro_dir;
|
2020-07-20 23:39:59 +00:00
|
|
|
bool prjReset = false;
|
2014-07-07 19:49:14 +00:00
|
|
|
|
|
|
|
if( !fn.IsOk() )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
fn.Clear();
|
2021-01-23 04:17:32 +00:00
|
|
|
fn.SetPath( PATHS::GetDefaultUserProjectsPath() );
|
2010-02-24 15:33:03 +00:00
|
|
|
fn.SetName( NAMELESS_PROJECT );
|
2020-06-19 03:23:03 +00:00
|
|
|
fn.SetExt( ProjectFileExtension );
|
2020-07-20 23:39:59 +00:00
|
|
|
prjReset = true;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
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
|
|
|
|
2020-07-20 23:39:59 +00:00
|
|
|
// We may have opened a legacy project, in which case GetProjectFileName will return the
|
|
|
|
// name of the migrated (new format) file, which may not have been saved to disk yet.
|
|
|
|
if( !prjOpened && !prjReset )
|
|
|
|
{
|
|
|
|
fn.SetExt( LegacyProjectFileExtension );
|
|
|
|
prjOpened = fn.FileExists();
|
|
|
|
|
|
|
|
// Set the ext back so that in the tree view we see the (not-yet-saved) new file
|
|
|
|
fn.SetExt( ProjectFileExtension );
|
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
// root tree:
|
2020-10-12 22:40:17 +00:00
|
|
|
m_root = m_TreeProject->AddRoot( fn.GetFullName(), static_cast<int>( TREE_FILE_TYPE::ROOT ),
|
2020-12-02 12:35:19 +00:00
|
|
|
static_cast<int>( TREE_FILE_TYPE::ROOT ) );
|
2019-07-17 10:57:12 +00:00
|
|
|
m_TreeProject->SetItemBold( m_root, true );
|
2020-07-07 00:14:27 +00:00
|
|
|
|
|
|
|
// The main project file is now a JSON file
|
2020-12-02 12:35:19 +00:00
|
|
|
m_TreeProject->SetItemData( m_root, new PROJECT_TREE_ITEM( TREE_FILE_TYPE::JSON_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
|
|
|
{
|
2020-12-22 13:51:32 +00:00
|
|
|
std::vector<wxString> projects = getProjects( dir );
|
|
|
|
wxString filename;
|
|
|
|
bool haveFile = dir.GetFirst( &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
|
|
|
|
2020-12-22 13:51:32 +00:00
|
|
|
while( haveFile )
|
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( filename != fn.GetFullName() )
|
|
|
|
{
|
2014-10-21 16:34:51 +00:00
|
|
|
wxString name = dir.GetName() + wxFileName::GetPathSeparator() + filename;
|
2021-01-08 16:40:29 +00:00
|
|
|
// Add items living in the project directory, and populate the item
|
2021-01-08 10:30:33 +00:00
|
|
|
// if it is a directory (sub directories will be not populated)
|
2021-01-08 16:40:29 +00:00
|
|
|
addItemToProjectTree( name, m_root, &projects, true );
|
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
|
|
|
|
2020-12-22 13:51:32 +00:00
|
|
|
haveFile = dir.GetNext( &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
|
|
|
}
|
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
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
void PROJECT_TREE_PANE::onRight( wxTreeEvent& Event )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2020-12-02 12:35:19 +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 );
|
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
std::vector<PROJECT_TREE_ITEM*> selection = GetSelectedData();
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2020-08-06 10:12:34 +00:00
|
|
|
bool can_switch_to_project = true;
|
|
|
|
bool can_create_new_directory = true;
|
|
|
|
bool can_open_this_directory = true;
|
|
|
|
bool can_edit = true;
|
|
|
|
bool can_rename = true;
|
|
|
|
bool can_delete = true;
|
|
|
|
bool can_print = true;
|
2019-12-05 19:35:37 +00:00
|
|
|
|
2020-08-06 10:12:34 +00:00
|
|
|
if( selection.size() == 0 )
|
2007-09-13 11:55:46 +00:00
|
|
|
return;
|
|
|
|
|
2020-08-06 10:12:34 +00:00
|
|
|
// Remove things that don't make sense for multiple selections
|
|
|
|
if( selection.size() != 1 )
|
|
|
|
{
|
|
|
|
can_switch_to_project = false;
|
|
|
|
can_create_new_directory = false;
|
|
|
|
can_rename = false;
|
|
|
|
can_print = false;
|
|
|
|
}
|
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
for( PROJECT_TREE_ITEM* item : selection )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2020-07-20 23:39:59 +00:00
|
|
|
// Check for empty project
|
2020-08-06 10:12:34 +00:00
|
|
|
if( !item )
|
|
|
|
{
|
|
|
|
can_switch_to_project = false;
|
|
|
|
can_edit = false;
|
|
|
|
can_rename = false;
|
|
|
|
can_print = false;
|
2020-07-20 23:39:59 +00:00
|
|
|
continue;
|
2020-08-06 10:12:34 +00:00
|
|
|
}
|
2020-07-20 23:39:59 +00:00
|
|
|
|
2020-08-06 10:12:34 +00:00
|
|
|
wxString full_file_name = item->GetFileName();
|
2019-12-05 19:35:37 +00:00
|
|
|
|
2020-10-12 22:40:17 +00:00
|
|
|
switch( item->GetType() )
|
2018-10-17 19:03:33 +00:00
|
|
|
{
|
2020-10-12 22:40:17 +00:00
|
|
|
case TREE_FILE_TYPE::LEGACY_PROJECT:
|
|
|
|
case TREE_FILE_TYPE::JSON_PROJECT:
|
2020-08-06 10:12:34 +00:00
|
|
|
can_rename = false;
|
|
|
|
can_print = false;
|
|
|
|
|
2021-01-10 13:52:56 +00:00
|
|
|
if( item->GetId() == m_TreeProject->GetRootItem() )
|
2020-08-06 10:12:34 +00:00
|
|
|
{
|
|
|
|
can_switch_to_project = false;
|
|
|
|
can_delete = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
can_create_new_directory = false;
|
|
|
|
can_open_this_directory = false;
|
|
|
|
}
|
2019-12-05 19:35:37 +00:00
|
|
|
break;
|
2019-12-06 08:34:29 +00:00
|
|
|
|
2020-10-12 22:40:17 +00:00
|
|
|
case TREE_FILE_TYPE::DIRECTORY:
|
2020-08-06 10:12:34 +00:00
|
|
|
can_switch_to_project = false;
|
|
|
|
can_edit = false;
|
|
|
|
can_rename = false;
|
|
|
|
can_print = false;
|
2019-12-05 19:35:37 +00:00
|
|
|
break;
|
2019-12-06 08:34:29 +00:00
|
|
|
|
2019-12-05 19:35:37 +00:00
|
|
|
default:
|
2020-08-06 10:12:34 +00:00
|
|
|
can_switch_to_project = false;
|
|
|
|
can_create_new_directory = false;
|
|
|
|
can_open_this_directory = false;
|
|
|
|
|
|
|
|
if( !CanPrintFile( full_file_name ) )
|
|
|
|
can_print = false;
|
|
|
|
|
2019-12-05 19:35:37 +00:00
|
|
|
break;
|
2018-10-17 19:03:33 +00:00
|
|
|
}
|
2019-12-05 19:35:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxMenu popup_menu;
|
|
|
|
wxString text;
|
|
|
|
wxString help_text;
|
|
|
|
|
|
|
|
if( can_switch_to_project )
|
|
|
|
{
|
2019-12-06 08:34:29 +00:00
|
|
|
AddMenuItem( &popup_menu, ID_PROJECT_SWITCH_TO_OTHER,
|
|
|
|
_( "Switch to this Project" ),
|
|
|
|
_( "Close all editors, and switch to the selected project" ),
|
|
|
|
KiBitmap( open_project_xpm ) );
|
2019-12-05 19:35:37 +00:00
|
|
|
popup_menu.AppendSeparator();
|
|
|
|
}
|
2018-10-17 19:03:33 +00:00
|
|
|
|
2019-12-05 19:35:37 +00:00
|
|
|
if( can_create_new_directory )
|
|
|
|
{
|
2019-12-06 08:34:29 +00:00
|
|
|
AddMenuItem( &popup_menu, ID_PROJECT_NEWDIR, _( "New Directory..." ),
|
|
|
|
_( "Create a New Directory" ), KiBitmap( directory_xpm ) );
|
2019-12-05 19:35:37 +00:00
|
|
|
}
|
2019-06-17 13:25:49 +00:00
|
|
|
|
2019-12-05 19:35:37 +00:00
|
|
|
if( can_open_this_directory )
|
|
|
|
{
|
2020-08-06 10:12:34 +00:00
|
|
|
if( selection.size() == 1 )
|
2019-12-05 19:35:37 +00:00
|
|
|
{
|
2019-07-17 10:57:12 +00:00
|
|
|
#ifdef __APPLE__
|
2019-12-05 19:35:37 +00:00
|
|
|
text = _( "Reveal in Finder" );
|
|
|
|
help_text = _( "Reveals the directory in a Finder window" );
|
2019-07-17 10:57:12 +00:00
|
|
|
#else
|
2019-12-06 08:34:29 +00:00
|
|
|
text = _( "Open Directory in File Explorer" );
|
2019-12-05 19:35:37 +00:00
|
|
|
help_text = _( "Opens the directory in the default system file manager" );
|
2019-07-17 10:57:12 +00:00
|
|
|
#endif
|
2019-12-05 19:35:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-17 10:57:12 +00:00
|
|
|
#ifdef __APPLE__
|
2019-12-05 19:35:37 +00:00
|
|
|
text = _( "Reveal in Finder" );
|
|
|
|
help_text = _( "Reveals the directories in a Finder window" );
|
2019-07-17 10:57:12 +00:00
|
|
|
#else
|
2019-12-06 08:34:29 +00:00
|
|
|
text = _( "Open Directories in File Explorer" );
|
2019-12-05 19:35:37 +00:00
|
|
|
help_text = _( "Opens the directories in the default system file manager" );
|
2019-07-17 10:57:12 +00:00
|
|
|
#endif
|
2019-12-05 19:35:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AddMenuItem( &popup_menu, ID_PROJECT_OPEN_DIR, text, help_text,
|
2020-08-09 13:37:19 +00:00
|
|
|
KiBitmap( directory_browser_xpm ) );
|
2019-12-05 19:35:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( can_edit )
|
|
|
|
{
|
2020-08-06 10:12:34 +00:00
|
|
|
if( selection.size() == 1 )
|
2019-12-05 19:35:37 +00:00
|
|
|
help_text = _( "Open the file in a Text Editor" );
|
|
|
|
else
|
2019-12-06 08:34:29 +00:00
|
|
|
help_text = _( "Open files in a Text Editor" );
|
2019-12-05 19:35:37 +00:00
|
|
|
|
2019-12-06 08:34:29 +00:00
|
|
|
AddMenuItem( &popup_menu, ID_PROJECT_TXTEDIT, _( "Edit in a Text Editor" ),
|
|
|
|
help_text, KiBitmap( editor_xpm ) );
|
2019-12-05 19:35:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( can_rename )
|
|
|
|
{
|
2020-08-06 10:12:34 +00:00
|
|
|
if( selection.size() == 1 )
|
2019-12-05 19:35:37 +00:00
|
|
|
{
|
2019-12-06 08:34:29 +00:00
|
|
|
text = _( "Rename File..." );
|
2019-12-05 19:35:37 +00:00
|
|
|
help_text = _( "Rename file" );
|
|
|
|
}
|
|
|
|
else
|
2019-08-29 20:59:49 +00:00
|
|
|
{
|
2019-12-06 08:34:29 +00:00
|
|
|
text = _( "Rename Files..." );
|
2019-12-05 19:35:37 +00:00
|
|
|
help_text = _( "Rename files" );
|
|
|
|
}
|
|
|
|
|
|
|
|
AddMenuItem( &popup_menu, ID_PROJECT_RENAME, text, help_text, KiBitmap( right_xpm ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( can_delete )
|
|
|
|
{
|
2020-08-06 10:12:34 +00:00
|
|
|
if( selection.size() == 1 )
|
2019-12-05 19:35:37 +00:00
|
|
|
help_text = _( "Delete the file and its content" );
|
|
|
|
else
|
|
|
|
help_text = _( "Delete the files and their contents" );
|
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
if( can_switch_to_project
|
|
|
|
|| can_create_new_directory
|
|
|
|
|| can_open_this_directory
|
|
|
|
|| can_edit
|
2019-12-05 19:35:37 +00:00
|
|
|
|| can_rename )
|
2020-12-02 12:35:19 +00:00
|
|
|
{
|
2019-12-05 19:35:37 +00:00
|
|
|
popup_menu.AppendSeparator();
|
2020-12-02 12:35:19 +00:00
|
|
|
}
|
2019-12-06 08:34:29 +00:00
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
AddMenuItem( &popup_menu, ID_PROJECT_DELETE, _( "Delete" ), help_text,
|
2021-01-02 20:48:43 +00:00
|
|
|
KiBitmap( trash_xpm ) );
|
2019-12-05 19:35:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( can_print )
|
|
|
|
{
|
|
|
|
popup_menu.AppendSeparator();
|
|
|
|
AddMenuItem( &popup_menu, ID_PROJECT_PRINT,
|
2019-08-29 20:59:49 +00:00
|
|
|
#ifdef __APPLE__
|
2019-12-05 19:35:37 +00:00
|
|
|
_( "Print..." ),
|
2019-08-29 20:59:49 +00:00
|
|
|
#else
|
2019-12-06 08:34:29 +00:00
|
|
|
_( "Print" ),
|
2019-08-29 20:59:49 +00:00
|
|
|
#endif
|
2019-12-05 19:35:37 +00:00
|
|
|
_( "Print the contents of the file" ), KiBitmap( print_button_xpm ) );
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 16:54:04 +00:00
|
|
|
if( popup_menu.GetMenuItemCount() > 0 )
|
|
|
|
PopupMenu( &popup_menu );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2014-07-07 19:49:14 +00:00
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
void PROJECT_TREE_PANE::onOpenSelectedFileWithTextEditor( wxCommandEvent& event )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2019-12-06 08:34:29 +00:00
|
|
|
wxString editorname = Pgm().GetEditorName();
|
|
|
|
|
|
|
|
if( editorname.IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2019-12-06 08:34:29 +00:00
|
|
|
wxString files;
|
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
for( PROJECT_TREE_ITEM* item_data : tree_data )
|
2019-12-05 19:35:37 +00:00
|
|
|
{
|
|
|
|
wxString fullFileName = item_data->GetFileName();
|
|
|
|
AddDelimiterString( fullFileName );
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2019-12-06 08:34:29 +00:00
|
|
|
if( !files.IsEmpty() )
|
|
|
|
files += " ";
|
|
|
|
|
|
|
|
files += fullFileName;
|
2019-12-05 19:35:37 +00:00
|
|
|
}
|
2019-12-06 08:34:29 +00:00
|
|
|
|
|
|
|
ExecuteFile( this, editorname, files );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
void PROJECT_TREE_PANE::onDeleteFile( wxCommandEvent& event )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2020-12-02 12:35:19 +00:00
|
|
|
std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
|
|
|
|
wxString msg, caption;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2020-04-09 16:54:04 +00:00
|
|
|
if( tree_data.size() == 1 )
|
|
|
|
{
|
|
|
|
bool is_directory = wxDirExists( tree_data[0]->GetFileName() );
|
|
|
|
caption = is_directory ? _( "Delete Directory" ) : _( "Delete File" );
|
2020-12-02 12:35:19 +00:00
|
|
|
msg = wxString::Format( _( "Are you sure you want to delete '%s'?" ),
|
|
|
|
tree_data[0]->GetFileName() );
|
2020-04-09 16:54:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-02 12:35:19 +00:00
|
|
|
msg = wxString::Format( _( "Are you sure you want to delete %lu items?" ),
|
|
|
|
tree_data.size() );
|
2020-04-09 16:54:04 +00:00
|
|
|
caption = _( "Delete Multiple Items" );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxMessageDialog dialog( m_parent, msg, caption, wxYES_NO | wxICON_QUESTION );
|
|
|
|
|
|
|
|
if( dialog.ShowModal() == wxID_YES )
|
|
|
|
{
|
2020-12-02 12:35:19 +00:00
|
|
|
for( PROJECT_TREE_ITEM* item_data : tree_data )
|
2020-04-09 16:54:04 +00:00
|
|
|
item_data->Delete();
|
|
|
|
}
|
2019-08-28 16:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
void PROJECT_TREE_PANE::onPrintFile( wxCommandEvent& event )
|
2019-08-28 16:01:06 +00:00
|
|
|
{
|
2020-12-02 12:35:19 +00:00
|
|
|
std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
for( PROJECT_TREE_ITEM* item_data : tree_data )
|
2019-12-05 19:35:37 +00:00
|
|
|
item_data->Print();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
void PROJECT_TREE_PANE::onRenameFile( wxCommandEvent& event )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2020-12-02 12:35:19 +00:00
|
|
|
wxTreeItemId curr_item = m_TreeProject->GetFocusedItem();
|
|
|
|
std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2019-12-05 19:35:37 +00:00
|
|
|
// XXX: Unnecessary?
|
|
|
|
if( tree_data.size() != 1 )
|
2009-02-04 15:25:03 +00:00
|
|
|
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-12-06 08:34:29 +00:00
|
|
|
wxString msg = wxString::Format( _( "Change filename: \"%s\"" ),
|
|
|
|
tree_data[0]->GetFileName() );
|
2019-07-17 10:57:12 +00:00
|
|
|
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
|
|
|
|
2019-12-05 19:35:37 +00:00
|
|
|
tree_data[0]->Rename( buffer, true );
|
2019-11-17 00:52:43 +00:00
|
|
|
m_isRenaming = true;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
void PROJECT_TREE_PANE::onSelect( wxTreeEvent& Event )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2020-12-02 12:35:19 +00:00
|
|
|
std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2019-12-05 19:35:37 +00:00
|
|
|
if( tree_data.size() != 1 )
|
2009-02-04 15:25:03 +00:00
|
|
|
return;
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2020-12-22 13:51:32 +00:00
|
|
|
// Bookmark the selected item but don't try and activate it until later. If we do it now,
|
|
|
|
// there will be more events at least on Windows in this frame that will steal focus from
|
|
|
|
// any newly launched windows
|
2020-10-17 03:40:27 +00:00
|
|
|
m_selectedItem = tree_data[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
void PROJECT_TREE_PANE::onIdle( wxIdleEvent& aEvent )
|
2020-10-17 03:40:27 +00:00
|
|
|
{
|
2020-12-22 13:51:32 +00:00
|
|
|
// Idle executes once all other events finished processing. This makes it ideal to launch
|
|
|
|
// a new window without starting Focus wars.
|
2021-01-08 16:40:29 +00:00
|
|
|
if( m_watcherNeedReset )
|
|
|
|
{
|
|
|
|
m_selectedItem = nullptr;
|
|
|
|
FileWatcherReset();
|
|
|
|
}
|
|
|
|
|
2020-10-17 03:40:27 +00:00
|
|
|
if( m_selectedItem != nullptr )
|
|
|
|
{
|
2020-12-22 13:51:32 +00:00
|
|
|
// Activate launches a window which may run the event loop on top of us and cause OnIdle
|
|
|
|
// to get called again, so be sure to block off the activation condition first.
|
2020-12-04 02:06:10 +00:00
|
|
|
PROJECT_TREE_ITEM* item = m_selectedItem;
|
|
|
|
m_selectedItem = nullptr;
|
|
|
|
|
|
|
|
item->Activate( this );
|
2020-10-17 03:40:27 +00:00
|
|
|
}
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
2010-02-20 13:20:55 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
void PROJECT_TREE_PANE::onExpand( wxTreeEvent& Event )
|
2010-02-20 13:20:55 +00:00
|
|
|
{
|
2020-12-02 12:35:19 +00:00
|
|
|
wxTreeItemId itemId = Event.GetItem();
|
|
|
|
PROJECT_TREE_ITEM* tree_data = GetItemIdData( itemId );
|
2010-02-20 13:20:55 +00:00
|
|
|
|
|
|
|
if( !tree_data )
|
|
|
|
return;
|
|
|
|
|
2020-10-12 22:40:17 +00:00
|
|
|
if( tree_data->GetType() != TREE_FILE_TYPE::DIRECTORY )
|
2010-02-20 13:20:55 +00:00
|
|
|
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 );
|
|
|
|
|
2019-09-05 16:57:30 +00:00
|
|
|
#ifndef __WINDOWS__
|
|
|
|
bool subdir_populated = false;
|
|
|
|
#endif
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
for( ; kid.IsOk(); kid = m_TreeProject->GetNextChild( itemId, cookie ) )
|
|
|
|
{
|
2020-12-02 12:35:19 +00:00
|
|
|
PROJECT_TREE_ITEM* itemData = GetItemIdData( kid );
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2020-10-12 22:40:17 +00:00
|
|
|
if( !itemData || itemData->GetType() != TREE_FILE_TYPE::DIRECTORY )
|
2010-02-20 13:20:55 +00:00
|
|
|
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
|
|
|
{
|
2020-12-22 13:51:32 +00:00
|
|
|
std::vector<wxString> projects = getProjects( dir );
|
|
|
|
wxString dir_filename;
|
|
|
|
bool haveFile = dir.GetFirst( &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
|
|
|
|
2020-12-22 13:51:32 +00:00
|
|
|
while( haveFile )
|
2010-02-20 13:20:55 +00:00
|
|
|
{
|
2020-12-22 13:51:32 +00:00
|
|
|
// Add name to tree item, but do not recurse in subdirs:
|
|
|
|
wxString name = fileName + wxFileName::GetPathSeparator() + dir_filename;
|
|
|
|
addItemToProjectTree( name, kid, &projects, false );
|
|
|
|
|
|
|
|
haveFile = dir.GetNext( &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
|
|
|
}
|
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
|
2019-09-05 16:57:30 +00:00
|
|
|
#ifndef __WINDOWS__
|
|
|
|
subdir_populated = true;
|
|
|
|
#endif
|
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
|
|
|
|
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 )
|
2021-01-08 16:40:29 +00:00
|
|
|
m_watcherNeedReset = true;
|
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
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
std::vector<PROJECT_TREE_ITEM*> PROJECT_TREE_PANE::GetSelectedData()
|
2010-02-20 13:20:55 +00:00
|
|
|
{
|
2019-12-05 19:35:37 +00:00
|
|
|
wxArrayTreeItemIds selection;
|
2020-12-02 12:35:19 +00:00
|
|
|
std::vector<PROJECT_TREE_ITEM*> data;
|
2019-12-05 19:35:37 +00:00
|
|
|
|
|
|
|
m_TreeProject->GetSelections( selection );
|
|
|
|
|
|
|
|
for( auto it = selection.begin(); it != selection.end(); it++ )
|
|
|
|
data.push_back( GetItemIdData( *it ) );
|
|
|
|
|
|
|
|
return data;
|
2010-02-20 13:20:55 +00:00
|
|
|
}
|
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
PROJECT_TREE_ITEM* PROJECT_TREE_PANE::GetItemIdData( wxTreeItemId aId )
|
2010-02-20 13:20:55 +00:00
|
|
|
{
|
2020-12-02 12:35:19 +00:00
|
|
|
return dynamic_cast<PROJECT_TREE_ITEM*>( m_TreeProject->GetItemData( aId ) );
|
2010-02-20 13:20:55 +00:00
|
|
|
}
|
|
|
|
|
2014-07-07 19:49:14 +00:00
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
wxTreeItemId PROJECT_TREE_PANE::findSubdirTreeItem( const wxString& aSubDir )
|
2012-12-31 08:12:29 +00:00
|
|
|
{
|
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
|
|
|
|
2019-12-05 19:35:37 +00:00
|
|
|
if( ! kid.IsOk() )
|
2012-12-31 08:12:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
PROJECT_TREE_ITEM* itemData = GetItemIdData( kid );
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2020-10-12 22:40:17 +00:00
|
|
|
if( itemData && ( itemData->GetType() == TREE_FILE_TYPE::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
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
void PROJECT_TREE_PANE::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:
|
2019-11-17 00:52:43 +00:00
|
|
|
{
|
2020-12-22 13:51:32 +00:00
|
|
|
wxTreeItemId newitem = addItemToProjectTree( pathModified.GetFullPath(), root_id,
|
|
|
|
nullptr, true );
|
2019-11-17 00:52:43 +00:00
|
|
|
|
|
|
|
// If we are in the process of renaming a file, select the new one
|
2019-11-17 01:51:54 +00:00
|
|
|
// This is needed for MSW and OSX, since we don't get RENAME events from them, just a
|
|
|
|
// pair of DELETE and CREATE events.
|
2019-11-17 00:52:43 +00:00
|
|
|
if( m_isRenaming && newitem.IsOk() )
|
|
|
|
{
|
|
|
|
m_TreeProject->SelectItem( newitem );
|
|
|
|
m_isRenaming = 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
|
|
|
break;
|
|
|
|
|
|
|
|
case wxFSW_EVENT_DELETE:
|
|
|
|
while( kid.IsOk() )
|
|
|
|
{
|
2020-12-02 12:35:19 +00:00
|
|
|
PROJECT_TREE_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
|
|
|
|
2020-05-16 11:05:53 +00:00
|
|
|
if( itemData && itemData->GetFileName() == 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
|
|
|
{
|
|
|
|
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();
|
2019-11-16 01:35:48 +00:00
|
|
|
wxString newdir = newpath.GetPath();
|
2017-09-22 17:11:11 +00:00
|
|
|
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
|
|
|
{
|
2020-12-02 12:35:19 +00:00
|
|
|
PROJECT_TREE_ITEM* itemData = GetItemIdData( kid );
|
2013-01-02 21:49:56 +00:00
|
|
|
|
2020-05-16 11:05:53 +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
|
|
|
|
2020-05-16 11:05:53 +00:00
|
|
|
// Add the new item only if it is not the current project file (root item).
|
|
|
|
// Remember: this code is called by a wxFileSystemWatcherEvent event, and not always
|
|
|
|
// called after an actual file rename, and the cleanup code does not explore the
|
2020-12-22 13:51:32 +00:00
|
|
|
// root item, because it cannot be renamed by the user. Also, ensure the new file
|
|
|
|
// actually exists on the file system before it is readded. On Linux, moving a file
|
|
|
|
// to the trash can cause the same path to be returned in both the old and new paths
|
|
|
|
// of the event, even though the file isn't there anymore.
|
2020-12-02 12:35:19 +00:00
|
|
|
PROJECT_TREE_ITEM* rootData = GetItemIdData( root_id );
|
2019-11-17 00:52:43 +00:00
|
|
|
|
2020-10-13 15:04:49 +00:00
|
|
|
if( newpath.Exists() && ( newfn != rootData->GetFileName() ) )
|
2020-05-16 11:05:53 +00:00
|
|
|
{
|
|
|
|
wxTreeItemId newroot_id = findSubdirTreeItem( newdir );
|
2020-12-22 13:51:32 +00:00
|
|
|
wxTreeItemId newitem = addItemToProjectTree( newfn, newroot_id, nullptr, true );
|
2020-05-16 11:05:53 +00:00
|
|
|
|
|
|
|
// If the item exists, select it
|
|
|
|
if( newitem.IsOk() )
|
|
|
|
m_TreeProject->SelectItem( newitem );
|
|
|
|
}
|
2019-11-17 01:51:54 +00:00
|
|
|
|
|
|
|
m_isRenaming = 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
|
|
|
}
|
|
|
|
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
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
void PROJECT_TREE_PANE::FileWatcherReset()
|
2012-12-31 08:12:29 +00:00
|
|
|
{
|
2021-01-08 16:40:29 +00:00
|
|
|
m_watcherNeedReset = false;
|
|
|
|
|
2020-12-16 00:36:12 +00:00
|
|
|
wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
|
|
|
|
|
|
|
|
#if defined( _WIN32 )
|
|
|
|
if( KIPLATFORM::ENV::IsNetworkPath( prj_dir ) )
|
|
|
|
{
|
2020-12-22 13:51:32 +00:00
|
|
|
// Due to a combination of a bug in SAMBA sending bad change event IDs and wxWidgets
|
|
|
|
// choosing to fault on an invalid event ID instead of sanely ignoring them we need to
|
|
|
|
// avoid spawning a filewatcher. Unforunately this punishes corporate environments with
|
|
|
|
// Windows Server shares :/
|
2020-12-16 00:36:12 +00:00
|
|
|
m_Parent->SetStatusText( _( "Network path: not monitoring folder changes" ), 0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_Parent->SetStatusText( _( "Local path: monitoring folder changes" ), 0 );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
// 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
|
|
|
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
|
|
|
|
2020-08-27 00:46:20 +00:00
|
|
|
if( m_TreeProject->IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
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
|
2020-12-02 12:35:19 +00:00
|
|
|
{
|
2013-01-01 14:06:49 +00:00
|
|
|
break;
|
2020-12-02 12:35:19 +00:00
|
|
|
}
|
2013-01-01 14:06:49 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
PROJECT_TREE_ITEM* itemData = GetItemIdData( kid );
|
2013-01-01 14:06:49 +00:00
|
|
|
|
2020-10-13 00:23:04 +00:00
|
|
|
if( itemData && itemData->GetType() == TREE_FILE_TYPE::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
|
|
|
|
2020-12-22 13:51:32 +00:00
|
|
|
if( wxFileName::IsDirReadable( path ) ) // linux whines about watching protected dir
|
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
|
|
|
{
|
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
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
void PROJECT_TREE_PANE::EmptyTreePrj()
|
2020-08-08 18:52:14 +00:00
|
|
|
{
|
|
|
|
m_TreeProject->DeleteAllItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|