Commit a564d2f8 authored by Dick Hollenbeck's avatar Dick Hollenbeck

minor file save as fixes, move legacy header into its plugin

parent 79b48462
...@@ -415,13 +415,22 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF ...@@ -415,13 +415,22 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF
wildcard << wxGetTranslation( PcbFileWildcard ) << wxChar( '|' ) << wildcard << wxGetTranslation( PcbFileWildcard ) << wxChar( '|' ) <<
wxGetTranslation( LegacyPcbFileWildcard ); wxGetTranslation( LegacyPcbFileWildcard );
wxFileDialog dlg( this, _( "Save Board File" ), wxEmptyString, GetBoard()->GetFileName(), wxFileDialog dlg( this, _( "Save Board File As" ), wxEmptyString, GetBoard()->GetFileName(),
wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); 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 ) if( dlg.ShowModal() != wxID_OK )
return false; 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(); pcbFileName = dlg.GetPath();
...@@ -492,21 +501,15 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF ...@@ -492,21 +501,15 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF
try try
{ {
PROPERTIES props; PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) );
PLUGIN* plugin = 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'" ), THROW_IO_ERROR( wxString::Format( _( "cannot find file plug in for file format '%s'" ),
GetChars( pcbFileName.GetExt() ) ) ); GetChars( pcbFileName.GetExt() ) ) );
*/
wxString header = wxString::Format( pi->Save( pcbFileName.GetFullPath(), GetBoard(), NULL );
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 );
} }
catch( IO_ERROR ioe ) catch( IO_ERROR ioe )
{ {
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <wx/ffile.h>
#include <legacy_plugin.h> // implement this here #include <legacy_plugin.h> // implement this here
...@@ -83,8 +84,7 @@ ...@@ -83,8 +84,7 @@
#include <drawtxt.h> #include <drawtxt.h>
#include <convert_to_biu.h> #include <convert_to_biu.h>
#include <trigo.h> #include <trigo.h>
#include <build_version.h>
#include <wx/ffile.h>
typedef LEGACY_PLUGIN::BIU BIU; typedef LEGACY_PLUGIN::BIU BIU;
...@@ -2823,14 +2823,26 @@ void LEGACY_PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, PROPERTIES* ...@@ -2823,14 +2823,26 @@ void LEGACY_PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, PROPERTIES*
m_fp = fp; // member function accessibility m_fp = fp; // member function accessibility
#if 0 // old school, property "header" was not used by any other plugin.
if( m_props ) if( m_props )
{ {
// @todo move the header production into this source file.
wxString header = (*m_props)["header"]; wxString header = (*m_props)["header"];
// save a file header, if caller provided one (with trailing \n hopefully). // save a file header, if caller provided one (with trailing \n hopefully).
fprintf( m_fp, "%s", TO_UTF8( header ) ); 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 ); SaveBOARD( aBoard );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment