KiCad PCB EDA Suite
Loading...
Searching...
No Matches
project_tree_pane.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) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <stack>
25#include <git/git_backend.h>
26
27#include <wx/regex.h>
28#include <wx/richmsgdlg.h>
29#include <wx/stdpaths.h>
30#include <wx/string.h>
31#include <wx/msgdlg.h>
32#include <wx/textdlg.h>
33#include <wx/timer.h>
34#include <wx/wupdlock.h>
35#include <wx/log.h>
36#include <wx/dcclient.h>
37#include <wx/progdlg.h>
38#include <wx/settings.h>
39#include <wx/weakref.h>
40
41#include <frame_type.h>
42#include <kiway.h>
43#include <mail_type.h>
45
47#include <advanced_config.h>
48#include <bitmaps.h>
49#include <bitmap_store.h>
50#include <confirm.h>
56#include <gestfich.h>
57#include <macros.h>
58#include <trace_helpers.h>
61#include <core/kicad_algo.h>
62#include <paths.h>
64#include <scoped_set_reset.h>
65#include <string_utils.h>
66#include <thread_pool.h>
67#include <launch_ext.h>
68#include <wx_log_utils.h>
69
76#include <git/kigit_ignore.h>
78
80
81#include "project_tree_item.h"
82#include "project_tree.h"
83#include "pgm_kicad.h"
84#include "kicad_id.h"
85#include "kicad_manager_frame.h"
86
87#include "project_tree_pane.h"
88#include <widgets/kistatusbar.h>
89
90#include <kiplatform/io.h>
91#include <kiplatform/secrets.h>
92
93
94/* Note about the project tree build process:
95 * Building the project tree can be *very* long if there are a lot of subdirectories in the
96 * working directory. Unfortunately, this happens easily if the project file *.pro is in the
97 * user's home directory.
98 * So the tree project is built "on demand":
99 * First the tree is built from the current directory and shows files and subdirs.
100 * > First level subdirs trees are built (i.e subdirs contents are not read)
101 * > When expanding a subdir, each subdir contains is read, and the corresponding sub tree is
102 * populated on the fly.
103 */
104
105// The pool's future does not block on destruction, so replacing one still running would abandon
106// the task rather than wait for it.
107static bool gitTaskStillRunning( const std::future<void>& aTask )
108{
109 return aTask.valid() && aTask.wait_for( std::chrono::seconds( 0 ) ) != std::future_status::ready;
110}
111
112
113namespace
114{
115
116// What the Ignore submenu can offer. A selection whose paths disagree offers nothing.
117struct IGNORE_SELECTION
118{
119 std::vector<GIT_IGNORE_TARGET> targets;
120
122 wxString extensionRule;
123
125 bool canIgnore = false;
126
128 bool ignored = false;
129
131 bool canKeepPath = false;
132 bool canKeepExtension = false;
133};
134
135
136// Reads the repository, so the caller holds the action lock.
137IGNORE_SELECTION gitIgnoreSelection( KIGIT_COMMON& aCommon, const wxString& aProjectPath,
138 const std::vector<PROJECT_TREE_ITEM*>& aSelection )
139{
140 const std::vector<wxString> rules = KIGIT::ReadIgnoreRules( KIGIT::ProjectIgnoreFile( aProjectPath ) );
141
142 IGNORE_SELECTION selection;
143 bool allIgnored = true;
144 bool allNamed = true;
145 bool allFiles = true;
146 bool anyTracked = false;
147
148 for( PROJECT_TREE_ITEM* item : aSelection )
149 {
150 if( !item )
151 return IGNORE_SELECTION();
152
153 wxString path = item->GetFileName();
154
155 if( !path.StartsWith( aProjectPath ) )
156 return IGNORE_SELECTION();
157
158 path = path.Mid( aProjectPath.length() );
159
160#ifdef __WINDOWS__
161 path.Replace( wxS( "\\" ), wxS( "/" ) );
162#endif
163
164 // The project folder holds the ignore file, so it cannot be one of its rules.
165 if( path.IsEmpty() )
166 return IGNORE_SELECTION();
167
168 const bool isDirectory = item->GetType() == TREE_FILE_TYPE::DIRECTORY;
169 const KIGIT::IGNORE_STATE state = KIGIT::IgnoreState( aCommon, path, isDirectory );
170
171 allIgnored &= state.ignored;
172 anyTracked |= state.tracked;
173 allNamed &= alg::contains( rules, KIGIT::PathIgnoreRule( path, isDirectory ) );
174 allFiles &= !isDirectory;
175
176 const wxString extensionRule = KIGIT::ExtensionIgnoreRule( path );
177
178 if( selection.targets.empty() )
179 selection.extensionRule = extensionRule;
180 else if( selection.extensionRule != extensionRule )
181 selection.extensionRule.Clear();
182
183 selection.targets.push_back( { path, isDirectory } );
184 }
185
186 if( selection.targets.empty() )
187 return selection;
188
189 if( !allFiles )
190 selection.extensionRule.Clear();
191
192 selection.canIgnore = !anyTracked && !allIgnored;
193 selection.ignored = allIgnored;
194 selection.canKeepPath = allIgnored && allNamed;
195 selection.canKeepExtension =
196 allIgnored && !selection.extensionRule.IsEmpty() && alg::contains( rules, selection.extensionRule );
197
198 return selection;
199}
200
201} // namespace
202
203
204// list of files extensions listed in the tree project window
205// Add extensions in a compatible regex format to see others files types
206static const wxChar* s_allowedExtensionsToList[] =
207{
208 wxT( "^.*\\.pro$" ),
209 wxT( "^.*\\.kicad_pro$" ),
210 wxT( "^.*\\.pdf$" ),
211 wxT( "^.*\\.sch$" ), // Legacy Eeschema files
212 wxT( "^.*\\.kicad_sch$" ), // S-expr Eeschema files
213 wxT( "^[^$].*\\.brd$" ), // Legacy Pcbnew files
214 wxT( "^[^$].*\\.kicad_pcb$" ), // S format Pcbnew board files
215 wxT( "^[^$].*\\.kicad_dru$" ), // Design rule files
216 wxT( "^[^$].*\\.kicad_wks$" ), // S format kicad drawing sheet files
217 wxT( "^[^$].*\\.kicad_mod$" ), // S format kicad footprint files, currently not listed
218 wxT( "^.*\\.net$" ), // pcbnew netlist file
219 wxT( "^.*\\.cir$" ), // Spice netlist file
220 wxT( "^.*\\.lib$" ), // Legacy schematic library file
221 wxT( "^.*\\.kicad_sym$" ), // S-expr symbol libraries
222 wxT( "^.*\\.txt$" ), // Text files
223 wxT( "^.*\\.md$" ), // Markdown files
224 wxT( "^.*\\.pho$" ), // Gerber file (Old Kicad extension)
225 wxT( "^.*\\.gbr$" ), // Gerber file
226 wxT( "^.*\\.gbrjob$" ), // Gerber job file
227 wxT( "^.*\\.gb[alops]$" ), // Gerber back (or bottom) layer file (deprecated Protel ext)
228 wxT( "^.*\\.gt[alops]$" ), // Gerber front (or top) layer file (deprecated Protel ext)
229 wxT( "^.*\\.g[0-9]{1,2}$" ), // Gerber inner layer file (deprecated Protel ext)
230 wxT( "^.*\\.gm[0-9]{1,2}$" ), // Gerber mechanical layer file (deprecated Protel ext)
231 wxT( "^.*\\.gko$" ), // Gerber keepout layer file (deprecated Protel ext)
232 wxT( "^.*\\.odt$" ),
233 wxT( "^.*\\.htm$" ),
234 wxT( "^.*\\.html$" ),
235 wxT( "^.*\\.rpt$" ), // Report files
236 wxT( "^.*\\.csv$" ), // Report files in comma separated format
237 wxT( "^.*\\.pos$" ), // Footprint position files
238 wxT( "^.*\\.cmp$" ), // CvPcb cmp/footprint link files
239 wxT( "^.*\\.drl$" ), // Excellon drill files
240 wxT( "^.*\\.nc$" ), // Excellon NC drill files (alternate file ext)
241 wxT( "^.*\\.xnc$" ), // Excellon NC drill files (alternate file ext)
242 wxT( "^.*\\.svg$" ), // SVG print/plot files
243 wxT( "^.*\\.ps$" ), // PostScript plot files
244 wxT( "^.*\\.zip$" ), // Zip archive files
245 wxT( "^.*\\.kicad_jobset" ), // KiCad jobs file
246 nullptr // end of list
247};
248
249
255
256
258{
259 ID_PROJECT_TXTEDIT = 8700, // Start well above wxIDs
265
266 ID_GIT_INITIALIZE_PROJECT, // Initialize a new git repository in an existing project
267 ID_GIT_REMOTE_SETTINGS, // Configure (or set) the default remote on an existing repo
268 ID_GIT_HISTORY, // Show the commit history in the advanced Git window
269 ID_GIT_REMOVE_VCS, // Toggle Git integration for this project (preference in kicad_prl)
270 ID_GIT_SWITCH_BRANCH, // Switch the local repository to a different branch
271 ID_GIT_SWITCH_QUICK1, // Switch the local repository to the first quick branch
272 ID_GIT_SWITCH_QUICK2, // Switch the local repository to the second quick branch
273 ID_GIT_SWITCH_QUICK3, // Switch the local repository to the third quick branch
274 ID_GIT_SWITCH_QUICK4, // Switch the local repository to the fourth quick branch
275 ID_GIT_SWITCH_QUICK5, // Switch the local repository to the fifth quick branch
276 ID_GIT_IGNORE_PATH, // Add the selected paths to the project's ignored files
277 ID_GIT_IGNORE_EXTENSION, // Ignore every file sharing the selection's extension
278 ID_GIT_KEEP_PATH, // Take the selected paths out of the ignored files
279 ID_GIT_KEEP_EXTENSION, // Stop ignoring every file sharing the selection's extension
280 ID_GIT_EDIT_IGNORE_FILE, // Open the project's ignore file in a text editor
281
283};
284
285
286BEGIN_EVENT_TABLE( PROJECT_TREE_PANE, wxSashLayoutWindow )
287 EVT_TREE_ITEM_ACTIVATED( ID_PROJECT_TREE, PROJECT_TREE_PANE::onSelect )
288 EVT_TREE_ITEM_EXPANDED( ID_PROJECT_TREE, PROJECT_TREE_PANE::onExpand )
289 EVT_TREE_ITEM_RIGHT_CLICK( ID_PROJECT_TREE, PROJECT_TREE_PANE::onRight )
296
305
307
308 EVT_IDLE( PROJECT_TREE_PANE::onIdle )
309 EVT_PAINT( PROJECT_TREE_PANE::onPaint )
310END_EVENT_TABLE()
311
312
313wxDECLARE_EVENT( UPDATE_ICONS, wxCommandEvent );
314
316 wxSashLayoutWindow( parent, ID_LEFT_FRAME, wxDefaultPosition, wxDefaultSize, wxNO_BORDER | wxTAB_TRAVERSAL ),
317 m_branchQuery( std::make_unique<KIGIT_QUERY>() )
318{
319 m_Parent = parent;
320 m_TreeProject = nullptr;
321 m_isRenaming = false;
322 m_selectedItem = nullptr;
323 m_watcherNeedReset = false;
324 m_watcher = nullptr;
325 m_gitIconsInitialized = false;
326
327 Bind( wxEVT_FSWATCHER,
328 wxFileSystemWatcherEventHandler( PROJECT_TREE_PANE::onFileSystemEvent ), this );
329
330 Bind( wxEVT_SYS_COLOUR_CHANGED,
331 wxSysColourChangedEventHandler( PROJECT_TREE_PANE::onThemeChanged ), this );
332
333 m_gitSyncTimer.SetOwner( this );
334 m_gitStatusTimer.SetOwner( this );
335 Bind( wxEVT_TIMER, wxTimerEventHandler( PROJECT_TREE_PANE::onGitSyncTimer ), this, m_gitSyncTimer.GetId() );
336 Bind( wxEVT_TIMER, wxTimerEventHandler( PROJECT_TREE_PANE::onGitStatusTimer ), this, m_gitStatusTimer.GetId() );
337 /*
338 * Filtering is now inverted: the filters are actually used to _enable_ support
339 * for a given file type.
340 */
341 for( int ii = 0; s_allowedExtensionsToList[ii] != nullptr; ii++ )
342 m_filters.emplace_back( s_allowedExtensionsToList[ii] );
343
344 m_filters.emplace_back( wxT( "^no KiCad files found" ) );
345
347}
348
349
351{
352 m_branchQuery->Cancel();
353
354 Unbind( wxEVT_FSWATCHER,
355 wxFileSystemWatcherEventHandler( PROJECT_TREE_PANE::onFileSystemEvent ), this );
356 Unbind( wxEVT_SYS_COLOUR_CHANGED,
357 wxSysColourChangedEventHandler( PROJECT_TREE_PANE::onThemeChanged ), this );
358
359 m_gitSyncTimer.Stop();
360 m_gitStatusTimer.Stop();
361 Unbind( wxEVT_TIMER, wxTimerEventHandler( PROJECT_TREE_PANE::onGitSyncTimer ), this, m_gitSyncTimer.GetId() );
362 Unbind( wxEVT_TIMER, wxTimerEventHandler( PROJECT_TREE_PANE::onGitStatusTimer ), this, m_gitStatusTimer.GetId() );
364
365 if( std::shared_ptr<KIGIT_COMMON> common = m_gitListenerSession.lock() )
366 common->RemoveRefreshListener( this );
367
368 if( m_gitSyncTask.valid() )
369 m_gitSyncTask.wait();
370
371 if( m_gitStatusIconTask.valid() )
372 m_gitStatusIconTask.wait();
373}
374
375
377{
378 if( m_watcher )
379 {
380 m_watcher->RemoveAll();
381 m_watcher->SetOwner( nullptr );
382 delete m_watcher;
383 m_watcher = nullptr;
384 }
385}
386
387
389{
390 std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
391
392 if( tree_data.size() != 1 )
393 return;
394
395 wxString prj_filename = tree_data[0]->GetFileName();
396
397 m_Parent->LoadProject( prj_filename );
398}
399
400
401void PROJECT_TREE_PANE::onOpenDirectory( wxCommandEvent& event )
402{
403 // Get the root directory name:
404 std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
405
406 for( PROJECT_TREE_ITEM* item_data : tree_data )
407 {
408 // Ask for the new sub directory name
409 wxString curr_dir = item_data->GetDir();
410
411 if( curr_dir.IsEmpty() )
412 {
413 // Use project path if the tree view path was empty.
414 curr_dir = wxPathOnly( m_Parent->GetProjectFileName() );
415
416 // As a last resort use the user's documents folder.
417 if( curr_dir.IsEmpty() || !wxFileName::DirExists( curr_dir ) )
419
420 if( !curr_dir.IsEmpty() )
421 curr_dir += wxFileName::GetPathSeparator();
422 }
423
424 LaunchExternal( curr_dir );
425 }
426}
427
428
429void PROJECT_TREE_PANE::onCreateNewDirectory( wxCommandEvent& event )
430{
431 // Get the root directory name:
432 std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
433
434 for( PROJECT_TREE_ITEM* item_data : tree_data )
435 {
436 wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
437
438 // Ask for the new sub directory name
439 wxString curr_dir = item_data->GetDir();
440
441 if( curr_dir.IsEmpty() )
442 curr_dir = prj_dir;
443
444 wxString new_dir = wxGetTextFromUser( _( "Directory name:" ), _( "Create New Directory" ) );
445
446 if( new_dir.IsEmpty() )
447 return;
448
449 wxString full_dirname = curr_dir + wxFileName::GetPathSeparator() + new_dir;
450
451 if( !wxMkdir( full_dirname ) )
452 return;
453
454 addItemToProjectTree( full_dirname, item_data->GetId(), nullptr, false );
455 }
456}
457
458
460{
461 switch( type )
462 {
481 case TREE_FILE_TYPE::DRILL_NC: return "nc";
482 case TREE_FILE_TYPE::DRILL_XNC: return "xnc";
492
496 case TREE_FILE_TYPE::DIRECTORY: break;
497 }
498
499 return wxEmptyString;
500}
501
502
503std::vector<wxString> getProjects( const wxDir& dir )
504{
505 std::vector<wxString> projects;
506 wxString dir_filename;
507 bool haveFile = dir.GetFirst( &dir_filename );
508
509 while( haveFile )
510 {
511 wxFileName file( dir_filename );
512
513 if( file.GetExt() == FILEEXT::LegacyProjectFileExtension
514 || file.GetExt() == FILEEXT::ProjectFileExtension )
515 projects.push_back( file.GetName() );
516
517 haveFile = dir.GetNext( &dir_filename );
518 }
519
520 return projects;
521}
522
523
524
525
526
527wxTreeItemId PROJECT_TREE_PANE::addItemToProjectTree( const wxString& aName,
528 const wxTreeItemId& aParent,
529 std::vector<wxString>* aProjectNames,
530 bool aRecurse )
531{
533 wxFileName fn( aName );
534
535 if( KIPLATFORM::IO::IsFileHidden( aName ) )
536 return wxTreeItemId();
537
538 // Windows only hides .git when it carries the hidden attribute
539 if( fn.GetFullName().IsSameAs( wxS( ".git" ), false ) )
540 return wxTreeItemId();
541
542 if( wxDirExists( aName ) )
543 {
545 }
546 else
547 {
548 // Filter
549 wxRegEx reg;
550 bool addFile = false;
551
552 for( const wxString& m_filter : m_filters )
553 {
554 wxCHECK2_MSG( reg.Compile( m_filter, wxRE_ICASE ), continue,
555 wxString::Format( "Regex %s failed to compile.", m_filter ) );
556
557 if( reg.Matches( aName ) )
558 {
559 addFile = true;
560 break;
561 }
562 }
563
564 if( !addFile )
565 return wxTreeItemId();
566
567 for( int i = static_cast<int>( TREE_FILE_TYPE::LEGACY_PROJECT );
568 i < static_cast<int>( TREE_FILE_TYPE::MAX ); i++ )
569 {
570 wxString ext = GetFileExt( (TREE_FILE_TYPE) i );
571
572 if( ext == wxT( "" ) )
573 continue;
574
575 if( reg.Compile( wxString::FromAscii( "^.*\\." ) + ext + wxString::FromAscii( "$" ), wxRE_ICASE )
576 && reg.Matches( aName ) )
577 {
578 type = (TREE_FILE_TYPE) i;
579 break;
580 }
581 }
582 }
583
584 wxString file = wxFileNameFromPath( aName );
585 wxFileName currfile( file );
586 wxFileName project( m_Parent->GetProjectFileName() );
587 bool showAllSchematics = gitRepo() != nullptr;
588
589 // Ignore legacy projects with the same name as the current project
590 if( ( type == TREE_FILE_TYPE::LEGACY_PROJECT )
591 && ( currfile.GetName().CmpNoCase( project.GetName() ) == 0 ) )
592 {
593 return wxTreeItemId();
594 }
595
596 if( !showAllSchematics && ( currfile.GetExt() == GetFileExt( TREE_FILE_TYPE::LEGACY_SCHEMATIC )
597 || currfile.GetExt() == GetFileExt( TREE_FILE_TYPE::SEXPR_SCHEMATIC ) ) )
598 {
599 if( aProjectNames )
600 {
601 if( !alg::contains( *aProjectNames, currfile.GetName() ) )
602 return wxTreeItemId();
603 }
604 else
605 {
606 PROJECT_TREE_ITEM* parentTreeItem = GetItemIdData( aParent );
607
608 if( !parentTreeItem )
609 return wxTreeItemId();
610
611 wxDir parentDir( parentTreeItem->GetDir() );
612 std::vector<wxString> projects = getProjects( parentDir );
613
614 if( !alg::contains( projects, currfile.GetName() ) )
615 return wxTreeItemId();
616 }
617 }
618
619 // also check to see if it is already there.
620 wxTreeItemIdValue cookie;
621 wxTreeItemId kid = m_TreeProject->GetFirstChild( aParent, cookie );
622
623 while( kid.IsOk() )
624 {
625 PROJECT_TREE_ITEM* itemData = GetItemIdData( kid );
626
627 if( itemData && itemData->GetFileName() == aName )
628 return itemData->GetId(); // well, we would have added it, but it is already here!
629
630 kid = m_TreeProject->GetNextChild( aParent, cookie );
631 }
632
633 // Only show current files if both legacy and current files are present
638 {
639 kid = m_TreeProject->GetFirstChild( aParent, cookie );
640
641 while( kid.IsOk() )
642 {
643 PROJECT_TREE_ITEM* itemData = GetItemIdData( kid );
644
645 if( itemData )
646 {
647 wxFileName fname( itemData->GetFileName() );
648
649 if( fname.GetName().CmpNoCase( currfile.GetName() ) == 0 )
650 {
651 switch( type )
652 {
654 if( itemData->GetType() == TREE_FILE_TYPE::JSON_PROJECT )
655 return wxTreeItemId();
656
657 break;
658
660 if( itemData->GetType() == TREE_FILE_TYPE::SEXPR_SCHEMATIC )
661 return wxTreeItemId();
662
663 break;
664
666 if( itemData->GetType() == TREE_FILE_TYPE::LEGACY_PROJECT )
667 m_TreeProject->Delete( kid );
668
669 break;
670
672 if( itemData->GetType() == TREE_FILE_TYPE::LEGACY_SCHEMATIC )
673 m_TreeProject->Delete( kid );
674
675 break;
676
677 default:
678 break;
679 }
680 }
681 }
682
683 kid = m_TreeProject->GetNextChild( aParent, cookie );
684 }
685 }
686
687 // Append the item (only appending the filename not the full path):
688 wxTreeItemId newItemId = m_TreeProject->AppendItem( aParent, file );
689 PROJECT_TREE_ITEM* data = new PROJECT_TREE_ITEM( type, aName, m_TreeProject );
690
691 m_TreeProject->SetItemData( newItemId, data );
692 data->SetState( 0 );
693
694 // Mark root files (files which have the same aName as the project)
695 wxString fileName = currfile.GetName().Lower();
696 wxString projName = project.GetName().Lower();
697
698 if( fileName == projName || fileName.StartsWith( projName + "-" ) )
699 data->SetRootFile( true );
700
701#ifndef __WINDOWS__
702 bool subdir_populated = false;
703#endif
704
705 // This section adds dirs and files found in the subdirs
706 // in this case AddFile is recursive, but for the first level only.
707 if( TREE_FILE_TYPE::DIRECTORY == type && aRecurse )
708 {
709 wxDir dir( aName );
710
711 if( dir.IsOpened() ) // protected dirs will not open properly.
712 {
713 std::vector<wxString> projects = getProjects( dir );
714 wxString dir_filename;
715 bool haveFile = dir.GetFirst( &dir_filename );
716
717 data->SetPopulated( true );
718
719#ifndef __WINDOWS__
720 subdir_populated = aRecurse;
721#endif
722
723 while( haveFile )
724 {
725 // Add name in tree, but do not recurse
726 wxString path = aName + wxFileName::GetPathSeparator() + dir_filename;
727 addItemToProjectTree( path, newItemId, &projects, false );
728
729 haveFile = dir.GetNext( &dir_filename );
730 }
731 }
732
733 // Sort filenames by alphabetic order
734 m_TreeProject->SortChildren( newItemId );
735 }
736
737#ifndef __WINDOWS__
738 if( subdir_populated )
739 m_watcherNeedReset = true;
740#endif
741
742 return newItemId;
743}
744
745
747{
748 std::lock_guard<std::mutex> lock1( m_gitStatusMutex );
749 std::lock_guard<std::mutex> lock2( m_gitTreeCacheMutex );
750
751 m_gitStatusTimer.Stop();
752 m_gitSyncTimer.Stop();
753
754 m_gitTreeCache.clear();
755 m_gitStatusIcons.clear();
756 m_gitLastStatus.clear();
757
758 wxString pro_dir = m_Parent->GetProjectFileName();
759
760 if( !m_TreeProject )
761 m_TreeProject = new PROJECT_TREE( this );
762 else
763 m_TreeProject->DeleteAllItems();
764
765 if( !pro_dir ) // This is empty from PROJECT_TREE_PANE constructor
766 return;
767
768 // Releasing here would cancel a push or pull running from an editor panel on every tree
769 // refresh, and a project switch already disposes of the session.
770 if( gitRepo() )
771 {
772 if( !Pgm().GetCommonSettings()->m_Git.enableGit )
774
775 m_gitIconsInitialized = false;
776 }
777
778 wxFileName fn = pro_dir;
779 bool prjReset = false;
780
781 if( !fn.IsOk() )
782 {
783 fn.Clear();
784 fn.SetPath( PATHS::GetDefaultUserProjectsPath() );
785 fn.SetName( NAMELESS_PROJECT );
787 prjReset = true;
788 }
789
790 bool prjOpened = fn.FileExists();
791
792 if( Pgm().GetCommonSettings()->m_Git.enableGit )
793 {
796 }
797
798 // We may have opened a legacy project, in which case GetProjectFileName will return the
799 // name of the migrated (new format) file, which may not have been saved to disk yet.
800 if( !prjOpened && !prjReset )
801 {
803 prjOpened = fn.FileExists();
804
805 // Set the ext back so that in the tree view we see the (not-yet-saved) new file
807 }
808
809 // root tree:
810 m_root = m_TreeProject->AddRoot( fn.GetFullName(), static_cast<int>( TREE_FILE_TYPE::ROOT ),
811 static_cast<int>( TREE_FILE_TYPE::ROOT ) );
812 m_TreeProject->SetItemBold( m_root, true );
813
814 // The main project file is now a JSON file
817
818 m_TreeProject->SetItemData( m_root, data );
819
820 // Now adding all current files if available
821 if( prjOpened )
822 {
823 pro_dir = wxPathOnly( m_Parent->GetProjectFileName() );
824 wxDir dir( pro_dir );
825
826 if( dir.IsOpened() ) // protected dirs will not open, see "man opendir()"
827 {
828 std::vector<wxString> projects = getProjects( dir );
829 wxString filename;
830 bool haveFile = dir.GetFirst( &filename );
831
832 while( haveFile )
833 {
834 if( filename != fn.GetFullName() )
835 {
836 wxString name = dir.GetName() + wxFileName::GetPathSeparator() + filename;
837
838 // Add items living in the project directory, and populate the item
839 // if it is a directory (sub directories will be not populated)
840 addItemToProjectTree( name, m_root, &projects, true );
841 }
842
843 haveFile = dir.GetNext( &filename );
844 }
845 }
846 }
847 else
848 {
849 m_TreeProject->AppendItem( m_root, wxT( "Empty project" ) );
850 }
851
852 m_TreeProject->Expand( m_root );
853
854 // Sort filenames by alphabetic order
855 m_TreeProject->SortChildren( m_root );
856
857 CallAfter(
858 [this] ()
859 {
860 wxLogTrace( traceGit, "PROJECT_TREE_PANE::ReCreateTreePrj: starting timers" );
861 m_gitSyncTimer.Start( 100, wxTIMER_ONE_SHOT );
862 m_gitStatusTimer.Start( 500, wxTIMER_ONE_SHOT );
863 } );
864}
865
866
867void PROJECT_TREE_PANE::onRight( wxTreeEvent& Event )
868{
869 wxTreeItemId curr_item = Event.GetItem();
870
871 // Ensure item is selected (Under Windows right click does not select the item)
872 m_TreeProject->SelectItem( curr_item );
873
874 // The tree control still uses the clicked item after this returns, so a menu command
875 // that closes the project must not run inside the click.
876 CallAfter(
877 [this]
878 {
880 } );
881}
882
883
885{
886 std::vector<PROJECT_TREE_ITEM*> selection = GetSelectedData();
887
888 bool can_switch_to_project = true;
889 bool can_create_new_directory = true;
890 bool can_open_this_directory = true;
891 bool can_edit = true;
892 bool can_rename = true;
893 bool can_delete = true;
894 bool run_jobs = false;
895
896 bool gitIntegrationDisabled = Prj().GetLocalSettings().m_GitIntegrationDisabled;
897 bool vcs_enabled = !gitIntegrationDisabled;
898 bool vcs_has_repo = gitRepo() != nullptr;
899 bool vcs_can_init = vcs_enabled && !vcs_has_repo;
900 bool vcs_can_set_remote = vcs_enabled && vcs_has_repo;
901 // Disable/Enable is a per-project preference toggle, so it's available whenever we
902 // detected a repository for this project or integration is currently disabled.
903 bool vcs_can_remove = vcs_has_repo || gitIntegrationDisabled;
904 bool vcs_can_switch = vcs_enabled && vcs_has_repo;
905 bool vcs_can_show_history = vcs_enabled && vcs_has_repo;
906 bool vcs_menu = Pgm().GetCommonSettings()->m_Git.enableGit;
907
908 // Check if the libgit2 library is available via backend
909 bool libgit_init = GetGitBackend() && GetGitBackend()->IsLibraryAvailable();
910
911 vcs_menu &= libgit_init;
912
913 if( selection.size() == 0 )
914 return;
915
916 // Remove things that don't make sense for multiple selections
917 if( selection.size() != 1 )
918 {
919 can_switch_to_project = false;
920 can_create_new_directory = false;
921 can_rename = false;
922 }
923
924 for( PROJECT_TREE_ITEM* item : selection )
925 {
926 // Check for empty project
927 if( !item )
928 {
929 can_switch_to_project = false;
930 can_edit = false;
931 can_rename = false;
932 continue;
933 }
934
935 can_delete = item->CanDelete();
936 can_rename = item->CanRename();
937
938 switch( item->GetType() )
939 {
942 can_rename = false;
943
944 if( item->GetId() == m_TreeProject->GetRootItem() )
945 {
946 can_switch_to_project = false;
947 }
948 else
949 {
950 can_create_new_directory = false;
951 can_open_this_directory = false;
952 }
953 break;
954
956 can_switch_to_project = false;
957 can_edit = false;
958 break;
959
962 can_edit = false;
963 can_switch_to_project = false;
964 can_create_new_directory = false;
965 can_open_this_directory = false;
966 break;
967
969 run_jobs = true;
970 can_edit = false;
972
976
977 default:
978 can_switch_to_project = false;
979 can_create_new_directory = false;
980 can_open_this_directory = false;
981
982 break;
983 }
984 }
985
986 wxMenu popup_menu;
987 wxString text;
988 wxString help_text;
989
990 if( can_switch_to_project )
991 {
992 KIUI::AddMenuItem( &popup_menu, ID_PROJECT_SWITCH_TO_OTHER, _( "Switch to this Project" ),
993 _( "Close all editors, and switch to the selected project" ),
995 popup_menu.AppendSeparator();
996 }
997
998 if( can_create_new_directory )
999 {
1000 KIUI::AddMenuItem( &popup_menu, ID_PROJECT_NEWDIR, _( "New Directory..." ),
1001 _( "Create a New Directory" ), KiBitmapBundle( BITMAPS::directory ) );
1002 }
1003
1004 if( can_open_this_directory )
1005 {
1006 if( selection.size() == 1 )
1007 {
1008#ifdef __APPLE__
1009 text = _( "Reveal in Finder" );
1010 help_text = _( "Reveals the directory in a Finder window" );
1011#else
1012 text = _( "Open Directory in File Explorer" );
1013 help_text = _( "Opens the directory in the default system file manager" );
1014#endif
1015 }
1016 else
1017 {
1018#ifdef __APPLE__
1019 text = _( "Reveal in Finder" );
1020 help_text = _( "Reveals the directories in a Finder window" );
1021#else
1022 text = _( "Open Directories in File Explorer" );
1023 help_text = _( "Opens the directories in the default system file manager" );
1024#endif
1025 }
1026
1027 KIUI::AddMenuItem( &popup_menu, ID_PROJECT_OPEN_DIR, text, help_text,
1029 }
1030
1031 if( can_edit )
1032 {
1033 if( selection.size() == 1 )
1034 help_text = _( "Open the file in a Text Editor" );
1035 else
1036 help_text = _( "Open files in a Text Editor" );
1037
1038 KIUI::AddMenuItem( &popup_menu, ID_PROJECT_TXTEDIT, _( "Edit in a Text Editor" ), help_text,
1040 }
1041
1042 if( run_jobs && selection.size() == 1 )
1043 {
1044 KIUI::AddMenuItem( &popup_menu, ID_JOBS_RUN, _( "Run Jobs" ), help_text,
1046 }
1047
1048 if( can_rename )
1049 {
1050 if( selection.size() == 1 )
1051 {
1052 text = _( "Rename File..." );
1053 help_text = _( "Rename file" );
1054 }
1055 else
1056 {
1057 text = _( "Rename Files..." );
1058 help_text = _( "Rename files" );
1059 }
1060
1061 KIUI::AddMenuItem( &popup_menu, ID_PROJECT_RENAME, text, help_text,
1063 }
1064
1065 if( can_delete )
1066 {
1067 if( selection.size() == 1 )
1068 help_text = _( "Delete the file and its content" );
1069 else
1070 help_text = _( "Delete the files and their contents" );
1071
1072 if( can_switch_to_project
1073 || can_create_new_directory
1074 || can_open_this_directory
1075 || can_edit
1076 || can_rename )
1077 {
1078 popup_menu.AppendSeparator();
1079 }
1080
1081#ifdef __WINDOWS__
1082 KIUI::AddMenuItem( &popup_menu, ID_PROJECT_DELETE, _( "Delete" ), help_text,
1084#else
1085 KIUI::AddMenuItem( &popup_menu, ID_PROJECT_DELETE, _( "Move to Trash" ), help_text,
1087#endif
1088 }
1089
1090 if( vcs_menu )
1091 {
1092 // Setting up the repository, its history, its branch and whether git is used at all
1093 // apply to the whole project, so they are offered on the project file and nowhere else.
1094 // Ignoring is the only thing here that acts on the item clicked.
1095 const bool repoWide =
1096 selection.size() == 1 && selection[0] && selection[0]->GetId() == m_TreeProject->GetRootItem();
1097 wxMenu* vcs_submenu = new wxMenu();
1098 wxMenuItem* vcs_menuitem = nullptr;
1099
1100 m_gitMenuBranches.clear();
1101
1102 if( repoWide )
1103 {
1104 vcs_menuitem = vcs_submenu->Append( ID_GIT_INITIALIZE_PROJECT, _( "Add Project to Version Control..." ),
1105 _( "Initialize a new repository" ) );
1106 vcs_menuitem->Enable( vcs_can_init );
1107
1108 vcs_menuitem = vcs_submenu->Append( ID_GIT_REMOTE_SETTINGS, _( "Configure Default Remote..." ),
1109 _( "Set or change the default remote URL and credentials" ) );
1110 vcs_menuitem->Enable( vcs_can_set_remote );
1111
1112 // Committing, pushing and pulling are done from the docked Version Control panel, so
1113 // the version-control submenu keeps only repository setup, history and branch operations.
1114 vcs_submenu->AppendSeparator();
1115
1116 vcs_menuitem = vcs_submenu->Append( ID_GIT_HISTORY, _( "Version History..." ),
1117 _( "Show the commits made to this project" ) );
1118 vcs_menuitem->Enable( vcs_can_show_history );
1119
1120 // Reading the branch list walks the repository. On contention the submenu is built
1121 // without the shortcuts rather than reading it concurrently.
1122 std::shared_ptr<KIGIT_COMMON> common = gitCommon();
1123 std::vector<KIGIT_BRANCH_INFO> branches;
1124
1125 m_gitMenuSession = common;
1126
1127 {
1128 std::unique_lock<std::mutex> branchLock = common->TryLockAction();
1129
1130 if( branchLock.owns_lock() )
1131 branches = common->GetBranches();
1132 }
1133
1135
1136 for( const KIGIT_BRANCH_INFO& branch : branches )
1137 {
1138 if( branch.isRemote || branch.isCurrent )
1139 continue;
1140
1141 m_gitMenuBranches.push_back( branch.name );
1142
1143 if( m_gitMenuBranches.size() == 5 )
1144 break;
1145 }
1146
1147 wxMenu* branch_submenu = new wxMenu();
1148
1149 for( size_t ii = 0; ii < m_gitMenuBranches.size(); ++ii )
1150 {
1151 wxString msg = _( "Switch to branch " ) + m_gitMenuBranches[ii];
1152 vcs_menuitem = branch_submenu->Append( ID_GIT_SWITCH_QUICK1 + ii, m_gitMenuBranches[ii], msg );
1153 vcs_menuitem->Enable( vcs_can_switch );
1154 }
1155
1156 vcs_menuitem = branch_submenu->Append( ID_GIT_SWITCH_BRANCH, _( "Other..." ),
1157 _( "Switch to a different branch" ) );
1158 vcs_menuitem->Enable( vcs_can_switch );
1159
1160 vcs_menuitem = vcs_submenu->Append( ID_GIT_SWITCH_BRANCH, _( "Switch to Branch" ), branch_submenu );
1161 vcs_menuitem->Enable( vcs_can_switch );
1162 }
1163
1164 bool ignore_usable = false;
1165 wxMenu* ignore_submenu = buildIgnoreSubmenu( selection, ignore_usable );
1166
1167 vcs_menuitem = vcs_submenu->AppendSubMenu( ignore_submenu, _( "Ignore" ) );
1168 vcs_menuitem->Enable( ignore_usable );
1169
1170 if( repoWide )
1171 {
1172 vcs_submenu->AppendSeparator();
1173
1174 if( gitIntegrationDisabled )
1175 {
1176 vcs_menuitem = vcs_submenu->Append( ID_GIT_REMOVE_VCS, _( "Enable Git Integration" ),
1177 _( "Re-enable Git integration for this project" ) );
1178 }
1179 else
1180 {
1181 vcs_menuitem = vcs_submenu->Append( ID_GIT_REMOVE_VCS, _( "Disable Git Integration" ),
1182 _( "Disable Git integration for this project" ) );
1183 }
1184
1185 vcs_menuitem->Enable( vcs_can_remove );
1186 }
1187
1188 popup_menu.AppendSeparator();
1189 popup_menu.AppendSubMenu( vcs_submenu, _( "Version Control" ) );
1190 }
1191
1192 if( popup_menu.GetMenuItemCount() > 0 )
1193 PopupMenu( &popup_menu );
1194}
1195
1196
1197void PROJECT_TREE_PANE::openInTextEditor( const std::vector<wxString>& aFileNames )
1198{
1199 wxString editorname = Pgm().GetTextEditor();
1200
1201 if( editorname.IsEmpty() )
1202 {
1203 wxMessageBox( _( "No text editor selected in KiCad. Please choose one." ) );
1204 return;
1205 }
1206
1207 for( const wxString& fullFileName : aFileNames )
1208 {
1209 if( !fullFileName.IsEmpty() )
1210 ExecuteFile( editorname, fullFileName.wc_str(), nullptr, false );
1211 }
1212}
1213
1214
1216{
1217 std::vector<wxString> fileNames;
1218
1219 for( PROJECT_TREE_ITEM* item_data : GetSelectedData() )
1220 fileNames.push_back( item_data->GetFileName() );
1221
1222 openInTextEditor( fileNames );
1223}
1224
1225
1226void PROJECT_TREE_PANE::onDeleteFile( wxCommandEvent& event )
1227{
1228 std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
1229
1230 for( PROJECT_TREE_ITEM* item_data : tree_data )
1231 item_data->Delete();
1232}
1233
1234
1235void PROJECT_TREE_PANE::onRenameFile( wxCommandEvent& event )
1236{
1237 wxTreeItemId curr_item = m_TreeProject->GetFocusedItem();
1238 std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
1239
1240 // XXX: Unnecessary?
1241 if( tree_data.size() != 1 )
1242 return;
1243
1244 wxString buffer = m_TreeProject->GetItemText( curr_item );
1245 wxString msg = wxString::Format( _( "Change filename: '%s'" ),
1246 tree_data[0]->GetFileName() );
1247 wxTextEntryDialog dlg( wxGetTopLevelParent( this ), msg, _( "Change filename" ), buffer );
1248
1249 if( dlg.ShowModal() != wxID_OK )
1250 return; // canceled by user
1251
1252 buffer = dlg.GetValue();
1253 buffer.Trim( true );
1254 buffer.Trim( false );
1255
1256 if( buffer.IsEmpty() )
1257 return; // empty file name not allowed
1258
1259 tree_data[0]->Rename( buffer, true );
1260 m_isRenaming = true;
1261}
1262
1263
1264void PROJECT_TREE_PANE::onSelect( wxTreeEvent& Event )
1265{
1266 std::vector<PROJECT_TREE_ITEM*> tree_data = GetSelectedData();
1267
1268 if( tree_data.size() != 1 )
1269 return;
1270
1271 // Bookmark the selected item but don't try and activate it until later. If we do it now,
1272 // there will be more events at least on Windows in this frame that will steal focus from
1273 // any newly launched windows
1274 m_selectedItem = tree_data[0];
1275}
1276
1277
1278void PROJECT_TREE_PANE::onIdle( wxIdleEvent& aEvent )
1279{
1280 // Idle executes once all other events finished processing. This makes it ideal to launch
1281 // a new window without starting Focus wars.
1282 if( m_watcherNeedReset )
1283 {
1284 m_selectedItem = nullptr;
1286 }
1287
1288 if( m_selectedItem != nullptr && m_TreeProject->GetRootItem().IsOk() )
1289 {
1290 // Make sure m_selectedItem still exists in the tree before activating it.
1291 std::vector<wxTreeItemId> validItemIds;
1292 m_TreeProject->GetItemsRecursively( m_TreeProject->GetRootItem(), validItemIds );
1293
1294 for( wxTreeItemId id : validItemIds )
1295 {
1296 if( GetItemIdData( id ) == m_selectedItem )
1297 {
1298 // Activate launches a window which may run the event loop on top of us and cause
1299 // onIdle to get called again, so be sure to null out m_selectedItem first.
1301 m_selectedItem = nullptr;
1302
1303 item->Activate( this );
1304 break;
1305 }
1306 }
1307 }
1308}
1309
1310
1311void PROJECT_TREE_PANE::onExpand( wxTreeEvent& Event )
1312{
1313 wxTreeItemId itemId = Event.GetItem();
1314 PROJECT_TREE_ITEM* tree_data = GetItemIdData( itemId );
1315
1316 if( !tree_data )
1317 return;
1318
1319 if( tree_data->GetType() != TREE_FILE_TYPE::DIRECTORY )
1320 return;
1321
1322 // explore list of non populated subdirs, and populate them
1323 wxTreeItemIdValue cookie;
1324 wxTreeItemId kid = m_TreeProject->GetFirstChild( itemId, cookie );
1325
1326#ifndef __WINDOWS__
1327 bool subdir_populated = false;
1328#endif
1329
1330 for( ; kid.IsOk(); kid = m_TreeProject->GetNextChild( itemId, cookie ) )
1331 {
1332 PROJECT_TREE_ITEM* itemData = GetItemIdData( kid );
1333
1334 if( !itemData || itemData->GetType() != TREE_FILE_TYPE::DIRECTORY )
1335 continue;
1336
1337 if( itemData->IsPopulated() )
1338 continue;
1339
1340 wxString fileName = itemData->GetFileName();
1341 wxDir dir( fileName );
1342
1343 if( dir.IsOpened() )
1344 {
1345 std::vector<wxString> projects = getProjects( dir );
1346 wxString dir_filename;
1347 bool haveFile = dir.GetFirst( &dir_filename );
1348
1349 while( haveFile )
1350 {
1351 // Add name to tree item, but do not recurse in subdirs:
1352 wxString name = fileName + wxFileName::GetPathSeparator() + dir_filename;
1353 addItemToProjectTree( name, kid, &projects, false );
1354
1355 haveFile = dir.GetNext( &dir_filename );
1356 }
1357
1358 itemData->SetPopulated( true ); // set state to populated
1359
1360#ifndef __WINDOWS__
1361 subdir_populated = true;
1362#endif
1363 }
1364
1365 // Sort filenames by alphabetic order
1366 m_TreeProject->SortChildren( kid );
1367 }
1368
1369#ifndef __WINDOWS__
1370 if( subdir_populated )
1371 m_watcherNeedReset = true;
1372#endif
1373}
1374
1375
1376std::vector<PROJECT_TREE_ITEM*> PROJECT_TREE_PANE::GetSelectedData()
1377{
1378 wxArrayTreeItemIds selection;
1379 std::vector<PROJECT_TREE_ITEM*> data;
1380
1381 m_TreeProject->GetSelections( selection );
1382
1383 for( const wxTreeItemId itemId : selection )
1384 {
1385 PROJECT_TREE_ITEM* item = GetItemIdData( itemId );
1386
1387 if( !item )
1388 {
1389 wxLogTrace( traceGit, wxS( "Null tree item returned for selection, dynamic_cast failed?" ) );
1390 continue;
1391 }
1392
1393 data.push_back( item );
1394 }
1395
1396 return data;
1397}
1398
1399
1401{
1402 return dynamic_cast<PROJECT_TREE_ITEM*>( m_TreeProject->GetItemData( aId ) );
1403}
1404
1405
1406wxTreeItemId PROJECT_TREE_PANE::findSubdirTreeItem( const wxString& aSubDir )
1407{
1408 wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
1409
1410 // If the subdir is the current working directory, return m_root
1411 // in main list:
1412 if( prj_dir == aSubDir )
1413 return m_root;
1414
1415 // The subdir is in the main tree or in a subdir: Locate it
1416 wxTreeItemIdValue cookie;
1417 wxTreeItemId root_id = m_root;
1418 std::stack<wxTreeItemId> subdirs_id;
1419
1420 wxTreeItemId child = m_TreeProject->GetFirstChild( root_id, cookie );
1421
1422 while( true )
1423 {
1424 if( ! child.IsOk() )
1425 {
1426 if( subdirs_id.empty() ) // all items were explored
1427 {
1428 root_id = child; // Not found: return an invalid wxTreeItemId
1429 break;
1430 }
1431 else
1432 {
1433 root_id = subdirs_id.top();
1434 subdirs_id.pop();
1435 child = m_TreeProject->GetFirstChild( root_id, cookie );
1436
1437 if( !child.IsOk() )
1438 continue;
1439 }
1440 }
1441
1442 PROJECT_TREE_ITEM* itemData = GetItemIdData( child );
1443
1444 if( itemData && ( itemData->GetType() == TREE_FILE_TYPE::DIRECTORY ) )
1445 {
1446 if( itemData->GetFileName() == aSubDir ) // Found!
1447 {
1448 root_id = child;
1449 break;
1450 }
1451
1452 // child is a subdir, push in list to explore it later
1453 if( itemData->IsPopulated() )
1454 subdirs_id.push( child );
1455 }
1456
1457 child = m_TreeProject->GetNextChild( root_id, cookie );
1458 }
1459
1460 return root_id;
1461}
1462
1463
1464void PROJECT_TREE_PANE::onFileSystemEvent( wxFileSystemWatcherEvent& event )
1465{
1466 // No need to process events when we're shutting down
1467 if( !m_watcher )
1468 return;
1469
1470 // Ignore events that are not file creation, deletion, renaming or modification because
1471 // they are not relevant to the project tree.
1472 if( !( event.GetChangeType() & ( wxFSW_EVENT_CREATE |
1473 wxFSW_EVENT_DELETE |
1474 wxFSW_EVENT_RENAME |
1475 wxFSW_EVENT_MODIFY ) ) )
1476 {
1477 return;
1478 }
1479
1480 const wxFileName& pathModified = event.GetPath();
1481
1482 // Ignore events from .history directory (local backup)
1483 if( pathModified.GetFullPath().Contains( wxS( ".history" ) ) )
1484 return;
1485
1486 wxString subdir = pathModified.GetPath();
1487 wxString fn = pathModified.GetFullPath();
1488
1489 // Adjust directories to look like a file item (path and name).
1490 if( pathModified.GetFullName().IsEmpty() )
1491 {
1492 subdir = subdir.BeforeLast( '/' );
1493 fn = fn.BeforeLast( '/' );
1494 }
1495
1496 wxTreeItemId root_id = findSubdirTreeItem( subdir );
1497
1498 if( !root_id.IsOk() )
1499 return;
1500
1501 CallAfter( [this] ()
1502 {
1503 wxLogTrace( traceGit, wxS( "File system event detected, updating tree cache" ) );
1504 m_gitStatusTimer.Start( 1500, wxTIMER_ONE_SHOT );
1505 } );
1506
1507 wxTreeItemIdValue cookie; // dummy variable needed by GetFirstChild()
1508 wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
1509
1510 switch( event.GetChangeType() )
1511 {
1512 case wxFSW_EVENT_CREATE:
1513 {
1514 wxTreeItemId newitem = addItemToProjectTree( fn, root_id, nullptr, true );
1515
1516 // If we are in the process of renaming a file, select the new one
1517 // This is needed for MSW and OSX, since we don't get RENAME events from them, just a
1518 // pair of DELETE and CREATE events.
1519 if( m_isRenaming && newitem.IsOk() )
1520 {
1521 m_TreeProject->SelectItem( newitem );
1522 m_isRenaming = false;
1523 }
1524 }
1525 break;
1526
1527 case wxFSW_EVENT_DELETE:
1528 while( kid.IsOk() )
1529 {
1530 PROJECT_TREE_ITEM* itemData = GetItemIdData( kid );
1531
1532 if( itemData && itemData->GetFileName() == fn )
1533 {
1534 m_TreeProject->Delete( kid );
1535 return;
1536 }
1537 kid = m_TreeProject->GetNextChild( root_id, cookie );
1538 }
1539 break;
1540
1541 case wxFSW_EVENT_RENAME :
1542 {
1543 const wxFileName& newpath = event.GetNewPath();
1544 wxString newdir = newpath.GetPath();
1545 wxString newfn = newpath.GetFullPath();
1546
1547 while( kid.IsOk() )
1548 {
1549 PROJECT_TREE_ITEM* itemData = GetItemIdData( kid );
1550
1551 if( itemData && itemData->GetFileName() == fn )
1552 {
1553 m_TreeProject->Delete( kid );
1554 break;
1555 }
1556
1557 kid = m_TreeProject->GetNextChild( root_id, cookie );
1558 }
1559
1560 // Add the new item only if it is not the current project file (root item).
1561 // Remember: this code is called by a wxFileSystemWatcherEvent event, and not always
1562 // called after an actual file rename, and the cleanup code does not explore the
1563 // root item, because it cannot be renamed by the user. Also, ensure the new file
1564 // actually exists on the file system before it is readded. On Linux, moving a file
1565 // to the trash can cause the same path to be returned in both the old and new paths
1566 // of the event, even though the file isn't there anymore.
1567 PROJECT_TREE_ITEM* rootData = GetItemIdData( root_id );
1568
1569 if( rootData && newpath.Exists() && ( newfn != rootData->GetFileName() ) )
1570 {
1571 wxTreeItemId newroot_id = findSubdirTreeItem( newdir );
1572 wxTreeItemId newitem = addItemToProjectTree( newfn, newroot_id, nullptr, true );
1573
1574 // If the item exists, select it
1575 if( newitem.IsOk() )
1576 m_TreeProject->SelectItem( newitem );
1577 }
1578
1579 m_isRenaming = false;
1580 }
1581 break;
1582
1583 default:
1584 return;
1585 }
1586
1587 // Sort filenames by alphabetic order
1588 m_TreeProject->SortChildren( root_id );
1589}
1590
1591
1593{
1594 m_watcherNeedReset = false;
1595
1596 wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
1597
1598#if defined( _WIN32 )
1599 if( KIPLATFORM::ENV::IsNetworkPath( prj_dir ) )
1600 {
1601 // Due to a combination of a bug in SAMBA sending bad change event IDs and wxWidgets
1602 // choosing to fault on an invalid event ID instead of sanely ignoring them we need to
1603 // avoid spawning a filewatcher. Unfortunately this punishes corporate environments with
1604 // Windows Server shares :/
1605 m_Parent->m_FileWatcherInfo = _( "Network path: not monitoring folder changes" );
1606 m_Parent->SetStatusText( m_Parent->m_FileWatcherInfo, 1 );
1607 return;
1608 }
1609 else
1610 {
1611 m_Parent->m_FileWatcherInfo = _( "Local path: monitoring folder changes" );
1612 m_Parent->SetStatusText( m_Parent->m_FileWatcherInfo, 1 );
1613 }
1614#endif
1615
1616 // Prepare file watcher:
1617 if( m_watcher )
1618 {
1619 m_watcher->RemoveAll();
1620 }
1621 else
1622 {
1623 // Create a wxWidgets log handler to catch errors during watcher creation
1624 // We need to to this because we cannot get error codes from the wxFileSystemWatcher
1625 // constructor. On Linux, if inotify cannot be initialized (usually due to resource limits),
1626 // wxWidgets will throw a system error and then, we throw another error below, trying to
1627 // add paths to a null watcher. We skip this by installing a temporary log handler that
1628 // catches errors during watcher creation and aborts if any error is detected.
1629 class WatcherLogHandler : public wxLog
1630 {
1631 public:
1632 explicit WatcherLogHandler( bool* err ) :
1633 m_err( err )
1634 {
1635 if( m_err )
1636 *m_err = false;
1637 }
1638
1639 protected:
1640 void DoLogTextAtLevel( wxLogLevel level, const wxString& text ) override
1641 {
1642 if( m_err && ( level == wxLOG_Error || level == wxLOG_FatalError ) )
1643 *m_err = true;
1644 }
1645
1646 private:
1647 bool* m_err;
1648 };
1649
1650 bool watcherHasError = false;
1651 WatcherLogHandler tmpLog( &watcherHasError );
1652
1653 {
1654 SCOPED_WXLOG_TARGET logOverride( &tmpLog );
1655
1657 m_watcher->SetOwner( this );
1658 }
1659
1660 if( watcherHasError )
1661 {
1662 return;
1663 }
1664 }
1665
1666 // We can see wxString under a debugger, not a wxFileName
1667 wxFileName fn;
1668 fn.AssignDir( prj_dir );
1669 fn.DontFollowLink();
1670
1671 // Add directories which should be monitored.
1672 // under windows, we add the curr dir and all subdirs
1673 // under unix, we add only the curr dir and the populated subdirs
1674 // see http://docs.wxwidgets.org/trunk/classwx_file_system_watcher.htm
1675 // under unix, the file watcher needs more work to be efficient
1676 // moreover, under wxWidgets 2.9.4, AddTree does not work properly.
1677 {
1678 wxLogNull logNo; // avoid log messages
1679#ifdef __WINDOWS__
1680 if( ! m_watcher->AddTree( fn ) )
1681 {
1682 wxLogTrace( tracePathsAndFiles, "%s: failed to add '%s'\n", __func__,
1683 TO_UTF8( fn.GetFullPath() ) );
1684 return;
1685 }
1686 }
1687#else
1688 if( !m_watcher->Add( fn ) )
1689 {
1690 wxLogTrace( tracePathsAndFiles, "%s: failed to add '%s'\n", __func__,
1691 TO_UTF8( fn.GetFullPath() ) );
1692 return;
1693 }
1694 }
1695
1696 if( m_TreeProject->IsEmpty() )
1697 return;
1698
1699 // Add subdirs
1700 wxTreeItemIdValue cookie;
1701 wxTreeItemId root_id = m_root;
1702
1703 std::stack < wxTreeItemId > subdirs_id;
1704
1705 wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
1706 int total_watch_count = 0;
1707
1708 while( total_watch_count < ADVANCED_CFG::GetCfg().m_MaxFilesystemWatchers )
1709 {
1710 if( !kid.IsOk() )
1711 {
1712 if( subdirs_id.empty() ) // all items were explored
1713 {
1714 break;
1715 }
1716 else
1717 {
1718 root_id = subdirs_id.top();
1719 subdirs_id.pop();
1720 kid = m_TreeProject->GetFirstChild( root_id, cookie );
1721
1722 if( !kid.IsOk() )
1723 continue;
1724 }
1725 }
1726
1727 PROJECT_TREE_ITEM* itemData = GetItemIdData( kid );
1728
1729 if( itemData && itemData->GetType() == TREE_FILE_TYPE::DIRECTORY )
1730 {
1731 // we can see wxString under a debugger, not a wxFileName
1732 const wxString& path = itemData->GetFileName();
1733
1734 // Skip .history directory and its descendants (local backup)
1735 if( path.Contains( wxS( ".history" ) ) )
1736 {
1737 kid = m_TreeProject->GetNextChild( root_id, cookie );
1738 continue;
1739 }
1740
1741 wxLogTrace( tracePathsAndFiles, "%s: add '%s'\n", __func__, TO_UTF8( path ) );
1742
1743 if( wxFileName::IsDirReadable( path ) ) // linux whines about watching protected dir
1744 {
1745 {
1746 // Silence OS errors that come from the watcher
1747 wxLogNull silence;
1748 fn.AssignDir( path );
1749 m_watcher->Add( fn );
1750 total_watch_count++;
1751 }
1752
1753 // if kid is a subdir, push in list to explore it later
1754 if( itemData->IsPopulated() && m_TreeProject->GetChildrenCount( kid ) )
1755 subdirs_id.push( kid );
1756 }
1757 }
1758
1759 kid = m_TreeProject->GetNextChild( root_id, cookie );
1760 }
1761
1762 if( total_watch_count >= ADVANCED_CFG::GetCfg().m_MaxFilesystemWatchers )
1763 wxLogTrace( tracePathsAndFiles, "%s: too many directories to watch\n", __func__ );
1764#endif
1765
1766#if defined(DEBUG) && 1
1767 wxArrayString paths;
1768 m_watcher->GetWatchedPaths( &paths );
1769 wxLogTrace( tracePathsAndFiles, "%s: watched paths:", __func__ );
1770
1771 for( unsigned ii = 0; ii < paths.GetCount(); ii++ )
1772 wxLogTrace( tracePathsAndFiles, " %s\n", TO_UTF8( paths[ii] ) );
1773#endif
1774 }
1775
1776
1778{
1779 m_branchQuery->Cancel();
1780 m_gitMenuBranches.clear();
1781 m_gitMenuIgnoreTargets.clear();
1782 m_gitMenuSession.reset();
1784
1785 // Make sure we don't try to inspect the tree after we've deleted its items.
1787
1788 m_TreeProject->DeleteAllItems();
1789}
1790
1791
1793{
1794 m_branchQuery->Cancel();
1795
1796 if( gitRepo() )
1797 {
1798 std::shared_ptr<KIGIT_COMMON> common = gitCommon();
1799 common->SetShuttingDown( true );
1800
1801 std::unique_lock<std::mutex> lock = common->TryLockAction();
1802
1803 constexpr auto kGraceMs = std::chrono::seconds( 2 );
1804 auto graceEnd = std::chrono::steady_clock::now() + kGraceMs;
1805
1806 while( !lock.owns_lock() && std::chrono::steady_clock::now() < graceEnd )
1807 {
1808 if( lock.try_lock() )
1809 break;
1810 std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) );
1811 }
1812
1813 constexpr auto kCheckInterval = std::chrono::seconds( 30 );
1814 bool userAbandoned = false;
1815
1816 while( !lock.owns_lock() && !userAbandoned )
1817 {
1818 auto intervalEnd = std::chrono::steady_clock::now() + kCheckInterval;
1819
1820 {
1821 wxProgressDialog progress( _( "Please wait" ),
1822 _( "Closing project..." ),
1823 100, this,
1824 wxPD_APP_MODAL | wxPD_SMOOTH );
1825
1826 while( !lock.try_lock()
1827 && std::chrono::steady_clock::now() < intervalEnd )
1828 {
1829 progress.Pulse();
1830 std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
1831 wxYield();
1832 }
1833 }
1834
1835 if( lock.owns_lock() )
1836 break;
1837
1838 wxMessageDialog ask( this,
1839 _( "A Git operation is still running.\n"
1840 "Keep waiting, or abandon?" ),
1841 _( "Git Operation Delayed" ),
1842 wxYES_NO | wxICON_QUESTION );
1843 ask.SetYesNoLabels( _( "Keep Waiting" ), _( "Abandon" ) );
1844
1845 if( ask.ShowModal() == wxID_NO )
1846 userAbandoned = true;
1847 }
1848
1849 if( userAbandoned )
1850 {
1851 // Cancellation was requested above, so a running fetch exits at its next
1852 // callback. The release defers the actual free to the orphan registry.
1853 common.reset();
1855 }
1856 else
1857 {
1858 git_repository* repo = common->GetRepo();
1860 common->SetRepo( nullptr );
1861 }
1862 }
1863}
1864
1865
1867{
1868 m_branchQuery->Cancel();
1869 m_gitMenuBranches.clear();
1870 m_gitMenuIgnoreTargets.clear();
1871 m_gitMenuSession.reset();
1873}
1874
1875
1876std::shared_ptr<KIGIT_COMMON> PROJECT_TREE_PANE::gitCommon() const
1877{
1878 return Prj().GetGitCommon();
1879}
1880
1881
1883{
1884 std::shared_ptr<KIGIT_COMMON> common = gitCommon();
1885
1886 if( m_gitListenerSession.lock() == common )
1887 return;
1888
1889 m_branchQuery->Cancel();
1890 m_gitMenuBranches.clear();
1891 m_gitMenuIgnoreTargets.clear();
1892 m_gitMenuSession.reset();
1894
1895 if( std::shared_ptr<KIGIT_COMMON> previous = m_gitListenerSession.lock() )
1896 previous->RemoveRefreshListener( this );
1897
1898 // The status timer coalesces several notifications into one pass, and reads the repository
1899 // locally without fetching.
1900 common->AddRefreshListener( this,
1901 [this]()
1902 {
1903 if( m_TreeProject )
1904 m_gitStatusTimer.Start( 500, wxTIMER_ONE_SHOT );
1905 } );
1906
1907 m_gitListenerSession = common;
1908}
1909
1910
1912{
1913 return gitCommon()->GetRepo();
1914}
1915
1916
1917void PROJECT_TREE_PANE::onThemeChanged( wxSysColourChangedEvent &aEvent )
1918{
1919 m_TreeProject->LoadIcons();
1920 m_TreeProject->Refresh();
1921
1922 aEvent.Skip();
1923}
1924
1925
1926void PROJECT_TREE_PANE::onPaint( wxPaintEvent& event )
1927{
1928 wxRect rect( wxPoint( 0, 0 ), GetClientSize() );
1929 wxPaintDC dc( this );
1930
1931 dc.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_FRAMEBK ) );
1932 dc.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_ACTIVEBORDER ), 1 ) );
1933
1934 dc.DrawLine( rect.GetLeft(), rect.GetTop(), rect.GetLeft(), rect.GetBottom() );
1935 dc.DrawLine( rect.GetRight(), rect.GetTop(), rect.GetRight(), rect.GetBottom() );
1936}
1937
1938
1939void KICAD_MANAGER_FRAME::OnChangeWatchedPaths( wxCommandEvent& aEvent )
1940{
1941 m_projectTreePane->FileWatcherReset();
1942}
1943
1944
1945// Prompts for git credentials after an auth failure. Returns false if cancelled.
1946static bool promptForGitCredentials( wxWindow* aParent, KIGIT_COMMON* aCommon, const wxString& aExplanation )
1947{
1948 return KIGIT::PromptForCredentials( aParent, aCommon, &Prj(), aExplanation ) == KIGIT::PROMPT_ANSWER::ACCEPTED;
1949}
1950
1951
1952// Persist a remote configuration the user accepted, to the secret store and the project
1953// local settings. Runs only after the remote itself was set up successfully.
1954static void saveAcceptedRemoteSettings( PROJECT& aProject, const RemoteConfig& aConfig )
1955{
1956 // Keyed like the attach-time lookup, which never sees credentials embedded in the address. Async so an
1957 // unlock prompt cannot hold the event loop
1959 aConfig.password );
1960 aProject.GetLocalSettings().m_GitRepoUsername = aConfig.username;
1961 aProject.GetLocalSettings().m_GitSSHKey = aConfig.sshKey;
1962
1964 aProject.GetLocalSettings().m_GitRepoType = "ssh";
1966 aProject.GetLocalSettings().m_GitRepoType = "https";
1967 else
1968 aProject.GetLocalSettings().m_GitRepoType = "local";
1969}
1970
1971
1972void PROJECT_TREE_PANE::onGitInitializeProject( wxCommandEvent& aEvent )
1973{
1974 PROJECT_TREE_ITEM* tree_data = GetItemIdData( m_TreeProject->GetRootItem() );
1975
1976 wxString dir = tree_data->GetDir();
1977
1978 if( dir.empty() )
1979 {
1980 wxLogError( "Failed to initialize git project: project directory is empty." );
1981 return;
1982 }
1983
1984 GIT_INIT_HANDLER initHandler( gitCommon().get() );
1985 wxWindow* topLevelParent = wxGetTopLevelParent( this );
1986
1987 if( initHandler.IsRepository( dir ) )
1988 {
1989 DisplayInfoMessage( topLevelParent,
1990 _( "The selected directory is already a Git project." ) );
1991 return;
1992 }
1993
1994 InitResult result = initHandler.InitializeRepository( dir );
1996 {
1997 KIGIT_ERROR_MESSAGE error = initHandler.PopError();
1998 DisplayErrorMessage( m_parent, error.summary, error.details );
1999 return;
2000 }
2001
2003
2004 gitCommon()->SetShuttingDown( false );
2005
2006 const char* canonicalWorkDir = git_repository_workdir( initHandler.GetRepo() );
2007
2008 if( canonicalWorkDir )
2009 {
2011 dir, wxString::FromUTF8( canonicalWorkDir ) );
2012 gitCommon()->SetProjectDir( symlinkWorkDir );
2013 }
2014
2015 DIALOG_GIT_REPOSITORY dlg( topLevelParent, initHandler.GetRepo() );
2016 dlg.SetTitle( _( "Set default remote" ) );
2017 dlg.SetSkipButtonLabel( _( "Skip" ) );
2018
2019 if( dlg.ShowModal() != wxID_OK )
2020 return;
2021
2022 // Set up the remote
2023 RemoteConfig remoteConfig;
2024 remoteConfig.url = dlg.GetRepoURL();
2025 remoteConfig.username = dlg.GetUsername();
2026 remoteConfig.password = dlg.GetPassword();
2027 remoteConfig.sshKey = dlg.GetRepoSSHPath();
2028 remoteConfig.connType = dlg.GetRepoType();
2029
2030 if( !initHandler.SetupRemote( remoteConfig ) )
2031 {
2032 KIGIT_ERROR_MESSAGE error = initHandler.PopError();
2033 DisplayErrorMessage( m_parent, error.summary, error.details );
2034 return;
2035 }
2036
2038
2039 // Before the fetch, so a corrected login from the prompt below is the one that stays saved
2040 saveAcceptedRemoteSettings( Prj(), remoteConfig );
2041
2042 KIGIT_COMMON* common = gitCommon().get();
2043 bool retriedAfterTrust = false;
2044
2045 while( true )
2046 {
2047 GIT_PULL_HANDLER handler( common );
2048 handler.SetProgressReporter(
2049 std::make_unique<WX_PROGRESS_REPORTER>( this, _( "Fetch Remote" ), 1, PR_NO_ABORT ) );
2050
2051 // A status read can hold the lock briefly, and the login or key just confirmed must not be dropped
2053
2054 if( handler.PerformFetch() )
2055 break;
2056
2057 if( std::optional<KIGIT::HOST_KEY_FAILURE> hostKey = handler.GetHostKeyFailure() )
2058 {
2059 if( KIGIT::PromptToTrustHost( m_parent, *hostKey, retriedAfterTrust ) != KIGIT::PROMPT_ANSWER::ACCEPTED )
2060 break;
2061
2062 retriedAfterTrust = true;
2063 continue;
2064 }
2065
2066 KIGIT_ERROR_MESSAGE error = handler.PopError();
2067
2068 if( handler.WasAuthFailure() )
2069 {
2070 if( promptForGitCredentials( m_parent, common, error.summary ) )
2071 continue;
2072
2073 break;
2074 }
2075
2076 // The remote is saved either way, so this only says why its first fetch did not happen. A cancelled
2077 // fetch needs no dialog
2078 if( !error.summary.IsEmpty() && handler.GetFailureKind() != KIGIT_FAILURE::CANCELLED )
2079 DisplayErrorMessage( m_parent, error.summary, error.details );
2080
2081 break;
2082 }
2083}
2084
2085
2086void PROJECT_TREE_PANE::onGitHistory( wxCommandEvent& aEvent )
2087{
2088 m_Parent->ShowGitHistory();
2089}
2090
2091
2092void PROJECT_TREE_PANE::onGitRemoteSettings( wxCommandEvent& aEvent )
2093{
2094 KIGIT_COMMON* common = gitCommon().get();
2095 git_repository* repo = common ? common->GetRepo() : nullptr;
2096
2097 if( !repo )
2098 return;
2099
2100 wxString existingURL;
2101
2102 {
2103 // Read the remote under the lock, then release it before opening the dialog.
2104 std::unique_lock<std::mutex> lock = KIGIT::TryLockAction( *common, this );
2105
2106 if( !lock.owns_lock() )
2107 return;
2108
2109 git_remote* remote = nullptr;
2110
2111 if( git_remote_lookup( &remote, repo, "origin" ) == GIT_OK )
2112 {
2113 KIGIT::GitRemotePtr remotePtr( remote );
2114
2115 if( const char* url = git_remote_url( remote ) )
2116 existingURL = wxString::FromUTF8( url );
2117 }
2118 }
2119
2120 // Credentials are stored separately from the remote URL.
2121 KIGIT_COMMON credentials( nullptr );
2122 credentials.SetUsername( common->GetUsername() );
2123 credentials.SetRemote( existingURL );
2124
2125 if( credentials.SecretRead() )
2126 {
2127 showGitRemoteSettings( existingURL, credentials.GetUsername(), credentials.GetPassword() );
2128 return;
2129 }
2130
2131 wxWeakRef<PROJECT_TREE_PANE> self( this );
2132 std::shared_ptr<KIGIT_COMMON> session = gitCommon();
2133 wxString username = credentials.GetUsername();
2134
2135 // Saving the dialog stores its password, so a locked keyring must unlock rather than read as empty
2137 credentials.GetRemote(), username,
2138 [self, session, existingURL, username]( bool aFound, const wxString& aSecret )
2139 {
2140 if( !self || self->gitCommon() != session || session->IsShuttingDown() || !session->GetRepo() )
2141 return;
2142
2143 self->showGitRemoteSettings( existingURL, username, aFound ? aSecret : wxString() );
2144 } );
2145}
2146
2147
2148void PROJECT_TREE_PANE::showGitRemoteSettings( const wxString& aExistingURL, const wxString& aUsername,
2149 const wxString& aPassword )
2150{
2151 KIGIT_COMMON* common = gitCommon().get();
2152 git_repository* repo = common ? common->GetRepo() : nullptr;
2153
2154 if( !repo )
2155 return;
2156
2157 wxWindow* topLevelParent = wxGetTopLevelParent( this );
2158 DIALOG_GIT_REPOSITORY dlg( topLevelParent, repo, aExistingURL );
2159 dlg.SetTitle( _( "Configure Default Remote" ) );
2160 dlg.SetUsername( aUsername );
2161 dlg.SetPassword( aPassword );
2162 dlg.SetRepoSSHPath( Prj().GetLocalSettings().m_GitSSHKey );
2163
2164 if( dlg.ShowModal() != wxID_OK )
2165 return;
2166
2167 GIT_INIT_HANDLER initHandler( common );
2168
2169 RemoteConfig remoteConfig;
2170 remoteConfig.url = dlg.GetRepoURL();
2171 remoteConfig.username = dlg.GetUsername();
2172 remoteConfig.password = dlg.GetPassword();
2173 remoteConfig.sshKey = dlg.GetRepoSSHPath();
2174 remoteConfig.connType = dlg.GetRepoType();
2175
2176 bool setupOk = false;
2177 wxString setupError;
2178 wxString setupDetails;
2179
2180 {
2181 // Update the remote config and cached branch info under the same lock.
2182 std::unique_lock<std::mutex> lock = KIGIT::WaitForActionLock( *common, this );
2183
2184 if( !lock.owns_lock() )
2185 return;
2186
2187 setupOk = initHandler.SetupRemote( remoteConfig );
2188 KIGIT_ERROR_MESSAGE error = initHandler.PopError();
2189 setupError = error.summary;
2190 setupDetails = error.details;
2191
2192 if( setupOk )
2193 common->UpdateCurrentBranchInfo();
2194 }
2195
2196 if( !setupOk )
2197 {
2198 DisplayErrorMessage( topLevelParent, setupError, setupDetails );
2199 return;
2200 }
2201
2202 saveAcceptedRemoteSettings( Prj(), remoteConfig );
2203
2204 m_gitStatusTimer.Start( 500, wxTIMER_ONE_SHOT );
2205}
2206
2207
2208void PROJECT_TREE_PANE::onGitSwitchBranch( wxCommandEvent& aEvent )
2209{
2210 std::shared_ptr<KIGIT_COMMON> common = gitCommon();
2211
2212 if( !common->GetRepo() || common->IsShuttingDown() )
2213 return;
2214
2215 if( aEvent.GetId() == ID_GIT_SWITCH_BRANCH )
2216 {
2217 struct BRANCHES
2218 {
2219 std::vector<KIGIT_BRANCH_INFO> entries;
2220 bool loaded = false;
2221 };
2222
2223 auto branches = std::make_shared<BRANCHES>();
2224 wxWeakRef<PROJECT_TREE_PANE> self( this );
2225
2226 m_branchQuery->Run(
2227 common,
2228 [branches]( KIGIT_COMMON& aCommon )
2229 {
2230 branches->entries = aCommon.GetBranches();
2231 branches->loaded = true;
2232 },
2233 [self, common, branches]()
2234 {
2235 if( !branches->loaded || !self || self->IsBeingDeleted() || self->m_Parent->IsBeingDeleted()
2236 || common->IsShuttingDown() || self->gitCommon() != common
2237 || !Pgm().GetCommonSettings()->m_Git.enableGit
2238 || Prj().GetLocalSettings().m_GitIntegrationDisabled )
2239 {
2240 return;
2241 }
2242
2243 DIALOG_GIT_SWITCH dlg( wxGetTopLevelParent( self->m_Parent ), std::move( branches->entries ) );
2244 int retval = dlg.ShowModal();
2245
2246 if( !self || self->IsBeingDeleted() || common->IsShuttingDown() || self->gitCommon() != common )
2247 return;
2248
2249 if( retval == wxID_OK || retval == wxID_ADD )
2250 self->switchGitBranch( common, dlg.GetBranchName(), retval == wxID_ADD );
2251 } );
2252
2253 return;
2254 }
2255
2256 int branchIndex = aEvent.GetId() - ID_GIT_SWITCH_QUICK1;
2257
2258 if( m_gitMenuSession.lock() != common || branchIndex < 0
2259 || static_cast<size_t>( branchIndex ) >= m_gitMenuBranches.size() )
2260 {
2261 return;
2262 }
2263
2264 switchGitBranch( common, m_gitMenuBranches[branchIndex], false );
2265}
2266
2267
2268void PROJECT_TREE_PANE::switchGitBranch( std::shared_ptr<KIGIT_COMMON> aCommon, const wxString& aBranchName,
2269 bool aCreate )
2270{
2271 if( IsBeingDeleted() || m_Parent->IsBeingDeleted() || gitCommon() != aCommon || aCommon->IsShuttingDown()
2272 || !Pgm().GetCommonSettings()->m_Git.enableGit || Prj().GetLocalSettings().m_GitIntegrationDisabled )
2273 {
2274 return;
2275 }
2276
2277 if( !aCreate )
2278 {
2279 SwitchProjectToBranch( m_Parent, this, aBranchName, *m_branchQuery );
2280 return;
2281 }
2282
2283 if( wxString nameError = KIGIT::BranchNameError( aBranchName ); !nameError.IsEmpty() )
2284 {
2285 DisplayErrorMessage( this, nameError );
2286 return;
2287 }
2288
2289 // Keep Add subject to the same worktree checks before creating the branch. The shared
2290 // switch helper then owns confirmation, editor checks, checkout, and reload.
2291 auto createBranch = [this, aCommon, aBranchName]( const GIT_WORKTREE_STATUS& )
2292 {
2293 if( IsBeingDeleted() || m_Parent->IsBeingDeleted() || gitCommon() != aCommon || aCommon->IsShuttingDown()
2294 || !Pgm().GetCommonSettings()->m_Git.enableGit || Prj().GetLocalSettings().m_GitIntegrationDisabled )
2295 {
2296 return;
2297 }
2298
2299 int result;
2300 wxString error;
2301
2302 {
2303 std::unique_lock<std::mutex> lock = KIGIT::WaitForActionLock( *aCommon, this );
2304
2305 if( !lock.owns_lock() )
2306 return;
2307
2308 result = KIGIT::PROJECT_GIT_UTILS::CreateBranch( aCommon->GetRepo(), aBranchName );
2310 }
2311
2312 if( result != GIT_OK )
2313 {
2314 DisplayErrorMessage( this, _( "Could not create the branch." ), error );
2315 return;
2316 }
2317
2318 SwitchProjectToBranch( m_Parent, this, aBranchName, *m_branchQuery );
2319 aCommon->NotifyRefreshListeners();
2320 };
2321
2322 ProjectClearOfUncommittedWork( m_Parent, this, *m_branchQuery, std::move( createBranch ) );
2323}
2324
2325
2326wxMenu* PROJECT_TREE_PANE::buildIgnoreSubmenu( const std::vector<PROJECT_TREE_ITEM*>& aSelection, bool& aUsable )
2327{
2328 wxMenu* submenu = new wxMenu();
2329 std::shared_ptr<KIGIT_COMMON> common = gitCommon();
2330 IGNORE_SELECTION ignore;
2331
2332 m_gitMenuIgnoreTargets.clear();
2333
2334 if( !Prj().GetLocalSettings().m_GitIntegrationDisabled && common->GetRepo() )
2335 {
2336 // Reading the state walks the index, so a busy repository leaves the submenu disabled.
2337 std::unique_lock<std::mutex> lock = common->TryLockAction();
2338
2339 if( lock.owns_lock() )
2340 ignore = gitIgnoreSelection( *common, Prj().GetProjectPath(), aSelection );
2341 }
2342
2343 m_gitMenuIgnoreTargets = ignore.targets;
2344
2345 const bool single = ignore.targets.size() == 1;
2346 const bool folder = single && ignore.targets.front().isDirectory;
2347
2348 auto append = [submenu]( int aId, const wxString& aLabel, const wxString& aHelp, bool aEnabled )
2349 {
2350 submenu->Append( aId, aLabel, aHelp )->Enable( aEnabled );
2351 };
2352
2353 if( ignore.ignored )
2354 {
2355 // Only a rule in the project's own ignore file can be taken out of it.
2356 append( ID_GIT_KEEP_PATH,
2357 folder ? _( "Stop Ignoring This Folder" )
2358 : single ? _( "Stop Ignoring This File" )
2359 : _( "Stop Ignoring Selected Items" ),
2360 _( "Take the rule naming these out of the project's ignored files" ), ignore.canKeepPath );
2361
2362 if( ignore.canKeepExtension )
2363 {
2364 append( ID_GIT_KEEP_EXTENSION,
2365 wxString::Format( _( "Stop Ignoring All '%s' Files" ), ignore.extensionRule ),
2366 _( "Take that rule out of the project's ignored files" ), true );
2367 }
2368 }
2369 else
2370 {
2371 append( ID_GIT_IGNORE_PATH,
2372 folder ? _( "Ignore This Folder" )
2373 : single ? _( "Ignore This File" )
2374 : _( "Ignore Selected Items" ),
2375 _( "Leave these out of version control" ), ignore.canIgnore );
2376
2377 if( !ignore.extensionRule.IsEmpty() )
2378 {
2379 append( ID_GIT_IGNORE_EXTENSION, wxString::Format( _( "Ignore All '%s' Files" ), ignore.extensionRule ),
2380 _( "Leave every file with this extension out of version control" ), ignore.canIgnore );
2381 }
2382 }
2383
2384 // A pattern matching nothing on disk has no item to right-click, so the file stays reachable.
2385 const bool haveIgnoreFile = KIGIT::ProjectIgnoreFile( Prj().GetProjectPath() ).FileExists();
2386
2387 submenu->AppendSeparator();
2388 append( ID_GIT_EDIT_IGNORE_FILE, _( "Edit Ignore File..." ),
2389 _( "Open the project's ignored files in a text editor" ), haveIgnoreFile );
2390
2391 aUsable = ignore.canIgnore || ignore.canKeepPath || ignore.canKeepExtension || haveIgnoreFile;
2392
2393 return submenu;
2394}
2395
2396
2397void PROJECT_TREE_PANE::onGitIgnore( wxCommandEvent& aEvent )
2398{
2399 GIT_IGNORE_CHANGE change;
2400
2401 switch( aEvent.GetId() )
2402 {
2405 case ID_GIT_KEEP_PATH: change = GIT_IGNORE_CHANGE::KEEP_PATH; break;
2407 default: return;
2408 }
2409
2411}
2412
2413
2414void PROJECT_TREE_PANE::onGitEditIgnoreFile( wxCommandEvent& aEvent )
2415{
2416 openInTextEditor( { KIGIT::ProjectIgnoreFile( Prj().GetProjectPath() ).GetFullPath() } );
2417}
2418
2419
2420void PROJECT_TREE_PANE::onGitRemoveVCS( wxCommandEvent& aEvent )
2421{
2422 PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
2423
2424 // Toggle the Git integration disabled preference
2425 localSettings.m_GitIntegrationDisabled = !localSettings.m_GitIntegrationDisabled;
2426
2427 wxLogTrace( traceGit, wxS( "onGitRemoveVCS: Git integration %s" ),
2428 localSettings.m_GitIntegrationDisabled ? wxS( "disabled" ) : wxS( "enabled" ) );
2429
2430 if( localSettings.m_GitIntegrationDisabled )
2431 {
2432 // Disabling Git integration - release the repo and clear item states
2434 m_gitIconsInitialized = false;
2435
2436 // Clear all item states to remove git status icons
2437 std::stack<wxTreeItemId> items;
2438 items.push( m_TreeProject->GetRootItem() );
2439
2440 while( !items.empty() )
2441 {
2442 wxTreeItemId current = items.top();
2443 items.pop();
2444
2445 m_TreeProject->SetItemState( current, wxTREE_ITEMSTATE_NONE );
2446
2447 wxTreeItemIdValue cookie;
2448 wxTreeItemId child = m_TreeProject->GetFirstChild( current, cookie );
2449
2450 while( child.IsOk() )
2451 {
2452 items.push( child );
2453 child = m_TreeProject->GetNextChild( current, cookie );
2454 }
2455 }
2456 }
2457 else
2458 {
2459 // Re-enabling Git integration - try to find and connect to the repository
2461 }
2462
2463 // Save the preference to the project local settings file
2464 localSettings.SaveToFile( Prj().GetProjectPath() );
2465}
2466
2467
2469{
2470 wxLogTrace( traceGit, wxS( "updateGitStatusIcons: Updating git status icons" ) );
2471 std::unique_lock<std::mutex> lock( m_gitStatusMutex, std::try_to_lock );
2472
2473 if( !lock.owns_lock() )
2474 {
2475 wxLogTrace( traceGit, wxS( "updateGitStatusIcons: Failed to acquire lock for git status icon update" ) );
2476 m_gitStatusTimer.Start( 500, wxTIMER_ONE_SHOT );
2477 return;
2478 }
2479
2480 if( !Pgm().GetCommonSettings()->m_Git.enableGit || !m_TreeProject )
2481 {
2482 wxLogTrace( traceGit, wxS( "updateGitStatusIcons: Git is disabled or tree control is null" ) );
2483 return;
2484 }
2485
2486 const wxColour normal = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
2487 const wxColour dimmed = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
2488
2489 // Git reports an ignored folder on its own, so the flag travels down to its contents.
2490 std::stack<std::pair<wxTreeItemId, bool>> items;
2491 items.push( { m_TreeProject->GetRootItem(), false } );
2492
2493 while( !items.empty() )
2494 {
2495 auto [current, parentIgnored] = items.top();
2496 items.pop();
2497
2498 if( current.IsOk() && m_TreeProject->ItemHasChildren( current ) )
2499 {
2500 wxTreeItemIdValue cookie;
2501 wxTreeItemId child = m_TreeProject->GetFirstChild( current, cookie );
2502
2503 while( child.IsOk() )
2504 {
2505 auto it = m_gitStatusIcons.find( child );
2506 const bool known = it != m_gitStatusIcons.end();
2507 const bool ignored =
2508 parentIgnored || ( known && it->second == KIGIT_COMMON::GIT_STATUS::GIT_STATUS_IGNORED );
2509
2510 items.push( { child, ignored } );
2511
2512 const int state = known && !ignored ? static_cast<int>( it->second ) : wxTREE_ITEMSTATE_NONE;
2513 const wxColour colour = ignored ? dimmed : normal;
2514
2515 // Setting either repaints the row, so only a change is worth writing.
2516 if( m_TreeProject->GetItemState( child ) != state )
2517 m_TreeProject->SetItemState( child, state );
2518
2519 if( m_TreeProject->GetItemTextColour( child ) != colour )
2520 m_TreeProject->SetItemTextColour( child, colour );
2521
2522 child = m_TreeProject->GetNextChild( current, cookie );
2523 }
2524 }
2525 }
2526
2527 if( !m_gitCurrentBranchName.empty() )
2528 {
2529 wxTreeItemId kid = m_TreeProject->GetRootItem();
2530 PROJECT_TREE_ITEM* rootItem = kid.IsOk() ? GetItemIdData( kid ) : nullptr;
2531
2532 if( rootItem )
2533 {
2534 wxString filename = wxFileNameFromPath( rootItem->GetFileName() );
2535 m_TreeProject->SetItemText( kid, filename + " [" + m_gitCurrentBranchName + "]" );
2536 }
2537 }
2538
2539 // Set even without a branch name, or each pass on an unborn HEAD notifies the panels and their
2540 // refresh restarts the status timer
2541 m_gitIconsInitialized = true;
2542
2543 wxLogTrace( traceGit, wxS( "updateGitStatusIcons: Git status icons updated" ) );
2544}
2545
2546
2548{
2549 wxLogTrace( traceGit, wxS( "updateTreeCache: Updating tree cache" ) );
2550
2551 std::unique_lock<std::mutex> lock( m_gitTreeCacheMutex, std::try_to_lock );
2552
2553 if( !lock.owns_lock() )
2554 {
2555 wxLogTrace( traceGit, wxS( "updateTreeCache: Failed to acquire lock for tree cache update" ) );
2556 return;
2557 }
2558
2559 if( !m_TreeProject )
2560 {
2561 wxLogTrace( traceGit, wxS( "updateTreeCache: Tree control is null" ) );
2562 return;
2563 }
2564
2565 wxTreeItemId kid = m_TreeProject->GetRootItem();
2566
2567 if( !kid.IsOk() )
2568 return;
2569
2570 // Collect a map to easily set the state of each item
2571 m_gitTreeCache.clear();
2572 std::stack<wxTreeItemId> items;
2573 items.push( kid );
2574
2575 while( !items.empty() )
2576 {
2577 kid = items.top();
2578 items.pop();
2579
2580 PROJECT_TREE_ITEM* nextItem = GetItemIdData( kid );
2581
2582 if( !nextItem )
2583 continue;
2584
2585 wxString gitAbsPath = nextItem->GetFileName();
2586#ifdef _WIN32
2587 gitAbsPath.Replace( wxS( "\\" ), wxS( "/" ) );
2588#endif
2589 m_gitTreeCache[gitAbsPath] = kid;
2590
2591 wxTreeItemIdValue cookie;
2592 wxTreeItemId child = m_TreeProject->GetFirstChild( kid, cookie );
2593
2594 while( child.IsOk() )
2595 {
2596 items.push( child );
2597 child = m_TreeProject->GetNextChild( kid, cookie );
2598 }
2599 }
2600}
2601
2602
2603void PROJECT_TREE_PANE::updateGitStatusIconMap( std::shared_ptr<KIGIT_COMMON> aGitCommon,
2604 const wxString& aProjectFullName )
2605{
2606 wxLogTrace( traceGit, wxS( "updateGitStatusIconMap: Updating git status icons" ) );
2607#if defined( _WIN32 )
2609
2610 if( refresh != 0 && KIPLATFORM::ENV::IsNetworkPath( wxPathOnly( aProjectFullName ) ) )
2611 {
2612 // Need to treat windows network paths special here until we get the samba bug fixed
2613 // https://github.com/wxWidgets/wxWidgets/issues/18953
2614 CallAfter(
2615 [this, refresh]()
2616 {
2617 m_gitStatusTimer.Start( refresh, wxTIMER_ONE_SHOT );
2618 } );
2619 }
2620
2621#endif
2622
2623 if( !Pgm().GetCommonSettings()->m_Git.enableGit || !m_TreeProject )
2624 return;
2625
2626 std::unique_lock<std::mutex> lock1( m_gitStatusMutex, std::try_to_lock );
2627 std::unique_lock<std::mutex> lock2( m_gitTreeCacheMutex, std::try_to_lock );
2628
2629 if( !lock1.owns_lock() || !lock2.owns_lock() )
2630 {
2631 wxLogTrace( traceGit, wxS( "updateGitStatusIconMap: Failed to acquire locks for git status icon update" ) );
2632 return;
2633 }
2634
2635 // The caller pinned the session on the UI thread, so a concurrent release cannot
2636 // free it under us.
2637 if( !aGitCommon || !aGitCommon->GetRepo() )
2638 {
2639 wxLogTrace( traceGit, wxS( "updateGitStatusIconMap: No git repository found" ) );
2640 return;
2641 }
2642
2643 // Acquire the git action mutex to synchronize with EmptyTreePrj() shutdown.
2644 // This ensures the repository isn't freed while we're using it.
2645 std::unique_lock<std::mutex> gitLock = aGitCommon->TryLockAction();
2646
2647 if( !gitLock.owns_lock() )
2648 {
2649 wxLogTrace( traceGit, wxS( "updateGitStatusIconMap: Failed to acquire git action mutex" ) );
2650 return;
2651 }
2652
2653 // Check if cancellation was requested (e.g., during shutdown)
2654 if( aGitCommon->IsShuttingDown() )
2655 {
2656 wxLogTrace( traceGit, wxS( "updateGitStatusIconMap: Cancelled" ) );
2657 return;
2658 }
2659
2660 GIT_STATUS_HANDLER statusHandler( aGitCommon.get() );
2661
2662 // Set up pathspec for project files. The name is passed in from the UI thread
2663 // because Prj() must not be read here, the project can be unloaded concurrently.
2664 wxFileName rootFilename( aProjectFullName );
2665 wxString repoWorkDir = statusHandler.GetWorkingDirectory();
2666
2667 wxFileName relative = rootFilename;
2668 relative.MakeRelativeTo( repoWorkDir );
2669 wxString pathspecStr = relative.GetPath( wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR );
2670
2671#ifdef _WIN32
2672 pathspecStr.Replace( wxS( "\\" ), wxS( "/" ) );
2673#endif
2674
2675 // Get file status
2676 auto fileStatusMap = statusHandler.GetFileStatus( pathspecStr );
2677 auto [localChanges, remoteChanges] = aGitCommon->GetDifferentFiles();
2678 statusHandler.UpdateRemoteStatus( localChanges, remoteChanges, fileStatusMap );
2679
2680 std::map<wxString, unsigned int> currentStatus;
2681
2682 for( const auto& [absPath, fileStatus] : fileStatusMap )
2683 currentStatus.emplace( absPath, fileStatus.gitStatus );
2684
2685 // A file deleted outside KiCad loses its tree item, so no icon changes to say so
2686 bool updated = currentStatus != m_gitLastStatus;
2687 m_gitLastStatus = std::move( currentStatus );
2688
2689 // Rebuilt rather than added to, so an item git has stopped reporting on loses its badge.
2690 std::map<wxTreeItemId, KIGIT_COMMON::GIT_STATUS> icons;
2691
2692 for( const auto& [absPath, fileStatus] : fileStatusMap )
2693 {
2694 auto iter = m_gitTreeCache.find( absPath );
2695
2696 if( iter == m_gitTreeCache.end() )
2697 {
2698 wxLogTrace( traceGit, wxS( "File '%s' not found in tree cache" ), absPath );
2699 continue;
2700 }
2701
2702 icons[iter->second] = fileStatus.status;
2703 }
2704
2705 if( icons != m_gitStatusIcons )
2706 updated = true;
2707
2708 m_gitStatusIcons = std::move( icons );
2709
2710 // Get the current branch name
2711 wxString branchName = statusHandler.GetCurrentBranchName();
2712
2713 if( branchName != m_gitCurrentBranchName )
2714 updated = true;
2715
2716 m_gitCurrentBranchName = branchName;
2717
2718 wxLogTrace( traceGit, wxS( "updateGitStatusIconMap: Updated git status icons" ) );
2719
2720 // Update UI if icons changed
2721 if( updated || !m_gitIconsInitialized )
2722 {
2723 CallAfter(
2724 [this, aGitCommon]()
2725 {
2727
2728 // The docked panels read the same status, so they are stale until they
2729 // are told. Without this a file edited outside KiCad shows as changed in
2730 // the tree while the panel still says there is nothing to commit.
2731 aGitCommon->NotifyRefreshListeners();
2732 } );
2733 }
2734}
2735
2736
2737void PROJECT_TREE_PANE::onRunSelectedJobsFile( wxCommandEvent& event )
2738{
2739}
2740
2741
2742void PROJECT_TREE_PANE::onGitSyncTimer( wxTimerEvent& aEvent )
2743{
2744 wxLogTrace( traceGit, "onGitSyncTimer" );
2745 COMMON_SETTINGS::GIT& gitSettings = Pgm().GetCommonSettings()->m_Git;
2746
2747 if( !gitSettings.enableGit || gitSettings.updatInterval <= 0 || !m_TreeProject )
2748 return;
2749
2750 // Skip the tick rather than stack a second fetch. Assigning over a running std::async
2751 // future blocks in its destructor, here on the UI thread.
2753 {
2754 wxLogTrace( traceGit, "onGitSyncTimer: previous fetch still running, skipping" );
2755 m_gitSyncTimer.Start( gitSettings.updatInterval * 60 * 1000, wxTIMER_ONE_SHOT );
2756 return;
2757 }
2758
2759 // Pin the session on the UI thread, so a concurrent release cannot free it while
2760 // PerformFetch() is inside it.
2761 std::shared_ptr<KIGIT_COMMON> common = gitCommon();
2762
2763 // Never the shared compute pool. A libgit2 network read parked there stalls DRC, zone
2764 // filling and library loading.
2765 m_gitSyncTask = std::async( std::launch::async,
2766 [this, common]()
2767 {
2768 if( !common->GetRepo() )
2769 {
2770 wxLogTrace( traceGit, "onGitSyncTimer: No git repository found" );
2771 return;
2772 }
2773
2774 // Check if cancellation was requested (e.g., during shutdown)
2775 if( common->IsShuttingDown() )
2776 {
2777 wxLogTrace( traceGit, "onGitSyncTimer: Cancelled" );
2778 return;
2779 }
2780
2781 GIT_PULL_HANDLER handler( common.get() );
2782 bool fetched = handler.PerformFetch();
2783 std::optional<KIGIT_FAILURE> kind = handler.GetFailureKind();
2784 wxString summary = handler.PopError().summary;
2785
2786 // Only schedule the follow-up work if not cancelled
2787 if( !common->IsShuttingDown() )
2788 CallAfter(
2789 [this, common, fetched, kind, summary]()
2790 {
2791 // The project may have closed or changed while queued
2792 if( common->IsShuttingDown() || common != gitCommon() )
2793 return;
2794
2795 reportGitSyncResult( fetched, kind, summary );
2797
2798 // The panels show whether the remote is ahead, and the fetch
2799 // just moved the remote refs.
2800 common->NotifyRefreshListeners();
2801 } );
2802 } );
2803
2804 wxLogTrace( traceGit, "onGitSyncTimer: Restarting git sync timer" );
2805 // We store the timer interval in minutes but wxTimer uses milliseconds
2806 m_gitSyncTimer.Start( gitSettings.updatInterval * 60 * 1000, wxTIMER_ONE_SHOT );
2807}
2808
2809
2810void PROJECT_TREE_PANE::reportGitSyncResult( bool aFetched, std::optional<KIGIT_FAILURE> aKind,
2811 const wxString& aSummary )
2812{
2813 KISTATUSBAR* statusBar = dynamic_cast<KISTATUSBAR*>( m_Parent->GetStatusBar() );
2814
2815 if( aFetched )
2816 {
2818 return;
2819 }
2820
2821 // A busy repository or a closing project is not something to warn about
2822 if( !statusBar || !aKind || *aKind == KIGIT_FAILURE::CANCELLED )
2823 return;
2824
2825 // The timer fires every few minutes, and the same failure each time would bury every other warning. The list
2826 // itself is the record, so anything that clears it lets the next failure show again
2827 std::map<wxString, std::vector<KI_ERROR>> shown = statusBar->GetWarningMessages();
2828
2829 for( const KI_ERROR& existing : shown[KIGIT::SYNC_WARNING_SOURCE] )
2830 {
2831 if( existing.GetTitle() == aSummary )
2832 return;
2833 }
2834
2835 KI_ERROR warning;
2836 warning.SetTitle( aSummary );
2838 statusBar->AddWarningMessages( KIGIT::SYNC_WARNING_SOURCE, { warning } );
2839}
2840
2841
2843{
2844 if( !m_TreeProject )
2845 return;
2846
2847 // Pin the session on the UI thread, so a concurrent release cannot free it while
2848 // the status worker is using it.
2849 std::shared_ptr<KIGIT_COMMON> common = gitCommon();
2850
2851 if( common->IsShuttingDown() )
2852 return;
2853
2854 // See onGitSyncTimer: overwriting a still-running task's future abandons a task that holds
2855 // a raw pointer to this pane, and the destructor would no longer wait for it.
2857 return;
2858
2861
2862 wxString projectFullName = Prj().GetProjectFullName();
2863
2864 m_gitStatusIconTask = tp.submit_task(
2865 [this, common, projectFullName]()
2866 {
2867 updateGitStatusIconMap( common, projectFullName );
2868 } );
2869}
2870
2871void PROJECT_TREE_PANE::onGitStatusTimer( wxTimerEvent& aEvent )
2872{
2873 wxLogTrace( traceGit, "onGitStatusTimer" );
2874
2875 if( !Pgm().GetCommonSettings()->m_Git.enableGit || !m_TreeProject )
2876 return;
2877
2879}
const char * name
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
@ directory_browser
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void SetRepoSSHPath(const wxString &aPath)
KIGIT_COMMON::GIT_CONN_TYPE GetRepoType() const
void SetPassword(const wxString &aPassword)
wxString GetRepoSSHPath() const
The private key, also when its .pub was picked.
void SetUsername(const wxString &aUsername)
void SetSkipButtonLabel(const wxString &aLabel)
wxString GetBranchName() const
int ShowModal() override
virtual bool IsLibraryAvailable()=0
bool IsRepository(const wxString &aPath)
Check if a directory is already a git repository.
InitResult InitializeRepository(const wxString &aPath)
Initialize a new git repository in the specified directory.
bool SetupRemote(const RemoteConfig &aConfig)
Set up a remote for the repository.
void SetProgressReporter(std::unique_ptr< PROGRESS_REPORTER > aProgressReporter)
bool PerformFetch(bool aSkipLock=false)
std::map< wxString, FileStatus > GetFileStatus(const wxString &aPathspec=wxEmptyString, bool aChangedOnly=false)
Get detailed file status for all files in the specified path.
wxString GetCurrentBranchName()
Get the current branch name.
void UpdateRemoteStatus(const std::set< wxString > &aLocalChanges, const std::set< wxString > &aRemoteChanges, std::map< wxString, FileStatus > &aFileStatus)
Get status for modified files based on local/remote changes.
wxString GetWorkingDirectory()
Get the repository working directory path.
The main KiCad project manager frame.
void OnChangeWatchedPaths(wxCommandEvent &aEvent)
Called by sending a event with id = ID_INIT_WATCHED_PATHS rebuild the list of watched paths.
PROJECT_TREE_PANE * m_projectTreePane
static wxString ComputeSymlinkPreservingWorkDir(const wxString &aUserProjectPath, const wxString &aCanonicalWorkDir)
Compute a working directory path that preserves symlinks from the user's project path.
static bool RemoveVCS(git_repository *&aRepo, const wxString &aProjectPath=wxEmptyString, bool aRemoveGitDir=false, wxString *aErrors=nullptr)
Remove version control from a directory by freeing the repository and optionally removing the ....
static int CreateBranch(git_repository *aRepo, const wxString &aBranchName)
Create a new branch based on HEAD.
The project's git session.
wxString GetRemote() const
void SetUsername(const wxString &aUsername)
git_repository * GetRepo() const
void SetProjectDir(const wxString &aProjectDir)
Keep symlinks in the repository path so Git status paths match the project tree.
static constexpr std::chrono::milliseconds ACTION_LOCK_WAIT
Long enough for a status read to finish, short enough that a window does not look hung.
wxString GetUsername() const
void SetShuttingDown(bool aCancel)
Stop the operation running now and keep later ones from starting.
static wxString GetLastGitError()
libgit2's last message, without credentials from any URL it quotes, so it is safe to show or trace.
static REMOTE_URL ParseRemoteURL(const wxString &aURL)
wxString GetPassword()
The secret for the remote, read without ever prompting, so it is safe on a transfer worker.
std::vector< KIGIT_BRANCH_INFO > GetBranches() const
Local and remote branches with their tip commits.
void SetRemote(const wxString &aRemote)
bool SecretRead() const
False while the keyring has not been read for the current remote.
KIGIT_ERROR_MESSAGE PopError()
Take the newest error with its details. Both are empty when none is queued.
Read repository state without blocking the UI.
std::optional< KIGIT::HOST_KEY_FAILURE > GetHostKeyFailure() const
The host key this operation's transfer refused, for the UI to offer to trust or to report.
git_repository * GetRepo() const
Get a pointer to the git repository.
void SetActionLockWait(std::chrono::milliseconds aWait)
A UI caller retrying confirmed input waits this long for a background read instead of failing at once...
std::optional< KIGIT_FAILURE > GetFailureKind() const
The kind of the last failure ReportTransferFailure classified, or none.
bool WasAuthFailure() const
Set when the server refused every credential offered, so the caller can prompt and retry.
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
Definition kistatusbar.h:50
void AddWarningMessages(const wxString &aSource, const wxString &aMessages)
Add warning/error messages (not thread-safe, use the std::vector<KI_ERROR> variant from other threads...
std::map< wxString, std::vector< KI_ERROR > > GetWarningMessages() const
Get a copy of all stored warning/error messages, grouped by source and sorted by source name for stab...
Holds a structured error message.
Definition ki_error.h:38
KI_ERROR & SetSeverity(SEVERITY aSeverity)
Definition ki_error.h:76
KI_ERROR & SetTitle(const wxString &aTitle)
Definition ki_error.h:58
static wxString GetDefaultUserProjectsPath()
Gets the default path we point users to create projects.
Definition paths.cpp:137
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:600
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
Definition pgm_base.cpp:250
The project local settings are things that are attached to a particular project, but also might be pa...
bool m_GitIntegrationDisabled
If true, KiCad will not use Git integration for this project even if a .git directory exists.
bool SaveToFile(const wxString &aDirectory="", bool aForce=false) override
Calls Store() and then writes the contents of the JSON document to a file.
Handle one item (a file or a directory name) for the tree file.
void SetRootFile(bool aValue)
void SetState(int state)
const wxString & GetFileName() const
bool IsPopulated() const
void SetPopulated(bool aValue)
TREE_FILE_TYPE GetType() const
const wxString GetDir() const
void Activate(PROJECT_TREE_PANE *aTreePrjFrame)
Window to display the tree files.
PROJECT_TREE_ITEM * m_selectedItem
void switchGitBranch(std::shared_ptr< KIGIT_COMMON > aCommon, const wxString &aBranchName, bool aCreate)
void syncGitListener()
Follow the project's git session with a refresh listener, so operations started from the version cont...
std::unordered_map< wxString, wxTreeItemId > m_gitTreeCache
void onGitIgnore(wxCommandEvent &event)
Add the selected files to, or take them out of, the project's ignored files.
std::map< wxTreeItemId, KIGIT_COMMON::GIT_STATUS > m_gitStatusIcons
void onGitInitializeProject(wxCommandEvent &event)
Initialize a new git repository in the current project directory.
void showGitRemoteSettings(const wxString &aExistingURL, const wxString &aUsername, const wxString &aPassword)
void openInTextEditor(const std::vector< wxString > &aFileNames)
Open files in the user's text editor, or explain that none is chosen.
git_repository * gitRepo() const
void onDeleteFile(wxCommandEvent &event)
Delete the selected file or directory in the tree project.
void onGitRemoveVCS(wxCommandEvent &event)
Remove the git repository from the current project directory.
void EmptyTreePrj()
Delete all m_TreeProject entries.
void FileWatcherReset()
Reinit the watched paths Should be called after opening a new project to rebuild the list of watched ...
std::vector< PROJECT_TREE_ITEM * > GetSelectedData()
Return the item data from item currently selected (highlighted)
void onOpenDirectory(wxCommandEvent &event)
Handles the right-click menu for opening a directory in the current system file browser.
void onFileSystemEvent(wxFileSystemWatcherEvent &event)
called when a file or directory is modified/created/deleted The tree project is modified when a file ...
std::vector< GIT_IGNORE_TARGET > m_gitMenuIgnoreTargets
wxFileSystemWatcher * m_watcher
void WaitForGitOperations()
Give a running background git operation a chance to finish, asking the user to keep waiting or abando...
void onRight(wxTreeEvent &Event)
Called on a right click on an item.
void onSelect(wxTreeEvent &Event)
Called on a double click on an item.
PROJECT_TREE * m_TreeProject
PROJECT_TREE_PANE(KICAD_MANAGER_FRAME *parent)
std::weak_ptr< KIGIT_COMMON > m_gitMenuSession
KICAD_MANAGER_FRAME * m_Parent
std::future< void > m_gitSyncTask
void onExpand(wxTreeEvent &Event)
Called on a click on the + or - button of an item with children.
std::weak_ptr< KIGIT_COMMON > m_gitListenerSession
std::map< wxString, unsigned int > m_gitLastStatus
Raw status of every file in the last pass, so a change with no tree item still reaches the panels.
std::vector< wxString > m_gitMenuBranches
Preserve the shortcut targets while the context menu runs its event loop.
void onGitSyncTimer(wxTimerEvent &event)
void onGitHistory(wxCommandEvent &event)
Open the advanced Git window on its History page.
void onIdle(wxIdleEvent &aEvent)
Idle event handler, used process the selected items at a point in time when all other events have bee...
void updateTreeCache()
Updates the map of the wxtreeitemid to the name of each file for use in the thread.
static wxString GetFileExt(TREE_FILE_TYPE type)
friend class PROJECT_TREE_ITEM
wxTreeItemId findSubdirTreeItem(const wxString &aSubDir)
Search for the item in tree project which is the node of the subdirectory aSubDir.
void onGitEditIgnoreFile(wxCommandEvent &event)
Open the project's ignore file, for rules the menu items cannot reach.
void ReCreateTreePrj()
Create or modify the tree showing project file names.
void onThemeChanged(wxSysColourChangedEvent &aEvent)
void onRunSelectedJobsFile(wxCommandEvent &event)
Run a selected jobs file.
void onGitStatusTimer(wxTimerEvent &event)
void shutdownFileWatcher()
Shutdown the file watcher.
std::mutex m_gitTreeCacheMutex
std::shared_ptr< KIGIT_COMMON > gitCommon() const
The current project's git session, created empty on first use.
void updateGitStatusIconMap(std::shared_ptr< KIGIT_COMMON > aGitCommon, const wxString &aProjectFullName)
This is a threaded call that will change the map of git status icons for use in the main thread.
wxTreeItemId addItemToProjectTree(const wxString &aName, const wxTreeItemId &aParent, std::vector< wxString > *aProjectNames, bool aRecurse)
Add the file or directory aName to the project tree.
void onGitRemoteSettings(wxCommandEvent &event)
Configure (or change) the default remote on an already-initialized repository.
void onOpenSelectedFileWithTextEditor(wxCommandEvent &event)
Call the text editor to open the selected file in the tree project.
void updateGitStatusIcons()
Updates the icons shown in the tree project to reflect the current git status.
std::future< void > m_gitStatusIconTask
PROJECT_TREE_ITEM * GetItemIdData(wxTreeItemId aId)
Return the item data corresponding to a wxTreeItemId identifier.
std::unique_ptr< KIGIT_QUERY > m_branchQuery
Owns the branch-switch preflight and suppresses callbacks when the project closes.
void reportGitSyncResult(bool aFetched, std::optional< KIGIT_FAILURE > aKind, const wxString &aSummary)
Background fetches have no window to answer, so each failure goes to the status bar's warnings once,...
void onGitSwitchBranch(wxCommandEvent &event)
Switch to a different branch in the git repository.
void onCreateNewDirectory(wxCommandEvent &event)
Creates a new subdirectory inside the current kicad project directory the user is prompted to enter a...
void onSwitchToSelectedProject(wxCommandEvent &event)
Switch to a other project selected from the tree project (by selecting an other .pro file inside the ...
void onPaint(wxPaintEvent &aEvent)
We don't have uniform borders so we have to draw them ourselves.
void onRenameFile(wxCommandEvent &event)
Rename the selected file or directory in the tree project.
void releaseGitRepo()
Releases the git repository handle, deferring the free to the orphan registry while a background git ...
wxMenu * buildIgnoreSubmenu(const std::vector< PROJECT_TREE_ITEM * > &aSelection, bool &aUsable)
Build the Ignore submenu for a selection, and remember what its items apply to.
std::vector< wxString > m_filters
PROJECT_TREE This is the class to show (as a tree) the files in the project directory.
Container for project specific data.
Definition project.h:63
virtual std::shared_ptr< KIGIT_COMMON > GetGitCommon() const
This project's Git session, created empty on first use.
Definition project.cpp:85
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition project.cpp:271
virtual bool AttachGitRepository()
Find the Git repository containing the project directory and bind it to the session.
Definition project.cpp:94
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition project.h:207
virtual void ReleaseGitCommon()
Safely release the session's repository handle and drop the session.
Definition project.cpp:166
A scoped application of a wxLog target.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition confirm.cpp:245
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
This file is part of the common library.
#define _(s)
wxDECLARE_EVENT(wxEVT_REFRESH_CUSTOM_COMMAND, wxCommandEvent)
EVT_MENU_RANGE(ID_GERBVIEW_DRILL_FILE1, ID_GERBVIEW_DRILL_FILEMAX, GERBVIEW_FRAME::OnDrlFileHistory) EVT_MENU_RANGE(ID_GERBVIEW_ZIP_FILE1
int ExecuteFile(const wxString &aEditorName, const wxString &aFileName, wxProcess *aCallback, bool aFileForKicad)
Call the executable file aEditorName with the parameter aFileName.
Definition gestfich.cpp:170
GIT_BACKEND * GetGitBackend()
InitResult
void ChangeGitIgnore(EDA_BASE_FRAME *aFrame, wxWindow *aParent, GIT_IGNORE_CHANGE aChange, const std::vector< GIT_IGNORE_TARGET > &aTargets)
Write a change to the project's ignored files and refresh every Git surface.
void ProjectClearOfUncommittedWork(EDA_BASE_FRAME *aFrame, wxWindow *aParent, KIGIT_QUERY &aQuery, std::function< void(const GIT_WORKTREE_STATUS &)> aReady)
Check the working tree and Git LFS on a worker, then run aReady on the UI thread when the operation c...
void SwitchProjectToBranch(EDA_BASE_FRAME *aFrame, wxWindow *aParent, const wxString &aBranch, KIGIT_QUERY &aQuery, std::function< void()> aFinished)
Check the working tree on a worker, then confirm switching to aBranch and recheck unsaved editors.
GIT_IGNORE_CHANGE
Which change to the project's ignored files a menu item asks for.
@ IGNORE_PATH
Ignore the paths themselves.
@ KEEP_EXTENSION
Stop ignoring every file sharing the paths' extension.
@ KEEP_PATH
Stop ignoring the paths themselves.
@ IGNORE_EXTENSION
Ignore every file sharing the paths' extension.
int m_GitIconRefreshInterval
The interval in milliseconds to refresh the git icons in the project tree.
static const std::string LegacySchematicFileExtension
static const std::string HtmlFileExtension
static const wxString GerberFileExtensionsRegex
static const std::string NetlistFileExtension
static const std::string GerberJobFileExtension
static const std::string ReportFileExtension
static const std::string ProjectFileExtension
static const std::string FootprintPlaceFileExtension
static const std::string LegacyPcbFileExtension
static const std::string LegacyProjectFileExtension
static const std::string KiCadSchematicFileExtension
static const std::string LegacySymbolLibFileExtension
static const std::string CsvFileExtension
static const std::string KiCadSymbolLibFileExtension
static const std::string SpiceFileExtension
static const std::string PdfFileExtension
static const std::string TextFileExtension
static const std::string DrawingSheetFileExtension
static const std::string KiCadJobSetFileExtension
static const std::string FootprintAssignmentFileExtension
static const std::string SVGFileExtension
static const std::string DrillFileExtension
static const std::string DesignRulesFileExtension
static const std::string MarkdownFileExtension
static const std::string KiCadFootprintFileExtension
static const std::string ArchiveFileExtension
static const std::string KiCadPcbFileExtension
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
const wxChar *const traceGit
Flag to enable Git debugging output.
PROJECT & Prj()
Definition kicad.cpp:730
@ ID_PROJECT_TREE
Definition kicad_id.h:32
@ ID_LEFT_FRAME
Definition kicad_id.h:31
EVT_MENU(ID_COMPARE_PROJECT_BRANCHES, KICAD_MANAGER_FRAME::OnCompareProjectBranches) KICAD_MANAGER_FRAME
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition macros.h:79
void ClearSyncWarnings(wxWindow *aWindow)
Clear the background fetch's warnings from the frame holding aWindow.
void SortBranchesForDisplay(std::vector< KIGIT_BRANCH_INFO > &aBranches)
Put the current branch first, then local and remote branches with the newest tips first.
wxString BranchNameError(const wxString &aName)
Empty when aName is a branch name git would accept, otherwise why it would not, in the words to show ...
constexpr const wxChar * SYNC_WARNING_SOURCE
The status bar source under which background fetch failures are listed.
APIEXPORT wxFileName ProjectIgnoreFile(const wxString &aProjectPath)
The ignore file that covers a project.
std::unique_lock< std::mutex > WaitForActionLock(KIGIT_COMMON &aCommon, wxWindow *aParent)
TryLockAction that first waits a moment for a status read or fetch to let go.
APIEXPORT wxString ExtensionIgnoreRule(const wxString &aProjectRelPath)
The rule that ignores every file sharing a path's extension, or nothing when it has none.
PROMPT_ANSWER PromptForCredentials(wxWindow *aParent, KIGIT_COMMON *aCommon, PROJECT *aProject=nullptr, const wxString &aExplanation=wxEmptyString)
Ask the user for the credentials of the session's remote and apply them to the session.
std::unique_lock< std::mutex > TryLockAction(KIGIT_COMMON &aCommon, wxWindow *aParent)
Try the action lock and show a busy message if it is unavailable.
APIEXPORT IGNORE_STATE IgnoreState(KIGIT_COMMON &aCommon, const wxString &aProjectRelPath, bool aIsDirectory)
What git's rules and its index say about a project path, so the user is offered only what would take ...
PROMPT_ANSWER PromptToTrustHost(wxWindow *aParent, const HOST_KEY_FAILURE &aFailure, bool aRetriedAfterTrust)
Ask whether to trust a server seen for the first time, and remember its key when the user agrees.
APIEXPORT wxString PathIgnoreRule(const wxString &aProjectRelPath, bool aIsDirectory)
The rule that ignores one path and nothing else.
APIEXPORT std::vector< wxString > ReadIgnoreRules(const wxFileName &aIgnoreFile)
The rules an ignore file holds, in order, without its comments and blank lines.
std::unique_ptr< git_remote, decltype([](git_remote *aRemote) { git_remote_free(aRemote); })> GitRemotePtr
A unique pointer for git_remote objects with automatic cleanup.
bool IsNetworkPath(const wxString &aPath)
Determines if a given path is a network shared file apth On Windows for example, any form of path is ...
bool IsFileHidden(const wxString &aFileName)
Helper function to determine the status of the 'Hidden' file attribute.
Definition unix/io.cpp:109
void StoreSecretAsync(const wxString &aService, const wxString &aKey, const wxString &aSecret, std::function< void(bool)> aDone=nullptr)
Like StoreSecret(), but never blocks the event loop while the platform asks the user to unlock the st...
void GetSecretAsync(const wxString &aService, const wxString &aKey, std::function< void(bool, const wxString &)> aDone)
Like GetSecret(), but never blocks the event loop while the platform asks the user to unlock the stor...
KICOMMON_API wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmapBundle &aImage, wxItemKind aType=wxITEM_NORMAL)
Create and insert a menu item with an icon into aMenu.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:96
STL namespace.
PGM_BASE & Pgm()
The global program "get" accessor.
#define NAMELESS_PROJECT
default name for nameless projects
Definition project.h:40
static bool gitTaskStillRunning(const std::future< void > &aTask)
project_tree_ids
The frame that shows the tree list of files and subdirectories inside the working directory.
@ ID_PROJECT_OPEN_DIR
@ ID_JOBS_RUN
@ ID_PROJECT_SWITCH_TO_OTHER
@ ID_GIT_EDIT_IGNORE_FILE
@ ID_PROJECT_NEWDIR
@ ID_PROJECT_RENAME
@ ID_GIT_SWITCH_QUICK5
@ ID_GIT_REMOVE_VCS
@ ID_GIT_IGNORE_PATH
@ ID_GIT_KEEP_EXTENSION
@ ID_PROJECT_TXTEDIT
@ ID_GIT_SWITCH_QUICK2
@ ID_GIT_KEEP_PATH
@ ID_GIT_SWITCH_QUICK4
@ ID_GIT_IGNORE_EXTENSION
@ ID_GIT_SWITCH_QUICK3
@ ID_GIT_SWITCH_BRANCH
@ ID_GIT_HISTORY
@ ID_GIT_SWITCH_QUICK1
@ ID_GIT_INITIALIZE_PROJECT
@ ID_PROJECT_DELETE
@ ID_GIT_REMOTE_SETTINGS
static bool promptForGitCredentials(wxWindow *aParent, KIGIT_COMMON *aCommon, const wxString &aExplanation)
static void saveAcceptedRemoteSettings(PROJECT &aProject, const RemoteConfig &aConfig)
std::vector< wxString > getProjects(const wxDir &dir)
static const wxChar * s_allowedExtensionsToList[]
@ RPT_SEVERITY_WARNING
#define wxFileSystemWatcher
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Repository state used before an operation that requires a clean working tree.
What an ignore rule for one path would achieve.
bool tracked
The path, or a file inside it, is in the index, so a new rule would do nothing.
bool ignored
Git's rules already cover the path.
A summary the user can act on, with the raw text that explains it kept apart for the details.
KIGIT_COMMON::GIT_CONN_TYPE connType
DATABASE_CONNECTION dc(odbcBackend(cs))
std::string path
wxString result
Test unit parsing edge cases and error handling.
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
static thread_pool * tp
BS::priority_thread_pool thread_pool
Definition thread_pool.h:27
wxLogTrace helper definitions.
TREE_FILE_TYPE
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)
Definition of file extensions used in Kicad.
#define PR_NO_ABORT