Add option to sort subtitles by text

This commit is contained in:
arch1t3cht 2022-08-23 16:11:23 +02:00
parent 732c5c7654
commit c8d4df1355
5 changed files with 70 additions and 0 deletions

View file

@ -200,6 +200,12 @@ bool AssFile::CompEffect(AssDialogue const& lft, AssDialogue const& rgt) {
bool AssFile::CompLayer(AssDialogue const& lft, AssDialogue const& rgt) {
return lft.Layer < rgt.Layer;
}
bool AssFile::CompText(AssDialogue const& lft, AssDialogue const& rgt) {
return lft.Text < rgt.Text;
}
bool AssFile::CompTextStripped(AssDialogue const& lft, AssDialogue const& rgt) {
return lft.GetStrippedText() < rgt.GetStrippedText();
}
void AssFile::Sort(CompFunc comp, std::set<AssDialogue*> const& limit) {
Sort(Events, comp, limit);

View file

@ -194,6 +194,10 @@ public:
static bool CompEffect(AssDialogue const& lft, AssDialogue const& rgt);
/// Compare based on layer
static bool CompLayer(AssDialogue const& lft, AssDialogue const& rgt);
/// Compare based on text
static bool CompText(AssDialogue const& lft, AssDialogue const& rgt);
/// Compare based on stripped text
static bool CompTextStripped(AssDialogue const& lft, AssDialogue const& rgt);
/// @brief Sort the dialogue lines in this file
/// @param comp Comparison function to use. Defaults to sorting by start time.

View file

@ -248,6 +248,54 @@ struct grid_sort_style_selected final : public validate_sel_multiple {
}
};
struct grid_sort_text final : public Command {
CMD_NAME("grid/sort/text")
STR_MENU("Te&xt")
STR_DISP("Text")
STR_HELP("Sort all subtitles by their text, including styling tags")
void operator()(agi::Context *c) override {
c->ass->Sort(AssFile::CompText);
c->ass->Commit(_("sort"), AssFile::COMMIT_ORDER);
}
};
struct grid_sort_text_selected final : public validate_sel_multiple {
CMD_NAME("grid/sort/text/selected")
STR_MENU("Te&xt")
STR_DISP("Text")
STR_HELP("Sort selected subtitles by their text, including styling tags")
void operator()(agi::Context *c) override {
c->ass->Sort(AssFile::CompText, c->selectionController->GetSelectedSet());
c->ass->Commit(_("sort"), AssFile::COMMIT_ORDER);
}
};
struct grid_sort_text_stripped final : public Command {
CMD_NAME("grid/sort/text_stripped")
STR_MENU("Stri&pped Text")
STR_DISP("Stripped Text")
STR_HELP("Sort all subtitles by their stripped text")
void operator()(agi::Context *c) override {
c->ass->Sort(AssFile::CompTextStripped);
c->ass->Commit(_("sort"), AssFile::COMMIT_ORDER);
}
};
struct grid_sort_text_stripped_selected final : public validate_sel_multiple {
CMD_NAME("grid/sort/text_stripped/selected")
STR_MENU("Stri&pped Text")
STR_DISP("Stripped Text")
STR_HELP("Sort selected subtitles by their stripped text")
void operator()(agi::Context *c) override {
c->ass->Sort(AssFile::CompTextStripped, c->selectionController->GetSelectedSet());
c->ass->Commit(_("sort"), AssFile::COMMIT_ORDER);
}
};
struct grid_tag_cycle_hiding final : public Command {
CMD_NAME("grid/tag/cycle_hiding")
CMD_ICON(toggle_tag_hiding)
@ -411,12 +459,16 @@ namespace cmd {
reg(agi::make_unique<grid_sort_layer>());
reg(agi::make_unique<grid_sort_start>());
reg(agi::make_unique<grid_sort_style>());
reg(agi::make_unique<grid_sort_text>());
reg(agi::make_unique<grid_sort_text_stripped>());
reg(agi::make_unique<grid_sort_actor_selected>());
reg(agi::make_unique<grid_sort_effect_selected>());
reg(agi::make_unique<grid_sort_end_selected>());
reg(agi::make_unique<grid_sort_layer_selected>());
reg(agi::make_unique<grid_sort_start_selected>());
reg(agi::make_unique<grid_sort_style_selected>());
reg(agi::make_unique<grid_sort_text_selected>());
reg(agi::make_unique<grid_sort_text_stripped_selected>());
reg(agi::make_unique<grid_move_down>());
reg(agi::make_unique<grid_move_up>());
reg(agi::make_unique<grid_swap>());

View file

@ -109,6 +109,8 @@
{ "command" : "grid/sort/style" },
{ "command" : "grid/sort/actor" },
{ "command" : "grid/sort/effect" },
{ "command" : "grid/sort/text" },
{ "command" : "grid/sort/text_stripped" },
{ "command" : "grid/sort/layer" }
],
"main/subtitle/sort selected lines" : [
@ -117,6 +119,8 @@
{ "command" : "grid/sort/style/selected" },
{ "command" : "grid/sort/actor/selected" },
{ "command" : "grid/sort/effect/selected" },
{ "command" : "grid/sort/text/selected" },
{ "command" : "grid/sort/text_stripped/selected" },
{ "command" : "grid/sort/layer/selected" }
],
"main/timing" : [

View file

@ -111,6 +111,8 @@
{ "command" : "grid/sort/style" },
{ "command" : "grid/sort/actor" },
{ "command" : "grid/sort/effect" },
{ "command" : "grid/sort/text" },
{ "command" : "grid/sort/text_stripped" },
{ "command" : "grid/sort/layer" }
],
"main/subtitle/sort selected lines" : [
@ -119,6 +121,8 @@
{ "command" : "grid/sort/style/selected" },
{ "command" : "grid/sort/actor/selected" },
{ "command" : "grid/sort/effect/selected" },
{ "command" : "grid/sort/text/selected" },
{ "command" : "grid/sort/text_stripped/selected" },
{ "command" : "grid/sort/layer/selected" }
],
"main/timing" : [