File indexing completed on 2024-03-24 04:38:27
0001 /* This file is part of KDevelop 0002 * 0003 * Copyright (C) 2014-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 <rails/support.h> 0020 0021 #include <QtWidgets/QAction> 0022 0023 #include <KLocalizedString> 0024 0025 #include <interfaces/icore.h> 0026 #include <interfaces/iplugincontroller.h> 0027 #include <language/interfaces/iquickopen.h> 0028 0029 #include <languagesupport.h> 0030 #include <rails/dataprovider.h> 0031 #include <rails/switchers.h> 0032 0033 using namespace ruby::rails; 0034 0035 Support::Support(ruby::LanguageSupport *support) 0036 : QObject(nullptr) 0037 , m_support(support) 0038 , m_views(nullptr) 0039 , m_tests(nullptr) 0040 { 0041 m_switchers = new Switchers(support); 0042 setupQuickOpen(); 0043 } 0044 0045 Support::~Support() 0046 { 0047 delete m_switchers; 0048 delete m_views; 0049 delete m_tests; 0050 } 0051 0052 void Support::setupQuickOpen() 0053 { 0054 auto qo = m_support->core()->pluginController()-> 0055 extensionForPlugin<KDevelop::IQuickOpen>("org.kdevelop.IQuickOpen"); 0056 if (qo) { 0057 m_views = new DataProvider(Kind::Views); 0058 auto name = QStringList(i18n("Rails Views")); 0059 qo->registerProvider(DataProvider::scopes(), name, m_views); 0060 0061 m_tests = new DataProvider(Kind::Tests); 0062 name = QStringList(i18n("Rails Tests")); 0063 qo->registerProvider(DataProvider::scopes(), name, m_tests); 0064 } 0065 } 0066 0067 void Support::setupActions(KActionCollection &actions) 0068 { 0069 QAction *action = actions.addAction("ruby_switch_to_controller"); 0070 action->setText(i18n("Switch To Controller")); 0071 action->setShortcut(Qt::CTRL | Qt::ALT | Qt::Key_1); 0072 connect(action, &QAction::triggered, 0073 m_switchers, &Switchers::switchToController); 0074 0075 action = actions.addAction("ruby_switch_to_model"); 0076 action->setText(i18n("Switch To Model")); 0077 action->setShortcut(Qt::CTRL | Qt::ALT | Qt::Key_2); 0078 connect(action, &QAction::triggered, 0079 m_switchers, &Switchers::switchToModel); 0080 0081 action = actions.addAction("ruby_switch_to_view"); 0082 action->setText(i18n("Switch To View")); 0083 action->setShortcut(Qt::CTRL | Qt::ALT | Qt::Key_3); 0084 connect(action, &QAction::triggered, 0085 m_switchers, &Switchers::switchToView); 0086 0087 action = actions.addAction("ruby_switch_to_test"); 0088 action->setText(i18n("Switch To Test")); 0089 action->setShortcut(Qt::CTRL | Qt::ALT | Qt::Key_4); 0090 connect(action, &QAction::triggered, 0091 m_switchers, &Switchers::switchToTest); 0092 } 0093