diff --git a/languages/qmljs/duchain/navigation/navigationwidget.cpp b/languages/qmljs/duchain/navigation/navigationwidget.cpp index 2d414c775a..4497b24534 100644 --- a/languages/qmljs/duchain/navigation/navigationwidget.cpp +++ b/languages/qmljs/duchain/navigation/navigationwidget.cpp @@ -1,49 +1,66 @@ /* * This file is part of qmljs, the QML/JS language support plugin for KDevelop * Copyright (c) 2014 Denis Steckelmacher * * 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 "navigationwidget.h" #include "declarationnavigationcontext.h" #include +#include using namespace KDevelop; namespace QmlJS { NavigationWidget::NavigationWidget(KDevelop::Declaration* decl, KDevelop::TopDUContext* topContext, const QString& htmlPrefix, const QString& htmlSuffix, KDevelop::AbstractNavigationWidget::DisplayHints hints) { m_topContext = TopDUContextPointer(topContext); m_startContext = NavigationContextPointer(new DeclarationNavigationContext( DeclarationPointer(decl), m_topContext, nullptr )); m_startContext->setPrefixSuffix(htmlPrefix, htmlSuffix); m_hints = hints; setContext(m_startContext); } +NavigationWidget::NavigationWidget(const KDevelop::IncludeItem& includeItem, + KDevelop::TopDUContextPointer topContext, + const QString& htmlPrefix, + const QString& htmlSuffix, + KDevelop::AbstractNavigationWidget::DisplayHints hints) + : AbstractNavigationWidget() +{ + setDisplayHints(hints); + m_topContext = topContext; + + initBrowser(200); + + m_startContext = NavigationContextPointer(new KDevelop::AbstractIncludeNavigationContext(includeItem, m_topContext, StandardParsingEnvironment)); + m_startContext->setPrefixSuffix(htmlPrefix, htmlSuffix); + setContext(m_startContext); +} } diff --git a/languages/qmljs/duchain/navigation/navigationwidget.h b/languages/qmljs/duchain/navigation/navigationwidget.h index acd3b040af..63c2c6d4ac 100644 --- a/languages/qmljs/duchain/navigation/navigationwidget.h +++ b/languages/qmljs/duchain/navigation/navigationwidget.h @@ -1,43 +1,52 @@ /* * This file is part of qmljs, the QML/JS language support plugin for KDevelop * Copyright (c) 2014 Denis Steckelmacher * * 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 . * */ #ifndef __NAVIGATIONWIDGET_H__ #define __NAVIGATIONWIDGET_H__ #include #include "duchainexport.h" +namespace KDevelop { + class IncludeItem; +} + namespace QmlJS { class KDEVQMLJSDUCHAIN_EXPORT NavigationWidget : public KDevelop::AbstractNavigationWidget { public: NavigationWidget(KDevelop::Declaration* decl, KDevelop::TopDUContext* topContext, const QString& htmlPrefix, const QString& htmlSuffix, KDevelop::AbstractNavigationWidget::DisplayHints hints); + NavigationWidget(const KDevelop::IncludeItem& includeItem, + KDevelop::TopDUContextPointer topContext, + const QString& htmlPrefix, + const QString& htmlSuffix, + KDevelop::AbstractNavigationWidget::DisplayHints hints); }; } #endif diff --git a/languages/qmljs/duchain/qmljsducontext.cpp b/languages/qmljs/duchain/qmljsducontext.cpp index 875c655ad0..430d088ed8 100644 --- a/languages/qmljs/duchain/qmljsducontext.cpp +++ b/languages/qmljs/duchain/qmljsducontext.cpp @@ -1,62 +1,69 @@ /* * This file is part of qmljs, the QML/JS language support plugin for KDevelop * Copyright (c) 2013 Sven Brauch * Copyright (c) 2014 Denis Steckelmacher * * 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 "qmljsducontext.h" #include "debug.h" #include #include #include #include +#include #include "navigation/navigationwidget.h" using namespace KDevelop; namespace QmlJS { template<> QWidget* QmlJSTopDUContext::createNavigationWidget(Declaration* decl, TopDUContext* topContext, const QString& htmlPrefix, const QString& htmlSuffix, AbstractNavigationWidget::DisplayHints hints) const { if (!decl) { - qCDebug(KDEV_QMLJS_DUCHAIN) << "no declaration, not returning navigationwidget"; - return nullptr; + const QUrl u = url().toUrl(); + IncludeItem item; + item.pathNumber = -1; + item.name = u.fileName(); + item.isDirectory = false; + item.basePath = u.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash); + + return new NavigationWidget(item, TopDUContextPointer(topContext ? topContext : this->topContext()), htmlPrefix, htmlSuffix, hints); } return new NavigationWidget(decl, topContext, htmlPrefix, htmlSuffix, hints); } template<> QWidget* QmlJSNormalDUContext::createNavigationWidget(Declaration* decl, TopDUContext* topContext, const QString& htmlPrefix, const QString& htmlSuffix, AbstractNavigationWidget::DisplayHints hints) const { if (!decl) { qCDebug(KDEV_QMLJS_DUCHAIN) << "no declaration, not returning navigationwidget"; return nullptr; } return new NavigationWidget(decl, topContext, htmlPrefix, htmlSuffix, hints); } } DUCHAIN_DEFINE_TYPE_WITH_DATA(QmlJS::QmlJSNormalDUContext, DUContextData) DUCHAIN_DEFINE_TYPE_WITH_DATA(QmlJS::QmlJSTopDUContext, TopDUContextData)