diff --git a/eeschema/onrightclick.cpp b/eeschema/onrightclick.cpp index d2b1c4baef..8a59e474e3 100644 --- a/eeschema/onrightclick.cpp +++ b/eeschema/onrightclick.cpp @@ -167,14 +167,6 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component, SYMBOL_LIB AddMenuItem( editmenu, sel_unit_menu, ID_POPUP_SCH_SELECT_UNIT_CMP, _( "Unit" ), KiBitmap( component_select_unit_xpm ) ); } - - if( !Component->GetEditFlags() ) - { - msg = AddHotkeyName( _( "Edit with Library Editor" ), g_Schematic_Hotkeys_Descr, - HK_EDIT_COMPONENT_WITH_LIBEDIT ); - AddMenuItem( editmenu, ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP, - msg, KiBitmap( libedit_xpm ) ); - } } diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index eef859d945..1f737c187e 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -235,7 +235,6 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_MENU( ID_PREFERENCES_CONFIGURE_PATHS, SCH_EDIT_FRAME::OnConfigurePaths ) EVT_TOOL( ID_RUN_LIBRARY, SCH_EDIT_FRAME::OnOpenLibraryEditor ) - EVT_TOOL( ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP, SCH_EDIT_FRAME::OnOpenLibraryEditor ) EVT_TOOL( ID_TO_LIBVIEW, SCH_EDIT_FRAME::OnOpenLibraryViewer ) EVT_TOOL( ID_RESCUE_CACHED, SCH_EDIT_FRAME::OnRescueProject ) EVT_MENU( ID_REMAP_SYMBOLS, SCH_EDIT_FRAME::OnRemapSymbols ) @@ -1076,44 +1075,6 @@ void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) void SCH_EDIT_FRAME::OnOpenLibraryEditor( wxCommandEvent& event ) { - SCH_SELECTION_TOOL* selTool = GetToolManager()->GetTool(); - SCH_COMPONENT* component = NULL; - - if( event.GetId() == ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP ) - { - // We want to edit a component with Libedit. - // we are here by a hot key, or by a popup menu - SCH_ITEM* item = GetScreen()->GetCurItem(); - - if( !item ) - { - // If we didn't get here by a hot key, then something has gone wrong. - if( event.GetInt() == 0 ) - return; - - EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) event.GetClientObject(); - - wxCHECK_RET( data != NULL, wxT( "Invalid hot key client object." ) ); - - // Set the locat filter, according to the edit command - const KICAD_T* filterList = SCH_COLLECTOR::ComponentsOnly; - item = selTool->SelectPoint( data->GetPosition(), filterList ); - - // Exit if no item found at the current location or the item is already being edited. - if( item == NULL || item->GetEditFlags() != 0 ) - return; - } - - - if( !item || item->GetEditFlags() != 0 || item->Type() != SCH_COMPONENT_T ) - { - wxMessageBox( _( "Error: not a symbol or no symbol." ) ); - return; - } - - component = (SCH_COMPONENT*) item; - } - LIB_EDIT_FRAME* libeditFrame = (LIB_EDIT_FRAME*) Kiway().Player( FRAME_SCH_LIB_EDITOR, false ); if( !libeditFrame ) @@ -1129,34 +1090,6 @@ void SCH_EDIT_FRAME::OnOpenLibraryEditor( wxCommandEvent& event ) libeditFrame->Iconize( false ); libeditFrame->Raise(); - - if( component ) - { - LIB_ID id = component->GetLibId(); - LIB_ALIAS* entry = nullptr; - - try - { - entry = Prj().SchSymbolLibTable()->LoadSymbol( id ); - } - catch( const IO_ERROR& ioe ) - { - wxString msg; - - msg.Printf( _( "Error occurred loading symbol \"%s\" from library \"%s\"." ), - id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() ); - DisplayErrorMessage( this, msg, ioe.What() ); - return; - } - - if( !entry ) // Should not occur - return; - - libeditFrame->LoadComponentAndSelectLib( id, component->GetUnit(), component->GetConvert() ); - } - - SchematicCleanUp(); - m_canvas->Refresh(); } diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 9cd15e5749..0b5fa543f0 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -647,6 +647,8 @@ public: bool OpenProjectFiles( const std::vector& aFileSet, int aCtl = 0 ) override; + void OnOpenLibraryEditor( wxCommandEvent& event ); + /** * Import a KiCad schematic into the current page. * @@ -825,7 +827,6 @@ private: void OnOpenPcbnew( wxCommandEvent& event ); void OnOpenPcbModuleEditor( wxCommandEvent& event ); void OnOpenCvpcb( wxCommandEvent& event ); - void OnOpenLibraryEditor( wxCommandEvent& event ); void OnRescueProject( wxCommandEvent& event ); void OnRemapSymbols( wxCommandEvent& aEvent ); diff --git a/eeschema/tools/sch_actions.cpp b/eeschema/tools/sch_actions.cpp index 871fa42b88..da5489d5ee 100644 --- a/eeschema/tools/sch_actions.cpp +++ b/eeschema/tools/sch_actions.cpp @@ -247,6 +247,9 @@ OPT SCH_ACTIONS::TranslateLegacyId( int aId ) case ID_POPUP_SCH_DISPLAYDOC_CMP: return SCH_ACTIONS::showDatasheet.MakeEvent(); + + case ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP: + return SCH_ACTIONS::editWithSymbolEditor.MakeEvent(); } return OPT(); diff --git a/eeschema/tools/sch_actions.h b/eeschema/tools/sch_actions.h index 7e7a45b216..dd61762b9f 100644 --- a/eeschema/tools/sch_actions.h +++ b/eeschema/tools/sch_actions.h @@ -146,6 +146,7 @@ public: /// Inspection static TOOL_ACTION showDatasheet; static TOOL_ACTION showMarkerInfo; + static TOOL_ACTION editWithSymbolEditor; /// Clipboard static TOOL_ACTION cut; diff --git a/eeschema/tools/sch_drawing_tool.cpp b/eeschema/tools/sch_drawing_tool.cpp index 8f95cc3a45..d121845c9f 100644 --- a/eeschema/tools/sch_drawing_tool.cpp +++ b/eeschema/tools/sch_drawing_tool.cpp @@ -551,7 +551,7 @@ int SCH_DRAWING_TOOL::PlaceImage( const TOOL_EVENT& aEvent ) m_view->ClearPreview(); m_view->AddToPreview( image->Clone() ); - m_toolMgr->RunAction( SCH_ACTIONS::selectItem, true, aComponent ); + m_toolMgr->RunAction( SCH_ACTIONS::selectItem, true, image ); m_controls->SetCursorPosition( cursorPos, false ); } diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 25d4a83ce1..11b2a92b49 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -46,6 +46,7 @@ #include #include #include +#include TOOL_ACTION SCH_ACTIONS::refreshPreview( "eeschema.EditorControl.refreshPreview", AS_GLOBAL, 0, "", "" ); @@ -83,6 +84,11 @@ TOOL_ACTION SCH_ACTIONS::paste( "eeschema.EditorControl.paste", AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_EDIT_PASTE ), _( "Paste" ), _( "Paste clipboard into schematic" ), paste_xpm ); +TOOL_ACTION SCH_ACTIONS::editWithSymbolEditor( "eeschema.EditorControl.editWithSymbolEditor", + AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_EDIT_COMPONENT_WITH_LIBEDIT ), + _( "Edit with Symbol Editor" ), _( "Open the symbol editor to edit the symbol" ), + libedit_xpm ); + SCH_EDITOR_CONTROL::SCH_EDITOR_CONTROL() : TOOL_INTERACTIVE( "eeschema.EditorControl" ), @@ -650,6 +656,34 @@ int SCH_EDITOR_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent ) } +int SCH_EDITOR_CONTROL::EditWithSymbolEditor( const TOOL_EVENT& aEvent ) +{ + SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + SELECTION& selection = selTool->RequestSelection( SCH_COLLECTOR::ComponentsOnly ); + SCH_COMPONENT* comp = nullptr; + wxString msg; + + if( selection.GetSize() >= 1 ) + comp = (SCH_COMPONENT*) selection.GetItem( 0 ); + + if( !comp || comp->GetEditFlags() != 0 ) + return 0; + + wxCommandEvent dummy; + m_frame->OnOpenLibraryEditor( dummy ); + + auto libeditFrame = (LIB_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_LIB_EDITOR, false ); + + if( libeditFrame ) + { + const LIB_ID& id = comp->GetLibId(); + libeditFrame->LoadComponentAndSelectLib( id, comp->GetUnit(), comp->GetConvert() ); + } + + return 0; +} + + void SCH_EDITOR_CONTROL::setTransitions() { /* @@ -682,4 +716,6 @@ void SCH_EDITOR_CONTROL::setTransitions() Go( &SCH_EDITOR_CONTROL::Cut, SCH_ACTIONS::cut.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Copy, SCH_ACTIONS::copy.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Paste, SCH_ACTIONS::paste.MakeEvent() ); + + Go( &SCH_EDITOR_CONTROL::EditWithSymbolEditor, SCH_ACTIONS::editWithSymbolEditor.MakeEvent() ); } diff --git a/eeschema/tools/sch_editor_control.h b/eeschema/tools/sch_editor_control.h index 0897876cf4..270a64d603 100644 --- a/eeschema/tools/sch_editor_control.h +++ b/eeschema/tools/sch_editor_control.h @@ -83,6 +83,8 @@ public: int Copy( const TOOL_EVENT& aEvent ); int Paste( const TOOL_EVENT& aEvent ); + int EditWithSymbolEditor( const TOOL_EVENT& aEvent ); + private: ///> copy selection to clipboard bool doCopy();