Use enum classes for the selection dialog modes

This commit is contained in:
Thomas Goyne 2014-03-18 13:46:13 -07:00
parent 3ef8fa9ec0
commit e74f1dc80e

View file

@ -46,30 +46,32 @@
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/textctrl.h> #include <wx/textctrl.h>
enum { namespace {
ACTION_SET = 0,
ACTION_ADD, enum class Action {
ACTION_SUB, SET = 0,
ACTION_INTERSECT ADD,
SUB,
INTERSECT
}; };
enum { enum Mode {
MODE_EXACT = 0, EXACT = 0,
MODE_CONTAINS, CONTAINS,
MODE_REGEXP REGEXP
}; };
static std::set<AssDialogue*> process(std::string const& match_text, bool match_case, int mode, bool invert, bool comments, bool dialogue, int field_n, AssFile *ass) { std::set<AssDialogue*> process(std::string const& match_text, bool match_case, Mode mode, bool invert, bool comments, bool dialogue, int field_n, AssFile *ass) {
SearchReplaceSettings settings = { SearchReplaceSettings settings = {
match_text, match_text,
std::string(), std::string(),
static_cast<SearchReplaceSettings::Field>(field_n), static_cast<SearchReplaceSettings::Field>(field_n),
SearchReplaceSettings::Limit::ALL, SearchReplaceSettings::Limit::ALL,
match_case, match_case,
mode == MODE_REGEXP, mode == Mode::REGEXP,
false, false,
false, false,
mode == MODE_EXACT mode == Mode::EXACT
}; };
auto predicate = SearchReplaceEngine::GetMatcher(settings); auto predicate = SearchReplaceEngine::GetMatcher(settings);
@ -86,6 +88,8 @@ static std::set<AssDialogue*> process(std::string const& match_text, bool match_
return matches; return matches;
} }
}
DialogSelection::DialogSelection(agi::Context *c) : DialogSelection::DialogSelection(agi::Context *c) :
wxDialog (c->parent, -1, _("Select"), wxDefaultPosition, wxDefaultSize, wxCAPTION) wxDialog (c->parent, -1, _("Select"), wxDefaultPosition, wxDefaultSize, wxCAPTION)
, con(c) , con(c)
@ -171,7 +175,7 @@ void DialogSelection::Process(wxCommandEvent&) {
try { try {
matches = process( matches = process(
from_wx(match_text->GetValue()), case_sensitive->IsChecked(), from_wx(match_text->GetValue()), case_sensitive->IsChecked(),
match_mode->GetSelection(), select_unmatching_lines->GetValue(), static_cast<Mode>(match_mode->GetSelection()), select_unmatching_lines->GetValue(),
apply_to_comments->IsChecked(), apply_to_dialogue->IsChecked(), apply_to_comments->IsChecked(), apply_to_dialogue->IsChecked(),
dialogue_field->GetSelection(), con->ass); dialogue_field->GetSelection(), con->ass);
} }
@ -180,34 +184,34 @@ void DialogSelection::Process(wxCommandEvent&) {
return; return;
} }
int action = selection_change_type->GetSelection(); auto action = static_cast<Action>(selection_change_type->GetSelection());
SubtitleSelection old_sel, new_sel; SubtitleSelection old_sel, new_sel;
if (action != ACTION_SET) if (action != Action::SET)
con->selectionController->GetSelectedSet(old_sel); con->selectionController->GetSelectedSet(old_sel);
wxString message; wxString message;
size_t count; size_t count;
switch (action) { switch (action) {
case ACTION_SET: case Action::SET:
new_sel = std::move(matches); new_sel = std::move(matches);
message = (count = new_sel.size()) message = (count = new_sel.size())
? wxString::Format(wxPLURAL("Selection was set to one line", "Selection was set to %u lines", count), (unsigned)count) ? wxString::Format(wxPLURAL("Selection was set to one line", "Selection was set to %u lines", count), (unsigned)count)
: _("Selection was set to no lines"); : _("Selection was set to no lines");
break; break;
case ACTION_ADD: case Action::ADD:
boost::set_union(old_sel, matches, inserter(new_sel, new_sel.begin())); boost::set_union(old_sel, matches, inserter(new_sel, new_sel.begin()));
message = (count = new_sel.size() - old_sel.size()) message = (count = new_sel.size() - old_sel.size())
? wxString::Format(wxPLURAL("One line was added to selection", "%u lines were added to selection", count), (unsigned)count) ? wxString::Format(wxPLURAL("One line was added to selection", "%u lines were added to selection", count), (unsigned)count)
: _("No lines were added to selection"); : _("No lines were added to selection");
break; break;
case ACTION_SUB: case Action::SUB:
boost::set_difference(old_sel, matches, inserter(new_sel, new_sel.begin())); boost::set_difference(old_sel, matches, inserter(new_sel, new_sel.begin()));
goto sub_message; goto sub_message;
case ACTION_INTERSECT: case Action::INTERSECT:
boost::set_intersection(old_sel, matches, inserter(new_sel, new_sel.begin())); boost::set_intersection(old_sel, matches, inserter(new_sel, new_sel.begin()));
sub_message: sub_message:
message = (count = old_sel.size() - new_sel.size()) message = (count = old_sel.size() - new_sel.size())