Fixed replace bug (#338) and cleaned search and replace code up a bit.

Originally committed to SVN as r957.
This commit is contained in:
Rodrigo Braz Monteiro 2007-03-28 01:11:52 +00:00
parent 27b08cc8aa
commit ee3178a8e1
3 changed files with 65 additions and 54 deletions

View file

@ -190,9 +190,12 @@ void DialogSearchReplace::OnKeyDown (wxKeyEvent &event) {
}
/////////////
// Find next
void DialogSearchReplace::OnFindNext (wxCommandEvent &event) {
///////////////////
// Find or replace
void DialogSearchReplace::FindReplace(int mode) {
// Check mode
if (mode < 0 || mode > 2) return;
// Variables
wxString LookFor = FindEdit->GetValue();
if (LookFor.IsEmpty()) return;
@ -205,67 +208,50 @@ void DialogSearchReplace::OnFindNext (wxCommandEvent &event) {
Search.CanContinue = true;
Search.affect = Affect->GetSelection();
Search.field = Field->GetSelection();
Search.FindNext();
if (hasReplace) {
// Find
if (mode == 0) {
Search.FindNext();
if (hasReplace) {
wxString ReplaceWith = ReplaceEdit->GetValue();
Search.ReplaceWith = ReplaceWith;
Options.AddToRecentList(ReplaceWith,_T("Recent replace"));
}
}
// Replace
else {
wxString ReplaceWith = ReplaceEdit->GetValue();
Search.ReplaceWith = ReplaceWith;
if (mode == 1) Search.ReplaceNext();
else Search.ReplaceAll();
Options.AddToRecentList(ReplaceWith,_T("Recent replace"));
}
}
// Add to history
Options.AddToRecentList(LookFor,_T("Recent find"));
UpdateDropDowns();
}
/////////////
// Find next
void DialogSearchReplace::OnFindNext (wxCommandEvent &event) {
FindReplace(0);
}
////////////////
// Replace next
void DialogSearchReplace::OnReplaceNext (wxCommandEvent &event) {
// Variables
wxString LookFor = FindEdit->GetValue();
wxString ReplaceWith = ReplaceEdit->GetValue();
if (LookFor.IsEmpty()) return;
// Setup
Search.isReg = CheckRegExp->IsChecked() && CheckRegExp->IsEnabled();
Search.matchCase = CheckMatchCase->IsChecked();
Search.LookFor = LookFor;
Search.ReplaceWith = ReplaceWith;
Search.affect = Affect->GetSelection();
Search.field = Field->GetSelection();
Search.updateVideo = CheckUpdateVideo->IsChecked() && CheckUpdateVideo->IsEnabled();
Search.ReplaceNext();
// Add to history
Options.AddToRecentList(LookFor,_T("Recent find"));
Options.AddToRecentList(ReplaceWith,_T("Recent replace"));
UpdateDropDowns();
FindReplace(1);
}
///////////////
// Replace all
void DialogSearchReplace::OnReplaceAll (wxCommandEvent &event) {
// Setup
wxString LookFor = FindEdit->GetValue();
wxString ReplaceWith = ReplaceEdit->GetValue();
if (LookFor.IsEmpty()) return;
// Do search
Search.isReg = CheckRegExp->IsChecked() && CheckRegExp->IsEnabled();
Search.matchCase = CheckMatchCase->IsChecked();
Search.LookFor = LookFor;
Search.ReplaceWith = ReplaceWith;
Search.affect = Affect->GetSelection();
Search.field = Field->GetSelection();
Search.updateVideo = CheckUpdateVideo->IsChecked() && CheckUpdateVideo->IsEnabled();
Search.ReplaceAll();
// Add to history
Options.AddToRecentList(LookFor,_T("Recent find"));
Options.AddToRecentList(ReplaceWith,_T("Recent replace"));
UpdateDropDowns();
FindReplace(2);
}
@ -509,6 +495,7 @@ void SearchReplaceEngine::ReplaceAll() {
if (count > 0) {
grid->ass->FlagAsModified(_("replace"));
grid->CommitChanges();
grid->editBox->Update();
wxMessageBox(wxString::Format(_("%i matches were replaced."),count));
}

View file

@ -105,6 +105,7 @@ private:
wxRadioBox *Field;
void UpdateDropDowns();
void FindReplace(int mode); // 0 = find, 1 = replace next, 2 = replace all
void OnClose (wxCommandEvent &event);
void OnFindNext (wxCommandEvent &event);

View file

@ -42,6 +42,10 @@
/////////
// Reset
void AegiVideoFrame::Reset() {
// Note that this function DOES NOT unallocate memory.
// Use Clear() for that
// Zero variables
for (int i=0;i<4;i++) {
data[i] = NULL;
pitch[i] = 0;
@ -49,6 +53,8 @@ void AegiVideoFrame::Reset() {
memSize = 0;
w = 0;
h = 0;
// Set properties
format = FORMAT_NONE;
flipped = false;
cppAlloc = true;
@ -66,19 +72,25 @@ AegiVideoFrame::AegiVideoFrame() {
//////////////////
// Create default
AegiVideoFrame::AegiVideoFrame(int width,int height,VideoFrameFormat fmt) {
// Clear
Reset();
// Set format
format = fmt;
w = width;
h = height;
pitch[0] = w * GetBpp();
Allocate();
for (int i=0;i<4;i++) {
int height = h;
if (format == FORMAT_YV12 && i > 0) height/=2;
int size = pitch[i]*height;
memset(data[0],0,size);
if (fmt == FORMAT_YV12) {
pitch[1] = w/2;
pitch[2] = w/2;
}
// Allocate
Allocate();
// Clear data
int size = pitch[0]*height + (pitch[1]+pitch[2])*height/2;
memset(data[0],0,size);
}
@ -126,8 +138,11 @@ void AegiVideoFrame::Allocate() {
/////////
// Clear
void AegiVideoFrame::Clear() {
// Free memory
if (cppAlloc) delete[] data[0];
else free(data[0]);
// Zero variables
for (int i=0;i<4;i++) {
data[i] = NULL;
pitch[i] = 0;
@ -135,7 +150,9 @@ void AegiVideoFrame::Clear() {
memSize = 0;
w = 0;
h = 0;
format = FORMAT_RGB24;
// Reset properties
format = FORMAT_NONE;
flipped = false;
cppAlloc = true;
invertChannels = true;
@ -161,6 +178,7 @@ void AegiVideoFrame::CopyFrom(const AegiVideoFrame &source) {
// ------
// This function is only used on screenshots, so it doesn't have to be fast
wxImage AegiVideoFrame::GetImage() const {
// RGB
if (format == FORMAT_RGB32 || format == FORMAT_RGB24) {
// Create
unsigned char *buf = (unsigned char*)malloc(w*h*3);
@ -189,6 +207,11 @@ wxImage AegiVideoFrame::GetImage() const {
return img;
}
// YV12
//else if (format == FORMAT_YV12) {
// TODO
//}
else {
return wxImage(w,h);
}