| 363 | } |
| 364 | |
| 365 | void MainWindow::createEditor(const QString& path, bool openAsModified, bool isNewFile, bool readOnly, bool focus) { |
| 366 | QTextDocument* doc = nullptr; |
| 367 | bool large = false; |
| 368 | QString fileContents; |
| 369 | QString absPath = QFileInfo(path).canonicalFilePath(); |
| 370 | if (isNewFile && path == "Playground") { |
| 371 | absPath = path; |
| 372 | fileContents = "% Use this editor as a MiniZinc scratch book\n"; |
| 373 | openAsModified = false; |
| 374 | } else if (isNewFile && path.startsWith(".")) { |
| 375 | absPath = QString("Untitled")+QString().setNum(newFileCounter++)+path; |
| 376 | } else if (path.isEmpty()) { |
| 377 | absPath = path; |
| 378 | // Do nothing |
| 379 | } else if (openAsModified) { |
| 380 | QFile file(path); |
| 381 | if (file.open(QFile::ReadOnly)) { |
| 382 | fileContents = file.readAll(); |
| 383 | } else { |
| 384 | QMessageBox::warning(this,"MiniZinc IDE", |
| 385 | "Could not open file "+path, |
| 386 | QMessageBox::Ok); |
| 387 | return; |
| 388 | } |
| 389 | if (isNewFile) { |
| 390 | absPath = QFileInfo(path).fileName(); |
| 391 | } |
| 392 | } else { |
| 393 | if (absPath.isEmpty()) { |
| 394 | QMessageBox::warning(this,"MiniZinc IDE", |
| 395 | "Could not open file "+path, |
| 396 | QMessageBox::Ok); |
| 397 | return; |
| 398 | } |
| 399 | QPair<QTextDocument*,bool> d = IDE::instance()->loadFile(absPath,this); |
| 400 | updateRecentFiles(absPath); |
| 401 | doc = d.first; |
| 402 | large = d.second; |
| 403 | } |
| 404 | if (doc || !fileContents.isEmpty() || isNewFile) { |
| 405 | int closeTab = -1; |
| 406 | if (!isNewFile && ui->tabWidget->count()==1) { |
| 407 | CodeEditor* ce = qobject_cast<CodeEditor*>(ui->tabWidget->widget(0)); |
| 408 | if (ce && ce->filepath == "" && !ce->document()->isModified()) { |
| 409 | closeTab = 0; |
| 410 | } |
| 411 | } |
| 412 | auto& theme = IDE::instance()->themeManager->current(); |
| 413 | CodeEditor* ce = new CodeEditor(doc,absPath,isNewFile,large,editorFont,indentSize,useTabs,theme,darkMode,ui->tabWidget,this); |
| 414 | if (readOnly || ce->filename == "_coursera" || ce->filename.endsWith(".mzc")) |
| 415 | ce->setReadOnly(true); |
| 416 | int tab = ui->tabWidget->addTab(ce, ce->filename); |
| 417 | if(profileInfoVisible) |
| 418 | ce->showDebugInfo(profileInfoVisible); |
| 419 | if (focus) { |
| 420 | ui->tabWidget->setCurrentIndex(tab); |
| 421 | curEditor->setFocus(); |
| 422 | } |
nothing calls this directly
no test coverage detected