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 = std::make_unique<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 // KiCad for macOS currently has backported high-DPI support for this control
72 // that is not in a released version of wxWidgets 3.2 yet. This can become the
73 // main codepath once wxWidgets 3.4 is released.
74#ifdef __WXMAC__
75 wxVector<wxBitmapBundle> images;
76 images.push_back( KiBitmapBundle( BITMAPS::project ) ); // TREE_LEGACY_PROJECT
77 images.push_back( KiBitmapBundle( BITMAPS::project_kicad ) ); // TREE_JSON_PROJECT
78 images.push_back( KiBitmapBundle( BITMAPS::icon_eeschema_24 ) ); // TREE_LEGACY_SCHEMATIC
79 images.push_back( KiBitmapBundle( BITMAPS::icon_eeschema_24 ) ); // TREE_SEXPR_SCHEMATIC
80 images.push_back( KiBitmapBundle( BITMAPS::icon_pcbnew_24 ) ); // TREE_LEGACY_PCB
81 images.push_back( KiBitmapBundle( BITMAPS::icon_pcbnew_24 ) ); // TREE_SEXPR_PCB
82 images.push_back( KiBitmapBundle( BITMAPS::icon_gerbview_24 ) ); // TREE_GERBER
83 images.push_back( KiBitmapBundle( BITMAPS::file_gerber_job ) ); // TREE_GERBER_JOB_FILE (.gbrjob)
84 images.push_back( KiBitmapBundle( BITMAPS::file_html ) ); // TREE_HTML
85 images.push_back( KiBitmapBundle( BITMAPS::file_pdf ) ); // TREE_PDF
86 images.push_back( KiBitmapBundle( BITMAPS::editor ) ); // TREE_TXT
87 images.push_back( KiBitmapBundle( BITMAPS::editor ) ); // TREE_MD
88 images.push_back( KiBitmapBundle( BITMAPS::netlist ) ); // TREE_NET
89 images.push_back( KiBitmapBundle( BITMAPS::file_cir ) ); // TREE_NET_SPICE
90 images.push_back( KiBitmapBundle( BITMAPS::unknown ) ); // TREE_UNKNOWN
91 images.push_back( KiBitmapBundle( BITMAPS::directory ) ); // TREE_DIRECTORY
92 images.push_back( KiBitmapBundle( BITMAPS::icon_cvpcb_24 ) ); // TREE_CMP_LINK
93 images.push_back( KiBitmapBundle( BITMAPS::tools ) ); // TREE_REPORT
94 images.push_back( KiBitmapBundle( BITMAPS::file_pos ) ); // TREE_POS
95 images.push_back( KiBitmapBundle( BITMAPS::file_drl ) ); // TREE_DRILL
96 images.push_back( KiBitmapBundle( BITMAPS::file_drl ) ); // TREE_DRILL_NC (similar TREE_DRILL)
97 images.push_back( KiBitmapBundle( BITMAPS::file_drl ) ); // TREE_DRILL_XNC (similar TREE_DRILL)
98 images.push_back( KiBitmapBundle( BITMAPS::file_svg ) ); // TREE_SVG
99 images.push_back( KiBitmapBundle( BITMAPS::icon_pagelayout_editor_24 ) ); // TREE_PAGE_LAYOUT_DESCR
100 images.push_back( KiBitmapBundle( BITMAPS::module ) ); // TREE_FOOTPRINT_FILE
101 images.push_back( KiBitmapBundle( BITMAPS::library ) ); // TREE_SCHEMATIC_LIBFILE
102 images.push_back( KiBitmapBundle( BITMAPS::library ) ); // TREE_SEXPR_SYMBOL_LIB_FILE
103 images.push_back( KiBitmapBundle( BITMAPS::editor ) ); // DESIGN_RULES
104 images.push_back( KiBitmapBundle( BITMAPS::zip ) ); // ZIP_ARCHIVE
105 SetImages( images );
106
107 wxVector<wxBitmapBundle> stateImages;
108 stateImages.push_back( wxBitmapBundle() ); // GIT_STATUS_UNTRACKED
109 stateImages.push_back( KiBitmapBundle( BITMAPS::git_good_check ) ); // GIT_STATUS_CURRENT
110 stateImages.push_back( KiBitmapBundle( BITMAPS::git_modified ) ); // GIT_STATUS_MODIFIED
111 stateImages.push_back( KiBitmapBundle( BITMAPS::git_add ) ); // GIT_STATUS_ADDED
112 stateImages.push_back( KiBitmapBundle( BITMAPS::git_delete ) ); // GIT_STATUS_DELETED
113 stateImages.push_back( KiBitmapBundle( BITMAPS::git_out_of_date ) ); // GIT_STATUS_BEHIND
114 stateImages.push_back( KiBitmapBundle( BITMAPS::git_changed_ahead ) ); // GIT_STATUS_AHEAD
115 stateImages.push_back( KiBitmapBundle( BITMAPS::git_conflict ) ); // GIT_STATUS_CONFLICTED
116
117 SetStateImages( stateImages );
118#else
119 delete m_imageList;
120
121 // Make an image list containing small icons
122 int size = 24;
123
124 m_imageList = new wxImageList( size, size, true,
125 static_cast<int>( TREE_FILE_TYPE::MAX ) );
126
127 m_imageList->Add( KiBitmap( BITMAPS::project, size ) ); // TREE_LEGACY_PROJECT
128 m_imageList->Add( KiBitmap( BITMAPS::project_kicad, size ) ); // TREE_JSON_PROJECT
129 m_imageList->Add( KiBitmap( BITMAPS::icon_eeschema_24, size ) ); // TREE_LEGACY_SCHEMATIC
130 m_imageList->Add( KiBitmap( BITMAPS::icon_eeschema_24, size ) ); // TREE_SEXPR_SCHEMATIC
131 m_imageList->Add( KiBitmap( BITMAPS::icon_pcbnew_24, size ) ); // TREE_LEGACY_PCB
132 m_imageList->Add( KiBitmap( BITMAPS::icon_pcbnew_24, size ) ); // TREE_SEXPR_PCB
133 m_imageList->Add( KiBitmap( BITMAPS::icon_gerbview_24, size ) ); // TREE_GERBER
134 m_imageList->Add( KiBitmap( BITMAPS::file_gerber_job, size ) ); // TREE_GERBER_JOB_FILE (.gbrjob)
135 m_imageList->Add( KiBitmap( BITMAPS::file_html, size ) ); // TREE_HTML
136 m_imageList->Add( KiBitmap( BITMAPS::file_pdf, size ) ); // TREE_PDF
137 m_imageList->Add( KiBitmap( BITMAPS::editor, size ) ); // TREE_TXT
138 m_imageList->Add( KiBitmap( BITMAPS::editor, size ) ); // TREE_MD
139 m_imageList->Add( KiBitmap( BITMAPS::netlist, size ) ); // TREE_NET
140 m_imageList->Add( KiBitmap( BITMAPS::file_cir, size ) ); // TREE_NET_SPICE
141 m_imageList->Add( KiBitmap( BITMAPS::unknown, size ) ); // TREE_UNKNOWN
142 m_imageList->Add( KiBitmap( BITMAPS::directory, size ) ); // TREE_DIRECTORY
143 m_imageList->Add( KiBitmap( BITMAPS::icon_cvpcb_24, size ) ); // TREE_CMP_LINK
144 m_imageList->Add( KiBitmap( BITMAPS::tools, size ) ); // TREE_REPORT
145 m_imageList->Add( KiBitmap( BITMAPS::file_pos, size ) ); // TREE_POS
146 m_imageList->Add( KiBitmap( BITMAPS::file_drl, size ) ); // TREE_DRILL
147 m_imageList->Add( KiBitmap( BITMAPS::file_drl, size ) ); // TREE_DRILL_NC (similar TREE_DRILL)
148 m_imageList->Add( KiBitmap( BITMAPS::file_drl, size ) ); // TREE_DRILL_XNC (similar TREE_DRILL)
149 m_imageList->Add( KiBitmap( BITMAPS::file_svg, size ) ); // TREE_SVG
150 m_imageList->Add( KiBitmap( BITMAPS::icon_pagelayout_editor_24, size ) ); // TREE_PAGE_LAYOUT_DESCR
151 m_imageList->Add( KiBitmap( BITMAPS::module, size ) ); // TREE_FOOTPRINT_FILE
152 m_imageList->Add( KiBitmap( BITMAPS::library, size ) ); // TREE_SCHEMATIC_LIBFILE
153 m_imageList->Add( KiBitmap( BITMAPS::library, size ) ); // TREE_SEXPR_SYMBOL_LIB_FILE
154 m_imageList->Add( KiBitmap( BITMAPS::editor, size ) ); // DESIGN_RULES
155 m_imageList->Add( KiBitmap( BITMAPS::zip, size ) ); // ZIP_ARCHIVE
156
157 SetImageList( m_imageList );
158
159 // Make an image list containing small icons
160 size = 16;
161
162 wxBitmap blank_bitmap( size, size );
163
164 delete m_statusImageList;
165 m_statusImageList = new wxImageList( size, size, true,
166 static_cast<int>( KIGIT_COMMON::GIT_STATUS::GIT_STATUS_LAST ) );
167
168 m_statusImageList->Add( blank_bitmap ); // GIT_STATUS_UNTRACKED
169 m_statusImageList->Add( KiBitmap( BITMAPS::git_good_check, size ) ); // GIT_STATUS_CURRENT
170 m_statusImageList->Add( KiBitmap( BITMAPS::git_modified, size ) ); // GIT_STATUS_MODIFIED
171 m_statusImageList->Add( KiBitmap( BITMAPS::git_add, size ) ); // GIT_STATUS_ADDED
172 m_statusImageList->Add( KiBitmap( BITMAPS::git_delete, size ) ); // GIT_STATUS_DELETED
173 m_statusImageList->Add( KiBitmap( BITMAPS::git_out_of_date, size ) ); // GIT_STATUS_BEHIND
174 m_statusImageList->Add( KiBitmap( BITMAPS::git_changed_ahead, size ) ); // GIT_STATUS_AHEAD
175 m_statusImageList->Add( KiBitmap( BITMAPS::git_conflict, size ) ); // GIT_STATUS_CONFLICTED
176
177 SetStateImageList( m_statusImageList );
178#endif
179
180}
181
182
183int PROJECT_TREE::OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 )
184{
185 PROJECT_TREE_ITEM* myitem1 = (PROJECT_TREE_ITEM*) GetItemData( item1 );
186 PROJECT_TREE_ITEM* myitem2 = (PROJECT_TREE_ITEM*) GetItemData( item2 );
187
188 if( !myitem1 || !myitem2 )
189 return 0;
190
191 if( myitem1->GetType() == TREE_FILE_TYPE::DIRECTORY
192 && myitem2->GetType() != TREE_FILE_TYPE::DIRECTORY )
193 return -1;
194
195 if( myitem2->GetType() == TREE_FILE_TYPE::DIRECTORY
196 && myitem1->GetType() != TREE_FILE_TYPE::DIRECTORY )
197 return 1;
198
199 if( myitem1->IsRootFile() && !myitem2->IsRootFile() )
200 return -1;
201
202 if( myitem2->IsRootFile() && !myitem1->IsRootFile() )
203 return 1;
204
205 return myitem1->GetFileName().CmpNoCase( myitem2->GetFileName() );
206}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
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:43
PROJECT_TREE_PANE * m_projectTreePane
Definition: project_tree.h:47
int OnCompareItems(const wxTreeItemId &item1, const wxTreeItemId &item2) override
wxImageList * m_statusImageList
Definition: project_tree.h:49
PROJECT_TREE(PROJECT_TREE_PANE *parent)
std::unique_ptr< KIGIT_COMMON > m_gitCommon
Definition: project_tree.h:50
void LoadIcons()
wxImageList * m_imageList
Definition: project_tree.h:48
IDs used in KiCad main frame foe menuitems and tools.
@ ID_PROJECT_TREE
Definition: kicad_id.h:58
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
Definition: ui_common.cpp:157
#define PLATFORM_STYLE