Common Actions: Find Previous

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/8968
This commit is contained in:
Mike Williams 2023-01-26 09:36:41 -05:00
parent 3e715c99c8
commit 4b07e3e413
8 changed files with 33 additions and 14 deletions

View File

@ -228,9 +228,15 @@ TOOL_ACTION ACTIONS::findNext( "common.Interactive.findNext",
_( "Find Next" ), _( "Find next match" ),
BITMAPS::find );
TOOL_ACTION ACTIONS::findPrevious( "common.Interactive.findPrevious",
AS_GLOBAL,
MD_SHIFT + WXK_F3, LEGACY_HK_NAME( "Find Previous" ),
_( "Find Previous" ), _( "Find previous match" ),
BITMAPS::find );
TOOL_ACTION ACTIONS::findNextMarker( "common.Interactive.findNextMarker",
AS_GLOBAL,
MD_SHIFT + WXK_F3, LEGACY_HK_NAME( "Find Next Marker" ),
MD_CTRL + MD_SHIFT + WXK_F3, LEGACY_HK_NAME( "Find Next Marker" ),
_( "Find Next Marker" ), "",
BITMAPS::find );

View File

@ -108,7 +108,8 @@ int SCH_FIND_REPLACE_TOOL::UpdateFind( const TOOL_EVENT& aEvent )
SCH_ITEM* SCH_FIND_REPLACE_TOOL::nextMatch( SCH_SCREEN* aScreen, SCH_SHEET_PATH* aSheet,
SCH_ITEM* aAfter, EDA_SEARCH_DATA& aData )
SCH_ITEM* aAfter, EDA_SEARCH_DATA& aData,
bool reversed )
{
bool past_item = !aAfter;
std::vector<SCH_ITEM*> sorted_items;
@ -155,6 +156,9 @@ SCH_ITEM* SCH_FIND_REPLACE_TOOL::nextMatch( SCH_SCREEN* aScreen, SCH_SHEET_PATH*
return a->GetPosition().x < b->GetPosition().x;
} );
if( reversed )
std::reverse( sorted_items.begin(), sorted_items.end() );
for( SCH_ITEM* item : sorted_items )
{
if( item == aAfter )
@ -179,6 +183,7 @@ int SCH_FIND_REPLACE_TOOL::FindNext( const TOOL_EVENT& aEvent )
{
EDA_SEARCH_DATA& data = m_frame->GetFindReplaceData();
bool searchAllSheets = false;
bool isReversed = aEvent.IsAction( &ACTIONS::findPrevious );
try
{
@ -211,7 +216,8 @@ int SCH_FIND_REPLACE_TOOL::FindNext( const TOOL_EVENT& aEvent )
m_selectionTool->ClearSelection();
if( afterSheet || !searchAllSheets )
item = nextMatch( m_frame->GetScreen(), &m_frame->GetCurrentSheet(), afterItem, data );
item = nextMatch( m_frame->GetScreen(), &m_frame->GetCurrentSheet(), afterItem, data,
isReversed );
if( !item && searchAllSheets )
{
@ -239,6 +245,9 @@ int SCH_FIND_REPLACE_TOOL::FindNext( const TOOL_EVENT& aEvent )
return lhs->GetCurrentHash() < rhs->GetCurrentHash();
} );
if( isReversed )
std::reverse( paths.begin(), paths.end() );
for( SCH_SHEET_PATH* sheet : paths )
{
if( afterSheet )
@ -249,7 +258,7 @@ int SCH_FIND_REPLACE_TOOL::FindNext( const TOOL_EVENT& aEvent )
continue;
}
item = nextMatch( sheet->LastScreen(), sheet, nullptr, data );
item = nextMatch( sheet->LastScreen(), sheet, nullptr, data, isReversed );
if( item )
{
@ -367,12 +376,12 @@ int SCH_FIND_REPLACE_TOOL::ReplaceAll( const TOOL_EVENT& aEvent )
{
SCH_SHEET_PATH* currentSheet = &m_frame->GetCurrentSheet();
SCH_ITEM* item = nextMatch( m_frame->GetScreen(), currentSheet, nullptr, data );
SCH_ITEM* item = nextMatch( m_frame->GetScreen(), currentSheet, nullptr, data, false );
while( item )
{
doReplace( item, currentSheet, data );
item = nextMatch( m_frame->GetScreen(), currentSheet, item, data );
item = nextMatch( m_frame->GetScreen(), currentSheet, item, data, false );
}
}
else
@ -386,7 +395,7 @@ int SCH_FIND_REPLACE_TOOL::ReplaceAll( const TOOL_EVENT& aEvent )
for( unsigned ii = 0; ii < sheets.size(); ++ii )
{
SCH_ITEM* item = nextMatch( screen, &sheets[ii], nullptr, data );
SCH_ITEM* item = nextMatch( screen, &sheets[ii], nullptr, data, false );
while( item )
{
@ -416,7 +425,7 @@ int SCH_FIND_REPLACE_TOOL::ReplaceAll( const TOOL_EVENT& aEvent )
}
}
item = nextMatch( screen, &sheets[ii], item, data );
item = nextMatch( screen, &sheets[ii], item, data, false );
}
}
}
@ -437,6 +446,7 @@ void SCH_FIND_REPLACE_TOOL::setTransitions()
Go( &SCH_FIND_REPLACE_TOOL::FindAndReplace, ACTIONS::find.MakeEvent() );
Go( &SCH_FIND_REPLACE_TOOL::FindAndReplace, ACTIONS::findAndReplace.MakeEvent() );
Go( &SCH_FIND_REPLACE_TOOL::FindNext, ACTIONS::findNext.MakeEvent() );
Go( &SCH_FIND_REPLACE_TOOL::FindNext, ACTIONS::findPrevious.MakeEvent() );
Go( &SCH_FIND_REPLACE_TOOL::FindNext, ACTIONS::findNextMarker.MakeEvent() );
Go( &SCH_FIND_REPLACE_TOOL::ReplaceAndFindNext, ACTIONS::replaceAndFindNext.MakeEvent() );
Go( &SCH_FIND_REPLACE_TOOL::ReplaceAll, ACTIONS::replaceAll.MakeEvent() );

