diff --git a/src/latexdocument.cpp b/src/latexdocument.cpp index e3125dde6..a8d8f7a7a 100644 --- a/src/latexdocument.cpp +++ b/src/latexdocument.cpp @@ -3001,6 +3001,12 @@ void LatexDocument::gatherCompletionFiles(QStringList &files, QStringList &loade found=!zw.containsOptionalSections; } if(!found){ + if(fileName.startsWith(".")){ + // replace relative path with absolute with repsit to root document + QFileInfo fi=getRootDocument()->getFileInfo(); + QFileInfo fi_cwl=QFileInfo(fi.absolutePath(),fileName); + fileName=fi_cwl.absoluteFilePath(); + } zw = loadCwlFile(fileName, completerConfig, options); if (!zw.notFound) { fileName= zw.containsOptionalSections ? elem : fileName; diff --git a/src/latexeditorview.cpp b/src/latexeditorview.cpp index c81558364..d093f6020 100644 --- a/src/latexeditorview.cpp +++ b/src/latexeditorview.cpp @@ -1646,9 +1646,19 @@ void LatexEditorView::updatePackageFormats() const QString rpck = trimLeft(curLineText.mid(tk.start, tk.length)); // left spaces are ignored by \cite, right space not const QString suffix = tk.type == Token::documentclass ? ".cls" : ".sty"; //check and highlight + bool localPackage = false; + if(rpck.startsWith(".")){ + // check if file exists + LatexDocument *root=document->getRootDocument(); + QFileInfo fi=root->getFileInfo(); + QFileInfo fi_cwl=QFileInfo(fi.absolutePath(),rpck+suffix); + localPackage=fi_cwl.exists(); + } if (latexPackageList->empty()) dlh->addOverlay(QFormatRange(tk.start, tk.length, packageUndefinedFormat)); - else if ( (latexPackageList->find(preambel + rpck + suffix) != latexPackageList->end()) || (latexPackageList->find(preambel + rpck) != latexPackageList->end())) { + else if ( (latexPackageList->find(preambel + rpck + suffix) != latexPackageList->end()) + || (latexPackageList->find(preambel + rpck) != latexPackageList->end()) + || localPackage) { dlh->addOverlay(QFormatRange(tk.start, tk.length, packagePresentFormat)); } else { dlh->addOverlay(QFormatRange(tk.start, tk.length, packageMissingFormat)); @@ -2211,9 +2221,19 @@ void LatexEditorView::documentContentChanged(int linenr, int count) const QString rpck = trimLeft(text.mid(tk.start, tk.length)); // left spaces are ignored by \cite, right space not const QString suffix = tk.type == Token::documentclass ? ".cls" : ".sty"; //check and highlight + bool localPackage = false; + if(rpck.startsWith(".")){ + // check if file exists + LatexDocument *root=document->getRootDocument(); + QFileInfo fi=root->getFileInfo(); + QFileInfo fi_cwl=QFileInfo(fi.absolutePath(),rpck+suffix); + localPackage=fi_cwl.exists(); + } if (latexPackageList->empty()) dlh->addOverlay(QFormatRange(tk.start, tk.length, packageUndefinedFormat)); - else if ( (latexPackageList->find(preambel + rpck + suffix) != latexPackageList->end()) || (latexPackageList->find(preambel + rpck) != latexPackageList->end())) { + else if ( (latexPackageList->find(preambel + rpck + suffix) != latexPackageList->end()) + || (latexPackageList->find(preambel + rpck) != latexPackageList->end()) + || localPackage) { dlh->addOverlay(QFormatRange(tk.start, tk.length, packagePresentFormat)); } else { dlh->addOverlay(QFormatRange(tk.start, tk.length, packageMissingFormat)); @@ -2718,7 +2738,9 @@ void LatexEditorView::mouseHovered(QPoint pos) } QString text = QString("%1: %2").arg(type,value); const QString suffix = tk.type == Token::documentclass ? ".cls" : ".sty"; - if (latexPackageList->find(preambel + value + suffix) != latexPackageList->end() || latexPackageList->find(preambel + value) != latexPackageList->end()) { + if (latexPackageList->find(preambel + value + suffix) != latexPackageList->end() + || latexPackageList->find(preambel + value) != latexPackageList->end() + || value.startsWith(".")) { // don't check relative paths,i.e. local packages QString description = LatexRepository::instance()->shortDescription(value); if (!description.isEmpty()) text += "
" + description; QToolTip::showText(editor->mapToGlobal(editor->mapFromFrame(pos)), text); diff --git a/src/latexpackage.cpp b/src/latexpackage.cpp index 9dd93b9ea..53e84a0c6 100644 --- a/src/latexpackage.cpp +++ b/src/latexpackage.cpp @@ -91,6 +91,9 @@ LatexPackage loadCwlFile(const QString fileName, LatexCompleterConfig *config, Q LatexPackage package; QFile tagsfile("cwl:" + fileName); + if(QFileInfo(fileName).isAbsolute() && !tagsfile.exists()){ + tagsfile.setFileName(fileName); + } bool skipSection = false; if (tagsfile.exists() && tagsfile.open(QFile::ReadOnly)) { QString line;