From bf5e504c59c093c1b844b27fda17ad774080e012 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 12 Oct 2011 23:08:11 +0000 Subject: [PATCH] Combine duplicated commands time/snap/frame and time/frame/current into one command that actually works Originally committed to SVN as r5736. --- aegisub/src/command/icon.cpp | 1 - aegisub/src/command/time.cpp | 54 ++++------------------- aegisub/src/libresrc/default_toolbar.json | 2 +- 3 files changed, 9 insertions(+), 48 deletions(-) diff --git a/aegisub/src/command/icon.cpp b/aegisub/src/command/icon.cpp index 860f6aef3..312988a04 100644 --- a/aegisub/src/command/icon.cpp +++ b/aegisub/src/command/icon.cpp @@ -160,7 +160,6 @@ INSERT_ICON("time/next", button_next) INSERT_ICON("time/prev", button_prev) INSERT_ICON("time/shift", shift_times_toolbutton) 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/start_video", substart_to_video) INSERT_ICON("time/sort/end", blank_button) diff --git a/aegisub/src/command/time.cpp b/aegisub/src/command/time.cpp index 42ac041af..3ce345eff 100644 --- a/aegisub/src/command/time.cpp +++ b/aegisub/src/command/time.cpp @@ -128,25 +128,18 @@ struct time_frame_current : public validate_video_loaded { void operator()(agi::Context *c) { if (!c->videoController->IsLoaded()) return; - wxArrayInt sels = c->subsGrid->GetSelection(); - size_t n=sels.Count(); - if (n == 0) return; + std::set sel = c->selectionController->GetSelectedSet(); + AssDialogue *active_line = c->selectionController->GetActiveLine(); - // Get shifting in ms - AssDialogue *cur = c->subsGrid->GetDialogue(sels[0]); - if (!cur) return; - int shiftBy = c->videoController->TimeAtFrame(c->videoController->GetFrameN(),agi::vfr::START) - cur->Start.GetMS(); + if (sel.empty() || !active_line) return; - // Update - for (size_t i=0;isubsGrid->GetDialogue(sels[i]); - if (cur) { - cur->Start.SetMS(cur->Start.GetMS()+shiftBy); - cur->End.SetMS(cur->End.GetMS()+shiftBy); - } + int shift_by = c->videoController->TimeAtFrame(c->videoController->GetFrameN(), agi::vfr::START) - active_line->Start.GetMS(); + + for (std::set::iterator it = sel.begin(); it != sel.end(); ++it) { + (*it)->Start.SetMS((*it)->Start.GetMS() + shift_by); + (*it)->End.SetMS((*it)->End.GetMS() + shift_by); } - // Commit 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. struct time_snap_scene : public validate_video_loaded { CMD_NAME("time/snap/scene") @@ -401,7 +364,6 @@ namespace cmd { reg(new time_prev); reg(new time_shift); reg(new time_snap_end_video); - reg(new time_snap_frame); reg(new time_snap_scene); reg(new time_snap_start_video); reg(new time_sort_end); diff --git a/aegisub/src/libresrc/default_toolbar.json b/aegisub/src/libresrc/default_toolbar.json index b8888431d..0e85cf05b 100644 --- a/aegisub/src/libresrc/default_toolbar.json +++ b/aegisub/src/libresrc/default_toolbar.json @@ -40,7 +40,7 @@ "time/snap/end_video", "subtitle/select/visible", "time/snap/scene", - "time/snap/frame", + "time/frame/current", "", "tool/style/manager", "subtitle/properties",