Make the enter-key-in-edit-box logic a standard hotkeyed command

Originally committed to SVN as r6294.
This commit is contained in:
Thomas Goyne 2012-01-14 01:40:21 +00:00
parent d8cedf0eec
commit 40e4f887ba
3 changed files with 45 additions and 32 deletions

View File

@ -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);

View File

@ -545,6 +545,19 @@
]
},
"Subtitle Edit Box" : {
"grid/line/next/create" : [
{
"modifiers" : [],
"key" : "KP_Enter"
},
{
"modifiers" : [],
"key" : "Enter"
}
]
},
"Styling Assistant" : {
"audio/play/selection" : [
{

View File

@ -54,19 +54,19 @@
#include <wx/spinctrl.h>
#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) {