File indexing completed on 2024-05-12 04:38:19
0001 /* 0002 SPDX-FileCopyrightText: 2006 Matt Rogers <mattr@kde.org> 0003 SPDX-FileCopyrightText: 2007 Hamish Rodda <rodda@kde.org> 0004 SPDX-FileCopyrightText: 2009 David Nolden <david.nolden.kdevelop@art-master.de> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "languagepreferences.h" 0010 0011 #include <KTextEditor/View> 0012 #include <KTextEditor/Document> 0013 #include <KTextEditor/CodeCompletionInterface> 0014 0015 #include <interfaces/idocumentcontroller.h> 0016 #include <interfaces/idocument.h> 0017 #include <interfaces/ilanguagecontroller.h> 0018 #include <interfaces/icompletionsettings.h> 0019 0020 #include "../completionsettings.h" 0021 #include "../core.h" 0022 #include "languageconfig.h" 0023 #include "ui_languagepreferences.h" 0024 0025 using namespace KTextEditor; 0026 0027 namespace KDevelop 0028 { 0029 0030 LanguagePreferences::LanguagePreferences(QWidget* parent) 0031 : ConfigPage(nullptr, LanguageConfig::self(), parent) 0032 { 0033 preferencesDialog = new Ui::LanguagePreferences; 0034 preferencesDialog->setupUi(this); 0035 preferencesDialog->kcfg_minFilesForSimplifiedParsing->setSuffix(ki18ncp("@item:valuesuffix", " file", " files")); 0036 0037 connect(preferencesDialog->kcfg_globalColorSource, qOverload<int>(&QComboBox::currentIndexChanged), this, 0038 [this](int index) { 0039 auto canColorize = index == static_cast<int>(ICompletionSettings::GlobalColorSource::AutoGenerated); 0040 preferencesDialog->kcfg_globalColorization->setEnabled(canColorize); 0041 }); 0042 0043 preferencesDialog->label_precompiledPreambleStorage->setToolTip( 0044 preferencesDialog->kcfg_precompiledPreambleStorage->toolTip()); 0045 } 0046 0047 void LanguagePreferences::notifySettingsChanged() 0048 { 0049 auto& settings(static_cast<CompletionSettings&>(*ICore::self()->languageController()->completionSettings())); 0050 0051 settings.emitChanged(); 0052 } 0053 0054 LanguagePreferences::~LanguagePreferences( ) 0055 { 0056 delete preferencesDialog; 0057 } 0058 0059 void LanguagePreferences::apply() 0060 { 0061 ConfigPage::apply(); 0062 0063 const auto documents = Core::self()->documentController()->openDocuments(); 0064 for (KDevelop::IDocument* doc : documents) { 0065 if (Document* textDoc = doc->textDocument()) { 0066 const auto views = textDoc->views(); 0067 for (View* view : views) { 0068 if (auto* cc = qobject_cast<CodeCompletionInterface*>(view)) { 0069 cc->setAutomaticInvocationEnabled(preferencesDialog->kcfg_automaticInvocation->isChecked()); 0070 } 0071 } 0072 } 0073 } 0074 0075 notifySettingsChanged(); 0076 } 0077 0078 QString LanguagePreferences::name() const 0079 { 0080 return i18n("Language Support"); 0081 } 0082 0083 QString LanguagePreferences::fullName() const 0084 { 0085 return i18n("Configure Code-Completion and Semantic Highlighting"); 0086 } 0087 0088 QIcon LanguagePreferences::icon() const 0089 { 0090 return QIcon::fromTheme(QStringLiteral("page-zoom")); 0091 } 0092 0093 } 0094 0095 #include "moc_languagepreferences.cpp"