From 49486b83b0cfa7b229e84556396a1095d13fe8f7 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 6 Mar 2018 16:21:53 +0100 Subject: [PATCH] Add "create a new directory" checkbox to the Create Project dialog Fixes: lp:1753325 * https://bugs.launchpad.net/kicad/+bug/1753325 --- kicad/prjconfig.cpp | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/kicad/prjconfig.cpp b/kicad/prjconfig.cpp index ad16fadc3b..24a127f012 100644 --- a/kicad/prjconfig.cpp +++ b/kicad/prjconfig.cpp @@ -184,12 +184,47 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event ) } +///> Helper widget to select whether a new directory should be created for a project +class DIR_CHECKBOX : public wxPanel +{ +public: + DIR_CHECKBOX( wxWindow* aParent ) + : wxPanel( aParent ) + { + m_cbCreateDir = new wxCheckBox( aParent, wxID_ANY, + _( "Create a new directory for the project" ) ); + m_cbCreateDir->SetValue( true ); + + wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL ); + sizer->Add( m_cbCreateDir ); + + SetSizerAndFit( sizer ); + } + + bool CreateNewDir() const + { + return m_cbCreateDir->GetValue(); + } + + static wxWindow* Create( wxWindow* aParent ) + { + return new DIR_CHECKBOX( aParent ); + } + +protected: + wxCheckBox* m_cbCreateDir; +}; + + void KICAD_MANAGER_FRAME::OnNewProject( wxCommandEvent& aEvent ) { wxString default_dir = GetMruPath(); wxFileDialog dlg( this, _( "Create New Project" ), default_dir, wxEmptyString, ProjectFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); + // Add a "Create a new directory" checkbox + dlg.SetExtraControlCreator( &DIR_CHECKBOX::Create ); + if( dlg.ShowModal() == wxID_CANCEL ) return; @@ -200,7 +235,8 @@ void KICAD_MANAGER_FRAME::OnNewProject( wxCommandEvent& aEvent ) pro.MakeAbsolute(); // Append a new directory with the same name of the project file. - pro.AppendDir( pro.GetName() ); + if( static_cast( dlg.GetExtraControl() )->CreateNewDir() ) + pro.AppendDir( pro.GetName() ); // Check if the project directory is empty if it already exists. wxDir directory( pro.GetPath() );