| 324 | } |
| 325 | |
| 326 | void IDE::fileModifiedTimeout(void) |
| 327 | { |
| 328 | QSet<QString> modCopy = modifiedFiles; |
| 329 | modifiedFiles.clear(); |
| 330 | for (QSet<QString>::iterator s_it = modCopy.begin(); s_it != modCopy.end(); ++s_it) { |
| 331 | DMap::iterator it = documents.find(*s_it); |
| 332 | if (it != documents.end()) { |
| 333 | QFileInfo fi(*s_it); |
| 334 | QMessageBox msg; |
| 335 | |
| 336 | if (!fi.exists()) { |
| 337 | msg.setText("The file "+fi.fileName()+" has been removed or renamed outside MiniZinc IDE."); |
| 338 | msg.setStandardButtons(QMessageBox::Ok); |
| 339 | } else { |
| 340 | msg.setText("The file "+fi.fileName()+" has been modified outside MiniZinc IDE."); |
| 341 | |
| 342 | bool isModified = it.value()->td.isModified(); |
| 343 | if (!isModified) { |
| 344 | QFile newFile(fi.absoluteFilePath()); |
| 345 | if (newFile.open(QFile::ReadOnly | QFile::Text)) { |
| 346 | QString newFileContents = newFile.readAll(); |
| 347 | isModified = (newFileContents != it.value()->td.toPlainText()); |
| 348 | } else { |
| 349 | isModified = true; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | if (isModified) { |
| 354 | if (it.value()->td.isModified()) { |
| 355 | msg.setInformativeText("Do you want to reload the file and discard your changes?"); |
| 356 | } else { |
| 357 | msg.setInformativeText("Do you want to reload the file?"); |
| 358 | } |
| 359 | QPushButton* cancelButton = msg.addButton(QMessageBox::Cancel); |
| 360 | msg.addButton("Reload", QMessageBox::AcceptRole); |
| 361 | msg.exec(); |
| 362 | if (msg.clickedButton()==cancelButton) { |
| 363 | it.value()->td.setModified(true); |
| 364 | } else { |
| 365 | QFile file(*s_it); |
| 366 | if (file.open(QFile::ReadOnly | QFile::Text)) { |
| 367 | QString contents = file.readAll(); |
| 368 | it.value()->td.setPlainText(contents); |
| 369 | it.value()->td.setModified(false); |
| 370 | emit reloadedFile(*s_it, contents); |
| 371 | } else { |
| 372 | QMessageBox::warning(nullptr, "MiniZinc IDE", |
| 373 | "Could not reload file "+*s_it, |
| 374 | QMessageBox::Ok); |
| 375 | it.value()->td.setModified(true); |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 |
nothing calls this directly
no test coverage detected