Handle empty files better in the translation assistant

Originally committed to SVN as r6167.
This commit is contained in:
Thomas Goyne 2011-12-26 22:21:19 +00:00
parent 92254a9806
commit ae3895fb8e
3 changed files with 19 additions and 6 deletions

View file

@ -49,6 +49,7 @@
#include "../dialog_fonts_collector.h" #include "../dialog_fonts_collector.h"
#include "../standard_paths.h" // tool_assdraw #include "../standard_paths.h" // tool_assdraw
#include "../video_context.h" // tool_font_collector #include "../video_context.h" // tool_font_collector
#include "../compat.h"
#include "../dialog_export.h" #include "../dialog_export.h"
#include "../dialog_resample.h" #include "../dialog_resample.h"
#include "../dialog_selection.h" #include "../dialog_selection.h"
@ -227,10 +228,16 @@ struct tool_translation_assistant : public Command {
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
c->videoController->Stop(); c->videoController->Stop();
DialogTranslation d(c); try {
c->translationAssistant = &d; DialogTranslation d(c);
d.ShowModal(); c->translationAssistant = &d;
c->translationAssistant = 0; d.ShowModal();
c->translationAssistant = 0;
}
catch (agi::Exception const& e) {
c->translationAssistant = 0;
wxMessageBox(lagi_wxString(e.GetChainedMessage()));
}
} }
}; };

View file

@ -32,6 +32,7 @@
#include "ass_file.h" #include "ass_file.h"
#include "audio_controller.h" #include "audio_controller.h"
#include "command/command.h" #include "command/command.h"
#include "compat.h"
#include "help_button.h" #include "help_button.h"
#include "libresrc/libresrc.h" #include "libresrc/libresrc.h"
#include "persist_location.h" #include "persist_location.h"
@ -157,8 +158,10 @@ DialogTranslation::DialogTranslation(agi::Context *c)
Bind(wxEVT_KEY_DOWN, &DialogTranslation::OnKeyDown, this); Bind(wxEVT_KEY_DOWN, &DialogTranslation::OnKeyDown, this);
active_line->ParseASSTags(); active_line->ParseASSTags();
if (bad_block(active_line->Blocks[0])) if (bad_block(active_line->Blocks[0])) {
NextBlock(); if (!NextBlock())
throw NothingToTranslate(STD_STR(_("There is nothing to translate in the file.")));
}
else else
UpdateDisplay(); UpdateDisplay();
} }

View file

@ -24,6 +24,7 @@
#include <wx/dialog.h> #include <wx/dialog.h>
#endif #endif
#include <libaegisub/exception.h>
#include <libaegisub/scoped_ptr.h> #include <libaegisub/scoped_ptr.h>
namespace agi { struct Context; } namespace agi { struct Context; }
@ -71,4 +72,6 @@ public:
bool PrevBlock(); bool PrevBlock();
void Commit(bool next); void Commit(bool next);
void InsertOriginal(); void InsertOriginal();
DEFINE_SIMPLE_EXCEPTION_NOINNER(NothingToTranslate, agi::Exception, "dialog/translation/nothing_to_translate");
}; };