Kicad manager:

* Use the recent wxFileSystemWatcher to automatically update the tree project when a file is created/deleted/renamed in the project directory
(and if the file type is usually shown by the manager.)
Needs wxWidgets 2.9.4 or more recent.
* Also code cleanup, dead code or useless code removed.
This commit is contained in:
jean-pierre charras 2013-01-01 16:57:48 +01:00
commit 8c75adb8c1
11 changed files with 679 additions and 420 deletions

View File

@ -1,10 +1,34 @@
/**
* @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
*/
/*
* 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 <gestfich.h>
#include <macros.h>
@ -18,37 +42,30 @@
#include <wx/regex.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,
wxTreeCtrl* parent ) :
wxTreeCtrl* parent ) :
wxTreeItemData()
{
m_Type = type;
m_Parent = parent;
m_FileName = data;
m_IsRootFile = false; // true only for the root item of the tree (the project name)
m_WasPopulated = false;
m_Type = type;
m_parent = parent;
m_FileName = data;
m_IsRootFile = false; // true only for the root item of the tree (the project name)
m_WasPopulated = false;
}
// Set the state used in the icon list
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 ) )
return;
m_State = state;
m_state = state;
int imgid = m_Type - 1 + state * ( TREE_MAX - 1 );
m_Parent->SetItemImage( GetId(), imgid );
m_Parent->SetItemImage( GetId(), imgid, wxTreeItemIcon_Selected );
m_parent->SetItemImage( GetId(), imgid );
m_parent->SetItemImage( GetId(), imgid, wxTreeItemIcon_Selected );
}
@ -62,9 +79,10 @@ wxString TREEPROJECT_ITEM::GetDir() const
filename.MakeRelativeTo( wxGetCwd() );
wxArrayString dirs = filename.GetDirs();
wxArrayString dirs = filename.GetDirs();
wxString dir;
wxString dir;
for( unsigned int i = 0; i < dirs.Count(); i++ )
{
dir += dirs[i] + filename.GetPathSeparator();
@ -74,49 +92,42 @@ 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
void TREEPROJECT_ITEM::Move( TREEPROJECT_ITEM* dest )
{
//function not safe.
// function not safe.
return;
const wxString sep = wxFileName().GetPathSeparator();
if( m_Type == TREE_DIRECTORY )
return;
if( !dest )
return;
if( m_Parent != dest->m_Parent )
if( m_parent != dest->m_parent )
return; // Can not cross move!
if( dest == this )
return; // Can not move to ourself...
wxTreeItemId parent = m_Parent->GetItemParent( GetId() );
if( dest == dynamic_cast<TREEPROJECT_ITEM*>( m_Parent->GetItemData( parent ) ) )
wxTreeItemId parent = m_parent->GetItemParent( GetId() );
if( dest == dynamic_cast<TREEPROJECT_ITEM*>( m_parent->GetItemData( parent ) ) )
return; // same parent ?
// We need to create a new item from us, and move
// data to there ...
// First move file on the disk
wxFileName fname( m_FileName );
wxFileName fname( m_FileName );
wxString destName;
wxString destName;
if( !dest->GetDir().IsEmpty() )
destName = dest->GetDir() + sep;
destName += fname.GetFullName();
if( destName == GetFileName() )
@ -125,7 +136,7 @@ void TREEPROJECT_ITEM::Move( TREEPROJECT_ITEM* dest )
// Move the file on the disk:
if( !wxRenameFile( GetFileName(), destName, false ) )
{
wxMessageDialog( m_Parent, _( "Unable to move file ... " ),
wxMessageDialog( m_parent, _( "Unable to move file ... " ),
_( "Permission error ?" ), wxICON_ERROR | wxOK );
return;
}
@ -135,39 +146,38 @@ void TREEPROJECT_ITEM::Move( TREEPROJECT_ITEM* dest )
if( TREE_DIRECTORY != GetType() )
{
// Move the tree item itself now:
wxTreeItemId oldId = GetId();
int i = m_Parent->GetItemImage( oldId );
wxString text = m_Parent->GetItemText( oldId );
wxTreeItemId oldId = GetId();
int i = m_parent->GetItemImage( oldId );
wxString text = m_parent->GetItemText( oldId );
// Bye bye old Id :'(
wxTreeItemId newId = m_Parent->AppendItem( dest->GetId(), text, i );
m_Parent->SetItemData( newId, this );
m_Parent->SetItemData( oldId, NULL );
m_Parent->Delete( oldId );
wxTreeItemId newId = m_parent->AppendItem( dest->GetId(), text, i );
m_parent->SetItemData( newId, this );
m_parent->SetItemData( oldId, NULL );
m_parent->Delete( oldId );
}
else
{
// 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 ...)
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 */
bool TREEPROJECT_ITEM::Rename( const wxString& name, bool check )
{
//this is broken & unsafe to use on linux.
// this is broken & unsafe to use on linux.
if( m_Type == TREE_DIRECTORY )
return false;
if( name.IsEmpty() )
return false;
const wxString sep = wxFileName().GetPathSeparator();
wxString newFile;
wxString dirs = GetDir();
const wxString sep = wxFileName().GetPathSeparator();
wxString newFile;
wxString dirs = GetDir();
if( !dirs.IsEmpty() && GetType() != TREE_DIRECTORY )
newFile = dirs + sep + name;
@ -177,15 +187,16 @@ bool TREEPROJECT_ITEM::Rename( const wxString& name, bool check )
if( newFile == m_FileName )
return false;
wxString ext = TREE_PROJECT_FRAME::GetFileExt( GetType() );
wxString ext = TREE_PROJECT_FRAME::GetFileExt( GetType() );
wxRegEx reg( wxT ( "^.*\\" ) + ext + wxT( "$" ), wxRE_ICASE );
wxRegEx reg( wxT( "^.*\\" ) + ext + wxT( "$" ), wxRE_ICASE );
if( check && !ext.IsEmpty() && !reg.Matches( newFile ) )
{
wxMessageDialog dialog( m_Parent,
_( "Changing file extension will change file \
type.\n Do you want to continue ?" ),
wxMessageDialog dialog( m_parent,
_(
"Changing file extension will change file \
type.\n Do you want to continue ?" ),
_( "Rename File" ),
wxYES_NO | wxICON_QUESTION );
@ -194,16 +205,19 @@ type.\n Do you want to continue ?" ),
}
#if ( ( wxMAJOR_VERSION < 2 ) || ( ( wxMAJOR_VERSION == 2 ) \
&& ( wxMINOR_VERSION < 7 ) ) )
&& ( wxMINOR_VERSION < 7 ) ) )
if( !wxRenameFile( m_FileName, newFile ) )
#else
if( !wxRenameFile( m_FileName, newFile, false ) )
#endif
{
wxMessageDialog( m_Parent, _( "Unable to rename file ... " ),
wxMessageDialog( m_parent, _( "Unable to rename file ... " ),
_( "Permission error ?" ), wxICON_ERROR | wxOK );
return false;
}
SetFileName( newFile );
return true;
@ -215,17 +229,18 @@ bool TREEPROJECT_ITEM::Delete( bool check )
/*******************************************/
/* delete a file */
{
wxString msg;
msg.Printf( _("Do you really want to delete '%s'"), GetChars(GetFileName() ) );
wxMessageDialog dialog( m_Parent, msg,
wxString msg;
msg.Printf( _( "Do you really want to delete '%s'" ), GetChars( GetFileName() ) );
wxMessageDialog dialog( m_parent, msg,
_( "Delete File" ), wxYES_NO | wxICON_QUESTION );
if( !check || wxID_YES == dialog.ShowModal() )
{
bool success;
if( !wxDirExists( m_FileName ) )
{
wxRemoveFile( m_FileName );
}
success = wxRemoveFile( m_FileName );
else
{
wxArrayString filelist;
@ -235,12 +250,15 @@ bool TREEPROJECT_ITEM::Delete( bool check )
for( unsigned int i = 0; i < filelist.Count(); 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;
}
@ -248,31 +266,32 @@ bool TREEPROJECT_ITEM::Delete( bool check )
/* Called under item activation */
void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe )
{
wxString sep = wxFileName().GetPathSeparator();
wxString FullFileName = GetFileName();
wxTreeItemId id = GetId();
wxString sep = wxFileName().GetPathSeparator();
wxString FullFileName = GetFileName();
wxTreeItemId id = GetId();
AddDelimiterString( FullFileName );
switch( GetType() )
{
case TREE_PROJECT:
break;
case TREE_DIRECTORY:
m_Parent->Toggle( id );
m_parent->Toggle( id );
break;
case TREE_SCHEMA:
ExecuteFile( m_Parent, EESCHEMA_EXE, FullFileName );
ExecuteFile( m_parent, EESCHEMA_EXE, FullFileName );
break;
case TREE_LEGACY_PCB:
case TREE_SEXP_PCB:
ExecuteFile( m_Parent, PCBNEW_EXE, FullFileName );
ExecuteFile( m_parent, PCBNEW_EXE, FullFileName );
break;
case TREE_GERBER:
ExecuteFile( m_Parent, GERBVIEW_EXE, FullFileName );
ExecuteFile( m_parent, GERBVIEW_EXE, FullFileName );
break;
case TREE_PDF:
@ -280,20 +299,21 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe )
break;
case TREE_NET:
ExecuteFile( m_Parent, CVPCB_EXE, FullFileName );
ExecuteFile( m_parent, CVPCB_EXE, FullFileName );
break;
case TREE_TXT:
{
wxString editorname = wxGetApp().GetEditorName();
if( !editorname.IsEmpty() )
ExecuteFile( m_Parent, editorname, FullFileName );
break;
}
{
wxString editorname = wxGetApp().GetEditorName();
if( !editorname.IsEmpty() )
ExecuteFile( m_parent, editorname, FullFileName );
break;
}
default:
OpenFile( FullFileName );
break;
}
}

View File

@ -9,28 +9,24 @@
class TREEPROJECT_ITEM : public wxTreeItemData
{
public:
TreeFileType m_Type; // = TREE_PROJECT, TREE_DIRECTORY ...
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_WasPopulated; // True the name is a directory, and its containt was read
TreeFileType m_Type; // = TREE_PROJECT, TREE_DIRECTORY ...
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_WasPopulated; // True the name is a directory, and its content was read
private:
wxTreeCtrl* m_Parent;
wxMenu m_fileMenu;
int m_State;
wxTreeCtrl* m_parent;
wxMenu m_fileMenu;
int m_state;
public:
TREEPROJECT_ITEM( TreeFileType type, const wxString& data,
wxTreeCtrl* parent );
TREEPROJECT_ITEM() : m_Parent( NULL ) { }
TREEPROJECT_ITEM() : m_parent( NULL ) { }
TREEPROJECT_ITEM( const TREEPROJECT_ITEM& src ) :
m_Type( src.m_Type ),
m_FileName( src.m_FileName ),
m_Parent( src.m_Parent )
m_Type( src.m_Type ), m_FileName( src.m_FileName ), m_parent( src.m_parent )
{
SetState( src.m_State );
SetState( src.m_state );
m_WasPopulated = false;
}
@ -39,39 +35,32 @@ public:
return m_Type;
}
void SetType( TreeFileType aType )
{
m_Type = aType;
}
wxString GetFileName() const
{
return m_FileName;
}
void SetFileName( const wxString& 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 Delete( bool check = true );
void Move( TREEPROJECT_ITEM* dest );
void Activate( TREE_PROJECT_FRAME* prjframe );
bool Rename( const wxString& name, bool check = true );
bool Delete( bool check = true );
void Move( TREEPROJECT_ITEM* dest );
void Activate( TREE_PROJECT_FRAME* prjframe );
const wxMenu* GetMenu()
{
return &m_fileMenu;
}
void SetState( int state );
void SetState( int state );
};

View File

@ -45,7 +45,7 @@ IMPLEMENT_ABSTRACT_CLASS( TREEPROJECTFILES, wxTreeCtrl )
TREEPROJECTFILES::TREEPROJECTFILES( TREE_PROJECT_FRAME* parent ) :
wxTreeCtrl( parent, ID_PROJECT_TREE,
wxDefaultPosition, wxDefaultSize,
wxTR_HAS_BUTTONS | wxTR_EDIT_LABELS, wxDefaultValidator,
wxTR_HAS_BUTTONS, wxDefaultValidator,
wxT( "EDATreeCtrl" ) )
{
m_Parent = parent;

View File

@ -31,12 +31,6 @@
#include <fctsys.h>
#include <appl_wxstruct.h>
#ifdef USE_SPLASH_IMAGE
#define SPLASH_IMAGE logo_kicad.png
#include "wx/splash.h"
#include "wx/mediactrl.h"
#endif
#include <kicad.h>
#include <tree_project_frame.h>
#include <wildcards_and_files_ext.h>
@ -45,12 +39,6 @@
const wxString g_KicadPrjFilenameExtension( wxT( ".pro" ) );
/* Import functions */
char* GetFileName( char* FullPathName );
void ShowLogo( char* FonteFileName );
/* Local functions */
/************************************/
/* Called to initialize the program */
/************************************/
@ -113,7 +101,8 @@ bool EDA_APP::OnInit()
wxFileName namelessProject( wxGetCwd(), NAMELESS_PROJECT, ProjectFileExtension );
frame = new KICAD_MANAGER_FRAME( NULL, wxT( "KiCad" ),
wxPoint( 30, 20 ), wxSize( 600, 400 ) );
wxDefaultPosition, wxDefaultSize );
SetTopWindow( frame );
if( argc > 1 )
{
@ -141,38 +130,6 @@ bool EDA_APP::OnInit()
frame->OnLoadProject( cmd );
}
wxString title = GetTitle() + wxT( " " ) + GetBuildVersion() +
wxT( " " ) + frame->m_ProjectFileName.GetFullPath();
if( !namelessProject.IsDirWritable() )
title += _( " [Read Only]" );
frame->SetTitle( title );
frame->ReCreateMenuBar();
frame->RecreateBaseHToolbar();
frame->m_LeftWin->ReCreateTreePrj();
SetTopWindow( frame );
/* Splash screen logo */
#ifdef USE_SPLASH_IMAGE
wxBitmap bmp;
wxString binDir = GetTraits()->GetStandardPaths().GetExecutablePath() +
wxFileName::GetPathSeparator();
if( bmp.LoadFile( binDir + _T( "logokicad.png" ), wxBITMAP_TYPE_PNG ) )
{
wxSplashScreen* splash = new wxSplashScreen( splash_screen,
wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_TIMEOUT,
3000,
frame,
wxID_ANY,
wxDefaultPosition,
wxDefaultSize,
wxSIMPLE_BORDER | wxSTAY_ON_TOP );
}
#endif /* USE_SPLASH_IMAGE */
frame->Show( true );
frame->Raise();

View File

@ -15,6 +15,12 @@
#include <wxstruct.h>
#include <appl_wxstruct.h>
// With a recent wxWidget, we can use the wxFileSystemWatcherEvent
// to monitor files add/remove/rename in tree project
#if wxCHECK_VERSION( 2, 9, 4 )
#define KICAD_USE_FILES_WATCHER
#endif
extern const wxString g_KicadPrjFilenameExtension;
class RIGHT_KM_FRAME;
@ -77,7 +83,8 @@ enum id_kicad_frm {
ID_SELECT_PREFERED_PDF_BROWSER,
ID_SELECT_DEFAULT_PDF_BROWSER,
ID_SAVE_AND_ZIP_FILES,
ID_READ_ZIP_ARCHIVE
ID_READ_ZIP_ARCHIVE,
ID_INIT_WATCHED_PATHS
};
@ -175,6 +182,15 @@ public: KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& title,
*/
void SaveSettings();
#ifdef KICAD_USE_FILES_WATCHER
void FileWatcherReset();
/**
* Called by sending a event with id = ID_INIT_WATCHED_PATHS
* rebuild the list of wahtched paths
*/
void OnChangeWatchedPaths(wxCommandEvent& aEvent );
#endif
DECLARE_EVENT_TABLE()
};

View File

@ -89,6 +89,7 @@ KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME( wxWindow* parent,
PrintMsg( line );
RecreateBaseHToolbar();
ReCreateMenuBar();
m_auimgr.SetManagedWindow( this );
@ -258,8 +259,9 @@ void KICAD_MANAGER_FRAME::OnOpenFileInTextEditor( wxCommandEvent& event )
#endif
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 );
if( dlg.ShowModal() == wxID_CANCEL )

View File

@ -31,6 +31,7 @@
#include <appl_wxstruct.h>
#include <kicad.h>
#include <menus_helpers.h>
#include <tree_project_frame.h>
/* Menubar and toolbar event table */
BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME )
@ -67,9 +68,13 @@ BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME )
/* Range menu events */
EVT_MENU_RANGE( ID_LANGUAGE_CHOICE, ID_LANGUAGE_CHOICE_END, KICAD_MANAGER_FRAME::SetLanguage )
EVT_MENU_RANGE( wxID_FILE1, wxID_FILE9, KICAD_MANAGER_FRAME::OnFileHistory )
// Special functions
#ifdef KICAD_USE_FILES_WATCHER
EVT_MENU( ID_INIT_WATCHED_PATHS, KICAD_MANAGER_FRAME::OnChangeWatchedPaths )
#endif
/* Button events */
EVT_BUTTON( ID_TO_PCB, KICAD_MANAGER_FRAME::OnRunPcbNew )
EVT_BUTTON( ID_TO_CVPCB, KICAD_MANAGER_FRAME::OnRunCvpcb )

