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

Method createEditor

MiniZincIDE/mainwindow.cpp:365–445  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

363}
364
365void 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 }

Callers

nothing calls this directly

Calls 13

loadFileMethod · 0.80
countMethod · 0.80
isModifiedMethod · 0.80
currentMethod · 0.80
showDebugInfoMethod · 0.80
setCurrentIndexMethod · 0.80
setModifiedMethod · 0.80
currentIndexMethod · 0.80
historyMethod · 0.80
updateFileContentsMethod · 0.80
addMethod · 0.80
registerEditorMethod · 0.80

Tested by

no test coverage detected