// Originally user templates were stored whereever the user wanted and maintained in the option "User/Templates". // This behavior has now been changed to always store user templates in [config]/templates/user/ The advantage is // that we don't have to maintain the template list and it's not lost when resetting the configuration. // This function allows to move existing templates to the the new location. void TemplateManager::checkForOldUserTemplates() { ConfigManagerInterface *cfg = ConfigManager::getInstance(); if (!cfg) return; QStringList userTemplateList = cfg->getOption("User/Templates").toStringList(); if (!userTemplateList.isEmpty()) { bool move = txsConfirmWarning(tr("TeXstudio found user templates in deprecated locations.\n" "From now on user templates are hosted at\n%1\n" "Should TeXstudio move the existing user templates there?\n" "If not, they will not be available via the Make Template dialog.").arg(userTemplateDir())); if (move) { foreach (const QString &fname, userTemplateList) { QFileInfo fi(fname); if (!fi.exists()) { userTemplateList.removeOne(fname); continue; } QString newName = userTemplateDir() + fi.fileName(); if (!QFile::copy(fname, newName)) { txsWarning(tr("Copying template from\n%1\nto\n%2\nfailed.").arg(fname).arg(newName)); } else { if (!QFile::remove(fname)) { txsInformation(tr("File\n%1\n could not be removed.").arg(fname)); } userTemplateList.removeOne(fname); } } }
void UpdateChecker::parseData(const QByteArray &data) { QDomDocument domDocument; if (domDocument.setContent(data)){ QDomElement root = domDocument.documentElement(); if (root.tagName() != "versions") { if (!silent) txsWarning(tr("Update check failed (invalid update file format).")); return; } QDomNodeList nodes = root.elementsByTagName("stable"); if (nodes.count() == 1) { QDomElement latestRelease = nodes.at(0).toElement(); m_latestVersion = latestRelease.attribute("value"); VersionCompareResult res = versionCompare(m_latestVersion, TXSVERSION); if (res == Invalid) { if (!silent) txsWarning(tr("Update check failed (invalid update file format).")); return; } if (res == Higher) { QString text = QString(tr( "A new version of TeXstudio is available.<br><br>" "Current version: %1<br>" "Latest version: %2<br><br>" "You can download it from the <a href='%3'>TeXstudio website</a>." )).arg(TXSVERSION).arg(m_latestVersion).arg("http://texstudio.sourceforge.net"); QMessageBox msgBox; msgBox.setWindowTitle(tr("TeXstudio Update")); msgBox.setTextFormat(Qt::RichText); msgBox.setText(text); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.exec(); } else { if (!silent) txsInformation(tr("TeXstudio is up-to-date.")); } ConfigManager::getInstance()->setOption("Update/LastCheck", QDateTime::currentDateTime()); emit checkCompleted(); } } }
void ScriptObject::warning(const QString& message){ txsWarning(message); }
void diffDocs(LatexDocument *doc,LatexDocument *doc2,bool dontAddLines){ QString text=doc->text(); QString text2=doc2->text(); diff_match_patch dmp; QString error; QList<Diff> diffList; try{ diffList= dmp.diff_main(text, text2,true); dmp.diff_cleanupSemantic(diffList); } catch (const char* c) { if (c) error = QString(c); } catch (char* c) { if (c) error = QString(c); } catch (const QString& s) { error = s; } catch (...) { error = LatexDocument::tr("Unknown error. Potential crash. You are advised to restart TeXstudio");} if (!error.isEmpty()) { txsWarning("Diff: "+error); return; } int lineNr=0; int lineNr2=0; int col=0; for(int i=0;i<diffList.size();++i){ const Diff elem=diffList.at(i); if(elem.operation==EQUAL){ lineNr+=elem.text.count("\n"); lineNr2+=elem.text.count("\n"); if(elem.text.count("\n")>0) col=0; col+=elem.text.length(); if(elem.text.lastIndexOf("\n")>=0) col-=elem.text.lastIndexOf("\n")+1; } if(elem.operation==DELETE){ QStringList splitList=elem.text.split("\n"); QStringList splitListInsert; if(splitList.isEmpty()) continue; QString lineDelete=splitList.takeFirst(); int diff=lineDelete.length(); bool toBeReplaced=false; if(i+1<diffList.size() && diffList[i+1].operation==INSERT){ splitListInsert=diffList[i+1].text.split("\n"); } if( splitListInsert.size()>0 && (splitList.size()>1 || splitListInsert.size()>1) ){ toBeReplaced=true; } QVariant var=doc->line(lineNr).getCookie(QDocumentLine::DIFF_LIST_COOCKIE); DiffList lineData; bool lineModified; if(var.isValid()){ lineData=var.value<DiffList>(); if(lineData.isEmpty()) lineModified=doc->isLineModified(doc->line(lineNr)); else lineModified=lineData.first().lineWasModified; } else { lineModified=doc->isLineModified(doc->line(lineNr)); } //doc->line(lineNr).addOverlay(QFormatRange(col,diff,fid)); DiffOp diffOperation; diffOperation.start=col; diffOperation.length=diff; diffOperation.lineWasModified=lineModified; if(toBeReplaced){ diffOperation.type=DiffOp::Replace; diffOperation.text=splitListInsert.takeFirst(); diffOperation.dlh=doc2->line(lineNr2).handle(); //qDebug()<<doc->line(lineNr).text()<<" <-> "<< diffOperation.dlh->text(); if(splitList.isEmpty()){ diffOperation.text+="\n"+splitListInsert.join("\n"); lineNr2+=splitListInsert.size(); } } else { diffOperation.type=DiffOp::Delete; } lineData.append(diffOperation); doc->line(lineNr).setCookie(QDocumentLine::DIFF_LIST_COOCKIE,QVariant::fromValue<DiffList>(lineData)); col+=diff; int sz=splitList.size(); for(int j=0;j<sz;j++){ col=0; QString ln=splitList.takeFirst(); DiffOp diffOperation; diffOperation.start=col; diffOperation.length=ln.length(); if(toBeReplaced){ lineNr2++; diffOperation.type=DiffOp::Replace; if(splitListInsert.isEmpty()){ diffOperation.text=""; }else{ diffOperation.text=splitListInsert.takeFirst(); diffOperation.dlh=doc2->line(lineNr2).handle(); //qDebug()<<doc->line(lineNr+j+1).text()<<" <-> "<< diffOperation.dlh->text(); if(splitList.isEmpty() && !splitListInsert.isEmpty()){ diffOperation.text+="\n"+splitListInsert.join("\n"); lineNr2+=splitListInsert.size(); } } } else { diffOperation.type=DiffOp::Delete; } var=doc->line(lineNr+j+1).getCookie(QDocumentLine::DIFF_LIST_COOCKIE); DiffList lineData; if(var.isValid()){ lineData=var.value<DiffList>(); if(lineData.isEmpty()) lineModified=doc->isLineModified(doc->line(lineNr+j+1)); else lineModified=lineData.first().lineWasModified; } else { lineModified=doc->isLineModified(doc->line(lineNr+j+1)); } diffOperation.lineWasModified=lineModified; lineData.append(diffOperation); doc->line(lineNr+j+1).setCookie(QDocumentLine::DIFF_LIST_COOCKIE,QVariant::fromValue<DiffList>(lineData)); col=ln.length(); } lineNr+=elem.text.count("\n"); if(toBeReplaced) i++; } if(elem.operation==INSERT){ QStringList splitList=elem.text.split("\n"); if(splitList.isEmpty()) continue; QDocumentCursor cur(doc); if(lineNr+1>doc->lines()){ if(dontAddLines) continue; cur.moveTo(lineNr-1,0); cur.movePosition(1,QDocumentCursor::EndOfLine); cur.insertText("\n"); }else{ cur.moveTo(lineNr,col); } int diff=splitList.first().length(); cur.insertText(splitList.first()); int lnNr=cur.lineNumber(); if(splitList.size()>1 &&!dontAddLines) cur.insertText("\n"); QVariant var=doc->line(lnNr).getCookie(QDocumentLine::DIFF_LIST_COOCKIE); DiffList lineData; bool lineModified; if(var.isValid()){ lineData=var.value<DiffList>(); if(lineData.isEmpty()) lineModified=doc->isLineModified(doc->line(lnNr)); else lineModified=lineData.first().lineWasModified; } else { lineModified=doc->isLineModified(doc->line(lnNr)); } DiffOp diffOperation; diffOperation.start=col; diffOperation.length=diff; diffOperation.type=DiffOp::Insert; diffOperation.text=""; diffOperation.lineWasModified=lineModified; diffOperation.dlh=doc2->line(lineNr2).handle(); //qDebug()<<doc->line(lnNr).text()<<" <-> "<< diffOperation.dlh->text(); lineData.append(diffOperation); doc->line(lnNr).setCookie(QDocumentLine::DIFF_LIST_COOCKIE,QVariant::fromValue<DiffList>(lineData)); //doc->line(lnNr).addOverlay(QFormatRange(col,diff,fid_Insert)); col+=diff; splitList.removeFirst(); if(dontAddLines) continue; for(int i=0;i<splitList.size();i++){ lineNr2++; QString ln=splitList.at(i); cur.insertText(ln); lnNr=cur.lineNumber(); if(i+1<splitList.size()) cur.insertText("\n"); QVariant var=doc->line(lnNr).getCookie(QDocumentLine::DIFF_LIST_COOCKIE); DiffList lineData; if(var.isValid()){ lineData=var.value<DiffList>(); if(lineData.isEmpty()) lineModified=doc->isLineModified(doc->line(lnNr)); else lineModified=lineData.first().lineWasModified; } else { lineModified=doc->isLineModified(doc->line(lnNr)); } DiffOp diffOperation; diffOperation.start=0; diffOperation.length=ln.length(); diffOperation.type=DiffOp::Insert; diffOperation.text=""; diffOperation.lineWasModified=lineModified; diffOperation.dlh=doc2->line(lineNr2).handle(); //qDebug()<<doc->line(lnNr).text()<<" <-> "<< diffOperation.dlh->text(); lineData.append(diffOperation); doc->line(lnNr).setCookie(QDocumentLine::DIFF_LIST_COOCKIE,QVariant::fromValue<DiffList>(lineData)); //doc->line(lnNr).addOverlay(QFormatRange(0,ln.length(),fid_Insert)); col=ln.length(); } lineNr+=elem.text.count("\n"); } } doc->mayHaveDiffMarkers = true; }