From 75be90e888dac5a147f9296cde6ee0faf3f4ac58 Mon Sep 17 00:00:00 2001 From: Michael Kavanagh Date: Tue, 5 Mar 2019 17:38:01 +0000 Subject: [PATCH] KiCad Manager: add Save Project As... MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2.17.2 (Apple Git-113)" This is a multi-part message in MIME format. --------------2.17.2 (Apple Git-113) Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit Also fix an error when there is no icon .png in template metadata directory. Fixes: lp:594051 * https://bugs.launchpad.net/kicad/+bug/594051 --- kicad/kicad.h | 11 +++++++++-- kicad/menubar.cpp | 14 ++++++++++++++ kicad/prjconfig.cpp | 20 +++++++++++++++----- kicad/project_template.cpp | 7 ++++++- 4 files changed, 44 insertions(+), 8 deletions(-) --------------2.17.2 (Apple Git-113) Content-Type: text/x-patch; name="0001-KiCad-Manager-add-Save-Project-As.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0001-KiCad-Manager-add-Save-Project-As.patch" diff --git a/kicad/kicad.h b/kicad/kicad.h index 803dcc314..3110027bc 100644 --- a/kicad/kicad.h +++ b/kicad/kicad.h @@ -36,6 +36,7 @@ #include #include #include +#include "project_template.h" #define KICAD_MANAGER_FRAME_NAME wxT( "KicadFrame" ) @@ -150,7 +151,7 @@ public: /** * Creates a new project folder, copy a template into this new folder. - * and open this new projrct as working project + * and open this new project as working project */ void OnCreateProjectFromTemplate( wxCommandEvent& event ); @@ -161,6 +162,12 @@ public: */ void OnSaveProject( wxCommandEvent& event ); + /** + * Creates a copy of the current project with a new name, and open this new project + * as the working project. + */ + void OnSaveProjectAs( wxCommandEvent& event ); + void OnArchiveFiles( wxCommandEvent& event ); void OnUnarchiveFiles( wxCommandEvent& event ); @@ -225,7 +232,7 @@ public: */ void CreateNewProject( const wxFileName& aProjectFileName ); void LoadProject( const wxFileName& aProjectFileName ); - + void CreateProjectFromTemplate( PROJECT_TEMPLATE* ps ); void LoadSettings( wxConfigBase* aCfg ) override; diff --git a/kicad/menubar.cpp b/kicad/menubar.cpp index 182480304..e53d1623f 100644 --- a/kicad/menubar.cpp +++ b/kicad/menubar.cpp @@ -50,6 +50,7 @@ BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME ) // Menu events EVT_MENU( ID_SAVE_PROJECT, KICAD_MANAGER_FRAME::OnSaveProject ) + EVT_MENU( ID_SAVE_PROJECT_AS, KICAD_MANAGER_FRAME::OnSaveProjectAs ) EVT_MENU( wxID_EXIT, KICAD_MANAGER_FRAME::OnExit ) EVT_MENU( ID_TO_TEXT_EDITOR, KICAD_MANAGER_FRAME::OnOpenTextEditor ) EVT_MENU( ID_BROWSE_AN_SELECT_FILE, KICAD_MANAGER_FRAME::OnOpenFileInTextEditor ) @@ -150,6 +151,7 @@ static EDA_HOTKEY HkRunPleditor( _HKI( "Run PlEditor" ), HK_RUN_PLEDITOR, 'Y' + static EDA_HOTKEY HkNewProject( _HKI( "New Project" ), HK_NEW, GR_KB_CTRL + 'N' ); static EDA_HOTKEY HkOpenProject( _HKI( "Open Project" ), HK_OPEN, GR_KB_CTRL + 'O' ); static EDA_HOTKEY HkSaveProject( _HKI( "Save Project" ), HK_SAVE, GR_KB_CTRL + 'S' ); +static EDA_HOTKEY HkSaveProjectAs( _HKI( "Save Project As" ), HK_SAVEAS, GR_KB_CTRL + GR_KB_SHIFT + 'S' ); static EDA_HOTKEY HkHelp( _HKI( "List Hotkeys" ), HK_HELP, GR_KB_CTRL + WXK_F1 ); // List of hotkey descriptors @@ -161,6 +163,7 @@ EDA_HOTKEY* common_Hotkey_List[] = #if 0 &HkSaveProject, #endif + &HkSaveProjectAs, &HkRefresh, &HkHelp, &HkRunEeschema, &HkRunLibedit, &HkRunPcbnew, &HkRunModedit, &HkRunGerbview, @@ -249,6 +252,12 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar() KiBitmap( save_project_xpm ) ); #endif + // Save As + msg = AddHotkeyName( _( "&Save Project As..." ), kicad_Manager_Hokeys_Descr, HK_SAVEAS ); + AddMenuItem( fileMenu, ID_SAVE_PROJECT_AS, msg, + _( "Save a copy of the current project" ), + KiBitmap( save_project_xpm ) ); + fileMenu->AppendSeparator(); wxMenu* importprjSubMenu = new wxMenu(); @@ -489,6 +498,11 @@ void KICAD_MANAGER_FRAME::RecreateBaseHToolbar() _( "Save current project" ) ); #endif + // Save as + m_mainToolBar->AddTool( ID_SAVE_PROJECT_AS, wxEmptyString, + KiScaledBitmap( save_project_xpm, this ), + _( "Save a copy of the current project" ) ); + KiScaledSeparator( m_mainToolBar, this ); // Archive diff --git a/kicad/prjconfig.cpp b/kicad/prjconfig.cpp index b191dd063..0579caf38 100644 --- a/kicad/prjconfig.cpp +++ b/kicad/prjconfig.cpp @@ -41,6 +41,7 @@ #include #include "dialogs/dialog_template_selector.h" +#include "project_template.h" #include "kicad.h" #include "pgm_kicad.h" @@ -314,6 +315,17 @@ void KICAD_MANAGER_FRAME::OnCreateProjectFromTemplate( wxCommandEvent& event ) return; } + CreateProjectFromTemplate( ps->GetSelectedTemplate() ); +} + + +void KICAD_MANAGER_FRAME::OnSaveProjectAs( wxCommandEvent& event ) +{ + PROJECT_TEMPLATE* ps = new PROJECT_TEMPLATE( wxFileName( Prj().GetProjectFullName() ).GetPathWithSep() ); + CreateProjectFromTemplate( ps ); +} + +void KICAD_MANAGER_FRAME::CreateProjectFromTemplate( PROJECT_TEMPLATE* ps ) { // Get project destination folder and project file name. wxString default_dir = wxFileName( Prj().GetProjectFullName() ).GetPathWithSep(); wxString title = _( "New Project Folder" ); @@ -351,7 +363,7 @@ void KICAD_MANAGER_FRAME::OnCreateProjectFromTemplate( wxCommandEvent& event ) // Make sure we are not overwriting anything in the destination folder. std::vector< wxFileName > destFiles; - if( ps->GetSelectedTemplate()->GetDestinationFiles( fn, destFiles ) ) + if( ps->GetDestinationFiles( fn, destFiles ) ) { std::vector< wxFileName > overwrittenFiles; @@ -369,7 +381,7 @@ void KICAD_MANAGER_FRAME::OnCreateProjectFromTemplate( wxCommandEvent& event ) extendedMsg += "\n" + file.GetFullName(); KIDIALOG msgDlg( this, _( "Similar files already exist in the destination folder." ), - _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING ); + _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING ); msgDlg.SetExtendedMessage( extendedMsg ); msgDlg.SetOKLabel( _( "Overwrite" ) ); msgDlg.DoNotShowCheckbox( __FILE__, __LINE__ ); @@ -381,9 +393,7 @@ void KICAD_MANAGER_FRAME::OnCreateProjectFromTemplate( wxCommandEvent& event ) wxString errorMsg; - // The selected template widget contains the template we're attempting to use to - // create a project - if( !ps->GetSelectedTemplate()->CreateProject( fn, &errorMsg ) ) + if( !ps->CreateProject( fn, &errorMsg ) ) { wxMessageDialog createDlg( this, _( "A problem occurred creating new project from template!" ), diff --git a/kicad/project_template.cpp b/kicad/project_template.cpp index af82fc824..0e5a2a955 100644 --- a/kicad/project_template.cpp +++ b/kicad/project_template.cpp @@ -64,7 +64,12 @@ PROJECT_TEMPLATE::PROJECT_TEMPLATE( const wxString& aPath ) } // Try to load an icon - metaIcon = new wxBitmap( templateMetaIconFile.GetFullPath(), wxBITMAP_TYPE_PNG ); + if( !wxFileName::FileExists( templateMetaIconFile.GetFullPath() ) ) + { + metaIcon = &wxNullBitmap; + } + else + metaIcon = new wxBitmap( templateMetaIconFile.GetFullPath(), wxBITMAP_TYPE_PNG ); } --------------2.17.2 (Apple Git-113)--