File indexing completed on 2024-05-12 04:39:39

0001 /*
0002     SPDX-FileCopyrightText: 2010 Andreas Pakulat <apaku@gmx.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-or-later
0005 */
0006 
0007 #include "definesandincludesconfigpage.h"
0008 
0009 #include <QVBoxLayout>
0010 #include <QIcon>
0011 
0012 #include "projectpathswidget.h"
0013 #include "customdefinesandincludes.h"
0014 #include "../compilerprovider/compilerprovider.h"
0015 
0016 #include <interfaces/iproject.h>
0017 #include <interfaces/iprojectcontroller.h>
0018 #include <interfaces/icore.h>
0019 #include <interfaces/idocument.h>
0020 #include <project/projectmodel.h>
0021 
0022 DefinesAndIncludesConfigPage::DefinesAndIncludesConfigPage(KDevelop::IPlugin* plugin, const KDevelop::ProjectConfigOptions& options, QWidget* parent)
0023     : ProjectConfigPage<CustomDefinesAndIncludes>(plugin, options, parent)
0024 {
0025     auto* layout = new QVBoxLayout( this );
0026     layout->setContentsMargins(0, 0, 0, 0);
0027     configWidget = new ProjectPathsWidget( this );
0028     configWidget->setProject( project() );
0029     connect(configWidget, &ProjectPathsWidget::changed, this, &DefinesAndIncludesConfigPage::changed);
0030     layout->addWidget( configWidget );
0031 }
0032 
0033 DefinesAndIncludesConfigPage::~DefinesAndIncludesConfigPage()
0034 {
0035 }
0036 
0037 void DefinesAndIncludesConfigPage::loadFrom( KConfig* cfg )
0038 {
0039     configWidget->clear();
0040 
0041     auto settings = SettingsManager::globalInstance();
0042 
0043     configWidget->setPaths( settings->readPaths( cfg ) );
0044 }
0045 
0046 void DefinesAndIncludesConfigPage::saveTo(KConfig* cfg, KDevelop::IProject*)
0047 {
0048     auto settings = SettingsManager::globalInstance();
0049     settings->writePaths( cfg, configWidget->paths() );
0050 
0051     if ( settings->needToReparseCurrentProject( cfg ) ) {
0052         KDevelop::ICore::self()->projectController()->reparseProject(project());
0053     }
0054 }
0055 
0056 void DefinesAndIncludesConfigPage::reset()
0057 {
0058    ProjectConfigPage::reset();
0059    loadFrom(CustomDefinesAndIncludes::self()->config());
0060 }
0061 
0062 void DefinesAndIncludesConfigPage::apply()
0063 {
0064     ProjectConfigPage::apply();
0065     saveTo(CustomDefinesAndIncludes::self()->config(), project());
0066 }
0067 
0068 QString DefinesAndIncludesConfigPage::name() const
0069 {
0070     return i18nc("@title:tab", "Language Support");
0071 }
0072 
0073 QString DefinesAndIncludesConfigPage::fullName() const
0074 {
0075     return i18nc("@title:tab", "Configure Language Support");
0076 }
0077 
0078 QIcon DefinesAndIncludesConfigPage::icon() const
0079 {
0080     return QIcon::fromTheme(QStringLiteral("kdevelop"));
0081 }
0082 
0083 #include "moc_definesandincludesconfigpage.cpp"