From da4fe274473b6829c7a67af29e35f26ca930c204 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 2 Jun 2019 21:07:57 +0100 Subject: [PATCH] More ACTIONS work. --- eeschema/widgets/symbol_tree_pane.cpp | 21 +++------ pcbnew/footprint_edit_frame.cpp | 9 +++- pcbnew/footprint_edit_frame.h | 1 + pcbnew/footprint_editor_utils.cpp | 19 -------- pcbnew/footprint_libraries_utils.cpp | 3 ++ pcbnew/footprint_tree_pane.cpp | 67 +++++++++------------------ pcbnew/menubar_footprint_editor.cpp | 12 +---- pcbnew/pcbnew_id.h | 2 - pcbnew/tools/pcbnew_control.cpp | 16 +++++++ pcbnew/tools/pcbnew_control.h | 1 + 10 files changed, 60 insertions(+), 91 deletions(-) diff --git a/eeschema/widgets/symbol_tree_pane.cpp b/eeschema/widgets/symbol_tree_pane.cpp index 221e90737f..7e951afaa1 100644 --- a/eeschema/widgets/symbol_tree_pane.cpp +++ b/eeschema/widgets/symbol_tree_pane.cpp @@ -62,31 +62,24 @@ SYMBOL_TREE_PANE::SYMBOL_TREE_PANE( LIB_EDIT_FRAME* aParent, LIB_MANAGER* aLibMg menuLibrary->AppendSeparator(); menuLibrary->Add( EE_ACTIONS::newSymbol ); menuLibrary->Add( EE_ACTIONS::importSymbol ); - AddMenuItem( menuLibrary.get(), ID_LIBEDIT_PASTE_PART, _( "Paste Symbol" ), - KiBitmap( paste_xpm ) ); + menuLibrary->Add( _( "Paste Symbol" ), ID_LIBEDIT_PASTE_PART, paste_xpm ); std::unique_ptr menuPart = std::make_unique(); - AddMenuItem( menuPart.get(), ID_LIBEDIT_EDIT_PART, _( "Edit Symbol" ), - KiBitmap( edit_xpm ) ); + menuPart->Add( _( "Edit Symbol" ), ID_LIBEDIT_EDIT_PART, edit_xpm ); menuPart->AppendSeparator(); menuPart->Add( ACTIONS::save ); menuPart->Add( ACTIONS::saveCopyAs ); - AddMenuItem( menuPart.get(), ID_LIBEDIT_DUPLICATE_PART, _( "Duplicate" ), - KiBitmap( duplicate_xpm ) ); - AddMenuItem( menuPart.get(), ID_LIBEDIT_REMOVE_PART, _( "Delete" ), - KiBitmap( delete_xpm ) ); + menuPart->Add( _( "Duplicate" ), ID_LIBEDIT_DUPLICATE_PART, duplicate_xpm ); + menuPart->Add( _( "Delete" ), ID_LIBEDIT_REMOVE_PART, delete_xpm ); menuPart->Add( ACTIONS::revert ); menuPart->AppendSeparator(); - AddMenuItem( menuPart.get(), ID_LIBEDIT_CUT_PART, _( "Cut" ), - KiBitmap( cut_xpm ) ); - AddMenuItem( menuPart.get(), ID_LIBEDIT_COPY_PART, _( "Copy" ), - KiBitmap( copy_xpm ) ); + menuPart->Add( _( "Cut" ), ID_LIBEDIT_CUT_PART, cut_xpm ); + menuPart->Add( _( "Copy" ), ID_LIBEDIT_COPY_PART, copy_xpm ); menuPart->AppendSeparator(); - AddMenuItem( menuPart.get(), ID_LIBEDIT_EXPORT_PART, _( "E&xport Symbol..." ), - KiBitmap( export_part_xpm ) ); + menuPart->Add( _( "Export Symbol..." ), ID_LIBEDIT_EXPORT_PART, export_part_xpm ); // Menu displayed when nothing is selected std::unique_ptr menuNoSelection = std::make_unique(); diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index b994501908..45234a264a 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -101,8 +101,6 @@ BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME ) EVT_TOOL( ID_MODEDIT_NEW_MODULE_FROM_WIZARD, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_MODEDIT_IMPORT_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_MODEDIT_EXPORT_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) - EVT_TOOL( ID_MODEDIT_CREATE_NEW_LIB, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) - EVT_TOOL( ID_MODEDIT_ADD_LIBRARY, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_MODEDIT_SHEET_SET, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( wxID_PRINT, FOOTPRINT_EDIT_FRAME::ToPrinter ) EVT_TOOL( ID_MODEDIT_EDIT_MODULE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) @@ -773,6 +771,13 @@ void FOOTPRINT_EDIT_FRAME::SyncLibraryTree( bool aProgress ) } +void FOOTPRINT_EDIT_FRAME::FocusOnLibrary( const wxString& aLibName ) +{ + LIB_ID libID( aLibName, wxEmptyString ); + m_treePane->GetLibTree()->SelectLibId( libID ); +} + + bool FOOTPRINT_EDIT_FRAME::IsGridVisible() const { return IsElementVisible( LAYER_GRID ); diff --git a/pcbnew/footprint_edit_frame.h b/pcbnew/footprint_edit_frame.h index d1677fd54b..6b526a8783 100644 --- a/pcbnew/footprint_edit_frame.h +++ b/pcbnew/footprint_edit_frame.h @@ -346,6 +346,7 @@ public: * @param aProgress */ void SyncLibraryTree( bool aProgress ); + void FocusOnLibrary( const wxString& aLibName ); void KiwayMailIn( KIWAY_EXPRESS& mail ) override; diff --git a/pcbnew/footprint_editor_utils.cpp b/pcbnew/footprint_editor_utils.cpp index bc22274572..a2a421c1e8 100644 --- a/pcbnew/footprint_editor_utils.cpp +++ b/pcbnew/footprint_editor_utils.cpp @@ -426,25 +426,6 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) Export_Module( LoadFootprint( getTargetFPID() ) ); break; - case ID_MODEDIT_CREATE_NEW_LIB: - { - wxFileName fn( CreateNewLibrary() ); - wxString name = fn.GetName(); - - if( !name.IsEmpty() ) - { - LIB_ID newLib( name, wxEmptyString ); - - SyncLibraryTree( true ); - m_treePane->GetLibTree()->SelectLibId( newLib ); - } - } - break; - - case ID_MODEDIT_ADD_LIBRARY: - AddLibrary(); - break; - case ID_MODEDIT_EDIT_MODULE: LoadModuleFromLibrary( m_treePane->GetLibTree()->GetSelectedLibId() ); break; diff --git a/pcbnew/footprint_libraries_utils.cpp b/pcbnew/footprint_libraries_utils.cpp index efc4bdca7f..1c7458d1c7 100644 --- a/pcbnew/footprint_libraries_utils.cpp +++ b/pcbnew/footprint_libraries_utils.cpp @@ -571,7 +571,10 @@ bool PCB_BASE_EDIT_FRAME::AddLibrary( const wxString& aFilename ) auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_PCB_MODULE_EDITOR, false ); if( editor ) + { editor->SyncLibraryTree( true ); + editor->FocusOnLibrary( libName ); + } auto viewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_PCB_MODULE_VIEWER, false ); diff --git a/pcbnew/footprint_tree_pane.cpp b/pcbnew/footprint_tree_pane.cpp index e8a966ef51..0f15251b14 100644 --- a/pcbnew/footprint_tree_pane.cpp +++ b/pcbnew/footprint_tree_pane.cpp @@ -23,7 +23,8 @@ #include "footprint_tree_pane.h" #include "fp_tree_synchronizing_adapter.h" - +#include +#include #include #include #include @@ -46,62 +47,40 @@ FOOTPRINT_TREE_PANE::FOOTPRINT_TREE_PANE( FOOTPRINT_EDIT_FRAME* aParent ) boxSizer->Fit( this ); // Setup right click-context menus - std::unique_ptr menuLibrary = std::make_unique(); - - AddMenuItem( menuLibrary.get(), ID_MODEDIT_CREATE_NEW_LIB, _( "&New Library..." ), - KiBitmap( new_library_xpm ) ); - - AddMenuItem( menuLibrary.get(), ID_MODEDIT_ADD_LIBRARY, _( "&Add Library..." ), - KiBitmap( add_library_xpm ) ); - - AddMenuItem( menuLibrary.get(), ID_MODEDIT_SAVE, _( "&Save" ), - KiBitmap( save_xpm ) ); - AddMenuItem( menuLibrary.get(), ID_MODEDIT_SAVE_AS, _( "Save a Copy &As..." ), - KiBitmap( save_as_xpm ) ); + std::unique_ptr menuLibrary = std::make_unique(); + menuLibrary->Add( ACTIONS::newLibrary ); + menuLibrary->Add( ACTIONS::addLibrary ); + menuLibrary->Add( _( "Save" ), ID_MODEDIT_SAVE, save_xpm ); + menuLibrary->Add( _( "Save a Copy As..." ), ID_MODEDIT_SAVE_AS, save_as_xpm ); menuLibrary->AppendSeparator(); - AddMenuItem( menuLibrary.get(), ID_MODEDIT_NEW_MODULE, _( "&New Footprint..." ), - KiBitmap( new_footprint_xpm ) ); + menuLibrary->Add( _( "New Footprint..." ), ID_MODEDIT_NEW_MODULE, new_footprint_xpm ); #ifdef KICAD_SCRIPTING - AddMenuItem( menuLibrary.get(), ID_MODEDIT_NEW_MODULE_FROM_WIZARD, _( "&Create Footprint from Wizard..." ), - KiBitmap( module_wizard_xpm ) ); + menuLibrary->Add( _( "Create Footprint from Wizard..." ), ID_MODEDIT_NEW_MODULE_FROM_WIZARD, module_wizard_xpm ); #endif - AddMenuItem( menuLibrary.get(), ID_MODEDIT_IMPORT_PART, _( "&Import Footprint..." ), - KiBitmap( import_module_xpm ) ); - AddMenuItem( menuLibrary.get(), ID_MODEDIT_PASTE_PART, _( "Paste Footprint" ), - KiBitmap( paste_xpm ) ); + menuLibrary->Add( _( "Import Footprint..." ), ID_MODEDIT_IMPORT_PART, import_module_xpm ); + menuLibrary->Add( _( "Paste Footprint" ), ID_MODEDIT_PASTE_PART, paste_xpm ); - std::unique_ptr menuPart = std::make_unique(); - AddMenuItem( menuPart.get(), ID_MODEDIT_EDIT_MODULE, _( "&Edit Footprint" ), - KiBitmap( edit_xpm ) ); + std::unique_ptr menuPart = std::make_unique(); + menuPart->Add( _( "Edit Footprint" ), ID_MODEDIT_EDIT_MODULE, edit_xpm ); menuPart->AppendSeparator(); - AddMenuItem( menuPart.get(), ID_MODEDIT_SAVE, _( "&Save" ), - KiBitmap( save_xpm ) ); - AddMenuItem( menuPart.get(), ID_MODEDIT_SAVE_AS, _( "Save &As..." ), - KiBitmap( save_xpm ) ); - AddMenuItem( menuPart.get(), ID_MODEDIT_DELETE_PART, _( "&Delete" ), - KiBitmap( delete_xpm ) ); - AddMenuItem( menuPart.get(), ID_MODEDIT_REVERT_PART, _( "Revert" ), - KiBitmap( undo_xpm ) ); + menuPart->Add( _( "Save" ), ID_MODEDIT_SAVE, save_xpm ); + menuPart->Add( _( "Save a Copy As..." ), ID_MODEDIT_SAVE_AS, save_as_xpm ); + menuPart->Add( _( "Delete" ), ID_MODEDIT_DELETE_PART, delete_xpm ); + menuPart->Add( _( "Revert" ), ID_MODEDIT_REVERT_PART, undo_xpm ); menuPart->AppendSeparator(); - AddMenuItem( menuPart.get(), ID_MODEDIT_CUT_PART, _( "Cut" ), - KiBitmap( cut_xpm ) ); - AddMenuItem( menuPart.get(), ID_MODEDIT_COPY_PART, _( "Copy" ), - KiBitmap( copy_xpm ) ); + menuPart->Add( _( "Cut" ), ID_MODEDIT_CUT_PART, cut_xpm ); + menuPart->Add( _( "Copy" ), ID_MODEDIT_COPY_PART, copy_xpm ); menuPart->AppendSeparator(); - AddMenuItem( menuPart.get(), ID_MODEDIT_EXPORT_PART, _( "E&xport Footprint..." ), - KiBitmap( export_module_xpm ) ); + menuPart->Add( _( "Export Footprint..." ), ID_MODEDIT_EXPORT_PART, export_module_xpm ); // Menu displayed when nothing is selected - std::unique_ptr menuNoSelection = std::make_unique(); - AddMenuItem( menuNoSelection.get(), ID_MODEDIT_CREATE_NEW_LIB, _( "&New Library..." ), - KiBitmap( new_library_xpm ) ); - - AddMenuItem( menuNoSelection.get(), ID_MODEDIT_ADD_LIBRARY, _( "&Add Library..." ), - KiBitmap( add_library_xpm ) ); + std::unique_ptr menuNoSelection = std::make_unique(); + menuNoSelection->Add( ACTIONS::newLibrary ); + menuNoSelection->Add( ACTIONS::addLibrary ); m_tree->SetMenu( LIB_TREE_NODE::LIBID, std::move( menuPart ) ); m_tree->SetMenu( LIB_TREE_NODE::LIB, std::move( menuLibrary ) ); diff --git a/pcbnew/menubar_footprint_editor.cpp b/pcbnew/menubar_footprint_editor.cpp index 0143e1e628..276290ed10 100644 --- a/pcbnew/menubar_footprint_editor.cpp +++ b/pcbnew/menubar_footprint_editor.cpp @@ -63,16 +63,8 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar() // CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool ); - fileMenu->AddItem( ID_MODEDIT_CREATE_NEW_LIB, - _( "New Library..." ), - _( "Creates an empty library" ), - new_library_xpm, SELECTION_CONDITIONS::ShowAlways ); - - fileMenu->AddItem( ID_MODEDIT_ADD_LIBRARY, - _( "Add Library..." ), - _( "Adds a previously created library" ), - add_library_xpm, SELECTION_CONDITIONS::ShowAlways ); - + fileMenu->AddItem( ACTIONS::newLibrary, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->AddItem( ACTIONS::addLibrary, SELECTION_CONDITIONS::ShowAlways ); fileMenu->AddItem( ID_MODEDIT_NEW_MODULE, AddHotkeyName( _( "&New Footprint..." ), m_hotkeysDescrList, HK_NEW ), _( "Create a new footprint" ), diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index 3e96466e11..ae5a170853 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -183,8 +183,6 @@ enum pcbnew_ids // ID used in module editor: ID_MODEDIT_CHECK, - ID_MODEDIT_CREATE_NEW_LIB, - ID_MODEDIT_ADD_LIBRARY, ID_MODEDIT_SAVE, ID_MODEDIT_SAVE_AS, ID_MODEDIT_SAVE_PNG, diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 1c4b5d1bc5..5784949d3c 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -224,6 +224,20 @@ void PCBNEW_CONTROL::Reset( RESET_REASON aReason ) } +int PCBNEW_CONTROL::AddLibrary( const TOOL_EVENT& aEvent ) +{ + if( m_frame->IsType( FRAME_PCB_MODULE_EDITOR ) || m_frame->IsType( FRAME_PCB ) ) + { + if( aEvent.IsAction( &ACTIONS::newLibrary ) ) + static_cast( m_frame )->CreateNewLibrary(); + else if( aEvent.IsAction( &ACTIONS::addLibrary ) ) + static_cast( m_frame )->AddLibrary(); + } + + return 0; +} + + int PCBNEW_CONTROL::Quit( const TOOL_EVENT& aEvent ) { m_frame->Close( false ); @@ -1040,6 +1054,8 @@ int PCBNEW_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent ) void PCBNEW_CONTROL::setTransitions() { + Go( &PCBNEW_CONTROL::AddLibrary, ACTIONS::newLibrary.MakeEvent() ); + Go( &PCBNEW_CONTROL::AddLibrary, ACTIONS::addLibrary.MakeEvent() ); Go( &PCBNEW_CONTROL::Print, ACTIONS::print.MakeEvent() ); Go( &PCBNEW_CONTROL::Quit, ACTIONS::quit.MakeEvent() ); diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index 960a34badb..a1b7c306f1 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -50,6 +50,7 @@ public: /// @copydoc TOOL_INTERACTIVE::Reset() void Reset( RESET_REASON aReason ) override; + int AddLibrary( const TOOL_EVENT& aEvent ); int Print( const TOOL_EVENT& aEvent ); int Quit( const TOOL_EVENT& aEvent );