Commit 85d2f2f1 authored by Wayne Stambaugh's avatar Wayne Stambaugh

Eeschema find and replace improvements.

* Add check box and flag to ignore replacing the component reference
  designator field.
* Fix a resizing bug when switching between the find and replace modes of
  the find/replace dialog.
* Fix replace component reference designator field bug.
* Force rebuild of search list when schematic is modified and the replace
  dialog is closed.
* Prevent finding the next item when the find/replace dialog is closed.
* Respect warp mouse pointer setting when closing find/replace dialog.
* Fix duplicate mnemonic control accelerator keys in find/replace dialog.
parent 6c28cdc6
......@@ -528,7 +528,7 @@
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="0">
<property name="bg"></property>
<property name="checked">0</property>
<property name="checked">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="enabled">1</property>
......@@ -536,7 +536,7 @@
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Match &amp;whole word</property>
<property name="label">Match whole wor&amp;d</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">m_checkWholeWord</property>
......@@ -764,7 +764,7 @@
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Search all component &amp;fields</property>
<property name="label">Search all com&amp;ponent fields</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">m_checkAllFields</property>
......@@ -821,7 +821,7 @@
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Search all pin names and numbers</property>
<property name="label">Search all pin &amp;names and numbers</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">m_checkAllPins</property>
......@@ -878,7 +878,7 @@
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Search the current sheet on&amp;ly</property>
<property name="label">Search the current &amp;sheet onl&amp;y</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">m_checkCurrentSheetOnly</property>
......@@ -921,6 +921,63 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">6</property>
<property name="flag">wxBOTTOM|wxLEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<property name="bg"></property>
<property name="checked">0</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="font"></property>
<property name="hidden">1</property>
<property name="id">wxID_ANY</property>
<property name="label">Replace componen&amp;t reference designators</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">m_checkReplaceReferences</property>
<property name="permission">protected</property>
<property name="pos"></property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnChar"></event>
<event name="OnCheckBox"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">6</property>
<property name="flag">wxBOTTOM|wxLEFT|wxRIGHT</property>
......@@ -935,7 +992,7 @@
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Do not warp cursor to found item</property>
<property name="label">D&amp;o not warp cursor to found item</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">m_checkNoWarpCursor</property>
......
/*
* 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.
*/
#include "dialog_schematic_find.h"
......@@ -21,6 +50,7 @@ DIALOG_SCH_FIND::DIALOG_SCH_FIND( wxWindow* aParent, wxFindReplaceData* aData,
m_buttonReplaceAll->Show( true );
m_staticReplace->Show( true );
m_comboReplace->Show( true );
m_checkReplaceReferences->Show( true );
m_checkWildcardMatch->Show( false ); // Wildcard replace is not implemented.
}
......@@ -36,6 +66,7 @@ DIALOG_SCH_FIND::DIALOG_SCH_FIND( wxWindow* aParent, wxFindReplaceData* aData,
m_checkWildcardMatch->SetValue( flags & FR_MATCH_WILDCARD );
m_checkAllFields->SetValue( flags & FR_SEARCH_ALL_FIELDS );
m_checkReplaceReferences->SetValue( flags & FR_REPLACE_REFERENCES );
m_checkAllPins->SetValue( flags & FR_SEARCH_ALL_PINS );
m_checkWrap->SetValue( flags & FR_SEARCH_WRAP );
m_checkCurrentSheetOnly->SetValue( flags & FR_CURRENT_SHEET_ONLY );
......@@ -43,7 +74,21 @@ DIALOG_SCH_FIND::DIALOG_SCH_FIND( wxWindow* aParent, wxFindReplaceData* aData,
m_buttonFind->SetDefault();
m_comboFind->SetFocus();
SetPosition( aPosition );
SetSize( aSize );
// 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.
wxSize size = aSize;
if( aSize != wxDefaultSize )
{
wxSize bestSize = GetBestSize();
if( size.GetHeight() != bestSize.GetHeight() )
size.SetHeight( bestSize.GetHeight() );
}
SetSize( size );
}
......@@ -142,6 +187,9 @@ void DIALOG_SCH_FIND::SendEvent( const wxEventType& aEventType )
{
event.SetReplaceString( m_comboReplace->GetValue() );
flags |= FR_SEARCH_REPLACE;
if( m_checkReplaceReferences->GetValue() )
flags |= FR_REPLACE_REFERENCES;
}
if( m_radioForward->GetValue() )
......
#ifndef __dialog_schematic_find__
#define __dialog_schematic_find__
/*
* 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
......@@ -12,6 +33,9 @@
* find out how matching is performed against that item.
*/
#ifndef __dialog_schematic_find__
#define __dialog_schematic_find__
#include "dialog_schematic_find_base.h"
#include <wx/fdrepdlg.h> // Use the wxFindReplaceDialog events, data, and enums.
......@@ -49,7 +73,10 @@ enum SchematicFindReplaceFlags
/// Used by the search event handler to let the dialog know that a replaceable
/// item has been found.
FR_REPLACE_ITEM_FOUND = wxFR_MATCHCASE << 8
FR_REPLACE_ITEM_FOUND = wxFR_MATCHCASE << 8,
/// Used by replace to ignore the component reference designator field.
FR_REPLACE_REFERENCES = wxFR_MATCHCASE << 9
};
......
......@@ -67,7 +67,8 @@ DIALOG_SCH_FIND_BASE::DIALOG_SCH_FIND_BASE( wxWindow* parent, wxWindowID id, con
leftSizer->Add( leftGridSizer, 0, wxALL|wxEXPAND, 6 );
m_checkWholeWord = new wxCheckBox( this, wxID_ANY, _("Match &whole word"), wxDefaultPosition, wxDefaultSize, 0 );
m_checkWholeWord = new wxCheckBox( this, wxID_ANY, _("Match whole wor&d"), wxDefaultPosition, wxDefaultSize, 0 );
m_checkWholeWord->SetValue(true);
leftSizer->Add( m_checkWholeWord, 0, wxALL, 6 );
m_checkMatchCase = new wxCheckBox( this, wxID_ANY, _("&Match case"), wxDefaultPosition, wxDefaultSize, 0 );
......@@ -80,16 +81,21 @@ DIALOG_SCH_FIND_BASE::DIALOG_SCH_FIND_BASE( wxWindow* parent, wxWindowID id, con
m_checkWrap->SetValue(true);
leftSizer->Add( m_checkWrap, 0, wxBOTTOM|wxLEFT|wxRIGHT, 6 );
m_checkAllFields = new wxCheckBox( this, wxID_ANY, _("Search all component &fields"), wxDefaultPosition, wxDefaultSize, 0 );
m_checkAllFields = new wxCheckBox( this, wxID_ANY, _("Search all com&ponent fields"), wxDefaultPosition, wxDefaultSize, 0 );
leftSizer->Add( m_checkAllFields, 0, wxBOTTOM|wxLEFT|wxRIGHT, 6 );
m_checkAllPins = new wxCheckBox( this, wxID_ANY, _("Search all pin names and numbers"), wxDefaultPosition, wxDefaultSize, 0 );
m_checkAllPins = new wxCheckBox( this, wxID_ANY, _("Search all pin &names and numbers"), wxDefaultPosition, wxDefaultSize, 0 );
leftSizer->Add( m_checkAllPins, 0, wxBOTTOM|wxRIGHT|wxLEFT, 6 );
m_checkCurrentSheetOnly = new wxCheckBox( this, wxID_ANY, _("Search the current sheet on&ly"), wxDefaultPosition, wxDefaultSize, 0 );
m_checkCurrentSheetOnly = new wxCheckBox( this, wxID_ANY, _("Search the current &sheet onl&y"), wxDefaultPosition, wxDefaultSize, 0 );
leftSizer->Add( m_checkCurrentSheetOnly, 0, wxBOTTOM|wxLEFT|wxRIGHT, 6 );
m_checkNoWarpCursor = new wxCheckBox( this, wxID_ANY, _("Do not warp cursor to found item"), wxDefaultPosition, wxDefaultSize, 0 );
m_checkReplaceReferences = new wxCheckBox( this, wxID_ANY, _("Replace componen&t reference designators"), wxDefaultPosition, wxDefaultSize, 0 );
m_checkReplaceReferences->Hide();
leftSizer->Add( m_checkReplaceReferences, 0, wxBOTTOM|wxLEFT|wxRIGHT, 6 );
m_checkNoWarpCursor = new wxCheckBox( this, wxID_ANY, _("D&o not warp cursor to found item"), wxDefaultPosition, wxDefaultSize, 0 );
leftSizer->Add( m_checkNoWarpCursor, 0, wxBOTTOM|wxLEFT|wxRIGHT, 6 );
mainSizer->Add( leftSizer, 1, wxALL|wxEXPAND, 6 );
......
......@@ -48,6 +48,7 @@ class DIALOG_SCH_FIND_BASE : public wxDialog
wxCheckBox* m_checkAllFields;
wxCheckBox* m_checkAllPins;
wxCheckBox* m_checkCurrentSheetOnly;
wxCheckBox* m_checkReplaceReferences;
wxCheckBox* m_checkNoWarpCursor;
wxButton* m_buttonFind;
wxButton* m_buttonReplace;
......
......@@ -309,13 +309,14 @@ void SCH_EDIT_FRAME::OnFindSchematicItem( wxFindDialogEvent& aEvent )
searchCriteria.SetFindString( aEvent.GetFindString() );
searchCriteria.SetReplaceString( aEvent.GetReplaceString() );
if( m_foundItems.GetFindReplaceData().ChangesSearch( searchCriteria ) )
if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_CLOSE )
{
if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_CLOSE )
{
warpCursor = true;
}
else if( aEvent.GetFlags() & FR_CURRENT_SHEET_ONLY && g_RootSheet->CountSheets() > 1 )
if( m_foundItems.GetCount() == 0 )
return;
}
else if( m_foundItems.IsSearchRequired( searchCriteria ) )
{
if( aEvent.GetFlags() & FR_CURRENT_SHEET_ONLY && g_RootSheet->CountSheets() > 1 )
{
m_foundItems.Collect( searchCriteria, m_CurrentSheet );
}
......
......@@ -494,13 +494,14 @@ SEARCH_RESULT SCH_FIND_COLLECTOR::Inspect( EDA_ITEM* aItem, const void* aTestDat
void SCH_FIND_COLLECTOR::Collect( SCH_FIND_REPLACE_DATA& aFindReplaceData,
SCH_SHEET_PATH* aSheetPath )
{
if( !m_findReplaceData.ChangesSearch( aFindReplaceData ) )
if( !m_findReplaceData.ChangesSearch( aFindReplaceData ) && !m_List.empty() && !m_forceSearch )
return;
m_findReplaceData = aFindReplaceData;
Empty(); // empty the collection just in case
m_data.clear();
m_foundIndex = 0;
m_forceSearch = false;
if( aSheetPath )
{
......
......@@ -221,6 +221,10 @@ class SCH_FIND_COLLECTOR : public COLLECTOR
/// The current found item list index.
int m_foundIndex;
/// A flag to indicate that the schemtic has been modified and a new search must be
/// performed even if the search criteria hasn't changed.
bool m_forceSearch;
/**
* Function atEnd
* tests if #m_foundIndex is at the end of the list give the current find/replace
......@@ -247,8 +251,11 @@ public:
{
SetScanTypes( aScanTypes );
m_foundIndex = 0;
m_forceSearch = false;
}
void SetForceSearch() { m_forceSearch = true; }
/**
* Function UpdateIndex
* updates the list index according to the current find and replace criteria.
......@@ -266,12 +273,19 @@ public:
SCH_FIND_COLLECTOR_DATA GetFindData( int aIndex );
/**
* Function GetFindReplaceData
* Function IsSearchRequired
* checks the current collector state agaianst \a aFindReplaceData to see if a new search
* needs to be performed to update the collector.
*
* @return A reference to a #SCH_FIND_REPLACE_DATA object containing the current
* search criteria.
* @param aFindReplaceData A #SCH_FIND_REPLACE_DATA object containing the search criteria
* to test for changes against the current search criteria.
* @return True if \a aFindReplaceData would require a new search to be performaed or
* the force search flag is true. Otherwise, false is returned.
*/
SCH_FIND_REPLACE_DATA& GetFindReplaceData() { return m_findReplaceData; }
bool IsSearchRequired( SCH_FIND_REPLACE_DATA& aFindReplaceData )
{
return m_findReplaceData.ChangesSearch( aFindReplaceData ) || m_forceSearch;
}
/**
* Function GetText()
......
......@@ -364,7 +364,8 @@ bool SCH_FIELD::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint
bool match;
wxString text = GetText();
if( (m_id > VALUE) && !(aSearchData.GetFlags() & FR_SEARCH_ALL_FIELDS) )
if( ((m_id > VALUE) && !(aSearchData.GetFlags() & FR_SEARCH_ALL_FIELDS))
|| ((m_id == REFERENCE) && !(aSearchData.GetFlags() & FR_REPLACE_REFERENCES)) )
return false;
wxLogTrace( traceFindItem, wxT( " child item " ) + GetSelectMenuText() );
......@@ -398,6 +399,40 @@ bool SCH_FIELD::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint
}
bool SCH_FIELD::Replace( wxFindReplaceData& aSearchData, void* aAuxData )
{
bool isReplaced;
wxString text = GetText();
if( m_id == REFERENCE && aAuxData != NULL )
{
wxCHECK_MSG( aSearchData.GetFlags() & FR_REPLACE_REFERENCES, false,
wxT( "Invalid replace component reference field call." ) ) ;
SCH_COMPONENT* component = (SCH_COMPONENT*) m_Parent;
wxCHECK_MSG( component != NULL, false,
wxT( "No component associated with field" ) + text );
text = component->GetRef( (SCH_SHEET_PATH*) aAuxData );
if( component->GetPartCount() > 1 )
text << LIB_COMPONENT::ReturnSubReference( component->GetUnit() );
isReplaced = EDA_ITEM::Replace( aSearchData, text );
if( isReplaced )
component->SetRef( (SCH_SHEET_PATH*) aAuxData, text );
}
else
{
isReplaced = EDA_ITEM::Replace( aSearchData, m_Text );
}
return isReplaced;
}
void SCH_FIELD::Rotate( wxPoint rotationPoint )
{
RotatePoint( &m_Pos, rotationPoint, 900 );
......
......@@ -203,12 +203,9 @@ public:
void* aAuxData, wxPoint* aFindLocation );
/**
* @copydoc EDA_ITEM::Replace(wxFindReplaceData&)
* @copydoc EDA_ITEM::Replace(wxFindReplaceData&,void*)
*/
virtual bool Replace( wxFindReplaceData& aSearchData )
{
return EDA_ITEM::Replace( aSearchData, m_Text );
}
virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL );
virtual wxString GetSelectMenuText() const;
......
......@@ -955,7 +955,7 @@ bool SCH_SHEET::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint
}
bool SCH_SHEET::Replace( wxFindReplaceData& aSearchData )
bool SCH_SHEET::Replace( wxFindReplaceData& aSearchData, void* aAuxData )
{
return EDA_ITEM::Replace( aSearchData, m_name );
}
......
......@@ -206,9 +206,9 @@ public:
virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation );
/**
* @copydoc EDA_ITEM::Replace(wxFindReplaceData&)
* @copydoc EDA_ITEM::Replace(wxFindReplaceData&,void*)
*/
virtual bool Replace( wxFindReplaceData& aSearchData )
virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL )
{
return EDA_ITEM::Replace( aSearchData, m_Text );
}
......@@ -579,9 +579,9 @@ public:
virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation );
/**
* @copydoc EDA_ITEM::Replace(wxFindReplaceData&)
* @copydoc EDA_ITEM::Replace(wxFindReplaceData&,void*)
*/
virtual bool Replace( wxFindReplaceData& aSearchData );
virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL );
/**
* @copydoc EDA_ITEM::IsReplaceable()
......
......@@ -207,9 +207,9 @@ public:
virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation );
/**
* @copydoc EDA_ITEM::Replace(wxFindReplaceData&)
* @copydoc EDA_ITEM::Replace(wxFindReplaceData&,void*)
*/
virtual bool Replace( wxFindReplaceData& aSearchData )
virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL )
{
return EDA_ITEM::Replace( aSearchData, m_Text );
}
......
......@@ -545,6 +545,9 @@ void SCH_EDIT_FRAME::OnModify()
GetScreen()->SetModify();
GetScreen()->SetSave();
if( m_dlgFindReplace == NULL )
m_foundItems.SetForceSearch();
wxString date = GenDate();
SCH_SCREENS s_list;
......@@ -559,6 +562,7 @@ void SCH_EDIT_FRAME::OnModify()
screen->m_Date = date;
}
/*****************************************************************************
* Enable or disable menu entry and toolbar buttons according to current
* conditions.
......@@ -680,7 +684,6 @@ void SCH_EDIT_FRAME::OnFindItems( wxCommandEvent& aEvent )
m_dlgFindReplace->SetFindEntries( m_findStringHistoryList );
m_dlgFindReplace->SetReplaceEntries( m_replaceStringHistoryList );
m_dlgFindReplace->SetMinSize( m_dlgFindReplace->GetBestSize() );
m_dlgFindReplace->Show( true );
}
......
......@@ -661,9 +661,11 @@ public:
*
* @param aSearchData A reference to a wxFindReplaceData object containing the
* search and replace criteria.
* @param aAuxData A pointer to optional data required for the search or NULL
* if not used.
* @return True if the item text was modified, otherwise false.
*/
virtual bool Replace( wxFindReplaceData& aSearchData ) { return false; }
virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL ) { return false; }
/**
* Function IsReplaceable
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment