2011-12-21 20:21:15 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Wayne Stambaugh <stambaughw@verizon.net>
|
2019-05-19 21:04:04 +00:00
|
|
|
* Copyright (C) 2010-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-12-21 20:21:15 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialog_schematic_find.h>
|
2019-05-19 21:04:04 +00:00
|
|
|
#include <tool/actions.h>
|
|
|
|
#include <sch_edit_frame.h>
|
2023-01-11 14:17:36 +00:00
|
|
|
#include <tools/sch_find_replace_tool.h>
|
2010-03-16 18:22:59 +00:00
|
|
|
|
|
|
|
|
2022-08-05 02:40:38 +00:00
|
|
|
DIALOG_SCH_FIND::DIALOG_SCH_FIND( SCH_EDIT_FRAME* aParent, SCH_SEARCH_DATA* aData,
|
2010-03-16 18:22:59 +00:00
|
|
|
const wxPoint& aPosition, const wxSize& aSize, int aStyle ) :
|
|
|
|
DIALOG_SCH_FIND_BASE( aParent, wxID_ANY, _( "Find" ), aPosition, aSize,
|
2018-07-05 15:50:21 +00:00
|
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | aStyle ),
|
2019-05-19 21:04:04 +00:00
|
|
|
m_frame( aParent ),
|
2023-01-11 14:17:36 +00:00
|
|
|
m_findReplaceTool( m_frame->GetToolManager()->GetTool<SCH_FIND_REPLACE_TOOL>() ),
|
2020-04-18 11:04:52 +00:00
|
|
|
m_findReplaceData( aData ),
|
|
|
|
m_findDirty( true )
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
|
|
|
wxASSERT_MSG( m_findReplaceData, wxT( "can't create find dialog without data" ) );
|
|
|
|
|
|
|
|
if( aStyle & wxFR_REPLACEDIALOG )
|
|
|
|
{
|
2011-12-01 16:49:28 +00:00
|
|
|
SetTitle( _( "Find and Replace" ) );
|
2011-12-13 15:37:33 +00:00
|
|
|
m_buttonReplace->Show( true );
|
|
|
|
m_buttonReplaceAll->Show( true );
|
2010-03-16 18:22:59 +00:00
|
|
|
m_staticReplace->Show( true );
|
|
|
|
m_comboReplace->Show( true );
|
2023-01-26 17:35:15 +00:00
|
|
|
m_checkSelectedOnly->Show( true );
|
2011-12-21 20:21:15 +00:00
|
|
|
m_checkReplaceReferences->Show( true );
|
2011-12-01 16:49:28 +00:00
|
|
|
m_checkWildcardMatch->Show( false ); // Wildcard replace is not implemented.
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|
|
|
|
|
2022-08-05 02:40:38 +00:00
|
|
|
m_checkMatchCase->SetValue( m_findReplaceData->matchCase );
|
|
|
|
m_checkWholeWord->SetValue( m_findReplaceData->matchMode == EDA_SEARCH_MATCH_MODE::WHOLEWORD );
|
|
|
|
m_checkWildcardMatch->SetValue( m_findReplaceData->matchMode
|
|
|
|
== EDA_SEARCH_MATCH_MODE::WILDCARD );
|
2010-03-16 18:22:59 +00:00
|
|
|
|
2022-08-05 02:40:38 +00:00
|
|
|
m_checkAllFields->SetValue( m_findReplaceData->searchAllFields );
|
|
|
|
m_checkReplaceReferences->SetValue( m_findReplaceData->replaceReferences );
|
|
|
|
m_checkAllPins->SetValue( m_findReplaceData->searchAllPins );
|
|
|
|
m_checkCurrentSheetOnly->SetValue( m_findReplaceData->searchCurrentSheetOnly );
|
2023-01-26 17:35:15 +00:00
|
|
|
m_checkCurrentSheetOnly->Enable( !m_findReplaceData->searchSelectedOnly );
|
|
|
|
m_checkSelectedOnly->SetValue( m_findReplaceData->searchSelectedOnly );
|
2010-03-16 18:22:59 +00:00
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
m_buttonFind->SetDefault();
|
2018-07-05 15:50:21 +00:00
|
|
|
SetInitialFocus( m_comboFind );
|
|
|
|
|
2011-12-21 20:21:15 +00:00
|
|
|
// Adjust the height of the dialog to prevent controls from being hidden when
|
|
|
|
// switching between the find and find/replace modes of the dialog. This ignores
|
|
|
|
// the users preferred height if any of the controls would be hidden.
|
2012-03-08 17:47:23 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
2011-12-21 20:21:15 +00:00
|
|
|
wxSize size = aSize;
|
|
|
|
|
|
|
|
if( aSize != wxDefaultSize )
|
|
|
|
{
|
|
|
|
wxSize bestSize = GetBestSize();
|
|
|
|
|
|
|
|
if( size.GetHeight() != bestSize.GetHeight() )
|
|
|
|
size.SetHeight( bestSize.GetHeight() );
|
|
|
|
}
|
|
|
|
|
|
|
|
SetSize( size );
|
2014-11-19 17:13:55 +00:00
|
|
|
|
|
|
|
GetSizer()->Fit( this ); // Needed on Ubuntu/Unity to display the dialog
|
2010-03-16 18:22:59 +00:00
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
Connect( wxEVT_CHAR, wxKeyEventHandler( DIALOG_SCH_FIND::OnChar ), nullptr, this );
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
void DIALOG_SCH_FIND::OnClose( wxCloseEvent& aEvent )
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
// Notify the SCH_EDIT_FRAME
|
|
|
|
m_frame->OnFindDialogClose();
|
2020-04-18 11:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SCH_FIND::OnIdle( wxIdleEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( m_findDirty )
|
|
|
|
{
|
2023-01-11 14:17:36 +00:00
|
|
|
m_findReplaceTool->UpdateFind( ACTIONS::updateFind.MakeEvent() );
|
2020-04-18 11:04:52 +00:00
|
|
|
m_findDirty = false;
|
|
|
|
}
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-20 00:40:26 +00:00
|
|
|
void DIALOG_SCH_FIND::OnCancel( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
wxCloseEvent dummy;
|
|
|
|
OnClose( dummy );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-01 16:49:28 +00:00
|
|
|
void DIALOG_SCH_FIND::OnUpdateReplaceUI( wxUpdateUIEvent& aEvent )
|
|
|
|
{
|
2023-01-26 17:35:15 +00:00
|
|
|
aEvent.Enable( HasFlag( wxFR_REPLACEDIALOG ) && !m_comboFind->GetValue().empty()
|
|
|
|
&& m_findReplaceTool->HasMatch() );
|
2011-12-01 16:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-12 15:57:17 +00:00
|
|
|
void DIALOG_SCH_FIND::OnUpdateReplaceAllUI( wxUpdateUIEvent& aEvent )
|
|
|
|
{
|
|
|
|
aEvent.Enable( HasFlag( wxFR_REPLACEDIALOG ) && !m_comboFind->GetValue().empty() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
void DIALOG_SCH_FIND::OnChar( wxKeyEvent& aEvent )
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
if( aEvent.GetKeyCode() == WXK_RETURN )
|
|
|
|
{
|
|
|
|
wxCommandEvent dummyCommand;
|
|
|
|
OnFind( dummyCommand );
|
|
|
|
}
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
void DIALOG_SCH_FIND::OnSearchForText( wxCommandEvent& aEvent )
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
2022-08-05 02:40:38 +00:00
|
|
|
m_findReplaceData->findString = m_comboFind->GetValue();
|
2020-04-18 11:04:52 +00:00
|
|
|
m_findDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SCH_FIND::OnSearchForSelect( wxCommandEvent& aEvent )
|
|
|
|
{
|
2022-08-05 02:40:38 +00:00
|
|
|
m_findReplaceData->findString = m_comboFind->GetValue();
|
2020-04-18 11:04:52 +00:00
|
|
|
|
|
|
|
// Move the search string to the top of the list if it isn't already there.
|
|
|
|
if( aEvent.GetSelection() != 0 )
|
|
|
|
{
|
|
|
|
wxString tmp = m_comboFind->GetValue();
|
|
|
|
m_comboFind->Delete( aEvent.GetSelection() );
|
|
|
|
m_comboFind->Insert( tmp, 0 );
|
|
|
|
m_comboFind->SetSelection( 0 );
|
|
|
|
}
|
|
|
|
|
2023-01-11 14:17:36 +00:00
|
|
|
m_findReplaceTool->UpdateFind( ACTIONS::updateFind.MakeEvent() );
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-18 11:04:52 +00:00
|
|
|
void DIALOG_SCH_FIND::OnReplaceWithText( wxCommandEvent& aEvent )
|
|
|
|
{
|
2022-08-05 02:40:38 +00:00
|
|
|
m_findReplaceData->replaceString = m_comboReplace->GetValue();
|
2020-04-18 11:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SCH_FIND::OnReplaceWithSelect( wxCommandEvent& aEvent )
|
|
|
|
{
|
2022-08-05 02:40:38 +00:00
|
|
|
m_findReplaceData->replaceString = m_comboReplace->GetValue();
|
2020-04-18 11:04:52 +00:00
|
|
|
|
|
|
|
// Move the replace string to the top of the list if it isn't already there.
|
|
|
|
if( aEvent.GetSelection() != 0 )
|
|
|
|
{
|
|
|
|
wxString tmp = m_comboReplace->GetValue();
|
|
|
|
m_comboReplace->Delete( aEvent.GetSelection() );
|
|
|
|
m_comboReplace->Insert( tmp, 0 );
|
|
|
|
m_comboReplace->SetSelection( 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SCH_FIND::OnSearchForEnter( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
OnFind( aEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SCH_FIND::OnReplaceWithEnter( wxCommandEvent& aEvent )
|
2018-02-12 22:48:37 +00:00
|
|
|
{
|
|
|
|
OnFind( aEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
void DIALOG_SCH_FIND::OnOptions( wxCommandEvent& aEvent )
|
|
|
|
{
|
2022-07-09 08:28:53 +00:00
|
|
|
updateFlags();
|
|
|
|
m_findDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DIALOG_SCH_FIND::updateFlags()
|
|
|
|
{
|
|
|
|
// Rebuild the search flags in m_findReplaceData from dialog settings
|
2023-01-26 17:35:15 +00:00
|
|
|
m_findReplaceData->matchCase = m_checkMatchCase->GetValue();
|
|
|
|
m_findReplaceData->searchAllFields = m_checkAllFields->GetValue();
|
|
|
|
m_findReplaceData->searchAllPins = m_checkAllPins->GetValue();
|
|
|
|
m_findReplaceData->searchCurrentSheetOnly = m_checkCurrentSheetOnly->GetValue();
|
|
|
|
m_findReplaceData->replaceReferences = m_checkReplaceReferences->GetValue();
|
2019-05-19 21:04:04 +00:00
|
|
|
|
|
|
|
if( m_checkWholeWord->GetValue() )
|
2022-08-05 02:40:38 +00:00
|
|
|
m_findReplaceData->matchMode = EDA_SEARCH_MATCH_MODE::WHOLEWORD;
|
|
|
|
else if( m_checkWildcardMatch->IsShown() && m_checkWildcardMatch->GetValue() )
|
|
|
|
m_findReplaceData->matchMode = EDA_SEARCH_MATCH_MODE::WILDCARD;
|
|
|
|
else
|
|
|
|
m_findReplaceData->matchMode = EDA_SEARCH_MATCH_MODE::PLAIN;
|
2019-05-19 21:04:04 +00:00
|
|
|
|
2023-01-26 17:35:15 +00:00
|
|
|
if( m_checkSelectedOnly->GetValue() )
|
|
|
|
{
|
|
|
|
m_checkCurrentSheetOnly->SetValue( true );
|
|
|
|
m_checkCurrentSheetOnly->Enable( false );
|
|
|
|
m_findReplaceData->searchSelectedOnly = true;
|
|
|
|
}
|
2022-08-05 02:40:38 +00:00
|
|
|
else
|
2023-01-26 17:35:15 +00:00
|
|
|
{
|
|
|
|
m_checkCurrentSheetOnly->Enable( true );
|
|
|
|
m_findReplaceData->searchSelectedOnly = false;
|
|
|
|
}
|
2019-05-19 21:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
void DIALOG_SCH_FIND::OnFind( wxCommandEvent& aEvent )
|
|
|
|
{
|
2022-07-09 08:28:53 +00:00
|
|
|
updateFlags(); // Ensure search flags are up to date
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
int index = m_comboFind->FindString( m_comboFind->GetValue(), true );
|
|
|
|
|
|
|
|
if( index == wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
m_comboFind->Insert( m_comboFind->GetValue(), 0 );
|
|
|
|
}
|
|
|
|
else if( index != 0 )
|
|
|
|
{
|
|
|
|
/* Move the search string to the top of the list if it isn't already there. */
|
|
|
|
wxString tmp = m_comboFind->GetValue();
|
|
|
|
m_comboFind->Delete( index );
|
|
|
|
m_comboFind->Insert( tmp, 0 );
|
|
|
|
m_comboFind->SetSelection( 0 );
|
|
|
|
}
|
|
|
|
|
2023-01-11 14:17:36 +00:00
|
|
|
m_findReplaceTool->FindNext( ACTIONS::findNext.MakeEvent() );
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-01 16:49:28 +00:00
|
|
|
void DIALOG_SCH_FIND::OnReplace( wxCommandEvent& aEvent )
|
|
|
|
{
|
2022-07-09 08:28:53 +00:00
|
|
|
updateFlags(); // Ensure search flags are up to date
|
|
|
|
|
2011-12-01 16:49:28 +00:00
|
|
|
int index = m_comboReplace->FindString( m_comboReplace->GetValue(), true );
|
|
|
|
|
|
|
|
if( index == wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
m_comboReplace->Insert( m_comboReplace->GetValue(), 0 );
|
|
|
|
}
|
|
|
|
else if( index != 0 )
|
|
|
|
{
|
|
|
|
/* Move the search string to the top of the list if it isn't already there. */
|
|
|
|
wxString tmp = m_comboReplace->GetValue();
|
|
|
|
m_comboReplace->Delete( index );
|
|
|
|
m_comboReplace->Insert( tmp, 0 );
|
|
|
|
m_comboReplace->SetSelection( 0 );
|
|
|
|
}
|
|
|
|
|
2011-12-13 15:37:33 +00:00
|
|
|
if( aEvent.GetId() == wxID_REPLACE )
|
2023-01-11 14:17:36 +00:00
|
|
|
m_findReplaceTool->ReplaceAndFindNext( ACTIONS::replaceAndFindNext.MakeEvent() );
|
2011-12-13 15:37:33 +00:00
|
|
|
else if( aEvent.GetId() == wxID_REPLACE_ALL )
|
2023-01-11 14:17:36 +00:00
|
|
|
m_findReplaceTool->ReplaceAll( ACTIONS::replaceAll.MakeEvent() );
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxArrayString DIALOG_SCH_FIND::GetFindEntries() const
|
|
|
|
{
|
2020-09-24 17:46:01 +00:00
|
|
|
int index = m_comboFind->FindString( m_comboFind->GetValue(), true );
|
|
|
|
|
|
|
|
if( index == wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
m_comboFind->Insert( m_comboFind->GetValue(), 0 );
|
|
|
|
}
|
|
|
|
else if( index != 0 )
|
|
|
|
{
|
|
|
|
/* Move the search string to the top of the list if it isn't already there. */
|
|
|
|
wxString tmp = m_comboFind->GetValue();
|
|
|
|
m_comboFind->Delete( index );
|
|
|
|
m_comboFind->Insert( tmp, 0 );
|
|
|
|
}
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
return m_comboFind->GetStrings();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-18 23:30:45 +00:00
|
|
|
void DIALOG_SCH_FIND::SetFindEntries( const wxArrayString& aEntries, const wxString& aFindString )
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
|
|
|
m_comboFind->Append( aEntries );
|
|
|
|
|
2021-08-20 18:47:27 +00:00
|
|
|
while( m_comboFind->GetCount() > 10 )
|
|
|
|
{
|
|
|
|
m_frame->GetFindHistoryList().pop_back();
|
|
|
|
m_comboFind->Delete( 9 );
|
|
|
|
}
|
|
|
|
|
2022-03-18 23:30:45 +00:00
|
|
|
if( !aFindString.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_comboFind->SetValue( aFindString );
|
|
|
|
m_comboFind->SelectAll();
|
|
|
|
}
|
|
|
|
else if( m_comboFind->GetCount() )
|
2015-06-15 17:12:44 +00:00
|
|
|
{
|
2010-03-16 18:22:59 +00:00
|
|
|
m_comboFind->SetSelection( 0 );
|
2015-06-15 17:12:44 +00:00
|
|
|
m_comboFind->SelectAll();
|
|
|
|
}
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SCH_FIND::SetReplaceEntries( const wxArrayString& aEntries )
|
|
|
|
{
|
|
|
|
m_comboReplace->Append( aEntries );
|
|
|
|
|
2021-08-20 18:47:27 +00:00
|
|
|
while( m_comboReplace->GetCount() > 10 )
|
|
|
|
{
|
|
|
|
m_frame->GetFindHistoryList().pop_back();
|
|
|
|
m_comboReplace->Delete( 9 );
|
|
|
|
}
|
|
|
|
|
2010-03-18 20:35:29 +00:00
|
|
|
if( m_comboReplace->GetCount() )
|
2015-06-15 17:12:44 +00:00
|
|
|
{
|
2010-03-16 18:22:59 +00:00
|
|
|
m_comboReplace->SetSelection( 0 );
|
2015-06-15 17:12:44 +00:00
|
|
|
m_comboFind->SelectAll();
|
|
|
|
}
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|