Move the SearchReplaceEngine instance to the context

This commit is contained in:
Thomas Goyne 2013-01-11 08:53:36 -08:00
parent bc2ddfbaee
commit 2f4cae46b4
6 changed files with 30 additions and 29 deletions

View File

@ -462,7 +462,7 @@ struct edit_find_replace : public Command {
void operator()(agi::Context *c) {
c->videoController->Stop();
Search.OpenDialog(true);
c->search->OpenDialog(true);
}
};

View File

@ -105,7 +105,7 @@ struct subtitle_find : public Command {
void operator()(agi::Context *c) {
c->videoController->Stop();
Search.OpenDialog(false);
c->search->OpenDialog(false);
}
};
@ -119,7 +119,7 @@ struct subtitle_find_next : public Command {
void operator()(agi::Context *c) {
c->videoController->Stop();
Search.FindNext();
c->search->FindNext();
}
};

View File

@ -80,6 +80,7 @@ enum {
DialogSearchReplace::DialogSearchReplace(agi::Context* c, bool withReplace)
: wxDialog(c->parent, -1, withReplace ? _("Replace") : _("Find"))
, c(c)
, hasReplace(withReplace)
{
wxSizer *FindSizer = new wxFlexGridSizer(2, 2, 5, 15);
@ -142,7 +143,7 @@ DialogSearchReplace::DialogSearchReplace(agi::Context* c, bool withReplace)
SetSizerAndFit(MainSizer);
CenterOnParent();
Search.OnDialogOpen();
c->search->OnDialogOpen();
Bind(wxEVT_COMMAND_BUTTON_CLICKED, std::bind(&DialogSearchReplace::FindReplace, this, 0), BUTTON_FIND_NEXT);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, std::bind(&DialogSearchReplace::FindReplace, this, 1), BUTTON_REPLACE_NEXT);
@ -150,8 +151,8 @@ DialogSearchReplace::DialogSearchReplace(agi::Context* c, bool withReplace)
}
DialogSearchReplace::~DialogSearchReplace() {
Search.isReg = CheckRegExp->IsChecked() && CheckRegExp->IsEnabled();
Search.matchCase = CheckMatchCase->IsChecked();
c->search->isReg = CheckRegExp->IsChecked() && CheckRegExp->IsEnabled();
c->search->matchCase = CheckMatchCase->IsChecked();
OPT_SET("Tool/Search Replace/Match Case")->SetBool(CheckMatchCase->IsChecked());
OPT_SET("Tool/Search Replace/RegExp")->SetBool(CheckRegExp->IsChecked());
OPT_SET("Tool/Search Replace/Field")->SetInt(Field->GetSelection());
@ -164,25 +165,25 @@ void DialogSearchReplace::FindReplace(int mode) {
wxString LookFor = FindEdit->GetValue();
if (!LookFor) return;
Search.isReg = CheckRegExp->IsChecked() && CheckRegExp->IsEnabled();
Search.matchCase = CheckMatchCase->IsChecked();
Search.LookFor = LookFor;
Search.initialized = true;
Search.affect = Affect->GetSelection();
Search.field = Field->GetSelection();
c->search->isReg = CheckRegExp->IsChecked() && CheckRegExp->IsEnabled();
c->search->matchCase = CheckMatchCase->IsChecked();
c->search->LookFor = LookFor;
c->search->initialized = true;
c->search->affect = Affect->GetSelection();
c->search->field = Field->GetSelection();
if (hasReplace) {
wxString ReplaceWith = ReplaceEdit->GetValue();
Search.ReplaceWith = ReplaceWith;
c->search->ReplaceWith = ReplaceWith;
config::mru->Add("Replace", from_wx(ReplaceWith));
}
if (mode == 0)
Search.FindNext();
c->search->FindNext();
else if (mode == 1)
Search.ReplaceNext();
c->search->ReplaceNext();
else
Search.ReplaceAll();
c->search->ReplaceAll();
config::mru->Add("Find", from_wx(LookFor));
UpdateDropDowns();
@ -204,8 +205,9 @@ void DialogSearchReplace::UpdateDropDowns() {
update_mru(ReplaceEdit, "Replace");
}
SearchReplaceEngine::SearchReplaceEngine()
: curLine(0)
SearchReplaceEngine::SearchReplaceEngine(agi::Context *c)
: context(c)
, curLine(0)
, pos(0)
, matchLen(0)
, replaceLen(0)
@ -216,7 +218,6 @@ SearchReplaceEngine::SearchReplaceEngine()
, initialized(false)
, field(FIELD_TEXT)
, affect(LIMIT_ALL)
, context(nullptr)
{
}
@ -373,7 +374,7 @@ void SearchReplaceEngine::ReplaceAll() {
}
}
else {
if (!Search.matchCase) {
if (!matchCase) {
bool replaced = false;
wxString Left, Right = *Text;
size_t pos = 0;
@ -439,5 +440,3 @@ void SearchReplaceEngine::OpenDialog(bool replace) {
diag->Show();
hasReplace = replace;
}
SearchReplaceEngine Search;

View File

@ -41,6 +41,8 @@ class wxComboBox;
class wxRadioBox;
class SearchReplaceEngine {
agi::Context *context;
int curLine;
size_t pos;
size_t matchLen;
@ -56,24 +58,21 @@ class SearchReplaceEngine {
wxString ReplaceWith;
public:
agi::Context *context;
void FindNext() { ReplaceNext(false); }
void ReplaceNext(bool DoReplace=true);
void ReplaceAll();
void OpenDialog(bool HasReplace);
void OnDialogOpen();
SearchReplaceEngine();
SearchReplaceEngine(agi::Context *c);
friend class DialogSearchReplace;
};
// Instance
extern SearchReplaceEngine Search;
class DialogSearchReplace : public wxDialog {
friend class SearchReplaceEngine;
agi::Context *c;
bool hasReplace;
wxComboBox *FindEdit;

View File

@ -376,7 +376,7 @@ void FrameMain::InitContents() {
StartupLog("Create subtitles grid");
context->subsGrid = SubsGrid = new SubtitlesGrid(Panel, context.get());
context->selectionController = context->subsGrid;
Search.context = context.get();
context->search = new SearchReplaceEngine(context.get());
StartupLog("Create video box");
videoBox = new VideoBox(Panel, false, context.get());

View File

@ -4,6 +4,7 @@ class AudioController;
class AssDialogue;
class AudioKaraoke;
class DialogManager;
class SearchReplaceEngine;
template<class T> class SelectionController;
class SubsTextEditCtrl;
class SubtitlesGrid;
@ -26,6 +27,8 @@ struct Context {
TextSelectionController *textSelectionController;
VideoContext *videoController;
SearchReplaceEngine *search;
// Things that should probably be in some sort of UI-context-model
wxWindow *parent;
wxWindow *previousFocus;