File indexing completed on 2024-04-28 05:48:37
0001 // SPDX-FileCopyrightText: 2023 Kåre Särs <kare.sars@iki.fi> 0002 // 0003 // SPDX-License-Identifier: LGPL-2.0-or-later * 0004 // 0005 // This program is distributed in the hope that it will be useful, 0006 // but WITHOUT ANY WARRANTY; without even the implied warranty of 0007 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0008 // General Public License for more details. 0009 // You should have received a copy of the GNU General Public 0010 // License along with this program. If not, see <http://www.gnu.org/licenses/>. 0011 0012 #include "buildconfig.h" 0013 0014 #include <QCheckBox> 0015 #include <QDebug> 0016 #include <QVBoxLayout> 0017 0018 #include <KConfigGroup> 0019 #include <KLocalizedString> 0020 #include <KSharedConfig> 0021 0022 /******************************************************************/ 0023 KateBuildConfigPage::KateBuildConfigPage(QWidget *parent) 0024 : KTextEditor::ConfigPage(parent) 0025 { 0026 m_useDiagnosticsCB = new QCheckBox(i18n("Add errors and warnings to Diagnostics"), this); 0027 m_autoSwitchToOutput = new QCheckBox(i18n("Automatically switch to output pane on executing the selected target"), this); 0028 QVBoxLayout *layout = new QVBoxLayout(this); 0029 layout->addWidget(m_useDiagnosticsCB); 0030 layout->addWidget(m_autoSwitchToOutput); 0031 layout->addStretch(1); 0032 reset(); 0033 for (const auto *item : {m_useDiagnosticsCB, m_autoSwitchToOutput}) 0034 connect(item, &QCheckBox::stateChanged, this, &KateBuildConfigPage::changed); 0035 } 0036 0037 /******************************************************************/ 0038 QString KateBuildConfigPage::name() const 0039 { 0040 return i18n("Build & Run"); 0041 } 0042 0043 /******************************************************************/ 0044 QString KateBuildConfigPage::fullName() const 0045 { 0046 return i18n("Build & Run Settings"); 0047 } 0048 0049 /******************************************************************/ 0050 QIcon KateBuildConfigPage::icon() const 0051 { 0052 return QIcon::fromTheme(QStringLiteral("run-build-clean")); 0053 } 0054 0055 /******************************************************************/ 0056 void KateBuildConfigPage::apply() 0057 { 0058 Q_ASSERT(m_useDiagnosticsCB); 0059 KConfigGroup config(KSharedConfig::openConfig(), QStringLiteral("BuildConfig")); 0060 config.writeEntry("UseDiagnosticsOutput", m_useDiagnosticsCB->isChecked()); 0061 config.writeEntry("AutoSwitchToOutput", m_autoSwitchToOutput->isChecked()); 0062 config.sync(); 0063 Q_EMIT configChanged(); 0064 } 0065 0066 /******************************************************************/ 0067 void KateBuildConfigPage::reset() 0068 { 0069 Q_ASSERT(m_useDiagnosticsCB); 0070 KConfigGroup config(KSharedConfig::openConfig(), QStringLiteral("BuildConfig")); 0071 m_useDiagnosticsCB->setChecked(config.readEntry(QStringLiteral("UseDiagnosticsOutput"), true)); 0072 m_autoSwitchToOutput->setChecked(config.readEntry(QStringLiteral("AutoSwitchToOutput"), true)); 0073 } 0074 0075 /******************************************************************/ 0076 void KateBuildConfigPage::defaults() 0077 { 0078 Q_ASSERT(m_useDiagnosticsCB); 0079 m_useDiagnosticsCB->setCheckState(Qt::CheckState::Checked); 0080 m_autoSwitchToOutput->setCheckState(Qt::CheckState::Checked); 0081 } 0082 0083 #include "moc_buildconfig.cpp"