Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
c2389e8f
Commit
c2389e8f
authored
Feb 20, 2010
by
charras
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kicad enhancement (see changelog) and serious code cleaning
parent
9ed9a723
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
630 additions
and
618 deletions
+630
-618
CMakeLists.txt
kicad/CMakeLists.txt
+1
-0
class_treeproject_item.cpp
kicad/class_treeproject_item.cpp
+337
-0
class_treeproject_item.h
kicad/class_treeproject_item.h
+89
-0
class_treeprojectfiles.cpp
kicad/class_treeprojectfiles.cpp
+4
-371
kicad-python.cpp
kicad/kicad-python.cpp
+19
-19
kicad.h
kicad/kicad.h
+0
-85
tree_project_frame.cpp
kicad/tree_project_frame.cpp
+151
-133
tree_project_frame.h
kicad/tree_project_frame.h
+29
-10
No files found.
kicad/CMakeLists.txt
View file @
c2389e8f
...
@@ -6,6 +6,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
...
@@ -6,6 +6,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
set
(
KICAD_SRCS
set
(
KICAD_SRCS
class_treeprojectfiles.cpp
class_treeprojectfiles.cpp
class_treeproject_item.cpp
commandframe.cpp
commandframe.cpp
files-io.cpp
files-io.cpp
kicad.cpp
kicad.cpp
...
...
kicad/class_treeproject_item.cpp
0 → 100644
View file @
c2389e8f
/*
* file class_treeproject_item.cpp
*
* Class TREEPROJECT_ITEM is a derived class from wxTreeItemData that
* store info about a file or directory shown in the Kicad tree project files
*/
#ifdef KICAD_PYTHON
#include <pyhandler.h>
#endif
#include "fctsys.h"
#include "common.h"
#include "gestfich.h"
#include "kicad.h"
#include "tree_project_frame.h"
#include "class_treeprojectfiles.h"
#include "class_treeproject_item.h"
#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
)
:
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
;
}
#ifdef KICAD_PYTHON
using
namespace
boost
::
python
;
// Convert the data to an id
object
TREEPROJECT_ITEM
::
GetIdPy
()
const
{
wxTreeItemId
*
id
=
new
wxTreeItemId
();
*
id
=
GetId
();
return
object
(
handle
<>
(
borrowed
(
wxPyConstructObject
(
id
,
wxT
(
"wxTreeItemId"
),
true
)
)
)
);
}
#endif
// Set the state used in the icon list
void
TREEPROJECT_ITEM
::
SetState
(
int
state
)
{
wxImageList
*
imglist
=
m_Parent
->
GetImageList
();
if
(
!
imglist
||
state
<
0
||
state
>=
imglist
->
GetImageCount
()
/
(
TREE_MAX
-
2
)
)
return
;
m_State
=
state
;
int
imgid
=
m_Type
-
1
+
state
*
(
TREE_MAX
-
1
);
m_Parent
->
SetItemImage
(
GetId
(),
imgid
);
m_Parent
->
SetItemImage
(
GetId
(),
imgid
,
wxTreeItemIcon_Selected
);
}
/* Get the directory containing the file */
wxString
TREEPROJECT_ITEM
::
GetDir
()
const
{
if
(
TREE_DIRECTORY
==
m_Type
)
return
m_FileName
;
wxFileName
filename
=
wxFileName
(
m_FileName
);
filename
.
MakeRelativeTo
(
wxGetCwd
()
);
wxArrayString
dirs
=
filename
.
GetDirs
();
wxString
dir
;
for
(
unsigned
int
i
=
0
;
i
<
dirs
.
Count
();
i
++
)
{
dir
+=
dirs
[
i
]
+
filename
.
GetPathSeparator
();
}
return
dir
;
}
/* 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.
return
;
const
wxString
sep
=
wxFileName
().
GetPathSeparator
();
if
(
m_Type
==
TREE_DIRECTORY
)
return
;
if
(
!
dest
)
return
;
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
)
)
)
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
);
wxString
destName
;
if
(
!
dest
->
GetDir
().
IsEmpty
()
)
destName
=
dest
->
GetDir
()
+
sep
;
destName
+=
fname
.
GetFullName
();
if
(
destName
==
GetFileName
()
)
return
;
// Same place ??
// Move the file on the disk:
if
(
!
wxRenameFile
(
GetFileName
(),
destName
,
false
)
)
{
wxMessageDialog
(
m_Parent
,
_
(
"Unable to move file ... "
),
_
(
"Permission error ?"
),
wxICON_ERROR
|
wxOK
);
return
;
}
#ifdef KICAD_PYTHON
object
param
=
make_tuple
(
PyHandler
::
Convert
(
m_FileName
),
PyHandler
::
Convert
(
destName
)
);
PyHandler
::
GetInstance
()
->
TriggerEvent
(
wxT
(
"kicad::MoveFile"
),
param
);
#endif
SetFileName
(
destName
);
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
);
// 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
);
}
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
);
}
}
/* 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.
if
(
m_Type
==
TREE_DIRECTORY
)
return
false
;
if
(
name
.
IsEmpty
()
)
return
false
;
const
wxString
sep
=
wxFileName
().
GetPathSeparator
();
wxString
newFile
;
wxString
dirs
=
GetDir
();
if
(
!
dirs
.
IsEmpty
()
&&
GetType
()
!=
TREE_DIRECTORY
)
newFile
=
dirs
+
sep
+
name
;
else
newFile
=
name
;
if
(
newFile
==
m_FileName
)
return
false
;
wxString
ext
=
TREE_PROJECT_FRAME
::
GetFileExt
(
GetType
()
);
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 ?"
),
_
(
"Rename File"
),
wxYES_NO
|
wxICON_QUESTION
);
if
(
wxID_YES
!=
dialog
.
ShowModal
()
)
return
false
;
}
#if ( ( wxMAJOR_VERSION < 2 ) || ( ( wxMAJOR_VERSION == 2 ) \
&& ( wxMINOR_VERSION < 7 ) ) )
if
(
!
wxRenameFile
(
m_FileName
,
newFile
)
)
#else
if
(
!
wxRenameFile
(
m_FileName
,
newFile
,
false
)
)
#endif
{
wxMessageDialog
(
m_Parent
,
_
(
"Unable to rename file ... "
),
_
(
"Permission error ?"
),
wxICON_ERROR
|
wxOK
);
return
false
;
}
SetFileName
(
newFile
);
#ifdef KICAD_PYTHON
object
param
=
make_tuple
(
PyHandler
::
Convert
(
m_FileName
),
PyHandler
::
Convert
(
newFile
)
);
PyHandler
::
GetInstance
()
->
TriggerEvent
(
wxT
(
"kicad::RenameFile"
),
param
);
#endif
return
true
;
}
/*******************************************/
bool
TREEPROJECT_ITEM
::
Delete
(
bool
check
)
/*******************************************/
/* delete a file */
{
wxMessageDialog
dialog
(
m_Parent
,
_
(
"Do you really want to delete "
)
+
GetFileName
(),
_
(
"Delete File"
),
wxYES_NO
|
wxICON_QUESTION
);
if
(
!
check
||
wxID_YES
==
dialog
.
ShowModal
()
)
{
if
(
!
wxDirExists
(
m_FileName
)
)
{
wxRemoveFile
(
m_FileName
);
}
else
{
wxArrayString
filelist
;
wxDir
::
GetAllFiles
(
m_FileName
,
&
filelist
);
for
(
unsigned
int
i
=
0
;
i
<
filelist
.
Count
();
i
++
)
wxRemoveFile
(
filelist
[
i
]
);
wxRmdir
(
m_FileName
);
}
m_Parent
->
Delete
(
GetId
()
);
#ifdef KICAD_PYTHON
PyHandler
::
GetInstance
()
->
TriggerEvent
(
wxT
(
"kicad::DeleteFile"
),
PyHandler
::
Convert
(
m_FileName
)
);
#endif
return
true
;
}
return
false
;
}
/* Called under item activation */
void
TREEPROJECT_ITEM
::
Activate
(
TREE_PROJECT_FRAME
*
prjframe
)
{
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
);
break
;
case
TREE_SCHEMA
:
ExecuteFile
(
m_Parent
,
EESCHEMA_EXE
,
FullFileName
);
break
;
case
TREE_PCB
:
ExecuteFile
(
m_Parent
,
PCBNEW_EXE
,
FullFileName
);
break
;
#ifdef KICAD_PYTHON
case
TREE_PY
:
PyHandler
::
GetInstance
()
->
RunScript
(
FullFileName
);
break
;
#endif
case
TREE_GERBER
:
ExecuteFile
(
m_Parent
,
GERBVIEW_EXE
,
FullFileName
);
break
;
case
TREE_PDF
:
OpenPDF
(
FullFileName
);
break
;
case
TREE_NET
:
ExecuteFile
(
m_Parent
,
CVPCB_EXE
,
FullFileName
);
break
;
case
TREE_TXT
:
{
wxString
editorname
=
wxGetApp
().
GetEditorName
();
if
(
!
editorname
.
IsEmpty
()
)
ExecuteFile
(
m_Parent
,
editorname
,
FullFileName
);
break
;
}
default
:
OpenFile
(
FullFileName
);
break
;
}
}
kicad/class_treeproject_item.h
0 → 100644
View file @
c2389e8f
/*
* class_treeproject_item.h
*/
/** class TREEPROJECT_ITEM
* Handle one item (a file or a directory name) for the tree file
*/
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
private
:
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
(
const
TREEPROJECT_ITEM
&
src
)
:
m_Type
(
src
.
m_Type
),
m_FileName
(
src
.
m_FileName
),
m_Parent
(
src
.
m_Parent
)
{
SetState
(
src
.
m_State
);
m_WasPopulated
=
false
;
}
TreeFileType
GetType
()
const
{
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
;
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
);
const
wxMenu
*
GetMenu
()
{
return
&
m_fileMenu
;
}
void
SetState
(
int
state
);
#ifdef KICAD_PYTHON
boost
::
python
::
object
GetFileNamePy
()
const
;
bool
RenamePy
(
const
boost
::
python
::
str
&
newname
,
bool
check
=
true
);
boost
::
python
::
object
GetDirPy
()
const
;
boost
::
python
::
object
GetIdPy
()
const
;
boost
::
python
::
object
GetMenuPy
();
#endif
};
kicad/class_treeprojectfiles.cpp
View file @
c2389e8f
/*
/*
* file class_treeprojectfiles.cpp
* file class_treeprojectfiles.cpp
* this is the wxTreeCtrl that shows a Kicad tree project files
*/
*/
#ifdef KICAD_PYTHON
#ifdef KICAD_PYTHON
...
@@ -7,21 +8,15 @@
...
@@ -7,21 +8,15 @@
#endif
#endif
#include "fctsys.h"
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "common.h"
#include "gestfich.h"
#include "appl_wxstruct.h"
#include "bitmaps.h"
#include "bitmaps.h"
#include "kicad.h"
#include "kicad.h"
#include "tree_project_frame.h"
#include "tree_project_frame.h"
#include "class_treeprojectfiles.h"
#include "class_treeprojectfiles.h"
#include "class_treeproject_item.h"
#include "wx/image.h"
#include "wx/imaglist.h"
#include "wx/treectrl.h"
#include "wx/regex.h"
#include "wx/regex.h"
#include "wx/dir.h"
IMPLEMENT_ABSTRACT_CLASS
(
TREEPROJECTFILES
,
wxTreeCtrl
)
IMPLEMENT_ABSTRACT_CLASS
(
TREEPROJECTFILES
,
wxTreeCtrl
)
...
@@ -60,16 +55,10 @@ TREEPROJECTFILES::~TREEPROJECTFILES()
...
@@ -60,16 +55,10 @@ TREEPROJECTFILES::~TREEPROJECTFILES()
}
}
/* sort function for tree items.
* items are sorted :
* directory names first by alphabetic order
* root file names after
* file names last by alphabetic order
*/
int
TREEPROJECTFILES
::
OnCompareItems
(
const
wxTreeItemId
&
item1
,
const
wxTreeItemId
&
item2
)
int
TREEPROJECTFILES
::
OnCompareItems
(
const
wxTreeItemId
&
item1
,
const
wxTreeItemId
&
item2
)
{
{
T
reePrjItemData
*
myitem1
=
(
TreePrjItemData
*
)
GetItemData
(
item1
);
T
REEPROJECT_ITEM
*
myitem1
=
(
TREEPROJECT_ITEM
*
)
GetItemData
(
item1
);
T
reePrjItemData
*
myitem2
=
(
TreePrjItemData
*
)
GetItemData
(
item2
);
T
REEPROJECT_ITEM
*
myitem2
=
(
TREEPROJECT_ITEM
*
)
GetItemData
(
item2
);
if
(
(
myitem1
->
m_Type
==
TREE_DIRECTORY
)
&&
(
myitem2
->
m_Type
!=
TREE_DIRECTORY
)
)
if
(
(
myitem1
->
m_Type
==
TREE_DIRECTORY
)
&&
(
myitem2
->
m_Type
!=
TREE_DIRECTORY
)
)
return
-
1
;
return
-
1
;
...
@@ -84,359 +73,3 @@ int TREEPROJECTFILES::OnCompareItems( const wxTreeItemId& item1, const wxTreeIte
...
@@ -84,359 +73,3 @@ int TREEPROJECTFILES::OnCompareItems( const wxTreeItemId& item1, const wxTreeIte
return
myitem1
->
m_FileName
.
CmpNoCase
(
myitem2
->
m_FileName
);
return
myitem1
->
m_FileName
.
CmpNoCase
(
myitem2
->
m_FileName
);
}
}
TreePrjItemData
::
TreePrjItemData
(
enum
TreeFileType
type
,
const
wxString
&
data
,
wxTreeCtrl
*
parent
)
:
wxTreeItemData
()
{
m_Type
=
type
;
m_Parent
=
parent
;
m_FileName
=
data
;
m_IsRootFile
=
false
;
}
#ifdef KICAD_PYTHON
using
namespace
boost
::
python
;
// Convert the data to an id
object
TreePrjItemData
::
GetIdPy
()
const
{
wxTreeItemId
*
id
=
new
wxTreeItemId
();
*
id
=
GetId
();
return
object
(
handle
<>
(
borrowed
(
wxPyConstructObject
(
id
,
wxT
(
"wxTreeItemId"
),
true
)
)
)
);
}
#endif
// Set the state used in the icon list
void
TreePrjItemData
::
SetState
(
int
state
)
{
wxImageList
*
imglist
=
m_Parent
->
GetImageList
();
if
(
!
imglist
||
state
<
0
||
state
>=
imglist
->
GetImageCount
()
/
(
TREE_MAX
-
2
)
)
return
;
m_State
=
state
;
int
imgid
=
m_Type
-
1
+
state
*
(
TREE_MAX
-
1
);
m_Parent
->
SetItemImage
(
GetId
(),
imgid
);
m_Parent
->
SetItemImage
(
GetId
(),
imgid
,
wxTreeItemIcon_Selected
);
}
/* Get the directory containing the file */
wxString
TreePrjItemData
::
GetDir
()
const
{
if
(
TREE_DIRECTORY
==
m_Type
)
return
m_FileName
;
wxFileName
filename
=
wxFileName
(
m_FileName
);
filename
.
MakeRelativeTo
(
wxGetCwd
()
);
wxArrayString
dirs
=
filename
.
GetDirs
();
wxString
dir
;
for
(
unsigned
int
i
=
0
;
i
<
dirs
.
Count
();
i
++
)
{
dir
+=
dirs
[
i
]
+
filename
.
GetPathSeparator
();
}
return
dir
;
}
/* Called upon tree item rename */
void
TreePrjItemData
::
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
TreePrjItemData
::
Move
(
TreePrjItemData
*
dest
)
{
//function not safe.
return
;
const
wxString
sep
=
wxFileName
().
GetPathSeparator
();
if
(
m_Type
==
TREE_DIRECTORY
)
return
;
if
(
!
dest
)
return
;
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
<
TreePrjItemData
*>
(
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
);
wxString
destName
;
if
(
!
dest
->
GetDir
().
IsEmpty
()
)
destName
=
dest
->
GetDir
()
+
sep
;
destName
+=
fname
.
GetFullName
();
if
(
destName
==
GetFileName
()
)
return
;
// Same place ??
// Move the file on the disk:
#if ( ( wxMAJOR_VERSION < 2 ) || ( ( wxMAJOR_VERSION == 2 ) \
&& ( wxMINOR_VERSION < 7 ) ) )
if
(
!
wxRenameFile
(
GetFileName
(),
destName
)
)
#else
if
(
!
wxRenameFile
(
GetFileName
(),
destName
,
false
)
)
#endif
{
wxMessageDialog
(
m_Parent
,
_
(
"Unable to move file ... "
),
_
(
"Permission error ?"
),
wxICON_ERROR
|
wxOK
);
return
;
}
#ifdef KICAD_PYTHON
object
param
=
make_tuple
(
PyHandler
::
Convert
(
m_FileName
),
PyHandler
::
Convert
(
destName
)
);
PyHandler
::
GetInstance
()
->
TriggerEvent
(
wxT
(
"kicad::MoveFile"
),
param
);
#endif
SetFileName
(
destName
);
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
);
// 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
);
}
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
);
}
}
/* rename the file checking if extension change occurs */
bool
TreePrjItemData
::
Rename
(
const
wxString
&
name
,
bool
check
)
{
//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
();
if
(
!
dirs
.
IsEmpty
()
&&
GetType
()
!=
TREE_DIRECTORY
)
newFile
=
dirs
+
sep
+
name
;
else
newFile
=
name
;
if
(
newFile
==
m_FileName
)
return
false
;
wxString
ext
=
TREE_PROJECT_FRAME
::
GetFileExt
(
GetType
()
);
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 ?"
),
_
(
"Rename File"
),
wxYES_NO
|
wxICON_QUESTION
);
if
(
wxID_YES
!=
dialog
.
ShowModal
()
)
return
false
;
}
#if ( ( wxMAJOR_VERSION < 2 ) || ( ( wxMAJOR_VERSION == 2 ) \
&& ( wxMINOR_VERSION < 7 ) ) )
if
(
!
wxRenameFile
(
m_FileName
,
newFile
)
)
#else
if
(
!
wxRenameFile
(
m_FileName
,
newFile
,
false
)
)
#endif
{
wxMessageDialog
(
m_Parent
,
_
(
"Unable to rename file ... "
),
_
(
"Permission error ?"
),
wxICON_ERROR
|
wxOK
);
return
false
;
}
SetFileName
(
newFile
);
#ifdef KICAD_PYTHON
object
param
=
make_tuple
(
PyHandler
::
Convert
(
m_FileName
),
PyHandler
::
Convert
(
newFile
)
);
PyHandler
::
GetInstance
()
->
TriggerEvent
(
wxT
(
"kicad::RenameFile"
),
param
);
#endif
return
true
;
}
/*******************************************/
bool
TreePrjItemData
::
Delete
(
bool
check
)
/*******************************************/
/* delete a file */
{
wxMessageDialog
dialog
(
m_Parent
,
_
(
"Do you really want to delete "
)
+
GetFileName
(),
_
(
"Delete File"
),
wxYES_NO
|
wxICON_QUESTION
);
if
(
!
check
||
wxID_YES
==
dialog
.
ShowModal
()
)
{
if
(
!
wxDirExists
(
m_FileName
)
)
{
wxRemoveFile
(
m_FileName
);
}
else
{
wxArrayString
filelist
;
wxDir
::
GetAllFiles
(
m_FileName
,
&
filelist
);
for
(
unsigned
int
i
=
0
;
i
<
filelist
.
Count
();
i
++
)
wxRemoveFile
(
filelist
[
i
]
);
wxRmdir
(
m_FileName
);
}
m_Parent
->
Delete
(
GetId
()
);
#ifdef KICAD_PYTHON
PyHandler
::
GetInstance
()
->
TriggerEvent
(
wxT
(
"kicad::DeleteFile"
),
PyHandler
::
Convert
(
m_FileName
)
);
#endif
return
true
;
}
return
false
;
}
/* Called under item activation */
void
TreePrjItemData
::
Activate
(
TREE_PROJECT_FRAME
*
prjframe
)
{
wxString
sep
=
wxFileName
().
GetPathSeparator
();
wxString
FullFileName
=
GetFileName
();
wxDir
*
dir
;
wxString
dir_filename
;
wxTreeItemId
id
=
GetId
();
int
count
;
switch
(
GetType
()
)
{
case
TREE_PROJECT
:
break
;
case
TREE_DIRECTORY
:
if
(
prjframe
)
{
dir
=
new
wxDir
(
FullFileName
);
count
=
0
;
if
(
dir
&&
dir
->
IsOpened
()
&&
dir
->
GetFirst
(
&
dir_filename
)
)
{
do
{
wxString
fil
=
FullFileName
+
sep
+
dir_filename
;
if
(
prjframe
->
AddFile
(
fil
,
id
)
)
{
count
++
;
}
}
while
(
dir
->
GetNext
(
&
dir_filename
)
);
}
if
(
count
==
0
)
{
/* The AddFile() text below should match the filter added to
* handle it in treeprj_frame.cpp in the line looking like this:
* m_Filters.push_back( wxT( "^no kicad files found" ) );
*/
prjframe
->
AddFile
(
_
(
"no kicad files found in this directory"
),
id
);
}
/* Sort filenames by alphabetic order */
m_Parent
->
SortChildren
(
id
);
delete
dir
;
}
m_Parent
->
Toggle
(
id
);
break
;
case
TREE_SCHEMA
:
AddDelimiterString
(
FullFileName
);
ExecuteFile
(
m_Parent
,
EESCHEMA_EXE
,
FullFileName
);
break
;
case
TREE_PCB
:
AddDelimiterString
(
FullFileName
);
ExecuteFile
(
m_Parent
,
PCBNEW_EXE
,
FullFileName
);
break
;
#ifdef KICAD_PYTHON
case
TREE_PY
:
PyHandler
::
GetInstance
()
->
RunScript
(
FullFileName
);
break
;
#endif
case
TREE_GERBER
:
AddDelimiterString
(
FullFileName
);
ExecuteFile
(
m_Parent
,
GERBVIEW_EXE
,
FullFileName
);
break
;
case
TREE_PDF
:
OpenPDF
(
FullFileName
);
break
;
case
TREE_NET
:
AddDelimiterString
(
FullFileName
);
ExecuteFile
(
m_Parent
,
CVPCB_EXE
,
FullFileName
);
break
;
case
TREE_TXT
:
{
wxString
editorname
=
wxGetApp
().
GetEditorName
();
if
(
!
editorname
.
IsEmpty
()
)
ExecuteFile
(
m_Parent
,
editorname
,
FullFileName
);
break
;
}
default
:
OpenFile
(
FullFileName
);
break
;
}
}
TreePrjItemData
*
TREE_PROJECT_FRAME
::
GetSelectedData
()
{
return
dynamic_cast
<
TreePrjItemData
*>
(
m_TreeProject
->
GetItemData
(
m_TreeProject
->
GetSelection
()
)
);
}
kicad/kicad-python.cpp
View file @
c2389e8f
...
@@ -178,10 +178,10 @@ void TREE_PROJECT_FRAME::AddFilePy( const str& file, object& root )
...
@@ -178,10 +178,10 @@ void TREE_PROJECT_FRAME::AddFilePy( const str& file, object& root )
/**
/**
* @brief convert wxTreeItem into T
reePrjItemData
* @brief convert wxTreeItem into T
REEPROJECT_ITEM
*/
*/
/*****************************************************************************/
/*****************************************************************************/
T
reePrjItemData
*
TREE_PROJECT_FRAME
::
GetItemData
(
const
object
&
item
)
T
REEPROJECT_ITEM
*
TREE_PROJECT_FRAME
::
GetItemData
(
const
object
&
item
)
/*****************************************************************************/
/*****************************************************************************/
{
{
wxTreeItemId
*
id
=
NULL
;
wxTreeItemId
*
id
=
NULL
;
...
@@ -191,36 +191,36 @@ TreePrjItemData* TREE_PROJECT_FRAME::GetItemData( const object& item )
...
@@ -191,36 +191,36 @@ TreePrjItemData* TREE_PROJECT_FRAME::GetItemData( const object& item )
return
NULL
;
return
NULL
;
}
}
return
dynamic_cast
<
T
reePrjItemData
*>
(
m_TreeProject
->
GetItemData
(
*
id
)
);
return
dynamic_cast
<
T
REEPROJECT_ITEM
*>
(
m_TreeProject
->
GetItemData
(
*
id
)
);
}
}
/*****************************************************************************/
/*****************************************************************************/
// T
reePrjItemData
Special binding functions
// T
REEPROJECT_ITEM
Special binding functions
// (one line functions are simple wrappers)
// (one line functions are simple wrappers)
/*****************************************************************************/
/*****************************************************************************/
// Python rename
// Python rename
bool
T
reePrjItemData
::
RenamePy
(
const
str
&
newname
,
bool
check
)
bool
T
REEPROJECT_ITEM
::
RenamePy
(
const
str
&
newname
,
bool
check
)
{
{
return
Rename
(
PyHandler
::
MakeStr
(
newname
),
check
);
return
Rename
(
PyHandler
::
MakeStr
(
newname
),
check
);
}
}
// Get python directory
// Get python directory
object
T
reePrjItemData
::
GetDirPy
()
const
object
T
REEPROJECT_ITEM
::
GetDirPy
()
const
{
{
return
PyHandler
::
Convert
(
GetDir
()
);
return
PyHandler
::
Convert
(
GetDir
()
);
}
}
// Get python filename
// Get python filename
object
T
reePrjItemData
::
GetFileNamePy
()
const
object
T
REEPROJECT_ITEM
::
GetFileNamePy
()
const
{
{
return
PyHandler
::
Convert
(
GetFileName
()
);
return
PyHandler
::
Convert
(
GetFileName
()
);
}
}
// Get python menu
// Get python menu
object
T
reePrjItemData
::
GetMenuPy
()
object
T
REEPROJECT_ITEM
::
GetMenuPy
()
{
{
return
object
(
handle
<>
(
borrowed
(
wxPyMake_wxObject
(
&
m_fileMenu
,
false
)
)
)
);
return
object
(
handle
<>
(
borrowed
(
wxPyMake_wxObject
(
&
m_fileMenu
,
false
)
)
)
);
}
}
...
@@ -238,21 +238,21 @@ static void py_kicad_init()
...
@@ -238,21 +238,21 @@ static void py_kicad_init()
return_value_policy
<
reference_existing_object
>
()
);
return_value_policy
<
reference_existing_object
>
()
);
def
(
"GetTypeExtension"
,
&
GetTypeExt
);
def
(
"GetTypeExtension"
,
&
GetTypeExt
);
class_
<
T
reePrjItemData
>
(
"PrjItem"
)
class_
<
T
REEPROJECT_ITEM
>
(
"PrjItem"
)
// Internal data:
// Internal data:
.
def
(
"GetFileName"
,
&
T
reePrjItemData
::
GetFileNamePy
)
.
def
(
"GetFileName"
,
&
T
REEPROJECT_ITEM
::
GetFileNamePy
)
.
def
(
"GetDir"
,
&
T
reePrjItemData
::
GetDirPy
)
.
def
(
"GetDir"
,
&
T
REEPROJECT_ITEM
::
GetDirPy
)
.
def
(
"GetType"
,
&
T
reePrjItemData
::
GetType
)
.
def
(
"GetType"
,
&
T
REEPROJECT_ITEM
::
GetType
)
.
def
(
"GetId"
,
&
T
reePrjItemData
::
GetIdPy
)
.
def
(
"GetId"
,
&
T
REEPROJECT_ITEM
::
GetIdPy
)
.
def
(
"GetMenu"
,
&
T
reePrjItemData
::
GetMenuPy
)
.
def
(
"GetMenu"
,
&
T
REEPROJECT_ITEM
::
GetMenuPy
)
// Item control
// Item control
.
def
(
"SetState"
,
&
T
reePrjItemData
::
SetState
)
.
def
(
"SetState"
,
&
T
REEPROJECT_ITEM
::
SetState
)
.
def
(
"Rename"
,
&
T
reePrjItemData
::
RenamePy
)
.
def
(
"Rename"
,
&
T
REEPROJECT_ITEM
::
RenamePy
)
.
def
(
"Move"
,
&
T
reePrjItemData
::
Move
)
.
def
(
"Move"
,
&
T
REEPROJECT_ITEM
::
Move
)
.
def
(
"Delete"
,
&
T
reePrjItemData
::
Delete
)
.
def
(
"Delete"
,
&
T
REEPROJECT_ITEM
::
Delete
)
.
def
(
"Activate"
,
&
T
reePrjItemData
::
Activate
)
.
def
(
"Activate"
,
&
T
REEPROJECT_ITEM
::
Activate
)
;
;
enum_
<
TreeFileType
>
(
"FileType"
)
enum_
<
TreeFileType
>
(
"FileType"
)
...
...
kicad/kicad.h
View file @
c2389e8f
...
@@ -38,9 +38,7 @@ enum id_kicad_frm {
...
@@ -38,9 +38,7 @@ enum id_kicad_frm {
ID_PROJECT_TXTEDIT
,
ID_PROJECT_TXTEDIT
,
ID_PROJECT_TREE_REFRESH
,
ID_PROJECT_TREE_REFRESH
,
ID_PROJECT_RUNPY
,
ID_PROJECT_RUNPY
,
ID_PROJECT_NEWFILE
,
ID_PROJECT_NEWPY
,
ID_PROJECT_NEWPY
,
ID_PROJECT_NEWTXT
,
ID_PROJECT_NEWDIR
,
ID_PROJECT_NEWDIR
,
ID_PROJECT_DELETE
,
ID_PROJECT_DELETE
,
ID_PROJECT_RENAME
,
ID_PROJECT_RENAME
,
...
@@ -188,87 +186,4 @@ private:
...
@@ -188,87 +186,4 @@ private:
DECLARE_EVENT_TABLE
()
DECLARE_EVENT_TABLE
()
};
};
/*********************************/
/* Classes for the project tree. */
/*********************************/
/** class TreePrjItemData
* Handle one item (a file or a directory name) for the tree file
*/
class
TreePrjItemData
:
public
wxTreeItemData
{
public
:
TreeFileType
m_Type
;
bool
m_IsRootFile
;
// True if m_Filename is a root schematic (same name as project)
wxString
m_FileName
;
// Filename for a file, or directory name
private
:
wxTreeCtrl
*
m_Parent
;
wxMenu
m_fileMenu
;
int
m_State
;
public
:
TreePrjItemData
(
TreeFileType
type
,
const
wxString
&
data
,
wxTreeCtrl
*
parent
);
TreePrjItemData
()
:
m_Parent
(
NULL
)
{
}
TreePrjItemData
(
const
TreePrjItemData
&
src
)
:
m_Type
(
src
.
m_Type
),
m_FileName
(
src
.
m_FileName
),
m_Parent
(
src
.
m_Parent
)
{
SetState
(
src
.
m_State
);
}
TreeFileType
GetType
()
const
{
return
m_Type
;
}
wxString
GetFileName
()
const
{
return
m_FileName
;
}
void
SetFileName
(
const
wxString
&
name
)
{
m_FileName
=
name
;
}
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
(
TreePrjItemData
*
dest
);
void
Activate
(
TREE_PROJECT_FRAME
*
prjframe
);
const
wxMenu
*
GetMenu
()
{
return
&
m_fileMenu
;
}
void
SetState
(
int
state
);
#ifdef KICAD_PYTHON
boost
::
python
::
object
GetFileNamePy
()
const
;
bool
RenamePy
(
const
boost
::
python
::
str
&
newname
,
bool
check
=
true
);
boost
::
python
::
object
GetDirPy
()
const
;
boost
::
python
::
object
GetIdPy
()
const
;
boost
::
python
::
object
GetMenuPy
();
#endif
};
#endif
#endif
kicad/tree_project_frame.cpp
View file @
c2389e8f
...
@@ -10,38 +10,32 @@
...
@@ -10,38 +10,32 @@
#include <wx/wupdlock.h>
#include <wx/wupdlock.h>
#include "fctsys.h"
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "common.h"
#include "confirm.h"
#include "confirm.h"
#include "gestfich.h"
#include "gestfich.h"
#include "appl_wxstruct.h"
#include "appl_wxstruct.h"
#include "bitmaps.h"
#include "bitmaps.h"
#include "macros.h"
#include "kicad.h"
#include "kicad.h"
#include "tree_project_frame.h"
#include "tree_project_frame.h"
#include "class_treeprojectfiles.h"
#include "class_treeprojectfiles.h"
#include "class_treeproject_item.h"
#include "wx/image.h"
#include "wx/imaglist.h"
#include "wx/treectrl.h"
#include "wx/regex.h"
#include "wx/regex.h"
#include "wx/dir.h"
#include "wx/dir.h"
/* Comment this if you do no want to load subdirs files in the tree project
/* Note about the tree project build process:
* UnComment this to load subdirs files in the tree project
* Building the tree project can be *very* long if there are a lot of subdirectories
* Building the tree project can be *very* long if there are a lot of subdirectories
* in the working directory.
* in the working directory.
* Unfornately, this happens easily if the project file *.pro is in the home directory
* Unfornately, this happens easily if the project file *.pro is in the home directory
* when subdirs are not built, double click on a directory to load its files and subdirs
* So the tree project is built "on demand":
* First the tree is built from the current directory and shows files and subdirs.
* > First level subdirs trees are built (i.e subdirs contents are not read)
* > When expanding a subdir, each subdir contains is read,
* and the corresponding sub tree is populated on the fly.
*/
*/
// #define ADD_FILES_IN_SUBDIRS
// TODO: a better way could be to load current dir and first subdirs, and load
// load subdir filenames on opening a subdir
// list of files extensions listed in the tree project window
// list of files extensions listed in the tree project window
// *.sch files are always allowed, do not add here
// *.sch files are always allowed, do not add here
// Add extensions in a compatible regex format to see others files types
// Add extensions in a compatible regex format to see others files types
...
@@ -81,8 +75,34 @@ const wxString TextFileWildcard( wxT( "Text files (*.txt)|*.txt" ) );
...
@@ -81,8 +75,34 @@ const wxString TextFileWildcard( wxT( "Text files (*.txt)|*.txt" ) );
/**
/**
* @brief TODO
* @brief class TREE_PROJECT_FRAME is the frame that shows the tree list
* of files and subdirs inside the working directory
* Files are filtered (see s_AllowedExtensionsToList) so
* only useful files are shown.
*/
*/
/*****************************************************************************/
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_EXPANDED
(
ID_PROJECT_TREE
,
TREE_PROJECT_FRAME
::
OnExpand
)
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_END_DRAG
(
ID_PROJECT_TREE
,
TREE_PROJECT_FRAME
::
OnDragEnd
)
EVT_MENU
(
ID_PROJECT_TXTEDIT
,
TREE_PROJECT_FRAME
::
OnTxtEdit
)
EVT_MENU
(
ID_PROJECT_NEWDIR
,
TREE_PROJECT_FRAME
::
OnNewDirectory
)
EVT_MENU
(
ID_PROJECT_NEWPY
,
TREE_PROJECT_FRAME
::
OnNewPyFile
)
EVT_MENU
(
ID_PROJECT_DELETE
,
TREE_PROJECT_FRAME
::
OnDeleteFile
)
EVT_MENU
(
ID_PROJECT_RENAME
,
TREE_PROJECT_FRAME
::
OnRenameFile
)
#ifdef KICAD_PYTHON
EVT_MENU
(
ID_PROJECT_RUNPY
,
TREE_PROJECT_FRAME
::
OnRunPy
)
#endif
/* KICAD_PYTHON */
END_EVENT_TABLE
()
/*****************************************************************************/
/******************************************************************/
/******************************************************************/
TREE_PROJECT_FRAME
::
TREE_PROJECT_FRAME
(
WinEDA_MainFrame
*
parent
)
:
TREE_PROJECT_FRAME
::
TREE_PROJECT_FRAME
(
WinEDA_MainFrame
*
parent
)
:
wxSashLayoutWindow
(
parent
,
wxSashLayoutWindow
(
parent
,
...
@@ -119,7 +139,6 @@ TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( WinEDA_MainFrame* parent ) :
...
@@ -119,7 +139,6 @@ TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( WinEDA_MainFrame* parent ) :
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::EditScript"
)
);
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::EditScript"
)
);
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::TreeContextMenu"
)
);
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::TreeContextMenu"
)
);
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::TreeAddFile"
)
);
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::TreeAddFile"
)
);
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::NewFile"
)
);
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::NewDirectory"
)
);
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::NewDirectory"
)
);
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::DeleteFile"
)
);
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::DeleteFile"
)
);
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::RenameFile"
)
);
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::RenameFile"
)
);
...
@@ -178,24 +197,6 @@ TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( WinEDA_MainFrame* parent ) :
...
@@ -178,24 +197,6 @@ TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( WinEDA_MainFrame* parent ) :
item
->
SetBitmap
(
new_python_xpm
);
item
->
SetBitmap
(
new_python_xpm
);
menu
->
Append
(
item
);
menu
->
Append
(
item
);
#endif
/* KICAD_PYTHON */
#endif
/* KICAD_PYTHON */
// ID_PROJECT_NEWTXT
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_NEWTXT
,
_
(
"New &Text File"
),
_
(
"Create a New Txt File"
)
);
item
->
SetBitmap
(
new_txt_xpm
);
menu
->
Append
(
item
);
// ID_PROJECT_NEWFILE
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_NEWFILE
,
_
(
"New &File"
),
_
(
"Create a New File"
)
);
item
->
SetBitmap
(
new_xpm
);
menu
->
Append
(
item
);
}
}
...
@@ -256,35 +257,6 @@ TREE_PROJECT_FRAME::~TREE_PROJECT_FRAME()
...
@@ -256,35 +257,6 @@ TREE_PROJECT_FRAME::~TREE_PROJECT_FRAME()
}
}
/*****************************************************************************/
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_RIGHT_CLICK
(
ID_PROJECT_TREE
,
TREE_PROJECT_FRAME
::
OnRight
)
EVT_TREE_BEGIN_DRAG
(
ID_PROJECT_TREE
,
TREE_PROJECT_FRAME
::
OnDragStart
)
EVT_TREE_END_DRAG
(
ID_PROJECT_TREE
,
TREE_PROJECT_FRAME
::
OnDragEnd
)
EVT_MENU
(
ID_PROJECT_TXTEDIT
,
TREE_PROJECT_FRAME
::
OnTxtEdit
)
EVT_MENU
(
ID_PROJECT_NEWFILE
,
TREE_PROJECT_FRAME
::
OnNewFile
)
EVT_MENU
(
ID_PROJECT_NEWDIR
,
TREE_PROJECT_FRAME
::
OnNewDirectory
)
EVT_MENU
(
ID_PROJECT_NEWPY
,
TREE_PROJECT_FRAME
::
OnNewPyFile
)
EVT_MENU
(
ID_PROJECT_NEWTXT
,
TREE_PROJECT_FRAME
::
OnNewTxtFile
)
EVT_MENU
(
ID_PROJECT_DELETE
,
TREE_PROJECT_FRAME
::
OnDeleteFile
)
EVT_MENU
(
ID_PROJECT_RENAME
,
TREE_PROJECT_FRAME
::
OnRenameFile
)
#ifdef KICAD_PYTHON
EVT_MENU
(
ID_PROJECT_RUNPY
,
TREE_PROJECT_FRAME
::
OnRunPy
)
#endif
/* KICAD_PYTHON */
/*****************************************************************************/
END_EVENT_TABLE
()
/*****************************************************************************/
/**
/**
* @brief Allowing drag & drop of file other than the currently opened project
* @brief Allowing drag & drop of file other than the currently opened project
*/
*/
...
@@ -297,7 +269,7 @@ void TREE_PROJECT_FRAME::OnDragStart( wxTreeEvent& event )
...
@@ -297,7 +269,7 @@ void TREE_PROJECT_FRAME::OnDragStart( wxTreeEvent& event )
wxTreeItemId
curr_item
=
event
.
GetItem
();
wxTreeItemId
curr_item
=
event
.
GetItem
();
m_TreeProject
->
SelectItem
(
curr_item
);
m_TreeProject
->
SelectItem
(
curr_item
);
T
reePrjItemData
*
data
=
GetSelectedData
();
T
REEPROJECT_ITEM
*
data
=
GetSelectedData
();
if
(
data
->
GetFileName
()
==
m_Parent
->
m_ProjectFileName
.
GetFullPath
()
)
if
(
data
->
GetFileName
()
==
m_Parent
->
m_ProjectFileName
.
GetFullPath
()
)
return
;
return
;
...
@@ -318,14 +290,14 @@ void TREE_PROJECT_FRAME::OnDragEnd( wxTreeEvent& event )
...
@@ -318,14 +290,14 @@ void TREE_PROJECT_FRAME::OnDragEnd( wxTreeEvent& event )
m_Parent
->
SetCursor
(
wxNullCursor
);
m_Parent
->
SetCursor
(
wxNullCursor
);
wxTreeItemId
moved
=
m_TreeProject
->
GetSelection
();
wxTreeItemId
moved
=
m_TreeProject
->
GetSelection
();
T
reePrjItemData
*
source_data
=
GetSelectedData
();
T
REEPROJECT_ITEM
*
source_data
=
GetSelectedData
();
wxTreeItemId
dest
=
event
.
GetItem
();
wxTreeItemId
dest
=
event
.
GetItem
();
if
(
!
dest
.
IsOk
()
)
if
(
!
dest
.
IsOk
()
)
return
;
// Cancelled ...
return
;
// Cancelled ...
T
reePrjItemData
*
destData
=
T
REEPROJECT_ITEM
*
destData
=
dynamic_cast
<
T
reePrjItemData
*>
(
m_TreeProject
->
GetItemData
(
dest
)
);
dynamic_cast
<
T
REEPROJECT_ITEM
*>
(
m_TreeProject
->
GetItemData
(
dest
)
);
if
(
!
destData
)
if
(
!
destData
)
return
;
return
;
...
@@ -341,7 +313,7 @@ void TREE_PROJECT_FRAME::OnDragEnd( wxTreeEvent& event )
...
@@ -341,7 +313,7 @@ void TREE_PROJECT_FRAME::OnDragEnd( wxTreeEvent& event )
// Select the right destData:
// Select the right destData:
destData
=
destData
=
dynamic_cast
<
T
reePrjItemData
*>
(
m_TreeProject
->
GetItemData
(
dest
)
);
dynamic_cast
<
T
REEPROJECT_ITEM
*>
(
m_TreeProject
->
GetItemData
(
dest
)
);
if
(
!
destData
)
if
(
!
destData
)
return
;
return
;
...
@@ -386,7 +358,7 @@ void TREE_PROJECT_FRAME::RemoveFilter( const wxString& filter )
...
@@ -386,7 +358,7 @@ void TREE_PROJECT_FRAME::RemoveFilter( const wxString& filter )
* @brief Return the data corresponding to the file, or NULL
* @brief Return the data corresponding to the file, or NULL
*/
*/
/*****************************************************************************/
/*****************************************************************************/
T
reePrjItemData
*
TREE_PROJECT_FRAME
::
FindItemData
(
const
boost
::
python
::
str
&
name
)
T
REEPROJECT_ITEM
*
TREE_PROJECT_FRAME
::
FindItemData
(
const
boost
::
python
::
str
&
name
)
/*****************************************************************************/
/*****************************************************************************/
{
{
// (Interative tree parsing)
// (Interative tree parsing)
...
@@ -400,7 +372,7 @@ TreePrjItemData* TREE_PROJECT_FRAME::FindItemData( const boost::python::str& nam
...
@@ -400,7 +372,7 @@ TreePrjItemData* TREE_PROJECT_FRAME::FindItemData( const boost::python::str& nam
root
->
push_back
(
m_TreeProject
->
GetRootItem
()
);
root
->
push_back
(
m_TreeProject
->
GetRootItem
()
);
// if we look for the root, return it ...
// if we look for the root, return it ...
T
reePrjItemData
*
data
=
dynamic_cast
<
TreePrjItemData
*>
(
T
REEPROJECT_ITEM
*
data
=
dynamic_cast
<
TREEPROJECT_ITEM
*>
(
m_TreeProject
->
GetItemData
(
root
->
at
(
0
)
)
);
m_TreeProject
->
GetItemData
(
root
->
at
(
0
)
)
);
if
(
data
->
GetFileName
()
==
filename
)
if
(
data
->
GetFileName
()
==
filename
)
...
@@ -420,7 +392,7 @@ TreePrjItemData* TREE_PROJECT_FRAME::FindItemData( const boost::python::str& nam
...
@@ -420,7 +392,7 @@ TreePrjItemData* TREE_PROJECT_FRAME::FindItemData( const boost::python::str& nam
while
(
child
.
IsOk
()
)
while
(
child
.
IsOk
()
)
{
{
T
reePrjItemData
*
data
=
dynamic_cast
<
TreePrjItemData
*>
(
T
REEPROJECT_ITEM
*
data
=
dynamic_cast
<
TREEPROJECT_ITEM
*>
(
m_TreeProject
->
GetItemData
(
child
)
);
m_TreeProject
->
GetItemData
(
child
)
);
if
(
data
)
if
(
data
)
...
@@ -509,17 +481,6 @@ void TREE_PROJECT_FRAME::OnNewDirectory( wxCommandEvent& event )
...
@@ -509,17 +481,6 @@ void TREE_PROJECT_FRAME::OnNewDirectory( wxCommandEvent& event )
}
}
/**
* @brief TODO
*/
/*****************************************************************************/
void
TREE_PROJECT_FRAME
::
OnNewFile
(
wxCommandEvent
&
event
)
/*****************************************************************************/
{
NewFile
(
TREE_UNKNOWN
);
}
/**
/**
* @brief TODO
* @brief TODO
*/
*/
...
@@ -531,17 +492,6 @@ void TREE_PROJECT_FRAME::OnNewPyFile( wxCommandEvent& event )
...
@@ -531,17 +492,6 @@ void TREE_PROJECT_FRAME::OnNewPyFile( wxCommandEvent& event )
}
}
/**
* @brief TODO
*/
/*****************************************************************************/
void
TREE_PROJECT_FRAME
::
OnNewTxtFile
(
wxCommandEvent
&
event
)
/*****************************************************************************/
{
NewFile
(
TREE_TXT
);
}
/**
/**
* @brief TODO
* @brief TODO
*/
*/
...
@@ -556,7 +506,7 @@ void TREE_PROJECT_FRAME::NewFile( TreeFileType type )
...
@@ -556,7 +506,7 @@ void TREE_PROJECT_FRAME::NewFile( TreeFileType type )
wxString
dir
;
wxString
dir
;
wxString
title
;
wxString
title
;
T
reePrjItemData
*
treeData
;
T
REEPROJECT_ITEM
*
treeData
;
title
=
(
TREE_DIRECTORY
!=
type
)
?
_
(
"Create New File"
)
:
title
=
(
TREE_DIRECTORY
!=
type
)
?
_
(
"Create New File"
)
:
_
(
"Create New Directory"
);
_
(
"Create New Directory"
);
...
@@ -722,14 +672,17 @@ wxString TREE_PROJECT_FRAME::GetFileWildcard( TreeFileType type )
...
@@ -722,14 +672,17 @@ wxString TREE_PROJECT_FRAME::GetFileWildcard( TreeFileType type )
}
}
/**
/**
function AddFile
* @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
* @return TODO
* @param aName = the filename or the dirctory name to add
* @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
* false to stop file add.
* @return true if the file (or directory) is added.
*/
*/
/*****************************************************************************/
bool
TREE_PROJECT_FRAME
::
AddFile
(
const
wxString
&
aName
,
bool
TREE_PROJECT_FRAME
::
AddFile
(
const
wxString
&
name
,
wxTreeItemId
&
root
)
wxTreeItemId
&
aRoot
,
bool
aRecurse
)
/*****************************************************************************/
{
{
wxTreeItemId
cellule
;
wxTreeItemId
cellule
;
...
@@ -737,13 +690,13 @@ bool TREE_PROJECT_FRAME::AddFile( const wxString& name, wxTreeItemId& root )
...
@@ -737,13 +690,13 @@ bool TREE_PROJECT_FRAME::AddFile( const wxString& name, wxTreeItemId& root )
TreeFileType
type
=
TREE_UNKNOWN
;
TreeFileType
type
=
TREE_UNKNOWN
;
// Skip not visible files and dirs
// Skip not visible files and dirs
wxFileName
fn
(
n
ame
);
wxFileName
fn
(
aN
ame
);
// 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
(
"."
)
)
)
return
false
;
return
false
;
if
(
wxDirExists
(
n
ame
)
)
if
(
wxDirExists
(
aN
ame
)
)
{
{
type
=
TREE_DIRECTORY
;
type
=
TREE_DIRECTORY
;
}
}
...
@@ -757,7 +710,7 @@ bool TREE_PROJECT_FRAME::AddFile( const wxString& name, wxTreeItemId& root )
...
@@ -757,7 +710,7 @@ bool TREE_PROJECT_FRAME::AddFile( const wxString& name, wxTreeItemId& root )
for
(
unsigned
i
=
0
;
i
<
m_Filters
.
size
();
i
++
)
for
(
unsigned
i
=
0
;
i
<
m_Filters
.
size
();
i
++
)
{
{
reg
.
Compile
(
m_Filters
[
i
],
wxRE_ICASE
);
reg
.
Compile
(
m_Filters
[
i
],
wxRE_ICASE
);
if
(
reg
.
Matches
(
n
ame
)
)
if
(
reg
.
Matches
(
aN
ame
)
)
{
{
addFile
=
true
;
addFile
=
true
;
if
(
i
==
0
)
if
(
i
==
0
)
...
@@ -779,7 +732,7 @@ bool TREE_PROJECT_FRAME::AddFile( const wxString& name, wxTreeItemId& root )
...
@@ -779,7 +732,7 @@ bool TREE_PROJECT_FRAME::AddFile( const wxString& name, wxTreeItemId& root )
char
line
[
128
];
// small because we just need a few bytes from the start of a line
char
line
[
128
];
// small because we just need a few bytes from the start of a line
FILE
*
fp
;
FILE
*
fp
;
wxString
FullFileName
=
n
ame
;
wxString
FullFileName
=
aN
ame
;
fp
=
wxFopen
(
FullFileName
,
wxT
(
"rt"
)
);
fp
=
wxFopen
(
FullFileName
,
wxT
(
"rt"
)
);
if
(
fp
==
NULL
)
if
(
fp
==
NULL
)
...
@@ -818,7 +771,7 @@ bool TREE_PROJECT_FRAME::AddFile( const wxString& name, wxTreeItemId& root )
...
@@ -818,7 +771,7 @@ bool TREE_PROJECT_FRAME::AddFile( const wxString& name, wxTreeItemId& root )
reg
.
Compile
(
wxString
::
FromAscii
(
"^.*
\\
"
)
+
ext
+
reg
.
Compile
(
wxString
::
FromAscii
(
"^.*
\\
"
)
+
ext
+
wxString
::
FromAscii
(
"$"
),
wxRE_ICASE
);
wxString
::
FromAscii
(
"$"
),
wxRE_ICASE
);
if
(
reg
.
Matches
(
n
ame
)
)
if
(
reg
.
Matches
(
aN
ame
)
)
{
{
type
=
(
TreeFileType
)
i
;
type
=
(
TreeFileType
)
i
;
break
;
break
;
...
@@ -828,30 +781,28 @@ bool TREE_PROJECT_FRAME::AddFile( const wxString& name, wxTreeItemId& root )
...
@@ -828,30 +781,28 @@ bool TREE_PROJECT_FRAME::AddFile( const wxString& name, wxTreeItemId& root )
//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
(
r
oot
,
cookie
);
wxTreeItemId
kid
=
m_TreeProject
->
GetFirstChild
(
aR
oot
,
cookie
);
while
(
kid
.
IsOk
()
)
while
(
kid
.
IsOk
()
)
{
{
TreePrjItemData
*
itemData
=
(
TreePrjItemData
*
)
TREEPROJECT_ITEM
*
itemData
=
GetItemIdData
(
kid
);
m_TreeProject
->
GetItemData
(
kid
);
if
(
itemData
)
if
(
itemData
)
{
{
if
(
itemData
->
m_FileName
==
n
ame
)
if
(
itemData
->
m_FileName
==
aN
ame
)
{
{
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
(
r
oot
,
cookie
);
kid
=
m_TreeProject
->
GetNextChild
(
aR
oot
,
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
(
n
ame
);
wxString
file
=
wxFileNameFromPath
(
aN
ame
);
cellule
=
m_TreeProject
->
AppendItem
(
r
oot
,
file
);
cellule
=
m_TreeProject
->
AppendItem
(
aR
oot
,
file
);
T
reePrjItemData
*
data
=
new
TreePrjItemData
(
type
,
n
ame
,
m_TreeProject
);
T
REEPROJECT_ITEM
*
data
=
new
TREEPROJECT_ITEM
(
type
,
aN
ame
,
m_TreeProject
);
m_TreeProject
->
SetItemData
(
cellule
,
data
);
m_TreeProject
->
SetItemData
(
cellule
,
data
);
data
->
SetState
(
0
);
data
->
SetState
(
0
);
/* Mark root files (files which have the same
n
ame as the project) */
/* Mark root files (files which have the same
aN
ame as the project) */
wxFileName
project
(
m_Parent
->
m_ProjectFileName
);
wxFileName
project
(
m_Parent
->
m_ProjectFileName
);
wxFileName
currfile
(
file
);
wxFileName
currfile
(
file
);
...
@@ -863,32 +814,29 @@ bool TREE_PROJECT_FRAME::AddFile( const wxString& name, wxTreeItemId& root )
...
@@ -863,32 +814,29 @@ bool TREE_PROJECT_FRAME::AddFile( const wxString& name, wxTreeItemId& root )
#ifdef KICAD_PYTHON
#ifdef KICAD_PYTHON
PyHandler
::
GetInstance
()
->
TriggerEvent
(
wxT
(
"kicad::TreeAddFile"
),
PyHandler
::
GetInstance
()
->
TriggerEvent
(
wxT
(
"kicad::TreeAddFile"
),
PyHandler
::
Convert
(
n
ame
)
);
PyHandler
::
Convert
(
aN
ame
)
);
#endif
/* KICAD_PYTHON */
#endif
/* KICAD_PYTHON */
// When enabled This section adds dirs and files found in the subdirs
// This section adds dirs and files found in the subdirs
// in this case AddFile is recursive.
// in this case AddFile is recursive, but for the first level only.
#ifdef ADD_FILES_IN_SUBDIRS
if
(
TREE_DIRECTORY
==
type
&&
aRecurse
)
if
(
TREE_DIRECTORY
==
type
)
{
{
const
wxString
sep
=
wxFileName
().
GetPathSeparator
();
const
wxString
sep
=
wxFileName
().
GetPathSeparator
();
wxDir
dir
(
n
ame
);
wxDir
dir
(
aN
ame
);
wxString
dir_filename
;
wxString
dir_filename
;
data
->
m_WasPopulated
=
true
;
// set state to populated
if
(
dir
.
GetFirst
(
&
dir_filename
)
)
if
(
dir
.
GetFirst
(
&
dir_filename
)
)
{
{
do
do
// Add name in tree, but do not recurse
{
{
AddFile
(
name
+
sep
+
dir_filename
,
cellul
e
);
AddFile
(
aName
+
sep
+
dir_filename
,
cellule
,
fals
e
);
}
while
(
dir
.
GetNext
(
&
dir_filename
)
);
}
while
(
dir
.
GetNext
(
&
dir_filename
)
);
}
}
/* Sort filenames by alphabetic order */
/* Sort filenames by alphabetic order */
m_TreeProject
->
SortChildren
(
cellule
);
m_TreeProject
->
SortChildren
(
cellule
);
}
}
#endif
/* ADD_FILES_IN_SUBDIRS */
return
true
;
return
true
;
}
}
...
@@ -935,7 +883,7 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj()
...
@@ -935,7 +883,7 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj()
m_TreeProject
->
SetItemBold
(
rootcellule
,
TRUE
);
m_TreeProject
->
SetItemBold
(
rootcellule
,
TRUE
);
m_TreeProject
->
SetItemData
(
rootcellule
,
m_TreeProject
->
SetItemData
(
rootcellule
,
new
T
reePrjItemData
(
TREE_PROJECT
,
new
T
REEPROJECT_ITEM
(
TREE_PROJECT
,
wxEmptyString
,
wxEmptyString
,
m_TreeProject
)
);
m_TreeProject
)
);
...
@@ -986,7 +934,7 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
...
@@ -986,7 +934,7 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
/*****************************************************************************/
/*****************************************************************************/
{
{
int
tree_id
;
int
tree_id
;
T
reePrjItemData
*
tree_data
;
T
REEPROJECT_ITEM
*
tree_data
;
wxString
FullFileName
;
wxString
FullFileName
;
wxTreeItemId
curr_item
=
Event
.
GetItem
();
wxTreeItemId
curr_item
=
Event
.
GetItem
();
...
@@ -1058,7 +1006,7 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
...
@@ -1058,7 +1006,7 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
void
TREE_PROJECT_FRAME
::
OnTxtEdit
(
wxCommandEvent
&
event
)
void
TREE_PROJECT_FRAME
::
OnTxtEdit
(
wxCommandEvent
&
event
)
/*****************************************************************************/
/*****************************************************************************/
{
{
T
reePrjItemData
*
tree_data
=
GetSelectedData
();
T
REEPROJECT_ITEM
*
tree_data
=
GetSelectedData
();
if
(
!
tree_data
)
if
(
!
tree_data
)
return
;
return
;
...
@@ -1086,7 +1034,7 @@ void TREE_PROJECT_FRAME::OnTxtEdit( wxCommandEvent& event )
...
@@ -1086,7 +1034,7 @@ void TREE_PROJECT_FRAME::OnTxtEdit( wxCommandEvent& event )
void
TREE_PROJECT_FRAME
::
OnDeleteFile
(
wxCommandEvent
&
)
void
TREE_PROJECT_FRAME
::
OnDeleteFile
(
wxCommandEvent
&
)
/*****************************************************************************/
/*****************************************************************************/
{
{
T
reePrjItemData
*
tree_data
=
GetSelectedData
();
T
REEPROJECT_ITEM
*
tree_data
=
GetSelectedData
();
if
(
!
tree_data
)
if
(
!
tree_data
)
return
;
return
;
...
@@ -1102,7 +1050,7 @@ void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& )
...
@@ -1102,7 +1050,7 @@ void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& )
/*****************************************************************************/
/*****************************************************************************/
{
{
wxTreeItemId
curr_item
=
m_TreeProject
->
GetSelection
();
wxTreeItemId
curr_item
=
m_TreeProject
->
GetSelection
();
T
reePrjItemData
*
tree_data
=
GetSelectedData
();
T
REEPROJECT_ITEM
*
tree_data
=
GetSelectedData
();
if
(
!
tree_data
)
if
(
!
tree_data
)
return
;
return
;
...
@@ -1127,7 +1075,7 @@ void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& )
...
@@ -1127,7 +1075,7 @@ void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& )
void
TREE_PROJECT_FRAME
::
OnRunPy
(
wxCommandEvent
&
event
)
void
TREE_PROJECT_FRAME
::
OnRunPy
(
wxCommandEvent
&
event
)
/*****************************************************************************/
/*****************************************************************************/
{
{
T
reePrjItemData
*
tree_data
=
GetSelectedData
();
T
REEPROJECT_ITEM
*
tree_data
=
GetSelectedData
();
if
(
!
tree_data
)
if
(
!
tree_data
)
return
;
return
;
...
@@ -1180,7 +1128,7 @@ int TREE_PROJECT_FRAME::AddStatePy( boost::python::object& bitmap )
...
@@ -1180,7 +1128,7 @@ int TREE_PROJECT_FRAME::AddStatePy( boost::python::object& bitmap )
void
TREE_PROJECT_FRAME
::
OnRenameAsk
(
wxTreeEvent
&
event
)
void
TREE_PROJECT_FRAME
::
OnRenameAsk
(
wxTreeEvent
&
event
)
/*****************************************************************************/
/*****************************************************************************/
{
{
T
reePrjItemData
*
tree_data
=
GetSelectedData
();
T
REEPROJECT_ITEM
*
tree_data
=
GetSelectedData
();
if
(
!
tree_data
)
if
(
!
tree_data
)
return
;
return
;
...
@@ -1196,7 +1144,7 @@ void TREE_PROJECT_FRAME::OnRenameAsk( wxTreeEvent& event )
...
@@ -1196,7 +1144,7 @@ void TREE_PROJECT_FRAME::OnRenameAsk( wxTreeEvent& event )
void
TREE_PROJECT_FRAME
::
OnRename
(
wxTreeEvent
&
event
)
void
TREE_PROJECT_FRAME
::
OnRename
(
wxTreeEvent
&
event
)
/*****************************************************************************/
/*****************************************************************************/
{
{
T
reePrjItemData
*
tree_data
=
GetSelectedData
();
T
REEPROJECT_ITEM
*
tree_data
=
GetSelectedData
();
if
(
!
tree_data
)
if
(
!
tree_data
)
return
;
return
;
...
@@ -1214,9 +1162,79 @@ void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event )
...
@@ -1214,9 +1162,79 @@ void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event )
{
{
wxString
FullFileName
;
wxString
FullFileName
;
T
reePrjItemData
*
tree_data
=
GetSelectedData
();
T
REEPROJECT_ITEM
*
tree_data
=
GetSelectedData
();
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
* populate tree items corresponding to subdirectories not already populated
*/
/*****************************************************************************/
void
TREE_PROJECT_FRAME
::
OnExpand
(
wxTreeEvent
&
Event
)
/*****************************************************************************/
{
wxString
FullFileName
;
wxTreeItemId
itemId
=
Event
.
GetItem
();
TREEPROJECT_ITEM
*
tree_data
=
GetItemIdData
(
itemId
);
if
(
!
tree_data
)
return
;
if
(
tree_data
->
GetType
()
!=
TREE_DIRECTORY
)
return
;
//explore list of non populated subdirs, and populate them
wxTreeItemIdValue
cookie
;
wxTreeItemId
kid
=
m_TreeProject
->
GetFirstChild
(
itemId
,
cookie
);
for
(
;
kid
.
IsOk
();
kid
=
m_TreeProject
->
GetNextChild
(
itemId
,
cookie
)
)
{
TREEPROJECT_ITEM
*
itemData
=
GetItemIdData
(
kid
);
if
(
!
itemData
||
itemData
->
GetType
()
!=
TREE_DIRECTORY
)
continue
;
if
(
itemData
->
m_WasPopulated
)
continue
;
wxString
fileName
=
itemData
->
GetFileName
();
const
wxString
sep
=
wxFileName
().
GetPathSeparator
();
wxDir
dir
(
fileName
);
wxString
dir_filename
;
if
(
dir
.
GetFirst
(
&
dir_filename
)
)
{
do
// Add name to tree item, but do not recurse in subdirs:
{
AddFile
(
fileName
+
sep
+
dir_filename
,
kid
,
false
);
}
while
(
dir
.
GetNext
(
&
dir_filename
)
);
}
itemData
->
m_WasPopulated
=
true
;
// set state to populated
/* Sort filenames by alphabetic order */
m_TreeProject
->
SortChildren
(
kid
);
}
}
/** function GetSelectedData
* return the item data from item currently selected (highlighted)
* Note this is not necessary the "clicked" item,
* because when expanding, collapsing an item this item is not selected
*/
TREEPROJECT_ITEM
*
TREE_PROJECT_FRAME
::
GetSelectedData
()
{
return
dynamic_cast
<
TREEPROJECT_ITEM
*>
(
m_TreeProject
->
GetItemData
(
m_TreeProject
->
GetSelection
()
)
);
}
/** 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
*
TREE_PROJECT_FRAME
::
GetItemIdData
(
wxTreeItemId
aId
)
{
return
dynamic_cast
<
TREEPROJECT_ITEM
*>
(
m_TreeProject
->
GetItemData
(
aId
)
);
}
kicad/tree_project_frame.h
View file @
c2389e8f
...
@@ -29,6 +29,8 @@
...
@@ -29,6 +29,8 @@
#ifndef TREEPRJ_FRAME_H
#ifndef TREEPRJ_FRAME_H
#define TREEPRJ_FRAME_H
#define TREEPRJ_FRAME_H
class
TREEPROJECT_ITEM
;
/** class TREE_PROJECT_FRAME
/** class TREE_PROJECT_FRAME
* Window to display the tree files
* Window to display the tree files
*/
*/
...
@@ -48,7 +50,18 @@ protected:
...
@@ -48,7 +50,18 @@ protected:
void
NewFile
(
TreeFileType
type
);
void
NewFile
(
TreeFileType
type
);
void
NewFile
(
const
wxString
&
name
,
TreeFileType
type
,
void
NewFile
(
const
wxString
&
name
,
TreeFileType
type
,
wxTreeItemId
&
root
);
wxTreeItemId
&
root
);
TreePrjItemData
*
GetSelectedData
();
/** function GetSelectedData
* return the item data from item currently selected (highlighted)
* Note this is not necessary the "clicked" item,
* because when expanding, collapsing an item this item is not selected
*/
TREEPROJECT_ITEM
*
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
);
public
:
public
:
WinEDA_MainFrame
*
m_Parent
;
WinEDA_MainFrame
*
m_Parent
;
...
@@ -63,6 +76,7 @@ public:
...
@@ -63,6 +76,7 @@ public:
TREE_PROJECT_FRAME
(
WinEDA_MainFrame
*
parent
);
TREE_PROJECT_FRAME
(
WinEDA_MainFrame
*
parent
);
~
TREE_PROJECT_FRAME
();
~
TREE_PROJECT_FRAME
();
void
OnSelect
(
wxTreeEvent
&
Event
);
void
OnSelect
(
wxTreeEvent
&
Event
);
void
OnExpand
(
wxTreeEvent
&
Event
);
void
OnRenameAsk
(
wxTreeEvent
&
Event
);
void
OnRenameAsk
(
wxTreeEvent
&
Event
);
void
OnRename
(
wxTreeEvent
&
Event
);
void
OnRename
(
wxTreeEvent
&
Event
);
void
OnDragStart
(
wxTreeEvent
&
event
);
void
OnDragStart
(
wxTreeEvent
&
event
);
...
@@ -75,14 +89,8 @@ public:
...
@@ -75,14 +89,8 @@ public:
void
OnDeleteFile
(
wxCommandEvent
&
event
);
void
OnDeleteFile
(
wxCommandEvent
&
event
);
void
OnRenameFile
(
wxCommandEvent
&
event
);
void
OnRenameFile
(
wxCommandEvent
&
event
);
void
OnNewFile
(
wxCommandEvent
&
event
);
void
OnNewDirectory
(
wxCommandEvent
&
event
);
void
OnNewDirectory
(
wxCommandEvent
&
event
);
void
OnNewSchFile
(
wxCommandEvent
&
event
);
void
OnNewBrdFile
(
wxCommandEvent
&
event
);
void
OnNewPyFile
(
wxCommandEvent
&
event
);
void
OnNewPyFile
(
wxCommandEvent
&
event
);
void
OnNewGerberFile
(
wxCommandEvent
&
event
);
void
OnNewTxtFile
(
wxCommandEvent
&
event
);
void
OnNewNetFile
(
wxCommandEvent
&
event
);
void
ClearFilters
();
void
ClearFilters
();
...
@@ -112,21 +120,32 @@ public:
...
@@ -112,21 +120,32 @@ public:
void
AddFilter
(
const
boost
::
python
::
str
&
filter
);
void
AddFilter
(
const
boost
::
python
::
str
&
filter
);
boost
::
python
::
object
GetTreeCtrl
();
boost
::
python
::
object
GetTreeCtrl
();
TreePrjItemData
*
GetItemData
(
const
boost
::
python
::
object
&
item
);
TREEPROJECT_ITEM
*
GetItemData
(
const
boost
::
python
::
object
&
item
);
void
AddFilePy
(
const
boost
::
python
::
str
&
name
,
void
AddFilePy
(
const
boost
::
python
::
str
&
name
,
boost
::
python
::
object
&
root
);
boost
::
python
::
object
&
root
);
void
NewFilePy
(
const
boost
::
python
::
str
&
name
,
void
NewFilePy
(
const
boost
::
python
::
str
&
name
,
TreeFileType
type
,
TreeFileType
type
,
boost
::
python
::
object
&
root
);
boost
::
python
::
object
&
root
);
T
reePrjItemData
*
FindItemData
(
const
boost
::
python
::
str
&
name
);
T
REEPROJECT_ITEM
*
FindItemData
(
const
boost
::
python
::
str
&
name
);
boost
::
python
::
object
GetCurrentMenu
();
boost
::
python
::
object
GetCurrentMenu
();
int
AddStatePy
(
boost
::
python
::
object
&
bitmap
);
int
AddStatePy
(
boost
::
python
::
object
&
bitmap
);
#endif
#endif
bool
AddFile
(
const
wxString
&
name
,
wxTreeItemId
&
root
);
/** function AddFile
* @brief Add filename "name" to the tree \n
* if name is a directory, add the sub directory file names
* @param aName = the filename or the dirctory name to add
* @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
* false to stop file add.
* @return true if the file (or directory) is added.
*/
bool
AddFile
(
const
wxString
&
aName
,
wxTreeItemId
&
aRoot
,
bool
aRecurse
=
true
);
DECLARE_EVENT_TABLE
()
DECLARE_EVENT_TABLE
()
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment