forked from mia/Aegisub
Don't block the source of a drag-and-drop while the dropped audio/video are loading
Originally committed to SVN as r6953.
This commit is contained in:
parent
b86a1bfb2d
commit
f2035d76fc
2 changed files with 88 additions and 66 deletions
|
@ -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,74 +570,14 @@ void FrameMain::StatusTimeout(wxString text,int ms) {
|
|||
StatusClear.Start(ms,true);
|
||||
}
|
||||
|
||||
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();
|
||||
void FrameMain::OnFilesDropped(wxThreadEvent &evt) {
|
||||
LoadList(evt.GetPayload<wxArrayString>());
|
||||
}
|
||||
|
||||
bool FrameMain::LoadList(wxArrayString list) {
|
||||
wxString audio, video, subs;
|
||||
get_files_to_load(list, subs, audio, video);
|
||||
|
||||
blockVideoLoad = !video.empty();
|
||||
blockAudioLoad = !audio.empty();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue