2011-09-15 07:16:47 +02:00
|
|
|
// Copyright (c) 2011, Thomas Goyne <plorkyeran@aegisub.org>
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2011-09-15 07:16:47 +02:00
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2011-09-15 07:16:47 +02:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
#include "ass_dialogue.h"
|
2011-09-15 07:16:47 +02:00
|
|
|
#include "ass_file.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "compat.h"
|
2014-05-22 21:07:15 +02:00
|
|
|
#include "dialog_manager.h"
|
2014-05-29 17:28:37 +02:00
|
|
|
#include "format.h"
|
2014-03-25 17:51:38 +01:00
|
|
|
#include "frame_main.h"
|
2008-01-14 00:34:38 +01:00
|
|
|
#include "help_button.h"
|
2011-09-15 07:16:47 +02:00
|
|
|
#include "include/aegisub/context.h"
|
2012-04-03 22:40:33 +02:00
|
|
|
#include "libresrc/libresrc.h"
|
2013-01-07 02:50:09 +01:00
|
|
|
#include "options.h"
|
2013-01-13 17:23:50 +01:00
|
|
|
#include "search_replace_engine.h"
|
2010-12-08 04:36:10 +01:00
|
|
|
#include "selection_controller.h"
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2014-05-23 00:40:16 +02:00
|
|
|
#include <boost/range/algorithm/set_algorithm.hpp>
|
2013-01-07 02:50:09 +01:00
|
|
|
|
|
|
|
#include <wx/checkbox.h>
|
|
|
|
#include <wx/combobox.h>
|
2014-05-22 21:07:15 +02:00
|
|
|
#include <wx/dialog.h>
|
2013-01-07 02:50:09 +01:00
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
#include <wx/radiobox.h>
|
|
|
|
#include <wx/radiobut.h>
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <wx/sizer.h>
|
2013-01-07 02:50:09 +01:00
|
|
|
#include <wx/textctrl.h>
|
|
|
|
|
2014-03-18 21:46:13 +01:00
|
|
|
namespace {
|
2014-05-22 21:07:15 +02:00
|
|
|
class DialogSelection final : public wxDialog {
|
|
|
|
agi::Context *con; ///< Project context
|
|
|
|
|
|
|
|
wxTextCtrl *match_text; ///< Text to search for
|
|
|
|
wxCheckBox *case_sensitive; ///< Should the search be case-sensitive
|
|
|
|
wxCheckBox *apply_to_dialogue; ///< Select/deselect uncommented lines
|
|
|
|
wxCheckBox *apply_to_comments; ///< Select/deselect commented lines
|
|
|
|
wxRadioButton *select_unmatching_lines; ///< Select lines which don't match instead
|
|
|
|
wxRadioBox *selection_change_type; ///< What sort of action to take on the selection
|
|
|
|
wxRadioBox *dialogue_field; ///< Which dialogue field to look at
|
|
|
|
wxRadioBox *match_mode;
|
|
|
|
|
|
|
|
void Process(wxCommandEvent&);
|
|
|
|
|
|
|
|
/// Dialogue/Comment check handler to ensure at least one is always checked
|
|
|
|
/// @param chk The checkbox to check if both are clear
|
|
|
|
void OnDialogueCheckbox(wxCheckBox *chk);
|
|
|
|
|
|
|
|
public:
|
|
|
|
DialogSelection(agi::Context *c);
|
|
|
|
~DialogSelection();
|
|
|
|
};
|
2014-03-18 21:46:13 +01:00
|
|
|
|
|
|
|
enum class Action {
|
|
|
|
SET = 0,
|
|
|
|
ADD,
|
|
|
|
SUB,
|
|
|
|
INTERSECT
|
2011-09-15 07:16:47 +02:00
|
|
|
};
|
|
|
|
|
2014-03-18 21:46:13 +01:00
|
|
|
enum Mode {
|
|
|
|
EXACT = 0,
|
|
|
|
CONTAINS,
|
|
|
|
REGEXP
|
2011-09-15 07:16:47 +02:00
|
|
|
};
|
|
|
|
|
2014-03-18 21:46:13 +01:00
|
|
|
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) {
|
2013-01-13 17:23:50 +01:00
|
|
|
SearchReplaceSettings settings = {
|
|
|
|
match_text,
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string(),
|
2013-01-13 17:23:50 +01:00
|
|
|
static_cast<SearchReplaceSettings::Field>(field_n),
|
|
|
|
SearchReplaceSettings::Limit::ALL,
|
|
|
|
match_case,
|
2014-03-18 21:46:13 +01:00
|
|
|
mode == Mode::REGEXP,
|
2013-01-13 17:23:50 +01:00
|
|
|
false,
|
|
|
|
false,
|
2014-03-18 21:46:13 +01:00
|
|
|
mode == Mode::EXACT
|
2013-01-13 17:23:50 +01:00
|
|
|
};
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
auto predicate = SearchReplaceEngine::GetMatcher(settings);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:16:47 +02:00
|
|
|
std::set<AssDialogue*> matches;
|
2014-03-07 19:58:51 +01:00
|
|
|
for (auto& diag : ass->Events) {
|
|
|
|
if (diag.Comment && !comments) continue;
|
|
|
|
if (!diag.Comment && !dialogue) continue;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2014-03-07 19:58:51 +01:00
|
|
|
if (invert != predicate(&diag, 0))
|
|
|
|
matches.insert(&diag);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:47 +02:00
|
|
|
return matches;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:47 +02:00
|
|
|
DialogSelection::DialogSelection(agi::Context *c) :
|
|
|
|
wxDialog (c->parent, -1, _("Select"), wxDefaultPosition, wxDefaultSize, wxCAPTION)
|
|
|
|
, con(c)
|
|
|
|
{
|
2012-04-03 22:40:33 +02:00
|
|
|
SetIcon(GETICON(select_lines_button_16));
|
|
|
|
|
2011-09-15 07:16:47 +02:00
|
|
|
wxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
|
|
|
|
wxSizerFlags main_flags = wxSizerFlags().Expand().Border();
|
|
|
|
|
2013-11-21 18:13:36 +01:00
|
|
|
wxRadioButton *select_matching_lines = nullptr;
|
2011-09-15 07:16:47 +02:00
|
|
|
{
|
|
|
|
wxSizer *match_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Match"));
|
|
|
|
{
|
|
|
|
wxSizerFlags radio_flags = wxSizerFlags().Border(wxLEFT | wxRIGHT);
|
|
|
|
wxSizer *match_radio_line = new wxBoxSizer(wxHORIZONTAL);
|
2012-05-18 07:03:11 +02:00
|
|
|
match_radio_line->Add(select_matching_lines = new wxRadioButton(this, -1, _("&Matches"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP), radio_flags);
|
2011-11-18 19:49:09 +01:00
|
|
|
match_radio_line->Add(select_unmatching_lines = new wxRadioButton(this, -1, _("&Doesn't Match")), radio_flags);
|
|
|
|
match_radio_line->Add(case_sensitive = new wxCheckBox(this, -1, _("Match c&ase")), radio_flags);
|
2011-09-15 07:16:47 +02:00
|
|
|
match_sizer->Add(match_radio_line);
|
|
|
|
}
|
2012-12-23 00:18:38 +01:00
|
|
|
match_sizer->Add(match_text = new wxTextCtrl(this, -1, to_wx(OPT_GET("Tool/Select Lines/Text")->GetString())), main_flags);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:16:47 +02:00
|
|
|
main_sizer->Add(match_sizer, main_flags);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:47 +02:00
|
|
|
{
|
2011-11-18 19:49:09 +01:00
|
|
|
wxString modes[] = { _("&Exact match"), _("&Contains"), _("&Regular Expression match") };
|
2011-09-15 07:16:47 +02:00
|
|
|
main_sizer->Add(match_mode = new wxRadioBox(this, -1, _("Mode"), wxDefaultPosition, wxDefaultSize, 3, modes, 1), main_flags);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:47 +02:00
|
|
|
{
|
2011-11-18 19:49:09 +01:00
|
|
|
wxString fields[] = { _("&Text"), _("&Style"), _("Act&or"), _("E&ffect") };
|
2011-09-15 07:16:47 +02:00
|
|
|
main_sizer->Add(dialogue_field = new wxRadioBox(this, -1, _("In Field"), wxDefaultPosition, wxDefaultSize, 4, fields), main_flags);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2011-09-15 07:16:47 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
wxSizer *comment_sizer = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Match dialogues/comments"));
|
2011-11-18 19:49:09 +01:00
|
|
|
comment_sizer->Add(apply_to_dialogue = new wxCheckBox(this, -1, _("D&ialogues")), wxSizerFlags().Border());
|
|
|
|
comment_sizer->Add(apply_to_comments = new wxCheckBox(this, -1, _("Comme&nts")), wxSizerFlags().Border());
|
2011-09-15 07:16:47 +02:00
|
|
|
main_sizer->Add(comment_sizer, main_flags);
|
2010-04-30 22:42:01 +02:00
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:16:47 +02:00
|
|
|
{
|
2011-11-18 19:49:09 +01:00
|
|
|
wxString actions[] = { _("Set se&lection"), _("&Add to selection"), _("S&ubtract from selection"), _("Intersect &with selection") };
|
2011-09-15 07:16:47 +02:00
|
|
|
main_sizer->Add(selection_change_type = new wxRadioBox(this, -1, _("Action"), wxDefaultPosition, wxDefaultSize, 4, actions, 1), main_flags);
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:16:47 +02:00
|
|
|
main_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL | wxHELP), main_flags);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:16:47 +02:00
|
|
|
SetSizerAndFit(main_sizer);
|
|
|
|
CenterOnParent();
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-09-15 07:16:47 +02:00
|
|
|
dialogue_field->SetSelection(OPT_GET("Tool/Select Lines/Field")->GetInt());
|
|
|
|
selection_change_type->SetSelection(OPT_GET("Tool/Select Lines/Action")->GetInt());
|
|
|
|
case_sensitive->SetValue(OPT_GET("Tool/Select Lines/Match/Case")->GetBool());
|
|
|
|
apply_to_dialogue->SetValue(OPT_GET("Tool/Select Lines/Match/Dialogue")->GetBool());
|
|
|
|
apply_to_comments->SetValue(OPT_GET("Tool/Select Lines/Match/Comment")->GetBool());
|
|
|
|
select_unmatching_lines->SetValue(!!OPT_GET("Tool/Select Lines/Condition")->GetInt());
|
2012-05-18 07:03:11 +02:00
|
|
|
select_matching_lines->SetValue(!select_unmatching_lines->GetValue());
|
2011-09-15 07:16:47 +02:00
|
|
|
match_mode->SetSelection(OPT_GET("Tool/Select Lines/Mode")->GetInt());
|
|
|
|
|
2013-12-12 03:25:13 +01:00
|
|
|
Bind(wxEVT_BUTTON, &DialogSelection::Process, this, wxID_OK);
|
|
|
|
Bind(wxEVT_BUTTON, std::bind(&HelpButton::OpenPage, "Select Lines"), wxID_HELP);
|
|
|
|
apply_to_comments->Bind(wxEVT_CHECKBOX, std::bind(&DialogSelection::OnDialogueCheckbox, this, apply_to_dialogue));
|
|
|
|
apply_to_dialogue->Bind(wxEVT_CHECKBOX, std::bind(&DialogSelection::OnDialogueCheckbox, this, apply_to_comments));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 22:40:39 +02:00
|
|
|
DialogSelection::~DialogSelection() {
|
2012-12-23 00:18:38 +01:00
|
|
|
OPT_SET("Tool/Select Lines/Text")->SetString(from_wx(match_text->GetValue()));
|
2012-04-03 22:40:39 +02:00
|
|
|
OPT_SET("Tool/Select Lines/Condition")->SetInt(select_unmatching_lines->GetValue());
|
|
|
|
OPT_SET("Tool/Select Lines/Field")->SetInt(dialogue_field->GetSelection());
|
|
|
|
OPT_SET("Tool/Select Lines/Action")->SetInt(selection_change_type->GetSelection());
|
|
|
|
OPT_SET("Tool/Select Lines/Mode")->SetInt(match_mode->GetSelection());
|
|
|
|
OPT_SET("Tool/Select Lines/Match/Case")->SetBool(case_sensitive->IsChecked());
|
|
|
|
OPT_SET("Tool/Select Lines/Match/Dialogue")->SetBool(apply_to_dialogue->IsChecked());
|
|
|
|
OPT_SET("Tool/Select Lines/Match/Comment")->SetBool(apply_to_comments->IsChecked());
|
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:47 +02:00
|
|
|
void DialogSelection::Process(wxCommandEvent&) {
|
|
|
|
std::set<AssDialogue*> matches;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:16:47 +02:00
|
|
|
try {
|
|
|
|
matches = process(
|
2013-01-04 16:01:50 +01:00
|
|
|
from_wx(match_text->GetValue()), case_sensitive->IsChecked(),
|
2014-03-18 21:46:13 +01:00
|
|
|
static_cast<Mode>(match_mode->GetSelection()), select_unmatching_lines->GetValue(),
|
2011-09-15 07:16:47 +02:00
|
|
|
apply_to_comments->IsChecked(), apply_to_dialogue->IsChecked(),
|
2014-03-25 22:49:26 +01:00
|
|
|
dialogue_field->GetSelection(), con->ass.get());
|
2011-09-15 07:16:47 +02:00
|
|
|
}
|
|
|
|
catch (agi::Exception const&) {
|
|
|
|
Close();
|
|
|
|
return;
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2014-03-18 21:46:13 +01:00
|
|
|
auto action = static_cast<Action>(selection_change_type->GetSelection());
|
2011-09-15 07:16:47 +02:00
|
|
|
|
2014-03-25 01:15:14 +01:00
|
|
|
Selection old_sel, new_sel;
|
2014-03-18 21:46:13 +01:00
|
|
|
if (action != Action::SET)
|
2014-04-17 23:24:26 +02:00
|
|
|
old_sel = con->selectionController->GetSelectedSet();
|
2011-09-15 07:16:47 +02:00
|
|
|
|
|
|
|
wxString message;
|
2014-05-06 02:53:14 +02:00
|
|
|
size_t count = 0;
|
2011-09-15 07:16:47 +02:00
|
|
|
switch (action) {
|
2014-03-18 21:46:13 +01:00
|
|
|
case Action::SET:
|
2014-03-12 17:13:46 +01:00
|
|
|
new_sel = std::move(matches);
|
|
|
|
message = (count = new_sel.size())
|
2014-05-29 17:28:37 +02:00
|
|
|
? fmt_plural(count, "Selection was set to one line", "Selection was set to %u lines", count)
|
2014-03-12 17:13:46 +01:00
|
|
|
: _("Selection was set to no lines");
|
2011-09-15 07:16:47 +02:00
|
|
|
break;
|
|
|
|
|
2014-03-18 21:46:13 +01:00
|
|
|
case Action::ADD:
|
2014-03-12 17:13:46 +01:00
|
|
|
boost::set_union(old_sel, matches, inserter(new_sel, new_sel.begin()));
|
|
|
|
message = (count = new_sel.size() - old_sel.size())
|
2014-05-29 17:28:37 +02:00
|
|
|
? fmt_plural(count, "One line was added to selection", "%u lines were added to selection", count)
|
2014-03-12 17:13:46 +01:00
|
|
|
: _("No lines were added to selection");
|
2011-09-15 07:16:47 +02:00
|
|
|
break;
|
|
|
|
|
2014-03-18 21:46:13 +01:00
|
|
|
case Action::SUB:
|
2014-03-12 17:13:46 +01:00
|
|
|
boost::set_difference(old_sel, matches, inserter(new_sel, new_sel.begin()));
|
|
|
|
goto sub_message;
|
2011-09-15 07:16:47 +02:00
|
|
|
|
2014-03-18 21:46:13 +01:00
|
|
|
case Action::INTERSECT:
|
2014-03-12 17:13:46 +01:00
|
|
|
boost::set_intersection(old_sel, matches, inserter(new_sel, new_sel.begin()));
|
|
|
|
sub_message:
|
|
|
|
message = (count = old_sel.size() - new_sel.size())
|
2014-05-29 17:28:37 +02:00
|
|
|
? fmt_plural(count, "One line was removed from selection", "%u lines were removed from selection", count)
|
2014-03-12 17:13:46 +01:00
|
|
|
: _("No lines were removed from selection");
|
2011-09-15 07:16:47 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:16:47 +02:00
|
|
|
if (count == 0)
|
2012-03-29 01:59:19 +02:00
|
|
|
wxMessageBox(message, _("Selection"), wxOK | wxCENTER, this);
|
2011-09-15 07:16:47 +02:00
|
|
|
else
|
2014-03-25 17:51:38 +01:00
|
|
|
con->frame->StatusTimeout(message);
|
2006-02-25 19:10:02 +01:00
|
|
|
|
2012-05-05 04:11:09 +02:00
|
|
|
AssDialogue *new_active = con->selectionController->GetActiveLine();
|
|
|
|
if (new_sel.size() && !new_sel.count(new_active))
|
|
|
|
new_active = *new_sel.begin();
|
2014-03-12 23:10:47 +01:00
|
|
|
con->selectionController->SetSelectionAndActive(std::move(new_sel), new_active);
|
2012-05-05 04:11:09 +02:00
|
|
|
|
2011-09-15 07:16:47 +02:00
|
|
|
Close();
|
2006-02-25 19:10:02 +01:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:47 +02:00
|
|
|
void DialogSelection::OnDialogueCheckbox(wxCheckBox *chk) {
|
|
|
|
if(!apply_to_dialogue->IsChecked() && !apply_to_comments->GetValue())
|
|
|
|
chk->SetValue(true);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2014-05-22 21:07:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShowSelectLinesDialog(agi::Context *c) {
|
|
|
|
c->dialog->Show<DialogSelection>(c);
|
2014-05-23 00:40:16 +02:00
|
|
|
}
|