Default and most recently used path fixes. (fixes: 1494210)

* Rename Eda_FileSelector to EDA_FILE_SELECTOR.
* Add optional pointer to wxString to save the most recently used path to EDA_FILE_SELECTOR.
* Rename Eda_DirectorySelector to EDA_PATH_SELECTOR.
* Replace wxGetCwd() with wxStandardPaths::GetDocumentsDir().  This fixes the windows issue
  where wxGetCwd() returns the path where the executable files are located.
* Add code to handle most recently used path to EDA_BASE_FRAME.
* Fix string formatting error in kicad/files-io.cpp.
* Remove setting and restoring current working directory when launching GerbView.  Setting the CWD
  has no effect on the launched executable which starts with it's own CWD.
* Allow project path to be passed to GerbView when launched from KiCad.
* Note: this is a work in progress.  Do not expect every path and/or file selection dialog to properly
  update the most recently used path.  The correct solution to this problem requires a much more
  well though out solution which will not happen until after the next stable release.
This commit is contained in:
Wayne Stambaugh 2015-09-25 15:38:09 -04:00
parent be8b0b4823
commit a6a9d8eedf
32 changed files with 292 additions and 224 deletions

View File

@ -651,9 +651,9 @@ void EDA_3D_CANVAS::TakeScreenshot( wxCommandEvent& event )
mask = wxT( "*." ) + file_ext;
fn.SetExt( file_ext );
FullFileName = EDA_FileSelector( _( "3D Image File Name:" ), fn.GetPath(),
fn.GetFullName(), file_ext, mask, this,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT, true );
FullFileName = EDA_FILE_SELECTOR( _( "3D Image File Name:" ), fn.GetPath(),
fn.GetFullName(), file_ext, mask, this,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT, true );
if( FullFileName.IsEmpty() )
return;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 1992-2010 jean-pierre.charras
* Copyright (C) 1992-2010 Kicad Developers, see change_log.txt for contributors.
* Copyright (C) 1992-2015 Kicad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -43,6 +43,7 @@
#include <kiway.h>
#include <kiface_i.h>
#define KEYWORD_FRAME_POSX wxT( "Bmconverter_Pos_x" )
#define KEYWORD_FRAME_POSY wxT( "Bmconverter_Pos_y" )
#define KEYWORD_FRAME_SIZEX wxT( "Bmconverter_Size_x" )
@ -96,7 +97,7 @@ private:
void OnExport( wxCommandEvent& event );
/**
* Generate a schematic library which comtains one component:
* Generate a schematic library which contains one component:
* the logo
*/
void OnExportEeschema();
@ -123,9 +124,9 @@ private:
void OnResolutionChange( wxCommandEvent& event );
// called when texts controls which handle the image resolution
// lose the focus, to ensure the rigyht vaules are displayed
// lose the focus, to ensure the right values are displayed
// because the m_imageDPI are clipped to acceptable values, and
// the text displayed could be differ duringa text edition
// the text displayed could be differ during text edition
// We are using ChangeValue here to avoid generating a wxEVT_TEXT event.
void UpdateDPITextValueX( wxMouseEvent& event )
{
@ -249,7 +250,7 @@ void BM2CMP_FRAME::OnPaint( wxPaintEvent& event )
m_BNPicturePanel->PrepareDC( nb_dc );
// OSX crashes with empty bitmaps (on initial refreshes)
if(m_Pict_Bitmap.IsOk() && m_Greyscale_Bitmap.IsOk() && m_BN_Bitmap.IsOk())
if( m_Pict_Bitmap.IsOk() && m_Greyscale_Bitmap.IsOk() && m_BN_Bitmap.IsOk() )
{
pict_dc.DrawBitmap( m_Pict_Bitmap, 0, 0, false );
greyscale_dc.DrawBitmap( m_Greyscale_Bitmap, 0, 0, false );
@ -258,19 +259,17 @@ void BM2CMP_FRAME::OnPaint( wxPaintEvent& event )
}
/* Called to load a bitmap file
*/
void BM2CMP_FRAME::OnLoadFile( wxCommandEvent& event )
{
wxFileName fn( m_BitmapFileName );
wxString path = fn.GetPath();
if( path.IsEmpty() || !wxDirExists(path) )
path = wxGetCwd();
if( path.IsEmpty() || !wxDirExists( path ) )
path = m_mruPath;
wxFileDialog fileDlg( this, _( "Choose Image" ), path, wxEmptyString,
_( "Image Files " ) + wxImage::GetImageExtWildcard(),
wxFD_OPEN );
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
int diag = fileDlg.ShowModal();
@ -282,6 +281,8 @@ void BM2CMP_FRAME::OnLoadFile( wxCommandEvent& event )
if( !OpenProjectFiles( std::vector<wxString>( 1, fullFilename ) ) )
return;
fn = fullFilename;
m_mruPath = fn.GetPath();
m_buttonExport->Enable( true );
SetStatusText( fullFilename );
Refresh();
@ -349,11 +350,12 @@ bool BM2CMP_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int
return true;
}
void BM2CMP_FRAME::updateImageInfo()
{
// Note: the image resolution text controls are not modified
// here, to avoid a race between text change when entered by user and
// a text change if it is modifed here.
// a text change if it is modified here.
int h = m_Pict_Bitmap.GetHeight();
int w = m_Pict_Bitmap.GetWidth();
int nb = m_Pict_Bitmap.GetDepth();
@ -368,6 +370,7 @@ void BM2CMP_FRAME::updateImageInfo()
(double) h / m_imageDPI.y * 25.4 ) );
}
void BM2CMP_FRAME::OnResolutionChange( wxCommandEvent& event )
{
long tmp;
@ -387,6 +390,7 @@ void BM2CMP_FRAME::OnResolutionChange( wxCommandEvent& event )
updateImageInfo();
}
void BM2CMP_FRAME::Binarize( double aThreshold )
{
unsigned int pixin;
@ -427,10 +431,10 @@ void BM2CMP_FRAME::NegateGreyscaleImage( )
}
}
/* Called on Normal/Negative change option */
void BM2CMP_FRAME::OnOptionsSelection( wxCommandEvent& event )
{
NegateGreyscaleImage( );
NegateGreyscaleImage();
m_Greyscale_Bitmap = wxBitmap( m_Greyscale_Image );
Binarize( (double)m_sliderThreshold->GetValue()/m_sliderThreshold->GetMax() );
Refresh();
@ -498,7 +502,7 @@ void BM2CMP_FRAME::OnExportLogo()
if( outfile == NULL )
{
wxString msg;
msg.Printf( _( "File '%s' could not be created" ), GetChars(m_ConvertedFileName) );
msg.Printf( _( "File '%s' could not be created." ), GetChars( m_ConvertedFileName ) );
wxMessageBox( msg );
return;
}
@ -536,7 +540,7 @@ void BM2CMP_FRAME::OnExportPostScript()
if( outfile == NULL )
{
wxString msg;
msg.Printf( _( "File '%s' could not be created" ), GetChars( m_ConvertedFileName ) );
msg.Printf( _( "File '%s' could not be created." ), GetChars( m_ConvertedFileName ) );
wxMessageBox( msg );
return;
}
@ -554,7 +558,7 @@ void BM2CMP_FRAME::OnExportEeschema()
if( path.IsEmpty() || !wxDirExists(path) )
path = ::wxGetCwd();
wxFileDialog fileDlg( this, _( "Create a lib file for Eeschema" ),
wxFileDialog fileDlg( this, _( "Create a component library file for Eeschema" ),
path, wxEmptyString,
wxGetTranslation( SchematicLibraryFileWildcard ),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
@ -573,7 +577,7 @@ void BM2CMP_FRAME::OnExportEeschema()
if( outfile == NULL )
{
wxString msg;
msg.Printf( _( "File '%s' could not be created" ), GetChars( m_ConvertedFileName ) );
msg.Printf( _( "File '%s' could not be created." ), GetChars( m_ConvertedFileName ) );
wxMessageBox( msg );
return;
}
@ -589,9 +593,9 @@ void BM2CMP_FRAME::OnExportPcbnew()
wxString path = fn.GetPath();
if( path.IsEmpty() || !wxDirExists( path ) )
path = ::wxGetCwd();
path = m_mruPath;
wxFileDialog fileDlg( this, _( "Create a footprint file for PcbNew" ),
wxFileDialog fileDlg( this, _( "Create a footprint file for Pcbnew" ),
path, wxEmptyString,
wxGetTranslation( KiCadFootprintLibFileWildcard ),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
@ -610,13 +614,14 @@ void BM2CMP_FRAME::OnExportPcbnew()
if( outfile == NULL )
{
wxString msg;
msg.Printf( _( "File '%s' could not be created" ), GetChars( m_ConvertedFileName ) );
msg.Printf( _( "File '%s' could not be created." ), GetChars( m_ConvertedFileName ) );
wxMessageBox( msg );
return;
}
ExportFile( outfile, PCBNEW_KICAD_MOD );
fclose( outfile );
m_mruPath = fn.GetPath();
}

View File

@ -33,6 +33,7 @@
#include <wx/clipbrd.h>
#include <wx/statline.h>
#include <wx/platinfo.h>
#include <wx/stdpaths.h>
#include <build_version.h>
#include <fctsys.h>
@ -61,6 +62,8 @@ static const wxChar entryAutoSaveInterval[] = wxT( "AutoSaveInterval" );
/// Configuration file entry for wxAuiManger perspective.
static const wxChar entryPerspective[] = wxT( "Perspective" );
/// Configuration file entry for most recently used path.
static const wxChar entryMruPath[] = wxT( "MostRecentlyUsedPath" );
EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType,
@ -76,7 +79,7 @@ EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType,
m_autoSaveState = false;
m_autoSaveInterval = -1;
m_autoSaveTimer = new wxTimer( this, ID_AUTO_SAVE_TIMER );
m_mruPath = wxStandardPaths::Get().GetDocumentsDir();
minsize.x = 470;
minsize.y = 350;
@ -265,6 +268,7 @@ void EDA_BASE_FRAME::LoadSettings( wxConfigBase* aCfg )
Maximize();
aCfg->Read( baseCfgName + entryPerspective, &m_perspective );
aCfg->Read( baseCfgName + entryMruPath, &m_mruPath );
}
@ -309,6 +313,7 @@ void EDA_BASE_FRAME::SaveSettings( wxConfigBase* aCfg )
// printf( "perspective(%s): %s\n",
// TO_UTF8( m_FrameName + entryPerspective ), TO_UTF8( perspective ) );
aCfg->Write( baseCfgName + entryPerspective, perspective );
aCfg->Write( baseCfgName + entryMruPath, m_mruPath );
}

View File

@ -141,15 +141,15 @@ bool GetAssociatedDocument( wxWindow* aParent,
if( wxIsWild( fullfilename ) )
{
fullfilename = EDA_FileSelector( _( "Doc Files" ),
wxPathOnly( fullfilename ),
fullfilename,
extension,
mask,
aParent,
wxFD_OPEN,
true,
wxPoint( -1, -1 ) );
fullfilename = EDA_FILE_SELECTOR( _( "Doc Files" ),
wxPathOnly( fullfilename ),
fullfilename,
extension,
mask,
aParent,
wxFD_OPEN,
true,
wxPoint( -1, -1 ) );
if( fullfilename.IsEmpty() )
return false;
}

View File

@ -58,26 +58,26 @@ void AddDelimiterString( wxString& string )
}
bool EDA_DirectorySelector( const wxString& Title,
wxString& Path,
int flag,
wxWindow* Frame,
const wxPoint& Pos )
bool EDA_PATH_SELECTOR( const wxString& aTitle,
wxString& aPath,
int aFlags,
wxWindow* aParent,
const wxPoint& aPosition )
{
int ii;
bool selected = false;
wxDirDialog* DirFrame = new wxDirDialog( Frame,
wxString( Title ),
Path,
flag,
Pos );
wxDirDialog* DirFrame = new wxDirDialog( aParent,
aTitle,
aPath,
aFlags,
aPosition );
ii = DirFrame->ShowModal();
if( ii == wxID_OK )
{
Path = DirFrame->GetPath();
aPath = DirFrame->GetPath();
selected = true;
}
@ -86,21 +86,22 @@ bool EDA_DirectorySelector( const wxString& Title,
}
wxString EDA_FileSelector( const wxString& Title,
const wxString& Path,
const wxString& FileName,
const wxString& Ext,
const wxString& Mask,
wxWindow* Frame,
int flag,
const bool keep_working_directory,
const wxPoint& Pos )
wxString EDA_FILE_SELECTOR( const wxString& aTitle,
const wxString& aPath,
const wxString& aFileName,
const wxString& aExtension,
const wxString& aWildcard,
wxWindow* aParent,
int aStyle,
const bool aKeepWorkingDirectory,
const wxPoint& aPosition,
wxString* aMruPath )
{
wxString fullfilename;
wxString curr_cwd = wxGetCwd();
wxString defaultname = FileName;
wxString defaultpath = Path;
wxString dotted_Ext = wxT(".") + Ext;
wxString defaultname = aFileName;
wxString defaultpath = aPath;
wxString dotted_Ext = wxT(".") + aExtension;
#ifdef __WINDOWS__
defaultname.Replace( wxT( "/" ), wxT( "\\" ) );
@ -108,7 +109,12 @@ wxString EDA_FileSelector( const wxString& Title,
#endif
if( defaultpath.IsEmpty() )
defaultpath = wxGetCwd();
{
if( aMruPath == NULL )
defaultpath = wxGetCwd();
else
defaultpath = *aMruPath;
}
wxSetWorkingDirectory( defaultpath );
@ -116,24 +122,30 @@ wxString EDA_FileSelector( const wxString& Title,
printf( "defaultpath=\"%s\" defaultname=\"%s\" Ext=\"%s\" Mask=\"%s\" flag=%d keep_working_directory=%d\n",
TO_UTF8( defaultpath ),
TO_UTF8( defaultname ),
TO_UTF8( Ext ),
TO_UTF8( Mask ),
flag,
keep_working_directory );
TO_UTF8( aExtension ),
TO_UTF8( aWildcard ),
aStyle,
aKeepWorkingDirectory );
#endif
fullfilename = wxFileSelector( wxString( Title ),
fullfilename = wxFileSelector( aTitle,
defaultpath,
defaultname,
dotted_Ext,
Mask,
flag, // open mode wxFD_OPEN, wxFD_SAVE ..
Frame,
Pos.x, Pos.y );
aWildcard,
aStyle, // open mode wxFD_OPEN, wxFD_SAVE ..
aParent,
aPosition.x, aPosition.y );
if( keep_working_directory )
if( aKeepWorkingDirectory )
wxSetWorkingDirectory( curr_cwd );
if( !fullfilename.IsEmpty() && aMruPath )
{
wxFileName fn = fullfilename;
*aMruPath = fn.GetPath();
}
return fullfilename;
}

View File

@ -749,12 +749,12 @@ void EDA_BASE_FRAME::ImportHotkeyConfigFromFile( EDA_HOTKEY_CONFIG* aDescList,
#if 0 // pass in the project dir as an argument
wxString path = wxPathOnly( Prj().GetProjectFullName() );
#else
wxString path = wxGetCwd();
wxString path = GetMruPath();
#endif
wxFileName fn( aDefaultShortname );
fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
wxString filename = EDA_FileSelector( _( "Read Hotkey Configuration File:" ),
wxString filename = EDA_FILE_SELECTOR( _( "Read Hotkey Configuration File:" ),
path,
fn.GetFullPath(),
ext,
@ -767,6 +767,7 @@ void EDA_BASE_FRAME::ImportHotkeyConfigFromFile( EDA_HOTKEY_CONFIG* aDescList,
return;
ReadHotkeyConfigFile( filename, aDescList );
SetMruPath( wxFileName( filename ).GetPath() );
}
@ -779,24 +780,25 @@ void EDA_BASE_FRAME::ExportHotkeyConfigToFile( EDA_HOTKEY_CONFIG* aDescList,
#if 0
wxString path = wxPathOnly( Prj().GetProjectFullName() );
#else
wxString path = wxGetCwd();
wxString path = GetMruPath();
#endif
wxFileName fn( aDefaultShortname );
fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
wxString filename = EDA_FileSelector( _( "Write Hotkey Configuration File:" ),
path,
fn.GetFullPath(),
ext,
mask,
this,
wxFD_SAVE,
true );
wxString filename = EDA_FILE_SELECTOR( _( "Write Hotkey Configuration File:" ),
path,
fn.GetFullPath(),
ext,
mask,
this,
wxFD_SAVE,
true );
if( filename.IsEmpty() )
return;
WriteHotkeyConfig( aDescList, &filename );
SetMruPath( wxFileName( filename ).GetPath() );
}

View File

@ -336,9 +336,9 @@ const wxString& PGM_BASE::GetEditorName()
#ifdef __WINDOWS__
mask += wxT( ".exe" );
#endif
editorname = EDA_FileSelector( _( "Preferred Editor:" ), wxEmptyString,
wxEmptyString, wxEmptyString, mask,
NULL, wxFD_OPEN, true );
editorname = EDA_FILE_SELECTOR( _( "Preferred Editor:" ), wxEmptyString,
wxEmptyString, wxEmptyString, mask,
NULL, wxFD_OPEN, true );
}
if( !editorname.IsEmpty() )

View File

@ -483,15 +483,14 @@ wxString DIALOG_BOM::choosePlugin()
wxString path = GetOSXKicadDataDir() + wxT( "/plugins" );
#endif
wxString fullFileName = EDA_FileSelector( _( "Plugin files:" ),
path,
wxEmptyString,
wxEmptyString,
mask,
this,
wxFD_OPEN,
true
);
wxString fullFileName = EDA_FILE_SELECTOR( _( "Plugin files:" ),
path,
wxEmptyString,
wxEmptyString,
mask,
this,
wxFD_OPEN,
true );
if( fullFileName.IsEmpty() )
return wxEmptyString;

View File

@ -453,15 +453,14 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::BrowseAndSelectDocFile( wxCommandEvent& e
if( !docpath )
docpath = search->LastVisitedPath( wxT( "doc" ) );
wxString fullFileName = EDA_FileSelector( _( "Doc Files" ),
docpath,
wxEmptyString,
wxEmptyString,
mask,
this,
wxFD_OPEN,
true
);
wxString fullFileName = EDA_FILE_SELECTOR( _( "Doc Files" ),
docpath,
wxEmptyString,
wxEmptyString,
mask,
this,
wxFD_OPEN,
true );
if( fullFileName.IsEmpty() )
return;

View File

@ -387,9 +387,9 @@ void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertPath( wxCommandEvent& event )
wxString abs_path = prj.GetRString( PROJECT::SCH_LIB_PATH );
wxString path;
bool select = EDA_DirectorySelector( _( "Default Path for Libraries" ),
abs_path, wxDD_DEFAULT_STYLE,
this, wxDefaultPosition );
bool select = EDA_PATH_SELECTOR( _( "Default Path for Libraries" ),
abs_path, wxDD_DEFAULT_STYLE,
this, wxDefaultPosition );
if( !select )
return;

View File

@ -837,14 +837,14 @@ void NETLIST_DIALOG_ADD_PLUGIN::OnBrowsePlugins( wxCommandEvent& event )
#else
Path = GetOSXKicadDataDir() + wxT( "/plugins" );
#endif
FullFileName = EDA_FileSelector( _( "Plugin files:" ),
Path,
FullFileName,
wxEmptyString,
Mask,
this,
wxFD_OPEN,
true
FullFileName = EDA_FILE_SELECTOR( _( "Plugin files:" ),
Path,
FullFileName,
wxEmptyString,
Mask,
this,
wxFD_OPEN,
true
);
if( FullFileName.IsEmpty() )
return;

View File

@ -49,7 +49,7 @@ void LIB_EDIT_FRAME::OnImportPart( wxCommandEvent& event )
m_lastDrawItem = NULL;
wxFileDialog dlg( this, _( "Import Component" ), m_lastLibImportPath,
wxEmptyString, SchematicLibraryFileWildcard,
m_mruPath, SchematicLibraryFileWildcard,
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
if( dlg.ShowModal() == wxID_CANCEL )
@ -57,6 +57,8 @@ void LIB_EDIT_FRAME::OnImportPart( wxCommandEvent& event )
wxFileName fn = dlg.GetPath();
m_mruPath = fn.GetPath();
std::auto_ptr<PART_LIB> lib;
try

View File

@ -71,7 +71,7 @@ void LIB_EDIT_FRAME::OnPlotCurrentComponent( wxCommandEvent& event )
wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() );
fullFileName = EDA_FileSelector( _( "Filename:" ), pro_dir,
fullFileName = EDA_FILE_SELECTOR( _( "Filename:" ), pro_dir,
fn.GetFullName(), file_ext, mask, this,
wxFD_SAVE, true );
@ -94,9 +94,9 @@ void LIB_EDIT_FRAME::OnPlotCurrentComponent( wxCommandEvent& event )
wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() );
fullFileName = EDA_FileSelector( _( "Filename:" ), pro_dir,
fn.GetFullName(), file_ext, mask, this,
wxFD_SAVE, true );
fullFileName = EDA_FILE_SELECTOR( _( "Filename:" ), pro_dir,
fn.GetFullName(), file_ext, mask, this,
wxFD_SAVE, true );
if( fullFileName.IsEmpty() )
return;

View File

@ -916,7 +916,7 @@ void SCH_EDIT_FRAME::OnLoadCmpToFootprintLinkFile( wxCommandEvent& event )
void SCH_EDIT_FRAME::OnNewProject( wxCommandEvent& event )
{
// wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() );
wxString pro_dir = wxGetCwd();
wxString pro_dir = m_mruPath;
wxFileDialog dlg( this, _( "New Schematic" ), pro_dir,
wxEmptyString, SchematicFileWildcard,
@ -942,6 +942,7 @@ void SCH_EDIT_FRAME::OnNewProject( wxCommandEvent& event )
wxASSERT_MSG( create_me.IsAbsolute(), wxT( "wxFileDialog returned non-absolute" ) );
OpenProjectFiles( std::vector<wxString>( 1, create_me.GetFullPath() ), KICTL_CREATE );
m_mruPath = create_me.GetPath();
}
}
@ -949,7 +950,7 @@ void SCH_EDIT_FRAME::OnNewProject( wxCommandEvent& event )
void SCH_EDIT_FRAME::OnLoadProject( wxCommandEvent& event )
{
// wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() );
wxString pro_dir = wxGetCwd();
wxString pro_dir = m_mruPath;
wxFileDialog dlg( this, _( "Open Schematic" ), pro_dir,
wxEmptyString, SchematicFileWildcard,
@ -958,6 +959,7 @@ void SCH_EDIT_FRAME::OnLoadProject( wxCommandEvent& event )
if( dlg.ShowModal() != wxID_CANCEL )
{
OpenProjectFiles( std::vector<wxString>( 1, dlg.GetPath() ) );
m_mruPath = Prj().GetProjectPath();
}
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2007-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2014 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 1992-2015 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -44,6 +44,7 @@
#include <build_version.h>
#include <wildcards_and_files_ext.h>
// Imported function
extern const wxString GetPCBDefaultLayerName( LAYER_NUM aLayerNumber );
@ -174,11 +175,11 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event )
}
wxString fileName;
wxString path = wxGetCwd();
wxString path = m_mruPath;
wxFileDialog filedlg( this, _( "Board file name:" ),
path, fileName, PcbFileWildcard,
wxFD_SAVE );
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( filedlg.ShowModal() == wxID_CANCEL )
return;
@ -195,16 +196,11 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event )
if( ok != wxID_OK )
return;
if( wxFileExists( fileName ) )
{
if( !IsOK( this, _( "OK to change the existing file ?" ) ) )
return;
}
m_mruPath = wxFileName( fileName ).GetPath();
GBR_TO_PCB_EXPORTER gbr_exporter( this, fileName );
gbr_exporter.ExportPcb( layerdlg->GetLayersLookUpTable(),
layerdlg->GetCopperLayersCount() );
gbr_exporter.ExportPcb( layerdlg->GetLayersLookUpTable(), layerdlg->GetCopperLayersCount() );
}

View File

@ -6,7 +6,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2004-2015 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -113,7 +113,7 @@ bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFullFileName )
* the .gbr (.pho in legacy files) extension is the default used in Pcbnew
* However there are a lot of other extensions used for gerber files
* Because the first letter is usually g, we accept g* as extension
* (Mainly internal copper layers do not have specific extention,
* (Mainly internal copper layers do not have specific extension,
* and filenames are like *.g1, *.g2 *.gb1 ...).
* Now (2014) Ucamco (the company which manager the Gerber format) encourage
* use of .gbr only and the Gerber X2 file format.
@ -144,7 +144,7 @@ bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFullFileName )
if( filename.DirExists() )
currentPath = filename.GetPath();
else
currentPath = wxGetCwd();
currentPath = m_mruPath;
wxFileDialog dlg( this,
_( "Open Gerber File" ),
@ -157,13 +157,20 @@ bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFullFileName )
return false;
dlg.GetPaths( filenamesList );
// @todo Take a closer look at the CWD switching here. The current working directory
// gets changed by wxFileDialog because the wxFD_CHANGE_DIR flag is set. Is this the
// appropriate behavior? The current working directory is not returned to the previous
// value so this may be an issue elsewhere.
currentPath = wxGetCwd();
m_mruPath = currentPath;
}
else
{
wxFileName filename = aFullFileName;
filenamesList.Add( aFullFileName );
currentPath = filename.GetPath();
m_mruPath = currentPath;
}
// Read gerber files: each file is loaded on a new GerbView layer
@ -208,6 +215,7 @@ bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFullFileName )
return true;
}
bool GERBVIEW_FRAME::LoadExcellonFiles( const wxString& aFullFileName )
{
wxString filetypes;
@ -226,7 +234,7 @@ bool GERBVIEW_FRAME::LoadExcellonFiles( const wxString& aFullFileName )
if( filename.DirExists() )
currentPath = filename.GetPath();
else
currentPath = wxGetCwd();
currentPath = m_mruPath;
wxFileDialog dlg( this,
_( "Open Drill File" ),
@ -240,12 +248,14 @@ bool GERBVIEW_FRAME::LoadExcellonFiles( const wxString& aFullFileName )
dlg.GetPaths( filenamesList );
currentPath = wxGetCwd();
m_mruPath = currentPath;
}
else
{
wxFileName filename = aFullFileName;
filenamesList.Add( aFullFileName );
currentPath = filename.GetPath();
m_mruPath = currentPath;
}
// Read gerber files: each file is loaded on a new GerbView layer
@ -264,7 +274,7 @@ bool GERBVIEW_FRAME::LoadExcellonFiles( const wxString& aFullFileName )
if( Read_EXCELLON_File( filename.GetFullPath() ) )
{
// Update the list of recentdrill files.
// Update the list of recent drill files.
UpdateFileHistory( filename.GetFullPath(), &m_drillFileHistory );
layer = getNextAvailableLayer( layer );

View File

@ -57,32 +57,56 @@ bool OpenPDF( const wxString& file );
void OpenFile( const wxString& file );
bool EDA_DirectorySelector( const wxString& Title,
wxString& Path,
int flag, /* reserve */
wxWindow* Frame,
const wxPoint& Pos );
/* Selection file dialog box:
* Dialog title
* Default path
* default filename
* default filename extension
* filter for filename list
* parent frame
* wxFD_SAVE, wxFD_OPEN ..
* true = keep the current path
/**
* Function EDA_PATH_SELECTOR
*
* is a helper function that wraps wxDirDialog.
*
* @param aTitle is a string to display in the dialog title bar.
* @param aPath is a string contain the default path for the path dialog. This string also
* contains the result of the wxDirDialog when the OK button is used to dismiss
* the dialog.
* @param aFlags is the style of the path dialog, wxDD_???.
* @param aParaent is the parent window of the dialog.
* @param aPosition is the position of the dialog.
* @return true if a path was selected.
*/
wxString EDA_FileSelector( const wxString& Title,
const wxString& Path,
const wxString& FileName,
const wxString& Ext,
const wxString& Mask,
wxWindow* Frame,
int flag,
const bool keep_working_directory,
const wxPoint& Pos = wxPoint( -1, -1 ) );
bool EDA_PATH_SELECTOR( const wxString& aTitle,
wxString& aPath,
int aFlags, /* reserve */
wxWindow* aParent,
const wxPoint& aPosition = wxDefaultPosition );
/**
* Function EDA_FILE_SELECTOR
*
* is a helper function that wraps a call to wxFileSelector.
*
* @param aTitle is a string to display in the dialog title bar.
* @param aPath is a string contain the default path for the path dialog.
* @param aFileName is a string containing the default file name.
* @param aExtension is a string containing the default file extension.
* @param aWildcard is a string containing the default wildcard.
* @param aParaent is the parent window of the dialog.
* @param aFlags is the style of the path dialog, wxFD_???.
* @param aKeepWorkingDirectory determines if current working directory should be set to the
* user selected path.
* @param aPosition is the position of the dialog.
* @param aMruPath is a pointer to a string to copy the path selected by the user when
* the OK button is pressed to dismiss the dialog. This can be NULL.
* @return the full path and file name of the selected file or wxEmptyString if the user
* pressed the cancel button to dismiss the dialog.
*/
wxString EDA_FILE_SELECTOR( const wxString& aTitle,
const wxString& aPath,
const wxString& aFileName,
const wxString& aExtension,
const wxString& aWildcard,
wxWindow* aParent,
int aStyle,
const bool aKeepWorkingDirectory,
const wxPoint& aPosition = wxDefaultPosition,
wxString* aMruPath = NULL );
EDA_LIST_DIALOG* GetFileNames( char* Directory, char* Mask );

View File

@ -152,6 +152,8 @@ protected:
wxString m_perspective; ///< wxAuiManager perspective.
wxString m_mruPath; ///< Most recently used path.
/**
* Function onAutoSaveTimer
* handles the auto save timer event.
@ -362,6 +364,10 @@ public:
*/
void UpdateFileHistory( const wxString& FullFileName, wxFileHistory * aFileHistory = NULL );
void SetMruPath( const wxString& aPath ) { m_mruPath = aPath; }
wxString GetMruPath() const { return m_mruPath; }
/**
* Function ReCreateMenuBar
* Creates recreates the menu bar.

View File

@ -176,7 +176,7 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event )
// Prepare the zip file
wxString zipfilename = zip.GetFullPath();
wxFFileOutputStream ostream(zipfilename);
wxFFileOutputStream ostream( zipfilename );
wxZipOutputStream zipstream( ostream );
// Build list of filenames to put in zip archive
@ -199,11 +199,11 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event )
curr_fn.MakeRelativeTo( currdirname );
currFilename = curr_fn.GetFullPath();
msg.Printf(_( "Archive file <%s>" ), GetChars( currFilename ) );
msg.Printf( _( "Archive file <%s>" ), GetChars( currFilename ) );
PrintMsg( msg );
// Read input file and add it to the zip file:
wxFSFile* infile = fsfile.OpenFile(currFilename);
wxFSFile* infile = fsfile.OpenFile( currFilename );
if( infile )
{
@ -213,20 +213,20 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event )
int zippedsize = zipstream.GetSize() - zipBytesCnt;
zipBytesCnt = zipstream.GetSize();
PrintMsg( wxT(" ") );
msg.Printf( _( "(%d bytes, compressed %d bytes)\n"),
infile->GetStream()->GetSize(), zippedsize );
msg.Printf( _( "(%lu bytes, compressed %d bytes)\n" ),
(unsigned long)infile->GetStream()->GetSize(), zippedsize );
PrintMsg( msg );
delete infile;
}
else
PrintMsg( _(" >>Error\n") );
PrintMsg( _( " >>Error\n" ) );
}
zipBytesCnt = ostream.GetSize();
if( zipstream.Close() )
{
msg.Printf( _("\nZip archive <%s> created (%d bytes)" ),
msg.Printf( _( "\nZip archive <%s> created (%d bytes)" ),
GetChars( zipfilename ), zipBytesCnt );
PrintMsg( msg );
PrintMsg( wxT( "\n** end **\n" ) );