Delete stuff in DialogSearchReplace

Originally committed to SVN as r6032.
This commit is contained in:
Thomas Goyne 2011-12-22 21:14:32 +00:00
parent ac9b09b847
commit 404e0fda4f
3 changed files with 27 additions and 168 deletions

View file

@ -37,6 +37,8 @@
#include "config.h" #include "config.h"
#ifndef AGI_PRE #ifndef AGI_PRE
#include <functional>
#include <wx/regex.h> #include <wx/regex.h>
#include <wx/string.h> #include <wx/string.h>
#endif #endif
@ -47,13 +49,11 @@
#include "compat.h" #include "compat.h"
#include "dialog_search_replace.h" #include "dialog_search_replace.h"
#include "include/aegisub/context.h" #include "include/aegisub/context.h"
#include "frame_main.h"
#include "main.h" #include "main.h"
#include "selection_controller.h" #include "selection_controller.h"
#include "subs_edit_ctrl.h" #include "subs_edit_ctrl.h"
#include "subs_grid.h" #include "subs_grid.h"
// IDs
enum { enum {
BUTTON_FIND_NEXT, BUTTON_FIND_NEXT,
BUTTON_REPLACE_NEXT, BUTTON_REPLACE_NEXT,
@ -63,22 +63,13 @@ enum {
CHECK_UPDATE_VIDEO CHECK_UPDATE_VIDEO
}; };
/// @brief Constructor DialogSearchReplace::DialogSearchReplace(wxWindow *parent, bool withReplace, wxString const& name)
/// @param parent : wxDialog(parent, -1, name)
/// @param _hasReplace , hasReplace(hasReplace)
/// @param name
///
DialogSearchReplace::DialogSearchReplace (wxWindow *parent,bool _hasReplace,wxString name)
: wxDialog(parent, -1, name, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, "SearchReplace")
{ {
// Setup
hasReplace = _hasReplace;
// Find sizer
wxSizer *FindSizer = new wxFlexGridSizer(2,2,5,15); wxSizer *FindSizer = new wxFlexGridSizer(2,2,5,15);
wxArrayString FindHistory = lagi_MRU_wxAS("Find"); wxArrayString FindHistory = lagi_MRU_wxAS("Find");
FindEdit = new wxComboBox(this,-1,"",wxDefaultPosition,wxSize(300,-1),FindHistory,wxCB_DROPDOWN); FindEdit = new wxComboBox(this,-1,"",wxDefaultPosition,wxSize(300,-1),FindHistory,wxCB_DROPDOWN);
//if (FindHistory.Count()) FindEdit->SetStringSelection(FindHistory[0]);
FindEdit->SetSelection(0); FindEdit->SetSelection(0);
FindSizer->Add(new wxStaticText(this,-1,_("Find what:")),0,wxRIGHT | wxALIGN_CENTER_VERTICAL,0); FindSizer->Add(new wxStaticText(this,-1,_("Find what:")),0,wxRIGHT | wxALIGN_CENTER_VERTICAL,0);
FindSizer->Add(FindEdit,0,wxRIGHT,0); FindSizer->Add(FindEdit,0,wxRIGHT,0);
@ -90,14 +81,12 @@ DialogSearchReplace::DialogSearchReplace (wxWindow *parent,bool _hasReplace,wxSt
ReplaceEdit->SetSelection(0); ReplaceEdit->SetSelection(0);
} }
// Options sizer
wxSizer *OptionsSizer = new wxBoxSizer(wxVERTICAL); wxSizer *OptionsSizer = new wxBoxSizer(wxVERTICAL);
CheckMatchCase = new wxCheckBox(this,CHECK_MATCH_CASE,_("&Match case")); CheckMatchCase = new wxCheckBox(this,CHECK_MATCH_CASE,_("&Match case"));
CheckRegExp = new wxCheckBox(this,CHECK_MATCH_CASE,_("&Use regular expressions")); CheckRegExp = new wxCheckBox(this,CHECK_MATCH_CASE,_("&Use regular expressions"));
CheckUpdateVideo = new wxCheckBox(this,CHECK_UPDATE_VIDEO,_("Update &Video")); CheckUpdateVideo = new wxCheckBox(this,CHECK_UPDATE_VIDEO,_("Update &Video"));
CheckMatchCase->SetValue(OPT_GET("Tool/Search Replace/Match Case")->GetBool()); CheckMatchCase->SetValue(OPT_GET("Tool/Search Replace/Match Case")->GetBool());
CheckRegExp->SetValue(OPT_GET("Tool/Search Replace/RegExp")->GetBool()); CheckRegExp->SetValue(OPT_GET("Tool/Search Replace/RegExp")->GetBool());
//CheckRegExp->Enable(false);
CheckUpdateVideo->SetValue(OPT_GET("Tool/Search Replace/Video Update")->GetBool()); CheckUpdateVideo->SetValue(OPT_GET("Tool/Search Replace/Video Update")->GetBool());
// CheckUpdateVideo->Enable(Search.grid->video->loaded); // CheckUpdateVideo->Enable(Search.grid->video->loaded);
OptionsSizer->Add(CheckMatchCase,0,wxBOTTOM,5); OptionsSizer->Add(CheckMatchCase,0,wxBOTTOM,5);
@ -143,27 +132,22 @@ DialogSearchReplace::DialogSearchReplace (wxWindow *parent,bool _hasReplace,wxSt
wxSizer *MainSizer = new wxBoxSizer(wxHORIZONTAL); wxSizer *MainSizer = new wxBoxSizer(wxHORIZONTAL);
MainSizer->Add(LeftSizer,0,wxEXPAND | wxALL,5); MainSizer->Add(LeftSizer,0,wxEXPAND | wxALL,5);
MainSizer->Add(ButtonSizer,0,wxEXPAND | wxALL,5); MainSizer->Add(ButtonSizer,0,wxEXPAND | wxALL,5);
MainSizer->SetSizeHints(this); SetSizerAndFit(MainSizer);
SetSizer(MainSizer);
CenterOnParent(); CenterOnParent();
// Open
Search.OnDialogOpen(); Search.OnDialogOpen();
Bind(wxEVT_COMMAND_BUTTON_CLICKED, std::tr1::bind(&DialogSearchReplace::FindReplace, this, 0), BUTTON_FIND_NEXT);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, std::tr1::bind(&DialogSearchReplace::FindReplace, this, 1), BUTTON_REPLACE_NEXT);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, std::tr1::bind(&DialogSearchReplace::FindReplace, this, 2), BUTTON_REPLACE_ALL);
Bind(wxEVT_SET_FOCUS, std::tr1::bind(&SearchReplaceEngine::SetFocus, &Search, true));
Bind(wxEVT_KILL_FOCUS, std::tr1::bind(&SearchReplaceEngine::SetFocus, &Search, false));
} }
/// @brief Destructor
///
DialogSearchReplace::~DialogSearchReplace() { DialogSearchReplace::~DialogSearchReplace() {
// Save options
UpdateSettings(); UpdateSettings();
} }
/// @brief Update search
///
void DialogSearchReplace::UpdateSettings() { void DialogSearchReplace::UpdateSettings() {
Search.isReg = CheckRegExp->IsChecked() && CheckRegExp->IsEnabled(); Search.isReg = CheckRegExp->IsChecked() && CheckRegExp->IsEnabled();
Search.matchCase = CheckMatchCase->IsChecked(); Search.matchCase = CheckMatchCase->IsChecked();
@ -173,40 +157,14 @@ void DialogSearchReplace::UpdateSettings() {
OPT_SET("Tool/Search Replace/Video Update")->SetBool(CheckUpdateVideo->IsChecked()); OPT_SET("Tool/Search Replace/Video Update")->SetBool(CheckUpdateVideo->IsChecked());
OPT_SET("Tool/Search Replace/Field")->SetInt(Field->GetSelection()); OPT_SET("Tool/Search Replace/Field")->SetInt(Field->GetSelection());
OPT_SET("Tool/Search Replace/Affect")->SetInt(Affect->GetSelection()); OPT_SET("Tool/Search Replace/Affect")->SetInt(Affect->GetSelection());
}
///////////////
// Event table
BEGIN_EVENT_TABLE(DialogSearchReplace,wxDialog)
EVT_BUTTON(wxID_CANCEL,DialogSearchReplace::OnClose)
EVT_BUTTON(BUTTON_FIND_NEXT,DialogSearchReplace::OnFindNext)
EVT_BUTTON(BUTTON_REPLACE_NEXT,DialogSearchReplace::OnReplaceNext)
EVT_BUTTON(BUTTON_REPLACE_ALL,DialogSearchReplace::OnReplaceAll)
EVT_SET_FOCUS(DialogSearchReplace::OnSetFocus)
EVT_KILL_FOCUS(DialogSearchReplace::OnKillFocus)
END_EVENT_TABLE()
/// @brief Close
/// @param event
///
void DialogSearchReplace::OnClose (wxCommandEvent &) {
Show(false);
} }
/// @brief Find or replace
/// @param mode
/// @return
///
void DialogSearchReplace::FindReplace(int mode) { void DialogSearchReplace::FindReplace(int mode) {
// Check mode
if (mode < 0 || mode > 2) return; if (mode < 0 || mode > 2) return;
// Variables // Variables
wxString LookFor = FindEdit->GetValue(); wxString LookFor = FindEdit->GetValue();
if (LookFor.IsEmpty()) return; if (!LookFor) return;
// Setup // Setup
Search.isReg = CheckRegExp->IsChecked() && CheckRegExp->IsEnabled(); Search.isReg = CheckRegExp->IsChecked() && CheckRegExp->IsEnabled();
@ -241,46 +199,13 @@ void DialogSearchReplace::FindReplace(int mode) {
UpdateDropDowns(); UpdateDropDowns();
} }
/// @brief Find next
/// @param event
///
void DialogSearchReplace::OnFindNext (wxCommandEvent &) {
FindReplace(0);
}
/// @brief Replace next
/// @param event
///
void DialogSearchReplace::OnReplaceNext (wxCommandEvent &) {
FindReplace(1);
}
/// @brief Replace all
/// @param event
///
void DialogSearchReplace::OnReplaceAll (wxCommandEvent &) {
FindReplace(2);
}
/// @brief Update drop down boxes
///
void DialogSearchReplace::UpdateDropDowns() { void DialogSearchReplace::UpdateDropDowns() {
// Find
FindEdit->Freeze(); FindEdit->Freeze();
FindEdit->Clear(); FindEdit->Clear();
FindEdit->Append(lagi_MRU_wxAS("Find")); FindEdit->Append(lagi_MRU_wxAS("Find"));
FindEdit->SetSelection(0); FindEdit->SetSelection(0);
FindEdit->Thaw(); FindEdit->Thaw();
// Replace
if (hasReplace) { if (hasReplace) {
ReplaceEdit->Freeze(); ReplaceEdit->Freeze();
ReplaceEdit->Clear(); ReplaceEdit->Clear();
@ -290,47 +215,18 @@ void DialogSearchReplace::UpdateDropDowns() {
} }
} }
/// @brief DOCME
/// @param event
///
void DialogSearchReplace::OnSetFocus (wxFocusEvent &) {
Search.hasFocus = true;
}
/// @brief DOCME
/// @param event
///
void DialogSearchReplace::OnKillFocus (wxFocusEvent &) {
Search.hasFocus = false;
}
/// @brief Constructor SearchReplaceEngine /////////////////////// /// @brief Constructor SearchReplaceEngine ///////////////////////
///
SearchReplaceEngine::SearchReplaceEngine () { SearchReplaceEngine::SearchReplaceEngine () {
CanContinue = false; CanContinue = false;
} }
/// @brief Find next instance
///
void SearchReplaceEngine::FindNext() { void SearchReplaceEngine::FindNext() {
ReplaceNext(false); ReplaceNext(false);
} }
/// @brief Find & Replace next instance /// @brief Find & Replace next instance
/// @param DoReplace
/// @return
///
void SearchReplaceEngine::ReplaceNext(bool DoReplace) { void SearchReplaceEngine::ReplaceNext(bool DoReplace) {
// Check if it's OK to go on
if (!CanContinue) { if (!CanContinue) {
OpenDialog(DoReplace); OpenDialog(DoReplace);
return; return;
@ -451,12 +347,8 @@ void SearchReplaceEngine::ReplaceNext(bool DoReplace) {
LastWasFind = !DoReplace; LastWasFind = !DoReplace;
} }
/// @brief Replace all instances
/// @brief Replace all instances
///
void SearchReplaceEngine::ReplaceAll() { void SearchReplaceEngine::ReplaceAll() {
// Setup
wxString *Text; wxString *Text;
int nrows = context->subsGrid->GetRows(); int nrows = context->subsGrid->GetRows();
size_t count = 0; size_t count = 0;
@ -526,13 +418,10 @@ void SearchReplaceEngine::ReplaceAll() {
} }
} }
// Commit
if (count > 0) { if (count > 0) {
context->ass->Commit(_("replace"), AssFile::COMMIT_DIAG_TEXT); context->ass->Commit(_("replace"), AssFile::COMMIT_DIAG_TEXT);
wxMessageBox(wxString::Format(_("%i matches were replaced."),count)); wxMessageBox(wxString::Format(_("%i matches were replaced."),count));
} }
// None found
else { else {
wxMessageBox(_("No matches found.")); wxMessageBox(_("No matches found."));
} }
@ -540,12 +429,7 @@ void SearchReplaceEngine::ReplaceAll() {
LastWasFind = false; LastWasFind = false;
} }
/// @brief Search dialog opened
///
void SearchReplaceEngine::OnDialogOpen() { void SearchReplaceEngine::OnDialogOpen() {
// Set curline
wxArrayInt sels = context->subsGrid->GetSelection(); wxArrayInt sels = context->subsGrid->GetSelection();
curLine = 0; curLine = 0;
if (sels.Count() > 0) curLine = sels[0]; if (sels.Count() > 0) curLine = sels[0];
@ -558,10 +442,6 @@ void SearchReplaceEngine::OnDialogOpen() {
replaceLen = 0; replaceLen = 0;
} }
/// @brief Open dialog
/// @param replace
/// @return
///
void SearchReplaceEngine::OpenDialog (bool replace) { void SearchReplaceEngine::OpenDialog (bool replace) {
static DialogSearchReplace *diag = NULL; static DialogSearchReplace *diag = NULL;
wxString title = replace? _("Replace") : _("Find"); wxString title = replace? _("Replace") : _("Find");
@ -579,19 +459,12 @@ void SearchReplaceEngine::OpenDialog (bool replace) {
diag->Destroy(); diag->Destroy();
} }
// create new one // create new one
diag = new DialogSearchReplace(((AegisubApp*)wxTheApp)->frame,replace,title); diag = new DialogSearchReplace(context->parent,replace,title);
diag->FindEdit->SetFocus(); diag->FindEdit->SetFocus();
diag->Show(); diag->Show();
hasReplace = replace; hasReplace = replace;
} }
/// @brief Get text pointer
/// @param n
/// @param field
/// @return
///
wxString *SearchReplaceEngine::GetText(int n,int field) { wxString *SearchReplaceEngine::GetText(int n,int field) {
AssDialogue *cur = context->subsGrid->GetDialogue(n); AssDialogue *cur = context->subsGrid->GetDialogue(n);
if (field == 0) return &cur->Text; if (field == 0) return &cur->Text;
@ -601,9 +474,4 @@ wxString *SearchReplaceEngine::GetText(int n,int field) {
else throw wxString("Invalid field"); else throw wxString("Invalid field");
} }
/// DOCME
SearchReplaceEngine Search; SearchReplaceEngine Search;

View file

@ -73,12 +73,6 @@ class SearchReplaceEngine {
/// DOCME /// DOCME
bool hasReplace; bool hasReplace;
wxString *GetText(int n,int field);
public:
/// DOCME
agi::Context *context;
/// DOCME /// DOCME
bool isReg; bool isReg;
@ -106,12 +100,22 @@ public:
/// DOCME /// DOCME
wxString ReplaceWith; wxString ReplaceWith;
wxString *GetText(int n,int field);
public:
/// DOCME
agi::Context *context;
void FindNext(); void FindNext();
void ReplaceNext(bool DoReplace=true); void ReplaceNext(bool DoReplace=true);
void ReplaceAll(); void ReplaceAll();
void OpenDialog(bool HasReplace); void OpenDialog(bool HasReplace);
void OnDialogOpen(); void OnDialogOpen();
void SetFocus(bool focus) { hasFocus = focus; }
bool HasFocus() const { return hasFocus; }
SearchReplaceEngine(); SearchReplaceEngine();
friend class DialogSearchReplace; friend class DialogSearchReplace;
}; };
@ -119,8 +123,6 @@ public:
// Instance // Instance
extern SearchReplaceEngine Search; extern SearchReplaceEngine Search;
/// DOCME /// DOCME
/// @class DialogSearchReplace /// @class DialogSearchReplace
/// @brief DOCME /// @brief DOCME
@ -129,8 +131,6 @@ extern SearchReplaceEngine Search;
class DialogSearchReplace : public wxDialog { class DialogSearchReplace : public wxDialog {
friend class SearchReplaceEngine; friend class SearchReplaceEngine;
private:
/// DOCME /// DOCME
bool hasReplace; bool hasReplace;
@ -159,17 +159,8 @@ private:
void UpdateDropDowns(); void UpdateDropDowns();
void FindReplace(int mode); // 0 = find, 1 = replace next, 2 = replace all void FindReplace(int mode); // 0 = find, 1 = replace next, 2 = replace all
void OnClose (wxCommandEvent &event);
void OnFindNext (wxCommandEvent &event);
void OnReplaceNext (wxCommandEvent &event);
void OnReplaceAll (wxCommandEvent &event);
void OnSetFocus (wxFocusEvent &event);
void OnKillFocus (wxFocusEvent &event);
public: public:
DialogSearchReplace(wxWindow *parent,bool hasReplace,wxString name); DialogSearchReplace(wxWindow *parent, bool withReplace, wxString const& name);
~DialogSearchReplace(); ~DialogSearchReplace();
void UpdateSettings(); void UpdateSettings();
DECLARE_EVENT_TABLE()
}; };

View file

@ -429,7 +429,7 @@ void SubsEditBox::OnActiveLineChanged(AssDialogue *new_line) {
/// @todo VideoContext should be doing this /// @todo VideoContext should be doing this
if (c->videoController->IsLoaded()) { if (c->videoController->IsLoaded()) {
bool sync; bool sync;
if (Search.hasFocus) sync = OPT_GET("Tool/Search Replace/Video Update")->GetBool(); if (Search.HasFocus()) sync = OPT_GET("Tool/Search Replace/Video Update")->GetBool();
else sync = OPT_GET("Video/Subtitle Sync")->GetBool(); else sync = OPT_GET("Video/Subtitle Sync")->GetBool();
if (sync) { if (sync) {