Add option to skip comments in the find/replace dialog. Updates #683.

This commit is contained in:
Thomas Goyne 2013-01-11 19:35:28 -08:00
parent ab3ef175cd
commit 5fff88473f
5 changed files with 9 additions and 1 deletions

View file

@ -56,6 +56,7 @@ DialogSearchReplace::DialogSearchReplace(agi::Context* c, bool replace)
settings->replace_with = recent_replace.empty() ? wxString() : recent_replace.front();
settings->match_case = OPT_GET("Tool/Search Replace/Match Case")->GetBool();
settings->use_regex = OPT_GET("Tool/Search Replace/RegExp")->GetBool();
settings->ignore_comments = OPT_GET("Tool/Search Replace/Skip Comments")->GetBool();
auto find_sizer = new wxFlexGridSizer(2, 2, 5, 15);
find_edit = new wxComboBox(this, -1, "", wxDefaultPosition, wxSize(300, -1), recent_find, wxCB_DROPDOWN, wxGenericValidator(&settings->find));
@ -70,7 +71,8 @@ DialogSearchReplace::DialogSearchReplace(agi::Context* c, bool replace)
auto options_sizer = new wxBoxSizer(wxVERTICAL);
options_sizer->Add(new wxCheckBox(this, -1, _("&Match case"), wxDefaultPosition, wxDefaultSize, 0, wxGenericValidator(&settings->match_case)), wxSizerFlags().Border(wxBOTTOM));
options_sizer->Add(new wxCheckBox(this, -1, _("&Use regular expressions"), wxDefaultPosition, wxDefaultSize, 0, wxGenericValidator(&settings->use_regex)));
options_sizer->Add(new wxCheckBox(this, -1, _("&Use regular expressions"), wxDefaultPosition, wxDefaultSize, 0, wxGenericValidator(&settings->use_regex)), wxSizerFlags().Border(wxBOTTOM));
options_sizer->Add(new wxCheckBox(this, -1, _("&Skip Comments"), wxDefaultPosition, wxDefaultSize, 0, wxGenericValidator(&settings->ignore_comments)));
auto left_sizer = new wxBoxSizer(wxVERTICAL);
left_sizer->Add(find_sizer, wxSizerFlags().DoubleBorder(wxBOTTOM));
@ -131,6 +133,7 @@ void DialogSearchReplace::FindReplace(bool (SearchReplaceEngine::*func)()) {
OPT_SET("Tool/Search Replace/Match Case")->SetBool(settings->match_case);
OPT_SET("Tool/Search Replace/RegExp")->SetBool(settings->use_regex);
OPT_SET("Tool/Search Replace/Skip Comments")->SetBool(settings->ignore_comments);
OPT_SET("Tool/Search Replace/Field")->SetInt(static_cast<int>(settings->field));
OPT_SET("Tool/Search Replace/Affect")->SetInt(static_cast<int>(settings->limit_to));

View file

@ -463,6 +463,7 @@
"Field" : 0,
"Match Case" : false,
"RegExp" : false,
"Skip Comments" : false
},
"Select Lines" : {
"Action" : 0,

View file

@ -463,6 +463,7 @@
"Field" : 0,
"Match Case" : false,
"RegExp" : false,
"Skip Comments" : false
},
"Select Lines" : {
"Action" : 0,

View file

@ -168,6 +168,7 @@ bool SearchReplaceEngine::FindReplace(bool replace) {
AssDialogue *diag = dynamic_cast<AssDialogue*>(&*it);
if (!diag) continue;
if (selection_only && !sel.count(diag)) continue;
if (settings.ignore_comments && diag->Comment) continue;
if (MatchState ms = matches(diag, pos)) {
if (selection_only)
@ -208,6 +209,7 @@ bool SearchReplaceEngine::ReplaceAll() {
for (auto diag : context->ass->Line | agi::of_type<AssDialogue>()) {
if (selection_only && !sel.count(diag)) continue;
if (settings.ignore_comments && diag->Comment) continue;
if (settings.use_regex) {
if (MatchState ms = matches(diag, 0)) {

View file

@ -41,6 +41,7 @@ struct SearchReplaceSettings {
bool match_case;
bool use_regex;
bool ignore_comments;
};
class SearchReplaceEngine {