diff --git a/aegisub/src/command/time.cpp b/aegisub/src/command/time.cpp index 1ffda77fd..a598d5a31 100644 --- a/aegisub/src/command/time.cpp +++ b/aegisub/src/command/time.cpp @@ -165,7 +165,22 @@ struct time_shift : public Command { } }; +static void snap_subs_video(agi::Context *c, bool start) { + std::set sel = c->selectionController->GetSelectedSet(); + if (!c->videoController->IsLoaded() || sel.empty()) return; + + int ms = c->videoController->TimeAtFrame(c->videoController->GetFrameN(), start ? agi::vfr::START : agi::vfr::END); + + for (std::set::iterator it = sel.begin(); it != sel.end(); ++it) { + if (start) + (*it)->Start.SetMS(ms); + else + (*it)->End.SetMS(ms); + } + + c->ass->Commit(_("timing"), AssFile::COMMIT_DIAG_TIME); +} /// Set end of selected subtitles to current video frame. struct time_snap_end_video : public validate_video_loaded { @@ -175,7 +190,7 @@ struct time_snap_end_video : public validate_video_loaded { STR_HELP("Set end of selected subtitles to current video frame.") void operator()(agi::Context *c) { - c->subsGrid->SetSubsToVideo(false); + snap_subs_video(c, false); } }; @@ -298,7 +313,7 @@ struct time_snap_start_video : public validate_video_loaded { STR_HELP("Set start of selected subtitles to current video frame.") void operator()(agi::Context *c) { - c->subsGrid->SetSubsToVideo(false); + snap_subs_video(c, true); } }; diff --git a/aegisub/src/subs_grid.cpp b/aegisub/src/subs_grid.cpp index fc102d42b..6e93f8e5a 100644 --- a/aegisub/src/subs_grid.cpp +++ b/aegisub/src/subs_grid.cpp @@ -553,29 +553,6 @@ bool SubtitlesGrid::SplitLineByKaraoke(int lineNumber) { return true; } -void SubtitlesGrid::SetSubsToVideo(bool start) { - if (!context->videoController->IsLoaded()) return; - - // Get new time - int ms = context->videoController->TimeAtFrame(context->videoController->GetFrameN(),start ? agi::vfr::START : agi::vfr::END); - - // Update selection - wxArrayInt sel = GetSelection(); - bool modified = false; - for (size_t i=0;iStart.SetMS(ms); - else cur->End.SetMS(ms); - } - } - - if (modified) { - context->ass->Commit(_("timing"), AssFile::COMMIT_DIAG_TIME); - } -} - /// @brief Retrieve a list of selected lines in the actual ASS file (ie. not as displayed in the grid but as represented in the file) /// @return /// diff --git a/aegisub/src/subs_grid.h b/aegisub/src/subs_grid.h index 7ebea5afc..883bdd3bf 100644 --- a/aegisub/src/subs_grid.h +++ b/aegisub/src/subs_grid.h @@ -76,10 +76,6 @@ public: SubtitlesGrid(wxWindow *parent, agi::Context *context, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr); ~SubtitlesGrid(); - /// @brief Set the start/end time of the current subtitle line to the current frame - /// @param start Start vs. End time - void SetSubsToVideo(bool start); - /// @brief Adjoins selected lines, setting each line's start time to the previous line's end time /// @param n1 First line to adjoin /// @param n2 Last line to adjoin