From 3b56bab68b9e47180072d1dec590e59a79c510af Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 9 Mar 2023 21:08:08 +0800 Subject: [PATCH] refactor: Don't implement custom indent options for C/C++ for now. --- RedPandaIDE/RedPandaIDE.pro | 3 ++ RedPandaIDE/editor.cpp | 20 -------- RedPandaIDE/settings.cpp | 8 ++-- .../settingsdialog/languagecformatwidget.cpp | 30 ++++++++++++ .../settingsdialog/languagecformatwidget.h | 28 +++++++++++ .../settingsdialog/languagecformatwidget.ui | 48 +++++++++++++++++++ RedPandaIDE/settingsdialog/settingsdialog.cpp | 3 ++ 7 files changed, 116 insertions(+), 24 deletions(-) create mode 100644 RedPandaIDE/settingsdialog/languagecformatwidget.cpp create mode 100644 RedPandaIDE/settingsdialog/languagecformatwidget.h create mode 100644 RedPandaIDE/settingsdialog/languagecformatwidget.ui diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 609c1404..a14058e5 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -129,6 +129,7 @@ SOURCES += \ settingsdialog/executorproblemsetwidget.cpp \ settingsdialog/formattergeneralwidget.cpp \ settingsdialog/languageasmgenerationwidget.cpp \ + settingsdialog/languagecformatwidget.cpp \ settingsdialog/projectcompileparamaterswidget.cpp \ settingsdialog/projectcompilerwidget.cpp \ settingsdialog/projectdirectorieswidget.cpp \ @@ -264,6 +265,7 @@ HEADERS += \ settingsdialog/executorproblemsetwidget.h \ settingsdialog/formattergeneralwidget.h \ settingsdialog/languageasmgenerationwidget.h \ + settingsdialog/languagecformatwidget.h \ settingsdialog/projectcompileparamaterswidget.h \ settingsdialog/projectcompilerwidget.h \ settingsdialog/projectdirectorieswidget.h \ @@ -371,6 +373,7 @@ FORMS += \ settingsdialog/executorproblemsetwidget.ui \ settingsdialog/formattergeneralwidget.ui \ settingsdialog/languageasmgenerationwidget.ui \ + settingsdialog/languagecformatwidget.ui \ settingsdialog/projectcompileparamaterswidget.ui \ settingsdialog/projectcompilerwidget.ui \ settingsdialog/projectdirectorieswidget.ui \ diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 132ab07a..65f9c0db 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -117,13 +117,6 @@ Editor::Editor(QWidget *parent, const QString& filename, setUseCodeFolding(false); } - if (formatter()) { - if (formatter()->supportLanguage()==QSynedit::ProgrammingLanguage::CPP) { - formatter()->setOption("IndentClassMemberVisibilityKeywords",pSettings->languages().indentCClassMemberVisibilityKeywords()); - formatter()->setOption("IndentSwitchCases",pSettings->languages().indentCSwitchCaseKeywords()); - } - } - if (mProject) { if (syntaxer && syntaxer->language() == QSynedit::ProgrammingLanguage::CPP) mParser = mProject->cppParser(); @@ -495,12 +488,6 @@ bool Editor::saveAs(const QString &name, bool fromProject){ setFormatter(syntaxerManager.getFormatter(QSynedit::ProgrammingLanguage::Unknown)); } setSyntaxer(newSyntaxer); - if (formatter()) { - if (formatter()->supportLanguage()==QSynedit::ProgrammingLanguage::CPP) { - formatter()->setOption("IndentClassMemberVisibilityKeywords",pSettings->languages().indentCClassMemberVisibilityKeywords()); - formatter()->setOption("IndentSwitchCases",pSettings->languages().indentCSwitchCaseKeywords()); - } - } if (!newSyntaxer || newSyntaxer->language() != QSynedit::ProgrammingLanguage::CPP) { mSyntaxIssues.clear(); @@ -5200,13 +5187,6 @@ void Editor::applySettings() } } - if (formatter()) { - if (formatter()->supportLanguage()==QSynedit::ProgrammingLanguage::CPP) { - formatter()->setOption("IndentClassMemberVisibilityKeywords",pSettings->languages().indentCClassMemberVisibilityKeywords()); - formatter()->setOption("IndentSwitchCases",pSettings->languages().indentCSwitchCaseKeywords()); - } - } - this->setUndoLimit(pSettings->editor().undoLimit()); this->setUndoMemoryUsage(pSettings->editor().undoMemoryUsage()); diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index a7455112..06b28d75 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -5961,8 +5961,8 @@ void Settings::Languages::doSave() saveValue("x86_dialect_of_asm_generated",(int)mX86DialectOfASMGenerated); //C/C++ - saveValue("ident_c_class_member_visibility_keywords",mIndentCClassMemberVisibilityKeywords); - saveValue("ident_c_switch_case_keywords",mIndentCSwitchCaseKeywords); +// saveValue("ident_c_class_member_visibility_keywords",mIndentCClassMemberVisibilityKeywords); +// saveValue("ident_c_switch_case_keywords",mIndentCSwitchCaseKeywords); } void Settings::Languages::doLoad() @@ -5973,8 +5973,8 @@ void Settings::Languages::doLoad() //C/C++ - mIndentCClassMemberVisibilityKeywords = boolValue("ident_c_class_member_visibility_keywords",true); - mIndentCSwitchCaseKeywords = boolValue("ident_c_switch_case_keywords",true); +// mIndentCClassMemberVisibilityKeywords = boolValue("ident_c_class_member_visibility_keywords",false); +// mIndentCSwitchCaseKeywords = boolValue("ident_c_switch_case_keywords",false); } bool Settings::Languages::noSEHDirectivesWhenGenerateASM() const diff --git a/RedPandaIDE/settingsdialog/languagecformatwidget.cpp b/RedPandaIDE/settingsdialog/languagecformatwidget.cpp new file mode 100644 index 00000000..d597412e --- /dev/null +++ b/RedPandaIDE/settingsdialog/languagecformatwidget.cpp @@ -0,0 +1,30 @@ +#include "languagecformatwidget.h" +#include "ui_languagecformatwidget.h" +#include "../settings.h" +#include "../mainwindow.h" + +LanguageCFormatWidget::LanguageCFormatWidget(const QString &name, const QString &group, QWidget *parent) : + SettingsWidget(name,group,parent), + ui(new Ui::LanguageCFormatWidget) +{ + ui->setupUi(this); +} + +LanguageCFormatWidget::~LanguageCFormatWidget() +{ + delete ui; +} + +void LanguageCFormatWidget::doLoad() +{ + ui->chkIndentCaseKeywords->setChecked(pSettings->languages().indentCSwitchCaseKeywords()); + ui->chkIndentClassMemberVisibilityMembers->setChecked(pSettings->languages().indentCClassMemberVisibilityKeywords()); +} + +void LanguageCFormatWidget::doSave() +{ + pSettings->languages().setIndentCSwitchCaseKeywords(ui->chkIndentCaseKeywords->isChecked()); + pSettings->languages().setIndentCClassMemberVisibilityKeywords(ui->chkIndentClassMemberVisibilityMembers->isChecked()); + pSettings->languages().save(); + pMainWindow->updateEditorSettings(); +} diff --git a/RedPandaIDE/settingsdialog/languagecformatwidget.h b/RedPandaIDE/settingsdialog/languagecformatwidget.h new file mode 100644 index 00000000..602244c6 --- /dev/null +++ b/RedPandaIDE/settingsdialog/languagecformatwidget.h @@ -0,0 +1,28 @@ +#ifndef LANGUAGECFORMATWIDGET_H +#define LANGUAGECFORMATWIDGET_H + +#include +#include "settingswidget.h" + +namespace Ui { +class LanguageCFormatWidget; +} + +class LanguageCFormatWidget : public SettingsWidget +{ + Q_OBJECT + +public: + explicit LanguageCFormatWidget(const QString& name, const QString& group, QWidget *parent = nullptr); + ~LanguageCFormatWidget(); + +private: + Ui::LanguageCFormatWidget *ui; + + // SettingsWidget interface +protected: + void doLoad() override; + void doSave() override; +}; + +#endif // LANGUAGECFORMATWIDGET_H diff --git a/RedPandaIDE/settingsdialog/languagecformatwidget.ui b/RedPandaIDE/settingsdialog/languagecformatwidget.ui new file mode 100644 index 00000000..11f9bb73 --- /dev/null +++ b/RedPandaIDE/settingsdialog/languagecformatwidget.ui @@ -0,0 +1,48 @@ + + + LanguageCFormatWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Indent case/switch + + + + + + + Indent private/public/protected + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/RedPandaIDE/settingsdialog/settingsdialog.cpp b/RedPandaIDE/settingsdialog/settingsdialog.cpp index 58162751..b4de9ee2 100644 --- a/RedPandaIDE/settingsdialog/settingsdialog.cpp +++ b/RedPandaIDE/settingsdialog/settingsdialog.cpp @@ -40,6 +40,7 @@ #include "debuggeneralwidget.h" #include "formattergeneralwidget.h" #include "languageasmgenerationwidget.h" +#include "languagecformatwidget.h" #include "projectgeneralwidget.h" #include "projectfileswidget.h" #include "projectcompilerwidget.h" @@ -207,6 +208,8 @@ PSettingsDialog SettingsDialog::optionDialog() widget = new EditorCustomCTypeKeywordsWidget(tr("Custom C/C++ Keywords"),tr("Languages")); dialog->addWidget(widget); +// widget = new LanguageCFormatWidget(tr("C/C++ Format"),tr("Languages")); +// dialog->addWidget(widget); widget = new LanguageAsmGenerationWidget(tr("ASM Generation"),tr("Languages")); dialog->addWidget(widget);