diff --git a/aegisub/src/command/grid.cpp b/aegisub/src/command/grid.cpp index 625a4d4bd..d8f9c06fd 100644 --- a/aegisub/src/command/grid.cpp +++ b/aegisub/src/command/grid.cpp @@ -43,9 +43,9 @@ #include "../ass_dialogue.h" #include "../ass_file.h" #include "../include/aegisub/context.h" -#include "../subs_grid.h" #include "../main.h" #include "../frame_main.h" +#include "../selection_controller.h" #include "../utils.h" namespace { @@ -61,10 +61,33 @@ struct grid_line_next : public Command { STR_HELP("Move to the next subtitle line.") void operator()(agi::Context *c) { - c->subsGrid->NextLine(); + c->selectionController->NextLine(); } }; +/// Move to the next subtitle line, creating it if needed +struct grid_line_next_create : public Command { + CMD_NAME("grid/line/next/create") + STR_MENU("Next Line") + STR_DISP("Next Line") + STR_HELP("Move to the next subtitle line, creating a new one if needed.") + + void operator()(agi::Context *c) { + AssDialogue *cur = c->selectionController->GetActiveLine(); + c->selectionController->NextLine(); + if (cur == c->selectionController->GetActiveLine()) { + AssDialogue *newline = new AssDialogue; + newline->Start = cur->End; + newline->End = cur->End + OPT_GET("Timing/Default Duration")->GetInt(); + newline->Style = cur->Style; + + entryIter pos = find(c->ass->Line.begin(), c->ass->Line.end(), cur); + c->ass->Line.insert(++pos, newline); + c->ass->Commit(_("line insertion"), AssFile::COMMIT_DIAG_ADDREM); + c->selectionController->NextLine(); + } + } +}; /// Move to the previous line. struct grid_line_prev : public Command { @@ -74,7 +97,7 @@ struct grid_line_prev : public Command { STR_HELP("Move to the previous line.") void operator()(agi::Context *c) { - c->subsGrid->PrevLine(); + c->selectionController->PrevLine(); } } ; @@ -284,6 +307,7 @@ struct grid_swap : public Command { namespace cmd { void init_grid() { reg(new grid_line_next); + reg(new grid_line_next_create); reg(new grid_line_prev); reg(new grid_sort_end); reg(new grid_sort_start); diff --git a/aegisub/src/libresrc/default_hotkey.json b/aegisub/src/libresrc/default_hotkey.json index b5f407018..b730c4ddd 100644 --- a/aegisub/src/libresrc/default_hotkey.json +++ b/aegisub/src/libresrc/default_hotkey.json @@ -545,6 +545,19 @@ ] }, + "Subtitle Edit Box" : { + "grid/line/next/create" : [ + { + "modifiers" : [], + "key" : "KP_Enter" + }, + { + "modifiers" : [], + "key" : "Enter" + } + ] + }, + "Styling Assistant" : { "audio/play/selection" : [ { diff --git a/aegisub/src/subs_edit_box.cpp b/aegisub/src/subs_edit_box.cpp index 7f018fe85..61f0ae502 100644 --- a/aegisub/src/subs_edit_box.cpp +++ b/aegisub/src/subs_edit_box.cpp @@ -54,19 +54,19 @@ #include #endif -#include "include/aegisub/hotkey.h" +#include "subs_edit_box.h" #include "ass_dialogue.h" #include "ass_file.h" #include "ass_override.h" #include "ass_style.h" -#include "audio_controller.h" +#include "command/command.h" #include "dialog_colorpicker.h" #include "dialog_search_replace.h" #include "include/aegisub/context.h" +#include "include/aegisub/hotkey.h" #include "libresrc/libresrc.h" #include "main.h" -#include "subs_edit_box.h" #include "subs_edit_ctrl.h" #include "subs_grid.h" #include "timeedit_ctrl.h" @@ -451,36 +451,12 @@ void SubsEditBox::UpdateFrameTiming(agi::vfr::Framerate const& fps) { } void SubsEditBox::OnKeyDown(wxKeyEvent &event) { - if (hotkey::check("Subtitle Edit Box", c, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) - return; - - int key = event.GetKeyCode(); - if (line && (key == WXK_RETURN || key == WXK_NUMPAD_ENTER)) { - NextLine(); - } - else { + if (!hotkey::check("Subtitle Edit Box", c, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) event.Skip(); - } } void SubsEditBox::OnCommitButton(wxCommandEvent &) { - if (line) NextLine(); -} - -void SubsEditBox::NextLine() { - AssDialogue *cur = line; - c->selectionController->NextLine(); - if (line == cur) { - AssDialogue *newline = new AssDialogue; - newline->Start = cur->End; - newline->End = cur->End + OPT_GET("Timing/Default Duration")->GetInt(); - newline->Style = cur->Style; - - entryIter pos = find(c->ass->Line.begin(), c->ass->Line.end(), line); - c->ass->Line.insert(++pos, newline); - c->ass->Commit(_("line insertion"), AssFile::COMMIT_DIAG_ADDREM); - c->selectionController->NextLine(); - } + cmd::call("grid/line/next/create", c); } void SubsEditBox::OnChange(wxStyledTextEvent &event) {