Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 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,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<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 +1338,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
4 changes: 4 additions & 0 deletions src/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down