Combine duplicated commands time/snap/frame and time/frame/current into one command that actually works

Originally committed to SVN as r5736.
This commit is contained in:
Thomas Goyne 2011-10-12 23:08:11 +00:00
parent 54f359f91b
commit bf5e504c59
3 changed files with 9 additions and 48 deletions

View File

@ -160,7 +160,6 @@ INSERT_ICON("time/next", button_next)
INSERT_ICON("time/prev", button_prev) INSERT_ICON("time/prev", button_prev)
INSERT_ICON("time/shift", shift_times_toolbutton) INSERT_ICON("time/shift", shift_times_toolbutton)
INSERT_ICON("time/snap/end_video", subend_to_video) INSERT_ICON("time/snap/end_video", subend_to_video)
INSERT_ICON("time/snap/frame", shift_to_frame)
INSERT_ICON("time/snap/scene", snap_subs_to_scene) INSERT_ICON("time/snap/scene", snap_subs_to_scene)
INSERT_ICON("time/snap/start_video", substart_to_video) INSERT_ICON("time/snap/start_video", substart_to_video)
INSERT_ICON("time/sort/end", blank_button) INSERT_ICON("time/sort/end", blank_button)

View File

@ -128,25 +128,18 @@ struct time_frame_current : public validate_video_loaded {
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
if (!c->videoController->IsLoaded()) return; if (!c->videoController->IsLoaded()) return;
wxArrayInt sels = c->subsGrid->GetSelection(); std::set<AssDialogue*> sel = c->selectionController->GetSelectedSet();
size_t n=sels.Count(); AssDialogue *active_line = c->selectionController->GetActiveLine();
if (n == 0) return;
// Get shifting in ms if (sel.empty() || !active_line) return;
AssDialogue *cur = c->subsGrid->GetDialogue(sels[0]);
if (!cur) return;
int shiftBy = c->videoController->TimeAtFrame(c->videoController->GetFrameN(),agi::vfr::START) - cur->Start.GetMS();
// Update int shift_by = c->videoController->TimeAtFrame(c->videoController->GetFrameN(), agi::vfr::START) - active_line->Start.GetMS();
for (size_t i=0;i<n;i++) {
cur = c->subsGrid->GetDialogue(sels[i]); for (std::set<AssDialogue*>::iterator it = sel.begin(); it != sel.end(); ++it) {
if (cur) { (*it)->Start.SetMS((*it)->Start.GetMS() + shift_by);
cur->Start.SetMS(cur->Start.GetMS()+shiftBy); (*it)->End.SetMS((*it)->End.GetMS() + shift_by);
cur->End.SetMS(cur->End.GetMS()+shiftBy);
}
} }
// Commit
c->ass->Commit(_("shift to frame"), AssFile::COMMIT_DIAG_TIME); c->ass->Commit(_("shift to frame"), AssFile::COMMIT_DIAG_TIME);
} }
}; };
@ -194,36 +187,6 @@ struct time_snap_end_video : public validate_video_loaded {
} }
}; };
/// Shift selected subtitles so first selected starts at this frame.
struct time_snap_frame : public validate_video_loaded {
CMD_NAME("time/snap/frame")
STR_MENU("Shift Subtitles to Frame")
STR_DISP("Shift Subtitles to Frame")
STR_HELP("Shift selected subtitles so first selected starts at this frame.")
void operator()(agi::Context *c) {
if (c->videoController->IsLoaded()) return;
wxArrayInt sels = c->subsGrid->GetSelection();
if (sels.empty()) return;
AssDialogue *cur = c->subsGrid->GetDialogue(sels[0]);
if (!cur) return;
int shiftBy = c->videoController->TimeAtFrame(c->videoController->GetFrameN(),agi::vfr::START) - cur->Start.GetMS();
for (size_t i = 0; i < sels.size(); ++i) {
if ((cur = c->subsGrid->GetDialogue(sels[i]))) {
cur->Start.SetMS(cur->Start.GetMS() + shiftBy);
cur->End.SetMS(cur->End.GetMS() + shiftBy);
}
}
c->ass->Commit(_("shift to frame"), AssFile::COMMIT_DIAG_TIME);
}
};
/// Set start and end of subtitles to the keyframes around current video frame. /// Set start and end of subtitles to the keyframes around current video frame.
struct time_snap_scene : public validate_video_loaded { struct time_snap_scene : public validate_video_loaded {
CMD_NAME("time/snap/scene") CMD_NAME("time/snap/scene")
@ -401,7 +364,6 @@ namespace cmd {
reg(new time_prev); reg(new time_prev);
reg(new time_shift); reg(new time_shift);
reg(new time_snap_end_video); reg(new time_snap_end_video);
reg(new time_snap_frame);
reg(new time_snap_scene); reg(new time_snap_scene);
reg(new time_snap_start_video); reg(new time_snap_start_video);
reg(new time_sort_end); reg(new time_sort_end);

View File

@ -40,7 +40,7 @@
"time/snap/end_video", "time/snap/end_video",
"subtitle/select/visible", "subtitle/select/visible",
"time/snap/scene", "time/snap/scene",
"time/snap/frame", "time/frame/current",
"", "",
"tool/style/manager", "tool/style/manager",
"subtitle/properties", "subtitle/properties",