diff --git a/kdevplatform/debugger/util/treeview.cpp b/kdevplatform/debugger/util/treeview.cpp index d2bd861e75..a451ab49fd 100644 --- a/kdevplatform/debugger/util/treeview.cpp +++ b/kdevplatform/debugger/util/treeview.cpp @@ -1,87 +1,88 @@ /* * This file is part of KDevelop * * Copyright 2008 Vladimir Prus * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "treeview.h" + +#include "treemodel.h" + #include #include #include -#include "treeview.h" -#include "treemodel.h" - using namespace KDevelop; AsyncTreeView::AsyncTreeView(TreeModel* model, QSortFilterProxyModel *proxy, QWidget *parent = nullptr) : QTreeView(parent) , m_proxy(proxy) { connect (this, &AsyncTreeView::expanded, this, &AsyncTreeView::slotExpanded); connect (this, &AsyncTreeView::collapsed, this, &AsyncTreeView::slotCollapsed); connect (this, &AsyncTreeView::clicked, this, &AsyncTreeView::slotClicked); connect (model, &TreeModel::itemChildrenReady, this, &AsyncTreeView::slotExpandedDataReady); } void AsyncTreeView::slotExpanded(const QModelIndex &index) { static_cast(model())->expanded(m_proxy->mapToSource(index)); } void AsyncTreeView::slotCollapsed(const QModelIndex &index) { static_cast(model())->collapsed(m_proxy->mapToSource(index)); resizeColumns(); } void AsyncTreeView::slotClicked(const QModelIndex &index) { static_cast(model())->clicked(m_proxy->mapToSource(index)); resizeColumns(); } QSize AsyncTreeView::sizeHint() const { //Assuming that columns are awlays resized to fit their contents, return a size that will fit all without a scrollbar QMargins margins = contentsMargins(); int horizontalSize = margins.left() + margins.right(); for (int i = 0; i < model()->columnCount(); ++i) { horizontalSize += columnWidth(i); } horizontalSize = qMin(horizontalSize, QApplication::desktop()->screenGeometry().width()*3/4); return QSize(horizontalSize, margins.top() + margins.bottom() + sizeHintForRow(0)); } void AsyncTreeView::resizeColumns() { for (int i = 0; i < model()->columnCount(); ++i) { this->resizeColumnToContents(i); } this->updateGeometry(); } void AsyncTreeView::slotExpandedDataReady() { resizeColumns(); } diff --git a/kdevplatform/language/codegen/templateengine.cpp b/kdevplatform/language/codegen/templateengine.cpp index e70b6b5c89..83bcb65c16 100644 --- a/kdevplatform/language/codegen/templateengine.cpp +++ b/kdevplatform/language/codegen/templateengine.cpp @@ -1,77 +1,77 @@ /* * This file is part of KDevelop * * Copyright 2012 Milian Wolff * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "templateengine.h" +#include "templateengine_p.h" #include "debug.h" -#include "templateengine_p.h" #include "codedescription.h" #include "codedescriptionmetatypes.h" #include "archivetemplateloader.h" #include #include using namespace KDevelop; using namespace Grantlee; TemplateEngine* TemplateEngine::self() { static TemplateEngine* engine = new TemplateEngine; return engine; } TemplateEngine::TemplateEngine() : d(new TemplateEnginePrivate) { d->engine.setSmartTrimEnabled(true); qCDebug(LANGUAGE) << "Generic data locations:" << QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); const auto templateDirectories = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kdevcodegen/templates"), QStandardPaths::LocateDirectory); if (!templateDirectories.isEmpty()) { qCDebug(LANGUAGE) << "Found template directories:" << templateDirectories; addTemplateDirectories(QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kdevcodegen/templates"), QStandardPaths::LocateDirectory)); } else { qCWarning(LANGUAGE) << "No template directories found -- templating engine will not work!"; } Grantlee::registerMetaType(); Grantlee::registerMetaType(); Grantlee::registerMetaType(); Grantlee::registerMetaType(); d->engine.addTemplateLoader(QSharedPointer(ArchiveTemplateLoader::self())); } TemplateEngine::~TemplateEngine() { } void TemplateEngine::addTemplateDirectories(const QStringList& directories) { FileSystemTemplateLoader* loader = new FileSystemTemplateLoader; loader->setTemplateDirs(directories); d->engine.addTemplateLoader(QSharedPointer(loader)); } diff --git a/kdevplatform/language/duchain/definitions.cpp b/kdevplatform/language/duchain/definitions.cpp index 9bc186bea1..69a00591e5 100644 --- a/kdevplatform/language/duchain/definitions.cpp +++ b/kdevplatform/language/duchain/definitions.cpp @@ -1,224 +1,225 @@ /* This file is part of KDevelop Copyright 2008 David Nolden Copyright 2014 Kevin Funk This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "appendedlist.h" #include "definitions.h" + +#include "appendedlist.h" #include "declaration.h" #include "declarationid.h" #include "duchainpointer.h" #include #include "serialization/itemrepository.h" namespace KDevelop { DEFINE_LIST_MEMBER_HASH(DefinitionsItem, definitions, IndexedDeclaration) class DefinitionsItem { public: DefinitionsItem() { initializeAppendedLists(); } DefinitionsItem(const DefinitionsItem& rhs, bool dynamic = true) : declaration(rhs.declaration) { initializeAppendedLists(dynamic); copyListsFrom(rhs); } ~DefinitionsItem() { freeAppendedLists(); } unsigned int hash() const { //We only compare the declaration. This allows us implementing a map, although the item-repository //originally represents a set. return declaration.hash(); } unsigned int itemSize() const { return dynamicSize(); } uint classSize() const { return sizeof(DefinitionsItem); } DeclarationId declaration; START_APPENDED_LISTS(DefinitionsItem); APPENDED_LIST_FIRST(DefinitionsItem, IndexedDeclaration, definitions); END_APPENDED_LISTS(DefinitionsItem, definitions); }; class DefinitionsRequestItem { public: DefinitionsRequestItem(const DefinitionsItem& item) : m_item(item) { } enum { AverageSize = 30 //This should be the approximate average size of an Item }; unsigned int hash() const { return m_item.hash(); } uint itemSize() const { return m_item.itemSize(); } void createItem(DefinitionsItem* item) const { new (item) DefinitionsItem(m_item, false); } static void destroy(DefinitionsItem* item, KDevelop::AbstractItemRepository&) { item->~DefinitionsItem(); } static bool persistent(const DefinitionsItem*) { return true; } bool equals(const DefinitionsItem* item) const { return m_item.declaration == item->declaration; } const DefinitionsItem& m_item; }; class DefinitionsVisitor { public: DefinitionsVisitor(Definitions* _definitions, const QTextStream& _out) : definitions(_definitions) , out(_out) { } bool operator()(const DefinitionsItem* item) { QDebug qout(out.device()); auto id = item->declaration; const auto allDefinitions = definitions->definitions(id); qout << "Definitions for" << id.qualifiedIdentifier() << endl; for (const IndexedDeclaration& decl : allDefinitions) { if(decl.data()) { qout << " " << decl.data()->qualifiedIdentifier() << "in" << decl.data()->url().byteArray() << "at" << decl.data()->rangeInCurrentRevision() << endl; } } return true; } private: const Definitions* definitions; const QTextStream& out; }; class DefinitionsPrivate { public: DefinitionsPrivate() : m_definitions(QStringLiteral("Definition Map")) { } //Maps declaration-ids to definitions ItemRepository m_definitions; }; Definitions::Definitions() : d(new DefinitionsPrivate()) { } Definitions::~Definitions() = default; void Definitions::addDefinition(const DeclarationId& id, const IndexedDeclaration& definition) { DefinitionsItem item; item.declaration = id; item.definitionsList().append(definition); DefinitionsRequestItem request(item); uint index = d->m_definitions.findIndex(item); if(index) { //Check whether the item is already in the mapped list, else copy the list into the new created item const DefinitionsItem* oldItem = d->m_definitions.itemFromIndex(index); for(unsigned int a = 0; a < oldItem->definitionsSize(); ++a) { if(oldItem->definitions()[a] == definition) return; //Already there item.definitionsList().append(oldItem->definitions()[a]); } d->m_definitions.deleteItem(index); } //This inserts the changed item d->m_definitions.index(request); } void Definitions::removeDefinition(const DeclarationId& id, const IndexedDeclaration& definition) { DefinitionsItem item; item.declaration = id; DefinitionsRequestItem request(item); uint index = d->m_definitions.findIndex(item); if(index) { //Check whether the item is already in the mapped list, else copy the list into the new created item const DefinitionsItem* oldItem = d->m_definitions.itemFromIndex(index); for(unsigned int a = 0; a < oldItem->definitionsSize(); ++a) if(!(oldItem->definitions()[a] == definition)) item.definitionsList().append(oldItem->definitions()[a]); d->m_definitions.deleteItem(index); Q_ASSERT(d->m_definitions.findIndex(item) == 0); //This inserts the changed item if(item.definitionsSize() != 0) d->m_definitions.index(request); } } KDevVarLengthArray Definitions::definitions(const DeclarationId& id) const { KDevVarLengthArray ret; DefinitionsItem item; item.declaration = id; DefinitionsRequestItem request(item); uint index = d->m_definitions.findIndex(item); if(index) { const DefinitionsItem* repositoryItem = d->m_definitions.itemFromIndex(index); FOREACH_FUNCTION(const IndexedDeclaration& decl, repositoryItem->definitions) ret.append(decl); } return ret; } void Definitions::dump(const QTextStream& out) { QMutexLocker lock(d->m_definitions.mutex()); DefinitionsVisitor v(this, out); d->m_definitions.visitAllItems(v); } } diff --git a/kdevplatform/project/helper.cpp b/kdevplatform/project/helper.cpp index 4bc71b53d8..98c458e28b 100644 --- a/kdevplatform/project/helper.cpp +++ b/kdevplatform/project/helper.cpp @@ -1,234 +1,235 @@ /* This file is part of KDevelop Copyright 2010 Milian Wolff This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "debug.h" #include "helper.h" + +#include "debug.h" #include "path.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace KDevelop; bool KDevelop::removeUrl(const KDevelop::IProject* project, const QUrl& url, const bool isFolder) { qCDebug(PROJECT) << "Removing url:" << url << "from project" << project; QWidget* window = QApplication::activeWindow(); auto job = KIO::stat(url, KIO::StatJob::DestinationSide, 0); KJobWidgets::setWindow(job, window); if (!job->exec()) { qCWarning(PROJECT) << "tried to remove non-existing url:" << url << project << isFolder; return true; } IPlugin* vcsplugin=project->versionControlPlugin(); if(vcsplugin) { IBasicVersionControl* vcs=vcsplugin->extension(); // We have a vcs and the file/folder is controller, need to make the rename through vcs if(vcs->isVersionControlled(url)) { VcsJob* job=vcs->remove(QList() << url); if(job) { return job->exec(); } } } //if we didn't find a VCS, we remove using KIO (if the file still exists, the vcs plugin might have simply deleted the url without returning a job auto deleteJob = KIO::del(url); KJobWidgets::setWindow(deleteJob, window); if (!deleteJob->exec() && url.isLocalFile() && (QFileInfo::exists(url.toLocalFile()))) { KMessageBox::error( window, isFolder ? i18n( "Cannot remove folder %1.", url.toDisplayString(QUrl::PreferLocalFile) ) : i18n( "Cannot remove file %1.", url.toDisplayString(QUrl::PreferLocalFile) ) ); return false; } return true; } bool KDevelop::removePath(const KDevelop::IProject* project, const KDevelop::Path& path, const bool isFolder) { return removeUrl(project, path.toUrl(), isFolder); } bool KDevelop::createFile(const QUrl& file) { auto statJob = KIO::stat(file, KIO::StatJob::DestinationSide, 0); KJobWidgets::setWindow(statJob, QApplication::activeWindow()); if (statJob->exec()) { KMessageBox::error( QApplication::activeWindow(), i18n( "The file %1 already exists.", file.toDisplayString(QUrl::PreferLocalFile) ) ); return false; } { auto uploadJob = KIO::storedPut(QByteArray("\n"), file, -1); KJobWidgets::setWindow(uploadJob, QApplication::activeWindow()); if (!uploadJob->exec()) { KMessageBox::error( QApplication::activeWindow(), i18n( "Cannot create file %1.", file.toDisplayString(QUrl::PreferLocalFile) ) ); return false; } } return true; } bool KDevelop::createFile(const KDevelop::Path& file) { return createFile(file.toUrl()); } bool KDevelop::createFolder(const QUrl& folder) { auto mkdirJob = KIO::mkdir(folder); KJobWidgets::setWindow(mkdirJob, QApplication::activeWindow()); if (!mkdirJob->exec()) { KMessageBox::error( QApplication::activeWindow(), i18n( "Cannot create folder %1.", folder.toDisplayString(QUrl::PreferLocalFile) ) ); return false; } return true; } bool KDevelop::createFolder(const KDevelop::Path& folder) { return createFolder(folder.toUrl()); } bool KDevelop::renameUrl(const KDevelop::IProject* project, const QUrl& oldname, const QUrl& newname) { bool wasVcsMoved = false; IPlugin* vcsplugin = project->versionControlPlugin(); if (vcsplugin) { IBasicVersionControl* vcs = vcsplugin->extension(); // We have a vcs and the file/folder is controller, need to make the rename through vcs if (vcs->isVersionControlled(oldname)) { VcsJob* job = vcs->move(oldname, newname); if (job && !job->exec()) { return false; } wasVcsMoved = true; } } // Fallback for the case of no vcs, or not-vcs-managed file/folder // try to save-as the text document, so users can directly continue to work // on the renamed url as well as keeping the undo-stack intact IDocument* document = ICore::self()->documentController()->documentForUrl(oldname); if (document && document->textDocument()) { if (!document->textDocument()->saveAs(newname)) { return false; } if (!wasVcsMoved) { // unlink the old file removeUrl(project, oldname, false); } return true; } else if (!wasVcsMoved) { // fallback for non-textdocuments (also folders e.g.) KIO::CopyJob* job = KIO::move(oldname, newname); KJobWidgets::setWindow(job, QApplication::activeWindow()); bool success = job->exec(); if (success) { // save files that where opened in this folder under the new name Path oldBasePath(oldname); Path newBasePath(newname); foreach (auto doc, ICore::self()->documentController()->openDocuments()) { auto textDoc = doc->textDocument(); if (textDoc && oldname.isParentOf(doc->url())) { const auto path = Path(textDoc->url()); const auto relativePath = oldBasePath.relativePath(path); const auto newPath = Path(newBasePath, relativePath); textDoc->saveAs(newPath.toUrl()); } } } return success; } else { return true; } } bool KDevelop::renamePath(const KDevelop::IProject* project, const KDevelop::Path& oldName, const KDevelop::Path& newName) { return renameUrl(project, oldName.toUrl(), newName.toUrl()); } bool KDevelop::copyUrl(const KDevelop::IProject* project, const QUrl& source, const QUrl& target) { IPlugin* vcsplugin=project->versionControlPlugin(); if(vcsplugin) { IBasicVersionControl* vcs=vcsplugin->extension(); // We have a vcs and the file/folder is controller, need to make the rename through vcs if(vcs->isVersionControlled(source)) { VcsJob* job=vcs->copy(source, target); if(job) { return job->exec(); } } } // Fallback for the case of no vcs, or not-vcs-managed file/folder auto job = KIO::copy(source, target); KJobWidgets::setWindow(job, QApplication::activeWindow()); return job->exec(); } bool KDevelop::copyPath(const KDevelop::IProject* project, const KDevelop::Path& source, const KDevelop::Path& target) { return copyUrl(project, source.toUrl(), target.toUrl()); } Path KDevelop::proposedBuildFolder(const Path& sourceFolder) { Path proposedBuildFolder; if (sourceFolder.path().contains(QStringLiteral("/src/"))) { const QString srcBuildPath = sourceFolder.path().replace(QStringLiteral("/src/"), QStringLiteral("/build/")); Q_ASSERT(!srcBuildPath.isEmpty()); if (QDir(srcBuildPath).exists()) { proposedBuildFolder = Path(srcBuildPath); } } if (!proposedBuildFolder.isValid()) { proposedBuildFolder = Path(sourceFolder, QStringLiteral("build")); } return proposedBuildFolder; } diff --git a/kdevplatform/tests/json/declarationvalidator.cpp b/kdevplatform/tests/json/declarationvalidator.cpp index 8908789f65..162bcbce09 100644 --- a/kdevplatform/tests/json/declarationvalidator.cpp +++ b/kdevplatform/tests/json/declarationvalidator.cpp @@ -1,87 +1,89 @@ /* This file is part of KDevelop Copyright 2012 Olivier de Gaalon This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "language/duchain/declaration.h" + #include "declarationvalidator.h" + +#include "language/duchain/declaration.h" #include "testsuite.h" #include "jsondeclarationtests.h" #include namespace KDevelop { class DeclarationValidatorPrivate { public: DeclarationValidatorPrivate() : testsPassed(true) {} bool testsPassed; }; QByteArray preprocess(QByteArray json) { int commentIndex = json.indexOf('#', 0); while (commentIndex > -1) { int commentEnd = json.indexOf('\n', commentIndex); if (commentEnd == -1) { json.truncate(commentIndex); break; } json.remove(commentIndex, commentEnd - commentIndex); commentIndex = json.indexOf('#', commentIndex); } return '{' + json + '}'; } DeclarationValidator::DeclarationValidator() : d(new DeclarationValidatorPrivate) { } DeclarationValidator::~DeclarationValidator() { } bool DeclarationValidator::testsPassed() { return d->testsPassed; } void DeclarationValidator::visit(DUContext*) { } void DeclarationValidator::visit(Declaration* declaration) { QJsonParseError error; const auto json = preprocess(declaration->comment()); QJsonDocument doc = QJsonDocument::fromJson(json, &error); if (error.error == 0) { QVariantMap testData = doc.toVariant().toMap(); if (!KDevelop::runTests(testData, declaration)) d->testsPassed = false; } else { d->testsPassed = false; QMessageLogger logger(declaration->topContext()->url().byteArray().constData(), declaration->range().start.line, nullptr); logger.warning() << "Error parsing JSON test data:" << error.errorString() << "at offset" << error.offset << "JSON input was:\n" << json; } } } diff --git a/kdevplatform/util/texteditorhelpers.cpp b/kdevplatform/util/texteditorhelpers.cpp index 3304ca0033..02c0530dbd 100644 --- a/kdevplatform/util/texteditorhelpers.cpp +++ b/kdevplatform/util/texteditorhelpers.cpp @@ -1,83 +1,83 @@ /* This file is part of the KDE project Copyright 2015 Maciej Cencora This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include - #include "texteditorhelpers.h" #include #include +#include + namespace KDevelop { namespace { // TODO: this is a hack, but Kate does not provide interface for this int lineHeight(const KTextEditor::View* view, int curLine) { KTextEditor::Cursor c(curLine, 0); int currentHeight = view->cursorToCoordinate(c).y(); c.setLine(curLine + 1); if (view->cursorToCoordinate(c).y() < 0) { c.setLine(curLine - 1); } return std::abs(view->cursorToCoordinate(c).y() - currentHeight); } } QRect KTextEditorHelpers::getItemBoundingRect(const KTextEditor::View* view, const KTextEditor::Range& itemRange) { QPoint startPoint = view->mapToGlobal(view->cursorToCoordinate(itemRange.start())); QPoint endPoint = view->mapToGlobal(view->cursorToCoordinate(itemRange.end())); endPoint.ry() += lineHeight(view, itemRange.start().line()); return QRect(startPoint, endPoint); } KTextEditor::Cursor KTextEditorHelpers::extractCursor(const QString& input, int* pathLength) { // ":ll:cc", ":ll" static const QRegularExpression pattern(QStringLiteral(":(\\d+)(?::(\\d+))?$")); // "#Lll", "#nll", "#ll" as e.g. seen with repo web links static const QRegularExpression pattern2(QStringLiteral("#(?:n|L|)(\\d+)$")); auto match = pattern.match(input); if (!match.hasMatch()) { match = pattern2.match(input); } if (!match.hasMatch()) { if (pathLength) *pathLength = input.length(); return KTextEditor::Cursor::invalid(); } int line = match.capturedRef(1).toInt() - 1; // captured(2) for pattern2 will yield null QString, toInt() thus 0, so no need for if-else // don't use an invalid column when the line is valid int column = qMax(0, match.captured(2).toInt() - 1); if (pathLength) *pathLength = match.capturedStart(0); return {line, column}; } } diff --git a/plugins/cmake/cmakeextraargumentshistory.cpp b/plugins/cmake/cmakeextraargumentshistory.cpp index 14f5e87b15..344c57ff0a 100644 --- a/plugins/cmake/cmakeextraargumentshistory.cpp +++ b/plugins/cmake/cmakeextraargumentshistory.cpp @@ -1,70 +1,70 @@ /* KDevelop CMake Support * * Copyright 2016 René J.V. Bertin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ +#include "cmakeextraargumentshistory.h" + #include #include -#include "cmakeextraargumentshistory.h" - namespace { const int maxExtraArgumentsInHistory = 15; } CMakeExtraArgumentsHistory::CMakeExtraArgumentsHistory(KComboBox* widget) : m_arguments(widget) { if (m_arguments) { KConfigGroup config = KSharedConfig::openConfig()->group("CMakeBuildDirChooser"); QStringList lastExtraArguments = config.readEntry("LastExtraArguments", QStringList()); m_arguments->addItem(QString()); m_arguments->addItems(lastExtraArguments); m_arguments->setInsertPolicy(QComboBox::InsertAtTop); KCompletion *comp = m_arguments->completionObject(); KComboBox::connect(m_arguments, static_cast(&KComboBox::returnPressed), comp, static_cast(&KCompletion::addItem)); comp->insertItems(lastExtraArguments); } else { qFatal("CMakeExtraArgumentsHistory initialised with invalid widget"); } } CMakeExtraArgumentsHistory::~CMakeExtraArgumentsHistory() { KConfigGroup config = KSharedConfig::openConfig()->group("CMakeBuildDirChooser"); config.writeEntry("LastExtraArguments", list()); config.sync(); } QStringList CMakeExtraArgumentsHistory::list() const { QStringList list; if (!m_arguments->currentText().isEmpty()) { list << m_arguments->currentText(); } for (int i = 0; i < qMin(maxExtraArgumentsInHistory, m_arguments->count()); ++i) { if (!m_arguments->itemText(i).isEmpty() && (m_arguments->currentText() != m_arguments->itemText(i))) { list << m_arguments->itemText(i); } } return list; } diff --git a/plugins/cmake/tests/kdevprojectopen.cpp b/plugins/cmake/tests/kdevprojectopen.cpp index 991106dcc6..65f04d0978 100644 --- a/plugins/cmake/tests/kdevprojectopen.cpp +++ b/plugins/cmake/tests/kdevprojectopen.cpp @@ -1,94 +1,97 @@ /* This file is part of KDevelop Copyright 2013 Aleix Pol Gonzalez This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include -#include -#include +#include "kdevprojectopen.h" + #include #include #include -#include "kdevprojectopen.h" #include "testhelpers.h" + +#include +#include + +#include #include #include using namespace KDevelop; KDevProjectOpen::KDevProjectOpen(QObject* parent) : QObject(parent) { AutoTestShell::init(); TestCore::initialize(); cleanup(); connect(ICore::self()->projectController(), &IProjectController::projectOpened, this, &KDevProjectOpen::projectDone); } void KDevProjectOpen::cleanup() { foreach(IProject* p, ICore::self()->projectController()->projects()) { ICore::self()->projectController()->closeProject(p); } Q_ASSERT(ICore::self()->projectController()->projects().isEmpty()); } void KDevProjectOpen::openProject(const QUrl& path) { const TestProjectPaths paths = projectPaths(path.toLocalFile()); defaultConfigure(paths); m_toOpen++; ICore::self()->projectController()->openProject(paths.projectFile.toUrl()); } void KDevProjectOpen::projectDone(IProject* ) { m_toOpen--; if(m_toOpen==0) { cleanup(); qApp->exit(); } } int main(int argc, char** argv) { QApplication app(argc, argv); KAboutData aboutData( QStringLiteral("kdevprojectopen"), i18n( "KDevelop" ), QStringLiteral("0.99"), i18n("opens a project then closes it, debugging tool"), KAboutLicense::GPL, i18n( "Copyright 1999-2012, The KDevelop developers" ), QString(), QStringLiteral("http://www.kdevelop.org/") ); aboutData.addAuthor( i18n("Aleix Pol Gonzalez"), i18n( "" ), QStringLiteral("aleixpol@kde.org") ); KAboutData::setApplicationData(aboutData); QCommandLineParser parser; aboutData.setupCommandLine(&parser); parser.addPositionalArgument(QStringLiteral("projects"), i18n("Projects to load")); parser.process(app); aboutData.processCommandLine(&parser); if(parser.positionalArguments().isEmpty()) { parser.showHelp(1); } KDevProjectOpen opener; foreach(const QString& arg, parser.positionalArguments()) { opener.openProject(QUrl::fromUserInput(arg)); } return app.exec(); } diff --git a/plugins/cppcheck/tests/test_cppcheckjob.cpp b/plugins/cppcheck/tests/test_cppcheckjob.cpp index ebd5ecd167..5b50b6b321 100644 --- a/plugins/cppcheck/tests/test_cppcheckjob.cpp +++ b/plugins/cppcheck/tests/test_cppcheckjob.cpp @@ -1,91 +1,91 @@ /************************************************************************************* * Copyright 2016 (C) Anton Anikin * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * *************************************************************************************/ +#include "test_cppcheckjob.h" + #include #include #include -#include "test_cppcheckjob.h" - #include "job.h" #include "parameters.h" using namespace KDevelop; using namespace cppcheck; class JobTester : public Job { public: explicit JobTester(const Parameters& params) : Job(params) {} using Job::postProcessStdout; using Job::postProcessStderr; QString standardOutput() const { return m_standardOutput.join('\n'); } QString xmlOutput() const { return m_xmlOutput.join('\n'); } }; void TestCppcheckJob::initTestCase() { AutoTestShell::init({"kdevcppcheck"}); TestCore::initialize(Core::NoUi); } void TestCppcheckJob::cleanupTestCase() { TestCore::shutdown(); } void TestCppcheckJob::testJob() { QStringList stdoutOutput = { "Checking source1.cpp...", "1/2 files checked 50% done", "Checking source2.cpp...", "2/2 files checked 50% done" }; QStringList stderrOutput = { "(information) Couldn't find path given by -I '/missing_include_dir_1/'", "(information) Couldn't find path given by -I '/missing_include_dir_2/'", "", "", " ", " ", " ", " ", "" }; Parameters jobParams; JobTester jobTester(jobParams); jobTester.postProcessStderr(stderrOutput); jobTester.postProcessStdout(stdoutOutput); // move non-XML elements from stderrOutput stdoutOutput.push_front(stderrOutput[1]); stdoutOutput.push_front(stderrOutput[0]); stderrOutput.pop_front(); stderrOutput.pop_front(); QCOMPARE(jobTester.standardOutput(), stdoutOutput.join('\n')); QCOMPARE(jobTester.xmlOutput(), stderrOutput.join('\n')); } QTEST_GUILESS_MAIN(TestCppcheckJob) diff --git a/plugins/custom-definesandincludes/kcm_widget/definesandincludesconfigpage.cpp b/plugins/custom-definesandincludes/kcm_widget/definesandincludesconfigpage.cpp index 32a289eac6..a046fb6e3a 100644 --- a/plugins/custom-definesandincludes/kcm_widget/definesandincludesconfigpage.cpp +++ b/plugins/custom-definesandincludes/kcm_widget/definesandincludesconfigpage.cpp @@ -1,92 +1,92 @@ /************************************************************************ * * * Copyright 2010 Andreas Pakulat * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 or version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ************************************************************************/ +#include "definesandincludesconfigpage.h" + #include #include #include "projectpathswidget.h" #include "customdefinesandincludes.h" #include "../compilerprovider/compilerprovider.h" #include #include #include #include #include -#include "definesandincludesconfigpage.h" - DefinesAndIncludesConfigPage::DefinesAndIncludesConfigPage(KDevelop::IPlugin* plugin, const KDevelop::ProjectConfigOptions& options, QWidget* parent) : ProjectConfigPage(plugin, options, parent) { QVBoxLayout* layout = new QVBoxLayout( this ); configWidget = new ProjectPathsWidget( this ); configWidget->setProject( project() ); connect(configWidget, &ProjectPathsWidget::changed, this, &DefinesAndIncludesConfigPage::changed); layout->addWidget( configWidget ); } DefinesAndIncludesConfigPage::~DefinesAndIncludesConfigPage() { } void DefinesAndIncludesConfigPage::loadFrom( KConfig* cfg ) { configWidget->clear(); auto settings = SettingsManager::globalInstance(); configWidget->setPaths( settings->readPaths( cfg ) ); } void DefinesAndIncludesConfigPage::saveTo(KConfig* cfg, KDevelop::IProject*) { auto settings = SettingsManager::globalInstance(); settings->writePaths( cfg, configWidget->paths() ); if ( settings->needToReparseCurrentProject( cfg ) ) { KDevelop::ICore::self()->projectController()->reparseProject(project(), true); } } void DefinesAndIncludesConfigPage::reset() { ProjectConfigPage::reset(); loadFrom(CustomDefinesAndIncludes::self()->config()); } void DefinesAndIncludesConfigPage::apply() { ProjectConfigPage::apply(); saveTo(CustomDefinesAndIncludes::self()->config(), project()); } QString DefinesAndIncludesConfigPage::name() const { return i18n("Language Support"); } QString DefinesAndIncludesConfigPage::fullName() const { return i18n("Configure Language Support"); } QIcon DefinesAndIncludesConfigPage::icon() const { return QIcon::fromTheme(QStringLiteral("kdevelop")); } diff --git a/plugins/ghprovider/ghdialog.cpp b/plugins/ghprovider/ghdialog.cpp index dc2f6e73db..0a4cdb488a 100644 --- a/plugins/ghprovider/ghdialog.cpp +++ b/plugins/ghprovider/ghdialog.cpp @@ -1,197 +1,198 @@ /* This file is part of KDevelop * * Copyright (C) 2012-2013 Miquel Sabaté * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "ghdialog.h" + +#include +#include + +#include +#include +#include + #include #include #include #include #include #include -#include -#include -#include - -#include -#include -#include - static QString invalidAccountText() { return i18n("You have not authorized KDevelop to use your GitHub account. " "If you authorize KDevelop, you will be able to fetch your " "public/private repositories and the repositories from your " "organizations."); } static QString tokenLinkStatementText() { return i18nc("%1 is the URL with the GitHub token settings", "You can check the authorization for this application and " "others at %1", QStringLiteral("https://github.com/settings/tokens.")); } namespace gh { Dialog::Dialog(QWidget *parent, Account *account) : QDialog(parent) , m_account(account) { auto mainWidget = new QWidget(this); auto mainLayout = new QVBoxLayout; setLayout(mainLayout); mainLayout->addWidget(mainWidget); auto buttonBox = new QDialogButtonBox(); if (m_account->validAccount()) { m_text = new QLabel(i18n("You are logged in as %1.
%2", m_account->name(), tokenLinkStatementText()), this); auto logOutButton = new QPushButton; logOutButton->setText(i18n("Log Out")); logOutButton->setIcon(QIcon::fromTheme(QStringLiteral("dialog-cancel"))); buttonBox->addButton(logOutButton, QDialogButtonBox::ActionRole); connect(logOutButton, &QPushButton::clicked, this, &Dialog::revokeAccess); auto forceSyncButton = new QPushButton; forceSyncButton->setText(i18n("Force Sync")); forceSyncButton->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh"))); buttonBox->addButton(forceSyncButton, QDialogButtonBox::ActionRole); connect(forceSyncButton, &QPushButton::clicked, this, &Dialog::syncUser); connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); } else { m_text = new QLabel(invalidAccountText(), this); buttonBox->addButton(QDialogButtonBox::Cancel); auto authorizeButton = new QPushButton; buttonBox->addButton(authorizeButton, QDialogButtonBox::ActionRole); authorizeButton->setText(i18n("Authorize")); authorizeButton->setIcon(QIcon::fromTheme(QStringLiteral("dialog-ok"))); connect(authorizeButton, &QPushButton::clicked, this, &Dialog::authorizeClicked); } m_text->setWordWrap(true); m_text->setOpenExternalLinks(true); setMinimumWidth(350); mainLayout->addWidget(m_text); mainLayout->addWidget(buttonBox); connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); setWindowTitle(i18n("GitHub Account")); } void Dialog::authorizeClicked() { QPointer dlg = new KPasswordDialog(this, KPasswordDialog::ShowUsernameLine); dlg->setPrompt(i18n("Enter a login and a password")); if(dlg->exec()) { m_text->setAlignment(Qt::AlignCenter); m_text->setText(i18n("Waiting for response")); m_account->setName(dlg->username()); Resource *rs = m_account->resource(); rs->authenticate(dlg->username(), dlg->password()); connect(rs, &Resource::twoFactorAuthRequested, this, &Dialog::twoFactorResponse); connect(rs, &Resource::authenticated, this, &Dialog::authorizeResponse); } delete dlg; } void Dialog::authorizeResponse(const QByteArray &id, const QByteArray &token, const QString &tokenName) { Q_UNUSED(tokenName); Resource *rs = m_account->resource(); disconnect(rs, &Resource::authenticated, this, &Dialog::authorizeResponse); if (id.isEmpty()) { m_text->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); m_text->setText(invalidAccountText()); m_account->setName(QString()); KMessageBox::sorry(this, i18n("Authentication failed. Please try again.\n\n" "Could not create token: \"%1\"\n%2", tokenName, tokenLinkStatementText()), i18n("GitHub Authorization Failed")); return; } else{ KMessageBox::information(this, i18n("Authentication succeeded.\n\n" "Created token: \"%1\"\n%2", tokenName, tokenLinkStatementText()), i18n("GitHub Account Authorized")); } m_account->saveToken(id, token); syncUser(); } void Dialog::twoFactorResponse(const QString &transferHeader) { auto code = QInputDialog::getText(this, i18n("Authentication Code"), i18n("OTP Code")); Resource* rs = m_account->resource(); disconnect(rs, &Resource::twoFactorAuthRequested, this, &Dialog::twoFactorResponse); rs->twoFactorAuthenticate(transferHeader, code); } void Dialog::syncUser() { Resource *rs = m_account->resource(); connect(rs, &Resource::orgsUpdated, this, &Dialog::updateOrgs); m_text->setAlignment(Qt::AlignCenter); m_text->setText(i18n("Waiting for response")); rs->getOrgs(m_account->token()); } void Dialog::updateOrgs(const QStringList& orgs) { Resource *rs = m_account->resource(); disconnect(rs, &Resource::orgsUpdated, this, &Dialog::updateOrgs); if (!orgs.isEmpty()) m_account->setOrgs(orgs); emit shouldUpdate(); close(); } void Dialog::revokeAccess() { QPointer dlg = new KPasswordDialog(this); dlg->setPrompt(i18n("Please, write your password here.")); if(dlg->exec()) { m_account->invalidate(dlg->password()); emit shouldUpdate(); close(); } delete dlg; } } // End of namespace gh diff --git a/plugins/ghprovider/ghlineedit.cpp b/plugins/ghprovider/ghlineedit.cpp index 4852091ed5..9463d72f02 100644 --- a/plugins/ghprovider/ghlineedit.cpp +++ b/plugins/ghprovider/ghlineedit.cpp @@ -1,60 +1,60 @@ /* This file is part of KDevelop * * Copyright (C) 2012-2013 Miquel Sabaté * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "ghlineedit.h" #include #include -#include namespace gh { LineEdit::LineEdit(QWidget *parent) : QLineEdit(parent) { m_timer = new QTimer(this); m_timer->setInterval(500); connect(m_timer, &QTimer::timeout, this, &LineEdit::timeOut); } LineEdit::~LineEdit() { /* There's nothing to do here! */ } void LineEdit::keyPressEvent(QKeyEvent *e) { m_timer->stop(); if (e->key() == Qt::Key_Return) { e->accept(); emit returnPressed(); return; } m_timer->start(); QLineEdit::keyPressEvent(e); } void LineEdit::timeOut() { m_timer->stop(); if (!text().isEmpty()) emit returnPressed(); } } // End of namespace gh diff --git a/plugins/ghprovider/ghproviderplugin.cpp b/plugins/ghprovider/ghproviderplugin.cpp index 94fbda6de6..d318d6dead 100644 --- a/plugins/ghprovider/ghproviderplugin.cpp +++ b/plugins/ghprovider/ghproviderplugin.cpp @@ -1,58 +1,58 @@ /* This file is part of KDevelop * * Copyright (C) 2012-2013 Miquel Sabaté * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - -#include -#include +#include #include -#include #include +#include +#include + using namespace KDevelop; K_PLUGIN_FACTORY_WITH_JSON(KDevGHProviderFactory, "kdevghprovider.json", registerPlugin();) namespace gh { ProviderPlugin::ProviderPlugin(QObject *parent, const QList &args) : IPlugin(QStringLiteral("kdevghprovider"), parent) { Q_UNUSED(args); } ProviderPlugin::~ProviderPlugin() { /* There's nothing to do here! */ } QString ProviderPlugin::name() const { return i18n("GitHub"); } IProjectProviderWidget * ProviderPlugin::providerWidget(QWidget *parent) { return new ProviderWidget(parent); } } // End of namespace gh #include "ghproviderplugin.moc" diff --git a/plugins/ghprovider/ghproviderwidget.cpp b/plugins/ghprovider/ghproviderwidget.cpp index 4fe5671316..06978574ba 100644 --- a/plugins/ghprovider/ghproviderwidget.cpp +++ b/plugins/ghprovider/ghproviderwidget.cpp @@ -1,175 +1,175 @@ /* This file is part of KDevelop * * Copyright (C) 2012-2013 Miquel Sabaté * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include +#include #include #include #include #include #include #include #include #include #include #include -#include #include #include #include #include #include -#include +#include +#include using namespace KDevelop; namespace gh { ProviderWidget::ProviderWidget(QWidget *parent) : IProjectProviderWidget(parent) { setLayout(new QVBoxLayout()); m_projects = new QListView(this); connect(m_projects, &QListView::clicked, this, &ProviderWidget::projectIndexChanged); m_waiting = new QLabel(i18n("Waiting for response"), this); m_waiting->setAlignment(Qt::AlignCenter); m_waiting->hide(); ProviderModel *model = new ProviderModel(this); m_projects->setModel(model); m_projects->setEditTriggers(QAbstractItemView::NoEditTriggers); m_resource = new Resource(this, model); m_account = new Account(m_resource); connect(m_resource, &Resource::reposUpdated, m_waiting, &QLabel::hide); QHBoxLayout *topLayout = new QHBoxLayout(); m_edit = new LineEdit(this); m_edit->setPlaceholderText(i18n("Search")); m_edit->setToolTip(i18n("You can press the Return key if you do not want to wait")); connect(m_edit, &LineEdit::returnPressed, this, &ProviderWidget::searchRepo); topLayout->addWidget(m_edit); m_combo = new QComboBox(this); m_combo->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); connect(m_combo, static_cast(&QComboBox::currentIndexChanged), this, &ProviderWidget::searchRepo); fillCombo(); topLayout->addWidget(m_combo); QPushButton *settings = new QPushButton(QIcon::fromTheme(QStringLiteral("configure")), QString(), this); settings->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); settings->setToolTip(i18n("Click this button to configure your GitHub account")); connect(settings, &QPushButton::clicked, this, &ProviderWidget::showSettings); topLayout->addWidget(settings); layout()->addItem(topLayout); layout()->addWidget(m_waiting); layout()->addWidget(m_projects); } KDevelop::VcsJob * ProviderWidget::createWorkingCopy(const QUrl &dest) { QModelIndex pos = m_projects->currentIndex(); if (!pos.isValid()) return nullptr; auto plugin = ICore::self()->pluginController()->pluginForExtension(QStringLiteral("org.kdevelop.IBasicVersionControl"), QStringLiteral("kdevgit")); if (!plugin) { KMessageBox::error(nullptr, i18n("The Git plugin could not be loaded which is required to import a GitHub project."), i18n("GitHub Provider Error")); return nullptr; } QString url = pos.data(ProviderModel::VcsLocationRole).toString(); if (m_account->validAccount()) url = QLatin1String("https://") + m_account->token() + QLatin1Char('@') + url.midRef(8); QUrl real = QUrl(url); VcsLocation loc(real); auto vc = plugin->extension(); Q_ASSERT(vc); return vc->createWorkingCopy(loc, dest); } void ProviderWidget::fillCombo() { m_combo->clear(); m_combo->addItem(i18n("User"), 1); m_combo->addItem(i18n("Organization"), 3); if (m_account->validAccount()) { m_combo->addItem(m_account->name(), 0); m_combo->setCurrentIndex(2); } const QStringList &orgs = m_account->orgs(); for (const QString& org : orgs) m_combo->addItem(org, 2); } bool ProviderWidget::isCorrect() const { return m_projects->currentIndex().isValid(); } void ProviderWidget::projectIndexChanged(const QModelIndex ¤tIndex) { if (currentIndex.isValid()) { QString name = currentIndex.data().toString(); emit changed(name); } } void ProviderWidget::showSettings() { Dialog *dialog = new Dialog(this, m_account); connect(dialog, &Dialog::shouldUpdate, this, &ProviderWidget::fillCombo); dialog->show(); } void ProviderWidget::searchRepo() { bool enabled = true; QString uri, text = m_edit->text(); int idx = m_combo->itemData(m_combo->currentIndex()).toInt(); switch (idx) { case 0: /* Looking for this user's repo */ uri = QStringLiteral("/user/repos"); enabled = false; break; case 1: /* Looking for some user's repo */ if (text == m_account->name()) uri = QStringLiteral("/user/repos"); else uri = QStringLiteral("/users/%1/repos").arg(text); break; case 2: /* Known organization */ text = m_combo->currentText(); enabled = false; default:/* Looking for some organization's repo. */ uri = QStringLiteral("/orgs/%1/repos").arg(text); break; } m_edit->setEnabled(enabled); m_waiting->show(); m_resource->searchRepos(uri, m_account->token()); } } // End of namespace gh diff --git a/plugins/grepview/tests/test_findreplace.cpp b/plugins/grepview/tests/test_findreplace.cpp index 334fccf235..ec76295e08 100644 --- a/plugins/grepview/tests/test_findreplace.cpp +++ b/plugins/grepview/tests/test_findreplace.cpp @@ -1,200 +1,201 @@ /*************************************************************************** * Copyright 1999-2001 Bernd Gehrmann and the KDevelop Team * * bernd@kdevelop.org * * Copyright 2010 Julien Desgats * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ +#include "test_findreplace.h" + #include #include #include #include #include #include -#include "test_findreplace.h" #include "../grepjob.h" #include "../grepviewplugin.h" #include "../grepoutputmodel.h" void FindReplaceTest::initTestCase() { KDevelop::AutoTestShell::init(); KDevelop::TestCore::initialize(KDevelop::Core::NoUi); } void FindReplaceTest::cleanupTestCase() { KDevelop::TestCore::shutdown(); } void FindReplaceTest::testFind_data() { QTest::addColumn("subject"); QTest::addColumn("search"); QTest::addColumn("matches"); QTest::newRow("Basic") << "foobar" << QRegExp("foo") << (MatchList() << Match(0, 0, 3)); QTest::newRow("Multiple matches") << "foobar\nbar\nbarfoo" << QRegExp("foo") << (MatchList() << Match(0, 0, 3) << Match(2, 3, 6)); QTest::newRow("Multiple on same line") << "foobarbaz" << QRegExp("ba") << (MatchList() << Match(0, 3, 5) << Match(0, 6, 8)); QTest::newRow("Multiple sticked together") << "foofoobar" << QRegExp("foo") << (MatchList() << Match(0, 0, 3) << Match(0, 3, 6)); QTest::newRow("RegExp (member call)") << "foo->bar ();\nbar();" << QRegExp("\\->\\s*\\b(bar)\\b\\s*\\(") << (MatchList() << Match(0, 3, 10)); // the matching must be started after the last previous match QTest::newRow("RegExp (greedy match)") << "foofooo" << QRegExp("[o]+") << (MatchList() << Match(0, 1, 3) << Match(0, 4, 7)); QTest::newRow("Matching EOL") << "foobar\nfoobar" << QRegExp("foo.*") << (MatchList() << Match(0, 0, 6) << Match(1, 0, 6)); QTest::newRow("Matching EOL (Windows style)") << "foobar\r\nfoobar" << QRegExp("foo.*") << (MatchList() << Match(0, 0, 6) << Match(1, 0, 6)); QTest::newRow("Empty lines handling") << "foo\n\n\n" << QRegExp("bar") << (MatchList()); QTest::newRow("Can match empty string (at EOL)") << "foobar\n" << QRegExp(".*") << (MatchList() << Match(0, 0, 6)); QTest::newRow("Matching empty string anywhere") << "foobar\n" << QRegExp("") << (MatchList()); } void FindReplaceTest::testFind() { QFETCH(QString, subject); QFETCH(QRegExp, search); QFETCH(MatchList, matches); QTemporaryFile file; QVERIFY(file.open()); file.write(subject.toUtf8()); file.close(); GrepOutputItem::List actualMatches = grepFile(file.fileName(), search); QCOMPARE(actualMatches.length(), matches.length()); for(int i=0; im_range.start().line(), matches[i].line); QCOMPARE(actualMatches[i].change()->m_range.start().column(), matches[i].start); QCOMPARE(actualMatches[i].change()->m_range.end().column(), matches[i].end); } // check that file has not been altered by grepFile QVERIFY(file.open()); QCOMPARE(QString(file.readAll()), subject); } void FindReplaceTest::testReplace_data() { QTest::addColumn("subject"); QTest::addColumn("searchPattern"); QTest::addColumn("searchTemplate"); QTest::addColumn("replace"); QTest::addColumn("replaceTemplate"); QTest::addColumn("result"); QTest::newRow("Raw replace") << (FileList() << File(QStringLiteral("myfile.txt"), QStringLiteral("some text\nreplacement\nsome other test\n")) << File(QStringLiteral("otherfile.txt"), QStringLiteral("some replacement text\n\n"))) << "replacement" << "%s" << "dummy" << "%s" << (FileList() << File(QStringLiteral("myfile.txt"), QStringLiteral("some text\ndummy\nsome other test\n")) << File(QStringLiteral("otherfile.txt"), QStringLiteral("some dummy text\n\n"))); // see bug: https://bugs.kde.org/show_bug.cgi?id=301362 QTest::newRow("LF character replace") << (FileList() << File(QStringLiteral("somefile.txt"), QStringLiteral("hello world\\n"))) << "\\\\n" << "%s" << "\\n\\n" << "%s" << (FileList() << File(QStringLiteral("somefile.txt"), QStringLiteral("hello world\\n\\n"))); QTest::newRow("Template replace") << (FileList() << File(QStringLiteral("somefile.h"), QStringLiteral("struct Foo {\n void setFoo(int foo);\n};")) << File(QStringLiteral("somefile.cpp"), QStringLiteral("instance->setFoo(0);\n setFoo(0); /*not replaced*/"))) << "setFoo" << "\\->\\s*\\b%s\\b\\s*\\(" << "setBar" << "->%s(" << (FileList() << File(QStringLiteral("somefile.h"), QStringLiteral("struct Foo {\n void setFoo(int foo);\n};")) << File(QStringLiteral("somefile.cpp"), QStringLiteral("instance->setBar(0);\n setFoo(0); /*not replaced*/"))); QTest::newRow("Template with captures") << (FileList() << File(QStringLiteral("somefile.cpp"), QStringLiteral("inst::func(1, 2)\n otherInst :: func (\"foo\")\n func()"))) << "func" << "([a-z0-9_$]+)\\s*::\\s*\\b%s\\b\\s*\\(" << "REPL" << "\\1::%s(" << (FileList() << File(QStringLiteral("somefile.cpp"), QStringLiteral("inst::REPL(1, 2)\n otherInst::REPL(\"foo\")\n func()"))); QTest::newRow("Regexp pattern") << (FileList() << File(QStringLiteral("somefile.txt"), QStringLiteral("foobar\n foooobar\n fake"))) << "f\\w*o" << "%s" << "FOO" << "%s" << (FileList() << File(QStringLiteral("somefile.txt"), QStringLiteral("FOObar\n FOObar\n fake"))); } void FindReplaceTest::testReplace() { QFETCH(FileList, subject); QFETCH(QString, searchPattern); QFETCH(QString, searchTemplate); QFETCH(QString, replace); QFETCH(QString, replaceTemplate); QFETCH(FileList, result); QTemporaryDir tempDir; QDir dir(tempDir.path()); // we need some convenience functions that are not in QTemporaryDir foreach(const File& fileData, subject) { QFile file(dir.filePath(fileData.first)); QVERIFY(file.open(QIODevice::WriteOnly)); QVERIFY(file.write(fileData.second.toUtf8()) != -1); file.close(); } GrepJob *job = new GrepJob(this); GrepOutputModel *model = new GrepOutputModel(job); GrepJobSettings settings; job->setOutputModel(model); job->setDirectoryChoice(QList() << QUrl::fromLocalFile(dir.path())); settings.projectFilesOnly = false; settings.caseSensitive = true; settings.regexp = true; settings.depth = -1; // fully recursive settings.pattern = searchPattern; settings.searchTemplate = searchTemplate; settings.replacementTemplate = replaceTemplate; settings.files = QStringLiteral("*"); settings.exclude = QString(); job->setSettings(settings); QVERIFY(job->exec()); QVERIFY(model->hasResults()); model->setReplacement(replace); model->makeItemsCheckable(true); model->doReplacements(); foreach(const File& fileData, result) { QFile file(dir.filePath(fileData.first)); QVERIFY(file.open(QIODevice::ReadOnly)); QCOMPARE(QString(file.readAll()), fileData.second); file.close(); } tempDir.remove(); } QTEST_MAIN(FindReplaceTest) diff --git a/plugins/manpage/manpageplugin.cpp b/plugins/manpage/manpageplugin.cpp index 3bbbf9ca7f..691c6e92d9 100644 --- a/plugins/manpage/manpageplugin.cpp +++ b/plugins/manpage/manpageplugin.cpp @@ -1,156 +1,157 @@ /* This file is part of KDevelop Copyright 2010 Yannick Motta Copyright 2010 Benjamin Port This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include +#include "manpageplugin.h" + +#include "manpagedocumentation.h" +#include "manpagemodel.h" #include +#include +#include #include #include #include #include #include #include #include #include #include +#include + #include #include -#include -#include - -#include "manpageplugin.h" -#include "manpagedocumentation.h" -#include "manpagemodel.h" using namespace KDevelop; K_PLUGIN_FACTORY_WITH_JSON(ManPageFactory, "kdevmanpage.json", registerPlugin(); ) ManPagePlugin::ManPagePlugin(QObject* parent, const QVariantList& args) : IPlugin(QStringLiteral("kdevmanpage"), parent) { Q_UNUSED(args); ManPageDocumentation::s_provider = this; m_model = new ManPageModel(this); } ManPagePlugin::~ManPagePlugin() { delete m_model; } QString ManPagePlugin::name() const { return i18n("Man Page"); } QIcon ManPagePlugin::icon() const { return QIcon::fromTheme(QStringLiteral("application-x-troff-man")); } ManPageModel* ManPagePlugin::model() const{ return m_model; } IDocumentation::Ptr ManPagePlugin::documentationForDeclaration( Declaration* dec ) const { Q_ASSERT(dec); Q_ASSERT(dec->topContext()); Q_ASSERT(dec->topContext()->parsingEnvironmentFile()); static const IndexedString cppLanguage("C++"); // TODO remove because of new clang parser? static const IndexedString clangLanguage("Clang"); const IndexedString declarationLanguage(dec->topContext()->parsingEnvironmentFile()->language()); if (declarationLanguage != cppLanguage && declarationLanguage != clangLanguage) return {}; // Don't show man-page documentation for files that are part of our project if (core()->projectController()->findProjectForUrl(dec->topContext()->url().toUrl())) return {}; // Don't show man-page documentation for files that are not in /usr/include, because then we // most probably will be confusing the global function-name with a local one if (!dec->topContext()->url().str().startsWith(QLatin1String("/usr/"))) return {}; ///@todo Do more verification to make sure that we're showing the correct documentation for the declaration QString identifier; IDocumentation::Ptr result; // First, try to find help for qualified identifier like 'std::vector' { DUChainReadLocker lock; identifier = dec->qualifiedIdentifier().toString(RemoveTemplateInformation); } result = documentationForIdentifier(identifier); if (result.data()) return result; // Second, try to find help for simple identifier like 'sin' { DUChainReadLocker lock; identifier = dec->identifier().toString(RemoveTemplateInformation); } result = documentationForIdentifier(identifier); if (result.data()) return result; return {}; } KDevelop::IDocumentation::Ptr ManPagePlugin::documentationForIdentifier(const QString& identifier) const { if (!m_model->containsIdentifier(identifier)) return KDevelop::IDocumentation::Ptr(nullptr); if (m_model->identifierInSection(identifier, QStringLiteral("3"))) return IDocumentation::Ptr(new ManPageDocumentation(identifier, QUrl(QLatin1String("man:(3)/") + identifier))); if (m_model->identifierInSection(identifier, QStringLiteral("2"))) return IDocumentation::Ptr(new ManPageDocumentation(identifier, QUrl(QLatin1String("man:(2)/") + identifier))); return IDocumentation::Ptr(new ManPageDocumentation(identifier, QUrl(QLatin1String("man:/") + identifier))); } QAbstractItemModel* ManPagePlugin::indexModel() const { return m_model->indexList(); } IDocumentation::Ptr ManPagePlugin::documentationForIndex(const QModelIndex& index) const { QString name = index.data().toString(); return IDocumentation::Ptr(new ManPageDocumentation(name, QUrl(QLatin1String("man:")+name))); } IDocumentation::Ptr ManPagePlugin::homePage() const { return IDocumentation::Ptr(new ManPageHomeDocumentation); } #include "manpageplugin.moc" diff --git a/plugins/qmljs/codecompletion/model.cpp b/plugins/qmljs/codecompletion/model.cpp index 2429dda651..f7715dfbb0 100644 --- a/plugins/qmljs/codecompletion/model.cpp +++ b/plugins/qmljs/codecompletion/model.cpp @@ -1,39 +1,40 @@ /* * This file is part of qmljs, the QML/JS language support plugin for KDevelop * Copyright (c) 2013 Sven Brauch * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ -#include "worker.h" #include "model.h" +#include "worker.h" + namespace QmlJS { CodeCompletionModel::CodeCompletionModel(QObject* parent) : KDevelop::CodeCompletionModel(parent) { } KDevelop::CodeCompletionWorker* CodeCompletionModel::createCompletionWorker() { return new CodeCompletionWorker(this); } } diff --git a/plugins/standardoutputview/tests/test_standardoutputview.cpp b/plugins/standardoutputview/tests/test_standardoutputview.cpp index c75ff97757..d20838ff86 100644 --- a/plugins/standardoutputview/tests/test_standardoutputview.cpp +++ b/plugins/standardoutputview/tests/test_standardoutputview.cpp @@ -1,228 +1,229 @@ /* Copyright (C) 2011 Silvère Lestang This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "test_standardoutputview.h" + #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#include "test_standardoutputview.h" #include "../outputwidget.h" #include "../toolviewdata.h" namespace KDevelop { class IUiController; } QTEST_MAIN(StandardOutputViewTest) const QString StandardOutputViewTest::toolViewTitle = QStringLiteral("my_toolview"); void StandardOutputViewTest::initTestCase() { KDevelop::AutoTestShell::init({QStringLiteral("KDevStandardOutputView")}); m_testCore = new KDevelop::TestCore(); m_testCore->initialize(KDevelop::Core::Default); m_controller = m_testCore->uiControllerInternal(); QTest::qWait(500); // makes sure that everything is loaded (don't know if it's required) m_stdOutputView = nullptr; KDevelop::IPluginController* plugin_controller = m_testCore->pluginController(); // make sure KDevStandardOutputView is loaded KDevelop::IPlugin* plugin = plugin_controller->loadPlugin(QStringLiteral("KDevStandardOutputView")); QVERIFY(plugin); m_stdOutputView = dynamic_cast(plugin); QVERIFY(m_stdOutputView); } void StandardOutputViewTest::cleanupTestCase() { m_testCore->cleanup(); delete m_testCore; } OutputWidget* StandardOutputViewTest::toolViewPointer(const QString& toolViewTitle) { const QList< Sublime::View* > views = m_controller->activeArea()->toolViews(); for (Sublime::View* view : views) { Sublime::ToolDocument *doc = dynamic_cast(view->document()); if(doc) { if(doc->title() == toolViewTitle && view->hasWidget()) { return dynamic_cast(view->widget()); } } } return nullptr; } void StandardOutputViewTest::testRegisterAndRemoveToolView() { toolViewId = m_stdOutputView->registerToolView(toolViewTitle, KDevelop::IOutputView::HistoryView); QVERIFY(toolViewPointer(toolViewTitle)); // re-registering should return the same tool view instead of creating a new one QCOMPARE(toolViewId, m_stdOutputView->registerToolView(toolViewTitle, KDevelop::IOutputView::HistoryView)); m_stdOutputView->removeToolView(toolViewId); QVERIFY(!toolViewPointer(toolViewTitle)); } void StandardOutputViewTest::testActions() { toolViewId = m_stdOutputView->registerToolView(toolViewTitle, KDevelop::IOutputView::MultipleView, QIcon()); OutputWidget* outputWidget = toolViewPointer(toolViewTitle); QVERIFY(outputWidget); QList actions = outputWidget->actions(); QCOMPARE(actions.size(), 11); m_stdOutputView->removeToolView(toolViewId); QVERIFY(!toolViewPointer(toolViewTitle)); QList addedActions; addedActions.append(new QAction(QStringLiteral("Action1"), nullptr)); addedActions.append(new QAction(QStringLiteral("Action2"), nullptr)); toolViewId = m_stdOutputView->registerToolView(toolViewTitle, KDevelop::IOutputView::HistoryView, QIcon(), KDevelop::IOutputView::ShowItemsButton | KDevelop::IOutputView::AddFilterAction, addedActions); outputWidget = toolViewPointer(toolViewTitle); QVERIFY(outputWidget); actions = outputWidget->actions(); QCOMPARE(actions.size(), 16); QCOMPARE(actions[actions.size()-2]->text(), addedActions[0]->text()); QCOMPARE(actions[actions.size()-1]->text(), addedActions[1]->text()); m_stdOutputView->removeToolView(toolViewId); QVERIFY(!toolViewPointer(toolViewTitle)); } void StandardOutputViewTest::testRegisterAndRemoveOutput() { toolViewId = m_stdOutputView->registerToolView(toolViewTitle, KDevelop::IOutputView::MultipleView, QIcon()); OutputWidget* outputWidget = toolViewPointer(toolViewTitle); QVERIFY(outputWidget); for(int i = 0; i < 5; i++) { outputId[i] = m_stdOutputView->registerOutputInToolView(toolViewId, QStringLiteral("output%1").arg(i)); } for(int i = 0; i < 5; i++) { QCOMPARE(outputWidget->data->outputdata.value(outputId[i])->title, QStringLiteral("output%1").arg(i)); QCOMPARE(outputWidget->m_tabwidget->tabText(i), QStringLiteral("output%1").arg(i)); } for(int i = 0; i < 5; i++) { m_stdOutputView->removeOutput(outputId[i]); QVERIFY(!outputWidget->data->outputdata.contains(outputId[i])); } QCOMPARE(outputWidget->m_tabwidget->count(), 0); m_stdOutputView->removeToolView(toolViewId); QVERIFY(!toolViewPointer(toolViewTitle)); toolViewId = m_stdOutputView->registerToolView(toolViewTitle, KDevelop::IOutputView::HistoryView, QIcon(), KDevelop::IOutputView::ShowItemsButton | KDevelop::IOutputView::AddFilterAction); outputWidget = toolViewPointer(toolViewTitle); QVERIFY(outputWidget); for(int i = 0; i < 5; i++) { outputId[i] = m_stdOutputView->registerOutputInToolView(toolViewId, QStringLiteral("output%1").arg(i)); } for(int i = 0; i < 5; i++) { QCOMPARE(outputWidget->data->outputdata.value(outputId[i])->title, QStringLiteral("output%1").arg(i)); } for(int i = 0; i < 5; i++) { m_stdOutputView->removeOutput(outputId[i]); QVERIFY(!outputWidget->data->outputdata.contains(outputId[i])); } QCOMPARE(outputWidget->m_stackwidget->count(), 0); m_stdOutputView->removeToolView(toolViewId); QVERIFY(!toolViewPointer(toolViewTitle)); } void StandardOutputViewTest::testSetModelAndDelegate() { toolViewId = m_stdOutputView->registerToolView(toolViewTitle, KDevelop::IOutputView::MultipleView, QIcon()); OutputWidget* outputWidget = toolViewPointer(toolViewTitle); QVERIFY(outputWidget); QAbstractItemModel* model = new QStandardItemModel; QPointer checkModel(model); QAbstractItemDelegate* delegate = new QItemDelegate; QPointer checkDelegate(delegate); outputId[0] = m_stdOutputView->registerOutputInToolView(toolViewId, QStringLiteral("output")); m_stdOutputView->setModel(outputId[0], model); m_stdOutputView->setDelegate(outputId[0], delegate); QCOMPARE(outputWidget->m_views.value(outputId[0])->model(), model); QCOMPARE(outputWidget->m_views.value(outputId[0])->itemDelegate(), delegate); QVERIFY(model->parent()); // they have a parent (the outputdata), so parent() != 0x0 QVERIFY(delegate->parent()); m_stdOutputView->removeToolView(toolViewId); QVERIFY(!toolViewPointer(toolViewTitle)); // view deleted, hence model + delegate deleted QVERIFY(!checkModel.data()); QVERIFY(!checkDelegate.data()); } void StandardOutputViewTest::testStandardToolViews() { QFETCH(KDevelop::IOutputView::StandardToolView, view); int id = m_stdOutputView->standardToolView(view); QVERIFY(id); QCOMPARE(id, m_stdOutputView->standardToolView(view)); } void StandardOutputViewTest::testStandardToolViews_data() { QTest::addColumn("view"); QTest::newRow("build") << KDevelop::IOutputView::BuildView; QTest::newRow("run") << KDevelop::IOutputView::RunView; QTest::newRow("debug") << KDevelop::IOutputView::DebugView; QTest::newRow("test") << KDevelop::IOutputView::TestView; QTest::newRow("vcs") << KDevelop::IOutputView::VcsView; }