MCPcopy Create free account
hub / github.com/MiniZinc/MiniZincIDE / fileModifiedTimeout

Method fileModifiedTimeout

MiniZincIDE/ide.cpp:326–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

324}
325
326void 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

Callers

nothing calls this directly

Calls 7

findMethod · 0.80
isModifiedMethod · 0.80
setModifiedMethod · 0.80
clearMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected