48#include <wx/filedlg.h>
67 m_frame = getEditFrame<KICAD_MANAGER_FRAME>();
73 wxString default_filename = aFileName ? *aFileName : wxString();
76 wxFileDialog dlg(
m_frame,
_(
"Create New Project" ), default_dir, default_filename,
78 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
82 dlg.SetCustomizeHook( newProjectHook );
84 if( dlg.ShowModal() == wxID_CANCEL )
87 wxFileName pro( dlg.GetPath() );
92 pro.SetName( pro.GetName() + wxT(
"." ) + pro.GetExt() );
96 if( !pro.IsAbsolute() )
100 bool createNewDir =
false;
105 pro.AppendDir( pro.GetName() );
110 if( !pro.DirExists() )
115 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
116 "Make sure you have write permissions and try again." ),
124 wxString msg =
_(
"The selected folder is not empty. It is recommended that you "
125 "create projects in their own empty folder.\n\n"
126 "Do you want to continue?" );
155 dlg.SetTitle(
_(
"Clone Project from Git Repository" ) );
189 if( projects.empty() )
197 wxString dest = pro.GetPath() + wxFileName::GetPathSeparator() + projects.front();
217 wxString default_dir = wxFileName(
Prj().GetProjectFullName() ).GetPathWithSep();
218 wxFileDialog dlg(
m_frame,
_(
"Create New Jobset" ), default_dir, wxEmptyString,
220 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
222 if( dlg.ShowModal() == wxID_CANCEL )
225 wxFileName jobsetFn( dlg.GetPath() );
237 std::map<wxString, wxFileName> titleDirMap;
239 wxFileName templatePath;
243 wxT(
"TEMPLATE_DIR" ) );
245 if( v && !v->IsEmpty() )
247 templatePath.AssignDir( *v );
248 titleDirMap.emplace(
_(
"System Templates" ), templatePath );
254 if( it !=
Pgm().GetLocalEnvVariables().
end() && it->second.GetValue() != wxEmptyString )
256 templatePath.AssignDir( it->second.GetValue() );
257 titleDirMap.emplace(
_(
"User Templates" ), templatePath );
269 if( result != wxID_OK )
274 wxMessageBox(
_(
"No project template was selected. Cannot generate new project." ),
275 _(
"Error" ), wxOK | wxICON_ERROR,
m_frame );
281 wxString default_dir = wxFileName(
Prj().GetProjectFullName() ).GetPathWithSep();
282 wxString title =
_(
"New Project Folder" );
284 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
288 dlg.SetCustomizeHook( newProjectHook );
290 if( dlg.ShowModal() == wxID_CANCEL )
293 wxFileName fn( dlg.GetPath() );
298 fn.SetName( fn.GetName() + wxT(
"." ) + fn.GetExt() );
302 if( !fn.IsAbsolute() )
305 bool createNewDir =
false;
310 fn.AppendDir( fn.GetName() );
314 if( !fn.DirExists() )
319 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
320 "Make sure you have write permissions and try again." ),
327 if( !fn.IsDirWritable() )
331 msg.Printf(
_(
"Insufficient permissions to write to folder '%s'." ), fn.GetPath() );
332 wxMessageDialog msgDlg(
m_frame, msg,
_(
"Error" ), wxICON_ERROR | wxOK | wxCENTER );
338 std::vector< wxFileName > destFiles;
342 std::vector<wxFileName> overwrittenFiles;
344 for(
const wxFileName& file : destFiles )
346 if( file.FileExists() )
347 overwrittenFiles.push_back( file );
350 if( !overwrittenFiles.empty() )
352 wxString extendedMsg =
_(
"Overwriting files:" ) +
"\n";
354 for(
const wxFileName& file : overwrittenFiles )
355 extendedMsg +=
"\n" + file.GetFullName();
358 _(
"Similar files already exist in the destination folder." ),
360 wxOK | wxCANCEL | wxICON_WARNING );
361 msgDlg.SetExtendedMessage( extendedMsg );
362 msgDlg.SetOKLabel(
_(
"Overwrite" ) );
376 wxMessageDialog createDlg(
m_frame,
377 _(
"A problem occurred creating new project from template." ),
379 wxOK | wxICON_ERROR );
381 if( !errorMsg.empty() )
382 createDlg.SetExtendedMessage( errorMsg );
384 createDlg.ShowModal();
400 wxFileDialog dlg(
m_frame,
_(
"Open Existing Project" ), aDefaultDir, wxEmptyString, wildcard,
401 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
403 if( dlg.ShowModal() == wxID_CANCEL )
406 wxFileName pro( dlg.GetPath() );
408 if( !pro.IsAbsolute() )
411 if( !pro.FileExists() )
434 wxString default_dir = wxFileName(
Prj().GetProjectFullName() ).GetPathWithSep();
435 wxFileDialog dlg(
m_frame,
_(
"Open Jobset" ), default_dir, wxEmptyString,
438 if( dlg.ShowModal() == wxID_CANCEL )
441 wxFileName jobsetFn( dlg.GetPath() );
470 wxFileDialog dlg(
m_frame,
_(
"Archive Project Files" ),
471 fileName.GetPath(), fileName.GetFullName(),
474 if( dlg.ShowModal() == wxID_CANCEL )
477 wxFileName zipFile = dlg.GetPath();
479 wxString currdirname = fileName.GetPathWithSep();
480 wxDir dir( currdirname );
482 if( !dir.IsOpened() )
488 archiver.
Archive( currdirname, zipFile.GetFullPath(), reporter,
true,
true );
511 wxExecute( *aEvent.
Parameter<wxString*>(), wxEXEC_ASYNC );
519 const wxString& aSrcProjectDirPath,
520 const wxString& aSrcProjectName,
521 const wxString& aNewProjectDirPath,
522 const wxString& aNewProjectName ) :
531 virtual wxDirTraverseResult
OnFile(
const wxString& aSrcFilePath )
override
535 return wxDIR_CONTINUE;
537 wxFileName destFile( aSrcFilePath );
538 wxString ext = destFile.GetExt();
545 wxString destPath = destFile.GetPath();
550 destFile.SetPath( destPath );
570 projectFile.
SaveAs( destFile.GetPath(), destFile.GetName() );
576 projectLocalSettings.
SaveAs( destFile.GetPath(), destFile.GetName() );
628 wxString destPath = destFile.GetPathWithSep();
629 wxString destName = destFile.GetName();
630 wxUniChar pathSep = wxFileName::GetPathSeparator();
632 wxString srcProjectFootprintLib = pathSep +
m_projectName +
".pretty" + pathSep;
633 wxString newProjectFootprintLib = pathSep +
m_newProjectName +
".pretty" + pathSep;
638 destPath.Replace( srcProjectFootprintLib, newProjectFootprintLib,
true );
643 destFile.SetPath( destPath );
648 return wxDIR_CONTINUE;
651 virtual wxDirTraverseResult
OnDir(
const wxString& aSrcDirPath )
override
655 return wxDIR_CONTINUE;
657 wxFileName destDir( aSrcDirPath );
658 wxString destDirPath = destDir.GetPathWithSep();
659 wxUniChar pathSep = wxFileName::GetPathSeparator();
665 destDir.SetPath( destDirPath );
670 if( destDir.GetExt() ==
"pretty" )
675 else if( destDir.GetExt() ==
"sym_lib_dir_extension" )
680 if( !wxMkdir( destDir.GetFullPath() ) )
687 msg.Printf(
_(
"Cannot copy folder '%s'." ), destDir.GetFullPath() );
691 return wxDIR_CONTINUE;
715 wxFileName currentProjectFile(
Prj().GetProjectFullName() );
716 wxString currentProjectDirPath = currentProjectFile.GetPath();
724 if( default_dir == currentProjectDirPath
725 || default_dir == currentProjectDirPath + wxFileName::GetPathSeparator() )
728 wxFileName default_dir_fn( default_dir );
729 default_dir_fn.RemoveLastDir();
730 default_dir = default_dir_fn.GetPath();
733 wxFileDialog dlg(
m_frame,
_(
"Save Project To" ), default_dir, wxEmptyString, wxEmptyString,
736 if( dlg.ShowModal() == wxID_CANCEL )
739 wxFileName newProjectDir( dlg.GetPath(), wxEmptyString );
741 if( !newProjectDir.IsAbsolute() )
742 newProjectDir.MakeAbsolute();
744 if( wxDirExists( newProjectDir.GetFullPath() ) )
746 msg.Printf(
_(
"'%s' already exists." ), newProjectDir.GetFullPath() );
751 if( !wxMkdir( newProjectDir.GetFullPath() ) )
753 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
754 "Please make sure you have write permissions and try again." ),
755 newProjectDir.GetPath() );
760 if( !newProjectDir.IsDirWritable() )
762 msg.Printf(
_(
"Insufficient permissions to write to folder '%s'." ),
763 newProjectDir.GetFullPath() );
764 wxMessageDialog msgDlg(
m_frame, msg,
_(
"Error!" ), wxICON_ERROR | wxOK | wxCENTER );
769 const wxString& newProjectDirPath = newProjectDir.GetFullPath();
770 const wxString& newProjectName = newProjectDir.GetDirs().Last();
771 wxDir currentProjectDir( currentProjectDirPath );
774 newProjectDirPath, newProjectName );
776 currentProjectDir.Traverse( traverser );
803 if( conditionalMenu )
804 conditionalMenu->Evaluate( dummySel );
835 const std::lock_guard<std::mutex> lock(
m_loading, std::adopt_lock );
843 wxLogError(
_(
"Application failed to load:\n" ) + err.
What() );
849 wxLogError(
_(
"Application cannot start." ) );
853 if( !player->IsVisible() )
862 if( !legacy_schematic.FileExists() || kicad_schematic.FileExists() )
863 filepath = kicad_schematic.GetFullPath();
865 filepath = legacy_schematic.GetFullPath();
872 if( !legacy_board.FileExists() || kicad_board.FileExists() )
873 filepath = kicad_board.GetFullPath();
875 filepath = legacy_board.GetFullPath();
878 if( !filepath.IsEmpty() )
880 std::vector<wxString> file_list{ filepath };
882 if( !player->OpenProjectFiles( file_list ) )
890 player->Show(
true );
894 if( player->IsIconized() )
895 player->Iconize(
false );
901 if( wxWindow::FindFocus() != player )
905 if(
Pgm().GetCommonSettings()->m_Session.remember_open_files
906 && !player->GetCurrentFileName().IsEmpty()
907 &&
Prj().GetLocalSettings().ShouldAutoSave() )
909 wxFileName rfn( player->GetCurrentFileName() );
910 rfn.MakeRelativeTo(
Prj().GetProjectPath() );
913 player->SaveWindowSettings( &windowSettings );
956 wxFAIL_MSG(
"Execute(): unexpected request" );
958 if( execFile.IsEmpty() )
968 long pid =
ExecuteFile( execFile, param, callback );
973 wxString script = wxString::Format( wxS(
"tell application \"System Events\"\n"
974 " set frontmost of the first process whose unix id is %l to true\n"
979 wxExecute( wxString::Format(
"osascript -e '%s'", script ) );
1014 if( changed.count( PCM_PACKAGE_TYPE::PT_PLUGIN ) || changed.count( PCM_PACKAGE_TYPE::PT_FAB ) )
1016 std::string payload =
"";
1023 if( changed.count( PCM_PACKAGE_TYPE::PT_LIBRARY )
1041 std::string payload =
"";
1050 if( changed.count( PCM_PACKAGE_TYPE::PT_COLORTHEME ) )
static TOOL_ACTION zoomRedraw
static TOOL_ACTION saveAs
static TOOL_ACTION updateMenu
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
T * GetAppSettings(const wxString &aFilename)
Return a handle to the a given settings by type.
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.
void OnTerminate(int pid, int status) override
TERMINATE_HANDLER(const wxString &appName)
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)
int ExecuteFile(const wxString &aEditorName, const wxString &aFileName, wxProcess *aCallback, bool aFileForKicad)
Call the executable file aEditorName with the parameter aFileName.
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.