File indexing completed on 2024-05-12 04:38:19
0001 /* 0002 SPDX-FileCopyrightText: 2008 Cédric Pasteur <cedric.pasteur@free.fr> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "sourceformattersettings.h" 0008 0009 #include <KLocalizedString> 0010 #include <KConfigGroup> 0011 0012 #include <shell/core.h> 0013 #include <shell/sourceformattercontroller.h> 0014 0015 #include "debug.h" 0016 0017 using namespace KDevelop; 0018 0019 SourceFormatterSettings::SourceFormatterSettings(QWidget* parent) 0020 : KDevelop::ConfigPage(nullptr, nullptr, parent) 0021 { 0022 setupUi(this); 0023 0024 // Widgets are managed manually, so we must notify ConfigDialog when something 0025 // changes. Otherwise it will not enable "Apply" button and won't call apply(). 0026 for (auto* checkbox : {chkKateOverrideIndentation, chkKateModelines}) { 0027 connect(checkbox, &QCheckBox::toggled, this, &SourceFormatterSettings::changed); 0028 } 0029 connect(formatterSelectionEdit, &SourceFormatterSelectionEdit::changed, 0030 this, &SourceFormatterSettings::changed); 0031 } 0032 0033 SourceFormatterSettings::~SourceFormatterSettings() 0034 { 0035 } 0036 0037 void SourceFormatterSettings::reset() 0038 { 0039 KConfigGroup sessionConfig = Core::self()->sourceFormatterControllerInternal()->sessionConfig(); 0040 0041 bool b = blockSignals( true ); 0042 chkKateModelines->blockSignals( !b ); 0043 chkKateOverrideIndentation->blockSignals( !b ); 0044 chkKateModelines->setChecked(sessionConfig.readEntry(SourceFormatterController::kateModeLineConfigKey(), false)); 0045 chkKateOverrideIndentation->setChecked(sessionConfig.readEntry(SourceFormatterController::kateOverrideIndentationConfigKey(), false)); 0046 blockSignals( b ); 0047 chkKateModelines->blockSignals( b ); 0048 chkKateOverrideIndentation->blockSignals( b ); 0049 0050 formatterSelectionEdit->loadSettings(sessionConfig); 0051 } 0052 0053 void SourceFormatterSettings::apply() 0054 { 0055 KConfigGroup sessionConfig = Core::self()->sourceFormatterControllerInternal()->sessionConfig(); 0056 0057 sessionConfig.writeEntry( SourceFormatterController::kateModeLineConfigKey(), chkKateModelines->isChecked() ); 0058 sessionConfig.writeEntry( SourceFormatterController::kateOverrideIndentationConfigKey(), chkKateOverrideIndentation->isChecked() ); 0059 0060 formatterSelectionEdit->saveSettings(sessionConfig); 0061 0062 sessionConfig.sync(); 0063 0064 Core::self()->sourceFormatterControllerInternal()->settingsChanged(); 0065 } 0066 0067 void SourceFormatterSettings::defaults() 0068 { 0069 // do nothing 0070 } 0071 0072 0073 QString SourceFormatterSettings::name() const 0074 { 0075 return i18n("Source Formatter"); 0076 } 0077 0078 QString SourceFormatterSettings::fullName() const 0079 { 0080 return i18n("Configure Source Formatter"); 0081 } 0082 0083 QIcon SourceFormatterSettings::icon() const 0084 { 0085 return QIcon::fromTheme(QStringLiteral("text-field")); 0086 } 0087 0088 #include "moc_sourceformattersettings.cpp"