47#include <wx/filedlg.h>
62 m_frame = getEditFrame<KICAD_MANAGER_FRAME>();
68 wxString default_filename = aFileName ? *aFileName : wxString();
71 wxFileDialog dlg(
m_frame,
_(
"Create New Project" ), default_dir, default_filename,
73 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
77 dlg.SetCustomizeHook( newProjectHook );
79 if( dlg.ShowModal() == wxID_CANCEL )
82 wxFileName pro( dlg.GetPath() );
87 pro.SetName( pro.GetName() + wxT(
"." ) + pro.GetExt() );
91 if( !pro.IsAbsolute() )
95 bool createNewDir =
false;
100 pro.AppendDir( pro.GetName() );
105 if( !pro.DirExists() )
110 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
111 "Make sure you have write permissions and try again." ),
119 wxString msg =
_(
"The selected folder is not empty. It is recommended that you "
120 "create projects in their own empty folder.\n\n"
121 "Do you want to continue?" );
150 dlg.SetTitle(
_(
"Clone Project from Git Repository" ) );
182 if( projects.empty() )
190 wxString dest = pro.GetPath() + wxFileName::GetPathSeparator() + projects.front();
210 wxString default_dir = wxFileName(
Prj().GetProjectFullName() ).GetPathWithSep();
211 wxFileDialog dlg(
m_frame,
_(
"Create New Jobset" ), default_dir, wxEmptyString,
213 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
215 if( dlg.ShowModal() == wxID_CANCEL )
218 wxFileName jobsetFn( dlg.GetPath() );
232 wxFileName templatePath;
236 wxT(
"TEMPLATE_DIR" ) );
238 if( v && !v->IsEmpty() )
240 templatePath.AssignDir( *v );
241 ps->AddTemplatesPage(
_(
"System Templates" ), templatePath );
247 if( it !=
Pgm().GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString )
249 templatePath.AssignDir( it->second.GetValue() );
250 ps->AddTemplatesPage(
_(
"User Templates" ), templatePath );
254 if( ps->ShowModal() != wxID_OK )
260 if( !ps->GetSelectedTemplate() )
262 wxMessageBox(
_(
"No project template was selected. Cannot generate new project." ),
263 _(
"Error" ), wxOK | wxICON_ERROR,
m_frame );
269 wxString default_dir = wxFileName(
Prj().GetProjectFullName() ).GetPathWithSep();
270 wxString title =
_(
"New Project Folder" );
272 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
276 dlg.SetCustomizeHook( newProjectHook );
278 if( dlg.ShowModal() == wxID_CANCEL )
281 wxFileName fn( dlg.GetPath() );
286 fn.SetName( fn.GetName() + wxT(
"." ) + fn.GetExt() );
290 if( !fn.IsAbsolute() )
293 bool createNewDir =
false;
298 fn.AppendDir( fn.GetName() );
302 if( !fn.DirExists() )
307 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
308 "Make sure you have write permissions and try again." ),
315 if( !fn.IsDirWritable() )
319 msg.Printf(
_(
"Insufficient permissions to write to folder '%s'." ), fn.GetPath() );
320 wxMessageDialog msgDlg(
m_frame, msg,
_(
"Error" ), wxICON_ERROR | wxOK | wxCENTER );
326 std::vector< wxFileName > destFiles;
328 if( ps->GetSelectedTemplate()->GetDestinationFiles( fn, destFiles ) )
330 std::vector<wxFileName> overwrittenFiles;
332 for(
const wxFileName& file : destFiles )
334 if( file.FileExists() )
335 overwrittenFiles.push_back( file );
338 if( !overwrittenFiles.empty() )
340 wxString extendedMsg =
_(
"Overwriting files:" ) +
"\n";
342 for(
const wxFileName& file : overwrittenFiles )
343 extendedMsg +=
"\n" + file.GetFullName();
346 _(
"Similar files already exist in the destination folder." ),
348 wxOK | wxCANCEL | wxICON_WARNING );
349 msgDlg.SetExtendedMessage( extendedMsg );
350 msgDlg.SetOKLabel(
_(
"Overwrite" ) );
362 if( !ps->GetSelectedTemplate()->CreateProject( fn, &errorMsg ) )
364 wxMessageDialog createDlg(
m_frame,
365 _(
"A problem occurred creating new project from template." ),
367 wxOK | wxICON_ERROR );
369 if( !errorMsg.empty() )
370 createDlg.SetExtendedMessage( errorMsg );
372 createDlg.ShowModal();
388 wxFileDialog dlg(
m_frame,
_(
"Open Existing Project" ), aDefaultDir, wxEmptyString, wildcard,
389 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
391 if( dlg.ShowModal() == wxID_CANCEL )
394 wxFileName pro( dlg.GetPath() );
396 if( !pro.IsAbsolute() )
399 if( !pro.FileExists() )
437 wxExecute( *aEvent.
Parameter<wxString*>(), wxEXEC_ASYNC );
445 const wxString& aSrcProjectDirPath,
446 const wxString& aSrcProjectName,
447 const wxString& aNewProjectDirPath,
448 const wxString& aNewProjectName ) :
457 virtual wxDirTraverseResult
OnFile(
const wxString& aSrcFilePath )
override
461 return wxDIR_CONTINUE;
463 wxFileName destFile( aSrcFilePath );
464 wxString ext = destFile.GetExt();
471 wxString destPath = destFile.GetPath();
476 destFile.SetPath( destPath );
496 projectFile.
SaveAs( destFile.GetPath(), destFile.GetName() );
502 projectLocalSettings.
SaveAs( destFile.GetPath(), destFile.GetName() );
514 || destFile.GetName() ==
"sym-lib-table" )
526 || destFile.GetName() ==
"fp-lib-table" )
554 wxString destPath = destFile.GetPathWithSep();
555 wxString destName = destFile.GetName();
556 wxUniChar pathSep = wxFileName::GetPathSeparator();
558 wxString srcProjectFootprintLib = pathSep +
m_projectName +
".pretty" + pathSep;
559 wxString newProjectFootprintLib = pathSep +
m_newProjectName +
".pretty" + pathSep;
564 destPath.Replace( srcProjectFootprintLib, newProjectFootprintLib,
true );
569 destFile.SetPath( destPath );
574 return wxDIR_CONTINUE;
577 virtual wxDirTraverseResult
OnDir(
const wxString& aSrcDirPath )
override
581 return wxDIR_CONTINUE;
583 wxFileName destDir( aSrcDirPath );
584 wxString destDirPath = destDir.GetPathWithSep();
585 wxUniChar pathSep = wxFileName::GetPathSeparator();
591 destDir.SetPath( destDirPath );
596 if( destDir.GetExt() ==
"pretty" )
601 else if( destDir.GetExt() ==
"sym_lib_dir_extension" )
606 if( !wxMkdir( destDir.GetFullPath() ) )
613 msg.Printf(
_(
"Cannot copy folder '%s'." ), destDir.GetFullPath() );
617 return wxDIR_CONTINUE;
641 wxFileName currentProjectFile(
Prj().GetProjectFullName() );
642 wxString currentProjectDirPath = currentProjectFile.GetPath();
650 if( default_dir == currentProjectDirPath
651 || default_dir == currentProjectDirPath + wxFileName::GetPathSeparator() )
654 wxFileName default_dir_fn( default_dir );
655 default_dir_fn.RemoveLastDir();
656 default_dir = default_dir_fn.GetPath();
659 wxFileDialog dlg(
m_frame,
_(
"Save Project To" ), default_dir, wxEmptyString, wxEmptyString,
662 if( dlg.ShowModal() == wxID_CANCEL )
665 wxFileName newProjectDir( dlg.GetPath(), wxEmptyString );
667 if( !newProjectDir.IsAbsolute() )
668 newProjectDir.MakeAbsolute();
670 if( wxDirExists( newProjectDir.GetFullPath() ) )
672 msg.Printf(
_(
"'%s' already exists." ), newProjectDir.GetFullPath() );
677 if( !wxMkdir( newProjectDir.GetFullPath() ) )
679 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
680 "Please make sure you have write permissions and try again." ),
681 newProjectDir.GetPath() );
686 if( !newProjectDir.IsDirWritable() )
688 msg.Printf(
_(
"Insufficient permissions to write to folder '%s'." ),
689 newProjectDir.GetFullPath() );
690 wxMessageDialog msgDlg(
m_frame, msg,
_(
"Error!" ), wxICON_ERROR | wxOK | wxCENTER );
695 const wxString& newProjectDirPath = newProjectDir.GetFullPath();
696 const wxString& newProjectName = newProjectDir.GetDirs().Last();
697 wxDir currentProjectDir( currentProjectDirPath );
700 newProjectDirPath, newProjectName );
702 currentProjectDir.Traverse( traverser );
729 if( conditionalMenu )
730 conditionalMenu->Evaluate( dummySel );
761 const std::lock_guard<std::mutex> lock(
m_loading, std::adopt_lock );
769 wxLogError(
_(
"Application failed to load:\n" ) + err.
What() );
775 wxLogError(
_(
"Application cannot start." ) );
779 if( !player->IsVisible() )
788 if( !legacy_schematic.FileExists() || kicad_schematic.FileExists() )
789 filepath = kicad_schematic.GetFullPath();
791 filepath = legacy_schematic.GetFullPath();
798 if( !legacy_board.FileExists() || kicad_board.FileExists() )
799 filepath = kicad_board.GetFullPath();
801 filepath = legacy_board.GetFullPath();
804 if( !filepath.IsEmpty() )
806 std::vector<wxString> file_list{ filepath };
808 if( !player->OpenProjectFiles( file_list ) )
816 player->Show(
true );
820 if( player->IsIconized() )
821 player->Iconize(
false );
827 if( wxWindow::FindFocus() != player )
831 if(
Pgm().GetCommonSettings()->m_Session.remember_open_files
832 && !player->GetCurrentFileName().IsEmpty() )
834 wxFileName rfn( player->GetCurrentFileName() );
835 rfn.MakeRelativeTo(
Prj().GetProjectPath() );
838 player->SaveWindowSettings( &windowSettings );
881 wxFAIL_MSG(
"Execute(): unexpected request" );
883 if( execFile.IsEmpty() )
893 long pid =
ExecuteFile( execFile, param, callback );
898 wxString script = wxString::Format( wxS(
"tell application \"System Events\"\n"
899 " set frontmost of the first process whose unix id is %l to true\n"
904 wxExecute( wxString::Format(
"osascript -e '%s'", script ) );
939 if( changed.count( PCM_PACKAGE_TYPE::PT_PLUGIN ) )
941 std::string payload =
"";
947 if( changed.count( PCM_PACKAGE_TYPE::PT_LIBRARY )
965 std::string payload =
"";
974 if( changed.count( PCM_PACKAGE_TYPE::PT_COLORTHEME ) )
static TOOL_ACTION zoomRedraw
static TOOL_ACTION saveAs
static TOOL_ACTION updateMenu
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
wxString GetMruPath() const
bool GetCreateNewDir() const
void SetURL(const wxString &aURL)
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 loadProject
static TOOL_ACTION editOtherPCB
static TOOL_ACTION newProject
static TOOL_ACTION editOtherSch
static TOOL_ACTION editSchematic
static TOOL_ACTION openTextEditor
static TOOL_ACTION openProject
static TOOL_ACTION closeProject
static TOOL_ACTION convertImage
static TOOL_ACTION editDrawingSheet
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 SaveProjectAs(const TOOL_EVENT &aEvent)
int NewProject(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)
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 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()
void OpenJobsFile(const wxFileName &aFileName, bool aCreate=false)
const wxString SchFileName()
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)
Checks the 'do not show again' setting for the dialog.
virtual void Reset() override
Reloads global state.
void SetConnType(GIT_CONN_TYPE aConnType)
void SetSSHKey(const wxString &aSSHKey)
void SetUsername(const wxString &aUsername)
std::vector< wxString > GetProjectDirs()
Return a vector of project files in the repository.
void SetPassword(const wxString &aPassword)
wxString GetErrorString()
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
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)
wxString m_GitRepoPassword
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)
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()
Returns a handle to the a given settings by type If the settings have already been loaded,...
void ReloadColorSettings()
Re-scans the color themes directory, reloading any changes it finds.
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 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 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 KiCadPcbFileExtension
static wxString ProjectFileWildcard()
static bool IsGerberFileExtension(const wxString &ext)
static wxString JobsetFileWildcard()
static wxString LegacyProjectFileWildcard()
static wxString AllProjectFilesWildcard()
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
This file is part of the common library.
KICOMMON_API std::optional< wxString > GetVersionedEnvVarValue(const std::map< wxString, ENV_VAR_ITEM > &aMap, const wxString &aBaseName)
Attempts 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 ...
Stores 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.