From f2035d76fc9cc45f10391ca0d37a1f0c5cff3e7c Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sat, 4 Aug 2012 16:31:44 +0000 Subject: [PATCH] Don't block the source of a drag-and-drop while the dropped audio/video are loading Originally committed to SVN as r6953. --- aegisub/src/frame_main.cpp | 153 +++++++++++++++++++++---------------- aegisub/src/frame_main.h | 1 + 2 files changed, 88 insertions(+), 66 deletions(-) diff --git a/aegisub/src/frame_main.cpp b/aegisub/src/frame_main.cpp index 9b12d03cf..0eb0efaca 100644 --- a/aegisub/src/frame_main.cpp +++ b/aegisub/src/frame_main.cpp @@ -94,13 +94,92 @@ enum { static void autosave_timer_changed(wxTimer *timer); +wxDEFINE_EVENT(FILE_LIST_DROPPED, wxThreadEvent); + +static void get_files_to_load(wxArrayString const& list, wxString &subs, wxString &audio, wxString &video) { + // Keep these lists sorted + + // Video formats + const wxString videoList[] = { + "asf", + "avi", + "avs", + "d2v", + "m2ts", + "mkv", + "mov", + "mp4", + "mpeg", + "mpg", + "ogm", + "rm", + "rmvb", + "ts", + "webm" + "wmv", + "y4m", + "yuv" + }; + + // Subtitle formats + const wxString subsList[] = { + "ass", + "srt", + "ssa", + "sub", + "ttxt", + "txt" + }; + + // Audio formats + const wxString audioList[] = { + "aac", + "ac3", + "ape", + "dts", + "flac", + "m4a", + "mka", + "mp3", + "ogg", + "w64", + "wav", + "wma" + }; + + // Scan list + for (size_t i = 0; i < list.size(); ++i) { + wxFileName file(list[i]); + if (file.IsRelative()) file.MakeAbsolute(); + if (!file.FileExists()) continue; + + wxString ext = file.GetExt().Lower(); + + if (subs.empty() && std::binary_search(subsList, subsList + countof(subsList), ext)) + subs = file.GetFullPath(); + if (video.empty() && std::binary_search(videoList, videoList + countof(videoList), ext)) + video = file.GetFullPath(); + if (audio.empty() && std::binary_search(audioList, audioList + countof(audioList), ext)) + audio = file.GetFullPath(); + } +} + /// Handle files drag and dropped onto Aegisub class AegisubFileDropTarget : public wxFileDropTarget { FrameMain *parent; public: AegisubFileDropTarget(FrameMain *parent) : parent(parent) { } bool OnDropFiles(wxCoord, wxCoord, const wxArrayString& filenames) { - return parent->LoadList(filenames); + wxString subs, audio, video; + get_files_to_load(filenames, subs, audio, video); + + if (!subs && !audio && !video) + return false; + + wxThreadEvent *evt = new wxThreadEvent(FILE_LIST_DROPPED); + evt->SetPayload(filenames); + parent->QueueEvent(evt); + return true; } }; @@ -222,6 +301,8 @@ FrameMain::FrameMain (wxArrayString args) PerformVersionCheck(false); #endif + Bind(FILE_LIST_DROPPED, &FrameMain::OnFilesDropped, this); + StartupLog("Leaving FrameMain constructor"); } @@ -489,73 +570,13 @@ void FrameMain::StatusTimeout(wxString text,int ms) { StatusClear.Start(ms,true); } +void FrameMain::OnFilesDropped(wxThreadEvent &evt) { + LoadList(evt.GetPayload()); +} + bool FrameMain::LoadList(wxArrayString list) { - // Keep these lists sorted - - // Video formats - const wxString videoList[] = { - "asf", - "avi", - "avs", - "d2v", - "m2ts", - "mkv", - "mov", - "mp4", - "mpeg", - "mpg", - "ogm", - "rm", - "rmvb", - "ts", - "webm" - "wmv", - "y4m", - "yuv" - }; - - // Subtitle formats - const wxString subsList[] = { - "ass", - "srt", - "ssa", - "sub", - "ttxt", - "txt" - }; - - // Audio formats - const wxString audioList[] = { - "aac", - "ac3", - "ape", - "dts", - "flac", - "m4a", - "mka", - "mp3", - "ogg", - "w64", - "wav", - "wma" - }; - - // Scan list wxString audio, video, subs; - for (size_t i = 0; i < list.size(); ++i) { - wxFileName file(list[i]); - if (file.IsRelative()) file.MakeAbsolute(); - if (!file.FileExists()) continue; - - wxString ext = file.GetExt().Lower(); - - if (subs.empty() && std::binary_search(subsList, subsList + countof(subsList), ext)) - subs = file.GetFullPath(); - if (video.empty() && std::binary_search(videoList, videoList + countof(videoList), ext)) - video = file.GetFullPath(); - if (audio.empty() && std::binary_search(audioList, audioList + countof(audioList), ext)) - audio = file.GetFullPath(); - } + get_files_to_load(list, subs, audio, video); blockVideoLoad = !video.empty(); blockAudioLoad = !audio.empty(); diff --git a/aegisub/src/frame_main.h b/aegisub/src/frame_main.h index baab8a795..ce02865b8 100644 --- a/aegisub/src/frame_main.h +++ b/aegisub/src/frame_main.h @@ -93,6 +93,7 @@ class FrameMain: public wxFrame { void InitToolbar(); void InitContents(); + void OnFilesDropped(wxThreadEvent &evt); bool LoadList(wxArrayString list); void UpdateTitle(); wxString GetScriptFileName() const;