KiCad PCB EDA Suite
Loading...
Searching...
No Matches
project_tree.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2004-2012 Jean-Pierre Charras
5 * Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25
26#include <bitmaps.h>
28#include <wx/settings.h>
29
30#include "project_tree_item.h"
31#include "project_tree_pane.h"
32#include "project_tree.h"
33#include "kicad_id.h"
34
35
36IMPLEMENT_ABSTRACT_CLASS( PROJECT_TREE, wxTreeCtrl )
37
38
39#ifdef __WXMSW__
40#define PLATFORM_STYLE wxTR_LINES_AT_ROOT
41#else
42#define PLATFORM_STYLE wxTR_NO_LINES
43#endif
44
46 wxTreeCtrl( parent, ID_PROJECT_TREE, wxDefaultPosition, wxDefaultSize,
47 PLATFORM_STYLE | wxTR_HAS_BUTTONS | wxTR_MULTIPLE, wxDefaultValidator,
48 wxT( "EDATreeCtrl" ) ),
49 m_imageList( nullptr ),
50 m_statusImageList( nullptr )
51{
52 m_projectTreePane = parent;
53 m_gitCommon = new KIGIT_COMMON( nullptr );
54
55 // Make sure the GUI font scales properly on GTK
56 SetFont( KIUI::GetControlFont( this ) );
57
58 LoadIcons();
59}
60
61
63{
64 delete m_imageList;
65 delete m_statusImageList;
66}
67
68
70{
71 delete m_imageList;
72
73 int size = 24;
74
75 // Make an image list containing small icons
76 m_imageList = new wxImageList( size, size, true,
77 static_cast<int>( TREE_FILE_TYPE::MAX ) );
78
79 m_imageList->Add( KiBitmap( BITMAPS::project, size ) ); // TREE_LEGACY_PROJECT
80 m_imageList->Add( KiBitmap( BITMAPS::project_kicad, size ) ); // TREE_JSON_PROJECT
81 m_imageList->Add( KiBitmap( BITMAPS::icon_eeschema_24, size ) ); // TREE_LEGACY_SCHEMATIC
82 m_imageList->Add( KiBitmap( BITMAPS::icon_eeschema_24, size ) ); // TREE_SEXPR_SCHEMATIC
83 m_imageList->Add( KiBitmap( BITMAPS::icon_pcbnew_24, size ) ); // TREE_LEGACY_PCB
84 m_imageList->Add( KiBitmap( BITMAPS::icon_pcbnew_24, size ) ); // TREE_SEXPR_PCB
85 m_imageList->Add( KiBitmap( BITMAPS::icon_gerbview_24, size ) ); // TREE_GERBER
86 m_imageList->Add( KiBitmap( BITMAPS::file_gerber_job, size ) ); // TREE_GERBER_JOB_FILE (.gbrjob)
87 m_imageList->Add( KiBitmap( BITMAPS::file_html, size ) ); // TREE_HTML
88 m_imageList->Add( KiBitmap( BITMAPS::file_pdf, size ) ); // TREE_PDF
89 m_imageList->Add( KiBitmap( BITMAPS::editor, size ) ); // TREE_TXT
90 m_imageList->Add( KiBitmap( BITMAPS::editor, size ) ); // TREE_MD
91 m_imageList->Add( KiBitmap( BITMAPS::netlist, size ) ); // TREE_NET
92 m_imageList->Add( KiBitmap( BITMAPS::netlist, size ) ); // TREE_NET_SPICE
93 m_imageList->Add( KiBitmap( BITMAPS::unknown, size ) ); // TREE_UNKNOWN
94 m_imageList->Add( KiBitmap( BITMAPS::directory, size ) ); // TREE_DIRECTORY
95 m_imageList->Add( KiBitmap( BITMAPS::icon_cvpcb_24, size ) ); // TREE_CMP_LINK
96 m_imageList->Add( KiBitmap( BITMAPS::tools, size ) ); // TREE_REPORT
97 m_imageList->Add( KiBitmap( BITMAPS::file_pos, size ) ); // TREE_POS
98 m_imageList->Add( KiBitmap( BITMAPS::file_drl, size ) ); // TREE_DRILL
99 m_imageList->Add( KiBitmap( BITMAPS::file_drl, size ) ); // TREE_DRILL_NC (similar TREE_DRILL)
100 m_imageList->Add( KiBitmap( BITMAPS::file_drl, size ) ); // TREE_DRILL_XNC (similar TREE_DRILL)
101 m_imageList->Add( KiBitmap( BITMAPS::file_svg, size ) ); // TREE_SVG
102 m_imageList->Add( KiBitmap( BITMAPS::icon_pagelayout_editor_24, size ) ); // TREE_PAGE_LAYOUT_DESCR
103 m_imageList->Add( KiBitmap( BITMAPS::module, size ) ); // TREE_FOOTPRINT_FILE
104 m_imageList->Add( KiBitmap( BITMAPS::library, size ) ); // TREE_SCHEMATIC_LIBFILE
105 m_imageList->Add( KiBitmap( BITMAPS::library, size ) ); // TREE_SEXPR_SYMBOL_LIB_FILE
106 m_imageList->Add( KiBitmap( BITMAPS::editor, size ) ); // DESIGN_RULES
107 m_imageList->Add( KiBitmap( BITMAPS::zip, size ) ); // ZIP_ARCHIVE
108
109 SetImageList( m_imageList );
110
111 // Make an image list containing small icons
112 size = 16;
113
114 wxBitmap blank_bitmap( size, size );
115
116 delete m_statusImageList;
117 m_statusImageList = new wxImageList( size, size, true,
118 static_cast<int>( KIGIT_COMMON::GIT_STATUS::GIT_STATUS_LAST ) );
119
120 m_statusImageList->Add( blank_bitmap ); // GIT_STATUS_UNTRACKED
121 m_statusImageList->Add( KiBitmap( BITMAPS::git_good_check, size ) ); // GIT_STATUS_CURRENT
122 m_statusImageList->Add( KiBitmap( BITMAPS::git_modified, size ) ); // GIT_STATUS_MODIFIED
123 m_statusImageList->Add( KiBitmap( BITMAPS::git_add, size ) ); // GIT_STATUS_ADDED
124 m_statusImageList->Add( KiBitmap( BITMAPS::git_delete, size ) ); // GIT_STATUS_DELETED
125 m_statusImageList->Add( KiBitmap( BITMAPS::git_out_of_date, size ) ); // GIT_STATUS_BEHIND
126 m_statusImageList->Add( KiBitmap( BITMAPS::git_changed_ahead, size ) ); // GIT_STATUS_AHEAD
127 m_statusImageList->Add( KiBitmap( BITMAPS::git_conflict, size ) ); // GIT_STATUS_CONFLICTED
128
129 SetStateImageList( m_statusImageList );
130
131}
132
133
134int PROJECT_TREE::OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 )
135{
136 PROJECT_TREE_ITEM* myitem1 = (PROJECT_TREE_ITEM*) GetItemData( item1 );
137 PROJECT_TREE_ITEM* myitem2 = (PROJECT_TREE_ITEM*) GetItemData( item2 );
138
139 if( !myitem1 || !myitem2 )
140 return 0;
141
142 if( myitem1->GetType() == TREE_FILE_TYPE::DIRECTORY
143 && myitem2->GetType() != TREE_FILE_TYPE::DIRECTORY )
144 return -1;
145
146 if( myitem2->GetType() == TREE_FILE_TYPE::DIRECTORY
147 && myitem1->GetType() != TREE_FILE_TYPE::DIRECTORY )
148 return 1;
149
150 if( myitem1->IsRootFile() && !myitem2->IsRootFile() )
151 return -1;
152
153 if( myitem2->IsRootFile() && !myitem1->IsRootFile() )
154 return 1;
155
156 return myitem1->GetFileName().CmpNoCase( myitem2->GetFileName() );
157}
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104
Handle one item (a file or a directory name) for the tree file.
const wxString & GetFileName() const
TREE_FILE_TYPE GetType() const
bool IsRootFile() const
PROJECT_TREE_PANE Window to display the tree files.
PROJECT_TREE This is the class to show (as a tree) the files in the project directory.
Definition: project_tree.h:41
PROJECT_TREE_PANE * m_projectTreePane
Definition: project_tree.h:45
KIGIT_COMMON * m_gitCommon
Definition: project_tree.h:48
int OnCompareItems(const wxTreeItemId &item1, const wxTreeItemId &item2) override
wxImageList * m_statusImageList
Definition: project_tree.h:47
PROJECT_TREE(PROJECT_TREE_PANE *parent)
void LoadIcons()
wxImageList * m_imageList
Definition: project_tree.h:46
IDs used in KiCad main frame foe menuitems and tools.
@ ID_PROJECT_TREE
Definition: kicad_id.h:58
wxFont GetControlFont(wxWindow *aWindow)
Definition: ui_common.cpp:157
#define PLATFORM_STYLE