From d62b4f36a61a79f6ec4144084e22191fa901086d Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 23 Feb 2018 09:22:56 -0800 Subject: [PATCH] Save hotkeys to combined app-based file Unifies the different sections of hotkeys so that we are not storing two [eeschema] or [pcbnew] sections in two different files. Previous hotkey definitions are loaded at start if they exist but are overwritten by the new format, if it exists. Changes to hotkeys save only in the combined format. Hotkey editor for each application only shows the hotkeys relevant to that application. Fixes: lp:1741757 * https://bugs.launchpad.net/kicad/+bug/1741757 Fixes: lp:1668799 * https://bugs.launchpad.net/kicad/+bug/1668799 --- common/dialogs/dialog_hotkeys_editor.cpp | 15 +++++--- common/hotkeys_basic.cpp | 39 +++++++++++++++++++- eeschema/dialogs/dialog_eeschema_options.cpp | 2 +- eeschema/eeschema_config.cpp | 7 +++- eeschema/lib_edit_frame.cpp | 2 - eeschema/sch_edit_frame.h | 2 - include/dialog_hotkeys_editor.h | 10 +++-- include/draw_frame.h | 8 ++++ include/eda_base_frame.h | 16 -------- include/hotkeys_basic.h | 13 ++++++- pagelayout_editor/pl_editor_frame.h | 1 - pcbnew/footprint_edit_frame.cpp | 3 +- pcbnew/footprint_viewer_frame.cpp | 3 -- pcbnew/footprint_wizard_frame.cpp | 2 - pcbnew/pcb_edit_frame.h | 1 - pcbnew/pcbnew_config.cpp | 6 +-- 16 files changed, 83 insertions(+), 47 deletions(-) diff --git a/common/dialogs/dialog_hotkeys_editor.cpp b/common/dialogs/dialog_hotkeys_editor.cpp index 658d985691..c355bb2c45 100644 --- a/common/dialogs/dialog_hotkeys_editor.cpp +++ b/common/dialogs/dialog_hotkeys_editor.cpp @@ -23,9 +23,13 @@ #include -void InstallHotkeyFrame( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys ) +void InstallHotkeyFrame( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys, + EDA_HOTKEY_CONFIG* aShowHotkeys ) { - HOTKEYS_EDITOR_DIALOG dialog( aParent, aHotkeys ); + if( !aShowHotkeys ) + aShowHotkeys = aHotkeys; + + HOTKEYS_EDITOR_DIALOG dialog( aParent, aHotkeys, aShowHotkeys ); int diag = dialog.ShowModal(); @@ -38,12 +42,13 @@ void InstallHotkeyFrame( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys ) HOTKEYS_EDITOR_DIALOG::HOTKEYS_EDITOR_DIALOG( EDA_BASE_FRAME* aParent, - EDA_HOTKEY_CONFIG* aHotkeys ) : + EDA_HOTKEY_CONFIG* aHotkeys, EDA_HOTKEY_CONFIG* aShowHotkeys ) : HOTKEYS_EDITOR_DIALOG_BASE( aParent ), - m_hotkeys( aHotkeys ) + m_hotkeys( aHotkeys ), + m_showhotkeys( aShowHotkeys ) { m_hotkeyListCtrl = new WIDGET_HOTKEY_LIST( m_panelHotkeys, - WIDGET_HOTKEY_LIST::GenSections( aHotkeys ) ); + WIDGET_HOTKEY_LIST::GenSections( aShowHotkeys ) ); m_hotkeyListCtrl->InstallOnPanel( m_panelHotkeys ); m_sdbSizerOK->SetDefault(); diff --git a/common/hotkeys_basic.cpp b/common/hotkeys_basic.cpp index e23fd47c16..4b4b710040 100644 --- a/common/hotkeys_basic.cpp +++ b/common/hotkeys_basic.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -570,6 +571,12 @@ int EDA_BASE_FRAME::WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList, else { wxString configName( ConfigBaseName() ); + if( configName == SCH_EDIT_FRAME_NAME || configName == LIB_EDIT_FRAME_NAME ) + configName = EESCHEMA_HOTKEY_NAME; + else if( configName == PCB_EDIT_FRAME_NAME || + configName == FOOTPRINT_EDIT_FRAME_NAME ) + configName = PCBNEW_HOTKEY_NAME; + wxFileName fn( configName ); fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT ); fn.SetPath( GetKicadConfigPath() ); @@ -624,7 +631,7 @@ int ReadHotkeyConfigFile( const wxString& aFilename, struct EDA_HOTKEY_CONFIG* a data.Replace( "\\n", "\n", true ); // parse - ParseHotkeyConfig( data, aDescList ); + ParseHotkeyConfig( data, aDescList, aFilename ); // cleanup cfgfile.Close(); @@ -634,6 +641,20 @@ int ReadHotkeyConfigFile( const wxString& aFilename, struct EDA_HOTKEY_CONFIG* a int ReadHotkeyConfig( const wxString& aAppname, struct EDA_HOTKEY_CONFIG* aDescList ) { + // For Eeschema and Pcbnew frames, we try twice. + // The first time, we try to read the new combined file. If it doesn't exist, + // we fall back to reading the old, frame-based file + if( aAppname == LIB_EDIT_FRAME_NAME || aAppname == SCH_EDIT_FRAME_NAME ) + { + if( ReadHotkeyConfigFile( EESCHEMA_HOTKEY_NAME, aDescList ) ) + return 1; + } + else if( aAppname == PCB_EDIT_FRAME_NAME || aAppname == FOOTPRINT_EDIT_FRAME_NAME ) + { + if( ReadHotkeyConfigFile( PCBNEW_HOTKEY_NAME, aDescList ) ) + return 1; + } + return ReadHotkeyConfigFile( aAppname, aDescList ); } @@ -644,7 +665,8 @@ int ReadHotkeyConfig( const wxString& aAppname, struct EDA_HOTKEY_CONFIG* aDescL * lines like [xxx] are tags (example: [common] or [libedit] which identify sections */ void ParseHotkeyConfig( const wxString& data, - struct EDA_HOTKEY_CONFIG* aDescList ) + struct EDA_HOTKEY_CONFIG* aDescList, + const wxString& aAppname ) { // Read the config wxStringTokenizer tokenizer( data, L"\r\n", wxTOKEN_STRTOK ); @@ -677,6 +699,19 @@ void ParseHotkeyConfig( const wxString& data, continue; } + // Do not accept hotkey assignments from hotkey files that don't match the application + if( aAppname == LIB_EDIT_FRAME_NAME && line_type == wxT( "[eeschema]" ) ) + CurrentHotkeyList = nullptr; + + if( aAppname == SCH_EDIT_FRAME_NAME && line_type == wxT( "[libedit]" ) ) + CurrentHotkeyList = nullptr; + + if( aAppname == PCB_EDIT_FRAME_NAME && line_type == wxT( "[footprinteditor]" ) ) + CurrentHotkeyList = nullptr; + + if( aAppname == FOOTPRINT_EDIT_FRAME_NAME && line_type == wxT( "[pcbnew]" ) ) + CurrentHotkeyList = nullptr; + if( line_type == wxT( "$Endlist" ) ) break; diff --git a/eeschema/dialogs/dialog_eeschema_options.cpp b/eeschema/dialogs/dialog_eeschema_options.cpp index febed7961f..37950fe5c0 100644 --- a/eeschema/dialogs/dialog_eeschema_options.cpp +++ b/eeschema/dialogs/dialog_eeschema_options.cpp @@ -58,7 +58,7 @@ DIALOG_EESCHEMA_OPTIONS::DIALOG_EESCHEMA_OPTIONS( SCH_EDIT_FRAME* parent ) : m_scaleSlider->SetStep( 25 ); // Embed the hotkeys list - HOTKEY_SECTIONS sections = WIDGET_HOTKEY_LIST::GenSections( g_Eeschema_Hokeys_Descr ); + HOTKEY_SECTIONS sections = WIDGET_HOTKEY_LIST::GenSections( g_Schematic_Hokeys_Descr ); m_hotkeyListCtrl = new WIDGET_HOTKEY_LIST( m_panelHotkeys, sections ); m_hotkeyListCtrl->InstallOnPanel( m_panelHotkeys ); diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index 1266f4ae12..205ab26749 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -135,7 +135,7 @@ void LIB_EDIT_FRAME::Process_Config( wxCommandEvent& event ) { // Hotkey IDs case ID_PREFERENCES_HOTKEY_SHOW_EDITOR: - InstallHotkeyFrame( this, g_Eeschema_Hokeys_Descr ); + InstallHotkeyFrame( this, g_Eeschema_Hokeys_Descr, g_Libedit_Hokeys_Descr ); break; case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG: @@ -206,7 +206,7 @@ void SCH_EDIT_FRAME::Process_Config( wxCommandEvent& event ) break; case ID_PREFERENCES_HOTKEY_SHOW_EDITOR: - InstallHotkeyFrame( this, g_Eeschema_Hokeys_Descr ); + InstallHotkeyFrame( this, g_Eeschema_Hokeys_Descr, g_Schematic_Hokeys_Descr ); break; case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST: @@ -514,6 +514,7 @@ void SCH_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg ) long tmp; + ReadHotkeyConfig( SCH_EDIT_FRAME_NAME, g_Schematic_Hokeys_Descr ); wxConfigLoadSetups( aCfg, GetConfigurationSettings() ); SetGridColor( GetLayerColor( LAYER_SCHEMATIC_GRID ) ); @@ -682,6 +683,8 @@ void LIB_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg ) { EDA_DRAW_FRAME::LoadSettings( aCfg ); + ReadHotkeyConfig( LIB_EDIT_FRAME_NAME, g_Libedit_Hokeys_Descr ); + SetGridColor( GetLayerColor( LAYER_SCHEMATIC_GRID ) ); SetDrawBgColor( GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) ); diff --git a/eeschema/lib_edit_frame.cpp b/eeschema/lib_edit_frame.cpp index a7ebd631e6..617acf2c49 100644 --- a/eeschema/lib_edit_frame.cpp +++ b/eeschema/lib_edit_frame.cpp @@ -202,8 +202,6 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME ) END_EVENT_TABLE() -#define LIB_EDIT_FRAME_NAME wxT( "LibeditFrame" ) - LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH_LIB_EDITOR, _( "Library Editor" ), wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, LIB_EDIT_FRAME_NAME ) diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 7f8548c580..be34627991 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -110,8 +110,6 @@ enum SCH_SEARCH_T { }; -#define SCH_EDIT_FRAME_NAME wxT( "SchematicFrame" ) - /** * Schematic editor (Eeschema) main window. */ diff --git a/include/dialog_hotkeys_editor.h b/include/dialog_hotkeys_editor.h index a944aaec87..1138cc9d84 100644 --- a/include/dialog_hotkeys_editor.h +++ b/include/dialog_hotkeys_editor.h @@ -41,6 +41,7 @@ class HOTKEYS_EDITOR_DIALOG : public HOTKEYS_EDITOR_DIALOG_BASE { protected: struct EDA_HOTKEY_CONFIG* m_hotkeys; + struct EDA_HOTKEY_CONFIG* m_showhotkeys; WIDGET_HOTKEY_LIST* m_hotkeyListCtrl; @@ -53,7 +54,8 @@ protected: } public: - HOTKEYS_EDITOR_DIALOG( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys ); + HOTKEYS_EDITOR_DIALOG( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys, + EDA_HOTKEY_CONFIG* aShowHotkeys ); ~HOTKEYS_EDITOR_DIALOG() {}; @@ -81,8 +83,10 @@ private: * Create a hotkey editor dialog window with the provided hotkey configuration array * * @param aParent is the parent window - * @param aHotkeys is the hotkey configuration array + * @param aHotkeys is the hotkey configuration array for read/writing + * @param aShowHotkeys is the hotkey configuration array that is displayed (subset) */ -void InstallHotkeyFrame( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys ); +void InstallHotkeyFrame( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys, + EDA_HOTKEY_CONFIG* aShowHotkeys = NULL ); #endif diff --git a/include/draw_frame.h b/include/draw_frame.h index 21dfa53ee4..27c1375eaa 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -46,6 +46,14 @@ namespace KIGFX #define DEFAULT_MAX_UNDO_ITEMS 0 #define ABS_MAX_UNDO_ITEMS (INT_MAX / 2) +#define LIB_EDIT_FRAME_NAME wxT( "LibeditFrame" ) +#define SCH_EDIT_FRAME_NAME wxT( "SchematicFrame" ) +#define PL_EDITOR_FRAME_NAME wxT( "PlEditorFrame" ) +#define FOOTPRINT_WIZARD_FRAME_NAME wxT( "FootprintWizard" ) +#define FOOTPRINT_EDIT_FRAME_NAME wxT( "ModEditFrame" ) +#define FOOTPRINT_VIEWER_FRAME_NAME wxT( "ModViewFrame" ) +#define FOOTPRINT_VIEWER_FRAME_NAME_MODAL wxT( "ModViewFrameModal" ) +#define PCB_EDIT_FRAME_NAME wxT( "PcbFrame" ) /** * Class EDA_DRAW_FRAME diff --git a/include/eda_base_frame.h b/include/eda_base_frame.h index 950a28fce2..43285dbc3f 100644 --- a/include/eda_base_frame.h +++ b/include/eda_base_frame.h @@ -283,13 +283,6 @@ public: // Read/Save and Import/export hotkeys config - /** - * Function ReadHotkeyConfig - * Read configuration data and fill the current hotkey list with hotkeys - * @param aDescList = current hotkey list descr. to initialize. - */ - int ReadHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList ); - /** * Function WriteHotkeyConfig * Store the current hotkey list @@ -303,15 +296,6 @@ public: */ virtual int WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList, wxString* aFullFileName = NULL ); - /** - * Function ReadHotkeyConfigFile - * Read an old configuration file (<file>.key) and fill the current hotkey list - * with hotkeys - * @param aFilename = file name to read. - * @param aDescList = current hotkey list descr. to initialize. - */ - int ReadHotkeyConfigFile( const wxString& aFilename, struct EDA_HOTKEY_CONFIG* aDescList ); - /** * Function ImportHotkeyConfigFromFile * Prompt the user for an old hotkey file to read, and read it. diff --git a/include/hotkeys_basic.h b/include/hotkeys_basic.h index 5bf80279c0..afccc55d7b 100644 --- a/include/hotkeys_basic.h +++ b/include/hotkeys_basic.h @@ -32,6 +32,8 @@ #include #define DEFAULT_HOTKEY_FILENAME_EXT wxT( "hotkeys" ) +#define EESCHEMA_HOTKEY_NAME wxT( "Eeschema" ) +#define PCBNEW_HOTKEY_NAME wxT( "PcbNew" ) // A define to allow translation of Hot Key message Info in hotkey help menu // We do not want to use the _( x ) usual macro from wxWidgets, which calls wxGetTranslation(), @@ -218,7 +220,6 @@ 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, @@ -239,7 +240,15 @@ int ReadHotkeyConfigFile( const wxString& aFilename, struct EDA_HOTKEY_CONFIG* a */ int ReadHotkeyConfig( const wxString& aAppname, struct EDA_HOTKEY_CONFIG* aDescList ); -void ParseHotkeyConfig( const wxString& data, struct EDA_HOTKEY_CONFIG* aDescList ); +/** + * Function ParseHotkeyConfig + * Translates hotkey string data into application hotkeys + * @param data The string of data read from the configuration files + * @param aDescList The list of hotkeys to update + * @param aAppname The application interface requesting hotkey updates or empty for all + */ +void ParseHotkeyConfig( const wxString& data, struct EDA_HOTKEY_CONFIG* aDescList, + const wxString& aAppname ); // common hotkeys event id diff --git a/pagelayout_editor/pl_editor_frame.h b/pagelayout_editor/pl_editor_frame.h index ae562d8203..1ebe5095f1 100644 --- a/pagelayout_editor/pl_editor_frame.h +++ b/pagelayout_editor/pl_editor_frame.h @@ -46,7 +46,6 @@ class WORKSHEET_DATAITEM; * Class PL_EDITOR_FRAME * is the main window used in the page layout editor. */ -#define PL_EDITOR_FRAME_NAME wxT( "PlEditorFrame" ) class PL_EDITOR_FRAME : public EDA_DRAW_FRAME { diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index 5430d0643d..94ec51ccb2 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -214,7 +214,6 @@ BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME ) END_EVENT_TABLE() -#define FOOTPRINT_EDIT_FRAME_NAME wxT( "ModEditFrame" ) FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_PCB_MODULE_EDITOR, wxEmptyString, @@ -833,7 +832,7 @@ void FOOTPRINT_EDIT_FRAME::ProcessPreferences( wxCommandEvent& event ) break; case ID_PREFERENCES_HOTKEY_SHOW_EDITOR: - InstallHotkeyFrame( this, g_Module_Editor_Hotkeys_Descr ); + InstallHotkeyFrame( this, g_Pcbnew_Editor_Hotkeys_Descr, g_Module_Editor_Hotkeys_Descr ); break; case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST: diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index c38a87e289..028b3e09e0 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -124,9 +124,6 @@ END_EVENT_TABLE() #define MODAL_MODE_EXTRASTYLE wxFRAME_FLOAT_ON_PARENT #endif -#define FOOTPRINT_VIEWER_FRAME_NAME "ModViewFrame" -#define FOOTPRINT_VIEWER_FRAME_NAME_MODAL "ModViewFrameModal" - FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType ) : PCB_BASE_FRAME( aKiway, aParent, aFrameType, _( "Footprint Library Browser" ), diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index e25d079d21..7f615ae4c6 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -91,8 +91,6 @@ BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME ) END_EVENT_TABLE() -#define FOOTPRINT_WIZARD_FRAME_NAME wxT( "FootprintWizard" ) - /* Note: our FOOTPRINT_WIZARD_FRAME is always modal. * Note: * On windows, when the frame with type wxFRAME_FLOAT_ON_PARENT is displayed diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 678912e19a..80dfe6ce08 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -71,7 +71,6 @@ namespace PCB { struct IFACE; } // KIFACE_I is in pcbnew.cpp * * See also class PCB_BASE_FRAME(): Basic class for Pcbnew and GerbView. */ -#define PCB_EDIT_FRAME_NAME wxT( "PcbFrame" ) class PCB_EDIT_FRAME : public PCB_BASE_EDIT_FRAME diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index c9d170be5a..b03dcd25c9 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -217,15 +217,15 @@ void PCB_EDIT_FRAME::Process_Config( wxCommandEvent& event ) // Hotkey IDs case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG: - ExportHotkeyConfigToFile( g_Board_Editor_Hotkeys_Descr, wxT( "pcbnew" ) ); + ExportHotkeyConfigToFile( g_Pcbnew_Editor_Hotkeys_Descr, wxT( "pcbnew" ) ); break; case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG: - ImportHotkeyConfigFromFile( g_Board_Editor_Hotkeys_Descr, wxT( "pcbnew" ) ); + ImportHotkeyConfigFromFile( g_Pcbnew_Editor_Hotkeys_Descr, wxT( "pcbnew" ) ); break; case ID_PREFERENCES_HOTKEY_SHOW_EDITOR: - InstallHotkeyFrame( this, g_Board_Editor_Hotkeys_Descr ); + InstallHotkeyFrame( this, g_Pcbnew_Editor_Hotkeys_Descr, g_Board_Editor_Hotkeys_Descr ); break; case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST: