2008-11-02 14:54:53 +00:00
|
|
|
/**
|
2010-12-14 10:56:30 -05:00
|
|
|
* @file tree_project_frame.cpp
|
2012-08-29 14:40:09 +02:00
|
|
|
* @brief Function to build the tree of files in the current project directory
|
2008-11-02 14:54:53 +00:00
|
|
|
*/
|
|
|
|
|
2012-08-29 14:40:09 +02: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
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2012-01-22 22:33:36 -06:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <gestfich.h>
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-19 19:42:08 -05:00
|
|
|
#include <pgm_base.h>
|
2012-04-16 14:56:01 +02:00
|
|
|
#include <macros.h>
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2012-01-22 22:33:36 -06:00
|
|
|
#include <tree_project_frame.h>
|
|
|
|
#include <class_treeprojectfiles.h>
|
|
|
|
#include <class_treeproject_item.h>
|
2012-02-16 21:03:33 +01:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2012-01-22 22:33:36 -06:00
|
|
|
#include <wx/regex.h>
|
|
|
|
#include <wx/dir.h>
|
|
|
|
#include <wx/imaglist.h>
|
2012-04-09 11:16:47 +02:00
|
|
|
#include <menus_helpers.h>
|
2012-12-31 09:12:29 +01:00
|
|
|
#include <stack>
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
/* Note about the tree project build process:
|
2010-02-17 17:47:12 +00:00
|
|
|
* Building the tree project can be *very* long if there are a lot of subdirectories
|
|
|
|
* in the working directory.
|
2010-05-29 20:34:18 +02:00
|
|
|
* Unfortunately, this happens easily if the project file *.pro is in the home directory
|
2010-02-20 13:20:55 +00:00
|
|
|
* So the tree project is built "on demand":
|
|
|
|
* First the tree is built from the current directory and shows files and subdirs.
|
|
|
|
* > First level subdirs trees are built (i.e subdirs contents are not read)
|
|
|
|
* > When expanding a subdir, each subdir contains is read,
|
|
|
|
* and the corresponding sub tree is populated on the fly.
|
2010-02-17 17:47:12 +00:00
|
|
|
*/
|
|
|
|
|
2008-05-30 18:06:21 +00:00
|
|
|
// list of files extensions listed in the tree project window
|
2009-02-04 15:25:03 +00:00
|
|
|
// *.sch files are always allowed, do not add here
|
2008-05-30 18:06:21 +00:00
|
|
|
// Add extensions in a compatible regex format to see others files types
|
2012-08-29 14:40:09 +02:00
|
|
|
static const wxChar* s_allowedExtensionsToList[] =
|
2008-05-30 18:06:21 +00:00
|
|
|
{
|
|
|
|
wxT( "^.*\\.pro$" ),
|
|
|
|
wxT( "^.*\\.pdf$" ),
|
2012-04-16 14:56:01 +02:00
|
|
|
wxT( "^[^$].*\\.brd$" ), // Legacy Pcbnew files
|
2012-12-14 20:37:51 +01:00
|
|
|
wxT( "^[^$].*\\.kicad_pcb$" ), // S format Pcbnew files
|
2013-07-19 20:27:22 +02:00
|
|
|
wxT( "^[^$].*\\.kicad_wks$" ), // S format kicad page layout descr files
|
2008-05-30 18:06:21 +00:00
|
|
|
wxT( "^.*\\.net$" ),
|
|
|
|
wxT( "^.*\\.txt$" ),
|
2014-06-30 12:00:21 +02:00
|
|
|
wxT( "^.*\\.pho$" ), // Gerber file (Old Kicad extension)
|
2011-08-19 15:08:24 +02:00
|
|
|
wxT( "^.*\\.gbr$" ), // Gerber file
|
|
|
|
wxT( "^.*\\.gb[alops]$" ), // Gerber back (or bottom) layer file
|
|
|
|
wxT( "^.*\\.gt[alops]$" ), // Gerber front (or top) layer file
|
|
|
|
wxT( "^.*\\.g[0-9]{1,2}$" ), // Gerber inner layer file
|
2008-05-30 18:06:21 +00:00
|
|
|
wxT( "^.*\\.odt$" ),
|
|
|
|
wxT( "^.*\\.sxw$" ),
|
|
|
|
wxT( "^.*\\.htm$" ),
|
|
|
|
wxT( "^.*\\.html$" ),
|
2012-12-31 09:12:29 +01:00
|
|
|
wxT( "^.*\\.rpt$" ), // Report files
|
|
|
|
wxT( "^.*\\.csv$" ), // Report files in comma separateed format
|
|
|
|
wxT( "^.*\\.pos$" ), // Footprint position files
|
|
|
|
wxT( "^.*\\.cmp$" ), // Cvpcb cmp/footprint link files
|
|
|
|
wxT( "^.*\\.drl$" ), // Excellon drill files
|
|
|
|
wxT( "^.*\\.svg$" ), // SVG print/plot files
|
|
|
|
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 14:15:37 -04:00
|
|
|
* in any of the other KiCad programs and move them into the common
|
2012-08-29 14:40:09 +02:00
|
|
|
* library as required.
|
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
/* File extension definitions. */
|
2014-04-14 13:49:52 -05:00
|
|
|
const wxChar TextFileExtension[] = wxT( "txt" );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
/* File wildcard definitions. */
|
2014-04-14 13:49:52 -05:00
|
|
|
const wxChar TextFileWildcard[] = wxT( "Text files (*.txt)|*.txt" );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
/**
|
2010-02-20 13:20:55 +00:00
|
|
|
* @brief class TREE_PROJECT_FRAME is the frame that shows the tree list
|
|
|
|
* of files and subdirs inside the working directory
|
2012-08-29 14:40:09 +02:00
|
|
|
* 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
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
BEGIN_EVENT_TABLE( TREE_PROJECT_FRAME, wxSashLayoutWindow )
|
2012-12-31 09:12:29 +01:00
|
|
|
EVT_TREE_ITEM_ACTIVATED( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnSelect )
|
|
|
|
EVT_TREE_ITEM_EXPANDED( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnExpand )
|
|
|
|
EVT_TREE_ITEM_RIGHT_CLICK( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnRight )
|
|
|
|
EVT_MENU( ID_PROJECT_TXTEDIT, TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor )
|
|
|
|
EVT_MENU( ID_PROJECT_NEWDIR, TREE_PROJECT_FRAME::OnCreateNewDirectory )
|
|
|
|
EVT_MENU( ID_PROJECT_DELETE, TREE_PROJECT_FRAME::OnDeleteFile )
|
|
|
|
EVT_MENU( ID_PROJECT_RENAME, TREE_PROJECT_FRAME::OnRenameFile )
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
/******************************************************************/
|
2011-04-17 15:54:17 +02:00
|
|
|
TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ) :
|
2009-02-04 15:25:03 +00:00
|
|
|
wxSashLayoutWindow( parent,
|
|
|
|
ID_LEFT_FRAME,
|
2009-11-18 20:12:11 +00:00
|
|
|
wxDefaultPosition,
|
|
|
|
wxDefaultSize,
|
2009-02-04 15:25:03 +00:00
|
|
|
wxNO_BORDER | wxSW_3D )
|
2007-05-28 18:09:49 +00:00
|
|
|
/******************************************************************/
|
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
m_Parent = parent;
|
|
|
|
m_TreeProject = NULL;
|
2013-01-01 15:06:49 +01:00
|
|
|
#ifdef KICAD_USE_FILES_WATCHER
|
|
|
|
m_watcher = NULL;
|
2012-12-31 09:12:29 +01:00
|
|
|
Connect( wxEVT_FSWATCHER,
|
|
|
|
wxFileSystemWatcherEventHandler( TREE_PROJECT_FRAME::OnFileSystemEvent ) );
|
|
|
|
#endif
|
2009-02-04 15:25:03 +00:00
|
|
|
/*
|
|
|
|
* Filtering is now inverted: the filters are actually used to _enable_ support
|
|
|
|
* for a given file type.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// NOTE: sch filter must be first because of a test in AddFile() below
|
2012-12-31 09:12:29 +01:00
|
|
|
m_filters.push_back( wxT( "^.*\\.sch$" ) );
|
|
|
|
|
2012-08-29 14:40:09 +02:00
|
|
|
for( int ii = 0; s_allowedExtensionsToList[ii] != NULL; ii++ )
|
2012-12-31 09:12:29 +01:00
|
|
|
m_filters.push_back( s_allowedExtensionsToList[ii] );
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
m_filters.push_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 00:58:45 -05:00
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
TREE_PROJECT_FRAME::~TREE_PROJECT_FRAME()
|
2009-05-21 17:42:42 +00:00
|
|
|
{
|
2013-01-01 15:06:49 +01:00
|
|
|
#ifdef KICAD_USE_FILES_WATCHER
|
2012-12-31 09:12:29 +01:00
|
|
|
delete m_watcher;
|
|
|
|
#endif
|
2009-05-21 17:42:42 +00:00
|
|
|
}
|
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::RemoveFilter( const wxString& filter )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
for( unsigned int i = 0; i < m_filters.size(); i++ )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
if( filter == m_filters[i] )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
m_filters.erase( m_filters.begin() + i );
|
2007-05-28 18:09:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
/**
|
2012-04-16 14:56:01 +02:00
|
|
|
* Called by the popup menu in the tree frame
|
2012-12-31 09:12:29 +01:00
|
|
|
* Creates a new subdirectory inside the current kicad project directory
|
2012-04-16 14:56:01 +02:00
|
|
|
* the user is prompted to enter a directory name
|
2008-11-02 14:54:53 +00:00
|
|
|
*/
|
2012-04-16 14:56:01 +02:00
|
|
|
void TREE_PROJECT_FRAME::OnCreateNewDirectory( wxCommandEvent& event )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2012-04-16 14:56:01 +02:00
|
|
|
// Get the root directory name:
|
|
|
|
TREEPROJECT_ITEM* treeData = GetSelectedData();
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( !treeData )
|
|
|
|
return;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
TreeFileType rootType = treeData->GetType();
|
|
|
|
wxTreeItemId root;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( TREE_DIRECTORY == rootType )
|
|
|
|
{
|
|
|
|
root = m_TreeProject->GetSelection();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
root = m_TreeProject->GetItemParent( m_TreeProject->GetSelection() );
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( !root.IsOk() )
|
|
|
|
root = m_TreeProject->GetSelection();
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2012-04-16 14:56:01 +02:00
|
|
|
// Ask for the new sub directory name
|
|
|
|
wxString curr_dir = treeData->GetDir();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2012-04-16 14:56:01 +02:00
|
|
|
// Make the current subdir relative to the current path:
|
2012-12-31 09:12:29 +01:00
|
|
|
if( !curr_dir.IsEmpty() ) // A subdir is selected
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
curr_dir += wxFileName::GetPathSeparator();
|
|
|
|
curr_dir += wxT( "dummy" );
|
|
|
|
wxFileName fn( curr_dir );
|
2012-04-16 14:56:01 +02:00
|
|
|
fn.MakeRelativeTo();
|
|
|
|
curr_dir = fn.GetPath() + wxFileName::GetPathSeparator();
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2012-12-31 09:12:29 +01:00
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( wxT( "Current working directory:\n%s" ), GetChars( wxGetCwd() ) );
|
|
|
|
wxString subdir = wxGetTextFromUser( msg, _( "Create New Directory" ), curr_dir );
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2012-04-16 14:56:01 +02:00
|
|
|
if( subdir.IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( wxMkdir( subdir ) )
|
2013-01-03 20:25:12 +01:00
|
|
|
{
|
|
|
|
#ifndef KICAD_USE_FILES_WATCHER
|
2012-12-31 09:12:29 +01:00
|
|
|
AddItemToTreeProject( subdir, root );
|
2013-01-03 20:25:12 +01:00
|
|
|
#endif
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
wxString TREE_PROJECT_FRAME::GetFileExt( TreeFileType type )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
wxString ext;
|
|
|
|
|
|
|
|
switch( type )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
case TREE_PROJECT:
|
|
|
|
ext = ProjectFileExtension;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_SCHEMA:
|
|
|
|
ext = SchematicFileExtension;
|
|
|
|
break;
|
|
|
|
|
2012-04-16 14:56:01 +02:00
|
|
|
case TREE_LEGACY_PCB:
|
2012-12-14 10:54:54 -06:00
|
|
|
ext = LegacyPcbFileExtension;
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2012-04-16 14:56:01 +02:00
|
|
|
case TREE_SEXP_PCB:
|
2012-12-14 10:54:54 -06:00
|
|
|
ext = KiCadPcbFileExtension;
|
2012-04-16 14:56:01 +02:00
|
|
|
break;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
case TREE_GERBER:
|
|
|
|
ext = GerberFileExtension;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_PDF:
|
|
|
|
ext = PdfFileExtension;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_TXT:
|
|
|
|
ext = TextFileExtension;
|
2008-11-02 14:54:53 +00:00
|
|
|
break;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
case TREE_NET:
|
|
|
|
ext = NetlistFileExtension;
|
|
|
|
break;
|
2012-02-16 21:03:33 +01:00
|
|
|
|
|
|
|
case TREE_CMP_LINK:
|
|
|
|
ext = ComponentFileExtension;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_REPORT:
|
|
|
|
ext = ReportFileExtension;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_FP_PLACE:
|
|
|
|
ext = FootprintPlaceFileExtension;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_DRILL:
|
|
|
|
ext = DrillFileExtension;
|
|
|
|
break;
|
|
|
|
|
2012-08-29 14:40:09 +02:00
|
|
|
case TREE_SVG:
|
|
|
|
ext = SVGFileExtension;
|
|
|
|
break;
|
|
|
|
|
2013-07-19 20:27:22 +02:00
|
|
|
case TREE_PAGE_LAYOUT_DESCR:
|
|
|
|
ext = PageLayoutDescrFileExtension;
|
|
|
|
break;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
default: /* Eliminates unnecessary GCC warning. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/*
|
|
|
|
* Return the wxFileDialog wildcard string for the selected file type.
|
|
|
|
*/
|
2010-02-19 15:01:32 +00:00
|
|
|
wxString TREE_PROJECT_FRAME::GetFileWildcard( TreeFileType type )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
wxString ext;
|
|
|
|
|
|
|
|
switch( type )
|
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
case TREE_PROJECT:
|
2009-04-05 20:49:15 +00:00
|
|
|
ext = ProjectFileWildcard;
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_SCHEMA:
|
2009-04-05 20:49:15 +00:00
|
|
|
ext = SchematicFileWildcard;
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
|
|
|
|
2012-04-16 14:56:01 +02:00
|
|
|
case TREE_LEGACY_PCB:
|
|
|
|
case TREE_SEXP_PCB:
|
2010-05-17 16:35:46 -04:00
|
|
|
ext = PcbFileWildcard;
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_GERBER:
|
2009-04-05 20:49:15 +00:00
|
|
|
ext = GerberFileWildcard;
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_PDF:
|
2009-04-05 20:49:15 +00:00
|
|
|
ext = PdfFileWildcard;
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_TXT:
|
2009-04-05 20:49:15 +00:00
|
|
|
ext = TextFileWildcard;
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_NET:
|
2009-04-05 20:49:15 +00:00
|
|
|
ext = NetlistFileWildcard;
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
2012-02-16 21:03:33 +01:00
|
|
|
|
|
|
|
case TREE_CMP_LINK:
|
|
|
|
ext = ComponentFileWildcard;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_REPORT:
|
|
|
|
ext = ReportFileWildcard;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_FP_PLACE:
|
|
|
|
ext = FootprintPlaceFileWildcard;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_DRILL:
|
|
|
|
ext = DrillFileWildcard;
|
|
|
|
break;
|
|
|
|
|
2012-08-29 14:40:09 +02:00
|
|
|
case TREE_SVG:
|
|
|
|
ext = SVGFileWildcard;
|
|
|
|
break;
|
|
|
|
|
2013-07-19 20:27:22 +02:00
|
|
|
case TREE_PAGE_LAYOUT_DESCR:
|
|
|
|
ext = PageLayoutDescrFileWildcard;
|
|
|
|
break;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
default: /* Eliminates unnecessary GCC warning. */
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ext;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2010-11-12 10:36:43 -06:00
|
|
|
/**
|
2012-12-31 09:12:29 +01:00
|
|
|
* Function AddItemToTreeProject
|
2008-11-02 14:54:53 +00:00
|
|
|
* @brief Add filename "name" to the tree \n
|
|
|
|
* if name is a directory, add the sub directory file names
|
2010-02-20 13:20:55 +00:00
|
|
|
* @param aName = the filename or the dirctory name to add
|
|
|
|
* @param aRoot = the wxTreeItemId item where to add sub tree items
|
2012-12-31 09:12:29 +01:00
|
|
|
* @param aRecurse = true to add file or subdir names to the current tree item
|
2010-02-20 13:20:55 +00:00
|
|
|
* false to stop file add.
|
|
|
|
* @return true if the file (or directory) is added.
|
2007-09-13 11:55:46 +00:00
|
|
|
*/
|
2012-12-31 09:12:29 +01:00
|
|
|
bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName,
|
|
|
|
wxTreeItemId& aRoot, bool aRecurse )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
wxTreeItemId cellule;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
// Check the file type
|
2012-12-31 09:12:29 +01:00
|
|
|
TreeFileType type = TREE_UNKNOWN;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2010-02-17 17:47:12 +00:00
|
|
|
// Skip not visible files and dirs
|
2012-12-31 09:12:29 +01:00
|
|
|
wxFileName fn( aName );
|
|
|
|
|
2010-02-17 17:47:12 +00:00
|
|
|
// Files/dirs names starting by "." are not visible files under unices.
|
|
|
|
// Skip them also under Windows
|
2012-12-31 09:12:29 +01:00
|
|
|
if( fn.GetName().StartsWith( wxT( "." ) ) )
|
2010-02-17 17:47:12 +00:00
|
|
|
return false;
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
if( wxDirExists( aName ) )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
type = TREE_DIRECTORY;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
// Filter
|
2009-02-04 15:25:03 +00:00
|
|
|
wxRegEx reg;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
bool isSchematic = false;
|
|
|
|
bool addFile = false;
|
2012-12-31 09:12:29 +01:00
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_filters.size(); i++ )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
wxCHECK2_MSG( reg.Compile( m_filters[i], wxRE_ICASE ), continue,
|
|
|
|
wxT( "Regular expression " ) + m_filters[i] +
|
2012-06-09 13:00:13 -04:00
|
|
|
wxT( " failed to compile." ) );
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
if( reg.Matches( aName ) )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
addFile = true;
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( i==0 )
|
|
|
|
isSchematic = true;
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2009-10-26 21:25:23 +00:00
|
|
|
break;
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !addFile )
|
modified the treeprj so that, instead of recursively scanning and adding
*all* the nested files and directories within the current working directory, it scans the first
level of files and directories. When a user double-clicks on a folder, *then*
the childeren of that directory are added to the wxTreeCtrl. This means that the little
triangle does not appear until the user opens a directory .. but, i think this is
a worthwile price to pay given below.
This prevents (or at least mitigates) memory overflow in the case that kicad starts in root, or,
in my case, it starts in my home directory, where thanks to wine & other sw,
there are far too many directories.
also modified the TreePrjItemData so that it stores the full pathnames in m_FileName,
not paths relative to the CWD. I'm not sure if this is the correct thing to do,
especially with the python interface, so change it back if it is more complicated.
the move and rename commands threw a segfault on my system
(Debian etch, wxWidgets 2.8.7),
and since there are better ways to rename and move files, this functionality
was disabled until somebody can fix it (alas, I don't have time for this now)
2007-12-16 18:44:12 +00:00
|
|
|
return false;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2011-09-30 14:15:37 -04:00
|
|
|
// only show the schematic if it is a top level schematic. Eeschema
|
2007-09-13 11:55:46 +00:00
|
|
|
// cannot open a schematic and display it properly unless it starts
|
|
|
|
// at the top of the hierarchy. The schematic is top level only if
|
|
|
|
// there is a line in the header saying:
|
|
|
|
// "Sheet 1 "
|
2013-01-03 20:25:12 +01:00
|
|
|
// However if the file has the same name as the project, it is always
|
|
|
|
// shown, because it is expected the root sheet.
|
|
|
|
// (and to fix an issue (under XP but could exist under other OS),
|
|
|
|
// when a .sch file is created, the file
|
|
|
|
// create is sent to the wxFileSystemWatcher, but the file still has 0 byte
|
|
|
|
// so it cannot detected as root sheet
|
|
|
|
// This is an ugly fix.
|
2007-09-13 11:55:46 +00:00
|
|
|
if( isSchematic )
|
|
|
|
{
|
2013-01-03 20:25:12 +01:00
|
|
|
wxString fullFileName = aName.BeforeLast( '.' );
|
|
|
|
wxString rootName;
|
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( m_root );
|
|
|
|
if( itemData )
|
|
|
|
rootName = itemData->m_FileName.BeforeLast( '.' );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2013-01-03 20:25:12 +01:00
|
|
|
if( fullFileName != rootName )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2013-01-03 20:25:12 +01:00
|
|
|
char line[128]; // small because we just need a few bytes from the start of a line
|
|
|
|
FILE* fp;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2013-01-03 20:25:12 +01:00
|
|
|
fullFileName = aName;
|
|
|
|
fp = wxFopen( fullFileName, wxT( "rt" ) );
|
2009-10-26 21:25:23 +00:00
|
|
|
|
2013-01-03 20:25:12 +01:00
|
|
|
if( fp == NULL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
addFile = false;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2013-01-03 20:25:12 +01:00
|
|
|
// check the first 100 lines for the "Sheet 1" string
|
|
|
|
for( int i = 0; i<100; ++i )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2013-01-03 20:25:12 +01:00
|
|
|
if( !fgets( line, sizeof(line), fp ) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( !strncmp( line, "Sheet 1 ", 8 ) )
|
|
|
|
{
|
|
|
|
addFile = true;
|
|
|
|
break;
|
|
|
|
}
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
|
|
|
|
2013-01-03 20:25:12 +01:00
|
|
|
fclose( fp );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2013-01-03 20:25:12 +01:00
|
|
|
if( !addFile )
|
|
|
|
return false; // it is a non-top-level schematic
|
|
|
|
}
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
for( int i = TREE_PROJECT; i < TREE_MAX; i++ )
|
|
|
|
{
|
|
|
|
wxString ext = GetFileExt( (TreeFileType) i );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( ext == wxT( "" ) )
|
|
|
|
continue;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
reg.Compile( wxString::FromAscii( "^.*\\" ) + ext +
|
|
|
|
wxString::FromAscii( "$" ), wxRE_ICASE );
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
if( reg.Matches( aName ) )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
type = (TreeFileType) i;
|
2007-05-28 18:09:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
// also check to see if it is already there.
|
|
|
|
wxTreeItemIdValue cookie;
|
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( aRoot, cookie );
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
while( kid.IsOk() )
|
|
|
|
{
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( itemData )
|
|
|
|
{
|
2010-02-20 13:20:55 +00:00
|
|
|
if( itemData->m_FileName == aName )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
return true; // well, we would have added it, but it is already here!
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
kid = m_TreeProject->GetNextChild( aRoot, cookie );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
// Append the item (only appending the filename not the full path):
|
2012-12-31 09:12:29 +01:00
|
|
|
wxString file = wxFileNameFromPath( aName );
|
2010-02-20 13:20:55 +00:00
|
|
|
cellule = m_TreeProject->AppendItem( aRoot, file );
|
2012-12-31 09:12:29 +01:00
|
|
|
TREEPROJECT_ITEM* data = new TREEPROJECT_ITEM( type, aName, m_TreeProject );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
m_TreeProject->SetItemData( cellule, data );
|
|
|
|
data->SetState( 0 );
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
/* Mark root files (files which have the same aName as the project) */
|
2012-12-31 09:12:29 +01:00
|
|
|
wxFileName project( m_Parent->m_ProjectFileName );
|
|
|
|
wxFileName currfile( file );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
if( currfile.GetName().CmpNoCase( project.GetName() ) == 0 )
|
|
|
|
data->m_IsRootFile = true;
|
|
|
|
else
|
|
|
|
data->m_IsRootFile = false;
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
// This section adds dirs and files found in the subdirs
|
|
|
|
// in this case AddFile is recursive, but for the first level only.
|
|
|
|
if( TREE_DIRECTORY == type && aRecurse )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
const wxString sep = wxFileName().GetPathSeparator();
|
|
|
|
wxDir dir( aName );
|
|
|
|
wxString dir_filename;
|
2010-02-20 13:20:55 +00:00
|
|
|
data->m_WasPopulated = true; // set state to populated
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2008-05-16 11:38:35 +00:00
|
|
|
if( dir.GetFirst( &dir_filename ) )
|
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
do // Add name in tree, but do not recurse
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
AddItemToTreeProject( aName + sep + dir_filename, cellule, false );
|
2009-02-04 15:25:03 +00:00
|
|
|
} while( dir.GetNext( &dir_filename ) );
|
2008-05-16 11:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort filenames by alphabetic order */
|
|
|
|
m_TreeProject->SortChildren( cellule );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
return true;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
/**
|
|
|
|
* @brief Create or modify the tree showing project file names
|
2007-09-13 11:55:46 +00:00
|
|
|
*/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::ReCreateTreePrj()
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
wxTreeItemId rootcellule;
|
|
|
|
wxFileName fn;
|
|
|
|
bool prjOpened = false;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !m_TreeProject )
|
2010-02-19 15:01:32 +00:00
|
|
|
m_TreeProject = new TREEPROJECTFILES( this );
|
2007-09-13 11:55:46 +00:00
|
|
|
else
|
|
|
|
m_TreeProject->DeleteAllItems();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( !m_Parent->m_ProjectFileName.IsOk() )
|
|
|
|
{
|
|
|
|
fn.Clear();
|
|
|
|
fn.SetPath( ::wxGetCwd() );
|
2010-02-24 15:33:03 +00:00
|
|
|
fn.SetName( NAMELESS_PROJECT );
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetExt( ProjectFileExtension );
|
|
|
|
}
|
2007-09-13 11:55:46 +00:00
|
|
|
else
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = m_Parent->m_ProjectFileName;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
prjOpened = fn.FileExists();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
// root tree:
|
2009-04-05 20:49:15 +00:00
|
|
|
m_root = rootcellule = m_TreeProject->AddRoot( fn.GetFullName(),
|
2009-02-04 15:25:03 +00:00
|
|
|
TREE_PROJECT - 1,
|
|
|
|
TREE_PROJECT - 1 );
|
|
|
|
|
2012-01-22 11:20:22 -06:00
|
|
|
m_TreeProject->SetItemBold( rootcellule, true );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
m_TreeProject->SetItemData( rootcellule,
|
2010-02-20 13:20:55 +00:00
|
|
|
new TREEPROJECT_ITEM( TREE_PROJECT,
|
2013-01-03 20:25:12 +01:00
|
|
|
fn.GetFullPath(),
|
2012-12-31 09:12:29 +01:00
|
|
|
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 )
|
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
wxString filename;
|
|
|
|
wxDir dir( wxGetCwd() );
|
|
|
|
bool cont = dir.GetFirst( &filename );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
while( cont )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
if( filename != fn.GetFullName() )
|
2012-12-31 09:12:29 +01:00
|
|
|
AddItemToTreeProject( dir.GetName() + wxFileName::GetPathSeparator() +
|
|
|
|
filename, m_root );
|
2009-10-26 21:25:23 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
cont = dir.GetNext( &filename );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
2012-12-31 09:12:29 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_TreeProject->AppendItem( m_root, wxT( "Empty project" ) );
|
|
|
|
}
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
m_TreeProject->Expand( rootcellule );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
/* Sort filenames by alphabetic order */
|
|
|
|
m_TreeProject->SortChildren( m_root );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
m_Parent->m_ProjectFileName = fn;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
/**
|
|
|
|
* @brief Opens *popup* the context menu
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
int tree_id;
|
|
|
|
TREEPROJECT_ITEM* tree_data;
|
|
|
|
wxString FullFileName;
|
|
|
|
wxTreeItemId curr_item = Event.GetItem();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
/* Ensure item is selected (Under Windows right click does not select the item) */
|
|
|
|
m_TreeProject->SelectItem( curr_item );
|
|
|
|
|
|
|
|
tree_data = GetSelectedData();
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !tree_data )
|
|
|
|
return;
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
tree_id = tree_data->GetType();
|
2007-09-13 11:55:46 +00:00
|
|
|
FullFileName = tree_data->GetFileName();
|
|
|
|
|
2013-01-03 20:25:12 +01:00
|
|
|
wxMenu popupMenu;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2013-01-03 20:25:12 +01:00
|
|
|
switch( tree_id )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2013-01-03 20:25:12 +01:00
|
|
|
case TREE_PROJECT:
|
|
|
|
AddMenuItem( &popupMenu, ID_PROJECT_NEWDIR,
|
|
|
|
_( "New D&irectory" ),
|
|
|
|
_( "Create a New Directory" ),
|
|
|
|
KiBitmap( directory_xpm ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_DIRECTORY:
|
|
|
|
AddMenuItem( &popupMenu, ID_PROJECT_NEWDIR,
|
|
|
|
_( "New D&irectory" ),
|
|
|
|
_( "Create a New Directory" ),
|
|
|
|
KiBitmap( directory_xpm ) );
|
|
|
|
AddMenuItem( &popupMenu, ID_PROJECT_DELETE,
|
|
|
|
_( "&Delete Directory" ),
|
|
|
|
_( "Delete the Directory and its content" ),
|
|
|
|
KiBitmap( delete_xpm ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
AddMenuItem( &popupMenu, ID_PROJECT_TXTEDIT,
|
|
|
|
_( "&Edit in a text editor" ),
|
|
|
|
_( "Open the file in a Text Editor" ),
|
|
|
|
KiBitmap( icon_txt_xpm ) );
|
|
|
|
AddMenuItem( &popupMenu, ID_PROJECT_RENAME,
|
|
|
|
_( "&Rename file" ),
|
|
|
|
_( "Rename file" ),
|
|
|
|
KiBitmap( right_xpm ) );
|
|
|
|
AddMenuItem( &popupMenu, ID_PROJECT_DELETE,
|
|
|
|
_( "&Delete File" ),
|
|
|
|
_( "Delete the Directory and its content" ),
|
|
|
|
KiBitmap( delete_xpm ) );
|
|
|
|
break;
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
|
|
|
|
2013-01-03 20:25:12 +01:00
|
|
|
PopupMenu( &popupMenu );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
/*
|
|
|
|
* Called by the popup menu, when right clicking on a file name
|
|
|
|
* Launch the text editor to open the selected file
|
2008-11-02 14:54:53 +00:00
|
|
|
*/
|
2012-12-31 09:12:29 +01:00
|
|
|
void TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor( wxCommandEvent& event )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
if( !tree_data )
|
|
|
|
return;
|
|
|
|
|
2013-01-03 20:25:12 +01:00
|
|
|
if( tree_data->GetType() == TREE_DIRECTORY )
|
|
|
|
return;
|
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
wxString FullFileName = tree_data->GetFileName();
|
2007-09-13 11:55:46 +00:00
|
|
|
AddDelimiterString( FullFileName );
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-19 19:42:08 -05:00
|
|
|
wxString editorname = Pgm().GetEditorName();
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !editorname.IsEmpty() )
|
2009-02-04 15:25:03 +00:00
|
|
|
ExecuteFile( this, editorname, FullFileName );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
/* Called via the popup menu, when right clicking on a file name
|
|
|
|
* or a directory name to delete the selected file or directory
|
|
|
|
* in the tree project
|
2008-11-02 14:54:53 +00:00
|
|
|
*/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnDeleteFile( wxCommandEvent& )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( !tree_data )
|
|
|
|
return;
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
tree_data->Delete();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
/* Called via the popup menu, when right clicking on a file name
|
|
|
|
* or a directory name to rename the selected file or directory
|
|
|
|
* in the tree project
|
2008-11-02 14:54:53 +00:00
|
|
|
*/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
wxTreeItemId curr_item = m_TreeProject->GetSelection();
|
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( !tree_data )
|
|
|
|
return;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
wxString buffer = m_TreeProject->GetItemText( curr_item );
|
2013-04-09 19:49:01 +02:00
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Change filename: <%s>" ), GetChars( tree_data->m_FileName ) );
|
2012-12-31 09:12:29 +01:00
|
|
|
|
|
|
|
wxTextEntryDialog dlg( this, msg, _( "Change filename" ), buffer );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2010-07-20 12:30:40 +02:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return; // cancelled by user
|
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
buffer = dlg.GetValue();
|
2010-07-21 10:15:54 +02:00
|
|
|
buffer.Trim( true );
|
|
|
|
buffer.Trim( false );
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2010-07-20 12:30:40 +02:00
|
|
|
if( buffer.IsEmpty() )
|
2012-12-31 09:12:29 +01:00
|
|
|
return; // empty file name not allowed
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( tree_data->Rename( buffer, true ) )
|
|
|
|
m_TreeProject->SetItemText( curr_item, buffer );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-03 20:25:12 +01:00
|
|
|
/*
|
|
|
|
* called on a double click on an item
|
2008-11-02 14:54:53 +00:00
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
wxString FullFileName;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( !tree_data )
|
|
|
|
return;
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
tree_data->Activate( this );
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
2010-02-20 13:20:55 +00:00
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
/**
|
|
|
|
* @brief Called when expanding an item of the tree
|
|
|
|
* populate tree items corresponding to subdirectories not already populated
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event )
|
|
|
|
/*****************************************************************************/
|
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
wxString FullFileName;
|
2010-02-20 13:20:55 +00:00
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
wxTreeItemId itemId = Event.GetItem();
|
|
|
|
TREEPROJECT_ITEM* tree_data = GetItemIdData( itemId );
|
2010-02-20 13:20:55 +00:00
|
|
|
|
|
|
|
if( !tree_data )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( tree_data->GetType() != TREE_DIRECTORY )
|
|
|
|
return;
|
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
// explore list of non populated subdirs, and populate them
|
|
|
|
wxTreeItemIdValue cookie;
|
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( itemId, cookie );
|
|
|
|
|
2013-01-01 15:06:49 +01:00
|
|
|
bool subdir_populated = false;
|
2010-02-20 13:20:55 +00:00
|
|
|
for( ; kid.IsOk(); kid = m_TreeProject->GetNextChild( itemId, cookie ) )
|
|
|
|
{
|
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
if( !itemData || itemData->GetType() != TREE_DIRECTORY )
|
|
|
|
continue;
|
2012-12-31 09:12:29 +01:00
|
|
|
|
|
|
|
if( itemData->m_WasPopulated )
|
2010-02-20 13:20:55 +00:00
|
|
|
continue;
|
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
wxString fileName = itemData->GetFileName();
|
|
|
|
const wxString sep = wxFileName().GetPathSeparator();
|
|
|
|
wxDir dir( fileName );
|
|
|
|
wxString dir_filename;
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
if( dir.GetFirst( &dir_filename ) )
|
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
do // Add name to tree item, but do not recurse in subdirs:
|
2010-02-20 13:20:55 +00:00
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
AddItemToTreeProject( fileName + sep + dir_filename, kid, false );
|
2010-02-20 13:20:55 +00:00
|
|
|
} while( dir.GetNext( &dir_filename ) );
|
|
|
|
}
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
itemData->m_WasPopulated = true; // set state to populated
|
2013-01-01 15:06:49 +01:00
|
|
|
subdir_populated = true;
|
2010-02-20 13:20:55 +00:00
|
|
|
|
|
|
|
/* Sort filenames by alphabetic order */
|
|
|
|
m_TreeProject->SortChildren( kid );
|
|
|
|
}
|
2013-01-01 15:06:49 +01:00
|
|
|
|
|
|
|
if( subdir_populated )
|
|
|
|
{
|
|
|
|
#ifdef KICAD_USE_FILES_WATCHER
|
|
|
|
#ifndef __WINDOWS__
|
2013-01-02 22:49:56 +01:00
|
|
|
FileWatcherReset();
|
2013-01-01 15:06:49 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
2010-02-20 13:20:55 +00:00
|
|
|
}
|
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2010-11-12 10:36:43 -06:00
|
|
|
/**
|
|
|
|
* Function GetSelectedData
|
2010-02-20 13:20:55 +00:00
|
|
|
* return the item data from item currently selected (highlighted)
|
|
|
|
* Note this is not necessary the "clicked" item,
|
|
|
|
* because when expanding, collapsing an item this item is not selected
|
|
|
|
*/
|
|
|
|
TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetSelectedData()
|
|
|
|
{
|
2012-12-31 09:12:29 +01:00
|
|
|
return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData
|
|
|
|
( m_TreeProject->GetSelection() ) );
|
2010-02-20 13:20:55 +00:00
|
|
|
}
|
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2010-11-12 10:36:43 -06:00
|
|
|
/**
|
|
|
|
* Function GetItemIdData
|
2010-02-20 13:20:55 +00:00
|
|
|
* return the item data corresponding to a wxTreeItemId identifier
|
|
|
|
* @param aId = the wxTreeItemId identifier.
|
|
|
|
* @return a TREEPROJECT_ITEM pointer correspondinfg to item id aId
|
|
|
|
*/
|
2012-12-31 09:12:29 +01:00
|
|
|
TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetItemIdData( wxTreeItemId aId )
|
2010-02-20 13:20:55 +00:00
|
|
|
{
|
|
|
|
return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( aId ) );
|
|
|
|
}
|
|
|
|
|
2012-12-31 09:12:29 +01:00
|
|
|
/* Search for the item in tree project which is the
|
|
|
|
* node of the subdirectory aSubDir
|
|
|
|
* param aSubDir = the directory to find in tree
|
|
|
|
* return the opaque reference to the tree item.
|
|
|
|
* if not found, return an invalid tree item.
|
|
|
|
* therefore wxTreeItemId::IsOk should be used to test
|
|
|
|
* the returned value
|
|
|
|
*/
|
|
|
|
wxTreeItemId TREE_PROJECT_FRAME::findSubdirTreeItem( const wxString& aSubDir )
|
|
|
|
{
|
|
|
|
// If the subdir is the current working directory, return m_root
|
|
|
|
// in main list:
|
|
|
|
if( wxGetCwd() == aSubDir )
|
|
|
|
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 );
|
|
|
|
while( 1 )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
if( ! kid.IsOk() )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
|
|
|
|
2013-01-01 15:06:49 +01:00
|
|
|
if( itemData && ( itemData->GetType() == TREE_DIRECTORY ) )
|
2012-12-31 09:12:29 +01:00
|
|
|
{
|
|
|
|
if( itemData->m_FileName == aSubDir ) // Found!
|
|
|
|
{
|
|
|
|
root_id = kid;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:06:49 +01:00
|
|
|
// kid is a subdir, push in list to explore it later
|
|
|
|
if( itemData->m_WasPopulated )
|
2012-12-31 09:12:29 +01:00
|
|
|
subdirs_id.push( kid );
|
|
|
|
}
|
|
|
|
kid = m_TreeProject->GetNextChild( root_id, cookie );
|
|
|
|
}
|
|
|
|
|
|
|
|
return root_id;
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:06:49 +01:00
|
|
|
#ifdef KICAD_USE_FILES_WATCHER
|
2012-12-31 09:12:29 +01:00
|
|
|
/* called when a file or directory is modified/created/deleted
|
2013-01-01 15:06:49 +01:00
|
|
|
* The tree project is modified when a file or directory
|
|
|
|
* is created/deleted/renamed to reflect the file change
|
2012-12-31 09:12:29 +01:00
|
|
|
*/
|
|
|
|
void TREE_PROJECT_FRAME::OnFileSystemEvent( wxFileSystemWatcherEvent& event )
|
|
|
|
{
|
2013-01-02 22:49:56 +01:00
|
|
|
wxFileName pathModified = event.GetPath();
|
|
|
|
wxString subdir = pathModified.GetPath();
|
|
|
|
wxString fn = pathModified.GetFullPath();
|
2012-12-31 09:12:29 +01:00
|
|
|
|
|
|
|
switch( event.GetChangeType() )
|
|
|
|
{
|
|
|
|
case wxFSW_EVENT_DELETE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wxFSW_EVENT_CREATE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wxFSW_EVENT_RENAME:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wxFSW_EVENT_MODIFY:
|
|
|
|
case wxFSW_EVENT_ACCESS:
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxTreeItemId root_id = findSubdirTreeItem( subdir );
|
|
|
|
if( !root_id.IsOk() )
|
|
|
|
return;
|
2010-02-20 13:20:55 +00:00
|
|
|
|
2013-01-02 22:49:56 +01:00
|
|
|
wxTreeItemIdValue cookie; // dummy variable needed by GetFirstChild()
|
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2013-01-02 22:49:56 +01:00
|
|
|
switch( event.GetChangeType() )
|
2012-12-31 09:12:29 +01:00
|
|
|
{
|
2013-01-02 22:49:56 +01:00
|
|
|
case wxFSW_EVENT_CREATE:
|
|
|
|
AddItemToTreeProject( pathModified.GetFullPath(), root_id, false );
|
|
|
|
break;
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2013-01-02 22:49:56 +01:00
|
|
|
case wxFSW_EVENT_DELETE:
|
|
|
|
while( kid.IsOk() )
|
2012-12-31 09:12:29 +01:00
|
|
|
{
|
2013-01-02 22:49:56 +01:00
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
|
|
|
|
|
|
|
if( itemData && ( itemData->m_FileName == fn ) )
|
2012-12-31 09:12:29 +01:00
|
|
|
{
|
2013-01-02 22:49:56 +01:00
|
|
|
m_TreeProject->Delete( kid );
|
|
|
|
return;
|
2012-12-31 09:12:29 +01:00
|
|
|
}
|
2013-01-02 22:49:56 +01:00
|
|
|
kid = m_TreeProject->GetNextChild( root_id, cookie );
|
2012-12-31 09:12:29 +01:00
|
|
|
}
|
2013-01-02 22:49:56 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case wxFSW_EVENT_RENAME :
|
|
|
|
{
|
|
|
|
wxFileName newpath = event.GetNewPath();
|
|
|
|
wxString newfn = newpath.GetFullPath();
|
|
|
|
while( kid.IsOk() )
|
|
|
|
{
|
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
2012-12-31 09:12:29 +01:00
|
|
|
|
2013-01-02 22:49:56 +01:00
|
|
|
if( itemData && ( itemData->m_FileName == fn ) )
|
|
|
|
{
|
|
|
|
m_TreeProject->Delete( kid );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
kid = m_TreeProject->GetNextChild( root_id, cookie );
|
|
|
|
}
|
|
|
|
AddItemToTreeProject( newfn, root_id, false );
|
2012-12-31 09:12:29 +01:00
|
|
|
}
|
2013-01-02 22:49:56 +01:00
|
|
|
break;
|
2012-12-31 09:12:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort filenames by alphabetic order */
|
|
|
|
m_TreeProject->SortChildren( root_id );
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:06:49 +01:00
|
|
|
/* Reinit the watched paths
|
|
|
|
* Should be called after opening a new project to
|
|
|
|
* rebuild the list of watched paths.
|
|
|
|
* Should be called after the main loop event handler is started
|
|
|
|
*/
|
2012-12-31 09:12:29 +01:00
|
|
|
void TREE_PROJECT_FRAME::FileWatcherReset()
|
|
|
|
{
|
|
|
|
// Prepare file watcher:
|
|
|
|
delete m_watcher;
|
|
|
|
m_watcher = new wxFileSystemWatcher();
|
|
|
|
m_watcher->SetOwner( this );
|
|
|
|
|
|
|
|
// Add directories which should be monitored.
|
2013-01-01 15:06:49 +01:00
|
|
|
// under windows, we add the curr dir and all subdirs
|
|
|
|
// under unix, we add only the curr dir and the populated subdirs
|
2012-12-31 09:12:29 +01:00
|
|
|
// see http://docs.wxwidgets.org/trunk/classwx_file_system_watcher.htm
|
|
|
|
// under unix, the file watcher needs more work to be efficient
|
2013-01-01 15:06:49 +01:00
|
|
|
// moreover, under wxWidgets 2.9.4, AddTree does not work properly.
|
|
|
|
wxFileName watched_path = wxFileName::DirName( wxGetCwd() );
|
2012-12-31 09:12:29 +01:00
|
|
|
#ifdef __WINDOWS__
|
2013-01-01 15:06:49 +01:00
|
|
|
m_watcher->AddTree( watched_path );
|
2012-12-31 09:12:29 +01:00
|
|
|
#else
|
2013-01-01 15:06:49 +01:00
|
|
|
m_watcher->Add( watched_path );
|
|
|
|
|
|
|
|
// Add subdirs
|
|
|
|
wxTreeItemIdValue cookie;
|
|
|
|
wxTreeItemId root_id = m_root;
|
|
|
|
std::stack < wxTreeItemId > subdirs_id;
|
|
|
|
|
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
|
|
|
|
while( 1 )
|
|
|
|
{
|
|
|
|
if( ! kid.IsOk() )
|
|
|
|
{
|
|
|
|
if( subdirs_id.empty() ) // all items were explored
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
root_id = subdirs_id.top();
|
|
|
|
subdirs_id.pop();
|
|
|
|
kid = m_TreeProject->GetFirstChild( root_id, cookie );
|
|
|
|
if( ! kid.IsOk() )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
|
|
|
|
|
|
|
if( itemData && ( itemData->GetType() == TREE_DIRECTORY ) )
|
|
|
|
{
|
|
|
|
watched_path = wxFileName::DirName( itemData->m_FileName );
|
|
|
|
m_watcher->Add( watched_path );
|
|
|
|
|
|
|
|
// if kid is a subdir, push in list to explore it later
|
|
|
|
if( itemData->m_WasPopulated && m_TreeProject->GetChildrenCount( kid ) )
|
|
|
|
subdirs_id.push( kid );
|
|
|
|
}
|
|
|
|
kid = m_TreeProject->GetNextChild( root_id, cookie );
|
|
|
|
}
|
2012-12-31 09:12:29 +01:00
|
|
|
#endif
|
2013-01-01 15:06:49 +01:00
|
|
|
|
|
|
|
#if 0 // For test only!
|
|
|
|
wxArrayString paths;
|
|
|
|
m_watcher->GetWatchedPaths( &paths );
|
|
|
|
for( unsigned ii = 0; ii < paths.GetCount(); ii++ )
|
|
|
|
wxLogMessage( paths[ii] );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called by sending a event with id = ID_INIT_WATCHED_PATHS
|
|
|
|
* rebuild the list of whatched paths
|
|
|
|
* We are using an event called function to install or reinit a file system watcher
|
|
|
|
* because a file watcher *needs* a running loop event handler.
|
|
|
|
* this is noticeable under Linux.
|
|
|
|
* therefore the safe way to do that is to use the main event loop
|
|
|
|
* to call m_LeftWin->FileWatcherReset()
|
|
|
|
*/
|
|
|
|
void KICAD_MANAGER_FRAME::OnChangeWatchedPaths(wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_LeftWin->FileWatcherReset();
|
2012-12-31 09:12:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|