From 5fff88473f629803d7272418329a345ce853622e Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Fri, 11 Jan 2013 19:35:28 -0800 Subject: [PATCH] Add option to skip comments in the find/replace dialog. Updates #683. --- aegisub/src/dialog_search_replace.cpp | 5 ++++- aegisub/src/libresrc/default_config.json | 1 + aegisub/src/libresrc/osx/default_config.json | 1 + aegisub/src/search_replace_engine.cpp | 2 ++ aegisub/src/search_replace_engine.h | 1 + 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/aegisub/src/dialog_search_replace.cpp b/aegisub/src/dialog_search_replace.cpp index d427fdc0f..3ae685bda 100644 --- a/aegisub/src/dialog_search_replace.cpp +++ b/aegisub/src/dialog_search_replace.cpp @@ -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(settings->field)); OPT_SET("Tool/Search Replace/Affect")->SetInt(static_cast(settings->limit_to)); diff --git a/aegisub/src/libresrc/default_config.json b/aegisub/src/libresrc/default_config.json index 9080f0467..edd950792 100644 --- a/aegisub/src/libresrc/default_config.json +++ b/aegisub/src/libresrc/default_config.json @@ -463,6 +463,7 @@ "Field" : 0, "Match Case" : false, "RegExp" : false, + "Skip Comments" : false }, "Select Lines" : { "Action" : 0, diff --git a/aegisub/src/libresrc/osx/default_config.json b/aegisub/src/libresrc/osx/default_config.json index e18f3c360..f9bb55843 100644 --- a/aegisub/src/libresrc/osx/default_config.json +++ b/aegisub/src/libresrc/osx/default_config.json @@ -463,6 +463,7 @@ "Field" : 0, "Match Case" : false, "RegExp" : false, + "Skip Comments" : false }, "Select Lines" : { "Action" : 0, diff --git a/aegisub/src/search_replace_engine.cpp b/aegisub/src/search_replace_engine.cpp index 274f9d971..3ec243688 100644 --- a/aegisub/src/search_replace_engine.cpp +++ b/aegisub/src/search_replace_engine.cpp @@ -168,6 +168,7 @@ bool SearchReplaceEngine::FindReplace(bool replace) { AssDialogue *diag = dynamic_cast(&*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()) { if (selection_only && !sel.count(diag)) continue; + if (settings.ignore_comments && diag->Comment) continue; if (settings.use_regex) { if (MatchState ms = matches(diag, 0)) { diff --git a/aegisub/src/search_replace_engine.h b/aegisub/src/search_replace_engine.h index af023f842..aea271ff7 100644 --- a/aegisub/src/search_replace_engine.h +++ b/aegisub/src/search_replace_engine.h @@ -41,6 +41,7 @@ struct SearchReplaceSettings { bool match_case; bool use_regex; + bool ignore_comments; }; class SearchReplaceEngine {