50#include <wx/filedlg.h>
69 m_frame = getEditFrame<KICAD_MANAGER_FRAME>();
75 wxString default_filename = aFileName ? *aFileName : wxString();
78 wxFileDialog dlg(
m_frame,
_(
"Create New Project" ), default_dir, default_filename,
80 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
84 dlg.SetCustomizeHook( newProjectHook );
86 if( dlg.ShowModal() == wxID_CANCEL )
89 wxFileName pro( dlg.GetPath() );
94 pro.SetName( pro.GetName() + wxT(
"." ) + pro.GetExt() );
98 if( !pro.IsAbsolute() )
102 bool createNewDir =
false;
107 pro.AppendDir( pro.GetName() );
112 if( !pro.DirExists() )
117 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
118 "Make sure you have write permissions and try again." ),
126 wxString msg =
_(
"The selected folder is not empty. It is recommended that you "
127 "create projects in their own empty folder.\n\n"
128 "Do you want to continue?" );
157 dlg.SetTitle(
_(
"Clone Project from Git Repository" ) );
192 if( projects.empty() )
200 wxString dest = pro.GetPath() + wxFileName::GetPathSeparator() + projects.front();
220 wxString default_dir = wxFileName(
Prj().GetProjectFullName() ).GetPathWithSep();
221 wxFileDialog dlg(
m_frame,
_(
"Create New Jobset" ), default_dir, wxEmptyString,
223 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
225 if( dlg.ShowModal() == wxID_CANCEL )
228 wxFileName jobsetFn( dlg.GetPath() );
238 KICAD_SETTINGS* settings = GetAppSettings<KICAD_SETTINGS>(
"kicad" );
239 std::map<wxString, wxFileName> titleDirMap;
240 wxFileName templatePath;
244 wxT(
"TEMPLATE_DIR" ) );
246 if( v && !v->IsEmpty() )
248 templatePath.AssignDir( *v );
249 titleDirMap.emplace(
_(
"System Templates" ), templatePath );
255 if( it !=
Pgm().GetLocalEnvVariables().
end() && it->second.GetValue() != wxEmptyString )
257 templatePath.AssignDir( it->second.GetValue() );
258 titleDirMap.emplace(
_(
"User Templates" ), templatePath );
270 if( result != wxID_OK )
275 wxMessageBox(
_(
"No project template was selected. Cannot generate new project." ),
276 _(
"Error" ), wxOK | wxICON_ERROR,
m_frame );
282 wxString default_dir = wxFileName(
Prj().GetProjectFullName() ).GetPathWithSep();
283 wxString title =
_(
"New Project Folder" );
285 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
289 dlg.SetCustomizeHook( newProjectHook );
291 if( dlg.ShowModal() == wxID_CANCEL )
294 wxFileName fn( dlg.GetPath() );
299 fn.SetName( fn.GetName() + wxT(
"." ) + fn.GetExt() );
303 if( !fn.IsAbsolute() )
306 bool createNewDir =
false;
311 fn.AppendDir( fn.GetName() );
315 if( !fn.DirExists() )
320 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
321 "Make sure you have write permissions and try again." ),
328 if( !fn.IsDirWritable() )
332 msg.Printf(
_(
"Insufficient permissions to write to folder '%s'." ), fn.GetPath() );
333 wxMessageDialog msgDlg(
m_frame, msg,
_(
"Error" ), wxICON_ERROR | wxOK | wxCENTER );
339 std::vector< wxFileName > destFiles;
343 std::vector<wxFileName> overwrittenFiles;
345 for(
const wxFileName& file : destFiles )
347 if( file.FileExists() )
348 overwrittenFiles.push_back( file );
351 if( !overwrittenFiles.empty() )
353 wxString extendedMsg =
_(
"Overwriting files:" ) +
"\n";
355 for(
const wxFileName& file : overwrittenFiles )
356 extendedMsg +=
"\n" + file.GetFullName();
359 _(
"Similar files already exist in the destination folder." ),
361 wxOK | wxCANCEL | wxICON_WARNING );
362 msgDlg.SetExtendedMessage( extendedMsg );
363 msgDlg.SetOKLabel(
_(
"Overwrite" ) );
377 wxMessageDialog createDlg(
m_frame,
378 _(
"A problem occurred creating new project from template." ),
380 wxOK | wxICON_ERROR );
382 if( !errorMsg.empty() )
383 createDlg.SetExtendedMessage( errorMsg );
385 createDlg.ShowModal();
401 wxFileDialog dlg(
m_frame,
_(
"Open Existing Project" ), aDefaultDir, wxEmptyString, wildcard,
402 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
404 if( dlg.ShowModal() == wxID_CANCEL )
407 wxFileName pro( dlg.GetPath() );
409 if( !pro.IsAbsolute() )
412 if( !pro.FileExists() )
435 wxString default_dir = wxFileName(
Prj().GetProjectFullName() ).GetPathWithSep();
436 wxFileDialog dlg(
m_frame,
_(
"Open Jobset" ), default_dir, wxEmptyString,
439 if( dlg.ShowModal() == wxID_CANCEL )
442 wxFileName jobsetFn( dlg.GetPath() );
471 wxFileDialog dlg(
m_frame,
_(
"Archive Project Files" ),
472 fileName.GetPath(), fileName.GetFullName(),
475 if( dlg.ShowModal() == wxID_CANCEL )
478 wxFileName zipFile = dlg.GetPath();
480 wxString currdirname = fileName.GetPathWithSep();
481 wxDir dir( currdirname );
483 if( !dir.IsOpened() )
489 archiver.
Archive( currdirname, zipFile.GetFullPath(), reporter,
true,
true );
512 wxExecute( *aEvent.
Parameter<wxString*>(), wxEXEC_ASYNC );
520 const wxString& aSrcProjectDirPath,
521 const wxString& aSrcProjectName,
522 const wxString& aNewProjectDirPath,
523 const wxString& aNewProjectName ) :
532 virtual wxDirTraverseResult
OnFile(
const wxString& aSrcFilePath )
override
536 return wxDIR_CONTINUE;
538 wxFileName destFile( aSrcFilePath );
539 wxString ext = destFile.GetExt();
546 wxString destPath = destFile.GetPath();
551 destFile.SetPath( destPath );
571 projectFile.
SaveAs( destFile.GetPath(), destFile.GetName() );
577 projectLocalSettings.
SaveAs( destFile.GetPath(), destFile.GetName() );
629 wxString destPath = destFile.GetPathWithSep();
630 wxString destName = destFile.GetName();
631 wxUniChar pathSep = wxFileName::GetPathSeparator();
633 wxString srcProjectFootprintLib = pathSep +
m_projectName +
".pretty" + pathSep;
634 wxString newProjectFootprintLib = pathSep +
m_newProjectName +
".pretty" + pathSep;
639 destPath.Replace( srcProjectFootprintLib, newProjectFootprintLib,
true );
644 destFile.SetPath( destPath );
649 return wxDIR_CONTINUE;
652 virtual wxDirTraverseResult
OnDir(
const wxString& aSrcDirPath )
override
656 return wxDIR_CONTINUE;
658 wxFileName destDir( aSrcDirPath );
659 wxString destDirPath = destDir.GetPathWithSep();
660 wxUniChar pathSep = wxFileName::GetPathSeparator();
666 destDir.SetPath( destDirPath );
671 if( destDir.GetExt() ==
"pretty" )
676 else if( destDir.GetExt() ==
"sym_lib_dir_extension" )
681 if( !wxMkdir( destDir.GetFullPath() ) )
688 msg.Printf(
_(
"Cannot copy folder '%s'." ), destDir.GetFullPath() );
692 return wxDIR_CONTINUE;
716 wxFileName currentProjectFile(
Prj().GetProjectFullName() );
717 wxString currentProjectDirPath = currentProjectFile.GetPath();
725 if( default_dir == currentProjectDirPath
726 || default_dir == currentProjectDirPath + wxFileName::GetPathSeparator() )
729 wxFileName default_dir_fn( default_dir );
730 default_dir_fn.RemoveLastDir();
731 default_dir = default_dir_fn.GetPath();
734 wxFileDialog dlg(
m_frame,
_(
"Save Project To" ), default_dir, wxEmptyString, wxEmptyString,
737 if( dlg.ShowModal() == wxID_CANCEL )
740 wxFileName newProjectDir( dlg.GetPath(), wxEmptyString );
742 if( !newProjectDir.IsAbsolute() )
743 newProjectDir.MakeAbsolute();
745 if( wxDirExists( newProjectDir.GetFullPath() ) )
747 msg.Printf(
_(
"'%s' already exists." ), newProjectDir.GetFullPath() );
752 if( !wxMkdir( newProjectDir.GetFullPath() ) )
754 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
755 "Please make sure you have write permissions and try again." ),
756 newProjectDir.GetPath() );
761 if( !newProjectDir.IsDirWritable() )
763 msg.Printf(
_(
"Insufficient permissions to write to folder '%s'." ),
764 newProjectDir.GetFullPath() );
765 wxMessageDialog msgDlg(
m_frame, msg,
_(
"Error!" ), wxICON_ERROR | wxOK | wxCENTER );
770 const wxString& newProjectDirPath = newProjectDir.GetFullPath();
771 const wxString& newProjectName = newProjectDir.GetDirs().Last();
772 wxDir currentProjectDir( currentProjectDirPath );
775 newProjectDirPath, newProjectName );
777 currentProjectDir.Traverse( traverser );
804 if( conditionalMenu )
805 conditionalMenu->Evaluate( dummySel );
836 const std::lock_guard<std::mutex> lock(
m_loading, std::adopt_lock );
844 wxLogError(
_(
"Application failed to load:\n" ) + err.
What() );
850 wxLogError(
_(
"Application cannot start." ) );
854 if( !player->IsVisible() )
863 if( !legacy_schematic.FileExists() || kicad_schematic.FileExists() )
864 filepath = kicad_schematic.GetFullPath();
866 filepath = legacy_schematic.GetFullPath();
873 if( !legacy_board.FileExists() || kicad_board.FileExists() )
874 filepath = kicad_board.GetFullPath();
876 filepath = legacy_board.GetFullPath();
879 if( !filepath.IsEmpty() )
881 std::vector<wxString> file_list{ filepath };
883 if( !player->OpenProjectFiles( file_list ) )
891 player->Show(
true );
895 if( player->IsIconized() )
896 player->Iconize(
false );
902 if( wxWindow::FindFocus() != player )
906 if(
Pgm().GetCommonSettings()->m_Session.remember_open_files
907 && !player->GetCurrentFileName().IsEmpty()
908 &&
Prj().GetLocalSettings().ShouldAutoSave() )
910 wxFileName rfn( player->GetCurrentFileName() );
911 rfn.MakeRelativeTo(
Prj().GetProjectPath() );
914 player->SaveWindowSettings( &windowSettings );
944 wxFAIL_MSG(
"Execute(): unexpected request" );
946 if( execFile.IsEmpty() )
955 return commonControl->
Execute( execFile, param );
981 if( changed.count( PCM_PACKAGE_TYPE::PT_PLUGIN ) || changed.count( PCM_PACKAGE_TYPE::PT_FAB ) )
983 std::string payload =
"";
987 KICAD_SETTINGS* settings = GetAppSettings<KICAD_SETTINGS>(
"kicad" );
989 if( changed.count( PCM_PACKAGE_TYPE::PT_LIBRARY )
1007 std::string payload =
"";
1016 if( changed.count( PCM_PACKAGE_TYPE::PT_COLORTHEME ) )
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 * GetSelectedTemplate()
wxString GetMruPath() const
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 newFromTemplate
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)
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 NewFromTemplate(const TOOL_EVENT &aEvent)
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.
void CreateNewProject(const wxFileName &aProjectFileName, bool aCreateStubFiles=true)
Creates a new project by setting up and initial project, schematic, and board files.
const wxString SchLegacyFileName()
wxWindow * GetToolCanvas() const override
Canvas access.
const wxString GetProjectFileName() const
const wxString SchFileName()
void OpenJobsFile(const wxFileName &aFileName, bool aCreate=false, bool aResaveProjectPreferences=true)
void LoadProject(const wxFileName &aProjectFileName)
std::shared_ptr< PLUGIN_CONTENT_MANAGER > GetPcm()
const wxString PcbLegacyFileName()
bool CloseProject(bool aSave)
Closes the project, and saves it if aSave is true;.
void RefreshProjectTree()
const wxString PcbFileName()
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.
virtual void Reset() override
Reloads global state.
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.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
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 KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
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 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)
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 GetProjectPath() const
Return the full path of the project.
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
This file is part of the common library.
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 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)
Definition of file extensions used in Kicad.