View File

@ -78,10 +78,11 @@ private:
* @param aScreen Pointer to the screen used for searching
* @param aAfter Starting match to compare
* @param aData Search data to compare against or NULL to match the first item found
* @param reverse Search in reverse (find previous)
* @return pointer to the next search item found or NULL if nothing found
*/
SCH_ITEM* nextMatch( SCH_SCREEN* aScreen, SCH_SHEET_PATH* aSheet, SCH_ITEM* aAfter,
EDA_SEARCH_DATA& aData );
EDA_SEARCH_DATA& aData, bool reverse );
private:
bool m_foundItemHighlighted;

View File

@ -78,6 +78,7 @@ public:
static TOOL_ACTION find;
static TOOL_ACTION findAndReplace;
static TOOL_ACTION findNext;
static TOOL_ACTION findPrevious;
static TOOL_ACTION findNextMarker;
static TOOL_ACTION replaceAndFindNext;
static TOOL_ACTION replaceAll;

View File

@ -68,7 +68,7 @@ public:
/**
* Finds the next item
*/
void FindNext() { search( true ); }
void FindNext( bool reverse ) { search( !reverse ); }
/**
* The Show method is overridden to make the search combobox

View File

@ -1660,12 +1660,12 @@ void PCB_EDIT_FRAME::ShowFindDialog()
}
void PCB_EDIT_FRAME::FindNext()
void PCB_EDIT_FRAME::FindNext( bool reverse )
{
if( !m_findDialog )
ShowFindDialog();
m_findDialog->FindNext();
m_findDialog->FindNext( reverse );
}

View File

@ -142,7 +142,7 @@ public:
/**
* Find the next item using our existing search parameters.
*/
void FindNext();
void FindNext( bool reverse = false );
/**
* Open a dialog frame to create plot and drill files relative to the current board.

View File

@ -350,7 +350,7 @@ int BOARD_EDITOR_CONTROL::Find( const TOOL_EVENT& aEvent )
int BOARD_EDITOR_CONTROL::FindNext( const TOOL_EVENT& aEvent )
{
m_frame->FindNext();
m_frame->FindNext( aEvent.IsAction( &ACTIONS::findPrevious ) );
return 0;
}
@ -1609,6 +1609,7 @@ void BOARD_EDITOR_CONTROL::setTransitions()
Go( &BOARD_EDITOR_CONTROL::Search, ACTIONS::showSearch.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::Find, ACTIONS::find.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::FindNext, ACTIONS::findNext.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::FindNext, ACTIONS::findPrevious.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::BoardSetup, PCB_ACTIONS::boardSetup.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::ImportNetlist, PCB_ACTIONS::importNetlist.MakeEvent() );