File indexing completed on 2024-04-14 04:31:13

0001 /* This file is part of KDevelop
0002  *
0003  * Copyright (C) 2011-2015 Miquel Sabaté Solà <mikisabate@gmail.com>
0004  *
0005  * This program is free software: you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation, either version 3 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017  */
0018 
0019 #include <duchain/rubyducontext.h>
0020 
0021 #include <kio/global.h>
0022 
0023 #include <duchain/navigation/navigationwidget.h>
0024 #include <language/duchain/duchainregister.h>
0025 #include <language/duchain/topducontextdata.h>
0026 #include <language/util/includeitem.h>
0027 
0028 using namespace KDevelop;
0029 namespace ruby {
0030 
0031 REGISTER_DUCHAIN_ITEM_WITH_DATA(RubyTopDUContext, TopDUContextData);
0032 REGISTER_DUCHAIN_ITEM_WITH_DATA(RubyNormalDUContext, DUContextData);
0033 
0034 template<>
0035 KDevelop::AbstractNavigationWidget * RubyTopDUContext::createNavigationWidget(Declaration *decl,
0036                                                    TopDUContext *topContext,
0037                                                    AbstractNavigationWidget::DisplayHints hints) const
0038 {
0039     if (!decl) {
0040         QUrl u = QUrl::fromLocalFile(url().str());
0041         IncludeItem i;
0042         i.pathNumber = -1;
0043         i.name = u.fileName();
0044         i.isDirectory = false;
0045         i.basePath = KIO::upUrl(u);
0046         return new NavigationWidget(i, TopDUContextPointer(topContext), hints);
0047     }
0048     return new NavigationWidget(DeclarationPointer(decl), TopDUContextPointer(topContext), hints);
0049 }
0050 
0051 template<>
0052 KDevelop::AbstractNavigationWidget * RubyNormalDUContext::createNavigationWidget(Declaration *decl, TopDUContext *topContext,
0053                                                       AbstractNavigationWidget::DisplayHints hints) const
0054 {
0055     if (!decl) {
0056         if (owner()) {
0057             return new NavigationWidget(DeclarationPointer(owner()), TopDUContextPointer(topContext), hints);
0058         }
0059         return nullptr;
0060     }
0061     return new NavigationWidget(DeclarationPointer(decl), TopDUContextPointer(topContext), hints);
0062 }
0063 
0064 };
0065