View File

@ -148,13 +148,14 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
{
int style;
wxString title;
bool newProject = ( event.GetId() == ID_NEW_PROJECT ) ||
( event.GetId() == ID_NEW_PROJECT_FROM_TEMPLATE );
ClearMsg();
if( event.GetId() != wxID_ANY )
{
if( ( event.GetId() == ID_NEW_PROJECT ) ||
( event.GetId() == ID_NEW_PROJECT_FROM_TEMPLATE ) )
if( newProject )
{
title = _( "Create New Project" );
style = wxFD_SAVE | wxFD_OVERWRITE_PROMPT;
@ -165,15 +166,16 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
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 )
return;
m_ProjectFileName = dlg.GetPath();
if( ( event.GetId() == ID_NEW_PROJECT ) ||
( event.GetId() == ID_NEW_PROJECT_FROM_TEMPLATE ) )
if( newProject )
{
if ( !m_ProjectFileName.GetFullPath().EndsWith( g_KicadPrjFilenameExtension ) )
{
@ -221,11 +223,17 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
SetTitle( title );
UpdateFileHistory( m_ProjectFileName.GetFullPath() );
m_LeftWin->ReCreateTreePrj();
#ifdef KICAD_USE_FILES_WATCHER
// Rebuild the list of watched paths.
// however this is possible only when the main loop event handler is running,
// so we use it to rub the rebuild function.
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED, ID_INIT_WATCHED_PATHS );
wxPostEvent( this, cmd);
#endif
PrintMsg( _( "Working dir: " ) + m_ProjectFileName.GetPath() +
_( "\nProject: " ) + m_ProjectFileName.GetFullName() +
wxT( "\n" ) );
}

View File

@ -161,7 +161,8 @@ bool PROJECT_TEMPLATE::CreateProject( wxFileName& aNewProjectPath )
wxString* PROJECT_TEMPLATE::GetTitle(void)
{
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 */
if( title == wxEmptyString )

File diff suppressed because it is too large Load Diff

View File

@ -5,8 +5,8 @@
/*
* 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-2009 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 1992-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
@ -29,6 +29,12 @@
#ifndef TREEPRJ_FRAME_H
#define TREEPRJ_FRAME_H
#include <kicad.h>
#ifdef KICAD_USE_FILES_WATCHER
#include <wx/fswatcher.h>
#endif
class TREEPROJECT_ITEM;
/** class TREE_PROJECT_FRAME
@ -36,17 +42,40 @@ class TREEPROJECT_ITEM;
*/
class TREE_PROJECT_FRAME : public wxSashLayoutWindow
{
friend class TREEPROJECT_ITEM;
public:
KICAD_MANAGER_FRAME* m_Parent;
TREEPROJECTFILES* m_TreeProject;
wxTreeItemId m_root;
private:
std::vector<wxMenu*> m_ContextMenus;
std::vector<wxString> m_filters;
wxMenu* m_PopupMenu;
wxCursor m_DragCursor;
wxCursor m_Default;
std::vector<wxMenu*> m_ContextMenus;
std::vector<wxString> m_Filters;
#ifdef KICAD_USE_FILES_WATCHER
wxFileSystemWatcher* m_watcher; // file system watcher (since wxWidgets 2.9.2)
#endif
wxMenu* m_PopupMenu;
wxCursor m_DragCursor;
wxCursor m_Default;
public:
TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent );
~TREE_PROJECT_FRAME();
void ReCreateTreePrj();
#ifdef KICAD_USE_FILES_WATCHER
/**
* Reinit the watched paths
* Should be called after opening a new project to
* rebuild the list of watched paths.
* Should be called *atfer* the main loop event handler is started
*/
void FileWatcherReset();
#endif
protected:
wxMenu* GetContextMenu( int type );
wxMenu* GetContextMenu( int type );
static wxString GetFileExt( TreeFileType type );
static wxString GetFileWildcard( TreeFileType type );
/**
* Function GetSelectedData
@ -54,66 +83,101 @@ protected:
* Note this is not necessary the "clicked" item,
* because when expanding, collapsing an item this item is not selected
*/
TREEPROJECT_ITEM* GetSelectedData();
TREEPROJECT_ITEM* GetSelectedData();
/**
* Function GetItemIdData
* return the item data corresponding to a wxTreeItemId identifier
* @param aId = the wxTreeItemId identifier.
* @return a TREEPROJECT_ITEM pointer correspondinfg to item id aId
*/
TREEPROJECT_ITEM* GetItemIdData(wxTreeItemId aId);
TREEPROJECT_ITEM* GetItemIdData( wxTreeItemId aId );
public:
KICAD_MANAGER_FRAME* m_Parent;
TREEPROJECTFILES* m_TreeProject;
private:
void OnSelect( wxTreeEvent& Event );
void OnExpand( wxTreeEvent& Event );
void OnDragStart( wxTreeEvent& event );
void OnDragEnd( wxTreeEvent& event );
void OnRight( wxTreeEvent& Event );
wxTreeItemId m_root;
/**
* 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 );
public:
static wxString GetFileExt( TreeFileType type );
static wxString GetFileWildcard( TreeFileType type );
/**
* 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 );
TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent );
~TREE_PROJECT_FRAME();
void OnSelect( wxTreeEvent& Event );
void OnExpand( wxTreeEvent& Event );
void OnRenameAsk( wxTreeEvent& Event );
void OnRename( wxTreeEvent& Event );
void OnDragStart( wxTreeEvent& event );
void OnDragEnd( wxTreeEvent& event );
void OnRight( wxTreeEvent& Event );
void ReCreateTreePrj();
void OnTxtEdit( wxCommandEvent& event );
void OnDeleteFile( wxCommandEvent& event );
void OnRenameFile( 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 );
/**
* Function OnCreateNewDirectory
* Creates a new subdirectory inside the current kicad project directory
* the user is prompted to enter a directory name
*/
void OnCreateNewDirectory( wxCommandEvent& event );
void OnCreateNewDirectory( wxCommandEvent& event );
void ClearFilters();
void ClearFilters()
{
m_filters.clear();
}
const std::vector<wxString>& GetFilters();
void RemoveFilter( const wxString& filter );
const std::vector<wxString>& GetFilters()
{
return m_filters;
}
/**
* Function AddFileToTree
void RemoveFilter( const wxString& filter );
/**
* Function AddItemToTreeProject
* @brief Add the file or directory aName to the project 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 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.
* @return true if the file (or directory) is added.
*/
bool AddFileToTree( const wxString& aName,
wxTreeItemId& aRoot, bool aRecurse = true);
bool AddItemToTreeProject( const wxString& aName,
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 );
#ifdef KICAD_USE_FILES_WATCHER
/**
* called when a file or directory is modified/created/deleted
* The tree project is modified when a file or directory
* is created/deleted/renamed to reflect the file change
*/
void OnFileSystemEvent( wxFileSystemWatcherEvent& event );
#endif
DECLARE_EVENT_TABLE()
};
#endif // TREEPRJ_FRAME_H
#endif // TREEPRJ_FRAME_H