Kicad manager: first use of wxFileSystemWatcher (only with wxWidgets >= 2.9.2) to monitor files list.
This commit is contained in:
parent
6789e62210
commit
45b01a5c9c
|
@ -1,10 +1,34 @@
|
||||||
/**
|
/**
|
||||||
* @file class_treeproject_item.cpp
|
* @file class_treeproject_item.cpp
|
||||||
*
|
*
|
||||||
* Class TREEPROJECT_ITEM is a derived class from wxTreeItemData that
|
* @brief Class TREEPROJECT_ITEM is a derived class from wxTreeItemData and
|
||||||
* store info about a file or directory shown in the KiCad tree project files
|
* store info about a file or directory shown in the KiCad tree project files
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <fctsys.h>
|
#include <fctsys.h>
|
||||||
#include <gestfich.h>
|
#include <gestfich.h>
|
||||||
#include <macros.h>
|
#include <macros.h>
|
||||||
|
@ -18,37 +42,30 @@
|
||||||
#include <wx/regex.h>
|
#include <wx/regex.h>
|
||||||
#include <wx/dir.h>
|
#include <wx/dir.h>
|
||||||
|
|
||||||
/* sort function for tree items.
|
|
||||||
* items are sorted :
|
|
||||||
* directory names first by alphabetic order
|
|
||||||
* root file names after
|
|
||||||
* file names last by alphabetic order
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TREEPROJECT_ITEM::TREEPROJECT_ITEM( enum TreeFileType type, const wxString& data,
|
TREEPROJECT_ITEM::TREEPROJECT_ITEM( enum TreeFileType type, const wxString& data,
|
||||||
wxTreeCtrl* parent ) :
|
wxTreeCtrl* parent ) :
|
||||||
wxTreeItemData()
|
wxTreeItemData()
|
||||||
{
|
{
|
||||||
m_Type = type;
|
m_Type = type;
|
||||||
m_Parent = parent;
|
m_parent = parent;
|
||||||
m_FileName = data;
|
m_FileName = data;
|
||||||
m_IsRootFile = false; // true only for the root item of the tree (the project name)
|
m_IsRootFile = false; // true only for the root item of the tree (the project name)
|
||||||
m_WasPopulated = false;
|
m_WasPopulated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Set the state used in the icon list
|
// Set the state used in the icon list
|
||||||
void TREEPROJECT_ITEM::SetState( int state )
|
void TREEPROJECT_ITEM::SetState( int state )
|
||||||
{
|
{
|
||||||
wxImageList* imglist = m_Parent->GetImageList();
|
wxImageList* imglist = m_parent->GetImageList();
|
||||||
|
|
||||||
if( !imglist || state < 0 || state >= imglist->GetImageCount() / ( TREE_MAX - 2 ) )
|
if( !imglist || state < 0 || state >= imglist->GetImageCount() / ( TREE_MAX - 2 ) )
|
||||||
return;
|
return;
|
||||||
m_State = state;
|
|
||||||
|
m_state = state;
|
||||||
int imgid = m_Type - 1 + state * ( TREE_MAX - 1 );
|
int imgid = m_Type - 1 + state * ( TREE_MAX - 1 );
|
||||||
m_Parent->SetItemImage( GetId(), imgid );
|
m_parent->SetItemImage( GetId(), imgid );
|
||||||
m_Parent->SetItemImage( GetId(), imgid, wxTreeItemIcon_Selected );
|
m_parent->SetItemImage( GetId(), imgid, wxTreeItemIcon_Selected );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,6 +82,7 @@ wxString TREEPROJECT_ITEM::GetDir() const
|
||||||
wxArrayString dirs = filename.GetDirs();
|
wxArrayString dirs = filename.GetDirs();
|
||||||
|
|
||||||
wxString dir;
|
wxString dir;
|
||||||
|
|
||||||
for( unsigned int i = 0; i < dirs.Count(); i++ )
|
for( unsigned int i = 0; i < dirs.Count(); i++ )
|
||||||
{
|
{
|
||||||
dir += dirs[i] + filename.GetPathSeparator();
|
dir += dirs[i] + filename.GetPathSeparator();
|
||||||
|
@ -74,19 +92,6 @@ wxString TREEPROJECT_ITEM::GetDir() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Called upon tree item rename */
|
|
||||||
void TREEPROJECT_ITEM::OnRename( wxTreeEvent& event, bool check )
|
|
||||||
{
|
|
||||||
//this segfaults on linux (in wxEvtHandler::ProcessEvent), wx version 2.8.7
|
|
||||||
//therefore, until it is fixed, we must cancel the rename.
|
|
||||||
event.Veto();
|
|
||||||
return;
|
|
||||||
|
|
||||||
if( !Rename( event.GetLabel(), check ) )
|
|
||||||
event.Veto();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Move the object to dest
|
// Move the object to dest
|
||||||
void TREEPROJECT_ITEM::Move( TREEPROJECT_ITEM* dest )
|
void TREEPROJECT_ITEM::Move( TREEPROJECT_ITEM* dest )
|
||||||
{
|
{
|
||||||
|
@ -97,15 +102,19 @@ void TREEPROJECT_ITEM::Move( TREEPROJECT_ITEM* dest )
|
||||||
|
|
||||||
if( m_Type == TREE_DIRECTORY )
|
if( m_Type == TREE_DIRECTORY )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( !dest )
|
if( !dest )
|
||||||
return;
|
return;
|
||||||
if( m_Parent != dest->m_Parent )
|
|
||||||
|
if( m_parent != dest->m_parent )
|
||||||
return; // Can not cross move!
|
return; // Can not cross move!
|
||||||
|
|
||||||
if( dest == this )
|
if( dest == this )
|
||||||
return; // Can not move to ourself...
|
return; // Can not move to ourself...
|
||||||
|
|
||||||
wxTreeItemId parent = m_Parent->GetItemParent( GetId() );
|
wxTreeItemId parent = m_parent->GetItemParent( GetId() );
|
||||||
if( dest == dynamic_cast<TREEPROJECT_ITEM*>( m_Parent->GetItemData( parent ) ) )
|
|
||||||
|
if( dest == dynamic_cast<TREEPROJECT_ITEM*>( m_parent->GetItemData( parent ) ) )
|
||||||
return; // same parent ?
|
return; // same parent ?
|
||||||
|
|
||||||
// We need to create a new item from us, and move
|
// We need to create a new item from us, and move
|
||||||
|
@ -115,8 +124,10 @@ void TREEPROJECT_ITEM::Move( TREEPROJECT_ITEM* dest )
|
||||||
wxFileName fname( m_FileName );
|
wxFileName fname( m_FileName );
|
||||||
|
|
||||||
wxString destName;
|
wxString destName;
|
||||||
|
|
||||||
if( !dest->GetDir().IsEmpty() )
|
if( !dest->GetDir().IsEmpty() )
|
||||||
destName = dest->GetDir() + sep;
|
destName = dest->GetDir() + sep;
|
||||||
|
|
||||||
destName += fname.GetFullName();
|
destName += fname.GetFullName();
|
||||||
|
|
||||||
if( destName == GetFileName() )
|
if( destName == GetFileName() )
|
||||||
|
@ -125,7 +136,7 @@ void TREEPROJECT_ITEM::Move( TREEPROJECT_ITEM* dest )
|
||||||
// Move the file on the disk:
|
// Move the file on the disk:
|
||||||
if( !wxRenameFile( GetFileName(), destName, false ) )
|
if( !wxRenameFile( GetFileName(), destName, false ) )
|
||||||
{
|
{
|
||||||
wxMessageDialog( m_Parent, _( "Unable to move file ... " ),
|
wxMessageDialog( m_parent, _( "Unable to move file ... " ),
|
||||||
_( "Permission error ?" ), wxICON_ERROR | wxOK );
|
_( "Permission error ?" ), wxICON_ERROR | wxOK );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -136,25 +147,24 @@ void TREEPROJECT_ITEM::Move( TREEPROJECT_ITEM* dest )
|
||||||
{
|
{
|
||||||
// Move the tree item itself now:
|
// Move the tree item itself now:
|
||||||
wxTreeItemId oldId = GetId();
|
wxTreeItemId oldId = GetId();
|
||||||
int i = m_Parent->GetItemImage( oldId );
|
int i = m_parent->GetItemImage( oldId );
|
||||||
wxString text = m_Parent->GetItemText( oldId );
|
wxString text = m_parent->GetItemText( oldId );
|
||||||
|
|
||||||
// Bye bye old Id :'(
|
// Bye bye old Id :'(
|
||||||
wxTreeItemId newId = m_Parent->AppendItem( dest->GetId(), text, i );
|
wxTreeItemId newId = m_parent->AppendItem( dest->GetId(), text, i );
|
||||||
m_Parent->SetItemData( newId, this );
|
m_parent->SetItemData( newId, this );
|
||||||
m_Parent->SetItemData( oldId, NULL );
|
m_parent->SetItemData( oldId, NULL );
|
||||||
m_Parent->Delete( oldId );
|
m_parent->Delete( oldId );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// We should move recursively all files, but that's quite boring
|
// We should move recursively all files, but that's quite boring
|
||||||
// let's just refresh that's all ... TODO (change this to a better code ...)
|
// let's just refresh that's all ... TODO (change this to a better code ...)
|
||||||
wxCommandEvent dummy;
|
wxCommandEvent dummy;
|
||||||
dynamic_cast<TREEPROJECTFILES*>( m_Parent )->GetParent()->m_Parent->OnRefresh( dummy );
|
dynamic_cast<TREEPROJECTFILES*>( m_parent )->GetParent()->m_Parent->OnRefresh( dummy );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* rename the file checking if extension change occurs */
|
/* rename the file checking if extension change occurs */
|
||||||
bool TREEPROJECT_ITEM::Rename( const wxString& name, bool check )
|
bool TREEPROJECT_ITEM::Rename( const wxString& name, bool check )
|
||||||
{
|
{
|
||||||
|
@ -183,8 +193,9 @@ bool TREEPROJECT_ITEM::Rename( const wxString& name, bool check )
|
||||||
|
|
||||||
if( check && !ext.IsEmpty() && !reg.Matches( newFile ) )
|
if( check && !ext.IsEmpty() && !reg.Matches( newFile ) )
|
||||||
{
|
{
|
||||||
wxMessageDialog dialog( m_Parent,
|
wxMessageDialog dialog( m_parent,
|
||||||
_( "Changing file extension will change file \
|
_(
|
||||||
|
"Changing file extension will change file \
|
||||||
type.\n Do you want to continue ?" ),
|
type.\n Do you want to continue ?" ),
|
||||||
_( "Rename File" ),
|
_( "Rename File" ),
|
||||||
wxYES_NO | wxICON_QUESTION );
|
wxYES_NO | wxICON_QUESTION );
|
||||||
|
@ -195,15 +206,18 @@ type.\n Do you want to continue ?" ),
|
||||||
|
|
||||||
#if ( ( wxMAJOR_VERSION < 2 ) || ( ( wxMAJOR_VERSION == 2 ) \
|
#if ( ( wxMAJOR_VERSION < 2 ) || ( ( wxMAJOR_VERSION == 2 ) \
|
||||||
&& ( wxMINOR_VERSION < 7 ) ) )
|
&& ( wxMINOR_VERSION < 7 ) ) )
|
||||||
|
|
||||||
if( !wxRenameFile( m_FileName, newFile ) )
|
if( !wxRenameFile( m_FileName, newFile ) )
|
||||||
#else
|
#else
|
||||||
|
|
||||||
if( !wxRenameFile( m_FileName, newFile, false ) )
|
if( !wxRenameFile( m_FileName, newFile, false ) )
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
wxMessageDialog( m_Parent, _( "Unable to rename file ... " ),
|
wxMessageDialog( m_parent, _( "Unable to rename file ... " ),
|
||||||
_( "Permission error ?" ), wxICON_ERROR | wxOK );
|
_( "Permission error ?" ), wxICON_ERROR | wxOK );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetFileName( newFile );
|
SetFileName( newFile );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -216,16 +230,17 @@ bool TREEPROJECT_ITEM::Delete( bool check )
|
||||||
/* delete a file */
|
/* delete a file */
|
||||||
{
|
{
|
||||||
wxString msg;
|
wxString msg;
|
||||||
|
|
||||||
msg.Printf( _( "Do you really want to delete '%s'" ), GetChars( GetFileName() ) );
|
msg.Printf( _( "Do you really want to delete '%s'" ), GetChars( GetFileName() ) );
|
||||||
wxMessageDialog dialog( m_Parent, msg,
|
wxMessageDialog dialog( m_parent, msg,
|
||||||
_( "Delete File" ), wxYES_NO | wxICON_QUESTION );
|
_( "Delete File" ), wxYES_NO | wxICON_QUESTION );
|
||||||
|
|
||||||
if( !check || wxID_YES == dialog.ShowModal() )
|
if( !check || wxID_YES == dialog.ShowModal() )
|
||||||
{
|
{
|
||||||
|
bool success;
|
||||||
|
|
||||||
if( !wxDirExists( m_FileName ) )
|
if( !wxDirExists( m_FileName ) )
|
||||||
{
|
success = wxRemoveFile( m_FileName );
|
||||||
wxRemoveFile( m_FileName );
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxArrayString filelist;
|
wxArrayString filelist;
|
||||||
|
@ -235,12 +250,15 @@ bool TREEPROJECT_ITEM::Delete( bool check )
|
||||||
for( unsigned int i = 0; i < filelist.Count(); i++ )
|
for( unsigned int i = 0; i < filelist.Count(); i++ )
|
||||||
wxRemoveFile( filelist[i] );
|
wxRemoveFile( filelist[i] );
|
||||||
|
|
||||||
wxRmdir( m_FileName );
|
success = wxRmdir( m_FileName );
|
||||||
}
|
}
|
||||||
m_Parent->Delete( GetId() );
|
|
||||||
|
|
||||||
return true;
|
if( success )
|
||||||
|
m_parent->Delete( GetId() );
|
||||||
|
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,26 +271,27 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe )
|
||||||
wxTreeItemId id = GetId();
|
wxTreeItemId id = GetId();
|
||||||
|
|
||||||
AddDelimiterString( FullFileName );
|
AddDelimiterString( FullFileName );
|
||||||
|
|
||||||
switch( GetType() )
|
switch( GetType() )
|
||||||
{
|
{
|
||||||
case TREE_PROJECT:
|
case TREE_PROJECT:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TREE_DIRECTORY:
|
case TREE_DIRECTORY:
|
||||||
m_Parent->Toggle( id );
|
m_parent->Toggle( id );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TREE_SCHEMA:
|
case TREE_SCHEMA:
|
||||||
ExecuteFile( m_Parent, EESCHEMA_EXE, FullFileName );
|
ExecuteFile( m_parent, EESCHEMA_EXE, FullFileName );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TREE_LEGACY_PCB:
|
case TREE_LEGACY_PCB:
|
||||||
case TREE_SEXP_PCB:
|
case TREE_SEXP_PCB:
|
||||||
ExecuteFile( m_Parent, PCBNEW_EXE, FullFileName );
|
ExecuteFile( m_parent, PCBNEW_EXE, FullFileName );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TREE_GERBER:
|
case TREE_GERBER:
|
||||||
ExecuteFile( m_Parent, GERBVIEW_EXE, FullFileName );
|
ExecuteFile( m_parent, GERBVIEW_EXE, FullFileName );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TREE_PDF:
|
case TREE_PDF:
|
||||||
|
@ -280,14 +299,16 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TREE_NET:
|
case TREE_NET:
|
||||||
ExecuteFile( m_Parent, CVPCB_EXE, FullFileName );
|
ExecuteFile( m_parent, CVPCB_EXE, FullFileName );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TREE_TXT:
|
case TREE_TXT:
|
||||||
{
|
{
|
||||||
wxString editorname = wxGetApp().GetEditorName();
|
wxString editorname = wxGetApp().GetEditorName();
|
||||||
|
|
||||||
if( !editorname.IsEmpty() )
|
if( !editorname.IsEmpty() )
|
||||||
ExecuteFile( m_Parent, editorname, FullFileName );
|
ExecuteFile( m_parent, editorname, FullFileName );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,4 +317,3 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,25 +12,21 @@ public:
|
||||||
TreeFileType m_Type; // = TREE_PROJECT, TREE_DIRECTORY ...
|
TreeFileType m_Type; // = TREE_PROJECT, TREE_DIRECTORY ...
|
||||||
wxString m_FileName; // Filename for a file, or directory name
|
wxString m_FileName; // Filename for a file, or directory name
|
||||||
bool m_IsRootFile; // True if m_Filename is a root schematic (same name as project)
|
bool m_IsRootFile; // True if m_Filename is a root schematic (same name as project)
|
||||||
bool m_WasPopulated; // True the name is a directory, and its containt was read
|
bool m_WasPopulated; // True the name is a directory, and its content was read
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxTreeCtrl* m_Parent;
|
wxTreeCtrl* m_parent;
|
||||||
wxMenu m_fileMenu;
|
wxMenu m_fileMenu;
|
||||||
int m_State;
|
int m_state;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TREEPROJECT_ITEM( TreeFileType type, const wxString& data,
|
TREEPROJECT_ITEM( TreeFileType type, const wxString& data,
|
||||||
wxTreeCtrl* parent );
|
wxTreeCtrl* parent );
|
||||||
TREEPROJECT_ITEM() : m_Parent( NULL ) { }
|
TREEPROJECT_ITEM() : m_parent( NULL ) { }
|
||||||
|
|
||||||
TREEPROJECT_ITEM( const TREEPROJECT_ITEM& src ) :
|
TREEPROJECT_ITEM( const TREEPROJECT_ITEM& src ) :
|
||||||
m_Type( src.m_Type ),
|
m_Type( src.m_Type ), m_FileName( src.m_FileName ), m_parent( src.m_parent )
|
||||||
m_FileName( src.m_FileName ),
|
|
||||||
m_Parent( src.m_Parent )
|
|
||||||
{
|
{
|
||||||
SetState( src.m_State );
|
SetState( src.m_state );
|
||||||
m_WasPopulated = false;
|
m_WasPopulated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,28 +35,23 @@ public:
|
||||||
return m_Type;
|
return m_Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SetType( TreeFileType aType )
|
void SetType( TreeFileType aType )
|
||||||
{
|
{
|
||||||
m_Type = aType;
|
m_Type = aType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxString GetFileName() const
|
wxString GetFileName() const
|
||||||
{
|
{
|
||||||
return m_FileName;
|
return m_FileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SetFileName( const wxString& name )
|
void SetFileName( const wxString& name )
|
||||||
{
|
{
|
||||||
m_FileName = name;
|
m_FileName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxString GetDir() const;
|
wxString GetDir() const;
|
||||||
|
|
||||||
void OnRename( wxTreeEvent& event, bool check = true );
|
|
||||||
bool Rename( const wxString& name, bool check = true );
|
bool Rename( const wxString& name, bool check = true );
|
||||||
bool Delete( bool check = true );
|
bool Delete( bool check = true );
|
||||||
void Move( TREEPROJECT_ITEM* dest );
|
void Move( TREEPROJECT_ITEM* dest );
|
||||||
|
@ -71,7 +62,5 @@ public:
|
||||||
return &m_fileMenu;
|
return &m_fileMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SetState( int state );
|
void SetState( int state );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -45,7 +45,7 @@ IMPLEMENT_ABSTRACT_CLASS( TREEPROJECTFILES, wxTreeCtrl )
|
||||||
TREEPROJECTFILES::TREEPROJECTFILES( TREE_PROJECT_FRAME* parent ) :
|
TREEPROJECTFILES::TREEPROJECTFILES( TREE_PROJECT_FRAME* parent ) :
|
||||||
wxTreeCtrl( parent, ID_PROJECT_TREE,
|
wxTreeCtrl( parent, ID_PROJECT_TREE,
|
||||||
wxDefaultPosition, wxDefaultSize,
|
wxDefaultPosition, wxDefaultSize,
|
||||||
wxTR_HAS_BUTTONS | wxTR_EDIT_LABELS, wxDefaultValidator,
|
wxTR_HAS_BUTTONS, wxDefaultValidator,
|
||||||
wxT( "EDATreeCtrl" ) )
|
wxT( "EDATreeCtrl" ) )
|
||||||
{
|
{
|
||||||
m_Parent = parent;
|
m_Parent = parent;
|
||||||
|
|
|
@ -258,8 +258,9 @@ void KICAD_MANAGER_FRAME::OnOpenFileInTextEditor( wxCommandEvent& event )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mask = _( "Text file (" ) + mask + wxT( ")|" ) + mask;
|
mask = _( "Text file (" ) + mask + wxT( ")|" ) + mask;
|
||||||
|
wxString default_dir = wxGetCwd();
|
||||||
|
|
||||||
wxFileDialog dlg( this, _( "Load File to Edit" ), wxGetCwd(),
|
wxFileDialog dlg( this, _( "Load File to Edit" ), default_dir,
|
||||||
wxEmptyString, mask, wxFD_OPEN );
|
wxEmptyString, mask, wxFD_OPEN );
|
||||||
|
|
||||||
if( dlg.ShowModal() == wxID_CANCEL )
|
if( dlg.ShowModal() == wxID_CANCEL )
|
||||||
|
|
|
@ -148,13 +148,14 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
|
||||||
{
|
{
|
||||||
int style;
|
int style;
|
||||||
wxString title;
|
wxString title;
|
||||||
|
bool newProject = ( event.GetId() == ID_NEW_PROJECT ) ||
|
||||||
|
( event.GetId() == ID_NEW_PROJECT_FROM_TEMPLATE );
|
||||||
|
|
||||||
ClearMsg();
|
ClearMsg();
|
||||||
|
|
||||||
if( event.GetId() != wxID_ANY )
|
if( event.GetId() != wxID_ANY )
|
||||||
{
|
{
|
||||||
if( ( event.GetId() == ID_NEW_PROJECT ) ||
|
if( newProject )
|
||||||
( event.GetId() == ID_NEW_PROJECT_FROM_TEMPLATE ) )
|
|
||||||
{
|
{
|
||||||
title = _( "Create New Project" );
|
title = _( "Create New Project" );
|
||||||
style = wxFD_SAVE | wxFD_OVERWRITE_PROMPT;
|
style = wxFD_SAVE | wxFD_OVERWRITE_PROMPT;
|
||||||
|
@ -165,15 +166,16 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
|
||||||
style = wxFD_OPEN | wxFD_FILE_MUST_EXIST;
|
style = wxFD_OPEN | wxFD_FILE_MUST_EXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileDialog dlg( this, title, wxGetCwd(), wxEmptyString, ProjectFileWildcard, style );
|
wxString default_dir = wxGetCwd();
|
||||||
|
wxFileDialog dlg( this, title, default_dir, wxEmptyString,
|
||||||
|
ProjectFileWildcard, style );
|
||||||
|
|
||||||
if( dlg.ShowModal() == wxID_CANCEL )
|
if( dlg.ShowModal() == wxID_CANCEL )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_ProjectFileName = dlg.GetPath();
|
m_ProjectFileName = dlg.GetPath();
|
||||||
|
|
||||||
if( ( event.GetId() == ID_NEW_PROJECT ) ||
|
if( newProject )
|
||||||
( event.GetId() == ID_NEW_PROJECT_FROM_TEMPLATE ) )
|
|
||||||
{
|
{
|
||||||
if ( !m_ProjectFileName.GetFullPath().EndsWith( g_KicadPrjFilenameExtension ) )
|
if ( !m_ProjectFileName.GetFullPath().EndsWith( g_KicadPrjFilenameExtension ) )
|
||||||
{
|
{
|
||||||
|
@ -220,12 +222,14 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
|
||||||
|
|
||||||
SetTitle( title );
|
SetTitle( title );
|
||||||
UpdateFileHistory( m_ProjectFileName.GetFullPath() );
|
UpdateFileHistory( m_ProjectFileName.GetFullPath() );
|
||||||
|
#if wxCHECK_VERSION( 2, 9, 2 )
|
||||||
|
m_LeftWin->FileWatcherReset();
|
||||||
|
#endif
|
||||||
m_LeftWin->ReCreateTreePrj();
|
m_LeftWin->ReCreateTreePrj();
|
||||||
|
|
||||||
PrintMsg( _( "Working dir: " ) + m_ProjectFileName.GetPath() +
|
PrintMsg( _( "Working dir: " ) + m_ProjectFileName.GetPath() +
|
||||||
_( "\nProject: " ) + m_ProjectFileName.GetFullName() +
|
_( "\nProject: " ) + m_ProjectFileName.GetFullName() +
|
||||||
wxT( "\n" ) );
|
wxT( "\n" ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -161,7 +161,8 @@ bool PROJECT_TEMPLATE::CreateProject( wxFileName& aNewProjectPath )
|
||||||
wxString* PROJECT_TEMPLATE::GetTitle(void)
|
wxString* PROJECT_TEMPLATE::GetTitle(void)
|
||||||
{
|
{
|
||||||
wxFileInputStream input( GetHtmlFile().GetFullPath() );
|
wxFileInputStream input( GetHtmlFile().GetFullPath() );
|
||||||
wxTextInputStream text( input, wxT( "\x9" ), wxConvUTF8 );
|
wxString separator( wxT( "\x9" ) );
|
||||||
|
wxTextInputStream text( input, separator, wxConvUTF8 );
|
||||||
|
|
||||||
/* Open HTML file and get the text between the title tags */
|
/* Open HTML file and get the text between the title tags */
|
||||||
if( title == wxEmptyString )
|
if( title == wxEmptyString )
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include <wx/dir.h>
|
#include <wx/dir.h>
|
||||||
#include <wx/imaglist.h>
|
#include <wx/imaglist.h>
|
||||||
#include <menus_helpers.h>
|
#include <menus_helpers.h>
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
|
|
||||||
/* Note about the tree project build process:
|
/* Note about the tree project build process:
|
||||||
|
@ -109,17 +110,16 @@ const wxString TextFileWildcard( wxT( "Text files (*.txt)|*.txt" ) );
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
BEGIN_EVENT_TABLE( TREE_PROJECT_FRAME, wxSashLayoutWindow )
|
BEGIN_EVENT_TABLE( TREE_PROJECT_FRAME, wxSashLayoutWindow )
|
||||||
EVT_TREE_BEGIN_LABEL_EDIT( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnRenameAsk )
|
|
||||||
EVT_TREE_END_LABEL_EDIT( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnRename )
|
|
||||||
EVT_TREE_ITEM_ACTIVATED( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnSelect )
|
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_EXPANDED( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnExpand )
|
||||||
EVT_TREE_ITEM_RIGHT_CLICK( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnRight )
|
EVT_TREE_ITEM_RIGHT_CLICK( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnRight )
|
||||||
EVT_TREE_BEGIN_DRAG( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnDragStart )
|
EVT_TREE_BEGIN_DRAG( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnDragStart )
|
||||||
EVT_TREE_END_DRAG( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnDragEnd )
|
EVT_TREE_END_DRAG( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnDragEnd )
|
||||||
EVT_MENU( ID_PROJECT_TXTEDIT, TREE_PROJECT_FRAME::OnTxtEdit )
|
EVT_MENU( ID_PROJECT_TXTEDIT, TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor )
|
||||||
EVT_MENU( ID_PROJECT_NEWDIR, TREE_PROJECT_FRAME::OnCreateNewDirectory )
|
EVT_MENU( ID_PROJECT_NEWDIR, TREE_PROJECT_FRAME::OnCreateNewDirectory )
|
||||||
EVT_MENU( ID_PROJECT_DELETE, TREE_PROJECT_FRAME::OnDeleteFile )
|
EVT_MENU( ID_PROJECT_DELETE, TREE_PROJECT_FRAME::OnDeleteFile )
|
||||||
EVT_MENU( ID_PROJECT_RENAME, TREE_PROJECT_FRAME::OnRenameFile )
|
EVT_MENU( ID_PROJECT_RENAME, TREE_PROJECT_FRAME::OnRenameFile )
|
||||||
|
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
@ -137,20 +137,24 @@ TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ) :
|
||||||
m_TreeProject = NULL;
|
m_TreeProject = NULL;
|
||||||
wxMenuItem* item;
|
wxMenuItem* item;
|
||||||
m_PopupMenu = NULL;
|
m_PopupMenu = NULL;
|
||||||
|
#if wxCHECK_VERSION( 2, 9, 2 )
|
||||||
|
m_watcher = new wxFileSystemWatcher();
|
||||||
|
m_watcher->SetOwner( this );
|
||||||
|
Connect( wxEVT_FSWATCHER,
|
||||||
|
wxFileSystemWatcherEventHandler( TREE_PROJECT_FRAME::OnFileSystemEvent ) );
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* Filtering is now inverted: the filters are actually used to _enable_ support
|
* Filtering is now inverted: the filters are actually used to _enable_ support
|
||||||
* for a given file type.
|
* for a given file type.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// NOTE: sch filter must be first because of a test in AddFile() below
|
// NOTE: sch filter must be first because of a test in AddFile() below
|
||||||
m_Filters.push_back( wxT( "^.*\\.sch$" ) );
|
m_filters.push_back( wxT( "^.*\\.sch$" ) );
|
||||||
for( int ii = 0; s_allowedExtensionsToList[ii] != NULL; ii++ )
|
|
||||||
{
|
|
||||||
m_Filters.push_back( s_allowedExtensionsToList[ii] );
|
|
||||||
}
|
|
||||||
|
|
||||||
m_Filters.push_back( wxT( "^no KiCad files found" ) );
|
for( int ii = 0; s_allowedExtensionsToList[ii] != NULL; ii++ )
|
||||||
|
m_filters.push_back( s_allowedExtensionsToList[ii] );
|
||||||
|
|
||||||
|
m_filters.push_back( wxT( "^no KiCad files found" ) );
|
||||||
|
|
||||||
for( int i = 0; i < TREE_MAX; i++ )
|
for( int i = 0; i < TREE_MAX; i++ )
|
||||||
m_ContextMenus.push_back( new wxMenu() );
|
m_ContextMenus.push_back( new wxMenu() );
|
||||||
|
@ -173,7 +177,6 @@ TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ) :
|
||||||
_( "Create a New Directory" ) );
|
_( "Create a New Directory" ) );
|
||||||
item->SetBitmap( KiBitmap( directory_xpm ) );
|
item->SetBitmap( KiBitmap( directory_xpm ) );
|
||||||
menu->Append( item );
|
menu->Append( item );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -231,6 +234,10 @@ TREE_PROJECT_FRAME::~TREE_PROJECT_FRAME()
|
||||||
|
|
||||||
if( m_PopupMenu )
|
if( m_PopupMenu )
|
||||||
delete m_PopupMenu;
|
delete m_PopupMenu;
|
||||||
|
|
||||||
|
#if wxCHECK_VERSION( 2, 9, 2 )
|
||||||
|
delete m_watcher;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -242,7 +249,8 @@ void TREE_PROJECT_FRAME::OnDragStart( wxTreeEvent& event )
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
{
|
{
|
||||||
/* Ensure item is selected
|
/* Ensure item is selected
|
||||||
* (Under Windows start drag does not activate the item) */
|
* (Under Windows start drag does not activate the item)
|
||||||
|
*/
|
||||||
wxTreeItemId curr_item = event.GetItem();
|
wxTreeItemId curr_item = event.GetItem();
|
||||||
|
|
||||||
m_TreeProject->SelectItem( curr_item );
|
m_TreeProject->SelectItem( curr_item );
|
||||||
|
@ -282,6 +290,7 @@ void TREE_PROJECT_FRAME::OnDragEnd( wxTreeEvent& event )
|
||||||
{
|
{
|
||||||
// the item is a member of the selected directory; get the directory itself
|
// the item is a member of the selected directory; get the directory itself
|
||||||
dest = m_TreeProject->GetItemParent( dest );
|
dest = m_TreeProject->GetItemParent( dest );
|
||||||
|
|
||||||
if( !dest.IsOk() )
|
if( !dest.IsOk() )
|
||||||
return; // no parent ?
|
return; // no parent ?
|
||||||
|
|
||||||
|
@ -294,19 +303,6 @@ void TREE_PROJECT_FRAME::OnDragEnd( wxTreeEvent& event )
|
||||||
}
|
}
|
||||||
|
|
||||||
source_data->Move( destData );
|
source_data->Move( destData );
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* Sort filenames by alphabetic order */
|
|
||||||
m_TreeProject->SortChildren( dest );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
void TREE_PROJECT_FRAME::ClearFilters()
|
|
||||||
/*****************************************************************************/
|
|
||||||
{
|
|
||||||
m_Filters.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -314,28 +310,17 @@ void TREE_PROJECT_FRAME::ClearFilters()
|
||||||
void TREE_PROJECT_FRAME::RemoveFilter( const wxString& filter )
|
void TREE_PROJECT_FRAME::RemoveFilter( const wxString& filter )
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
{
|
{
|
||||||
for( unsigned int i = 0; i < m_Filters.size(); i++ )
|
for( unsigned int i = 0; i < m_filters.size(); i++ )
|
||||||
{
|
{
|
||||||
if( filter == m_Filters[i] )
|
if( filter == m_filters[i] )
|
||||||
{
|
{
|
||||||
m_Filters.erase( m_Filters.begin() + i );
|
m_filters.erase( m_filters.begin() + i );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief TODO
|
|
||||||
*/
|
|
||||||
/*****************************************************************************/
|
|
||||||
const std::vector<wxString>& TREE_PROJECT_FRAME::GetFilters()
|
|
||||||
/*****************************************************************************/
|
|
||||||
{
|
|
||||||
return m_Filters;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TODO
|
* @brief TODO
|
||||||
*/
|
*/
|
||||||
|
@ -356,6 +341,7 @@ void TREE_PROJECT_FRAME::OnCreateNewDirectory( wxCommandEvent& event )
|
||||||
{
|
{
|
||||||
// Get the root directory name:
|
// Get the root directory name:
|
||||||
TREEPROJECT_ITEM* treeData = GetSelectedData();
|
TREEPROJECT_ITEM* treeData = GetSelectedData();
|
||||||
|
|
||||||
if( !treeData )
|
if( !treeData )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -369,6 +355,7 @@ void TREE_PROJECT_FRAME::OnCreateNewDirectory( wxCommandEvent& event )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
root = m_TreeProject->GetItemParent( m_TreeProject->GetSelection() );
|
root = m_TreeProject->GetItemParent( m_TreeProject->GetSelection() );
|
||||||
|
|
||||||
if( !root.IsOk() )
|
if( !root.IsOk() )
|
||||||
root = m_TreeProject->GetSelection();
|
root = m_TreeProject->GetSelection();
|
||||||
}
|
}
|
||||||
|
@ -385,6 +372,7 @@ void TREE_PROJECT_FRAME::OnCreateNewDirectory( wxCommandEvent& event )
|
||||||
fn.MakeRelativeTo();
|
fn.MakeRelativeTo();
|
||||||
curr_dir = fn.GetPath() + wxFileName::GetPathSeparator();
|
curr_dir = fn.GetPath() + wxFileName::GetPathSeparator();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString msg;
|
wxString msg;
|
||||||
msg.Printf( wxT( "Current working directory:\n%s" ), GetChars( wxGetCwd() ) );
|
msg.Printf( wxT( "Current working directory:\n%s" ), GetChars( wxGetCwd() ) );
|
||||||
wxString subdir = wxGetTextFromUser( msg, _( "Create New Directory" ), curr_dir );
|
wxString subdir = wxGetTextFromUser( msg, _( "Create New Directory" ), curr_dir );
|
||||||
|
@ -393,16 +381,11 @@ void TREE_PROJECT_FRAME::OnCreateNewDirectory( wxCommandEvent& event )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( wxMkdir( subdir ) )
|
if( wxMkdir( subdir ) )
|
||||||
AddFileToTree( subdir, root );
|
AddItemToTreeProject( subdir, root );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief TODO
|
|
||||||
*/
|
|
||||||
/*****************************************************************************/
|
|
||||||
wxString TREE_PROJECT_FRAME::GetFileExt( TreeFileType type )
|
wxString TREE_PROJECT_FRAME::GetFileExt( TreeFileType type )
|
||||||
/*****************************************************************************/
|
|
||||||
{
|
{
|
||||||
wxString ext;
|
wxString ext;
|
||||||
|
|
||||||
|
@ -467,6 +450,7 @@ wxString TREE_PROJECT_FRAME::GetFileExt( TreeFileType type )
|
||||||
return ext;
|
return ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the wxFileDialog wildcard string for the selected file type.
|
* Return the wxFileDialog wildcard string for the selected file type.
|
||||||
*/
|
*/
|
||||||
|
@ -534,16 +518,16 @@ wxString TREE_PROJECT_FRAME::GetFileWildcard( TreeFileType type )
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function AddFileToTree
|
* Function AddItemToTreeProject
|
||||||
* @brief Add filename "name" to the tree \n
|
* @brief Add filename "name" to the tree \n
|
||||||
* if name is a directory, add the sub directory file names
|
* if name is a directory, add the sub directory file names
|
||||||
* @param aName = the filename or the dirctory name to add
|
* @param aName = the filename or the dirctory name to add
|
||||||
* @param aRoot = the wxTreeItemId item where to add sub tree items
|
* @param aRoot = the wxTreeItemId item where to add sub tree items
|
||||||
* @param aRecurse = true to filenames or sub dir names to the current tree item
|
* @param aRecurse = true to add file or subdir names to the current tree item
|
||||||
* false to stop file add.
|
* false to stop file add.
|
||||||
* @return true if the file (or directory) is added.
|
* @return true if the file (or directory) is added.
|
||||||
*/
|
*/
|
||||||
bool TREE_PROJECT_FRAME::AddFileToTree( const wxString& aName,
|
bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName,
|
||||||
wxTreeItemId& aRoot, bool aRecurse )
|
wxTreeItemId& aRoot, bool aRecurse )
|
||||||
{
|
{
|
||||||
wxTreeItemId cellule;
|
wxTreeItemId cellule;
|
||||||
|
@ -553,6 +537,7 @@ bool TREE_PROJECT_FRAME::AddFileToTree( const wxString& aName,
|
||||||
|
|
||||||
// Skip not visible files and dirs
|
// Skip not visible files and dirs
|
||||||
wxFileName fn( aName );
|
wxFileName fn( aName );
|
||||||
|
|
||||||
// Files/dirs names starting by "." are not visible files under unices.
|
// Files/dirs names starting by "." are not visible files under unices.
|
||||||
// Skip them also under Windows
|
// Skip them also under Windows
|
||||||
if( fn.GetName().StartsWith( wxT( "." ) ) )
|
if( fn.GetName().StartsWith( wxT( "." ) ) )
|
||||||
|
@ -569,17 +554,20 @@ bool TREE_PROJECT_FRAME::AddFileToTree( const wxString& aName,
|
||||||
|
|
||||||
bool isSchematic = false;
|
bool isSchematic = false;
|
||||||
bool addFile = false;
|
bool addFile = false;
|
||||||
for( unsigned i = 0; i < m_Filters.size(); i++ )
|
|
||||||
|
for( unsigned i = 0; i < m_filters.size(); i++ )
|
||||||
{
|
{
|
||||||
wxCHECK2_MSG( reg.Compile( m_Filters[i], wxRE_ICASE ), continue,
|
wxCHECK2_MSG( reg.Compile( m_filters[i], wxRE_ICASE ), continue,
|
||||||
wxT( "Regular expression " ) + m_Filters[i] +
|
wxT( "Regular expression " ) + m_filters[i] +
|
||||||
wxT( " failed to compile." ) );
|
wxT( " failed to compile." ) );
|
||||||
|
|
||||||
if( reg.Matches( aName ) )
|
if( reg.Matches( aName ) )
|
||||||
{
|
{
|
||||||
addFile = true;
|
addFile = true;
|
||||||
|
|
||||||
if( i==0 )
|
if( i==0 )
|
||||||
isSchematic = true;
|
isSchematic = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -600,6 +588,7 @@ bool TREE_PROJECT_FRAME::AddFileToTree( const wxString& aName,
|
||||||
wxString FullFileName = aName;
|
wxString FullFileName = aName;
|
||||||
|
|
||||||
fp = wxFopen( FullFileName, wxT( "rt" ) );
|
fp = wxFopen( FullFileName, wxT( "rt" ) );
|
||||||
|
|
||||||
if( fp == NULL )
|
if( fp == NULL )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -647,9 +636,11 @@ bool TREE_PROJECT_FRAME::AddFileToTree( const wxString& aName,
|
||||||
// also check to see if it is already there.
|
// also check to see if it is already there.
|
||||||
wxTreeItemIdValue cookie;
|
wxTreeItemIdValue cookie;
|
||||||
wxTreeItemId kid = m_TreeProject->GetFirstChild( aRoot, cookie );
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( aRoot, cookie );
|
||||||
|
|
||||||
while( kid.IsOk() )
|
while( kid.IsOk() )
|
||||||
{
|
{
|
||||||
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
||||||
|
|
||||||
if( itemData )
|
if( itemData )
|
||||||
{
|
{
|
||||||
if( itemData->m_FileName == aName )
|
if( itemData->m_FileName == aName )
|
||||||
|
@ -657,8 +648,10 @@ bool TREE_PROJECT_FRAME::AddFileToTree( const wxString& aName,
|
||||||
return true; // well, we would have added it, but it is already here!
|
return true; // well, we would have added it, but it is already here!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
kid = m_TreeProject->GetNextChild( aRoot, cookie );
|
kid = m_TreeProject->GetNextChild( aRoot, cookie );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append the item (only appending the filename not the full path):
|
// Append the item (only appending the filename not the full path):
|
||||||
wxString file = wxFileNameFromPath( aName );
|
wxString file = wxFileNameFromPath( aName );
|
||||||
cellule = m_TreeProject->AppendItem( aRoot, file );
|
cellule = m_TreeProject->AppendItem( aRoot, file );
|
||||||
|
@ -684,11 +677,12 @@ bool TREE_PROJECT_FRAME::AddFileToTree( const wxString& aName,
|
||||||
wxDir dir( aName );
|
wxDir dir( aName );
|
||||||
wxString dir_filename;
|
wxString dir_filename;
|
||||||
data->m_WasPopulated = true; // set state to populated
|
data->m_WasPopulated = true; // set state to populated
|
||||||
|
|
||||||
if( dir.GetFirst( &dir_filename ) )
|
if( dir.GetFirst( &dir_filename ) )
|
||||||
{
|
{
|
||||||
do // Add name in tree, but do not recurse
|
do // Add name in tree, but do not recurse
|
||||||
{
|
{
|
||||||
AddFileToTree( aName + sep + dir_filename, cellule, false );
|
AddItemToTreeProject( aName + sep + dir_filename, cellule, false );
|
||||||
} while( dir.GetNext( &dir_filename ) );
|
} while( dir.GetNext( &dir_filename ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -703,9 +697,7 @@ bool TREE_PROJECT_FRAME::AddFileToTree( const wxString& aName,
|
||||||
/**
|
/**
|
||||||
* @brief Create or modify the tree showing project file names
|
* @brief Create or modify the tree showing project file names
|
||||||
*/
|
*/
|
||||||
/*****************************************************************************/
|
|
||||||
void TREE_PROJECT_FRAME::ReCreateTreePrj()
|
void TREE_PROJECT_FRAME::ReCreateTreePrj()
|
||||||
/*****************************************************************************/
|
|
||||||
{
|
{
|
||||||
wxTreeItemId rootcellule;
|
wxTreeItemId rootcellule;
|
||||||
wxFileName fn;
|
wxFileName fn;
|
||||||
|
@ -750,7 +742,7 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj()
|
||||||
while( cont )
|
while( cont )
|
||||||
{
|
{
|
||||||
if( filename != fn.GetFullName() )
|
if( filename != fn.GetFullName() )
|
||||||
AddFileToTree( dir.GetName() + wxFileName::GetPathSeparator() +
|
AddItemToTreeProject( dir.GetName() + wxFileName::GetPathSeparator() +
|
||||||
filename, m_root );
|
filename, m_root );
|
||||||
|
|
||||||
cont = dir.GetNext( &filename );
|
cont = dir.GetNext( &filename );
|
||||||
|
@ -791,6 +783,7 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
|
||||||
|
|
||||||
// Get the current filename:
|
// Get the current filename:
|
||||||
tree_data = GetSelectedData();
|
tree_data = GetSelectedData();
|
||||||
|
|
||||||
if( !tree_data )
|
if( !tree_data )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -807,6 +800,7 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
|
||||||
for( unsigned int j = 0; j < sizeof(menus) / sizeof(wxMenu*); j++ )
|
for( unsigned int j = 0; j < sizeof(menus) / sizeof(wxMenu*); j++ )
|
||||||
{
|
{
|
||||||
wxMenu* menu = menus[j];
|
wxMenu* menu = menus[j];
|
||||||
|
|
||||||
if( !menu )
|
if( !menu )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -833,13 +827,11 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
|
||||||
PopupMenu( m_PopupMenu );
|
PopupMenu( m_PopupMenu );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
/**
|
* Called by the popup menu, when right clicking on a file name
|
||||||
* @brief TODO
|
* Launch the text editor to open the selected file
|
||||||
*/
|
*/
|
||||||
/*****************************************************************************/
|
void TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor( wxCommandEvent& event )
|
||||||
void TREE_PROJECT_FRAME::OnTxtEdit( wxCommandEvent& event )
|
|
||||||
/*****************************************************************************/
|
|
||||||
{
|
{
|
||||||
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
||||||
|
|
||||||
|
@ -855,27 +847,26 @@ void TREE_PROJECT_FRAME::OnTxtEdit( wxCommandEvent& event )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/* Called via the popup menu, when right clicking on a file name
|
||||||
* @brief TODO
|
* or a directory name to delete the selected file or directory
|
||||||
|
* in the tree project
|
||||||
*/
|
*/
|
||||||
/*****************************************************************************/
|
|
||||||
void TREE_PROJECT_FRAME::OnDeleteFile( wxCommandEvent& )
|
void TREE_PROJECT_FRAME::OnDeleteFile( wxCommandEvent& )
|
||||||
/*****************************************************************************/
|
|
||||||
{
|
{
|
||||||
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
||||||
|
|
||||||
if( !tree_data )
|
if( !tree_data )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tree_data->Delete();
|
tree_data->Delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/* Called via the popup menu, when right clicking on a file name
|
||||||
* @brief TODO
|
* or a directory name to rename the selected file or directory
|
||||||
|
* in the tree project
|
||||||
*/
|
*/
|
||||||
/*****************************************************************************/
|
|
||||||
void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& )
|
void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& )
|
||||||
/*****************************************************************************/
|
|
||||||
{
|
{
|
||||||
wxTreeItemId curr_item = m_TreeProject->GetSelection();
|
wxTreeItemId curr_item = m_TreeProject->GetSelection();
|
||||||
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
||||||
|
@ -887,12 +878,14 @@ void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& )
|
||||||
wxString msg = _( "Change filename: " ) + tree_data->m_FileName;
|
wxString msg = _( "Change filename: " ) + tree_data->m_FileName;
|
||||||
|
|
||||||
wxTextEntryDialog dlg( this, msg, _( "Change filename" ), buffer );
|
wxTextEntryDialog dlg( this, msg, _( "Change filename" ), buffer );
|
||||||
|
|
||||||
if( dlg.ShowModal() != wxID_OK )
|
if( dlg.ShowModal() != wxID_OK )
|
||||||
return; // cancelled by user
|
return; // cancelled by user
|
||||||
|
|
||||||
buffer = dlg.GetValue();
|
buffer = dlg.GetValue();
|
||||||
buffer.Trim( true );
|
buffer.Trim( true );
|
||||||
buffer.Trim( false );
|
buffer.Trim( false );
|
||||||
|
|
||||||
if( buffer.IsEmpty() )
|
if( buffer.IsEmpty() )
|
||||||
return; // empty file name not allowed
|
return; // empty file name not allowed
|
||||||
|
|
||||||
|
@ -901,38 +894,6 @@ void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Prevent the main project to be renamed
|
|
||||||
*/
|
|
||||||
/*****************************************************************************/
|
|
||||||
void TREE_PROJECT_FRAME::OnRenameAsk( wxTreeEvent& event )
|
|
||||||
/*****************************************************************************/
|
|
||||||
{
|
|
||||||
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
|
||||||
|
|
||||||
if( !tree_data )
|
|
||||||
return;
|
|
||||||
if( m_Parent->m_ProjectFileName.GetFullPath() == tree_data->GetFileName() )
|
|
||||||
event.Veto();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Rename a tree item on demand of the context menu
|
|
||||||
*/
|
|
||||||
/*****************************************************************************/
|
|
||||||
void TREE_PROJECT_FRAME::OnRename( wxTreeEvent& event )
|
|
||||||
/*****************************************************************************/
|
|
||||||
{
|
|
||||||
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
|
||||||
|
|
||||||
if( !tree_data )
|
|
||||||
return;
|
|
||||||
|
|
||||||
tree_data->OnRename( event );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TODO
|
* @brief TODO
|
||||||
*/
|
*/
|
||||||
|
@ -946,9 +907,11 @@ void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event )
|
||||||
|
|
||||||
if( !tree_data )
|
if( !tree_data )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tree_data->Activate( this );
|
tree_data->Activate( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Called when expanding an item of the tree
|
* @brief Called when expanding an item of the tree
|
||||||
* populate tree items corresponding to subdirectories not already populated
|
* populate tree items corresponding to subdirectories not already populated
|
||||||
|
@ -971,11 +934,14 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event )
|
||||||
// explore list of non populated subdirs, and populate them
|
// explore list of non populated subdirs, and populate them
|
||||||
wxTreeItemIdValue cookie;
|
wxTreeItemIdValue cookie;
|
||||||
wxTreeItemId kid = m_TreeProject->GetFirstChild( itemId, cookie );
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( itemId, cookie );
|
||||||
|
|
||||||
for( ; kid.IsOk(); kid = m_TreeProject->GetNextChild( itemId, cookie ) )
|
for( ; kid.IsOk(); kid = m_TreeProject->GetNextChild( itemId, cookie ) )
|
||||||
{
|
{
|
||||||
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
||||||
|
|
||||||
if( !itemData || itemData->GetType() != TREE_DIRECTORY )
|
if( !itemData || itemData->GetType() != TREE_DIRECTORY )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( itemData->m_WasPopulated )
|
if( itemData->m_WasPopulated )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -983,13 +949,15 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event )
|
||||||
const wxString sep = wxFileName().GetPathSeparator();
|
const wxString sep = wxFileName().GetPathSeparator();
|
||||||
wxDir dir( fileName );
|
wxDir dir( fileName );
|
||||||
wxString dir_filename;
|
wxString dir_filename;
|
||||||
|
|
||||||
if( dir.GetFirst( &dir_filename ) )
|
if( dir.GetFirst( &dir_filename ) )
|
||||||
{
|
{
|
||||||
do // Add name to tree item, but do not recurse in subdirs:
|
do // Add name to tree item, but do not recurse in subdirs:
|
||||||
{
|
{
|
||||||
AddFileToTree( fileName + sep + dir_filename, kid, false );
|
AddItemToTreeProject( fileName + sep + dir_filename, kid, false );
|
||||||
} while( dir.GetNext( &dir_filename ) );
|
} while( dir.GetNext( &dir_filename ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
itemData->m_WasPopulated = true; // set state to populated
|
itemData->m_WasPopulated = true; // set state to populated
|
||||||
|
|
||||||
/* Sort filenames by alphabetic order */
|
/* Sort filenames by alphabetic order */
|
||||||
|
@ -997,6 +965,7 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function GetSelectedData
|
* Function GetSelectedData
|
||||||
* return the item data from item currently selected (highlighted)
|
* return the item data from item currently selected (highlighted)
|
||||||
|
@ -1005,9 +974,11 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event )
|
||||||
*/
|
*/
|
||||||
TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetSelectedData()
|
TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetSelectedData()
|
||||||
{
|
{
|
||||||
return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( m_TreeProject->GetSelection() ) );
|
return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData
|
||||||
|
( m_TreeProject->GetSelection() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function GetItemIdData
|
* Function GetItemIdData
|
||||||
* return the item data corresponding to a wxTreeItemId identifier
|
* return the item data corresponding to a wxTreeItemId identifier
|
||||||
|
@ -1019,4 +990,167 @@ TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetItemIdData(wxTreeItemId aId)
|
||||||
return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( aId ) );
|
return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( aId ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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 );
|
||||||
|
|
||||||
|
if( itemData )
|
||||||
|
{
|
||||||
|
if( itemData->GetType() != TREE_DIRECTORY )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if( itemData->m_FileName == aSubDir ) // Found!
|
||||||
|
{
|
||||||
|
root_id = kid;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if kid is a subdir, push in list to explore it later
|
||||||
|
if( itemData->GetType() == TREE_DIRECTORY &&
|
||||||
|
itemData->m_WasPopulated )
|
||||||
|
subdirs_id.push( kid );
|
||||||
|
}
|
||||||
|
kid = m_TreeProject->GetNextChild( root_id, cookie );
|
||||||
|
}
|
||||||
|
|
||||||
|
return root_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if wxCHECK_VERSION( 2, 9, 2 )
|
||||||
|
/* called when a file or directory is modified/created/deleted
|
||||||
|
* The tree project should be rebuilt when a file or directory
|
||||||
|
* is created or deleted
|
||||||
|
*/
|
||||||
|
void TREE_PROJECT_FRAME::OnFileSystemEvent( wxFileSystemWatcherEvent& event )
|
||||||
|
{
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxFileName pathModified = event.GetPath();
|
||||||
|
wxString subdir = pathModified.GetPath();
|
||||||
|
wxString fn = pathModified.GetFullPath();
|
||||||
|
|
||||||
|
wxTreeItemId root_id = findSubdirTreeItem( subdir );
|
||||||
|
if( !root_id.IsOk() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Add item if it is created
|
||||||
|
if( event.GetChangeType() == wxFSW_EVENT_CREATE )
|
||||||
|
AddItemToTreeProject( pathModified.GetFullPath(), root_id, false );
|
||||||
|
|
||||||
|
// search for item to delete/rename.
|
||||||
|
if( event.GetChangeType() == wxFSW_EVENT_DELETE ||
|
||||||
|
event.GetChangeType() == wxFSW_EVENT_RENAME )
|
||||||
|
{
|
||||||
|
wxTreeItemIdValue cookie; // dummy variable needed by GetFirstChild()
|
||||||
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
|
||||||
|
|
||||||
|
while( kid.IsOk() )
|
||||||
|
{
|
||||||
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
||||||
|
|
||||||
|
if( itemData )
|
||||||
|
{
|
||||||
|
if( itemData->m_FileName == fn )
|
||||||
|
{
|
||||||
|
if( event.GetChangeType() == wxFSW_EVENT_DELETE )
|
||||||
|
{
|
||||||
|
m_TreeProject->Delete( kid );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxFileName newpath = event.GetNewPath();
|
||||||
|
wxString newfn = newpath.GetFullPath();
|
||||||
|
// Change item label and item data
|
||||||
|
// Extension could be modified and be not an usually selected file type
|
||||||
|
// However, here we do not filter files.
|
||||||
|
// This is simple, and I am not sure filtering renamed files here is better,
|
||||||
|
// becuse they could disappear, like deleted files
|
||||||
|
itemData->SetFileName( newpath.GetFullPath() );
|
||||||
|
m_TreeProject->SetItemText( kid, newpath.GetFullName() );
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kid = m_TreeProject->GetNextChild( root_id, cookie );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Sort filenames by alphabetic order */
|
||||||
|
m_TreeProject->SortChildren( root_id );
|
||||||
|
}
|
||||||
|
|
||||||
|
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.
|
||||||
|
// under windows, we add the curr dir and subdirs
|
||||||
|
// under unix, we add only the curr dir
|
||||||
|
// see http://docs.wxwidgets.org/trunk/classwx_file_system_watcher.htm
|
||||||
|
// under unix, the file watcher needs more work to be efficient
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
m_watcher->AddTree( wxFileName::DirName( wxT( "./" ) ) );
|
||||||
|
#else
|
||||||
|
m_watcher->Add( wxFileName::DirName( wxT( "./" ) ) );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
/*
|
/*
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 1992-2009 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.fr
|
* Copyright (C) 1992-2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||||
* Copyright (C) 1992-2009 KiCad Developers, see change_log.txt for contributors.
|
* Copyright (C) 1992-2012 KiCad Developers, see change_log.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
@ -29,6 +29,10 @@
|
||||||
#ifndef TREEPRJ_FRAME_H
|
#ifndef TREEPRJ_FRAME_H
|
||||||
#define TREEPRJ_FRAME_H
|
#define TREEPRJ_FRAME_H
|
||||||
|
|
||||||
|
#if wxCHECK_VERSION( 2, 9, 2 )
|
||||||
|
#include <wx/fswatcher.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
class TREEPROJECT_ITEM;
|
class TREEPROJECT_ITEM;
|
||||||
|
|
||||||
/** class TREE_PROJECT_FRAME
|
/** class TREE_PROJECT_FRAME
|
||||||
|
@ -36,17 +40,34 @@ class TREEPROJECT_ITEM;
|
||||||
*/
|
*/
|
||||||
class TREE_PROJECT_FRAME : public wxSashLayoutWindow
|
class TREE_PROJECT_FRAME : public wxSashLayoutWindow
|
||||||
{
|
{
|
||||||
|
friend class TREEPROJECT_ITEM;
|
||||||
|
public:
|
||||||
|
KICAD_MANAGER_FRAME* m_Parent;
|
||||||
|
TREEPROJECTFILES* m_TreeProject;
|
||||||
|
wxTreeItemId m_root;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::vector<wxMenu*> m_ContextMenus;
|
std::vector<wxMenu*> m_ContextMenus;
|
||||||
std::vector<wxString> m_Filters;
|
std::vector<wxString> m_filters;
|
||||||
|
|
||||||
wxMenu* m_PopupMenu;
|
wxMenu* m_PopupMenu;
|
||||||
wxCursor m_DragCursor;
|
wxCursor m_DragCursor;
|
||||||
wxCursor m_Default;
|
wxCursor m_Default;
|
||||||
|
|
||||||
|
#if wxCHECK_VERSION( 2, 9, 2 )
|
||||||
|
wxFileSystemWatcher* m_watcher; // file system watcher
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public:
|
||||||
|
TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent );
|
||||||
|
~TREE_PROJECT_FRAME();
|
||||||
|
void ReCreateTreePrj();
|
||||||
|
#if wxCHECK_VERSION( 2, 9, 2 )
|
||||||
|
void FileWatcherReset();
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxMenu* GetContextMenu( int type );
|
wxMenu* GetContextMenu( int type );
|
||||||
|
static wxString GetFileExt( TreeFileType type );
|
||||||
|
static wxString GetFileWildcard( TreeFileType type );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function GetSelectedData
|
* Function GetSelectedData
|
||||||
|
@ -55,6 +76,7 @@ protected:
|
||||||
* because when expanding, collapsing an item this item is not selected
|
* because when expanding, collapsing an item this item is not selected
|
||||||
*/
|
*/
|
||||||
TREEPROJECT_ITEM* GetSelectedData();
|
TREEPROJECT_ITEM* GetSelectedData();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function GetItemIdData
|
* Function GetItemIdData
|
||||||
* return the item data corresponding to a wxTreeItemId identifier
|
* return the item data corresponding to a wxTreeItemId identifier
|
||||||
|
@ -63,30 +85,35 @@ protected:
|
||||||
*/
|
*/
|
||||||
TREEPROJECT_ITEM* GetItemIdData( wxTreeItemId aId );
|
TREEPROJECT_ITEM* GetItemIdData( wxTreeItemId aId );
|
||||||
|
|
||||||
public:
|
private:
|
||||||
KICAD_MANAGER_FRAME* m_Parent;
|
|
||||||
TREEPROJECTFILES* m_TreeProject;
|
|
||||||
|
|
||||||
wxTreeItemId m_root;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static wxString GetFileExt( TreeFileType type );
|
|
||||||
static wxString GetFileWildcard( TreeFileType type );
|
|
||||||
|
|
||||||
TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent );
|
|
||||||
~TREE_PROJECT_FRAME();
|
|
||||||
void OnSelect( wxTreeEvent& Event );
|
void OnSelect( wxTreeEvent& Event );
|
||||||
void OnExpand( wxTreeEvent& Event );
|
void OnExpand( wxTreeEvent& Event );
|
||||||
void OnRenameAsk( wxTreeEvent& Event );
|
|
||||||
void OnRename( wxTreeEvent& Event );
|
|
||||||
void OnDragStart( wxTreeEvent& event );
|
void OnDragStart( wxTreeEvent& event );
|
||||||
void OnDragEnd( wxTreeEvent& event );
|
void OnDragEnd( wxTreeEvent& event );
|
||||||
void OnRight( wxTreeEvent& Event );
|
void OnRight( wxTreeEvent& Event );
|
||||||
void ReCreateTreePrj();
|
|
||||||
|
|
||||||
void OnTxtEdit( wxCommandEvent& event );
|
/**
|
||||||
|
* Function OnOpenSelectedFileWithTextEditor
|
||||||
|
* Called via the popup menu, when right clicking on a file name
|
||||||
|
* Call the text editor to open the selected file
|
||||||
|
* in the tree project
|
||||||
|
*/
|
||||||
|
void OnOpenSelectedFileWithTextEditor( wxCommandEvent& event );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function OnDeleteFile
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
void OnDeleteFile( wxCommandEvent& event );
|
void OnDeleteFile( wxCommandEvent& event );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function OnRenameFile
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
void OnRenameFile( wxCommandEvent& event );
|
void OnRenameFile( wxCommandEvent& event );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,22 +123,46 @@ public:
|
||||||
*/
|
*/
|
||||||
void OnCreateNewDirectory( wxCommandEvent& event );
|
void OnCreateNewDirectory( wxCommandEvent& event );
|
||||||
|
|
||||||
void ClearFilters();
|
void ClearFilters()
|
||||||
|
{
|
||||||
|
m_filters.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<wxString>& GetFilters()
|
||||||
|
{
|
||||||
|
return m_filters;
|
||||||
|
}
|
||||||
|
|
||||||
const std::vector<wxString>& GetFilters();
|
|
||||||
void RemoveFilter( const wxString& filter );
|
void RemoveFilter( const wxString& filter );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function AddFileToTree
|
* Function AddItemToTreeProject
|
||||||
* @brief Add the file or directory aName to the project tree
|
* @brief Add the file or directory aName to the project tree
|
||||||
* @param aName = the filename or the directory name to add in tree
|
* @param aName = the filename or the directory name to add in tree
|
||||||
* @param aRoot = the wxTreeItemId item where to add sub tree items
|
* @param aRoot = the wxTreeItemId item where to add sub tree items
|
||||||
* @param aRecurse = true to filenames or sub dir names to the current tree item
|
* @param aRecurse = true to add file or subdir names to the current tree item
|
||||||
* false to stop file add.
|
* false to stop file add.
|
||||||
* @return true if the file (or directory) is added.
|
* @return true if the file (or directory) is added.
|
||||||
*/
|
*/
|
||||||
bool AddFileToTree( const wxString& aName,
|
bool AddItemToTreeProject( const wxString& aName,
|
||||||
wxTreeItemId& aRoot, bool aRecurse = true);
|
wxTreeItemId& aRoot,
|
||||||
|
bool aRecurse = true );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* function findSubdirTreeItem
|
||||||
|
* 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 findSubdirTreeItem( const wxString& aSubDir );
|
||||||
|
|
||||||
|
#if wxCHECK_VERSION( 2, 9, 2 )
|
||||||
|
void OnFileSystemEvent( wxFileSystemWatcherEvent& event );
|
||||||
|
#endif
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue