Report a more useful line number for bad lines in the TPP. Closes #1596.

This commit is contained in:
Thomas Goyne 2013-04-15 17:09:21 -07:00
parent 3c7527c2f7
commit b743bb39b0

View file

@ -36,7 +36,20 @@
#include "dialog_timing_processor.h" #include "dialog_timing_processor.h"
#include "ass_dialogue.h"
#include "ass_file.h"
#include "ass_time.h"
#include "compat.h"
#include "help_button.h"
#include "include/aegisub/context.h"
#include "libresrc/libresrc.h"
#include "options.h"
#include "selection_controller.h"
#include "utils.h"
#include "video_context.h"
#include <algorithm> #include <algorithm>
#include <boost/range/algorithm.hpp>
#include <functional> #include <functional>
#include <wx/button.h> #include <wx/button.h>
@ -50,18 +63,6 @@
#include <wx/textctrl.h> #include <wx/textctrl.h>
#include <wx/valnum.h> #include <wx/valnum.h>
#include "ass_dialogue.h"
#include "ass_file.h"
#include "ass_time.h"
#include "compat.h"
#include "help_button.h"
#include "include/aegisub/context.h"
#include "libresrc/libresrc.h"
#include "options.h"
#include "selection_controller.h"
#include "utils.h"
#include "video_context.h"
namespace { namespace {
using std::placeholders::_1; using std::placeholders::_1;
@ -260,12 +261,8 @@ void DialogTimingProcessor::UpdateControls() {
// Only enable the OK button if it'll actually do something // Only enable the OK button if it'll actually do something
bool any_checked = false; bool any_checked = false;
size_t len = StyleList->GetCount(); size_t len = StyleList->GetCount();
for (size_t i = 0; i < len; ++i) { for (size_t i = 0; !any_checked && i < len; ++i)
if (StyleList->IsChecked(i)) { any_checked = StyleList->IsChecked(i);
any_checked = true;
break;
}
}
ApplyButton->Enable(any_checked && (hasLeadIn->IsChecked() || hasLeadOut->IsChecked() || keysEnable->IsChecked() || adjsEnable->IsChecked())); ApplyButton->Enable(any_checked && (hasLeadIn->IsChecked() || hasLeadOut->IsChecked() || keysEnable->IsChecked() || adjsEnable->IsChecked()));
} }
@ -311,14 +308,15 @@ std::vector<AssDialogue*> DialogTimingProcessor::SortDialogues() {
} }
else { else {
transform(c->ass->Line.begin(), c->ass->Line.end(), back_inserter(sorted), cast<AssDialogue*>()); transform(c->ass->Line.begin(), c->ass->Line.end(), back_inserter(sorted), cast<AssDialogue*>());
sorted.erase(remove_if(sorted.begin(), sorted.end(), bind(bad_line, &styles, _1)), sorted.end()); sorted.erase(boost::remove_if(sorted, bind(bad_line, &styles, _1)), sorted.end());
} }
// Check if rows are valid // Check if rows are valid
for (size_t i = 0; i < sorted.size(); ++i) { for (auto diag : sorted) {
if (sorted[i]->Start > sorted[i]->End) { if (diag->Start > diag->End) {
int line = count_if(c->ass->Line.begin(), c->ass->Line.iterator_to(*diag), cast<const AssDialogue*>());
wxMessageBox( wxMessageBox(
wxString::Format(_("One of the lines in the file (%i) has negative duration. Aborting."), i), wxString::Format(_("One of the lines in the file (%i) has negative duration. Aborting."), line),
_("Invalid script"), _("Invalid script"),
wxOK | wxICON_ERROR | wxCENTER); wxOK | wxICON_ERROR | wxCENTER);
sorted.clear(); sorted.clear();
@ -326,16 +324,16 @@ std::vector<AssDialogue*> DialogTimingProcessor::SortDialogues() {
} }
} }
sort(sorted.begin(), sorted.end(), AssFile::CompStart); boost::sort(sorted, AssFile::CompStart);
return sorted; return sorted;
} }
static int get_closest_kf(std::vector<int> const& kf, int frame) { static int get_closest_kf(std::vector<int> const& kf, int frame) {
std::vector<int>::const_iterator pos = upper_bound(kf.begin(), kf.end(), frame); const auto pos = boost::upper_bound(kf, frame);
// Return last keyframe if this is after the last one // Return last keyframe if this is after the last one
if (pos == kf.end()) return kf.back(); if (pos == end(kf)) return kf.back();
// *pos is greater than frame, and *(pos - 1) is less than or equal to frame // *pos is greater than frame, and *(pos - 1) is less than or equal to frame
return (pos == kf.begin() || *pos - frame < frame - *(pos - 1)) ? *pos : *(pos - 1); return (pos == begin(kf) || *pos - frame < frame - *(pos - 1)) ? *pos : *(pos - 1);
} }
template<class Iter, class Field> template<class Iter, class Field>