Add command "edit/line/duplicate/shift_back"

This commit is contained in:
Thomas Goyne 2013-06-06 18:57:14 -07:00
parent 48c44440f7
commit 5c4279a654

View file

@ -571,7 +571,8 @@ struct in_selection : public std::unary_function<AssEntry, bool> {
} }
}; };
static void duplicate_lines(agi::Context *c, bool shift) { template<typename Func>
static void duplicate_lines(agi::Context *c, Func&& shift) {
in_selection sel(c->selectionController->GetSelectedSet()); in_selection sel(c->selectionController->GetSelectedSet());
SubtitleSelectionController::Selection new_sel; SubtitleSelectionController::Selection new_sel;
AssDialogue *new_active = 0; AssDialogue *new_active = 0;
@ -596,12 +597,7 @@ static void duplicate_lines(agi::Context *c, bool shift) {
new_sel.insert(new_diag); new_sel.insert(new_diag);
if (!new_active) if (!new_active)
new_active = new_diag; new_active = new_diag;
shift(new_diag);
if (shift) {
int pos = c->videoController->FrameAtTime(new_diag->End, agi::vfr::END) + 1;
new_diag->Start = c->videoController->TimeAtFrame(pos, agi::vfr::START);
new_diag->End = c->videoController->TimeAtFrame(pos, agi::vfr::END);
}
} while (start++ != last); } while (start++ != last);
// Skip over the lines we just made // Skip over the lines we just made
@ -623,17 +619,16 @@ struct edit_line_duplicate : public validate_sel_nonempty {
STR_HELP("Duplicate the selected lines") STR_HELP("Duplicate the selected lines")
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
duplicate_lines(c, false); duplicate_lines(c, [](AssDialogue *){});
} }
}; };
/// Duplicate lines and shift by one frame. /// Duplicate lines and shift by one frame.
struct edit_line_duplicate_shift : public Command { struct edit_line_duplicate_shift : public Command {
CMD_NAME("edit/line/duplicate/shift") CMD_NAME("edit/line/duplicate/shift")
STR_MENU("D&uplicate and Shift by 1 Frame") STR_MENU("D&uplicate and Shift by 1 Frame")
STR_DISP("Duplicate and Shift by 1 Frame") STR_DISP("Duplicate and Shift by 1 Frame")
STR_HELP("Duplicate lines and shift by one frame") STR_HELP("Duplicate lines and shift them to the frame after the original end frame")
CMD_TYPE(COMMAND_VALIDATE) CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) { bool Validate(const agi::Context *c) {
@ -641,7 +636,31 @@ struct edit_line_duplicate_shift : public Command {
} }
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
duplicate_lines(c, true); duplicate_lines(c, [=](AssDialogue *new_diag) {
int pos = c->videoController->FrameAtTime(new_diag->End, agi::vfr::END) + 1;
new_diag->Start = c->videoController->TimeAtFrame(pos, agi::vfr::START);
new_diag->End = c->videoController->TimeAtFrame(pos, agi::vfr::END);
});
}
};
struct edit_line_duplicate_shift_back : public Command {
CMD_NAME("edit/line/duplicate/shift_back")
STR_MENU("Du&plicate and Shift by 1 Frame Backwards")
STR_DISP("Duplicate and Shift by 1 Frame Backwards")
STR_HELP("Duplicate selected lines and shift them to the frame before the original start frame")
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return !c->selectionController->GetSelectedSet().empty() && c->videoController->IsLoaded();
}
void operator()(agi::Context *c) {
duplicate_lines(c, [=](AssDialogue *new_diag) {
int pos = c->videoController->FrameAtTime(new_diag->Start, agi::vfr::START) - 1;
new_diag->Start = c->videoController->TimeAtFrame(pos, agi::vfr::START);
new_diag->End = c->videoController->TimeAtFrame(pos, agi::vfr::END);
});
} }
}; };
@ -1000,6 +1019,7 @@ namespace cmd {
reg(new edit_line_delete); reg(new edit_line_delete);
reg(new edit_line_duplicate); reg(new edit_line_duplicate);
reg(new edit_line_duplicate_shift); reg(new edit_line_duplicate_shift);
reg(new edit_line_duplicate_shift_back);
reg(new edit_line_join_as_karaoke); reg(new edit_line_join_as_karaoke);
reg(new edit_line_join_concatenate); reg(new edit_line_join_concatenate);
reg(new edit_line_join_keep_first); reg(new edit_line_join_keep_first);