refactor: Don't implement custom indent options for C/C++ for now.

This commit is contained in:
Roy Qu 2023-03-09 21:08:08 +08:00
parent 45578a2603
commit 3b56bab68b
7 changed files with 116 additions and 24 deletions

View File

@ -129,6 +129,7 @@ SOURCES += \
settingsdialog/executorproblemsetwidget.cpp \ settingsdialog/executorproblemsetwidget.cpp \
settingsdialog/formattergeneralwidget.cpp \ settingsdialog/formattergeneralwidget.cpp \
settingsdialog/languageasmgenerationwidget.cpp \ settingsdialog/languageasmgenerationwidget.cpp \
settingsdialog/languagecformatwidget.cpp \
settingsdialog/projectcompileparamaterswidget.cpp \ settingsdialog/projectcompileparamaterswidget.cpp \
settingsdialog/projectcompilerwidget.cpp \ settingsdialog/projectcompilerwidget.cpp \
settingsdialog/projectdirectorieswidget.cpp \ settingsdialog/projectdirectorieswidget.cpp \
@ -264,6 +265,7 @@ HEADERS += \
settingsdialog/executorproblemsetwidget.h \ settingsdialog/executorproblemsetwidget.h \
settingsdialog/formattergeneralwidget.h \ settingsdialog/formattergeneralwidget.h \
settingsdialog/languageasmgenerationwidget.h \ settingsdialog/languageasmgenerationwidget.h \
settingsdialog/languagecformatwidget.h \
settingsdialog/projectcompileparamaterswidget.h \ settingsdialog/projectcompileparamaterswidget.h \
settingsdialog/projectcompilerwidget.h \ settingsdialog/projectcompilerwidget.h \
settingsdialog/projectdirectorieswidget.h \ settingsdialog/projectdirectorieswidget.h \
@ -371,6 +373,7 @@ FORMS += \
settingsdialog/executorproblemsetwidget.ui \ settingsdialog/executorproblemsetwidget.ui \
settingsdialog/formattergeneralwidget.ui \ settingsdialog/formattergeneralwidget.ui \
settingsdialog/languageasmgenerationwidget.ui \ settingsdialog/languageasmgenerationwidget.ui \
settingsdialog/languagecformatwidget.ui \
settingsdialog/projectcompileparamaterswidget.ui \ settingsdialog/projectcompileparamaterswidget.ui \
settingsdialog/projectcompilerwidget.ui \ settingsdialog/projectcompilerwidget.ui \
settingsdialog/projectdirectorieswidget.ui \ settingsdialog/projectdirectorieswidget.ui \

View File

@ -117,13 +117,6 @@ Editor::Editor(QWidget *parent, const QString& filename,
setUseCodeFolding(false); 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 (mProject) {
if (syntaxer && syntaxer->language() == QSynedit::ProgrammingLanguage::CPP) if (syntaxer && syntaxer->language() == QSynedit::ProgrammingLanguage::CPP)
mParser = mProject->cppParser(); mParser = mProject->cppParser();
@ -495,12 +488,6 @@ bool Editor::saveAs(const QString &name, bool fromProject){
setFormatter(syntaxerManager.getFormatter(QSynedit::ProgrammingLanguage::Unknown)); setFormatter(syntaxerManager.getFormatter(QSynedit::ProgrammingLanguage::Unknown));
} }
setSyntaxer(newSyntaxer); 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) { if (!newSyntaxer || newSyntaxer->language() != QSynedit::ProgrammingLanguage::CPP) {
mSyntaxIssues.clear(); 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->setUndoLimit(pSettings->editor().undoLimit());
this->setUndoMemoryUsage(pSettings->editor().undoMemoryUsage()); this->setUndoMemoryUsage(pSettings->editor().undoMemoryUsage());

View File

@ -5961,8 +5961,8 @@ void Settings::Languages::doSave()
saveValue("x86_dialect_of_asm_generated",(int)mX86DialectOfASMGenerated); saveValue("x86_dialect_of_asm_generated",(int)mX86DialectOfASMGenerated);
//C/C++ //C/C++
saveValue("ident_c_class_member_visibility_keywords",mIndentCClassMemberVisibilityKeywords); // saveValue("ident_c_class_member_visibility_keywords",mIndentCClassMemberVisibilityKeywords);
saveValue("ident_c_switch_case_keywords",mIndentCSwitchCaseKeywords); // saveValue("ident_c_switch_case_keywords",mIndentCSwitchCaseKeywords);
} }
void Settings::Languages::doLoad() void Settings::Languages::doLoad()
@ -5973,8 +5973,8 @@ void Settings::Languages::doLoad()
//C/C++ //C/C++
mIndentCClassMemberVisibilityKeywords = boolValue("ident_c_class_member_visibility_keywords",true); // mIndentCClassMemberVisibilityKeywords = boolValue("ident_c_class_member_visibility_keywords",false);
mIndentCSwitchCaseKeywords = boolValue("ident_c_switch_case_keywords",true); // mIndentCSwitchCaseKeywords = boolValue("ident_c_switch_case_keywords",false);
} }
bool Settings::Languages::noSEHDirectivesWhenGenerateASM() const bool Settings::Languages::noSEHDirectivesWhenGenerateASM() const

View File

@ -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();
}

View File

@ -0,0 +1,28 @@
#ifndef LANGUAGECFORMATWIDGET_H
#define LANGUAGECFORMATWIDGET_H
#include <QWidget>
#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

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LanguageCFormatWidget</class>
<widget class="QWidget" name="LanguageCFormatWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="chkIndentCaseKeywords">
<property name="text">
<string>Indent case/switch</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkIndentClassMemberVisibilityMembers">
<property name="text">
<string>Indent private/public/protected</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -40,6 +40,7 @@
#include "debuggeneralwidget.h" #include "debuggeneralwidget.h"
#include "formattergeneralwidget.h" #include "formattergeneralwidget.h"
#include "languageasmgenerationwidget.h" #include "languageasmgenerationwidget.h"
#include "languagecformatwidget.h"
#include "projectgeneralwidget.h" #include "projectgeneralwidget.h"
#include "projectfileswidget.h" #include "projectfileswidget.h"
#include "projectcompilerwidget.h" #include "projectcompilerwidget.h"
@ -207,6 +208,8 @@ PSettingsDialog SettingsDialog::optionDialog()
widget = new EditorCustomCTypeKeywordsWidget(tr("Custom C/C++ Keywords"),tr("Languages")); widget = new EditorCustomCTypeKeywordsWidget(tr("Custom C/C++ Keywords"),tr("Languages"));
dialog->addWidget(widget); dialog->addWidget(widget);
// widget = new LanguageCFormatWidget(tr("C/C++ Format"),tr("Languages"));
// dialog->addWidget(widget);
widget = new LanguageAsmGenerationWidget(tr("ASM Generation"),tr("Languages")); widget = new LanguageAsmGenerationWidget(tr("ASM Generation"),tr("Languages"));
dialog->addWidget(widget); dialog->addWidget(widget);