From 2804d2e566e2c43cd5231f24fe2dffca32bd6e6d Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 2 Mar 2015 18:29:18 +0100 Subject: [PATCH] Add hotkeys to Kicad manager, and some rework on hotkeys management. --- common/base_struct.cpp | 8 +- common/dialogs/dialog_hotkeys_editor.cpp | 4 +- common/hotkeys_basic.cpp | 38 +++-- eeschema/eeschema.cpp | 2 +- eeschema/eeschema_config.cpp | 8 +- eeschema/schframe.cpp | 1 - eeschema/schframe.h | 3 + gerbview/gerbview.cpp | 2 +- gerbview/gerbview_config.cpp | 4 +- gerbview/gerbview_frame.cpp | 2 - gerbview/gerbview_frame.h | 2 + include/base_struct.h | 3 + include/dialog_hotkeys_editor.h | 6 +- include/hotkeys_basic.h | 8 +- include/wxPcbStruct.h | 2 + include/wxstruct.h | 10 +- kicad/kicad.cpp | 6 + kicad/kicad.h | 6 + kicad/mainframe.cpp | 36 ++++- kicad/menubar.cpp | 181 ++++++++++++++++++++--- pagelayout_editor/pl_editor.cpp | 4 +- pagelayout_editor/pl_editor_config.cpp | 4 +- pagelayout_editor/pl_editor_frame.cpp | 2 - pagelayout_editor/pl_editor_frame.h | 2 + pcbnew/moduleframe.cpp | 4 +- pcbnew/pcbframe.cpp | 2 - pcbnew/pcbnew.cpp | 4 +- pcbnew/pcbnew_config.cpp | 4 +- 28 files changed, 282 insertions(+), 76 deletions(-) diff --git a/common/base_struct.cpp b/common/base_struct.cpp index 683d404038..19396404ee 100644 --- a/common/base_struct.cpp +++ b/common/base_struct.cpp @@ -1,8 +1,8 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com + * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.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 @@ -225,7 +225,7 @@ bool EDA_ITEM::operator<( const EDA_ITEM& aItem ) const return false; } - +#ifdef USE_EDA_ITEM_OP_EQ // see base_struct.h for explanations EDA_ITEM& EDA_ITEM::operator=( const EDA_ITEM& aItem ) { if( &aItem != this ) @@ -241,7 +241,7 @@ EDA_ITEM& EDA_ITEM::operator=( const EDA_ITEM& aItem ) return *this; } - +#endif const BOX2I EDA_ITEM::ViewBBox() const { diff --git a/common/dialogs/dialog_hotkeys_editor.cpp b/common/dialogs/dialog_hotkeys_editor.cpp index 6bca65d821..4023ae5a09 100644 --- a/common/dialogs/dialog_hotkeys_editor.cpp +++ b/common/dialogs/dialog_hotkeys_editor.cpp @@ -251,7 +251,7 @@ void HOTKEY_SECTION_PAGE::Restore() } -void InstallHotkeyFrame( EDA_DRAW_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys ) +void InstallHotkeyFrame( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys ) { HOTKEYS_EDITOR_DIALOG dialog( aParent, aHotkeys ); @@ -264,7 +264,7 @@ void InstallHotkeyFrame( EDA_DRAW_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys ) } -HOTKEYS_EDITOR_DIALOG::HOTKEYS_EDITOR_DIALOG( EDA_DRAW_FRAME* aParent, +HOTKEYS_EDITOR_DIALOG::HOTKEYS_EDITOR_DIALOG( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys ) : HOTKEYS_EDITOR_DIALOG_BASE( aParent ), m_parent( aParent ), diff --git a/common/hotkeys_basic.cpp b/common/hotkeys_basic.cpp index e03a24acf6..0b5a53d343 100644 --- a/common/hotkeys_basic.cpp +++ b/common/hotkeys_basic.cpp @@ -419,7 +419,7 @@ int KeyCodeFromKeyName( const wxString& keyname ) * Displays the current hotkey list * aList = a EDA_HOTKEY_CONFIG list(Null terminated) */ -void DisplayHotkeyList( EDA_DRAW_FRAME* aFrame, struct EDA_HOTKEY_CONFIG* aDescList ) +void DisplayHotkeyList( EDA_BASE_FRAME* aFrame, struct EDA_HOTKEY_CONFIG* aDescList ) { wxString keyname; EDA_HOTKEY** list; @@ -534,7 +534,9 @@ int EDA_BASE_FRAME::WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList, } else { - wxConfigBase* config = GetNewConfig( m_FrameName ); + wxFileName fn( m_FrameName ); + fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT ); + wxConfigBase* config = GetNewConfig( fn.GetFullPath() ); config->Write( HOTKEYS_CONFIG_KEY, msg ); delete config; } @@ -546,7 +548,10 @@ int EDA_BASE_FRAME::WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList, int EDA_BASE_FRAME::ReadHotkeyConfigFile( const wxString& aFilename, struct EDA_HOTKEY_CONFIG* aDescList ) { - wxFile cfgfile( aFilename ); + wxFileName fn( aFilename ); + fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT ); + + wxFile cfgfile( fn.GetFullPath() ); if( !cfgfile.IsOpened() ) // There is a problem to open file return 0; @@ -574,7 +579,10 @@ int EDA_BASE_FRAME::ReadHotkeyConfigFile( const wxString& aFilename, void ReadHotkeyConfig( const wxString& Appname, struct EDA_HOTKEY_CONFIG* aDescList ) { - wxConfigBase* config = GetNewConfig( Appname ); + wxFileName fn( Appname ); + fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT ); + + wxConfigBase* config = GetNewConfig( fn.GetFullPath() ); if( !config->HasEntry( HOTKEYS_CONFIG_KEY ) ) { @@ -677,7 +685,8 @@ void ParseHotkeyConfig( const wxString& data, } -void EDA_BASE_FRAME::ImportHotkeyConfigFromFile( EDA_HOTKEY_CONFIG* aDescList ) +void EDA_BASE_FRAME::ImportHotkeyConfigFromFile( EDA_HOTKEY_CONFIG* aDescList, + const wxString& aDefaultShortname ) { wxString ext = DEFAULT_HOTKEY_FILENAME_EXT; wxString mask = wxT( "*." ) + ext; @@ -687,12 +696,12 @@ void EDA_BASE_FRAME::ImportHotkeyConfigFromFile( EDA_HOTKEY_CONFIG* aDescList ) #else wxString path = wxGetCwd(); #endif + wxFileName fn( aDefaultShortname ); + fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT ); - wxString filename = Kiface().Name() + wxT( '.' ) + ext; - - filename = EDA_FileSelector( _( "Read Hotkey Configuration File:" ), + wxString filename = EDA_FileSelector( _( "Read Hotkey Configuration File:" ), path, - filename, + fn.GetFullPath(), ext, mask, this, @@ -706,7 +715,8 @@ void EDA_BASE_FRAME::ImportHotkeyConfigFromFile( EDA_HOTKEY_CONFIG* aDescList ) } -void EDA_BASE_FRAME::ExportHotkeyConfigToFile( EDA_HOTKEY_CONFIG* aDescList ) +void EDA_BASE_FRAME::ExportHotkeyConfigToFile( EDA_HOTKEY_CONFIG* aDescList, + const wxString& aDefaultShortname ) { wxString ext = DEFAULT_HOTKEY_FILENAME_EXT; wxString mask = wxT( "*." ) + ext; @@ -716,12 +726,12 @@ void EDA_BASE_FRAME::ExportHotkeyConfigToFile( EDA_HOTKEY_CONFIG* aDescList ) #else wxString path = wxGetCwd(); #endif + wxFileName fn( aDefaultShortname ); + fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT ); - wxString filename = Kiface().Name() + wxT( "." ) + ext; - - filename = EDA_FileSelector( _( "Write Hotkey Configuration File:" ), + wxString filename = EDA_FileSelector( _( "Write Hotkey Configuration File:" ), path, - filename, + fn.GetFullPath(), ext, mask, this, diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 922247ad20..5f32e567d1 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -229,7 +229,7 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) // Must be called before creating the main frame in order to // display the real hotkeys in menus or tool tips - ReadHotkeyConfig( wxT("SchematicFrame"), g_Eeschema_Hokeys_Descr ); + ReadHotkeyConfig( SCH_EDIT_FRAME_NAME, g_Eeschema_Hokeys_Descr ); wxConfigLoadSetups( KifaceSettings(), cfg_params() ); diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index bdc57b1f35..113e7868a3 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -177,11 +177,11 @@ void LIB_EDIT_FRAME::Process_Config( wxCommandEvent& event ) break; case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG: - ExportHotkeyConfigToFile( g_Eeschema_Hokeys_Descr ); + ExportHotkeyConfigToFile( g_Eeschema_Hokeys_Descr, wxT( "eeschema" ) ); break; case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG: - ImportHotkeyConfigFromFile( g_Eeschema_Hokeys_Descr ); + ImportHotkeyConfigFromFile( g_Eeschema_Hokeys_Descr, wxT( "eeschema" ) ); break; case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST: @@ -282,11 +282,11 @@ void SCH_EDIT_FRAME::Process_Config( wxCommandEvent& event ) // Hotkey IDs case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG: - ExportHotkeyConfigToFile( g_Eeschema_Hokeys_Descr ); + ExportHotkeyConfigToFile( g_Eeschema_Hokeys_Descr, wxT( "eeschema" ) ); break; case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG: - ImportHotkeyConfigFromFile( g_Eeschema_Hokeys_Descr ); + ImportHotkeyConfigFromFile( g_Eeschema_Hokeys_Descr, wxT( "eeschema" ) ); break; case ID_PREFERENCES_HOTKEY_SHOW_EDITOR: diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 4549da4ebf..f22cedcb0e 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -301,7 +301,6 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) END_EVENT_TABLE() -#define SCH_EDIT_FRAME_NAME wxT( "SchematicFrame" ) SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ): SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH, wxT( "Eeschema" ), diff --git a/eeschema/schframe.h b/eeschema/schframe.h index de58e78eeb..c09f0c3d16 100644 --- a/eeschema/schframe.h +++ b/eeschema/schframe.h @@ -30,6 +30,7 @@ #ifndef WX_EESCHEMA_STRUCT_H #define WX_EESCHEMA_STRUCT_H + #include #include #include @@ -106,6 +107,8 @@ enum SCH_SEARCH_T { }; +#define SCH_EDIT_FRAME_NAME wxT( "SchematicFrame" ) + /** * Schematic editor (Eeschema) main window. */ diff --git a/gerbview/gerbview.cpp b/gerbview/gerbview.cpp index 3a64d1ec3d..e6902ab129 100644 --- a/gerbview/gerbview.cpp +++ b/gerbview/gerbview.cpp @@ -140,7 +140,7 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) // Must be called before creating the main frame in order to // display the real hotkeys in menus or tool tips - ReadHotkeyConfig( wxT("GerberFrame"), s_Gerbview_Hokeys_Descr ); + ReadHotkeyConfig( GERBVIEW_FRAME_NAME, s_Gerbview_Hokeys_Descr ); return true; } diff --git a/gerbview/gerbview_config.cpp b/gerbview/gerbview_config.cpp index 4202284555..78955d7688 100644 --- a/gerbview/gerbview_config.cpp +++ b/gerbview/gerbview_config.cpp @@ -55,11 +55,11 @@ void GERBVIEW_FRAME::Process_Config( wxCommandEvent& event ) { // Hotkey IDs case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG: - ExportHotkeyConfigToFile( s_Gerbview_Hokeys_Descr ); + ExportHotkeyConfigToFile( s_Gerbview_Hokeys_Descr, wxT( "gerbview" ) ); break; case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG: - ImportHotkeyConfigFromFile( s_Gerbview_Hokeys_Descr ); + ImportHotkeyConfigFromFile( s_Gerbview_Hokeys_Descr, wxT( "gerbview" ) ); break; case ID_PREFERENCES_HOTKEY_SHOW_EDITOR: diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index 13063dbe1f..6f1261bd91 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -62,8 +62,6 @@ static const wxString cfgShowBorderAndTitleBlock( wxT( "ShowBorderAndTitleBloc /* class GERBVIEW_FRAME for GerbView */ /*************************************/ -#define GERBVIEW_FRAME_NAME wxT( "GerberFrame" ) - GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ): EDA_DRAW_FRAME( aKiway, aParent, FRAME_GERBER, wxT( "GerbView" ), wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, GERBVIEW_FRAME_NAME ) diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index b3a58e69f6..e5309dc17f 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -81,6 +81,8 @@ public: * is the main window used in GerbView. */ +#define GERBVIEW_FRAME_NAME wxT( "GerberFrame" ) + class GERBVIEW_FRAME : public EDA_DRAW_FRAME // PCB_BASE_FRAME { GBR_LAYOUT* m_gerberLayout; diff --git a/include/base_struct.h b/include/base_struct.h index 18283dbac4..4cad08a863 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -488,6 +488,7 @@ public: */ static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; } +#if 0 /** * Operator assignment * is used to assign the members of \a aItem to another object. @@ -496,6 +497,8 @@ public: * as there is a known issue with wxString buffers. */ virtual EDA_ITEM& operator=( const EDA_ITEM& aItem ); + #define USE_EDA_ITEM_OP_EQ +#endif /// @copydoc VIEW_ITEM::ViewBBox() virtual const BOX2I ViewBBox() const; diff --git a/include/dialog_hotkeys_editor.h b/include/dialog_hotkeys_editor.h index cc1ff04a5a..aa827e7b96 100644 --- a/include/dialog_hotkeys_editor.h +++ b/include/dialog_hotkeys_editor.h @@ -198,13 +198,13 @@ public: class HOTKEYS_EDITOR_DIALOG : public HOTKEYS_EDITOR_DIALOG_BASE { protected: - EDA_DRAW_FRAME* m_parent; + EDA_BASE_FRAME* m_parent; struct EDA_HOTKEY_CONFIG* m_hotkeys; std::vector m_hotkeySectionPages; public: - HOTKEYS_EDITOR_DIALOG( EDA_DRAW_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys ); + HOTKEYS_EDITOR_DIALOG( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys ); ~HOTKEYS_EDITOR_DIALOG() {}; @@ -259,6 +259,6 @@ private: * @param aParent is the parent window * @param aHotkeys is the hotkey configuration array */ -void InstallHotkeyFrame( EDA_DRAW_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys ); +void InstallHotkeyFrame( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys ); #endif diff --git a/include/hotkeys_basic.h b/include/hotkeys_basic.h index b560fe964f..3d08e6e298 100644 --- a/include/hotkeys_basic.h +++ b/include/hotkeys_basic.h @@ -29,10 +29,10 @@ #ifndef HOTKEYS_BASIC_H #define HOTKEYS_BASIC_H -#define DEFAULT_HOTKEY_FILENAME_EXT wxT( "key" ) +#define DEFAULT_HOTKEY_FILENAME_EXT wxT( "hotkeys" ) -class EDA_DRAW_FRAME; +class EDA_BASE_FRAME; /* Identifiers (tags) in key code configuration file (or section names) @@ -116,7 +116,7 @@ public: /* Functions: */ void AddHotkeyConfigMenu( wxMenu* menu ); -void HandleHotkeyConfigMenuSelection( EDA_DRAW_FRAME* frame, int id ); +void HandleHotkeyConfigMenuSelection( EDA_BASE_FRAME* frame, int id ); /** * Function KeyNameFromKeyCode @@ -196,7 +196,7 @@ wxString AddHotkeyName( const wxString& aText, * @param aFrame = current active frame * @param aList = pointer to a EDA_HOTKEY_CONFIG list (Null terminated) */ -void DisplayHotkeyList( EDA_DRAW_FRAME* aFrame, struct EDA_HOTKEY_CONFIG* aList ); +void DisplayHotkeyList( EDA_BASE_FRAME* aFrame, struct EDA_HOTKEY_CONFIG* aList ); /** * Function GetDescriptorFromHotkey diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index eb4df9c8e0..ecdf62fce1 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -73,6 +73,8 @@ 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 { friend struct PCB::IFACE; diff --git a/include/wxstruct.h b/include/wxstruct.h index af98b1858a..0a1fa481f0 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -291,15 +291,21 @@ public: * Function ImportHotkeyConfigFromFile * Prompt the user for an old hotkey file to read, and read it. * @param aDescList = current hotkey list descr. to initialize. + * @param aDefaultShortname = a default short name (extention not needed) + * like eechema, kicad... */ - void ImportHotkeyConfigFromFile( EDA_HOTKEY_CONFIG* aDescList ); + void ImportHotkeyConfigFromFile( EDA_HOTKEY_CONFIG* aDescList, + const wxString& aDefaultShortname ); /** * Function ExportHotkeyConfigToFile * Prompt the user for an old hotkey file to read, and read it. * @param aDescList = current hotkey list descr. to initialize. + * @param aDefaultShortname = a default short name (extention not needed) + * like eechema, kicad... */ - void ExportHotkeyConfigToFile( EDA_HOTKEY_CONFIG* aDescList ); + void ExportHotkeyConfigToFile( EDA_HOTKEY_CONFIG* aDescList, + const wxString& aDefaultShortname ); /** * Function GetFileFromHistory diff --git a/kicad/kicad.cpp b/kicad/kicad.cpp index 5be371e985..4f497e2c90 100644 --- a/kicad/kicad.cpp +++ b/kicad/kicad.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -137,6 +138,11 @@ bool PGM_KICAD::OnPgmInit( wxApp* aWxApp ) //DBG( m_bm.m_search.Show( (std::string( __func__ ) + " SysSearch()").c_str() );) } + // Must be called before creating the main frame in order to + // display the real hotkeys in menus or tool tips + extern struct EDA_HOTKEY_CONFIG kicad_Manager_Hokeys_Descr[]; + ReadHotkeyConfig( KICAD_MANAGER_FRAME_NAME, kicad_Manager_Hokeys_Descr ); + KICAD_MANAGER_FRAME* frame = new KICAD_MANAGER_FRAME( NULL, wxT( "KiCad" ), wxDefaultPosition, wxDefaultSize ); App().SetTopWindow( frame ); diff --git a/kicad/kicad.h b/kicad/kicad.h index 7be6ddd794..342ec06c00 100644 --- a/kicad/kicad.h +++ b/kicad/kicad.h @@ -46,6 +46,8 @@ #define KICAD_USE_FILES_WATCHER #endif +#define KICAD_MANAGER_FRAME_NAME wxT( "KicadFrame" ) + class LAUNCHER_PANEL; class TREEPROJECTFILES; class TREE_PROJECT_FRAME; @@ -190,6 +192,9 @@ public: void OnFileHistory( wxCommandEvent& event ); void OnExit( wxCommandEvent& event ); void Process_Preferences( wxCommandEvent& event ); + + void Process_Config( wxCommandEvent& event ); + void ReCreateMenuBar(); void RecreateBaseHToolbar(); @@ -292,6 +297,7 @@ private: wxAuiToolBar* m_VToolBar; // Vertical toolbar (not used) int m_leftWinWidth; + EDA_HOTKEY_CONFIG* m_manager_Hokeys_Descr; void language_change( wxCommandEvent& event ); }; diff --git a/kicad/mainframe.cpp b/kicad/mainframe.cpp index 2036c1af1f..ee67564e4b 100644 --- a/kicad/mainframe.cpp +++ b/kicad/mainframe.cpp @@ -40,17 +40,19 @@ #include #include #include +#include #define TREE_FRAME_WIDTH_ENTRY wxT( "LeftWinWidth" ) - KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size ) : EDA_BASE_FRAME( parent, KICAD_MAIN_FRAME_T, title, pos, size, - KICAD_DEFAULT_DRAWFRAME_STYLE, wxT( "KicadFrame" ) ) + KICAD_DEFAULT_DRAWFRAME_STYLE, KICAD_MANAGER_FRAME_NAME ) { m_leftWinWidth = 60; + m_manager_Hokeys_Descr = NULL; + m_FrameName = KICAD_MANAGER_FRAME_NAME; // Create the status line (bottom of the frame static const int dims[3] = { -1, -1, 100 }; @@ -529,3 +531,33 @@ void KICAD_MANAGER_FRAME::PrintPrjInfo() PrintMsg( msg ); } +void KICAD_MANAGER_FRAME::Process_Config( wxCommandEvent& event ) +{ + int id = event.GetId(); + wxFileName fn; + + switch( id ) + { + // Hotkey IDs + case ID_PREFERENCES_HOTKEY_SHOW_EDITOR: + InstallHotkeyFrame( this, m_manager_Hokeys_Descr ); + break; + + case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG: + ExportHotkeyConfigToFile( m_manager_Hokeys_Descr, wxT( "kicad" ) ); + break; + + case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG: + ImportHotkeyConfigFromFile( m_manager_Hokeys_Descr, wxT( "kicad" ) ); + break; + + case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST: + // Display current hotkey list for LibEdit. + DisplayHotkeyList( this, m_manager_Hokeys_Descr ); + break; + + default: + wxFAIL_MSG( wxT( "KICAD_MANAGER_FRAME::Process_Config error" ) ); + break; + } +} diff --git a/kicad/menubar.cpp b/kicad/menubar.cpp index ae2aac01cc..d34379bb26 100644 --- a/kicad/menubar.cpp +++ b/kicad/menubar.cpp @@ -1,9 +1,9 @@ /* * 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) 2009-2012 Wayne Stambaugh - * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2009-2015 Wayne Stambaugh + * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.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 @@ -32,6 +32,7 @@ #include #include #include +#include // Menubar and toolbar event table BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME ) @@ -68,24 +69,42 @@ BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME ) EVT_MENU_RANGE( wxID_FILE1, wxID_FILE9, KICAD_MANAGER_FRAME::OnFileHistory ) + // Hotkey management (show list, edit ...) events + EVT_MENU_RANGE( ID_PREFERENCES_HOTKEY_START, ID_PREFERENCES_HOTKEY_END, + KICAD_MANAGER_FRAME::Process_Config ) + + // Special functions #ifdef KICAD_USE_FILES_WATCHER EVT_MENU( ID_INIT_WATCHED_PATHS, KICAD_MANAGER_FRAME::OnChangeWatchedPaths ) #endif - // Button events + // Button events (in command frame), and menu events equivalent to buttons EVT_BUTTON( ID_TO_SCH, KICAD_MANAGER_FRAME::OnRunEeschema ) + EVT_MENU( ID_TO_SCH, KICAD_MANAGER_FRAME::OnRunEeschema ) + EVT_BUTTON( ID_TO_SCH_LIB_EDITOR, KICAD_MANAGER_FRAME::OnRunSchLibEditor ) + EVT_MENU( ID_TO_SCH_LIB_EDITOR, KICAD_MANAGER_FRAME::OnRunSchLibEditor ) EVT_BUTTON( ID_TO_CVPCB, KICAD_MANAGER_FRAME::OnRunCvpcb ) EVT_BUTTON( ID_TO_PCB, KICAD_MANAGER_FRAME::OnRunPcbNew ) + EVT_MENU( ID_TO_PCB, KICAD_MANAGER_FRAME::OnRunPcbNew ) + EVT_BUTTON( ID_TO_PCB_FP_EDITOR, KICAD_MANAGER_FRAME::OnRunPcbFpEditor ) + EVT_MENU( ID_TO_PCB_FP_EDITOR, KICAD_MANAGER_FRAME::OnRunPcbFpEditor ) EVT_BUTTON( ID_TO_GERBVIEW, KICAD_MANAGER_FRAME::OnRunGerbview ) + EVT_MENU( ID_TO_GERBVIEW, KICAD_MANAGER_FRAME::OnRunGerbview ) + EVT_BUTTON( ID_TO_BITMAP_CONVERTER, KICAD_MANAGER_FRAME::OnRunBitmapConverter ) + EVT_MENU( ID_TO_BITMAP_CONVERTER, KICAD_MANAGER_FRAME::OnRunBitmapConverter ) + EVT_BUTTON( ID_TO_PCB_CALCULATOR, KICAD_MANAGER_FRAME::OnRunPcbCalculator ) + EVT_MENU( ID_TO_PCB_CALCULATOR, KICAD_MANAGER_FRAME::OnRunPcbCalculator ) + EVT_BUTTON( ID_TO_PL_EDITOR, KICAD_MANAGER_FRAME::OnRunPageLayoutEditor ) + EVT_MENU( ID_TO_PL_EDITOR, KICAD_MANAGER_FRAME::OnRunPageLayoutEditor ) EVT_UPDATE_UI( ID_SELECT_DEFAULT_PDF_BROWSER, KICAD_MANAGER_FRAME::OnUpdateDefaultPdfBrowser ) EVT_UPDATE_UI( ID_SELECT_PREFERED_PDF_BROWSER, @@ -93,15 +112,72 @@ BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME ) END_EVENT_TABLE() +enum hotkey_id_commnand +{ + HK_RUN_EESCHEMA = HK_COMMON_END, + HK_LOAD_PROJECT, + HK_SAVE_PROJECT, + HK_NEW_PRJ, + HK_NEW_PRJ_TEMPLATE, + HK_RUN_LIBEDIT, + HK_RUN_PCBNEW, + HK_RUN_FPEDITOR, + HK_RUN_GERBVIEW, + HK_RUN_BM2COMPONENT, + HK_RUN_PCBCALCULATOR, + HK_RUN_PLEDITOR +}; + +///////////// Hotkeys management /////////////////////////////////////// +// hotkeys command: +static EDA_HOTKEY HkHelp( wxT( "Help (this window)" ), HK_HELP, '?' ); +static EDA_HOTKEY HkLoadPrj( wxT( "Load project" ), HK_LOAD_PROJECT, 'O' + GR_KB_CTRL ); +static EDA_HOTKEY HkSavePrj( wxT( "Save project" ), HK_SAVE_PROJECT, 'S' + GR_KB_CTRL ); +static EDA_HOTKEY HkNewProject( wxT( "New Project" ), HK_NEW_PRJ, 'N' + GR_KB_CTRL ); +static EDA_HOTKEY HkNewPrjFromTemplate( wxT( "New Prj From Template" ), + HK_NEW_PRJ_TEMPLATE, 'T' + GR_KB_CTRL ); + +static EDA_HOTKEY HkRunEeschema( wxT( "Run Eeschema" ), HK_RUN_EESCHEMA, 'E', 0 ); +static EDA_HOTKEY HkRunLibedit( wxT( "Run LibEdit" ), HK_RUN_LIBEDIT, 'L', 0 ); +static EDA_HOTKEY HkRunPcbnew( wxT( "Run Pcbnew" ), HK_RUN_PCBNEW, 'P', 0 ); +static EDA_HOTKEY HkRunModedit( wxT( "Run FpEditor" ), HK_RUN_FPEDITOR, 'F', 0 ); +static EDA_HOTKEY HkRunGerbview( wxT( "Run Gerbview" ), HK_RUN_GERBVIEW, 'G', 0 ); +static EDA_HOTKEY HkRunBm2Cmp( wxT( "Run Bitmap2Component" ), HK_RUN_BM2COMPONENT, 'B', 0 ); +static EDA_HOTKEY HkRunPcbCalc( wxT( "Run PcbCalculator" ), HK_RUN_PCBCALCULATOR, 'C', 0 ); +static EDA_HOTKEY HkRunPleditor( wxT( "Run PlEditor" ), HK_RUN_PLEDITOR, 'Y', 0 ); + +// List of hotkey descriptors +EDA_HOTKEY* common_Hotkey_List[] = +{ + &HkHelp, + &HkLoadPrj, &HkSavePrj, &HkNewProject, &HkNewPrjFromTemplate, + &HkRunEeschema, &HkRunLibedit, + &HkRunPcbnew, &HkRunModedit, &HkRunGerbview, + &HkRunBm2Cmp, &HkRunPcbCalc, &HkRunPleditor, + NULL +}; + +// list of sections and corresponding hotkey list for Kicad +// (used to create an hotkey config file, and edit hotkeys ) +// here we have only one section. +struct EDA_HOTKEY_CONFIG kicad_Manager_Hokeys_Descr[] = { + { &g_CommonSectionTag, common_Hotkey_List, &g_CommonSectionTitle }, + { NULL, NULL, NULL } +}; +///////////// End hotkeys management /////////////////////////////////////// + /** * @brief (Re)Create the menubar */ void KICAD_MANAGER_FRAME::ReCreateMenuBar() { + wxString msg; static wxMenu* openRecentMenu; // Open Recent submenu, // static to remember this menu + m_manager_Hokeys_Descr = kicad_Manager_Hokeys_Descr; + // Create and try to get the current menubar wxMenuBar* menuBar = GetMenuBar(); @@ -127,9 +203,8 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar() wxMenu* fileMenu = new wxMenu; // Open - AddMenuItem( fileMenu, - ID_LOAD_PROJECT, - _( "&Open Project\tCtrl+O" ), + msg = AddHotkeyName( _( "&Open Project" ), kicad_Manager_Hokeys_Descr, HK_LOAD_PROJECT ); + AddMenuItem( fileMenu, ID_LOAD_PROJECT, msg, _( "Open existing project" ), KiBitmap( open_project_xpm ) ); @@ -143,30 +218,35 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar() _( "Open recent schematic project" ), KiBitmap( open_project_xpm ) ); - // New - wxMenu* newMenu = new wxMenu(); - AddMenuItem( newMenu, ID_NEW_PROJECT, - _( "&Blank Project\tCtrl+N" ), - _( "Create blank project" ), + // New project creation + wxMenu* newprjSubMenu = new wxMenu(); + + msg = AddHotkeyName( _( "&New Project" ), kicad_Manager_Hokeys_Descr, HK_NEW_PRJ ); + AddMenuItem( newprjSubMenu, ID_NEW_PROJECT, msg, + _( "Create new blank project" ), KiBitmap( new_project_xpm ) ); - AddMenuItem( newMenu, ID_NEW_PROJECT_FROM_TEMPLATE, - _( "Project from &Template\tCtrl+T" ), - _( "Create new project from template" ), + msg = AddHotkeyName( _( "New Project from &Template" ), + kicad_Manager_Hokeys_Descr, HK_NEW_PRJ_TEMPLATE ); + AddMenuItem( newprjSubMenu, ID_NEW_PROJECT_FROM_TEMPLATE, msg, + _( "Create a new project from a template" ), KiBitmap( new_project_with_template_xpm ) ); - AddMenuItem( fileMenu, newMenu, + AddMenuItem( fileMenu, newprjSubMenu, wxID_ANY, - _( "New" ), + _( "New Project" ), _( "Create new project" ), KiBitmap( new_project_xpm ) ); + // Currently there is nothing to save + // (Kicad manager does not save any info in .pro file) +#if 0 // Save - AddMenuItem( fileMenu, - ID_SAVE_PROJECT, - _( "&Save\tCtrl+S" ), + msg = AddHotkeyName( _( "&Save" ), kicad_Manager_Hokeys_Descr, HK_SAVE_PROJECT ); + AddMenuItem( fileMenu, ID_SAVE_PROJECT, msg, _( "Save current project" ), KiBitmap( save_project_xpm ) ); +#endif // Archive fileMenu->AppendSeparator(); @@ -255,10 +335,61 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar() _( "PDF viewer preferences" ), KiBitmap( datasheet_xpm ) ); + // Hotkey submenu + preferencesMenu->AppendSeparator(); + AddHotkeyConfigMenu( preferencesMenu ); + // Language submenu preferencesMenu->AppendSeparator(); Pgm().AddMenuLanguageList( preferencesMenu ); + // Hotkey submenu + AddHotkeyConfigMenu( preferencesMenu ); + + // Menu Tools: + wxMenu* toolsMenu = new wxMenu; + + msg = AddHotkeyName( _( "Run Eeschema" ), kicad_Manager_Hokeys_Descr, HK_RUN_EESCHEMA ); + AddMenuItem( toolsMenu, ID_TO_SCH, msg, + KiBitmap( eeschema_xpm ) ); + + msg = AddHotkeyName( _( "Run Library Editor" ), + kicad_Manager_Hokeys_Descr, HK_RUN_LIBEDIT ); + AddMenuItem( toolsMenu, ID_TO_SCH_LIB_EDITOR, msg, + KiBitmap( libedit_xpm ) ); + + msg = AddHotkeyName( _( "Run Pcbnew" ), + kicad_Manager_Hokeys_Descr, HK_RUN_PCBNEW ); + AddMenuItem( toolsMenu, ID_TO_PCB, msg, + KiBitmap( pcbnew_xpm ) ); + + msg = AddHotkeyName( _( "Run Footprint Editor" ), + kicad_Manager_Hokeys_Descr, HK_RUN_FPEDITOR ); + AddMenuItem( toolsMenu, ID_TO_PCB_FP_EDITOR, msg, + KiBitmap( module_editor_xpm ) ); + + msg = AddHotkeyName( _( "Run Gerbview" ), + kicad_Manager_Hokeys_Descr, HK_RUN_GERBVIEW ); + AddMenuItem( toolsMenu, ID_TO_GERBVIEW, msg, + KiBitmap( icon_gerbview_small_xpm ) ); + + msg = AddHotkeyName( _( "Run Bitmap2Component" ), + kicad_Manager_Hokeys_Descr, HK_RUN_BM2COMPONENT ); + AddMenuItem( toolsMenu, ID_TO_BITMAP_CONVERTER, msg, + _( "Bitmap2Component - Convert bitmap images to Eeschema\n" + "or Pcbnew elements" ), + KiBitmap( image_xpm ) ); + + msg = AddHotkeyName( _( "Run Pcb Calculator" ), kicad_Manager_Hokeys_Descr, HK_RUN_PCBCALCULATOR ); + AddMenuItem( toolsMenu, ID_TO_PCB_CALCULATOR, msg, + _( "Pcb calculator - Calculator for components, track width, etc." ), + KiBitmap( options_module_xpm ) ); + + msg = AddHotkeyName( _( "Run Page Layout Editor" ), kicad_Manager_Hokeys_Descr, HK_RUN_PLEDITOR ); + AddMenuItem( toolsMenu, ID_TO_PL_EDITOR, msg, + _( "Pl editor - Worksheet layout editor" ), + KiBitmap( pagelayout_load_xpm ) ); + // Menu Help: wxMenu* helpMenu = new wxMenu; @@ -289,6 +420,7 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar() menuBar->Append( fileMenu, _( "&File" ) ); menuBar->Append( browseMenu, _( "&Browse" ) ); menuBar->Append( preferencesMenu, _( "&Preferences" ) ); + menuBar->Append( toolsMenu, _( "&Tools" ) ); menuBar->Append( helpMenu, _( "&Help" ) ); menuBar->Thaw(); @@ -298,6 +430,15 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar() SetMenuBar( menuBar ); else menuBar->Refresh(); + + // Add the hotkey to the "show hotkey list" menu, because we do not have + // a management of the keyboard keys in Kicad. + // So all hotheys should be added to the menubar + // Note Use wxMenuBar::SetLabel only after the menubar + // has been associated with a frame. (see wxWidgets doc) + msg = AddHotkeyName( menuBar->GetLabel( ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST ), + kicad_Manager_Hokeys_Descr, HK_HELP ); + menuBar->SetLabel( ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST, msg ); } diff --git a/pagelayout_editor/pl_editor.cpp b/pagelayout_editor/pl_editor.cpp index 2b341364d5..1dca031715 100644 --- a/pagelayout_editor/pl_editor.cpp +++ b/pagelayout_editor/pl_editor.cpp @@ -122,7 +122,7 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) // Must be called before creating the main frame in order to // display the real hotkeys in menus or tool tips - ReadHotkeyConfig( wxT("PlEditorFrame"), s_PlEditor_Hokeys_Descr ); + ReadHotkeyConfig( PL_EDITOR_FRAME_NAME, s_PlEditor_Hokeys_Descr ); g_UserUnit = MILLIMETRES; @@ -159,7 +159,7 @@ bool MYFACE::OnKifaceStart( PGM_BASE* aProgram ) // Must be called before creating the main frame in order to // display the real hotkeys in menus or tool tips - ReadHotkeyConfig( wxT("PlEditorFrame"), s_PlEditor_Hokeys_Descr ); + ReadHotkeyConfig( PL_EDITOR_FRAME_NAME, s_PlEditor_Hokeys_Descr ); PL_EDITOR_FRAME * frame = new PL_EDITOR_FRAME( NULL, wxT( "PlEditorFrame" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) ); diff --git a/pagelayout_editor/pl_editor_config.cpp b/pagelayout_editor/pl_editor_config.cpp index ad15cc65ad..dc9bc58dea 100644 --- a/pagelayout_editor/pl_editor_config.cpp +++ b/pagelayout_editor/pl_editor_config.cpp @@ -74,11 +74,11 @@ void PL_EDITOR_FRAME::Process_Config( wxCommandEvent& event ) break; case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG: - ExportHotkeyConfigToFile( s_PlEditor_Hokeys_Descr ); + ExportHotkeyConfigToFile( s_PlEditor_Hokeys_Descr, wxT( "pl_editor" ) ); break; case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG: - ImportHotkeyConfigFromFile( s_PlEditor_Hokeys_Descr ); + ImportHotkeyConfigFromFile( s_PlEditor_Hokeys_Descr, wxT( "pl_editor" ) ); break; case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST: diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index c244b2e859..be1abd7552 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -50,8 +50,6 @@ /* class PL_EDITOR_FRAME */ /*************************/ -#define PL_EDITOR_FRAME_NAME wxT( "PlEditorFrame" ) - PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) : EDA_DRAW_FRAME( aKiway, aParent, FRAME_PL_EDITOR, wxT( "PlEditorFrame" ), wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, PL_EDITOR_FRAME_NAME ) diff --git a/pagelayout_editor/pl_editor_frame.h b/pagelayout_editor/pl_editor_frame.h index 33c3b08086..b7aa5ee356 100644 --- a/pagelayout_editor/pl_editor_frame.h +++ b/pagelayout_editor/pl_editor_frame.h @@ -45,6 +45,8 @@ 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 { PL_EDITOR_LAYOUT m_pageLayout; diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index c2b3405c48..800b648ca3 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -835,11 +835,11 @@ void FOOTPRINT_EDIT_FRAME::ProcessPreferences( wxCommandEvent& event ) { // Hotkey IDs case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG: - ExportHotkeyConfigToFile( g_Module_Editor_Hokeys_Descr ); + ExportHotkeyConfigToFile( g_Module_Editor_Hokeys_Descr, wxT( "pcbnew" ) ); break; case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG: - ImportHotkeyConfigFromFile( g_Module_Editor_Hokeys_Descr ); + ImportHotkeyConfigFromFile( g_Module_Editor_Hokeys_Descr, wxT( "pcbnew" ) ); break; case ID_PREFERENCES_HOTKEY_SHOW_EDITOR: diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 1ccc128d66..4e619b4ed2 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -310,8 +310,6 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) END_EVENT_TABLE() -#define PCB_EDIT_FRAME_NAME wxT( "PcbFrame" ) - PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_PCB, wxT( "Pcbnew" ), wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, PCB_EDIT_FRAME_NAME ) diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 8e3f7f4b0c..6d45c3b056 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr + * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. * @@ -307,7 +307,7 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) // Must be called before creating the main frame in order to // display the real hotkeys in menus or tool tips - ReadHotkeyConfig( wxT( "PcbFrame" ), g_Board_Editor_Hokeys_Descr ); + ReadHotkeyConfig( PCB_EDIT_FRAME_NAME, g_Board_Editor_Hokeys_Descr ); try { diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index 1adf75aba5..51d58c4e7a 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -227,11 +227,11 @@ void PCB_EDIT_FRAME::Process_Config( wxCommandEvent& event ) // Hotkey IDs case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG: - ExportHotkeyConfigToFile( g_Board_Editor_Hokeys_Descr ); + ExportHotkeyConfigToFile( g_Board_Editor_Hokeys_Descr, wxT( "pcbnew" ) ); break; case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG: - ImportHotkeyConfigFromFile( g_Board_Editor_Hokeys_Descr ); + ImportHotkeyConfigFromFile( g_Board_Editor_Hokeys_Descr, wxT( "pcbnew" ) ); break; case ID_PREFERENCES_HOTKEY_SHOW_EDITOR: