Skip to content

Commit

Permalink
feat: add join as dialogue option
Browse files Browse the repository at this point in the history
  • Loading branch information
m-krastev committed Feb 14, 2025
1 parent 07800be commit cd57a11
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 1 deletion.
50 changes: 49 additions & 1 deletion po/aegisub.pot
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,23 @@ msgid ""
"line which starts on the current frame"
msgstr ""

#: ../src/command/edit.cpp:786
msgid "Join &Dialogue"
msgstr ""

#: ../src/command/edit.cpp:787
msgid "Join Dialogue"
msgstr ""

#: ../src/command/edit.cpp:788
msgid ""Join selected lines in a single one, concatenating dialogue together""
msgstr ""

#: ../src/command/edit.cpp:791
msgid "join as dialogue"
msgstr ""

#: ../src/command/edit.cpp:786
msgid "As &Karaoke"
msgstr ""

Expand Down Expand Up @@ -5190,7 +5206,35 @@ msgstr ""
msgid "Skip over whitespace"
msgstr ""

#: ../src/preferences.cpp:244
#: ../src/preferences.cpp:235
msgid "Colour Picker"
msgstr ""

#: ../src/preferences.cpp:236
msgid "Restrict Screen Picker to Window"
msgstr ""

#! ../src/preferences.cpp:246
msgid "Dash second line without space"
msgstr ""

#! ../src/preferences.cpp:246
msgid "Dash second line with space"
msgstr "
#: ../src/preferences.cpp:246
msgid "Dash both lines with space"
msgstr ""

#: ../src/preferences.cpp:246
msgid "Dash both lines without space"
msgstr ""

#: ../src/preferences.cpp:248
msgid "Join as Dialogue Format"
msgstr ""

#: ../src/preferences.cpp:251
msgid "Audio Display"
msgstr ""

Expand Down Expand Up @@ -6121,6 +6165,10 @@ msgstr ""
msgid "Join (keep first)"
msgstr ""

#: default_menu.json:0
msgid "Join as Dialogue"
msgstr ""

#: default_menu.json:0
msgid "Join (as Karaoke)"
msgstr ""
Expand Down
55 changes: 55 additions & 0 deletions src/command/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ std::unique_ptr<AssDialogue> get_dialogue(String data) {
}
}

enum class JoinDialogueFormat {
DashSecondLineWithSpace,
DashSecondLineWithoutSpace,
DashBothLinesWithSpace,
DashBothLinesWithoutSpace
};

