Skip to content

Commit cd57a11

Browse files
committed
feat: add join as dialogue option
1 parent 07800be commit cd57a11

File tree

5 files changed

+122
-1
lines changed

5 files changed

+122
-1
lines changed

po/aegisub.pot

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,23 @@ msgid ""
903903
"line which starts on the current frame"
904904
msgstr ""
905905

906+
#: ../src/command/edit.cpp:786
907+
msgid "Join &Dialogue"
908+
msgstr ""
909+
910+
#: ../src/command/edit.cpp:787
911+
msgid "Join Dialogue"
912+
msgstr ""
913+
906914
#: ../src/command/edit.cpp:788
915+
msgid ""Join selected lines in a single one, concatenating dialogue together""
916+
msgstr ""
917+
918+
#: ../src/command/edit.cpp:791
919+
msgid "join as dialogue"
920+
msgstr ""
921+
922+
#: ../src/command/edit.cpp:786
907923
msgid "As &Karaoke"
908924
msgstr ""
909925

@@ -5190,7 +5206,35 @@ msgstr ""
51905206
msgid "Skip over whitespace"
51915207
msgstr ""
51925208

5193-
#: ../src/preferences.cpp:244
5209+
#: ../src/preferences.cpp:235
5210+
msgid "Colour Picker"
5211+
msgstr ""
5212+
5213+
#: ../src/preferences.cpp:236
5214+
msgid "Restrict Screen Picker to Window"
5215+
msgstr ""
5216+
5217+
#! ../src/preferences.cpp:246
5218+
msgid "Dash second line without space"
5219+
msgstr ""
5220+
5221+
#! ../src/preferences.cpp:246
5222+
msgid "Dash second line with space"
5223+
msgstr "
5224+
5225+
#: ../src/preferences.cpp:246
5226+
msgid "Dash both lines with space"
5227+
msgstr ""
5228+
5229+
#: ../src/preferences.cpp:246
5230+
msgid "Dash both lines without space"
5231+
msgstr ""
5232+
5233+
#: ../src/preferences.cpp:248
5234+
msgid "Join as Dialogue Format"
5235+
msgstr ""
5236+
5237+
#: ../src/preferences.cpp:251
51945238
msgid "Audio Display"
51955239
msgstr ""
51965240

@@ -6121,6 +6165,10 @@ msgstr ""
61216165
msgid "Join (keep first)"
61226166
msgstr ""
61236167

6168+
#: default_menu.json:0
6169+
msgid "Join as Dialogue"
6170+
msgstr ""
6171+
61246172
#: default_menu.json:0
61256173
msgid "Join (as Karaoke)"
61266174
msgstr ""

src/command/edit.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ std::unique_ptr<AssDialogue> get_dialogue(String data) {
112112
}
113113
}
114114

