diff --git a/aegisub/auto4_base.cpp b/aegisub/auto4_base.cpp index f802edc41..9674cea98 100644 --- a/aegisub/auto4_base.cpp +++ b/aegisub/auto4_base.cpp @@ -366,7 +366,9 @@ namespace Automation4 { if (script_finished) { if (!debug_visible) { - EndModal(0); + if(IsModal()) + EndModal(0); + else Show(false); } else { cancel_button->Enable(true); cancel_button->SetLabel(_("Close")); @@ -450,7 +452,10 @@ namespace Automation4 { cancelled = true; cancel_button->Enable(false); } else { - EndModal(0); + if(this->IsModal()) + EndModal(0); + else + Show(false); } } diff --git a/aegisub/auto4_base.h b/aegisub/auto4_base.h index f5dd180f0..963ca0ce9 100644 --- a/aegisub/auto4_base.h +++ b/aegisub/auto4_base.h @@ -232,7 +232,6 @@ namespace Automation4 { void OnIdle(wxIdleEvent &evt); void OnConfigDialog(ShowConfigDialogEvent &evt); - void DoUpdateDisplay(); protected: volatile bool cancelled; @@ -242,6 +241,7 @@ namespace Automation4 { virtual ~ProgressSink(); public: + void DoUpdateDisplay(); void SetProgress(float _progress); void SetTask(const wxString &_task); void SetTitle(const wxString &_title); diff --git a/aegisub/auto4_ruby.cpp b/aegisub/auto4_ruby.cpp index d301dc75c..6aa88dba3 100644 --- a/aegisub/auto4_ruby.cpp +++ b/aegisub/auto4_ruby.cpp @@ -41,7 +41,7 @@ #include "ass_override.h" #include "text_file_reader.h" #include "options.h" -#include "../ruby/include/ruby.h" +#include #include #include #include @@ -262,6 +262,7 @@ namespace Automation4 { , macro_fun(macro_function) , validation_fun(validate_function) { + no_validate = validate_function == Qnil; RegisterFeature(); } @@ -273,25 +274,23 @@ namespace Automation4 { try { RubyAssFile *subsobj = new RubyAssFile(subs, true, true); VALUE sel = CreateIntegerArray(selected); // selected items - // RubyObjects::Get()->Register(sel); + RubyObjects::Get()->Register(sel); VALUE result = rbFunCall(rb_mKernel, rb_to_id(validation_fun), 3, subsobj->rbAssFile, sel, rb_int2inum(active)); + RubyObjects::Get()->Unregister(sel); if(result != Qnil && result != Qfalse) return true; - // RubyObjects::Get()->Unregister(sel); }catch (const char* e) { wxString *err = new wxString(e, wxConvUTF8); - throw err->c_str(); + wxMessageBox(*err, _T("Error running validation function"),wxICON_ERROR | wxOK); } - // wxMessageBox(error, _T("Error running validation function"), wxICON_ERROR | wxOK); - // } + return false; } void RubyFeatureMacro::Process(AssFile *subs, const std::vector &selected, int active, wxWindow * const progress_parent) { - // prepare function call try { - + delete RubyProgressSink::inst; RubyProgressSink::inst = new RubyProgressSink(progress_parent, false); RubyProgressSink::inst->SetTitle(GetName()); RubyProgressSink::inst->Show(true); @@ -301,19 +300,16 @@ namespace Automation4 { VALUE sel = CreateIntegerArray(selected); // selected items RubyObjects::Get()->Register(sel); VALUE result = rbFunCall(rb_mKernel, rb_to_id(macro_fun), 3, subsobj->rbAssFile, sel, rb_int2inum(active)); + RubyObjects::Get()->Unregister(sel); if(result != Qnil && result != Qfalse) { subsobj->RubyUpdateAssFile(result); RubyProgressSink::inst->script_finished = true; } - else RubyProgressSink::inst->Show(false); - // RubyObjects::Get()->Unregister(sel); } catch (const char* e) { wxString *err = new wxString(e, wxConvUTF8); wxMessageBox(*err, _T("Error running macro"),wxICON_ERROR | wxOK); } - delete RubyProgressSink::inst; - RubyProgressSink::inst = NULL; } @@ -355,7 +351,7 @@ namespace Automation4 { assert(config_dialog->RubyReadBack() == 1); // TODO, write back stored options here } - + delete RubyProgressSink::inst; RubyProgressSink::inst = new RubyProgressSink(export_dialog, false); RubyProgressSink::inst->SetTitle(GetName()); RubyProgressSink::inst->Show(true); @@ -365,15 +361,12 @@ namespace Automation4 { if(result != Qnil && result != Qfalse) { subsobj->RubyUpdateAssFile(result); + RubyProgressSink::inst->script_finished = true; } - // else RubyProgressSink::inst->Show(false); } catch (const char* e) { wxString *err = new wxString(e, wxConvUTF8); wxMessageBox(*err, _T("Error running filter"),wxICON_ERROR | wxOK); } - delete RubyProgressSink::inst; - RubyProgressSink::inst = NULL; - } ScriptConfigDialog* RubyFeatureFilter::GenerateConfigDialog(wxWindow *parent) @@ -412,10 +405,6 @@ namespace Automation4 { RubyProgressSink::~RubyProgressSink() { - rb_undef_method(RubyScript::RubyAegisub, "progress_set"); - rb_undef_method(RubyScript::RubyAegisub, "progress_task"); - rb_undef_method(RubyScript::RubyAegisub, "progress_title"); - rb_undef_method(RubyScript::RubyAegisub, "debug_out"); // remove progress reporting stuff // TODO } @@ -458,6 +447,7 @@ namespace Automation4 { wxString _m(StringValueCStr(msg), wxConvUTF8); RubyProgressSink::inst->AddDebugOutput(_m); RubyProgressSink::inst->DoUpdateDisplay(); + wxSafeYield(RubyProgressSink::inst); return Qtrue; } diff --git a/aegisub/auto4_ruby.h b/aegisub/auto4_ruby.h index 8a0ecc8c3..53c0778ac 100644 --- a/aegisub/auto4_ruby.h +++ b/aegisub/auto4_ruby.h @@ -41,7 +41,7 @@ #include "auto4_base.h" #include #include -#include "../ruby/include/ruby.h" +#include class wxWindow; diff --git a/aegisub/auto4_ruby_assfile.cpp b/aegisub/auto4_ruby_assfile.cpp index 129e262f8..d691ce234 100644 --- a/aegisub/auto4_ruby_assfile.cpp +++ b/aegisub/auto4_ruby_assfile.cpp @@ -40,7 +40,7 @@ #include "ass_override.h" #include #include -#include "../ruby/include/ruby.h" +#include namespace Automation4 { @@ -376,7 +376,8 @@ namespace Automation4 { new_entry = reinterpret_cast(rb_protect(rb2AssWrapper, rbEntry, &status)); if(status == 0) ass->Line.push_back(new_entry); else { - // TODO: log/display the error + if(RubyProgressSink::inst) + RubyProgressSink::inst->RubyDebugOut(Qnil, ruby_errinfo); ruby_errinfo = Qnil; // clear the error } } @@ -566,6 +567,8 @@ namespace Automation4 { VALUE res = rb_protect(rbAss2RbWrapper, reinterpret_cast(*entry), &status); if(status == 0) rb_ary_push(rbAssFile, res); else { + if(RubyProgressSink::inst) + RubyProgressSink::inst->RubyDebugOut(Qnil, ruby_errinfo); ruby_errinfo = Qnil; } } diff --git a/aegisub/subtitle_format_ass.cpp b/aegisub/subtitle_format_ass.cpp index 41927b977..d6aaeeb9a 100644 --- a/aegisub/subtitle_format_ass.cpp +++ b/aegisub/subtitle_format_ass.cpp @@ -111,7 +111,7 @@ void ASSSubtitleFormat::ReadFile(wxString filename,wxString encoding) { version = 2; } // Not-so-special case for other groups, just set it - else if (wxbuffer[0] == _T('[')) { + else if (!wxbuffer.IsEmpty() && wxbuffer[0] == _T('[')) { curgroup = wxbuffer; // default from extension in all other sections //version = 1; diff --git a/aegisub/subtitle_format_txt.cpp b/aegisub/subtitle_format_txt.cpp index 083244f5e..94e341223 100644 --- a/aegisub/subtitle_format_txt.cpp +++ b/aegisub/subtitle_format_txt.cpp @@ -103,6 +103,7 @@ void TXTSubtitleFormat::ReadFile(wxString filename,wxString encoding) { using na while (file.HasMoreLines()) { // Reads line wxString value = file.ReadLineFromFile(); + if(value.IsEmpty()) continue; // Check if this isn't a timecodes file if (value.Left(10) == _T("# timecode")) {