template<typename Paster>
void paste_lines(agi::Context *c, bool paste_over, Paster&& paste_line) {
std::string data = GetClipboard();
Expand Down Expand Up @@ -781,8 +788,55 @@ static void combine_concat(AssDialogue *first, AssDialogue *second) {
first->Text = agi::Str(first->Text.get(), " ", second->Text.get());
}

static void combine_dialogue(AssDialogue *first, AssDialogue *second) {
if (second) {
auto format_option = OPT_GET("Subtitle/Grid/Join as Dialogue Format");
JoinDialogueFormat format = JoinDialogueFormat::DashSecondLineWithSpace;

if (format_option) {
format = static_cast<JoinDialogueFormat>(format_option->GetInt());
}

std::string first_text = first->Text.get();
std::string second_text = second ? second->Text.get() : "";
std::string newline = OPT_GET("Subtitle/Edit Box/Soft Line Break")->GetBool() ? "\\n" : "\\N";

// Remove newlines from the lines to be merged
boost::replace_all(first_text, newline, " ");
boost::replace_all(second_text, newline, " ");

std::string combined_text = "";
switch (format) {
case JoinDialogueFormat::DashSecondLineWithSpace:
combined_text = first_text + newline + "- " + second_text;
break;
case JoinDialogueFormat::DashSecondLineWithoutSpace:
combined_text = first_text + newline + "-" + second_text;
break;
case JoinDialogueFormat::DashBothLinesWithSpace:
combined_text = "- " + first_text + newline + "- " + second_text;
break;
case JoinDialogueFormat::DashBothLinesWithoutSpace:
combined_text = "-" + first_text + newline + "-" + second_text;
break;
}
first->Text = combined_text;
}
}

static void combine_drop(AssDialogue *, AssDialogue *) { }

struct edit_line_join_dialogue final : public validate_sel_multiple {
CMD_NAME("edit/line/join/dialogue")
STR_MENU("Join &Dialogue")
STR_DISP("Join Dialogue")
STR_HELP("Join selected lines in a single one, concatenating dialogue together")

void operator()(agi::Context *c) override {
combine_lines(c, combine_dialogue, _("join dialogue"));
}
};

struct edit_line_join_as_karaoke final : public validate_sel_multiple {
CMD_NAME("edit/line/join/as_karaoke")
STR_MENU("As &Karaoke")
Expand Down Expand Up @@ -1283,6 +1337,7 @@ namespace cmd {
reg(std::make_unique<edit_line_duplicate_shift>());
reg(std::make_unique<edit_line_duplicate_shift_back>());
reg(std::make_unique<edit_line_join_as_karaoke>());
reg(std::make_unique<edit_line_join_dialogue>());
reg(std::make_unique<edit_line_join_concatenate>());
reg(std::make_unique<edit_line_join_keep_first>());
reg(std::make_unique<edit_line_paste>());
Expand Down
1 change: 1 addition & 0 deletions src/libresrc/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@
"Font Size" : 8,
"Hide Overrides" : 1,
"Hide Overrides Char" : "",
"Join as Dialogue Format" : 0,
"Highlight Subtitles in Frame" : true
},
"Highlight" : {
Expand Down
2 changes: 2 additions & 0 deletions src/libresrc/default_menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{},
{ "command" : "grid/swap" },
{ "command" : "edit/line/join/concatenate", "text" : "&Join (concatenate)" },
{ "command" : "edit/line/join/dialogue", "text" : "Join (as Dialogue)" },
{ "command" : "edit/line/join/keep_first", "text" : "Join (keep first)" },
{ "command" : "edit/line/join/as_karaoke", "text" : "Join (as Karaoke)" },
{},
Expand Down Expand Up @@ -39,6 +40,7 @@
],
"main/subtitle/join lines" : [
{ "command" : "edit/line/join/concatenate" },
{ "command" : "edit/line/join/dialogue" },
{ "command" : "edit/line/join/keep_first" },
{ "command" : "edit/line/join/as_karaoke" }
],
Expand Down
15 changes: 15 additions & 0 deletions src/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ void Interface(wxTreebook *book, Preferences *parent) {
auto tl_assistant = p->PageSizer(_("Translation Assistant"));
p->OptionAdd(tl_assistant, _("Skip over whitespace"), "Tool/Translation Assistant/Skip Whitespace");

auto visual_tools = p->PageSizer(_("Visual Tools"));
p->OptionAdd(visual_tools, _("Shape handle size"), "Tool/Visual/Shape Handle Size");

auto color_picker = p->PageSizer(_("Colour Picker"));
p->OptionAdd(color_picker, _("Restrict Screen Picker to Window"), "Tool/Colour Picker/Restrict to Window");

#if defined(__WXMSW__) && wxVERSION_NUMBER >= 3300
auto dark_mode = p->PageSizer(_("Dark Mode"));
p->OptionAdd(dark_mode, _("Enable experimental dark mode (restart required)"), "App/Dark Mode");
#endif

const wxString cdialogue_pref[4] = { _("Dash second line with space"), _("Dash second line without space"), _("Dash both lines with space"), _("Dash both lines without space") };
wxArrayString dialogue_pref(4, cdialogue_pref);
p->OptionChoice(grid, _("Join as Dialogue Format"), dialogue_pref, "Subtitle/Grid/Join as Dialogue Format");

p->SetSizerAndFit(p->sizer);
}

Expand Down

0 comments on commit cd57a11

Please sign in to comment.