Commit 45b01a5c authored by jean-pierre charras's avatar jean-pierre charras

Kicad manager: first use of wxFileSystemWatcher (only with wxWidgets >= 2.9.2)...

Kicad manager: first use of wxFileSystemWatcher (only with wxWidgets >= 2.9.2) to monitor files list.
parent 6789e622
This diff is collapsed.
...@@ -9,28 +9,24 @@ ...@@ -9,28 +9,24 @@
class TREEPROJECT_ITEM : public wxTreeItemData class TREEPROJECT_ITEM : public wxTreeItemData
{ {
public: 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,39 +35,32 @@ public: ...@@ -39,39 +35,32 @@ 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; bool Rename( const wxString& name, bool check = true );
bool Delete( bool check = true );
void OnRename( wxTreeEvent& event, bool check = true ); void Move( TREEPROJECT_ITEM* dest );
bool Rename( const wxString& name, bool check = true ); void Activate( TREE_PROJECT_FRAME* prjframe );
bool Delete( bool check = true );
void Move( TREEPROJECT_ITEM* dest );
void Activate( TREE_PROJECT_FRAME* prjframe );
const wxMenu* GetMenu() const wxMenu* GetMenu()
{ {
return &m_fileMenu; return &m_fileMenu;
} }
void SetState( int state );
void SetState( int state );
}; };
...@@ -45,7 +45,7 @@ IMPLEMENT_ABSTRACT_CLASS( TREEPROJECTFILES, wxTreeCtrl ) ...@@ -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 ) ...@@ -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 ) ...@@ -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 ) ...@@ -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 ) ...@@ -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 ) ...@@ -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 )
......
This diff is collapsed.
...@@ -5,8 +5,8 @@ ...@@ -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 @@ ...@@ -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; ...@@ -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<wxString> m_filters;
wxMenu* m_PopupMenu;
wxCursor m_DragCursor;
wxCursor m_Default;
std::vector<wxMenu*> m_ContextMenus; #if wxCHECK_VERSION( 2, 9, 2 )
std::vector<wxString> m_Filters; wxFileSystemWatcher* m_watcher; // file system watcher
#endif
wxMenu* m_PopupMenu; public:
wxCursor m_DragCursor; TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent );
wxCursor m_Default; ~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
...@@ -54,66 +75,96 @@ protected: ...@@ -54,66 +75,96 @@ protected:
* Note this is not necessary the "clicked" item, * Note this is not necessary the "clicked" item,
* 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
* @param aId = the wxTreeItemId identifier. * @param aId = the wxTreeItemId identifier.
* @return a TREEPROJECT_ITEM pointer correspondinfg to item id aId * @return a TREEPROJECT_ITEM pointer correspondinfg to item id aId
*/ */
TREEPROJECT_ITEM* GetItemIdData(wxTreeItemId aId); TREEPROJECT_ITEM* GetItemIdData( wxTreeItemId aId );
public: private:
KICAD_MANAGER_FRAME* m_Parent; void OnSelect( wxTreeEvent& Event );
TREEPROJECTFILES* m_TreeProject; void OnExpand( wxTreeEvent& Event );
void OnDragStart( wxTreeEvent& event );
wxTreeItemId m_root; void OnDragEnd( wxTreeEvent& event );
void OnRight( wxTreeEvent& Event );
public:
static wxString GetFileExt( TreeFileType type );
static wxString GetFileWildcard( TreeFileType type );
TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ); /**
~TREE_PROJECT_FRAME(); * Function OnOpenSelectedFileWithTextEditor
void OnSelect( wxTreeEvent& Event ); * Called via the popup menu, when right clicking on a file name
void OnExpand( wxTreeEvent& Event ); * Call the text editor to open the selected file
void OnRenameAsk( wxTreeEvent& Event ); * in the tree project
void OnRename( wxTreeEvent& Event ); */
void OnDragStart( wxTreeEvent& event ); void OnOpenSelectedFileWithTextEditor( wxCommandEvent& event );
void OnDragEnd( wxTreeEvent& event );
void OnRight( wxTreeEvent& Event );
void ReCreateTreePrj();
void OnTxtEdit( 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 ); /**
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 * Function OnCreateNewDirectory
* Creates a new subdirectory inside the current kicad project directory * Creates a new subdirectory inside the current kicad project directory
* the user is prompted to enter a directory name * 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(); const std::vector<wxString>& GetFilters()
void RemoveFilter( const wxString& filter ); {
return m_filters;
}
/** 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()
}; };
#endif // TREEPRJ_FRAME_H #endif // TREEPRJ_FRAME_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment