From 71d2467963ba9e4c91a46087a992b8af8d7611a0 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Fri, 14 Dec 2012 12:14:28 -0600 Subject: [PATCH] minor file save as fixes, move legacy header into its plugin --- pcbnew/files.cpp | 31 +++++++++++++++++-------------- pcbnew/legacy_plugin.cpp | 18 +++++++++++++++--- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 18f418c826..69fb123d87 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -415,13 +415,22 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF wildcard << wxGetTranslation( PcbFileWildcard ) << wxChar( '|' ) << wxGetTranslation( LegacyPcbFileWildcard ); - wxFileDialog dlg( this, _( "Save Board File" ), wxEmptyString, GetBoard()->GetFileName(), - wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); + wxFileDialog dlg( this, _( "Save Board File As" ), wxEmptyString, GetBoard()->GetFileName(), + wildcard, wxFD_SAVE + /* wxFileDialog is not equipped to handle multiple wildcards and + wxFD_OVERWRITE_PROMPT both together. + | wxFD_OVERWRITE_PROMPT + */ + ); if( dlg.ShowModal() != wxID_OK ) return false; - pluginType = ( dlg.GetFilterIndex() == 1 ) ? IO_MGR::LEGACY : IO_MGR::KICAD; + int filterNdx = dlg.GetFilterIndex(); + + pluginType = ( filterNdx == 1 ) ? IO_MGR::LEGACY : IO_MGR::KICAD; + + // Note: on Linux wxFileDialog is not reliable for noticing a changed filename. pcbFileName = dlg.GetPath(); @@ -492,21 +501,15 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF try { - PROPERTIES props; - PLUGIN* plugin = IO_MGR::PluginFind( pluginType ); + PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) ); - if( plugin == NULL ) + /* + if( (PLUGIN*)pi == NULL ) THROW_IO_ERROR( wxString::Format( _( "cannot find file plug in for file format '%s'" ), GetChars( pcbFileName.GetExt() ) ) ); + */ - wxString header = wxString::Format( - wxT( "PCBNEW-BOARD Version %d\n# Created by Pcbnew%s\n\n" ), - LEGACY_BOARD_FILE_VERSION, - GetBuildVersion().GetData() ); - - props["header"] = header; - - plugin->Save( pcbFileName.GetFullPath(), GetBoard(), &props ); + pi->Save( pcbFileName.GetFullPath(), GetBoard(), NULL ); } catch( IO_ERROR ioe ) { diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp index 97b84503a3..0c90cabb94 100644 --- a/pcbnew/legacy_plugin.cpp +++ b/pcbnew/legacy_plugin.cpp @@ -62,6 +62,7 @@ #include #include #include +#include #include // implement this here @@ -83,8 +84,7 @@ #include #include #include - -#include +#include typedef LEGACY_PLUGIN::BIU BIU; @@ -2823,14 +2823,26 @@ void LEGACY_PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, PROPERTIES* m_fp = fp; // member function accessibility +#if 0 // old school, property "header" was not used by any other plugin. if( m_props ) { - // @todo move the header production into this source file. wxString header = (*m_props)["header"]; + // save a file header, if caller provided one (with trailing \n hopefully). fprintf( m_fp, "%s", TO_UTF8( header ) ); } +#else + + wxString header = wxString::Format( + wxT( "PCBNEW-BOARD Version %d date %s\n\n# Created by Pcbnew%s\n\n" ), + LEGACY_BOARD_FILE_VERSION, DateAndTime().GetData(), + GetBuildVersion().GetData() ); + + // save a file header, if caller provided one (with trailing \n hopefully). + fprintf( m_fp, "%s", TO_UTF8( header ) ); +#endif + SaveBOARD( aBoard ); }