115+
enum class JoinDialogueFormat {
116+
DashSecondLineWithSpace,
117+
DashSecondLineWithoutSpace,
118+
DashBothLinesWithSpace,
119+
DashBothLinesWithoutSpace
120+
};
121+
115122
template<typename Paster>
116123
void paste_lines(agi::Context *c, bool paste_over, Paster&& paste_line) {
117124
std::string data = GetClipboard();
@@ -781,8 +788,55 @@ static void combine_concat(AssDialogue *first, AssDialogue *second) {
781788
first->Text = agi::Str(first->Text.get(), " ", second->Text.get());
782789
}
783790

791+
static void combine_dialogue(AssDialogue *first, AssDialogue *second) {
792+
if (second) {
793+
auto format_option = OPT_GET("Subtitle/Grid/Join as Dialogue Format");
794+
JoinDialogueFormat format = JoinDialogueFormat::DashSecondLineWithSpace;
795+
796+
if (format_option) {
797+
format = static_cast<JoinDialogueFormat>(format_option->GetInt());
798+
}
799+
800+
std::string first_text = first->Text.get();
801+
std::string second_text = second ? second->Text.get() : "";
802+
std::string newline = OPT_GET("Subtitle/Edit Box/Soft Line Break")->GetBool() ? "\\n" : "\\N";
803+
804+
// Remove newlines from the lines to be merged
805+
boost::replace_all(first_text, newline, " ");
806+
boost::replace_all(second_text, newline, " ");
807+
808+
std::string combined_text = "";
809+
switch (format) {
810+
case JoinDialogueFormat::DashSecondLineWithSpace:
811+
combined_text = first_text + newline + "- " + second_text;
812+
break;
813+
case JoinDialogueFormat::DashSecondLineWithoutSpace:
814+
combined_text = first_text + newline + "-" + second_text;
815+
break;
816+
case JoinDialogueFormat::DashBothLinesWithSpace:
817+
combined_text = "- " + first_text + newline + "- " + second_text;
818+
break;
819+
case JoinDialogueFormat::DashBothLinesWithoutSpace:
820+
combined_text = "-" + first_text + newline + "-" + second_text;
821+
break;
822+
}
823+
first->Text = combined_text;
824+
}
825+
}
826+
784827
static void combine_drop(AssDialogue *, AssDialogue *) { }
785828

829+
struct edit_line_join_dialogue final : public validate_sel_multiple {
830+
CMD_NAME("edit/line/join/dialogue")
831+
STR_MENU("Join &Dialogue")
832+
STR_DISP("Join Dialogue")
833+
STR_HELP("Join selected lines in a single one, concatenating dialogue together")
834+
835+
void operator()(agi::Context *c) override {
836+
combine_lines(c, combine_dialogue, _("join dialogue"));
837+
}
838+
};
839+
786840
struct edit_line_join_as_karaoke final : public validate_sel_multiple {
787841
CMD_NAME("edit/line/join/as_karaoke")
788842
STR_MENU("As &Karaoke")
@@ -1283,6 +1337,7 @@ namespace cmd {
12831337
reg(std::make_unique<edit_line_duplicate_shift>());
12841338
reg(std::make_unique<edit_line_duplicate_shift_back>());
12851339
reg(std::make_unique<edit_line_join_as_karaoke>());
1340+
reg(std::make_unique<edit_line_join_dialogue>());
12861341
reg(std::make_unique<edit_line_join_concatenate>());
12871342
reg(std::make_unique<edit_line_join_keep_first>());
12881343
reg(std::make_unique<edit_line_paste>());

src/libresrc/default_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@
394394
"Font Size" : 8,
395395
"Hide Overrides" : 1,
396396
"Hide Overrides Char" : "",
397+
"Join as Dialogue Format" : 0,
397398
"Highlight Subtitles in Frame" : true
398399
},
399400
"Highlight" : {

src/libresrc/default_menu.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
{},
1212
{ "command" : "grid/swap" },
1313
{ "command" : "edit/line/join/concatenate", "text" : "&Join (concatenate)" },
14+
{ "command" : "edit/line/join/dialogue", "text" : "Join (as Dialogue)" },
1415
{ "command" : "edit/line/join/keep_first", "text" : "Join (keep first)" },
1516
{ "command" : "edit/line/join/as_karaoke", "text" : "Join (as Karaoke)" },
1617
{},
@@ -39,6 +40,7 @@
3940
],
4041
"main/subtitle/join lines" : [
4142
{ "command" : "edit/line/join/concatenate" },
43+
{ "command" : "edit/line/join/dialogue" },
4244
{ "command" : "edit/line/join/keep_first" },
4345
{ "command" : "edit/line/join/as_karaoke" }
4446
],

src/preferences.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,21 @@ void Interface(wxTreebook *book, Preferences *parent) {
229229
auto tl_assistant = p->PageSizer(_("Translation Assistant"));
230230
p->OptionAdd(tl_assistant, _("Skip over whitespace"), "Tool/Translation Assistant/Skip Whitespace");
231231

232+
auto visual_tools = p->PageSizer(_("Visual Tools"));
233+
p->OptionAdd(visual_tools, _("Shape handle size"), "Tool/Visual/Shape Handle Size");
234+
235+
auto color_picker = p->PageSizer(_("Colour Picker"));
236+
p->OptionAdd(color_picker, _("Restrict Screen Picker to Window"), "Tool/Colour Picker/Restrict to Window");
237+
238+
#if defined(__WXMSW__) && wxVERSION_NUMBER >= 3300
239+
auto dark_mode = p->PageSizer(_("Dark Mode"));
240+
p->OptionAdd(dark_mode, _("Enable experimental dark mode (restart required)"), "App/Dark Mode");
241+
#endif
242+
243+
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") };
244+
wxArrayString dialogue_pref(4, cdialogue_pref);
245+
p->OptionChoice(grid, _("Join as Dialogue Format"), dialogue_pref, "Subtitle/Grid/Join as Dialogue Format");
246+
232247
p->SetSizerAndFit(p->sizer);
233248
}
234249

0 commit comments

Comments
 (0)