30#include <wx/stdpaths.h>
33#include <wx/textdlg.h>
35#include <wx/wupdlock.h>
57#include <wx/dcclient.h>
58#include <wx/progdlg.h>
59#include <wx/settings.h>
108 wxT(
"^.*\\.kicad_pro$" ),
111 wxT(
"^.*\\.kicad_sch$" ),
112 wxT(
"^[^$].*\\.brd$" ),
113 wxT(
"^[^$].*\\.kicad_pcb$" ),
114 wxT(
"^[^$].*\\.kicad_dru$" ),
115 wxT(
"^[^$].*\\.kicad_wks$" ),
116 wxT(
"^[^$].*\\.kicad_mod$" ),
120 wxT(
"^.*\\.kicad_sym$" ),
125 wxT(
"^.*\\.gbrjob$" ),
126 wxT(
"^.*\\.gb[alops]$" ),
127 wxT(
"^.*\\.gt[alops]$" ),
128 wxT(
"^.*\\.g[0-9]{1,2}$" ),
129 wxT(
"^.*\\.gm[0-9]{1,2}$" ),
133 wxT(
"^.*\\.html$" ),
144 wxT(
"^.*\\.kicad_jobset" ),
227 wxSashLayoutWindow( parent,
ID_LEFT_FRAME, wxDefaultPosition, wxDefaultSize, wxNO_BORDER | wxTAB_TRAVERSAL )
238 Bind( wxEVT_FSWATCHER,
241 Bind( wxEVT_SYS_COLOUR_CHANGED,
255 m_filters.emplace_back( wxT(
"^no KiCad files found" ) );
263 Unbind( wxEVT_FSWATCHER,
265 Unbind( wxEVT_SYS_COLOUR_CHANGED,
298 if( tree_data.size() != 1 )
301 wxString prj_filename = tree_data[0]->GetFileName();
303 m_Parent->LoadProject( prj_filename );
315 wxString curr_dir = item_data->GetDir();
317 if( curr_dir.IsEmpty() )
320 curr_dir = wxPathOnly(
m_Parent->GetProjectFileName() );
323 if( curr_dir.IsEmpty() || !wxFileName::DirExists( curr_dir ) )
326 if( !curr_dir.IsEmpty() )
327 curr_dir += wxFileName::GetPathSeparator();
342 wxString prj_dir = wxPathOnly(
m_Parent->GetProjectFileName() );
345 wxString curr_dir = item_data->GetDir();
347 if( curr_dir.IsEmpty() )
350 wxString new_dir = wxGetTextFromUser(
_(
"Directory name:" ),
_(
"Create New Directory" ) );
352 if( new_dir.IsEmpty() )
355 wxString full_dirname = curr_dir + wxFileName::GetPathSeparator() + new_dir;
357 if( !wxMkdir( full_dirname ) )
405 return wxEmptyString;
411 std::vector<wxString> projects;
412 wxString dir_filename;
413 bool haveFile = dir.GetFirst( &dir_filename );
417 wxFileName file( dir_filename );
421 projects.push_back( file.GetName() );
423 haveFile = dir.GetNext( &dir_filename );
434 const wxTreeItemId& aParent,
435 std::vector<wxString>* aProjectNames,
439 wxFileName fn( aName );
442 return wxTreeItemId();
444 if( wxDirExists( aName ) )
452 bool addFile =
false;
454 for(
const wxString& m_filter :
m_filters )
456 wxCHECK2_MSG( reg.Compile( m_filter, wxRE_ICASE ),
continue,
457 wxString::Format(
"Regex %s failed to compile.", m_filter ) );
459 if( reg.Matches( aName ) )
467 return wxTreeItemId();
474 if( ext == wxT(
"" ) )
477 if( reg.Compile( wxString::FromAscii(
"^.*\\." ) + ext + wxString::FromAscii(
"$" ), wxRE_ICASE )
478 && reg.Matches( aName ) )
486 wxString file = wxFileNameFromPath( aName );
487 wxFileName currfile( file );
489 bool showAllSchematics =
m_TreeProject->GetGitRepo() !=
nullptr;
493 && ( currfile.GetName().CmpNoCase(
project.GetName() ) == 0 ) )
495 return wxTreeItemId();
504 return wxTreeItemId();
510 if( !parentTreeItem )
511 return wxTreeItemId();
513 wxDir parentDir( parentTreeItem->
GetDir() );
514 std::vector<wxString> projects =
getProjects( parentDir );
517 return wxTreeItemId();
522 wxTreeItemIdValue cookie;
523 wxTreeItemId kid =
m_TreeProject->GetFirstChild( aParent, cookie );
530 return itemData->GetId();
551 if( fname.GetName().CmpNoCase( currfile.GetName() ) == 0 )
557 return wxTreeItemId();
563 return wxTreeItemId();
590 wxTreeItemId newItemId =
m_TreeProject->AppendItem( aParent, file );
597 wxString fileName = currfile.GetName().Lower();
598 wxString projName =
project.GetName().Lower();
600 if( fileName == projName || fileName.StartsWith( projName +
"-" ) )
604 bool subdir_populated =
false;
615 std::vector<wxString> projects =
getProjects( dir );
616 wxString dir_filename;
617 bool haveFile = dir.GetFirst( &dir_filename );
622 subdir_populated = aRecurse;
628 wxString
path = aName + wxFileName::GetPathSeparator() + dir_filename;
631 haveFile = dir.GetNext( &dir_filename );
640 if( subdir_populated )
654 while(
tp.get_tasks_running() )
656 tp.wait_for( std::chrono::milliseconds( 250 ) );
664 wxString pro_dir =
m_Parent->GetProjectFileName();
682 wxFileName fn = pro_dir;
683 bool prjReset =
false;
694 bool prjOpened = fn.FileExists();
697 if(
Pgm().GetCommonSettings()->m_Git.enableGit
698 && !
Prj().GetLocalSettings().m_GitIntegrationDisabled )
708 const char* canonicalWorkDir = git_repository_workdir(
m_TreeProject->GetGitRepo() );
710 if( canonicalWorkDir )
713 fn.GetPath(), wxString::FromUTF8( canonicalWorkDir ) );
717 m_TreeProject->GitCommon()->SetUsername(
Prj().GetLocalSettings().m_GitRepoUsername );
718 m_TreeProject->GitCommon()->SetSSHKey(
Prj().GetLocalSettings().m_GitSSHKey );
725 if( !prjOpened && !prjReset )
728 prjOpened = fn.FileExists();
748 pro_dir = wxPathOnly(
m_Parent->GetProjectFileName() );
749 wxDir dir( pro_dir );
753 std::vector<wxString> projects =
getProjects( dir );
755 bool haveFile = dir.GetFirst( &filename );
759 if( filename != fn.GetFullName() )
761 wxString
name = dir.GetName() + wxFileName::GetPathSeparator() + filename;
768 haveFile = dir.GetNext( &filename );
785 wxLogTrace(
traceGit,
"PROJECT_TREE_PANE::ReCreateTreePrj: starting timers" );
804 wxTreeItemId curr_item = Event.GetItem();
811 wxFileName prj_dir(
Prj().GetProjectPath(), wxEmptyString );
813 prj_dir.Normalize( wxPATH_NORM_ABSOLUTE | wxPATH_NORM_CASE | wxPATH_NORM_DOTS
814 | wxPATH_NORM_ENV_VARS | wxPATH_NORM_TILDE );
815 git_dir.Normalize( wxPATH_NORM_ABSOLUTE | wxPATH_NORM_CASE | wxPATH_NORM_DOTS
816 | wxPATH_NORM_ENV_VARS | wxPATH_NORM_TILDE );
817 wxString prj_name = prj_dir.GetFullPath();
818 wxString git_name = git_dir.GetFullPath();
820 bool can_switch_to_project =
true;
821 bool can_create_new_directory =
true;
822 bool can_open_this_directory =
true;
823 bool can_edit =
true;
824 bool can_rename =
true;
825 bool can_delete =
true;
826 bool run_jobs =
false;
830 bool vcs_can_init = !vcs_has_repo;
833 bool vcs_can_remove = ( vcs_has_repo && git_name.StartsWith( prj_name ) ) || gitIntegrationDisabled;
836 bool vcs_can_pull = vcs_can_fetch;
837 bool vcs_can_switch = vcs_has_repo;
843 vcs_menu &= libgit_init;
845 if( selection.size() == 0 )
849 if( selection.size() != 1 )
851 can_switch_to_project =
false;
852 can_create_new_directory =
false;
861 can_switch_to_project =
false;
867 can_delete = item->CanDelete();
868 can_rename = item->CanRename();
870 switch( item->GetType() )
878 can_switch_to_project =
false;
882 can_create_new_directory =
false;
883 can_open_this_directory =
false;
888 can_switch_to_project =
false;
895 can_switch_to_project =
false;
896 can_create_new_directory =
false;
897 can_open_this_directory =
false;
910 can_switch_to_project =
false;
911 can_create_new_directory =
false;
912 can_open_this_directory =
false;
922 if( can_switch_to_project )
925 _(
"Close all editors, and switch to the selected project" ),
927 popup_menu.AppendSeparator();
930 if( can_create_new_directory )
936 if( can_open_this_directory )
938 if( selection.size() == 1 )
941 text =
_(
"Reveal in Finder" );
942 help_text =
_(
"Reveals the directory in a Finder window" );
944 text =
_(
"Open Directory in File Explorer" );
945 help_text =
_(
"Opens the directory in the default system file manager" );
951 text =
_(
"Reveal in Finder" );
952 help_text =
_(
"Reveals the directories in a Finder window" );
954 text =
_(
"Open Directories in File Explorer" );
955 help_text =
_(
"Opens the directories in the default system file manager" );
965 if( selection.size() == 1 )
966 help_text =
_(
"Open the file in a Text Editor" );
968 help_text =
_(
"Open files in a Text Editor" );
974 if( run_jobs && selection.size() == 1 )
982 if( selection.size() == 1 )
984 text =
_(
"Rename File..." );
985 help_text =
_(
"Rename file" );
989 text =
_(
"Rename Files..." );
990 help_text =
_(
"Rename files" );
999 if( selection.size() == 1 )
1000 help_text =
_(
"Delete the file and its content" );
1002 help_text =
_(
"Delete the files and their contents" );
1004 if( can_switch_to_project
1005 || can_create_new_directory
1006 || can_open_this_directory
1010 popup_menu.AppendSeparator();
1024 wxMenu* vcs_submenu =
new wxMenu();
1025 wxMenu* branch_submenu =
new wxMenu();
1026 wxMenuItem* vcs_menuitem =
nullptr;
1029 _(
"Add Project to Version Control..." ),
1030 _(
"Initialize a new repository" ) );
1031 vcs_menuitem->Enable( vcs_can_init );
1035 _(
"Commit changes to the local repository" ) );
1036 vcs_menuitem->Enable( vcs_can_commit );
1038 vcs_menuitem = vcs_submenu->Append(
ID_GIT_PUSH,
_(
"Push" ),
1039 _(
"Push committed local changes to remote repository" ) );
1040 vcs_menuitem->Enable( vcs_can_push );
1042 vcs_menuitem = vcs_submenu->Append(
ID_GIT_PULL,
_(
"Pull" ),
1043 _(
"Pull changes from remote repository into local" ) );
1044 vcs_menuitem->Enable( vcs_can_pull );
1046 vcs_submenu->AppendSeparator();
1049 _(
"Commit changes to the local repository" ) );
1050 vcs_menuitem->Enable( vcs_can_commit );
1052 vcs_submenu->AppendSeparator();
1058 std::vector<wxString> branchNames =
m_TreeProject->GitCommon()->GetBranchNames();
1061 for(
size_t ii = 1; ii < branchNames.size() && ii < 6; ++ii )
1063 wxString msg =
_(
"Switch to branch " ) + branchNames[ii];
1065 vcs_menuitem->Enable( vcs_can_switch );
1069 _(
"Switch to a different branch" ) );
1070 vcs_menuitem->Enable( vcs_can_switch );
1074 vcs_submenu->AppendSeparator();
1076 if( gitIntegrationDisabled )
1078 vcs_menuitem = vcs_submenu->Append(
ID_GIT_REMOVE_VCS,
_(
"Enable Git Integration" ),
1079 _(
"Re-enable Git integration for this project" ) );
1083 vcs_menuitem = vcs_submenu->Append(
ID_GIT_REMOVE_VCS,
_(
"Disable Git Integration" ),
1084 _(
"Disable Git integration for this project" ) );
1087 vcs_menuitem->Enable( vcs_can_remove );
1089 popup_menu.AppendSeparator();
1090 popup_menu.AppendSubMenu( vcs_submenu,
_(
"Version Control" ) );
1093 if( popup_menu.GetMenuItemCount() > 0 )
1094 PopupMenu( &popup_menu );
1102 if( editorname.IsEmpty() )
1104 wxMessageBox(
_(
"No text editor selected in KiCad. Please choose one." ) );
1112 wxString fullFileName = item_data->GetFileName();
1114 if( !fullFileName.IsEmpty() )
1116 ExecuteFile( editorname, fullFileName.wc_str(),
nullptr,
false );
1127 item_data->Delete();
1137 if( tree_data.size() != 1 )
1141 wxString msg = wxString::Format(
_(
"Change filename: '%s'" ),
1142 tree_data[0]->GetFileName() );
1143 wxTextEntryDialog dlg( wxGetTopLevelParent(
this ), msg,
_(
"Change filename" ), buffer );
1145 if( dlg.ShowModal() != wxID_OK )
1148 buffer = dlg.GetValue();
1149 buffer.Trim(
true );
1150 buffer.Trim(
false );
1152 if( buffer.IsEmpty() )
1155 tree_data[0]->Rename( buffer,
true );
1164 if( tree_data.size() != 1 )
1187 std::vector<wxTreeItemId> validItemIds;
1190 for( wxTreeItemId
id : validItemIds )
1209 wxTreeItemId itemId = Event.GetItem();
1219 wxTreeItemIdValue cookie;
1220 wxTreeItemId kid =
m_TreeProject->GetFirstChild( itemId, cookie );
1223 bool subdir_populated =
false;
1226 for( ; kid.IsOk(); kid =
m_TreeProject->GetNextChild( itemId, cookie ) )
1237 wxDir dir( fileName );
1239 if( dir.IsOpened() )
1241 std::vector<wxString> projects =
getProjects( dir );
1242 wxString dir_filename;
1243 bool haveFile = dir.GetFirst( &dir_filename );
1248 wxString
name = fileName + wxFileName::GetPathSeparator() + dir_filename;
1251 haveFile = dir.GetNext( &dir_filename );
1257 subdir_populated =
true;
1266 if( subdir_populated )
1274 wxArrayTreeItemIds selection;
1275 std::vector<PROJECT_TREE_ITEM*> data;
1279 for(
const wxTreeItemId itemId : selection )
1285 wxLogTrace(
traceGit, wxS(
"Null tree item returned for selection, dynamic_cast failed?" ) );
1289 data.push_back( item );
1304 wxString prj_dir = wxPathOnly(
m_Parent->GetProjectFileName() );
1308 if( prj_dir == aSubDir )
1312 wxTreeItemIdValue cookie;
1313 wxTreeItemId root_id =
m_root;
1314 std::stack<wxTreeItemId> subdirs_id;
1316 wxTreeItemId child =
m_TreeProject->GetFirstChild( root_id, cookie );
1320 if( ! child.IsOk() )
1322 if( subdirs_id.empty() )
1329 root_id = subdirs_id.top();
1350 subdirs_id.push( child );
1368 if( !( event.GetChangeType() & ( wxFSW_EVENT_CREATE |
1369 wxFSW_EVENT_DELETE |
1370 wxFSW_EVENT_RENAME |
1371 wxFSW_EVENT_MODIFY ) ) )
1376 const wxFileName& pathModified =
event.GetPath();
1379 if( pathModified.GetFullPath().Contains( wxS(
".history" ) ) )
1382 wxString subdir = pathModified.GetPath();
1383 wxString fn = pathModified.GetFullPath();
1386 if( pathModified.GetFullName().IsEmpty() )
1388 subdir = subdir.BeforeLast(
'/' );
1389 fn = fn.BeforeLast(
'/' );
1394 if( !root_id.IsOk() )
1397 CallAfter( [
this] ()
1399 wxLogTrace(
traceGit, wxS(
"File system event detected, updating tree cache" ) );
1403 wxTreeItemIdValue cookie;
1404 wxTreeItemId kid =
m_TreeProject->GetFirstChild( root_id, cookie );
1406 switch( event.GetChangeType() )
1408 case wxFSW_EVENT_CREATE:
1423 case wxFSW_EVENT_DELETE:
1437 case wxFSW_EVENT_RENAME :
1439 const wxFileName& newpath =
event.GetNewPath();
1440 wxString newdir = newpath.GetPath();
1441 wxString newfn = newpath.GetFullPath();
1465 if( rootData && newpath.Exists() && ( newfn != rootData->
GetFileName() ) )
1471 if( newitem.IsOk() )
1492 wxString prj_dir = wxPathOnly(
m_Parent->GetProjectFileName() );
1494#if defined( _WIN32 )
1503 m_Parent->m_FileWatcherInfo =
_(
"Network path: not monitoring folder changes" );
1509 m_Parent->m_FileWatcherInfo =
_(
"Local path: monitoring folder changes" );
1527 class WatcherLogHandler :
public wxLog
1530 explicit WatcherLogHandler(
bool* err ) :
1538 void DoLogTextAtLevel( wxLogLevel level,
const wxString&
text )
override
1540 if( m_err && ( level == wxLOG_Error || level == wxLOG_FatalError ) )
1548 bool watcherHasError =
false;
1549 WatcherLogHandler tmpLog( &watcherHasError );
1550 wxLog* oldLog = wxLog::SetActiveTarget( &tmpLog );
1556 wxLog::SetActiveTarget( oldLog );
1558 if( watcherHasError )
1566 fn.AssignDir( prj_dir );
1567 fn.DontFollowLink();
1581 TO_UTF8( fn.GetFullPath() ) );
1589 TO_UTF8( fn.GetFullPath() ) );
1594 if( m_TreeProject->IsEmpty() )
1598 wxTreeItemIdValue cookie;
1599 wxTreeItemId root_id = m_root;
1601 std::stack < wxTreeItemId > subdirs_id;
1603 wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
1604 int total_watch_count = 0;
1610 if( subdirs_id.empty() )
1616 root_id = subdirs_id.top();
1618 kid = m_TreeProject->GetFirstChild( root_id, cookie );
1633 if(
path.Contains( wxS(
".history" ) ) )
1635 kid = m_TreeProject->GetNextChild( root_id, cookie );
1641 if( wxFileName::IsDirReadable(
path ) )
1646 fn.AssignDir(
path );
1647 m_watcher->Add( fn );
1648 total_watch_count++;
1652 if( itemData->
IsPopulated() && m_TreeProject->GetChildrenCount( kid ) )
1653 subdirs_id.push( kid );
1657 kid = m_TreeProject->GetNextChild( root_id, cookie );
1664#if defined(DEBUG) && 1
1665 wxArrayString paths;
1666 m_watcher->GetWatchedPaths( &paths );
1669 for(
unsigned ii = 0; ii < paths.GetCount(); ii++ )
1688 std::unique_lock<std::mutex> lock(
m_TreeProject->GitCommon()->m_gitActionMutex, std::try_to_lock );
1690 if( !lock.owns_lock() )
1694 wxProgressDialog progress(
_(
"Please wait" ),
_(
"Waiting for Git operations to finish..." ),
1695 100,
this, wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_SMOOTH );
1698 while ( !lock.try_lock() )
1701 std::this_thread::sleep_for( std::chrono::milliseconds(100) );
1727 wxRect rect( wxPoint( 0, 0 ), GetClientSize() );
1728 wxPaintDC dc(
this );
1730 dc.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_FRAMEBK ) );
1731 dc.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_ACTIVEBORDER ), 1 ) );
1733 dc.DrawLine( rect.GetLeft(), rect.GetTop(), rect.GetLeft(), rect.GetBottom() );
1734 dc.DrawLine( rect.GetRight(), rect.GetTop(), rect.GetRight(), rect.GetBottom() );
1748 wxString dir = tree_data->
GetDir();
1752 wxLogError(
"Failed to initialize git project: project directory is empty." );
1757 wxWindow* topLevelParent = wxGetTopLevelParent(
this );
1762 _(
"The selected directory is already a Git project." ) );
1777 dlg.SetTitle(
_(
"Set default remote" ) );
1832 handler.
SetProgressReporter( std::make_unique<WX_PROGRESS_REPORTER>(
this,
_(
"Fetch Remote" ), 1,
1855 handler.
SetProgressReporter( std::make_unique<WX_PROGRESS_REPORTER>(
this,
_(
"Fetch Remote" ), 1,
1875 wxString branchName;
1884 if( retval == wxID_ADD )
1886 else if( retval != wxID_OK )
1891 std::vector<wxString> branches =
m_TreeProject->GitCommon()->GetBranchNames();
1894 if( branchIndex < 0 ||
static_cast<size_t>( branchIndex ) >= branches.size() )
1897 branchName = branches[branchIndex];
1900 wxLogTrace(
traceGit, wxS(
"onGitSwitchBranch: Switching to branch '%s'" ), branchName );
1915 wxLogTrace(
traceGit, wxS(
"onGitRemoveVCS: Git integration %s" ),
1925 std::stack<wxTreeItemId> items;
1928 while( !items.empty() )
1930 wxTreeItemId current = items.top();
1933 m_TreeProject->SetItemState( current, wxTREE_ITEMSTATE_NONE );
1935 wxTreeItemIdValue cookie;
1936 wxTreeItemId child =
m_TreeProject->GetFirstChild( current, cookie );
1938 while( child.IsOk() )
1940 items.push( child );
1948 wxFileName fn(
Prj().GetProjectPath() );
1955 const char* canonicalWorkDir = git_repository_workdir(
m_TreeProject->GetGitRepo() );
1957 if( canonicalWorkDir )
1960 fn.GetPath(), wxString::FromUTF8( canonicalWorkDir ) );
1961 m_TreeProject->GitCommon()->SetProjectDir( symlinkWorkDir );
1976 wxLogTrace(
traceGit, wxS(
"updateGitStatusIcons: Updating git status icons" ) );
1979 if( !lock.owns_lock() )
1981 wxLogTrace(
traceGit, wxS(
"updateGitStatusIcons: Failed to acquire lock for git status icon update" ) );
1988 wxLogTrace(
traceGit, wxS(
"updateGitStatusIcons: Git is disabled or tree control is null" ) );
1992 std::stack<wxTreeItemId> items;
1995 while( !items.empty() )
1997 wxTreeItemId current = items.top();
2002 wxTreeItemIdValue cookie;
2003 wxTreeItemId child =
m_TreeProject->GetFirstChild( current, cookie );
2005 while( child.IsOk() )
2007 items.push( child );
2011 m_TreeProject->SetItemState( child,
static_cast<int>( it->second ) );
2026 wxString filename = wxFileNameFromPath( rootItem->
GetFileName() );
2032 wxLogTrace(
traceGit, wxS(
"updateGitStatusIcons: Git status icons updated" ) );
2038 wxLogTrace(
traceGit, wxS(
"updateTreeCache: Updating tree cache" ) );
2042 if( !lock.owns_lock() )
2044 wxLogTrace(
traceGit, wxS(
"updateTreeCache: Failed to acquire lock for tree cache update" ) );
2050 wxLogTrace(
traceGit, wxS(
"updateTreeCache: Tree control is null" ) );
2061 std::stack<wxTreeItemId> items;
2064 while( !items.empty() )
2076 gitAbsPath.Replace( wxS(
"\\" ), wxS(
"/" ) );
2080 wxTreeItemIdValue cookie;
2081 wxTreeItemId child =
m_TreeProject->GetFirstChild( kid, cookie );
2083 while( child.IsOk() )
2085 items.push( child );
2094 wxLogTrace(
traceGit, wxS(
"updateGitStatusIconMap: Updating git status icons" ) );
2095#if defined( _WIN32 )
2118 if( !lock1.owns_lock() || !lock2.owns_lock() )
2120 wxLogTrace(
traceGit, wxS(
"updateGitStatusIconMap: Failed to acquire locks for git status icon update" ) );
2126 wxLogTrace(
traceGit, wxS(
"updateGitStatusIconMap: No git repository found" ) );
2132 std::unique_lock<std::mutex> gitLock(
m_TreeProject->GitCommon()->m_gitActionMutex, std::try_to_lock );
2134 if( !gitLock.owns_lock() )
2136 wxLogTrace(
traceGit, wxS(
"updateGitStatusIconMap: Failed to acquire git action mutex" ) );
2143 wxLogTrace(
traceGit, wxS(
"updateGitStatusIconMap: Cancelled" ) );
2150 wxFileName rootFilename(
Prj().GetProjectFullName() );
2153 wxFileName relative = rootFilename;
2154 relative.MakeRelativeTo( repoWorkDir );
2155 wxString pathspecStr = relative.GetPath( wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR );
2158 pathspecStr.Replace( wxS(
"\\" ), wxS(
"/" ) );
2162 auto fileStatusMap = statusHandler.
GetFileStatus( pathspecStr );
2163 auto [localChanges, remoteChanges] =
m_TreeProject->GitCommon()->GetDifferentFiles();
2166 bool updated =
false;
2169 for(
const auto& [absPath, fileStatus] : fileStatusMap )
2174 wxLogTrace(
traceGit, wxS(
"File '%s' not found in tree cache" ), absPath );
2178 auto [it, inserted] =
m_gitStatusIcons.try_emplace( iter->second, fileStatus.status );
2179 if( inserted || it->second != fileStatus.status )
2181 it->second = fileStatus.status;
2187 wxLogTrace(
traceGit, wxS(
"updateGitStatusIconMap: Updated git status icons" ) );
2207 if( repo ==
nullptr )
2209 wxMessageBox(
_(
"The selected directory is not a Git project." ) );
2221 std::map<wxString, int> modifiedFiles;
2222 std::set<wxString> selected_files;
2227 selected_files.emplace( item->GetFileName() );
2232 for(
const auto& [absPath, fileStatus] : fileStatusMap )
2242 wxFileName fn( absPath );
2245 wxString relativePath = absPath;
2246 if( relativePath.StartsWith( repoWorkDir ) )
2248 relativePath = relativePath.Mid( repoWorkDir.length() );
2250 relativePath.Replace( wxS(
"\\" ), wxS(
"/" ) );
2256 if( !absPath.StartsWith( projectPath ) )
2271 if( fn.GetPath().Contains(
Prj().GetProjectName() + wxT(
"-backups" ) ) )
2276 modifiedFiles.emplace( relativePath, fileStatus.gitStatus );
2278 else if( selected_files.count( absPath ) )
2280 modifiedFiles.emplace( relativePath, fileStatus.gitStatus );
2289 if( ret != wxID_OK )
2296 wxMessageBox(
_(
"Discarding commit due to empty commit message." ) );
2302 wxMessageBox(
_(
"Discarding commit due to empty file selection." ) );
2312 wxMessageBox( wxString::Format(
_(
"Failed to create commit: %s" ),
2317 wxLogTrace(
traceGit, wxS(
"Created commit" ) );
2337 for(
const auto& [filePath, fileStatus] : fileStatusMap )
2339 if( filePath.EndsWith( aFile ) || filePath == aFile )
2353 wxLogTrace(
traceGit,
"Syncing project" );
2358 wxLogTrace(
traceGit,
"sync: No git repository found" );
2425 wxLogTrace(
traceGit,
"onGitSyncTimer" );
2439 wxLogTrace(
traceGit,
"onGitSyncTimer: No git repository found" );
2446 wxLogTrace(
traceGit,
"onGitSyncTimer: Cancelled" );
2460 wxLogTrace(
traceGit,
"onGitSyncTimer: Restarting git sync timer" );
2483 wxLogTrace(
traceGit,
"onGitStatusTimer" );
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
BITMAP_STORE * GetBitmapStore()
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void ThemeChanged()
Notifies the store that the icon theme has been changed by the user, so caches must be invalidated.
wxString GetCommitMessage() const
wxString GetAuthorEmail() const
std::vector< wxString > GetSelectedFiles() const
wxString GetAuthorName() const
KIGIT_COMMON::GIT_CONN_TYPE GetRepoType() const
wxString GetRepoSSHPath() const
wxString GetRepoURL() const
wxString GetUsername() const
wxString GetPassword() const
void SetSkipButtonLabel(const wxString &aLabel)
wxString GetBranchName() const
virtual bool IsLibraryAvailable()=0
BranchResult SwitchToBranch(const wxString &aBranchName)
Switch to the specified branch.
CommitResult PerformCommit(const std::vector< wxString > &aFiles, const wxString &aMessage, const wxString &aAuthorName, const wxString &aAuthorEmail)
wxString GetErrorString() const
GitUserConfig GetUserConfig()
Get user configuration (name and email) from git config Falls back to common settings if not found in...
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< WX_PROGRESS_REPORTER > aProgressReporter)
bool PerformFetch(bool aSkipLock=false)
void PerformRemoveFromIndex()
bool PerformResolveConflict()
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.
bool HasChangedFiles()
Check if the repository has any changed files.
std::map< wxString, FileStatus > GetFileStatus(const wxString &aPathspec=wxEmptyString)
Get detailed file status for all files in the specified 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 git_repository * GetRepositoryForFile(const char *aFilename)
Discover and open the repository that contains the given file.
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.
wxString GetGitRootDirectory() const
bool HasPushAndPullRemote() const
bool HasLocalCommits() const
wxString GetErrorString()
git_repository * GetRepo() const
Get a pointer to the git repository.
void SetEllipsedTextField(const wxString &aText, int aFieldId)
Set the text in a field using wxELLIPSIZE_MIDDLE option to adjust the text size to the field size.
static wxString GetDefaultUserProjectsPath()
Gets the default path we point users to create projects.
virtual COMMON_SETTINGS * GetCommonSettings() const
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
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.
wxString m_GitRepoUsername
Handle one item (a file or a directory name) for the tree file.
void SetRootFile(bool aValue)
const wxString & GetFileName() const
void SetPopulated(bool aValue)
TREE_FILE_TYPE GetType() const
const wxString GetDir() const
void Activate(PROJECT_TREE_PANE *aTreePrjFrame)
PROJECT_TREE_PANE Window to display the tree files.
PROJECT_TREE_ITEM * m_selectedItem
std::unordered_map< wxString, wxTreeItemId > m_gitTreeCache
void onGitFetch(wxCommandEvent &event)
Fetch the latest changes from the git repository.
std::map< wxTreeItemId, KIGIT_COMMON::GIT_STATUS > m_gitStatusIcons
void onGitInitializeProject(wxCommandEvent &event)
Initialize a new git repository in the current project directory.
void onGitSyncProject(wxCommandEvent &event)
Sync the current project with the git repository.
void onDeleteFile(wxCommandEvent &event)
Function onDeleteFile 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 ...
wxString m_gitCurrentBranchName
std::vector< PROJECT_TREE_ITEM * > GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
void onOpenDirectory(wxCommandEvent &event)
Function onOpenDirectory Handles the right-click menu for opening a directory in the current system f...
void onGitResolveConflict(wxCommandEvent &event)
Resolve conflicts in the git repository.
void onFileSystemEvent(wxFileSystemWatcherEvent &event)
called when a file or directory is modified/created/deleted The tree project is modified when a file ...
wxFileSystemWatcher * m_watcher
void onRight(wxTreeEvent &Event)
Called on a right click on an item.
void onGitCommit(wxCommandEvent &event)
Commit the current project saved changes to the git repository.
void onSelect(wxTreeEvent &Event)
Called on a double click on an item.
PROJECT_TREE * m_TreeProject
PROJECT_TREE_PANE(KICAD_MANAGER_FRAME *parent)
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.
void onGitSyncTimer(wxTimerEvent &event)
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.
void gitStatusTimerHandler()
std::mutex m_gitStatusMutex
void onGitRevertLocal(wxCommandEvent &event)
Revert the local repository to the last commit.
void onGitPullProject(wxCommandEvent &event)
Pull the latest changes from the git repository.
static wxString GetFileExt(TREE_FILE_TYPE type)
friend class PROJECT_TREE_ITEM
void onGitRemoveFromIndex(wxCommandEvent &event)
Remove a file from the git index.
wxTreeItemId findSubdirTreeItem(const wxString &aSubDir)
Function findSubdirTreeItem searches for the item in tree project which is the node of the subdirecto...
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 onGitCompare(wxCommandEvent &event)
Compare the current project to a different branch in the git repository.
void onGitStatusTimer(wxTimerEvent &event)
void shutdownFileWatcher()
Shutdown the file watcher.
std::mutex m_gitTreeCacheMutex
wxTreeItemId addItemToProjectTree(const wxString &aName, const wxTreeItemId &aParent, std::vector< wxString > *aProjectNames, bool aRecurse)
Function addItemToProjectTree.
bool hasChangedFiles()
Returns true if the current project has any uncommitted changes.
void onOpenSelectedFileWithTextEditor(wxCommandEvent &event)
Function onOpenSelectedFileWithTextEditor Call the text editor to open the selected file in the tree ...
void onGitAddToIndex(wxCommandEvent &event)
Add a file to the git index.
void updateGitStatusIcons()
Updates the icons shown in the tree project to reflect the current git status.
bool m_gitIconsInitialized
std::future< void > m_gitStatusIconTask
void updateGitStatusIconMap()
This is a threaded call that will change the map of git status icons for use in the main thread.
PROJECT_TREE_ITEM * GetItemIdData(wxTreeItemId aId)
Function GetItemIdData return the item data corresponding to a wxTreeItemId identifier.
void onGitSwitchBranch(wxCommandEvent &event)
Switch to a different branch in the git repository.
void onCreateNewDirectory(wxCommandEvent &event)
Function onCreateNewDirectory Creates a new subdirectory inside the current kicad project directory t...
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)
Function onRenameFile Rename the selected file or directory in the tree project.
void onGitPushProject(wxCommandEvent &event)
Push the current project changes to the git repository.
bool canFileBeAddedToVCS(const wxString &aFilePath)
Returns true if the file has already been added to the repository or false if it has not been added y...
std::vector< wxString > m_filters
PROJECT_TREE This is the class to show (as a tree) the files in the project directory.
virtual const wxString GetProjectPath() const
Return the full path of the project.
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
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.
GIT_BACKEND * GetGitBackend()
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 LockFileExtension
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 LockFilePrefix
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 BackupFileSuffix
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.
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 ...
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.
wxDECLARE_EVENT(wxCUSTOM_PANEL_SHOWN_EVENT, wxCommandEvent)
PGM_BASE & Pgm()
The global program "get" accessor.
#define NAMELESS_PROJECT
default name for nameless projects
project_tree_ids
The frame that shows the tree list of files and subdirectories inside the working directory.
@ ID_PROJECT_SWITCH_TO_OTHER
@ ID_GIT_REMOVE_FROM_INDEX
@ ID_GIT_RESOLVE_CONFLICT
@ ID_GIT_INITIALIZE_PROJECT
std::vector< wxString > getProjects(const wxDir &dir)
static const wxChar * s_allowedExtensionsToList[]
#define wxFileSystemWatcher
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
KIGIT_COMMON::GIT_CONN_TYPE connType
wxString result
Test unit parsing edge cases and error handling.
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
BS::priority_thread_pool thread_pool
wxLogTrace helper definitions.
Definition of file extensions used in Kicad.