Preserve line current length in Duplicate and Shift
It's quite rare to actually want a multi-frame line followed by a single-frame line; in most cases they're either all a single frame (in which case this behaves the same as it always has), or they're all multi-line, in which case this should be more convenient.
This commit is contained in:
parent
1f04d02c1b
commit
2f14c395e7
1 changed files with 19 additions and 20 deletions
|
@ -559,8 +559,7 @@ struct in_selection : public std::unary_function<AssEntry, bool> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Func>
|
static void duplicate_lines(agi::Context *c, int shift) {
|
||||||
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;
|
||||||
|
@ -585,7 +584,15 @@ static void duplicate_lines(agi::Context *c, Func&& 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 old_start = c->videoController->FrameAtTime(new_diag->Start, agi::vfr::START);
|
||||||
|
int old_end = c->videoController->FrameAtTime(new_diag->End, agi::vfr::END);
|
||||||
|
int dur = (old_end - old_start + 1) * shift;
|
||||||
|
|
||||||
|
new_diag->Start = c->videoController->TimeAtFrame(old_start + dur, agi::vfr::START);
|
||||||
|
new_diag->End = c->videoController->TimeAtFrame(old_end + dur, agi::vfr::END);
|
||||||
|
}
|
||||||
} while (start++ != last);
|
} while (start++ != last);
|
||||||
|
|
||||||
// Skip over the lines we just made
|
// Skip over the lines we just made
|
||||||
|
@ -606,15 +613,15 @@ 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, [](AssDialogue *){});
|
duplicate_lines(c, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
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")
|
||||||
STR_DISP("Duplicate and Shift by 1 Frame")
|
STR_DISP("Duplicate and Shift")
|
||||||
STR_HELP("Duplicate lines and shift them to the frame after the original end frame")
|
STR_HELP("Duplicate lines and shift them to start 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) {
|
||||||
|
@ -622,19 +629,15 @@ struct edit_line_duplicate_shift : public Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(agi::Context *c) {
|
void operator()(agi::Context *c) {
|
||||||
duplicate_lines(c, [=](AssDialogue *new_diag) {
|
duplicate_lines(c, 1);
|
||||||
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 {
|
struct edit_line_duplicate_shift_back : public Command {
|
||||||
CMD_NAME("edit/line/duplicate/shift_back")
|
CMD_NAME("edit/line/duplicate/shift_back")
|
||||||
STR_MENU("Du&plicate and Shift by 1 Frame Backwards")
|
STR_MENU("Du&plicate and Shift Backwards")
|
||||||
STR_DISP("Duplicate and Shift by 1 Frame Backwards")
|
STR_DISP("Duplicate and Shift Backwards")
|
||||||
STR_HELP("Duplicate selected lines and shift them to the frame before the original start frame")
|
STR_HELP("Duplicate selected lines and shift them to end the frame before the original start frame")
|
||||||
CMD_TYPE(COMMAND_VALIDATE)
|
CMD_TYPE(COMMAND_VALIDATE)
|
||||||
|
|
||||||
bool Validate(const agi::Context *c) {
|
bool Validate(const agi::Context *c) {
|
||||||
|
@ -642,11 +645,7 @@ struct edit_line_duplicate_shift_back : public Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(agi::Context *c) {
|
void operator()(agi::Context *c) {
|
||||||
duplicate_lines(c, [=](AssDialogue *new_diag) {
|
duplicate_lines(c, -1);
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue