Commit a63a2006 authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Add Eeschema replace code.

* Enable replace toolbar button and menu entry.
* Improve find replace logging granularity.
* Fix find and replace dialog control hiding and disabling.
* Minor improvements to the SCH_FIND_REPLACE_DATA object.
* Move find collector list iterator into the collector object.
* Add visibility override flag to EDA_ITEM to temporarily show items that
  are hidden during find and replace.
parent 5465966c
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -194,6 +194,16 @@ bool EDA_ITEM::Matches( const wxString& aText, wxFindReplaceData& aSearchData )
}
}




bool EDA_ITEM::Replace( wxFindReplaceData& aSearchData, wxString& aText )
{
    wxCHECK_MSG( IsReplaceable(), false,
                 wxT( "Attempt to replace text in <" ) + GetClass() + wxT( "> item." ) );

    return aText.Replace( aSearchData.GetFindString(),
                          aSearchData.GetReplaceString(), false ) != 0;
}


bool EDA_ITEM::operator<( const EDA_ITEM& aItem ) const
bool EDA_ITEM::operator<( const EDA_ITEM& aItem ) const
{
{
    wxFAIL_MSG( wxString::Format( wxT( "Less than operator not defined for item type %s." ),
    wxFAIL_MSG( wxString::Format( wxT( "Less than operator not defined for item type %s." ),
+2 −0
Original line number Original line Diff line number Diff line
@@ -42,6 +42,8 @@


const wxString traceFindReplace( wxT( "KicadFindReplace" ) );
const wxString traceFindReplace( wxT( "KicadFindReplace" ) );


const wxString traceFindItem( wxT( "KicadFindItem" ) );



bool sort_schematic_items( const SCH_ITEM* aItem1, const SCH_ITEM* aItem2 )
bool sort_schematic_items( const SCH_ITEM* aItem1, const SCH_ITEM* aItem2 )
{
{
+4 −4
Original line number Original line Diff line number Diff line
@@ -1047,8 +1047,8 @@
                            </object>
                            </object>
                        </object>
                        </object>
                        <object class="sizeritem" expanded="0">
                        <object class="sizeritem" expanded="0">
                            <property name="border">5</property>
                            <property name="border">6</property>
                            <property name="flag">wxALL</property>
                            <property name="flag">wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT</property>
                            <property name="proportion">0</property>
                            <property name="proportion">0</property>
                            <object class="wxButton" expanded="0">
                            <object class="wxButton" expanded="0">
                                <property name="bg"></property>
                                <property name="bg"></property>
@@ -1104,8 +1104,8 @@
                            </object>
                            </object>
                        </object>
                        </object>
                        <object class="sizeritem" expanded="0">
                        <object class="sizeritem" expanded="0">
                            <property name="border">5</property>
                            <property name="border">6</property>
                            <property name="flag">wxALL</property>
                            <property name="flag">wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT</property>
                            <property name="proportion">0</property>
                            <property name="proportion">0</property>
                            <object class="wxButton" expanded="0">
                            <object class="wxButton" expanded="0">
                                <property name="bg"></property>
                                <property name="bg"></property>
+7 −2
Original line number Original line Diff line number Diff line
@@ -17,6 +17,8 @@ DIALOG_SCH_FIND::DIALOG_SCH_FIND( wxWindow* aParent, wxFindReplaceData* aData,
    if( aStyle & wxFR_REPLACEDIALOG )
    if( aStyle & wxFR_REPLACEDIALOG )
    {
    {
        SetTitle( _( "Find and Replace" ) );
        SetTitle( _( "Find and Replace" ) );
        m_buttonReplace->Show( true );
        m_buttonReplaceAll->Show( true );
        m_staticReplace->Show( true );
        m_staticReplace->Show( true );
        m_comboReplace->Show( true );
        m_comboReplace->Show( true );
        m_checkWildcardMatch->Show( false );  // Wildcard replace is not implemented.
        m_checkWildcardMatch->Show( false );  // Wildcard replace is not implemented.
@@ -60,7 +62,7 @@ void DIALOG_SCH_FIND::OnUpdateFindUI( wxUpdateUIEvent& aEvent )
void DIALOG_SCH_FIND::OnUpdateReplaceUI( wxUpdateUIEvent& aEvent )
void DIALOG_SCH_FIND::OnUpdateReplaceUI( wxUpdateUIEvent& aEvent )
{
{
    aEvent.Enable( HasFlag( wxFR_REPLACEDIALOG ) && !m_comboFind->GetValue().empty() &&
    aEvent.Enable( HasFlag( wxFR_REPLACEDIALOG ) && !m_comboFind->GetValue().empty() &&
                   (m_findReplaceData->GetFlags() | FR_REPLACE_ITEM_FOUND) );
                   (m_findReplaceData->GetFlags() & FR_REPLACE_ITEM_FOUND) );
}
}




@@ -114,7 +116,10 @@ void DIALOG_SCH_FIND::OnReplace( wxCommandEvent& aEvent )
        m_comboReplace->SetSelection( 0 );
        m_comboReplace->SetSelection( 0 );
    }
    }


    SendEvent( wxEVT_COMMAND_FIND );
    if( aEvent.GetId() == wxID_REPLACE )
        SendEvent( wxEVT_COMMAND_FIND_REPLACE );
    else if( aEvent.GetId() == wxID_REPLACE_ALL )
        SendEvent( wxEVT_COMMAND_FIND_REPLACE_ALL );
}
}




+34 −0
Original line number Original line Diff line number Diff line
@@ -53,6 +53,14 @@ enum SchematicFindReplaceFlags
};
};




/**
 * Definition FR_MASK_NON_SEARCH_FLAGS
 * is used to mask find/replace flag bits that do not effect the search results.
 */
#define FR_MASK_NON_SEARCH_FLAGS  ~( wxFR_DOWN | FR_SEARCH_WRAP | FR_NO_WARP_CURSOR | \
                                     FR_REPLACE_ITEM_FOUND )


/**
/**
 * Class SCH_FIND_REPLACE_DATA
 * Class SCH_FIND_REPLACE_DATA
 * adds missing useful comparison and assignment operators to the wxFindReplaceData object.
 * adds missing useful comparison and assignment operators to the wxFindReplaceData object.
@@ -84,6 +92,32 @@ public:
    {
    {
        return !( *this == aFindReplaceData );
        return !( *this == aFindReplaceData );
    }
    }


    /**
     * Function ChangesSearch
     * tests \a aFindReplaceData to see if it would result in a change in the search
     * results.
     *
     * @param aFindReplaceData A reference to a #SCH_FIND_REPLACE_DATA object to compare
     *                         against.
     * @return True if \a aFindReplaceData would result in a search and/or replace change,
     *         otherwise false.
     */
    bool ChangesSearch( SCH_FIND_REPLACE_DATA& aFindReplaceData )
    {
        return ( (GetFindString() != aFindReplaceData.GetFindString())
              || (GetSearchFlags() != aFindReplaceData.GetSearchFlags()) );
    }

    bool IsReplacing() const { return (GetFlags() & FR_SEARCH_REPLACE) != 0; }

private:
    /**
     * Function GetSearchFlags
     * @return The flags that only effect the search result.
     */
    wxUint32 GetSearchFlags() const { return GetFlags() & FR_MASK_NON_SEARCH_FLAGS; }
};
};




Loading