mirror of https://github.com/odrling/Aegisub
Fixed replace bug (#338) and cleaned search and replace code up a bit.
Originally committed to SVN as r957.
This commit is contained in:
parent
27b08cc8aa
commit
ee3178a8e1
|
@ -190,9 +190,12 @@ void DialogSearchReplace::OnKeyDown (wxKeyEvent &event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////
|
///////////////////
|
||||||
// Find next
|
// Find or replace
|
||||||
void DialogSearchReplace::OnFindNext (wxCommandEvent &event) {
|
void DialogSearchReplace::FindReplace(int mode) {
|
||||||
|
// Check mode
|
||||||
|
if (mode < 0 || mode > 2) return;
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
wxString LookFor = FindEdit->GetValue();
|
wxString LookFor = FindEdit->GetValue();
|
||||||
if (LookFor.IsEmpty()) return;
|
if (LookFor.IsEmpty()) return;
|
||||||
|
@ -205,67 +208,50 @@ void DialogSearchReplace::OnFindNext (wxCommandEvent &event) {
|
||||||
Search.CanContinue = true;
|
Search.CanContinue = true;
|
||||||
Search.affect = Affect->GetSelection();
|
Search.affect = Affect->GetSelection();
|
||||||
Search.field = Field->GetSelection();
|
Search.field = Field->GetSelection();
|
||||||
Search.FindNext();
|
|
||||||
|
// Find
|
||||||
if (hasReplace) {
|
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();
|
wxString ReplaceWith = ReplaceEdit->GetValue();
|
||||||
Search.ReplaceWith = ReplaceWith;
|
Search.ReplaceWith = ReplaceWith;
|
||||||
|
if (mode == 1) Search.ReplaceNext();
|
||||||
|
else Search.ReplaceAll();
|
||||||
Options.AddToRecentList(ReplaceWith,_T("Recent replace"));
|
Options.AddToRecentList(ReplaceWith,_T("Recent replace"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to history
|
// Add to history
|
||||||
Options.AddToRecentList(LookFor,_T("Recent find"));
|
Options.AddToRecentList(LookFor,_T("Recent find"));
|
||||||
UpdateDropDowns();
|
UpdateDropDowns();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////
|
||||||
|
// Find next
|
||||||
|
void DialogSearchReplace::OnFindNext (wxCommandEvent &event) {
|
||||||
|
FindReplace(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
// Replace next
|
// Replace next
|
||||||
void DialogSearchReplace::OnReplaceNext (wxCommandEvent &event) {
|
void DialogSearchReplace::OnReplaceNext (wxCommandEvent &event) {
|
||||||
// Variables
|
FindReplace(1);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
// Replace all
|
// Replace all
|
||||||
void DialogSearchReplace::OnReplaceAll (wxCommandEvent &event) {
|
void DialogSearchReplace::OnReplaceAll (wxCommandEvent &event) {
|
||||||
// Setup
|
FindReplace(2);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -509,6 +495,7 @@ void SearchReplaceEngine::ReplaceAll() {
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
grid->ass->FlagAsModified(_("replace"));
|
grid->ass->FlagAsModified(_("replace"));
|
||||||
grid->CommitChanges();
|
grid->CommitChanges();
|
||||||
|
grid->editBox->Update();
|
||||||
wxMessageBox(wxString::Format(_("%i matches were replaced."),count));
|
wxMessageBox(wxString::Format(_("%i matches were replaced."),count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,7 @@ private:
|
||||||
wxRadioBox *Field;
|
wxRadioBox *Field;
|
||||||
|
|
||||||
void UpdateDropDowns();
|
void UpdateDropDowns();
|
||||||
|
void FindReplace(int mode); // 0 = find, 1 = replace next, 2 = replace all
|
||||||
|
|
||||||
void OnClose (wxCommandEvent &event);
|
void OnClose (wxCommandEvent &event);
|
||||||
void OnFindNext (wxCommandEvent &event);
|
void OnFindNext (wxCommandEvent &event);
|
||||||
|
|
|
@ -42,6 +42,10 @@
|
||||||
/////////
|
/////////
|
||||||
// Reset
|
// Reset
|
||||||
void AegiVideoFrame::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++) {
|
for (int i=0;i<4;i++) {
|
||||||
data[i] = NULL;
|
data[i] = NULL;
|
||||||
pitch[i] = 0;
|
pitch[i] = 0;
|
||||||
|
@ -49,6 +53,8 @@ void AegiVideoFrame::Reset() {
|
||||||
memSize = 0;
|
memSize = 0;
|
||||||
w = 0;
|
w = 0;
|
||||||
h = 0;
|
h = 0;
|
||||||
|
|
||||||
|
// Set properties
|
||||||
format = FORMAT_NONE;
|
format = FORMAT_NONE;
|
||||||
flipped = false;
|
flipped = false;
|
||||||
cppAlloc = true;
|
cppAlloc = true;
|
||||||
|
@ -66,19 +72,25 @@ AegiVideoFrame::AegiVideoFrame() {
|
||||||
//////////////////
|
//////////////////
|
||||||
// Create default
|
// Create default
|
||||||
AegiVideoFrame::AegiVideoFrame(int width,int height,VideoFrameFormat fmt) {
|
AegiVideoFrame::AegiVideoFrame(int width,int height,VideoFrameFormat fmt) {
|
||||||
|
// Clear
|
||||||
Reset();
|
Reset();
|
||||||
|
|
||||||
|
// Set format
|
||||||
format = fmt;
|
format = fmt;
|
||||||
w = width;
|
w = width;
|
||||||
h = height;
|
h = height;
|
||||||
pitch[0] = w * GetBpp();
|
pitch[0] = w * GetBpp();
|
||||||
|
if (fmt == FORMAT_YV12) {
|
||||||
Allocate();
|
pitch[1] = w/2;
|
||||||
for (int i=0;i<4;i++) {
|
pitch[2] = w/2;
|
||||||
int height = h;
|
|
||||||
if (format == FORMAT_YV12 && i > 0) height/=2;
|
|
||||||
int size = pitch[i]*height;
|
|
||||||
memset(data[0],0,size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// Clear
|
||||||
void AegiVideoFrame::Clear() {
|
void AegiVideoFrame::Clear() {
|
||||||
|
// Free memory
|
||||||
if (cppAlloc) delete[] data[0];
|
if (cppAlloc) delete[] data[0];
|
||||||
else free(data[0]);
|
else free(data[0]);
|
||||||
|
|
||||||
|
// Zero variables
|
||||||
for (int i=0;i<4;i++) {
|
for (int i=0;i<4;i++) {
|
||||||
data[i] = NULL;
|
data[i] = NULL;
|
||||||
pitch[i] = 0;
|
pitch[i] = 0;
|
||||||
|
@ -135,7 +150,9 @@ void AegiVideoFrame::Clear() {
|
||||||
memSize = 0;
|
memSize = 0;
|
||||||
w = 0;
|
w = 0;
|
||||||
h = 0;
|
h = 0;
|
||||||
format = FORMAT_RGB24;
|
|
||||||
|
// Reset properties
|
||||||
|
format = FORMAT_NONE;
|
||||||
flipped = false;
|
flipped = false;
|
||||||
cppAlloc = true;
|
cppAlloc = true;
|
||||||
invertChannels = 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
|
// This function is only used on screenshots, so it doesn't have to be fast
|
||||||
wxImage AegiVideoFrame::GetImage() const {
|
wxImage AegiVideoFrame::GetImage() const {
|
||||||
|
// RGB
|
||||||
if (format == FORMAT_RGB32 || format == FORMAT_RGB24) {
|
if (format == FORMAT_RGB32 || format == FORMAT_RGB24) {
|
||||||
// Create
|
// Create
|
||||||
unsigned char *buf = (unsigned char*)malloc(w*h*3);
|
unsigned char *buf = (unsigned char*)malloc(w*h*3);
|
||||||
|
@ -189,6 +207,11 @@ wxImage AegiVideoFrame::GetImage() const {
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// YV12
|
||||||
|
//else if (format == FORMAT_YV12) {
|
||||||
|
// TODO
|
||||||
|
//}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
return wxImage(w,h);
|
return wxImage(w,h);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue