50#include <wx/filedlg.h>
77 wxString default_filename = aFileName ? *aFileName : wxString();
79 wxString default_dir =
m_frame->GetMruPath();
80 wxFileDialog dlg(
m_frame,
_(
"Create New Project" ), default_dir, default_filename,
82 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
88 dlg.SetCustomizeHook( newProjectHook );
90 if( dlg.ShowModal() == wxID_CANCEL )
93 wxFileName pro( dlg.GetPath() );
98 pro.SetName( pro.GetName() + wxT(
"." ) + pro.GetExt() );
102 if( !pro.IsAbsolute() )
106 bool createNewDir =
false;
111 pro.AppendDir( pro.GetName() );
116 if( !pro.DirExists() )
121 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
122 "Make sure you have write permissions and try again." ),
130 wxString msg =
_(
"The selected folder is not empty. It is recommended that you "
131 "create projects in their own empty folder.\n\n"
132 "Do you want to continue?" );
146 if( it ==
Pgm().GetLocalEnvVariables().
end() || it->second.GetValue() == wxEmptyString )
149 wxFileName templatePath;
150 templatePath.AssignDir( it->second.GetValue() );
151 templatePath.AppendDir(
"default" );
153 if( templatePath.DirExists() )
156 if( !templatePath.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
159 wxFileName metaDir = templatePath;
162 if( !metaDir.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
165 wxFileName infoFile = metaDir;
167 wxFFile
info( infoFile.GetFullPath(), wxT(
"w" ) );
169 if( !
info.IsOpened() )
172 info.Write( wxT(
"<html><head><title>Default</title></head><body></body></html>" ) );
175 wxFileName proFile = templatePath;
176 proFile.SetFullName( wxT(
"default.kicad_pro" ) );
177 wxFFile proj( proFile.GetFullPath(), wxT(
"w" ) );
179 if( !proj.IsOpened() )
182 proj.Write( wxT(
"{}" ) );
192 if( !defaultTemplate.IsOk() )
199 m_frame->CreateNewProject( pro );
206 std::vector<std::pair<wxString, wxFileName>> titleDirList;
207 wxFileName templatePath;
211 if( itUser !=
Pgm().GetLocalEnvVariables().
end() && itUser->second.GetValue() != wxEmptyString )
213 templatePath.AssignDir( itUser->second.GetValue() );
214 titleDirList.emplace_back(
_(
"User Templates" ), templatePath );
218 wxT(
"TEMPLATE_DIR" ) );
220 if( v && !v->IsEmpty() )
222 templatePath.AssignDir( *v );
223 titleDirList.emplace_back(
_(
"System Templates" ), templatePath );
227 titleDirList, defaultTemplate );
239 if( !selectedTemplate )
242 if( !selectedTemplate )
244 wxMessageBox(
_(
"No project template was selected. Cannot generate new project." ),
_(
"Error" ),
245 wxOK | wxICON_ERROR,
m_frame );
250 wxString default_dir = wxFileName(
Prj().GetProjectFullName() ).GetPathWithSep();
251 wxString title =
_(
"New Project Folder" );
253 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
258 dlg.SetCustomizeHook( newProjectHook );
260 if( dlg.ShowModal() == wxID_CANCEL )
263 wxFileName fn( dlg.GetPath() );
266 fn.SetName( fn.GetName() + wxT(
"." ) + fn.GetExt() );
270 if( !fn.IsAbsolute() )
273 bool createNewDir =
false;
277 fn.AppendDir( fn.GetName() );
279 if( !fn.DirExists() && !fn.Mkdir() )
282 "Make sure you have write permissions and try again." ),
287 if( !fn.IsDirWritable() )
294 std::vector< wxFileName > destFiles;
298 std::vector<wxFileName> overwrittenFiles;
300 for(
const wxFileName& file : destFiles )
302 if( file.FileExists() )
303 overwrittenFiles.push_back( file );
306 if( !overwrittenFiles.empty() )
308 wxString extendedMsg =
_(
"Overwriting files:" ) +
"\n";
310 for(
const wxFileName& file : overwrittenFiles )
311 extendedMsg +=
"\n" + file.GetFullName();
313 KIDIALOG msgDlg(
m_frame,
_(
"Similar files already exist in the destination folder." ),
314 _(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
315 msgDlg.SetExtendedMessage( extendedMsg );
316 msgDlg.SetOKLabel(
_(
"Overwrite" ) );
332 m_frame->CreateNewProject( fn.GetFullPath() );
342 dlg.SetTitle(
_(
"Clone Project from Git Repository" ) );
377 if( projects.empty() )
385 wxString dest = pro.GetPath() + wxFileName::GetPathSeparator() + projects.front();
405 wxString default_dir = wxFileName(
Prj().GetProjectFullName() ).GetPathWithSep();
407 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
409 if( dlg.ShowModal() == wxID_CANCEL )
412 wxFileName jobsetFn( dlg.GetPath() );
415 bool fileExists = wxFileExists( jobsetFn.GetFullPath() );
420 if( !wxRemoveFile( jobsetFn.GetFullPath() ) )
426 m_frame->OpenJobsFile( jobsetFn.GetFullPath(),
true );
440 wxFileDialog dlg(
m_frame,
_(
"Open Existing Project" ), aDefaultDir, wxEmptyString, wildcard,
441 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
445 if( dlg.ShowModal() == wxID_CANCEL )
448 wxFileName pro( dlg.GetPath() );
450 if( !pro.IsAbsolute() )
481 wxString default_dir = wxFileName(
Prj().GetProjectFullName() ).GetPathWithSep();
483 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
485 if( dlg.ShowModal() == wxID_CANCEL )
488 wxFileName jobsetFn( dlg.GetPath() );
490 m_frame->OpenJobsFile( jobsetFn.GetFullPath(),
true );
513 wxFileName fileName =
m_frame->GetProjectFileName();
517 wxFileDialog dlg(
m_frame,
_(
"Archive Project Files" ), fileName.GetPath(), fileName.GetFullName(),
520 if( dlg.ShowModal() == wxID_CANCEL )
523 wxFileName zipFile = dlg.GetPath();
525 wxString currdirname = fileName.GetPathWithSep();
526 wxDir dir( currdirname );
528 if( !dir.IsOpened() )
534 archiver.
Archive( currdirname, zipFile.GetFullPath(), reporter,
true,
true );
557 wxExecute( *aEvent.
Parameter<wxString*>(), wxEXEC_ASYNC );
566 const wxString& aSrcProjectDirPath,
567 const wxString& aSrcProjectName,
568 const wxString& aNewProjectDirPath,
569 const wxString& aNewProjectName ) :
578 virtual wxDirTraverseResult
OnFile(
const wxString& aSrcFilePath )
override
582 return wxDIR_CONTINUE;
584 wxFileName destFile( aSrcFilePath );
585 wxString ext = destFile.GetExt();
592 wxString destPath = destFile.GetPath();
597 destFile.SetPath( destPath );
617 projectFile.
SaveAs( destFile.GetPath(), destFile.GetName() );
623 projectLocalSettings.
SaveAs( destFile.GetPath(), destFile.GetName() );
675 wxString destPath = destFile.GetPathWithSep();
676 wxString destName = destFile.GetName();
677 wxUniChar pathSep = wxFileName::GetPathSeparator();
679 wxString srcProjectFootprintLib = pathSep +
m_projectName +
".pretty" + pathSep;
680 wxString newProjectFootprintLib = pathSep +
m_newProjectName +
".pretty" + pathSep;
685 destPath.Replace( srcProjectFootprintLib, newProjectFootprintLib,
true );
690 destFile.SetPath( destPath );
695 return wxDIR_CONTINUE;
698 virtual wxDirTraverseResult
OnDir(
const wxString& aSrcDirPath )
override
702 return wxDIR_CONTINUE;
704 wxFileName destDir( aSrcDirPath );
705 wxString destDirPath = destDir.GetPathWithSep();
706 wxUniChar pathSep = wxFileName::GetPathSeparator();
712 destDir.SetPath( destDirPath );
717 if( destDir.GetExt() ==
"pretty" )
722 else if( destDir.GetExt() ==
"sym_lib_dir_extension" )
727 if( !wxMkdir( destDir.GetFullPath() ) )
734 msg.Printf(
_(
"Cannot copy folder '%s'." ), destDir.GetFullPath() );
738 return wxDIR_CONTINUE;
762 wxFileName currentProjectFile(
Prj().GetProjectFullName() );
763 wxString currentProjectDirPath = currentProjectFile.GetPath();
766 wxString default_dir =
m_frame->GetMruPath();
771 if( default_dir == currentProjectDirPath
772 || default_dir == currentProjectDirPath + wxFileName::GetPathSeparator() )
775 wxFileName default_dir_fn( default_dir );
776 default_dir_fn.RemoveLastDir();
777 default_dir = default_dir_fn.GetPath();
780 wxFileDialog dlg(
m_frame,
_(
"Save Project To" ), default_dir, wxEmptyString, wxEmptyString, wxFD_SAVE );
784 if( dlg.ShowModal() == wxID_CANCEL )
787 wxFileName newProjectDir( dlg.GetPath(), wxEmptyString );
789 if( !newProjectDir.IsAbsolute() )
790 newProjectDir.MakeAbsolute();
792 if( wxDirExists( newProjectDir.GetFullPath() ) )
794 msg.Printf(
_(
"'%s' already exists." ), newProjectDir.GetFullPath() );
799 if( !wxMkdir( newProjectDir.GetFullPath() ) )
802 "Please make sure you have sufficient permissions." ),
803 newProjectDir.GetPath() ) );
807 if( !newProjectDir.IsDirWritable() )
810 newProjectDir.GetFullPath() ) );
814 const wxString& newProjectDirPath = newProjectDir.GetFullPath();
815 const wxString& newProjectName = newProjectDir.GetDirs().Last();
816 wxDir currentProjectDir( currentProjectDirPath );
821 currentProjectDir.Traverse( traverser );
848 if( conditionalMenu )
849 conditionalMenu->Evaluate( dummySel );
881 player =
m_frame->Kiway().Player( playerType,
true );
885 wxLogError(
_(
"Application failed to load:\n" ) + err.
What() );
891 wxLogError(
_(
"Application cannot start." ) );
895 if( !player->IsVisible() )
901 wxFileName kicad_schematic(
m_frame->SchFileName() );
902 wxFileName legacy_schematic(
m_frame->SchLegacyFileName() );
904 if( !legacy_schematic.FileExists() || kicad_schematic.FileExists() )
905 filepath = kicad_schematic.GetFullPath();
907 filepath = legacy_schematic.GetFullPath();
911 wxFileName kicad_board(
m_frame->PcbFileName() );
912 wxFileName legacy_board(
m_frame->PcbLegacyFileName() );
914 if( !legacy_board.FileExists() || kicad_board.FileExists() )
915 filepath = kicad_board.GetFullPath();
917 filepath = legacy_board.GetFullPath();
920 if( !filepath.IsEmpty() )
922 std::vector<wxString> file_list{ filepath };
924 if( !player->OpenProjectFiles( file_list ) )
932 player->Show(
true );
936 if( player->IsIconized() )
937 player->Iconize(
false );
943 if( wxWindow::FindFocus() != player )
947 if(
Pgm().GetCommonSettings()->m_Session.remember_open_files
948 && !player->GetCurrentFileName().IsEmpty()
949 &&
Prj().GetLocalSettings().ShouldAutoSave() )
951 wxFileName rfn( player->GetCurrentFileName() );
952 rfn.MakeRelativeTo(
Prj().GetProjectPath() );
955 player->SaveWindowSettings( &windowSettings );
985 wxFAIL_MSG(
"Execute(): unexpected request" );
987 if( execFile.IsEmpty() )
993 param =
m_frame->Prj().GetProjectPath();
996 return commonControl->
Execute( execFile, param );
1024 std::string payload =
"";
1048 std::string payload =
"";
static TOOL_ACTION zoomRedraw
static TOOL_ACTION saveAs
static TOOL_ACTION updateMenu
Handle actions that are shared between different applications.
int Execute(const TOOL_EVENT &aEvent)
const wxString & GetFullURL() const
KIGIT_COMMON::GIT_CONN_TYPE GetRepoType() const
wxString GetRepoSSHPath() const
wxString GetRepoURL() const
wxString GetUsername() const
wxString GetRepoName() const
wxString GetPassword() const
Implementing pcm main dialog.
const std::unordered_set< PCM_PACKAGE_TYPE > & GetChangedPackageTypes() const
PROJECT_TEMPLATE * GetDefaultTemplate()
PROJECT_TEMPLATE * GetSelectedTemplate()
bool GetCreateNewDir() const
void SetRemote(const wxString &aRemote)
void SetClonePath(const wxString &aPath)
void SetProgressReporter(std::unique_ptr< WX_PROGRESS_REPORTER > aProgressReporter)
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
virtual bool LoadFromFile(const wxString &aDirectory="")
Loads the backing file from disk and then calls Load()
static TOOL_ACTION viewDroppedGerbers
static TOOL_ACTION openDemoProject
static TOOL_ACTION editPCB
static TOOL_ACTION unarchiveProject
static TOOL_ACTION loadProject
static TOOL_ACTION editOtherPCB
static TOOL_ACTION newProject
static TOOL_ACTION editOtherSch
static TOOL_ACTION editSchematic
static TOOL_ACTION openTextEditor
static TOOL_ACTION archiveProject
static TOOL_ACTION openProject
static TOOL_ACTION closeProject
static TOOL_ACTION convertImage
static TOOL_ACTION editDrawingSheet
static TOOL_ACTION openProjectDirectory
static TOOL_ACTION openJobsetFile
static TOOL_ACTION newJobsetFile
static TOOL_ACTION editFootprints
static TOOL_ACTION showPluginManager
static TOOL_ACTION showCalculator
static TOOL_ACTION viewGerbers
static TOOL_ACTION newFromRepository
static TOOL_ACTION editSymbols
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
int OpenProject(const TOOL_EVENT &aEvent)
int NewJobsetFile(const TOOL_EVENT &aEvent)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int OpenDemoProject(const TOOL_EVENT &aEvent)
int CloseProject(const TOOL_EVENT &aEvent)
int ArchiveProject(const TOOL_EVENT &aEvent)
bool m_inShowPlayer
Re-entrancy guard.
int SaveProjectAs(const TOOL_EVENT &aEvent)
int NewProject(const TOOL_EVENT &aEvent)
int UnarchiveProject(const TOOL_EVENT &aEvent)
int ViewDroppedViewers(const TOOL_EVENT &aEvent)
Imports a non kicad project from a sch/pcb dropped file.
int ShowPluginManager(const TOOL_EVENT &aEvent)
Set up handlers for various events.
int UpdateMenu(const TOOL_EVENT &aEvent)
int OpenJobsetFile(const TOOL_EVENT &aEvent)
wxFileName newProjectDirectory(wxString *aFileName=nullptr, bool isRepo=false)
int NewFromRepository(const TOOL_EVENT &aEvent)
int LoadProject(const TOOL_EVENT &aEvent)
KICAD_MANAGER_FRAME * m_frame
Pointer to the currently used edit/draw frame.
int ExploreProject(const TOOL_EVENT &aEvent)
int ShowPlayer(const TOOL_EVENT &aEvent)
int Refresh(const TOOL_EVENT &aEvent)
int openProject(const wxString &aDefaultDir)
int Execute(const TOOL_EVENT &aEvent)
The main KiCad project manager frame.
wxSize m_TemplateWindowSize
wxPoint m_TemplateWindowPos
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
wxString GetErrorString()
void SetPassword(const wxString &aPassword)
Set the password.
std::vector< wxString > GetProjectDirs()
Get a list of project directories.
void SetUsername(const wxString &aUsername)
Set the username.
void SetSSHKey(const wxString &aSSHKey)
Set the SSH key.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
static wxString GetDefaultUserProjectsPath()
Gets the default path we point users to create projects.
static wxString GetStockDemosPath()
Gets the stock (install) demos path.
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
virtual SETTINGS_MANAGER & GetSettingsManager() const
static bool Archive(const wxString &aSrcDir, const wxString &aDestFile, REPORTER &aReporter, bool aVerbose=true, bool aIncludeExtraFiles=false)
Create an archive of the project.
The backing store for a PROJECT, in JSON format.
bool SaveAs(const wxString &aDirectory, const wxString &aFile)
bool SaveToFile(const wxString &aDirectory="", bool aForce=false) override
Calls Store() and then writes the contents of the JSON document to a file.
The project local settings are things that are attached to a particular project, but also might be pa...
bool SaveAs(const wxString &aDirectory, const wxString &aFile)
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
void SaveFileState(const wxString &aFileName, const WINDOW_SETTINGS *aWindowCfg, bool aOpen)
A class which provides project template functionality.
size_t GetDestinationFiles(const wxFileName &aNewProjectPath, std::vector< wxFileName > &aDestFiles)
Fetch the list of destination files to be copied when the new project is created.
bool CreateProject(wxFileName &aNewProjectPath, wxString *aErrorMsg=nullptr)
Copies and renames all template files to create a new project.
PROJECT_TREE_PANE Window to display the tree files.
PROJECT_TREE * m_TreeProject
KIGIT_COMMON * GitCommon() const
virtual void SetElem(PROJECT::ELEM aIndex, _ELEM *aElem)
virtual const wxString GetProjectName() const
Return the short name of the project.
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
virtual PROJECT_FILE & GetProjectFile() const
wxString m_newProjectName
KICAD_MANAGER_FRAME * m_frame
virtual wxDirTraverseResult OnFile(const wxString &aSrcFilePath) override
SAVE_AS_TRAVERSER(KICAD_MANAGER_FRAME *aFrame, const wxString &aSrcProjectDirPath, const wxString &aSrcProjectName, const wxString &aNewProjectDirPath, const wxString &aNewProjectName)
virtual wxDirTraverseResult OnDir(const wxString &aSrcDirPath) override
wxString m_projectDirPath
wxFileName GetNewProjectFile()
wxString m_newProjectDirPath
wxFileName m_newProjectFile
void ReloadColorSettings()
Re-scan the color themes directory, reloading any changes it finds.
A wrapper for reporting to a specific text location in a statusbar.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
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.
This file is part of the common library.
Functions related to environment variables, including help functions.
const wxString EESCHEMA_EXE
const wxString GERBVIEW_EXE
const wxString PL_EDITOR_EXE
const wxString BITMAPCONVERTER_EXE
const wxString PCBNEW_EXE
const wxString PCB_CALCULATOR_EXE
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
@ FRAME_SCH_SYMBOL_EDITOR
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
static const std::string LegacySchematicFileExtension
static const std::string NetlistFileExtension
static const std::string SymbolLibraryTableFileName
static const std::string GerberJobFileExtension
static const std::string LockFileExtension
static const std::string ProjectFileExtension
static const std::string LegacyPcbFileExtension
static const std::string SchematicSymbolFileExtension
static const std::string LegacyProjectFileExtension
static const std::string ProjectLocalSettingsFileExtension
static const std::string KiCadSchematicFileExtension
static const std::string LegacySymbolLibFileExtension
static const std::string LockFilePrefix
static const std::string KiCadSymbolLibFileExtension
static const std::string FootprintLibraryTableFileName
static const std::string DrawingSheetFileExtension
static const std::string BackupFileSuffix
static const std::string LegacyFootprintLibPathExtension
static const std::string LegacySymbolDocumentFileExtension
static const std::string FootprintAssignmentFileExtension
static const std::string DrillFileExtension
static const std::string KiCadFootprintFileExtension
static const std::string ArchiveFileExtension
static const std::string KiCadPcbFileExtension
static wxString ProjectFileWildcard()
static bool IsGerberFileExtension(const wxString &ext)
static wxString JobsetFileWildcard()
static wxString LegacyProjectFileWildcard()
static wxString AllProjectFilesWildcard()
static wxString ZipFileWildcard()
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
static wxFileName ensureDefaultProjectTemplate()
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
KICOMMON_API std::optional< wxString > GetVersionedEnvVarValue(const std::map< wxString, ENV_VAR_ITEM > &aMap, const wxString &aBaseName)
Attempt to retrieve the value of a versioned environment variable, such as KICAD8_TEMPLATE_DIR.
PGM_BASE & Pgm()
The global program "get" accessor.
#define METADIR
A directory which contains information about the project template and does not get copied.
#define METAFILE_INFO_HTML
A required html formatted file which contains information about the project template.
T * GetAppSettings(const char *aFilename)
#define PROJECT_BACKUPS_DIR_SUFFIX
Project settings path will be <projectname> + this.
Implement a participant in the KIWAY alchemy.
virtual void SaveFileAs(const wxString &srcProjectBasePath, const wxString &srcProjectName, const wxString &newProjectBasePath, const wxString &newProjectName, const wxString &srcFilePath, wxString &aErrors)
Saving a file under a different name is delegated to the various KIFACEs because the project doesn't ...
Store the common settings that are saved and loaded for each window / frame.
IFACE KIFACE_BASE kiface("pcb_test_frame", KIWAY::FACE_PCB)
wxString result
Test unit parsing edge cases and error handling.
Definition of file extensions used in Kicad.