53#include <wx/filedlg.h>
80 wxString default_filename = aFileName ? *aFileName : wxString();
82 wxString default_dir =
m_frame->GetMruPath();
83 wxFileDialog dlg(
m_frame,
_(
"Create New Project" ), default_dir, default_filename,
85 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
91 dlg.SetCustomizeHook( newProjectHook );
95 if( dlg.ShowModal() == wxID_CANCEL )
98 wxFileName pro( dlg.GetPath() );
103 pro.SetName( pro.GetName() + wxT(
"." ) + pro.GetExt() );
107 if( !pro.IsAbsolute() )
111 bool createNewDir =
false;
116 pro.AppendDir( pro.GetName() );
121 if( !pro.DirExists() )
126 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
127 "Make sure you have write permissions and try again." ),
135 wxString msg =
_(
"The selected folder is not empty. It is recommended that you "
136 "create projects in their own empty folder.\n\n"
137 "Do you want to continue?" );
151 if( it ==
Pgm().GetLocalEnvVariables().
end() || it->second.GetValue() == wxEmptyString )
161 if( resolved.Contains( wxT(
"${" ) ) || resolved.Contains( wxT(
"$(" ) ) )
164 wxFileName templatePath;
165 templatePath.AssignDir( resolved );
167 templatePath.AppendDir(
"default" );
169 if( !templatePath.DirExists() && !templatePath.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
172 wxFileName metaDir = templatePath;
175 if( !metaDir.DirExists() && !metaDir.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
178 wxFileName infoFile = metaDir;
181 if( !infoFile.FileExists() )
183 wxFFile
info( infoFile.GetFullPath(), wxT(
"w" ) );
185 if( !
info.IsOpened() )
188 info.Write( wxT(
"<html><head><title>Default</title></head><body><h3>Default KiCad project template.</h3></body></html>" ) );
192 wxFileName proFile = templatePath;
193 proFile.SetFullName( wxT(
"default.kicad_pro" ) );
195 if( !proFile.FileExists() )
197 wxFFile proj( proFile.GetFullPath(), wxT(
"w" ) );
199 if( !proj.IsOpened() )
202 proj.Write( wxT(
"{}" ) );
206 if( infoFile.FileExists() && proFile.FileExists() )
216 if( !defaultTemplate.IsOk() )
223 m_frame->CreateNewProject( pro );
231 wxString userTemplatesPath;
232 wxString systemTemplatesPath;
234 auto resolveTemplateDir = [](
const wxString& aValue ) -> wxString
240 if( resolved.Contains( wxT(
"${" ) ) || resolved.Contains( wxT(
"$(" ) ) )
241 return wxEmptyString;
243 wxFileName templatePath;
244 templatePath.AssignDir( resolved );
246 return templatePath.GetFullPath();
251 if( itUser !=
Pgm().GetLocalEnvVariables().
end() && itUser->second.GetValue() != wxEmptyString )
252 userTemplatesPath = resolveTemplateDir( itUser->second.GetValue() );
255 wxT(
"TEMPLATE_DIR" ) );
257 if( v && !v->IsEmpty() )
258 systemTemplatesPath = resolveTemplateDir( *v );
264 wxString selectedTemplatePath;
265 wxPoint templateWindowPos;
266 wxSize templateWindowSize;
267 wxString projectToEdit;
277 templateWindowPos = ps.GetPosition();
278 templateWindowSize = ps.GetSize();
286 htmlFile.RemoveLastDir();
287 selectedTemplatePath = htmlFile.GetPath();
295 if(
result == wxID_APPLY )
297 if( !projectToEdit.IsEmpty() && wxFileExists( projectToEdit ) )
299 m_frame->LoadProject( wxFileName( projectToEdit ) );
307 if( selectedTemplatePath.IsEmpty() )
309 wxMessageBox(
_(
"No project template was selected. Cannot generate new project." ),
_(
"Error" ),
310 wxOK | wxICON_ERROR,
m_frame );
318 wxString default_dir = wxFileName(
Prj().GetProjectFullName() ).GetPathWithSep();
319 wxString title =
_(
"New Project Folder" );
321 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
326 dlg.SetCustomizeHook( newProjectHook );
330 if( dlg.ShowModal() == wxID_CANCEL )
333 wxFileName fn( dlg.GetPath() );
336 fn.SetName( fn.GetName() + wxT(
"." ) + fn.GetExt() );
340 if( !fn.IsAbsolute() )
343 bool createNewDir =
false;
347 fn.AppendDir( fn.GetName() );
349 if( !fn.DirExists() && !fn.Mkdir() )
352 "Make sure you have write permissions and try again." ),
357 if( !fn.IsDirWritable() )
364 std::vector< wxFileName > destFiles;
368 std::vector<wxFileName> overwrittenFiles;
370 for(
const wxFileName& file : destFiles )
372 if( file.FileExists() )
373 overwrittenFiles.push_back( file );
376 if( !overwrittenFiles.empty() )
378 wxString extendedMsg =
_(
"Overwriting files:" ) +
"\n";
380 for(
const wxFileName& file : overwrittenFiles )
381 extendedMsg +=
"\n" + file.GetFullName();
383 KIDIALOG msgDlg(
m_frame,
_(
"Similar files already exist in the destination folder." ),
384 _(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
385 msgDlg.SetExtendedMessage( extendedMsg );
386 msgDlg.SetOKLabel(
_(
"Overwrite" ) );
403 wxFileName templateDir = selectedTemplate.
GetHtmlFile();
404 templateDir.RemoveLastDir();
405 wxString templatePath = templateDir.GetPath();
411 recentTemplates.erase( std::remove( recentTemplates.begin(), recentTemplates.end(), templatePath ),
412 recentTemplates.end() );
413 recentTemplates.insert( recentTemplates.begin(), templatePath );
415 if( recentTemplates.size() > 5 )
416 recentTemplates.resize( 5 );
418 m_frame->CreateNewProject( fn.GetFullPath() );
428 dlg.SetTitle(
_(
"Clone Project from Git Repository" ) );
464 if( projects.empty() )
472 wxString dest = pro.GetPath() + wxFileName::GetPathSeparator() + projects.front();
492 wxString default_dir = wxFileName(
Prj().GetProjectFullName() ).GetPathWithSep();
494 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
498 if( dlg.ShowModal() == wxID_CANCEL )
501 wxFileName jobsetFn( dlg.GetPath() );
504 bool fileExists = wxFileExists( jobsetFn.GetFullPath() );
509 if( !wxRemoveFile( jobsetFn.GetFullPath() ) )
515 m_frame->OpenJobsFile( jobsetFn.GetFullPath(),
true );
529 wxFileDialog dlg(
m_frame,
_(
"Open Existing Project" ), aDefaultDir, wxEmptyString, wildcard,
530 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
536 if( dlg.ShowModal() == wxID_CANCEL )
539 wxFileName pro( dlg.GetPath() );
541 if( !pro.IsAbsolute() )
572 wxString default_dir = wxFileName(
Prj().GetProjectFullName() ).GetPathWithSep();
574 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
578 if( dlg.ShowModal() == wxID_CANCEL )
581 wxFileName jobsetFn( dlg.GetPath() );
583 m_frame->OpenJobsFile( jobsetFn.GetFullPath(),
true );
606 wxFileName fileName =
m_frame->GetProjectFileName();
610 wxFileDialog dlg(
m_frame,
_(
"Archive Project Files" ), fileName.GetPath(), fileName.GetFullName(),
615 if( dlg.ShowModal() == wxID_CANCEL )
618 wxFileName zipFile = dlg.GetPath();
620 wxString currdirname = fileName.GetPathWithSep();
621 wxDir dir( currdirname );
623 if( !dir.IsOpened() )
629 archiver.
Archive( currdirname, zipFile.GetFullPath(),
reporter,
true,
true );
650 m_frame->RestoreLocalHistory();
665 wxExecute( *aEvent.
Parameter<wxString*>(), wxEXEC_ASYNC );
676 wxFileName currentProjectFile(
Prj().GetProjectFullName() );
677 wxString currentProjectDirPath = currentProjectFile.GetPath();
680 wxString default_dir =
m_frame->GetMruPath();
685 if( default_dir == currentProjectDirPath
686 || default_dir == currentProjectDirPath + wxFileName::GetPathSeparator() )
689 wxFileName default_dir_fn( default_dir );
690 default_dir_fn.RemoveLastDir();
691 default_dir = default_dir_fn.GetPath();
694 wxFileDialog dlg(
m_frame,
_(
"Save Project To" ), default_dir, wxEmptyString, wxEmptyString, wxFD_SAVE );
700 if( dlg.ShowModal() == wxID_CANCEL )
703 wxFileName newProjectDir( dlg.GetPath(), wxEmptyString );
705 if( !newProjectDir.IsAbsolute() )
706 newProjectDir.MakeAbsolute();
708 if( wxDirExists( newProjectDir.GetFullPath() ) )
710 msg.Printf(
_(
"'%s' already exists." ), newProjectDir.GetFullPath() );
715 if( !wxMkdir( newProjectDir.GetFullPath() ) )
718 "Please make sure you have sufficient permissions." ),
719 newProjectDir.GetPath() ) );
723 if( !newProjectDir.IsDirWritable() )
726 newProjectDir.GetFullPath() ) );
730 const wxString& newProjectDirPath = newProjectDir.GetFullPath();
731 const wxString& newProjectName = newProjectDir.GetDirs().Last();
732 wxDir currentProjectDir( currentProjectDirPath );
735 newProjectDirPath, newProjectName );
737 currentProjectDir.Traverse( traverser );
764 if( conditionalMenu )
765 conditionalMenu->Evaluate( dummySel );
797 player =
m_frame->Kiway().Player( playerType,
true );
801 wxLogError(
_(
"Application failed to load:\n" ) + err.
What() );
807 wxLogError(
_(
"Application cannot start." ) );
811 if( !player->IsVisible() )
817 wxFileName kicad_schematic(
m_frame->SchFileName() );
818 wxFileName legacy_schematic(
m_frame->SchLegacyFileName() );
820 if( !legacy_schematic.FileExists() || kicad_schematic.FileExists() )
821 filepath = kicad_schematic.GetFullPath();
823 filepath = legacy_schematic.GetFullPath();
827 wxFileName kicad_board(
m_frame->PcbFileName() );
828 wxFileName legacy_board(
m_frame->PcbLegacyFileName() );
830 if( !legacy_board.FileExists() || kicad_board.FileExists() )
831 filepath = kicad_board.GetFullPath();
833 filepath = legacy_board.GetFullPath();
836 if( !filepath.IsEmpty() )
838 std::vector<wxString> file_list{ filepath };
840 if( !player->OpenProjectFiles( file_list ) )
848 player->Show(
true );
852 if( player->IsIconized() )
853 player->Iconize(
false );
859 if( wxWindow::FindFocus() != player )
863 if(
Pgm().GetCommonSettings()->m_Session.remember_open_files
864 && !player->GetCurrentFileName().IsEmpty()
865 &&
Prj().GetLocalSettings().ShouldAutoSave() )
867 wxFileName rfn( player->GetCurrentFileName() );
868 rfn.MakeRelativeTo(
Prj().GetProjectPath() );
871 player->SaveWindowSettings( &windowSettings );
901 wxFAIL_MSG(
"Execute(): unexpected request" );
903 if( execFile.IsEmpty() )
909 param =
m_frame->Prj().GetProjectPath();
912 return commonControl->
Execute( execFile, param );
940 std::string payload =
"";
959 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 * GetSelectedTemplate()
wxString GetProjectToEdit() 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()
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 restoreLocalHistory
static TOOL_ACTION newProject
static TOOL_ACTION editOtherSch
static TOOL_ACTION showLocalHistory
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 ToggleLocalHistory(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 RestoreLocalHistory(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)
std::vector< wxString > m_RecentTemplates
wxSize m_TemplateWindowSize
wxPoint m_TemplateWindowPos
wxString m_LastUsedTemplate
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.
void SetCancelled(bool aCancel)
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 void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr, bool aFromOtherThread=false)
Send aPayload to aDestination from aSource.
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
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.
bool SaveToFile(const wxString &aDirectory="", bool aForce=false) override
Calls Store() and then writes the contents of the JSON document to a file.
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.
wxFileName GetHtmlFile()
Get the full Html filename for the project template.
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
Traverser class to duplicate/copy project or template files with proper renaming.
wxString GetErrors() const
wxFileName GetNewProjectFile() const
KIGIT_COMMON * GitCommon() const
virtual const wxString GetProjectName() const
Return the short name of the project.
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
virtual PROJECT_FILE & GetProjectFile() const
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.
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
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
static const std::string ProjectFileExtension
static const std::string LegacyProjectFileExtension
static const std::string ArchiveFileExtension
static wxString ProjectFileWildcard()
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)
Implement a participant in the KIWAY alchemy.
Store the common settings that are saved and loaded for each window / frame.
IFACE KIFACE_BASE kiface("pcb_test_frame", KIWAY::FACE_PCB)
IbisParser parser & reporter
wxString result
Test unit parsing edge cases and error handling.
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().