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:
parent
bbc01e0c2b
commit
d22fceca7c
|
@ -530,6 +530,7 @@ int EDA_BASE_FRAME::WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList,
|
||||||
{
|
{
|
||||||
wxString msg;
|
wxString msg;
|
||||||
wxString keyname, infokey;
|
wxString keyname, infokey;
|
||||||
|
FILE* file;
|
||||||
|
|
||||||
msg = wxT( "$hotkey list\n" );
|
msg = wxT( "$hotkey list\n" );
|
||||||
|
|
||||||
|
@ -565,12 +566,19 @@ int EDA_BASE_FRAME::WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList,
|
||||||
msg += wxT( "$Endlist\n" );
|
msg += wxT( "$Endlist\n" );
|
||||||
|
|
||||||
if( aFullFileName )
|
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 )
|
if( file )
|
||||||
{
|
{
|
||||||
fputs( TO_UTF8( msg ), file );
|
wxFputs( msg, file );
|
||||||
fclose( file );
|
fclose( file );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -578,27 +586,26 @@ int EDA_BASE_FRAME::WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList,
|
||||||
msg.Printf( wxT( "Unable to write file %s" ), GetChars( *aFullFileName ) );
|
msg.Printf( wxT( "Unable to write file %s" ), GetChars( *aFullFileName ) );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxFileName fn( GetName() );
|
|
||||||
fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
|
|
||||||
std::unique_ptr<wxConfigBase> config( GetNewConfig( fn.GetFullPath() ) );
|
|
||||||
config->Write( HOTKEYS_CONFIG_KEY, msg );
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int EDA_BASE_FRAME::ReadHotkeyConfigFile( const wxString& aFilename,
|
int ReadHotkeyConfigFile( const wxString& aFilename, struct EDA_HOTKEY_CONFIG* aDescList,
|
||||||
struct EDA_HOTKEY_CONFIG* aDescList )
|
const bool aDefaultLocation )
|
||||||
{
|
{
|
||||||
wxFileName fn( aFilename );
|
wxFileName fn( aFilename );
|
||||||
|
|
||||||
|
if( aDefaultLocation )
|
||||||
|
{
|
||||||
fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
|
fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
|
||||||
|
fn.SetPath( GetKicadConfigPath() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !wxFile::Exists( fn.GetFullPath() ) )
|
||||||
|
return 0;
|
||||||
|
|
||||||
wxFile cfgfile( fn.GetFullPath() );
|
wxFile cfgfile( fn.GetFullPath() );
|
||||||
|
|
||||||
if( !cfgfile.IsOpened() ) // There is a problem to open file
|
if( !cfgfile.IsOpened() ) // There is a problem to open file
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -612,6 +619,10 @@ int EDA_BASE_FRAME::ReadHotkeyConfigFile( const wxString& aFilename,
|
||||||
cfgfile.Read( buffer.data(), size );
|
cfgfile.Read( buffer.data(), size );
|
||||||
wxString data( buffer.data(), wxConvUTF8 );
|
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
|
// parse
|
||||||
ParseHotkeyConfig( data, aDescList );
|
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 );
|
return ReadHotkeyConfigFile( aAppname, aDescList );
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -748,7 +733,7 @@ void EDA_BASE_FRAME::ImportHotkeyConfigFromFile( EDA_HOTKEY_CONFIG* aDescList,
|
||||||
if( filename.IsEmpty() )
|
if( filename.IsEmpty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ReadHotkeyConfigFile( filename, aDescList );
|
::ReadHotkeyConfigFile( filename, aDescList, false );
|
||||||
WriteHotkeyConfig( aDescList );
|
WriteHotkeyConfig( aDescList );
|
||||||
SetMruPath( wxFileName( filename ).GetPath() );
|
SetMruPath( wxFileName( filename ).GetPath() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,14 +218,26 @@ EDA_HOTKEY* GetDescriptorFromHotkey( int aKey, EDA_HOTKEY** aList );
|
||||||
*/
|
*/
|
||||||
EDA_HOTKEY* GetDescriptorFromCommand( int aCommand, EDA_HOTKEY** aList );
|
EDA_HOTKEY* GetDescriptorFromCommand( int aCommand, EDA_HOTKEY** aList );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function ReadHotkeyConfig
|
* Function ReadHotkeyConfig
|
||||||
* Read hotkey configuration for a given app,
|
* Read hotkey configuration for a given app,
|
||||||
* possibly before the frame for that app has been created
|
* 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 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 );
|
void ParseHotkeyConfig( const wxString& data, struct EDA_HOTKEY_CONFIG* aDescList );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue