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>
|
|
|
|
* Copyright (C) 2010-2011 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file dialog_schematic_find.cpp
|
|
|
|
* @brief Schematic find and replace dialog implementation.
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialog_schematic_find.h>
|
2010-03-16 18:22:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
DEFINE_EVENT_TYPE( EVT_COMMAND_FIND_DRC_MARKER )
|
|
|
|
DEFINE_EVENT_TYPE( EVT_COMMAND_FIND_COMPONENT_IN_LIB )
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_SCH_FIND::DIALOG_SCH_FIND( wxWindow* aParent, wxFindReplaceData* aData,
|
|
|
|
const wxPoint& aPosition, const wxSize& aSize, int aStyle ) :
|
|
|
|
DIALOG_SCH_FIND_BASE( aParent, wxID_ANY, _( "Find" ), aPosition, aSize,
|
|
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | aStyle )
|
|
|
|
{
|
|
|
|
SetData( aData );
|
|
|
|
|
|
|
|
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 );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
int flags = m_findReplaceData->GetFlags();
|
|
|
|
m_radioForward->SetValue( flags & wxFR_DOWN );
|
|
|
|
m_radioBackward->SetValue( ( flags & wxFR_DOWN ) == 0 );
|
|
|
|
m_checkMatchCase->SetValue( flags & wxFR_MATCHCASE );
|
|
|
|
m_checkWholeWord->SetValue( flags & wxFR_WHOLEWORD );
|
2011-02-03 21:57:02 +00:00
|
|
|
m_checkNoWarpCursor->SetValue( flags & FR_NO_WARP_CURSOR );
|
2010-03-16 18:22:59 +00:00
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
/* Whole word and wild card searches are mutually exclusive. */
|
2010-03-16 18:22:59 +00:00
|
|
|
if( !( flags & wxFR_WHOLEWORD ) )
|
|
|
|
m_checkWildcardMatch->SetValue( flags & FR_MATCH_WILDCARD );
|
|
|
|
|
|
|
|
m_checkAllFields->SetValue( flags & FR_SEARCH_ALL_FIELDS );
|
2011-12-21 20:21:15 +00:00
|
|
|
m_checkReplaceReferences->SetValue( flags & FR_REPLACE_REFERENCES );
|
2010-10-20 19:43:58 +00:00
|
|
|
m_checkAllPins->SetValue( flags & FR_SEARCH_ALL_PINS );
|
2010-03-16 18:22:59 +00:00
|
|
|
m_checkWrap->SetValue( flags & FR_SEARCH_WRAP );
|
|
|
|
m_checkCurrentSheetOnly->SetValue( flags & FR_CURRENT_SHEET_ONLY );
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
m_buttonFind->SetDefault();
|
2010-03-16 18:22:59 +00:00
|
|
|
m_comboFind->SetFocus();
|
|
|
|
SetPosition( aPosition );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SCH_FIND::OnClose( wxCloseEvent& aEvent )
|
|
|
|
{
|
|
|
|
SendEvent( wxEVT_COMMAND_FIND_CLOSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SCH_FIND::OnUpdateFindUI( wxUpdateUIEvent& aEvent )
|
|
|
|
{
|
|
|
|
aEvent.Enable( !m_comboFind->GetValue().empty() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-01 16:49:28 +00:00
|
|
|
void DIALOG_SCH_FIND::OnUpdateReplaceUI( wxUpdateUIEvent& aEvent )
|
|
|
|
{
|
|
|
|
aEvent.Enable( HasFlag( wxFR_REPLACEDIALOG ) && !m_comboFind->GetValue().empty() &&
|
2011-12-13 15:37:33 +00:00
|
|
|
(m_findReplaceData->GetFlags() & FR_REPLACE_ITEM_FOUND) );
|
2011-12-01 16:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
void DIALOG_SCH_FIND::OnUpdateWholeWordUI( wxUpdateUIEvent& aEvent )
|
|
|
|
{
|
|
|
|
aEvent.Enable( !m_checkWildcardMatch->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SCH_FIND::OnUpdateWildcardUI( wxUpdateUIEvent& aEvent )
|
|
|
|
{
|
|
|
|
aEvent.Enable( !m_checkWholeWord->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SCH_FIND::OnFind( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
SendEvent( wxEVT_COMMAND_FIND );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-01 16:49:28 +00:00
|
|
|
void DIALOG_SCH_FIND::OnReplace( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
SendEvent( wxEVT_COMMAND_FIND_REPLACE );
|
|
|
|
else if( aEvent.GetId() == wxID_REPLACE_ALL )
|
|
|
|
SendEvent( wxEVT_COMMAND_FIND_REPLACE_ALL );
|
2011-12-01 16:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
void DIALOG_SCH_FIND::OnCancel( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
SendEvent( wxEVT_COMMAND_FIND_CLOSE );
|
|
|
|
Show( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SCH_FIND::SendEvent( const wxEventType& aEventType )
|
|
|
|
{
|
|
|
|
wxFindDialogEvent event( aEventType, GetId() );
|
|
|
|
event.SetEventObject( this );
|
|
|
|
event.SetFindString( m_comboFind->GetValue() );
|
|
|
|
|
2011-12-01 16:49:28 +00:00
|
|
|
int flags = 0;
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
if ( HasFlag( wxFR_REPLACEDIALOG ) )
|
|
|
|
{
|
|
|
|
event.SetReplaceString( m_comboReplace->GetValue() );
|
2011-12-01 16:49:28 +00:00
|
|
|
flags |= FR_SEARCH_REPLACE;
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|
|
|
|
|
2012-01-10 20:12:46 +00:00
|
|
|
if( m_checkReplaceReferences->GetValue() )
|
|
|
|
flags |= FR_REPLACE_REFERENCES;
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
if( m_radioForward->GetValue() )
|
|
|
|
flags |= wxFR_DOWN;
|
|
|
|
|
|
|
|
if( m_checkMatchCase->GetValue() )
|
|
|
|
flags |= wxFR_MATCHCASE;
|
|
|
|
|
|
|
|
if( m_checkWholeWord->GetValue() )
|
|
|
|
flags |= wxFR_WHOLEWORD;
|
|
|
|
|
2011-12-01 16:49:28 +00:00
|
|
|
if( m_checkWildcardMatch->IsShown() && m_checkWildcardMatch->GetValue() )
|
2010-03-16 18:22:59 +00:00
|
|
|
flags |= FR_MATCH_WILDCARD;
|
|
|
|
|
|
|
|
if( m_checkAllFields->GetValue() )
|
|
|
|
flags |= FR_SEARCH_ALL_FIELDS;
|
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
if( m_checkAllPins->GetValue() )
|
|
|
|
flags |= FR_SEARCH_ALL_PINS;
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
if( m_checkWrap->GetValue() )
|
|
|
|
flags |= FR_SEARCH_WRAP;
|
|
|
|
|
|
|
|
if( m_checkCurrentSheetOnly->GetValue() )
|
|
|
|
flags |= FR_CURRENT_SHEET_ONLY;
|
|
|
|
|
2011-02-03 21:57:02 +00:00
|
|
|
if( m_checkNoWarpCursor->GetValue() )
|
|
|
|
flags |= FR_NO_WARP_CURSOR;
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
m_findReplaceData->SetFindString( event.GetFindString() );
|
|
|
|
|
|
|
|
if( HasFlag( wxFR_REPLACEDIALOG )
|
|
|
|
&& ( event.GetEventType() == wxEVT_COMMAND_FIND_REPLACE
|
|
|
|
|| event.GetEventType() == wxEVT_COMMAND_FIND_REPLACE_ALL ) )
|
|
|
|
{
|
|
|
|
m_findReplaceData->SetReplaceString( event.GetReplaceString() );
|
|
|
|
}
|
|
|
|
|
|
|
|
event.SetFlags( flags );
|
|
|
|
|
|
|
|
m_findReplaceData->SetFlags( event.GetFlags() );
|
|
|
|
|
2012-01-10 20:12:46 +00:00
|
|
|
// when we are no using the find/replace (just find)
|
|
|
|
// FR_REPLACE_REFERENCES flag bit is always set to 1 in event flags
|
|
|
|
// but not set in m_findReplaceData
|
|
|
|
if ( ! HasFlag( wxFR_REPLACEDIALOG ) )
|
|
|
|
{
|
|
|
|
flags |= FR_REPLACE_REFERENCES;
|
|
|
|
event.SetFlags( flags );
|
|
|
|
}
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
if( !GetEventHandler()->ProcessEvent( event ) )
|
|
|
|
{
|
|
|
|
GetParent()->GetEventHandler()->ProcessEvent( event );
|
|
|
|
}
|
2011-12-01 16:49:28 +00:00
|
|
|
|
|
|
|
if( event.GetFlags() != flags )
|
|
|
|
m_findReplaceData->SetFlags( event.GetFlags() );
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxArrayString DIALOG_SCH_FIND::GetFindEntries() const
|
|
|
|
{
|
|
|
|
return m_comboFind->GetStrings();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SCH_FIND::SetFindEntries( const wxArrayString& aEntries )
|
|
|
|
{
|
|
|
|
m_comboFind->Append( aEntries );
|
|
|
|
|
2010-03-18 20:35:29 +00:00
|
|
|
if( m_comboFind->GetCount() )
|
2010-03-16 18:22:59 +00:00
|
|
|
m_comboFind->SetSelection( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SCH_FIND::SetReplaceEntries( const wxArrayString& aEntries )
|
|
|
|
{
|
|
|
|
m_comboReplace->Append( aEntries );
|
|
|
|
|
2010-03-18 20:35:29 +00:00
|
|
|
if( m_comboReplace->GetCount() )
|
2010-03-16 18:22:59 +00:00
|
|
|
m_comboReplace->SetSelection( 0 );
|
|
|
|
}
|