| 157 | } |
| 158 | |
| 159 | void MainFrame::OnDropFiles(wxDropFilesEvent& event) { |
| 160 | const int count = event.GetNumberOfFiles(); |
| 161 | const auto* list = event.GetFiles(); |
| 162 | auto* man = wxDocManager::GetDocumentManager(); |
| 163 | if (count <= 0 || list == nullptr || man == nullptr) { |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | for (int ii = 0; ii < count; ++ii) { |
| 168 | try { |
| 169 | const auto& file = list[ii]; |
| 170 | std::filesystem::path p(file.ToStdWstring()); |
| 171 | if (!std::filesystem::exists(p)) { |
| 172 | continue; |
| 173 | } |
| 174 | const auto& u8str = p.u8string(); |
| 175 | const bool mdf = mdf::IsMdfFile(std::string(u8str.begin(), u8str.end())); |
| 176 | if (!mdf) { |
| 177 | continue; |
| 178 | } |
| 179 | // Check if the file already is open |
| 180 | const auto* doc_exist = man->FindDocumentByPath(file); |
| 181 | if (doc_exist != nullptr) { |
| 182 | continue; |
| 183 | } |
| 184 | |
| 185 | man->CreateDocument(file, wxDOC_SILENT); |
| 186 | } |
| 187 | catch (const std::exception&) { |
| 188 | // Not much to do here |
| 189 | continue; |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | } |