void SCH_EDIT_FRAME::OnFindReplace( wxFindDialogEvent& aEvent ) { SCH_FIND_COLLECTOR_DATA data; bool warpCursor = !( aEvent.GetFlags() & FR_NO_WARP_CURSOR ); SCH_ITEM* item = (SCH_ITEM*) m_foundItems.GetItem( data ); wxCHECK_RET( item != NULL, wxT( "Invalid replace item in find collector list." ) ); wxLogTrace( traceFindReplace, wxT( "Replacing %s with %s in item %s" ), GetChars( aEvent.GetFindString() ), GetChars( aEvent.GetReplaceString() ), GetChars( m_foundItems.GetText() ) ); SCH_ITEM* undoItem = data.GetParent(); if( undoItem == NULL ) undoItem = item; SetUndoItem( undoItem ); if( m_foundItems.ReplaceItem() ) { OnModify(); SaveUndoItemInUndoList( undoItem ); RedrawScreen( data.GetPosition(), warpCursor ); } OnFindSchematicItem( aEvent ); if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_REPLACE_ALL ) { while( ( item = (SCH_ITEM*) m_foundItems.GetItem( data ) ) != NULL ) { wxLogTrace( traceFindReplace, wxT( "Replacing %s with %s in item %s" ), GetChars( aEvent.GetFindString() ), GetChars( aEvent.GetReplaceString() ), GetChars( m_foundItems.GetText() ) ); SCH_ITEM* undoItem = data.GetParent(); // Don't save child items in undo list. if( undoItem == NULL ) undoItem = item; SetUndoItem( undoItem ); if( m_foundItems.ReplaceItem() ) { OnModify(); SaveUndoItemInUndoList( undoItem ); RedrawScreen( data.GetPosition(), warpCursor ); } OnFindSchematicItem( aEvent ); } } }
void wxFindReplaceDialogBase::Send(wxFindDialogEvent& event) { // we copy the data to dialog->GetData() as well m_FindReplaceData->m_Flags = event.GetFlags(); m_FindReplaceData->m_FindWhat = event.GetFindString(); if ( HasFlag(wxFR_REPLACEDIALOG) && (event.GetEventType() == wxEVT_FIND_REPLACE || event.GetEventType() == wxEVT_FIND_REPLACE_ALL) ) { m_FindReplaceData->m_ReplaceWith = event.GetReplaceString(); } // translate wxEVT_FIND_NEXT to wxEVT_FIND if needed if ( event.GetEventType() == wxEVT_FIND_NEXT ) { if ( m_FindReplaceData->m_FindWhat != m_lastSearch ) { event.SetEventType(wxEVT_FIND); m_lastSearch = m_FindReplaceData->m_FindWhat; } } if ( !GetEventHandler()->ProcessEvent(event) ) { // the event is not propagated upwards to the parent automatically // because the dialog is a top level window, so do it manually as // in 9 cases of 10 the message must be processed by the dialog // owner and not the dialog itself (void)GetParent()->GetEventHandler()->ProcessEvent(event); } }
void MyFrame::OnFindDialog(wxFindDialogEvent& event) { wxEventType type = event.GetEventType(); if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT ) { wxLogMessage(wxT("Find %s'%s' (flags: %s)"), type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""), event.GetFindString().c_str(), DecodeFindDialogEventFlags(event.GetFlags()).c_str()); } else if ( type == wxEVT_COMMAND_FIND_REPLACE || type == wxEVT_COMMAND_FIND_REPLACE_ALL ) { wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"), type == wxEVT_COMMAND_FIND_REPLACE_ALL ? _T("all ") : wxT(""), event.GetFindString().c_str(), event.GetReplaceString().c_str(), DecodeFindDialogEventFlags(event.GetFlags()).c_str()); } else if ( type == wxEVT_COMMAND_FIND_CLOSE ) { wxFindReplaceDialog *dlg = event.GetDialog(); int idMenu; const wxChar *txt; if ( dlg == m_dlgFind ) { txt = _T("Find"); idMenu = DIALOGS_FIND; m_dlgFind = NULL; } else if ( dlg == m_dlgReplace ) { txt = _T("Replace"); idMenu = DIALOGS_REPLACE; m_dlgReplace = NULL; } else { txt = _T("Unknown"); idMenu = wxID_ANY; wxFAIL_MSG( _T("unexpected event") ); } wxLogMessage(wxT("%s dialog is being closed."), txt); if ( idMenu != wxID_ANY ) { GetMenuBar()->Check(idMenu, false); } dlg->Destroy(); } else { wxLogError(wxT("Unknown find dialog event!")); } }
void MyFrame::MenuReplaceAll ( wxFindDialogEvent& event ) { if (stc==0) return; int flags = 0; if (event.GetFlags() & wxFR_WHOLEWORD) flags += wxSTC_FIND_WHOLEWORD; if (event.GetFlags() & wxFR_MATCHCASE) flags += wxSTC_FIND_MATCHCASE; ReplaceAll(event.GetFindString(), event.GetReplaceString(), flags); }
void SCH_EDIT_FRAME::OnFindSchematicItem( wxFindDialogEvent& aEvent ) { SCH_FIND_REPLACE_DATA searchCriteria; SCH_FIND_COLLECTOR_DATA data; searchCriteria.SetFlags( aEvent.GetFlags() ); searchCriteria.SetFindString( aEvent.GetFindString() ); searchCriteria.SetReplaceString( aEvent.GetReplaceString() ); if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_CLOSE ) { if( m_foundItems.GetCount() == 0 ) return; // Refresh the search cache in case something has changed. This prevents any stale // pointers from crashing Eeschema when the wxEVT_FIND_CLOSE event is handled. if( IsSearchCacheObsolete( searchCriteria ) ) { if( aEvent.GetFlags() & FR_CURRENT_SHEET_ONLY && g_RootSheet->CountSheets() > 1 ) { m_foundItems.Collect( searchCriteria, m_CurrentSheet ); } else { m_foundItems.Collect( searchCriteria ); } } } else if( IsSearchCacheObsolete( searchCriteria ) ) { if( aEvent.GetFlags() & FR_CURRENT_SHEET_ONLY && g_RootSheet->CountSheets() > 1 ) { m_foundItems.Collect( searchCriteria, m_CurrentSheet ); } else { m_foundItems.Collect( searchCriteria ); } } else { EDA_ITEM* currentItem = m_foundItems.GetItem( data ); if( currentItem != NULL ) currentItem->SetForceVisible( false ); m_foundItems.UpdateIndex(); } updateFindReplaceView( aEvent ); }
void SavvyEditor::AppFrame::OnFindDialog(wxFindDialogEvent& a_Event) { wxEventType type = a_Event.GetEventType(); if (type == wxEVT_FIND || type == wxEVT_FIND_NEXT) { if (!DoFind(a_Event.GetFindString(), a_Event.GetFlags())) { wxMessageBox(wxT("No more matches."), DEFAULT_FRAME_TITLE); } } else if (type == wxEVT_FIND_REPLACE) { if (!DoReplace(a_Event.GetFindString(), a_Event.GetReplaceString(), a_Event.GetFlags())) { wxMessageBox(wxT("Nothing to replace."), DEFAULT_FRAME_TITLE); } } else if (type == wxEVT_FIND_REPLACE_ALL) { int numReplaced = DoReplaceAll(a_Event.GetFindString(), a_Event.GetReplaceString(), a_Event.GetFlags()); if (numReplaced > 0) { wxString numString = wxString::Format(wxT("%i"), numReplaced); numString.Append(" occurrences replaced."); wxMessageBox(numString, DEFAULT_FRAME_TITLE); } else { wxMessageBox(wxT("Nothing to replace."), DEFAULT_FRAME_TITLE); } } else if (type == wxEVT_FIND_CLOSE) { wxFindReplaceDialog *dlg = a_Event.GetDialog(); int idMenu; const wxChar *txt; if (dlg == m_FindDialog) { txt = wxT("Find"); idMenu = ID_FindDialog; m_FindDialog = NULL; } else if (dlg == m_ReplaceDialog) { txt = wxT("Replace"); idMenu = ID_ReplaceDialog; m_ReplaceDialog = NULL; } else { txt = wxT("Unknown"); idMenu = wxID_ANY; wxFAIL_MSG(wxT("unexpected event")); } if (idMenu != wxID_ANY) { GetMenuBar()->Check(idMenu, false); } dlg->Destroy(); } else { wxLogError(wxT("Unknown find dialog event!")); } }
void DecisionLogicFrame::OnFindDialog(wxFindDialogEvent& event) { wxEventType type = event.GetEventType(); bool bMatchCase = (event.GetFlags() & wxFR_MATCHCASE) > 0; bool bMatchWholeWord = (event.GetFlags() & wxFR_WHOLEWORD) > 0; if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT ) { if (event.GetFlags() & wxFR_PROJECT) { if (!m_last_find_pos) m_last_find_pos = new wxPoint(0,0); bool res = m_gui->FindTextInAnyTable((wstring)event.GetFindString(), m_last_find_pos, m_found_name, m_worker->GetProjectManager(), bMatchCase, bMatchWholeWord); if (res == false) { wxMessageBox(_T("No more matches")); m_found_name.clear(); } if (m_last_find_pos->x == -1 && m_last_find_pos->y == -1) { delete m_last_find_pos; //next find will start a new table m_last_find_pos = NULL; } } else { if (type == wxEVT_COMMAND_FIND || (m_last_find_pos != NULL && (m_last_find_pos->x == -1 && m_last_find_pos->y == -1))) { if (m_last_find_pos) { delete m_last_find_pos; m_last_find_pos = NULL; } m_last_find_pos = new wxPoint(0,0); } //highlight on current open table if (!m_last_find_pos) m_last_find_pos = new wxPoint(0,0); m_gui->FindTextInActiveTable((wstring)event.GetFindString(), m_last_find_pos, bMatchCase, bMatchWholeWord); if (m_last_find_pos->x == -1 && m_last_find_pos->y == -1) { wxMessageBox(_T("Reached the end of the table, no matches")); if (m_last_find_pos) { delete m_last_find_pos; m_last_find_pos = NULL; } } } } else if ( type == wxEVT_COMMAND_FIND_REPLACE || type == wxEVT_COMMAND_FIND_REPLACE_ALL ) { if (type == wxEVT_COMMAND_FIND_REPLACE_ALL) { if (m_last_find_pos) { delete m_last_find_pos; m_last_find_pos = NULL; } m_last_find_pos = new wxPoint(0,0); do { m_gui->FindTextInActiveTable((wstring)event.GetFindString(), m_last_find_pos, bMatchCase, bMatchWholeWord, true, (wstring)event.GetReplaceString()); } while (m_last_find_pos->x != -1 && m_last_find_pos->y != -1); } else { if (!m_last_find_pos) m_last_find_pos = new wxPoint(0,0); m_gui->FindTextInActiveTable((wstring)event.GetFindString(), m_last_find_pos, bMatchCase, bMatchWholeWord, true, (wstring)event.GetReplaceString()); if (m_last_find_pos->x == -1 && m_last_find_pos->y == -1) wxMessageBox(_T("Reached the end of the table, no matches")); } } else if ( type == wxEVT_COMMAND_FIND_CLOSE ) { if (m_last_find_pos) { delete m_last_find_pos; m_last_find_pos = NULL; } m_dlgReplace->Destroy(); m_dlgReplace = NULL; } else { wxLogError(wxT("Unknown find dialog event!")); } }
void wxSTEditorFindReplacePanel::Send(wxFindDialogEvent& event) { // we copy the data to dialog->GetData() as well m_findReplaceData->SetFlags(event.GetFlags()); m_findReplaceData->SetFindString(event.GetFindString()); if (!event.GetFindString().IsEmpty()) m_findReplaceData->AddFindString(event.GetFindString()); if ( HasFlag(wxFR_REPLACEDIALOG) && (event.GetEventType() == wxEVT_COMMAND_FIND_REPLACE || event.GetEventType() == wxEVT_COMMAND_FIND_REPLACE_ALL) ) { m_findReplaceData->SetReplaceString(event.GetReplaceString()); m_findReplaceData->AddReplaceString(event.GetReplaceString()); } // translate wxEVT_COMMAND_FIND_NEXT to wxEVT_COMMAND_FIND if needed if ( event.GetEventType() == wxEVT_COMMAND_FIND_NEXT ) { if ( m_findReplaceData->GetFindString() != m_lastSearch ) { event.SetEventType(wxEVT_COMMAND_FIND); m_lastSearch = m_findReplaceData->GetFindString(); } } // ExtraLong is the line number pressed in the find all editor // when -1 it means that we want a new find all search if (m_findReplaceData->HasFlag(STE_FR_FINDALL) && m_resultEditor && (event.GetExtraLong() == -1) && ((event.GetEventType() == wxEVT_COMMAND_FIND) || (event.GetEventType() == wxEVT_COMMAND_FIND_NEXT))) { m_findReplaceData->GetFindAllStrings()->Clear(); m_resultEditor->SetReadOnly(false); m_resultEditor->SetText(wxEmptyString); m_resultEditor->SetReadOnly(true); } wxWindow *target = GetTargetWindow(); // first send event to ourselves then to the target if ( !GetEventHandler()->ProcessEvent(event) && target ) { // the event is not propagated upwards to the parent automatically // because the dialog is a top level window, so do it manually as // in 9 cases of 10 the message must be processed by the dialog // owner and not the dialog itself (void)target->GetEventHandler()->ProcessEvent(event); } if (m_findReplaceData->HasFlag(STE_FR_FINDALL) && m_resultEditor && (event.GetExtraLong() == -1) && ((event.GetEventType() == wxEVT_COMMAND_FIND) || (event.GetEventType() == wxEVT_COMMAND_FIND_NEXT))) { wxSTEditor* edit = GetEditor(); if (edit) { m_resultEditor->SetLanguage(edit->GetLanguageId()); } wxArrayString* findAllStrings = m_findReplaceData->GetFindAllStrings(); size_t n, count = findAllStrings->GetCount(); wxString str; for (n = 0; n < count; n++) str += findAllStrings->Item(n).AfterFirst(wxT('|')); m_resultEditor->Clear(); m_resultEditor->ClearAllIndicators(); m_resultEditor->SetReadOnly(false); m_resultEditor->SetText(str); m_resultEditor->SetReadOnly(true); m_resultEditor->Colourise(0, -1); wxSTEditorStyles::GetGlobalEditorStyles().SetEditorStyle( 3, STE_STYLE_STRING, m_resultEditor, false); wxSTEditorStyles::GetGlobalEditorStyles().SetEditorStyle( 4, STE_STYLE_NUMBER, m_resultEditor, false); for (n = 0; n < count; n++) { str = findAllStrings->Item(n).AfterFirst(wxT('|')); int pos = m_resultEditor->PositionFromLine(n); m_resultEditor->StartStyling(pos, 31); int length = str.BeforeFirst(wxT('(')).Length() - 1; m_resultEditor->SetStyling(length, 3); pos = pos + length + 1; m_resultEditor->StartStyling(pos, 31); length = str.AfterFirst(wxT('(')).BeforeFirst(wxT(')')).Length() + 2; m_resultEditor->SetStyling(length, 4); } m_resultEditor->IndicateAllStrings(m_findReplaceData->GetFindString(), m_findReplaceData->GetFlags(), wxSTC_INDIC0_MASK); } UpdateButtons(); }
void wxSTEditorNotebook::OnFindDialog(wxFindDialogEvent &event) { wxSTERecursionGuard guard(m_rGuard_OnFindDialog); if (guard.IsInside()) return; // currently opened page is where the search starts wxSTEditor *editor = GetEditor(); if (!editor) return; // just search the given page by letting the editor handle it if (!STE_HASBIT(event.GetFlags(), STE_FR_ALLDOCS)) { editor->HandleFindDialogEvent(event); return; } wxEventType eventType = event.GetEventType(); wxString findString = event.GetFindString(); long flags = event.GetFlags(); editor->SetFindString(findString, true); editor->SetFindFlags(flags, true); STE_TextPos pos = editor->GetCurrentPos(); if ((eventType == wxEVT_COMMAND_FIND) && STE_HASBIT(flags, STE_FR_WHOLEDOC)) pos = -1; // we have to move cursor to start of word if last backwards search suceeded // note cmp is ok since regexp doesn't handle searching backwards if ((eventType == wxEVT_COMMAND_FIND_NEXT) && !STE_HASBIT(flags, wxFR_DOWN)) { if ((labs(editor->GetSelectionEnd() - editor->GetSelectionStart()) == long(findString.Length())) && (editor->GetFindReplaceData()->StringCmp(findString, editor->GetSelectedText(), flags))) pos -= (STE_TextPos)findString.Length() + 1; // doesn't matter if it matches or not, skip it } if (eventType == wxEVT_STEFIND_GOTO) { wxString findAllString(event.GetString()); wxString fileName; int line_number = 0; int line_start_pos = 0; int string_start_pos = 0; int string_length = 0; wxString lineText; bool ok = wxSTEditorFindReplaceData::ParseFindAllString(findAllString, fileName, line_number, line_start_pos, string_start_pos, string_length, lineText); int page = wxNOT_FOUND; if (ok) page = FindEditorPageByFileName(fileName); if (page != wxNOT_FOUND) { SetSelection(page); GetEditor(page)->HandleFindDialogEvent(event); } } else if ((eventType == wxEVT_COMMAND_FIND) || (eventType == wxEVT_COMMAND_FIND_NEXT)) { if (STE_HASBIT(flags, STE_FR_FINDALL|STE_FR_BOOKMARKALL)) { // sum up all of the find strings in all editors int n, count = (int)GetPageCount(); for (n = 0; n < count; n++) { wxSTEditor* e = GetEditor(n); if (e) e->HandleFindDialogEvent(event); } } else { if ((eventType == wxEVT_COMMAND_FIND) && STE_HASBIT(flags, STE_FR_WHOLEDOC)) pos = 0; pos = FindString(findString, pos, flags, STE_FINDSTRING_SELECT|STE_FINDSTRING_GOTO); if (pos >= 0) { //editor->SetFocus(); } else { wxBell(); // bell ok to signify no more occurances? } } } else if (eventType == wxEVT_COMMAND_FIND_REPLACE) { if (!editor->GetFindReplaceData()->StringCmp(findString, editor->GetSelectedText(), flags)) { wxBell(); return; } STE_TextPos pos = editor->GetSelectionStart(); wxString replaceString(event.GetReplaceString()); editor->ReplaceSelection(replaceString); editor->EnsureCaretVisible(); editor->SetSelection(pos, pos + (STE_TextPos)replaceString.Length()); editor->UpdateCanDo(true); //editor->SetFocus(); } else if (eventType == wxEVT_COMMAND_FIND_REPLACE_ALL) { wxString replaceString(event.GetReplaceString()); if (editor->GetFindReplaceData()->StringCmp(findString, replaceString, flags)) return; wxBusyCursor busy; int pages = 0; int count = ReplaceAllStrings(findString, replaceString, flags, &pages); wxString msg( wxString::Format(_("Replaced %d occurances of\n'%s' with '%s'\nin %d documents."), count, findString.wx_str(), replaceString.wx_str(), pages) ); wxMessageBox( msg, _("Finished replacing"), wxOK|wxICON_INFORMATION|wxSTAY_ON_TOP, wxGetTopLevelParent(this) ); // make it be on top in GTK //wxDynamicCast(event.GetEventObject(), wxDialog)); } else if (eventType == wxEVT_COMMAND_FIND_CLOSE) { //if (wxDynamicCast(event.GetEventObject(), wxDialog)) // ((wxDialog*)event.GetEventObject())->Destroy(); } }
void SCH_EDIT_FRAME::OnFindSchematicItem( wxFindDialogEvent& aEvent ) { static wxPoint itemPosition; // the actual position of the matched item. SCH_SHEET_LIST schematic; wxString msg; SCH_FIND_REPLACE_DATA searchCriteria; bool warpCursor = !( aEvent.GetFlags() & FR_NO_WARP_CURSOR ); SCH_FIND_COLLECTOR_DATA data; searchCriteria.SetFlags( aEvent.GetFlags() ); searchCriteria.SetFindString( aEvent.GetFindString() ); searchCriteria.SetReplaceString( aEvent.GetReplaceString() ); if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_CLOSE ) { 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 ); } else { m_foundItems.Collect( searchCriteria ); } } else { EDA_ITEM* currentItem = m_foundItems.GetItem( data ); if( currentItem != NULL ) currentItem->SetForceVisible( false ); m_foundItems.UpdateIndex(); } if( m_foundItems.GetItem( data ) != NULL ) { wxLogTrace( traceFindReplace, wxT( "Found " ) + m_foundItems.GetText() ); SCH_SHEET_PATH* sheet = schematic.GetSheet( data.GetSheetPath() ); wxCHECK_RET( sheet != NULL, wxT( "Could not find sheet path " ) + data.GetSheetPath() ); // Make the item temporarily visible just in case it's hide flag is set. This // has no effect on objects that don't support hiding. If this is a close find // dialog event, clear the temporary visibility flag. if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_CLOSE ) m_foundItems.GetItem( data )->SetForceVisible( false ); else m_foundItems.GetItem( data )->SetForceVisible( true ); if( sheet->PathHumanReadable() != m_CurrentSheet->PathHumanReadable() ) { sheet->LastScreen()->SetZoom( GetScreen()->GetZoom() ); *m_CurrentSheet = *sheet; m_CurrentSheet->UpdateAllScreenReferences(); SetScreen( sheet->LastScreen() ); } sheet->LastScreen()->SetCrossHairPosition( data.GetPosition() ); RedrawScreen( data.GetPosition(), warpCursor ); msg = m_foundItems.GetText(); if( aEvent.GetFlags() & FR_SEARCH_REPLACE ) aEvent.SetFlags( aEvent.GetFlags() | FR_REPLACE_ITEM_FOUND ); } else { if( aEvent.GetFlags() & FR_SEARCH_REPLACE ) aEvent.SetFlags( aEvent.GetFlags() & ~FR_REPLACE_ITEM_FOUND ); msg.Printf( _( "No item found matching %s." ), GetChars( aEvent.GetFindString() ) ); } SetStatusText( msg ); }
// TOOD: map flags; detect wrap around void Edit::OnFindDialog(wxFindDialogEvent& event) { wxEventType type = event.GetEventType(); if(type == wxEVT_FIND || type == wxEVT_FIND_NEXT) { const wxString find = event.GetFindString(); const int curPos = FindLine(event); if(curPos > -1) { GotoPos(curPos); SetSelectionStart(curPos); SetSelectionEnd(curPos + find.size()); } else { wxLogMessage(wxT("Unable to find \"%s\""), find); } } else if(type == wxEVT_FIND_REPLACE) { const wxString find = event.GetFindString(); const int curPos = FindLine(event); if(curPos > -1) { SetSelectionStart(curPos); SetSelectionEnd(curPos + find.size()); ReplaceSelection(event.GetReplaceString()); } else { wxLogMessage(wxT("Unable to find \"%s\""), find); } } else if(type == wxEVT_FIND_REPLACE_ALL) { const wxString find = event.GetFindString(); const wxString replace = event.GetReplaceString(); const long minPos = GetCurrentPos(); const long maxPos = GetLastPosition(); int count = 0; int curPos = FindText(minPos, maxPos, find); while(curPos > minPos) { ++count; SetSelectionStart(curPos); SetSelectionEnd(curPos + find.size()); ReplaceSelection(replace); curPos = FindText(curPos + replace.size(), maxPos, find); } wxLogMessage(wxT("Replaced %d instance(s) of \"%s\" were replaced with \"%s\""), count, find, replace); } // FIX ME... else if(type == wxEVT_FIND_CLOSE) { /* if(event.GetDialog() == m_dlgFind) { wxDELETE(m_dlgFind); m_dlgFind = NULL; } else if(event.GetDialog() == m_dlgReplace) { wxDELETE(m_dlgReplace); m_dlgReplace = NULL; } */ } }
void SCH_EDIT_FRAME::updateFindReplaceView( wxFindDialogEvent& aEvent ) { wxString msg; SCH_SHEET_LIST schematic( g_RootSheet ); SCH_FIND_COLLECTOR_DATA data; SCH_FIND_REPLACE_DATA searchCriteria; bool warpCursor = !( aEvent.GetFlags() & FR_NO_WARP_CURSOR ); searchCriteria.SetFlags( aEvent.GetFlags() ); searchCriteria.SetFindString( aEvent.GetFindString() ); searchCriteria.SetReplaceString( aEvent.GetReplaceString() ); if( m_foundItems.GetItem( data ) != NULL ) { wxLogTrace( traceFindReplace, wxT( "Found " ) + m_foundItems.GetText() ); SCH_SHEET_PATH* sheet = schematic.GetSheetByPath( data.GetSheetPath() ); wxCHECK_RET( sheet != NULL, wxT( "Could not find sheet path " ) + data.GetSheetPath() ); SCH_ITEM* item = (SCH_ITEM*)m_foundItems.GetItem( data ); // Make the item temporarily visible just in case it's hide flag is set. This // has no effect on objects that don't support hiding. If this is a close find // dialog event, clear the temporary visibility flag. if( item ) { if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_CLOSE ) item->SetForceVisible( false ); else if( item->Type() == SCH_FIELD_T && !( (SCH_FIELD*) item )->IsVisible() ) item->SetForceVisible( true ); } if( sheet->PathHumanReadable() != m_CurrentSheet->PathHumanReadable() ) { sheet->LastScreen()->SetZoom( GetScreen()->GetZoom() ); *m_CurrentSheet = *sheet; m_CurrentSheet->UpdateAllScreenReferences(); SetScreen( sheet->LastScreen() ); } // careful here SetCrossHairPosition( data.GetPosition() ); RedrawScreen( data.GetPosition(), warpCursor ); msg = m_foundItems.GetText(); if( aEvent.GetFlags() & FR_SEARCH_REPLACE ) aEvent.SetFlags( aEvent.GetFlags() | FR_REPLACE_ITEM_FOUND ); } else { if( aEvent.GetFlags() & FR_SEARCH_REPLACE ) aEvent.SetFlags( aEvent.GetFlags() & ~FR_REPLACE_ITEM_FOUND ); msg.Printf( _( "No item found matching %s." ), GetChars( aEvent.GetFindString() ) ); } SetStatusText( msg ); }
void SCH_EDIT_FRAME::OnFindReplace( wxFindDialogEvent& aEvent ) { static int nextFoundIndex = 0; SCH_ITEM* item; SCH_SHEET_PATH* sheet; SCH_SHEET_LIST schematic( g_RootSheet ); SCH_FIND_COLLECTOR_DATA data; SCH_FIND_REPLACE_DATA searchCriteria; searchCriteria.SetFlags( aEvent.GetFlags() ); searchCriteria.SetFindString( aEvent.GetFindString() ); searchCriteria.SetReplaceString( aEvent.GetReplaceString() ); m_foundItems.SetReplaceString( aEvent.GetReplaceString() ); if( IsSearchCacheObsolete( searchCriteria ) ) { if( aEvent.GetFlags() & FR_CURRENT_SHEET_ONLY && g_RootSheet->CountSheets() > 1 ) { m_foundItems.Collect( searchCriteria, m_CurrentSheet ); } else { m_foundItems.Collect( searchCriteria ); } // Restore the next found index on cache refresh. Prevents single replace events // from starting back at the beginning of the cache. m_foundItems.SetFoundIndex( nextFoundIndex ); } if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_REPLACE_ALL ) { while( ( item = (SCH_ITEM*) m_foundItems.GetItem( data ) ) != NULL ) { SCH_ITEM* undoItem = data.GetParent(); // Don't save child items in undo list. if( undoItem == NULL ) undoItem = item; SetUndoItem( undoItem ); sheet = schematic.GetSheetByPath( data.GetSheetPath() ); wxCHECK_RET( sheet != NULL, wxT( "Could not find sheet path " ) + data.GetSheetPath() ); if( m_foundItems.ReplaceItem( sheet ) ) { OnModify(); SaveUndoItemInUndoList( undoItem ); updateFindReplaceView( aEvent ); } m_foundItems.IncrementIndex(); if( m_foundItems.PassedEnd() ) break; } } else { item = (SCH_ITEM*) m_foundItems.GetItem( data ); wxCHECK_RET( item != NULL, wxT( "Invalid replace item in find collector list." ) ); SCH_ITEM* undoItem = data.GetParent(); if( undoItem == NULL ) undoItem = item; SetUndoItem( undoItem ); sheet = schematic.GetSheetByPath( data.GetSheetPath() ); wxCHECK_RET( sheet != NULL, wxT( "Could not find sheet path " ) + data.GetSheetPath() ); if( m_foundItems.ReplaceItem( sheet ) ) { OnModify(); SaveUndoItemInUndoList( undoItem ); updateFindReplaceView( aEvent ); } m_foundItems.IncrementIndex(); nextFoundIndex = m_foundItems.GetFoundIndex(); } // End the replace if we are at the end if the list. This prevents an infinite loop if // wrap search is selected and all of the items have been replaced with a value that // still satisfies the search criteria. if( m_foundItems.PassedEnd() ) aEvent.SetFlags( aEvent.GetFlags() & ~FR_REPLACE_ITEM_FOUND ); }