File indexing completed on 2024-03-24 04:38:27
0001 /* 0002 * This file is part of KDevelop 0003 * 0004 * Copyright 2010 Alexander Dymo <adymo@kdevelop.org> 0005 * Copyright (C) 2014-2015 Miquel Sabaté Solà <mikisabate@gmail.com> 0006 * 0007 * This program is free software; you can redistribute it and/or modify 0008 * it under the terms of the GNU Library General Public License as 0009 * published by the Free Software Foundation; either version 2 of the 0010 * License, or (at your option) any later version. 0011 * 0012 * This program is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 * GNU General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU General Public 0018 * License along with this program; if not, write to the 0019 * Free Software Foundation, Inc., 0020 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0021 */ 0022 0023 #include <rails/dataprovider.h> 0024 0025 #include <algorithm> 0026 0027 #include <QtCore/QDir> 0028 #include <QtCore/QFileInfo> 0029 0030 #include <klocalizedstring.h> 0031 0032 #include <interfaces/icore.h> 0033 #include <interfaces/idocumentcontroller.h> 0034 0035 #include <rails/helpers.h> 0036 #include <rails/switchers.h> 0037 0038 using namespace KDevelop; 0039 using namespace ruby::rails; 0040 0041 DataProvider::DataProvider(Kind kind) : m_kind(kind) 0042 { 0043 reset(); 0044 } 0045 0046 QStringList DataProvider::scopes() 0047 { 0048 return QStringList{ QStringLiteral("Project") }; 0049 } 0050 0051 void DataProvider::setFilterText(const QString &text) 0052 { 0053 setFilter(text.split('/')); 0054 } 0055 0056 void DataProvider::reset() 0057 { 0058 updateItems([this](QVector<QuickOpenItem> &items) { 0059 const auto * const doc = ICore::self()->documentController()->activeDocument(); 0060 0061 QVector<Path> urlsToSwitch; 0062 if (m_kind == Kind::Views) { 0063 urlsToSwitch = Switchers::viewsToSwitch(); 0064 } else if (m_kind == Kind::Tests) { 0065 urlsToSwitch = Switchers::testsToSwitch(); 0066 } 0067 0068 items.resize(urlsToSwitch.size()); 0069 std::transform(urlsToSwitch.cbegin(), urlsToSwitch.cend(), items.begin(), 0070 [doc](const Path &url) { 0071 QuickOpenItem item; 0072 item.url = url.toUrl(); 0073 if (doc) { 0074 item.originUrl = Path(doc->url()).toUrl(); 0075 } 0076 return item; 0077 }); 0078 }); 0079 } 0080 0081 0082 uint DataProvider::itemCount() const 0083 { 0084 return filteredItems().count(); 0085 } 0086 0087 uint DataProvider::unfilteredItemCount() const 0088 { 0089 return items().count(); 0090 } 0091 0092 KDevelop::QuickOpenDataPointer DataProvider::data(uint row) const 0093 { 0094 QString s; 0095 QuickOpenItem item(filteredItems()[row]); 0096 0097 if (m_kind == Kind::Views) { 0098 s = i18n("View for:"); 0099 } else { 0100 s = i18n("Test for:"); 0101 } 0102 return QuickOpenDataPointer(new QuickOpenData(item, s)); 0103 } 0104 0105 void DataProvider::enableData(const QStringList &items, 0106 const QStringList &scopes) 0107 { 0108 QuickOpenDataProviderBase::enableData(items, scopes); 0109 } 0110