Revert hotkey save format

This reverts the hotkeys file format to a human readable and VCS
compatible listing by splitting individual hotkey assignments onto
separate lines instead of the single key. This unifies the hotkey format
between the application configuration and export Hotkey routines.

Both hotkey formats remain readable by the same routines.
This commit is contained in:
Seth Hillbrand 2018-02-23 08:44:29 -08:00
parent bbc01e0c2b
commit d22fceca7c
2 changed files with 47 additions and 50 deletions

View File

@ -530,6 +530,7 @@ int EDA_BASE_FRAME::WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList,
{
wxString msg;
wxString keyname, infokey;
FILE* file;
msg = wxT( "$hotkey list\n" );
@ -565,40 +566,46 @@ int EDA_BASE_FRAME::WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList,
msg += wxT( "$Endlist\n" );
if( aFullFileName )
file = wxFopen( *aFullFileName, wxT( "wt" ) );
else
{
FILE* file = wxFopen( *aFullFileName, wxT( "wt" ) );
wxString configName( ConfigBaseName() );
wxFileName fn( configName );
fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
fn.SetPath( GetKicadConfigPath() );
file = wxFopen( fn.GetFullPath(), wxT( "wt" ) );
}
if( file )
{
fputs( TO_UTF8( msg ), file );
fclose( file );
}
else
{
msg.Printf( wxT( "Unable to write file %s" ), GetChars( *aFullFileName ) );
return 0;
}
if( file )
{
wxFputs( msg, file );
fclose( file );
}
else
{
wxFileName fn( GetName() );
fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
std::unique_ptr<wxConfigBase> config( GetNewConfig( fn.GetFullPath() ) );
config->Write( HOTKEYS_CONFIG_KEY, msg );
msg.Printf( wxT( "Unable to write file %s" ), GetChars( *aFullFileName ) );
return 0;
}
return 1;
}
int EDA_BASE_FRAME::ReadHotkeyConfigFile( const wxString& aFilename,
struct EDA_HOTKEY_CONFIG* aDescList )
int ReadHotkeyConfigFile( const wxString& aFilename, struct EDA_HOTKEY_CONFIG* aDescList,
const bool aDefaultLocation )
{
wxFileName fn( aFilename );
fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
if( aDefaultLocation )
{
fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
fn.SetPath( GetKicadConfigPath() );
}
if( !wxFile::Exists( fn.GetFullPath() ) )
return 0;
wxFile cfgfile( fn.GetFullPath() );
if( !cfgfile.IsOpened() ) // There is a problem to open file
return 0;
@ -612,6 +619,10 @@ int EDA_BASE_FRAME::ReadHotkeyConfigFile( const wxString& aFilename,
cfgfile.Read( buffer.data(), size );
wxString data( buffer.data(), wxConvUTF8 );
// Is this the wxConfig format? If so, remove "Keys=" and parse the newlines.
if( data.StartsWith( wxT("Keys="), &data ) )
data.Replace( "\\n", "\n", true );
// parse
ParseHotkeyConfig( data, aDescList );
@ -621,35 +632,9 @@ int EDA_BASE_FRAME::ReadHotkeyConfigFile( const wxString& aFilename,
}
void ReadHotkeyConfig( const wxString& Appname, struct EDA_HOTKEY_CONFIG* aDescList )
int ReadHotkeyConfig( const wxString& aAppname, struct EDA_HOTKEY_CONFIG* aDescList )
{
wxFileName fn( Appname );
fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
std::unique_ptr<wxConfigBase> config;
config.reset( GetNewConfig( fn.GetFullPath() ) );
if( !config->HasEntry( HOTKEYS_CONFIG_KEY ) )
{
// assume defaults are ok
return;
}
wxString data;
config->Read( HOTKEYS_CONFIG_KEY, &data );
ParseHotkeyConfig( data, aDescList );
}
/* Function ReadHotkeyConfig
* Read configuration data and fill the current hotkey list with hotkeys
* aDescList is the current hotkey list descr. to initialize.
*/
int EDA_BASE_FRAME::ReadHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList )
{
::ReadHotkeyConfig( GetName(), aDescList );
return 1;
return ReadHotkeyConfigFile( aAppname, aDescList );
}
@ -748,7 +733,7 @@ void EDA_BASE_FRAME::ImportHotkeyConfigFromFile( EDA_HOTKEY_CONFIG* aDescList,
if( filename.IsEmpty() )
return;
ReadHotkeyConfigFile( filename, aDescList );
::ReadHotkeyConfigFile( filename, aDescList, false );
WriteHotkeyConfig( aDescList );
SetMruPath( wxFileName( filename ).GetPath() );
}

View File

@ -218,14 +218,26 @@ EDA_HOTKEY* GetDescriptorFromHotkey( int aKey, EDA_HOTKEY** aList );
*/
EDA_HOTKEY* GetDescriptorFromCommand( int aCommand, EDA_HOTKEY** aList );
/**
* Function ReadHotkeyConfig
* Read hotkey configuration for a given app,
* possibly before the frame for that app has been created
* @param Appname = the value of the app's m_FrameName
* @param aFilename = the filename to save the hotkeys as
* @param aDescList = the hotkey data
* @param aDefaultLocation = if true, add hotkey path and extension to aFilename
* @return 1 on success, 0 on failure
*/
void ReadHotkeyConfig( const wxString& Appname, struct EDA_HOTKEY_CONFIG* aDescList );
int ReadHotkeyConfigFile( const wxString& aFilename, struct EDA_HOTKEY_CONFIG* aDescList,
const bool aDefaultLocation = true );
/**
* Function ReadHotkeyConfig
* Read configuration data and fill the current hotkey list with hotkeys
* @param aAppname = the value of the app's m_FrameName
* @param aDescList = current hotkey list descr. to initialize.
*/
int ReadHotkeyConfig( const wxString& aAppname, struct EDA_HOTKEY_CONFIG* aDescList );
void ParseHotkeyConfig( const wxString& data, struct EDA_HOTKEY_CONFIG* aDescList );