From 65782d5c5a50acfc4490702503d5a6037693a603 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 9 Dec 2020 20:48:04 +0000 Subject: [PATCH] Move delete-again-to-delete-locked-objects to hypertext in infobar. Fixes https://gitlab.com/kicad/code/kicad/issues/6367 --- pcbnew/tools/edit_tool.cpp | 69 +++++++++++++++++++++++++------------- pcbnew/tools/edit_tool.h | 16 +++++---- 2 files changed, 56 insertions(+), 29 deletions(-) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index f38fa9d731..9603dd8ec1 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -55,6 +55,8 @@ #include using namespace std::placeholders; #include "kicad_clipboard.h" +#include +#include #include #include #include @@ -120,10 +122,11 @@ void EditToolSelectionFilter( GENERAL_COLLECTOR& aCollector, int aFlags, EDIT_TOOL::EDIT_TOOL() : - PCB_TOOL_BASE( "pcbnew.InteractiveEdit" ), - m_selectionTool( NULL ), - m_dragging( false ), - m_lockedSelected( false ) + PCB_TOOL_BASE( "pcbnew.InteractiveEdit" ), + m_selectionTool( NULL ), + m_dragging( false ), + m_dismissInfobarOnNextSel( false ), + m_forceDeleteLockedItems( false ) { } @@ -625,7 +628,7 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) } while( ( evt = Wait() ) ); // Assignment (instead of equality test) is intentional - m_lockedSelected = false; + m_forceDeleteLockedItems = false; controls->ForceCursorPosition( false ); controls->ShowCursor( false ); controls->SetAutoPan( false ); @@ -1279,9 +1282,9 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) return 0; // N.B. Setting the CUT flag prevents lock filtering as we only want to delete the items that - // were copied to the clipboard, no more, no fewer. Filtering for locked item, if any will be + // were copied to the clipboard, no more, no fewer. Any filtering for locked items will be // done in the copyToClipboard() routine - if( !isCut ) + if( !m_forceDeleteLockedItems && !isCut ) { // Second RequestSelection removes locked items but keeps a copy of their pointers selectionCopy = m_selectionTool->RequestSelection( @@ -1443,29 +1446,34 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) else m_commit->Push( _( "Delete" ) ); - if( !m_lockedSelected && !lockedItems.empty() ) + if( !m_forceDeleteLockedItems && !lockedItems.empty() ) { - ///> Popup nag for deleting locked items - m_lockedSelected = true; m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &lockedItems ); - m_statusPopup->SetText( _( "Locked items cannot be deleted" ) ); - m_statusPopup->PopupFor( 2000 ); - m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, 20 ) ); - Activate(); + WX_INFOBAR* infobar = frame()->GetInfoBar(); + wxString msg = _( "Locked items in the selection were not deleted." ); + wxString link = _( "Delete locked items" ); - while( m_lockedSelected && m_statusPopup->IsShown() ) - { - m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, 20 ) ); - Wait(); - } + wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY, link, wxEmptyString ); + button->Bind( wxEVT_COMMAND_HYPERLINK, std::function( + [&]( wxHyperlinkEvent& aEvent ) + { + m_forceDeleteLockedItems = true; + { + m_toolMgr->RunAction( ACTIONS::doDelete, true ); + } + m_forceDeleteLockedItems = false; - // Ensure statusPopup is hidden after use - m_statusPopup->Hide(); + frame()->GetInfoBar()->Dismiss(); + m_dismissInfobarOnNextSel = false; + } ) ); + + infobar->RemoveAllButtons(); + infobar->AddButton( button ); + infobar->ShowMessageFor( msg, 4000, wxICON_INFORMATION ); + m_dismissInfobarOnNextSel = true; } - m_lockedSelected = false; - return 0; } @@ -1924,6 +1932,18 @@ int EDIT_TOOL::cutToClipboard( const TOOL_EVENT& aEvent ) } +int EDIT_TOOL::onSelectionEvent( const TOOL_EVENT& aEvent ) +{ + if( m_dismissInfobarOnNextSel ) + { + frame()->GetInfoBar()->Dismiss(); + m_dismissInfobarOnNextSel = false; + } + + return 0; +} + + void EDIT_TOOL::setTransitions() { Go( &EDIT_TOOL::GetAndPlace, PCB_ACTIONS::getAndPlace.MakeEvent() ); @@ -1948,6 +1968,9 @@ void EDIT_TOOL::setTransitions() Go( &EDIT_TOOL::copyToClipboard, ACTIONS::copy.MakeEvent() ); Go( &EDIT_TOOL::copyToClipboard, PCB_ACTIONS::copyWithReference.MakeEvent() ); Go( &EDIT_TOOL::cutToClipboard, ACTIONS::cut.MakeEvent() ); + + Go( &EDIT_TOOL::onSelectionEvent, EVENTS::SelectedEvent ); + Go( &EDIT_TOOL::onSelectionEvent, EVENTS::UnselectedEvent ); } diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index 4b39872e8c..2ee509f165 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -203,14 +203,18 @@ private: bool pickReferencePoint( const wxString& aTooltip, const wxString& aSuccessMessage, const wxString& aCanceledMessage, VECTOR2I& aReferencePoint ); + int onSelectionEvent( const TOOL_EVENT& aEvent ); private: - SELECTION_TOOL* m_selectionTool; // Selection tool used for obtaining selected items - bool m_dragging; // Indicates objects are being dragged right now - bool m_lockedSelected; // Determines if we prompt before removing locked objects - VECTOR2I m_cursor; // Last cursor position (needed for getModificationPoint() - // to avoid changes of edit reference point). - std::unique_ptr m_commit; + SELECTION_TOOL* m_selectionTool; // Selection tool used for obtaining selected items + + bool m_dragging; // Indicates objects are being dragged right now + bool m_dismissInfobarOnNextSel; + bool m_forceDeleteLockedItems; // Delete even locked items if set + VECTOR2I m_cursor; // Last cursor position (needed for getModificationPoint() + // to avoid changes of edit reference point). + + std::unique_ptr m_commit; std::unique_ptr m_statusPopup; };