diff --git a/src/command/edit.cpp b/src/command/edit.cpp index bd32e36442..471b2968e6 100644 --- a/src/command/edit.cpp +++ b/src/command/edit.cpp @@ -112,6 +112,13 @@ std::unique_ptr get_dialogue(String data) { } } +enum class JoinDialogueFormat { + DashSecondLineWithSpace, + DashSecondLineWithoutSpace, + DashBothLinesWithSpace, + DashBothLinesWithoutSpace +}; + template void paste_lines(agi::Context *c, bool paste_over, Paster&& paste_line) { std::string data = GetClipboard(); @@ -781,8 +788,56 @@ 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(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") @@ -1283,6 +1338,7 @@ namespace cmd { reg(std::make_unique()); reg(std::make_unique()); reg(std::make_unique()); + reg(std::make_unique()); reg(std::make_unique()); reg(std::make_unique()); reg(std::make_unique()); diff --git a/src/libresrc/default_config.json b/src/libresrc/default_config.json index 8fdcfb6ef4..3d8e7a4bb4 100644 --- a/src/libresrc/default_config.json +++ b/src/libresrc/default_config.json @@ -394,6 +394,7 @@ "Font Size" : 8, "Hide Overrides" : 1, "Hide Overrides Char" : "☀", + "Join as Dialogue Format" : 0, "Highlight Subtitles in Frame" : true }, "Highlight" : { diff --git a/src/libresrc/default_menu.json b/src/libresrc/default_menu.json index 493938ac45..205fe6c75a 100644 --- a/src/libresrc/default_menu.json +++ b/src/libresrc/default_menu.json @@ -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)" }, {}, @@ -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" } ], diff --git a/src/preferences.cpp b/src/preferences.cpp index 0d20ff2035..9022873e69 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -229,6 +229,10 @@ 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"); + 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); }