diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro
index d2c7931a..be2b4711 100644
--- a/RedPandaIDE/RedPandaIDE.pro
+++ b/RedPandaIDE/RedPandaIDE.pro
@@ -185,6 +185,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
RESOURCES += \
+ codes.qrc \
colorschemes.qrc \
themes/dark/dark.qrc \
themes/light/light.qrc \
diff --git a/RedPandaIDE/RedPandaIDE_zh_CN.ts b/RedPandaIDE/RedPandaIDE_zh_CN.ts
index e8e4ac5d..0904f181 100644
--- a/RedPandaIDE/RedPandaIDE_zh_CN.ts
+++ b/RedPandaIDE/RedPandaIDE_zh_CN.ts
@@ -573,20 +573,20 @@ Are you really want to continue?
要剪切的内容超过了字符数限制!
-
-
-
+
+
+
Ctrl+单击以获取更多信息
-
-
+
+
未找到符号'%1'!
-
+
只读
@@ -1319,371 +1319,371 @@ Are you really want to continue?
预定义排版方案
-
+
基本
-
+
花括号修改
-
+
Attach spaces to namespace statements
添加花括号到命名空间(namespace)定义
-
+
Attach spaces to classes
添加花括号到类(class)定义
-
+
Attach spaces to class inline function definitions
添加花括号到类内联函数(inline function)定义
-
+
Attach spaces to extern "C" statements
添加花括号到extern "C"语句
-
+
将do-while语句的while部分与结尾花括号合并
-
+
将制表符(Tab)转换为相应数量的空格
-
+
缩进1
-
+
使用什么符号缩进:
-
+
使用空格缩进
-
+
空格
-
+
使用制表符缩进
-
+
制表符
-
+
缩进宽度
-
+
连续行的缩进量:
-
+
属于同一个条件语句('if','while',...)的条件的最小缩进量
-
+
连续行的最大缩进空格数:
-
+
缩进2
-
+
缩进标签(label)
-
+
缩进类定义(class)
-
+
缩进命名空间定义(namespace)
-
+
缩进类访问限制符('public','private'...)
-
+
在括号'('或赋值号'='后缩进
-
+
缩进预处理条件指令('#if','#else',...)
-
+
缩进多行#define语句
-
+
缩进在第一列开始的行注释
-
+
缩进预处理代码段
-
+
缩进switch语句
-
+
缩进case语句
-
+
填充1
-
+
在运算符周围插入空格
-
+
在逗号后插入空格
-
+
在语句和括号间插入空格('if','for'...)
-
+
在括号外侧加入空格
-
+
在括号内侧加入空格
-
+
在代码段之间加入空行
-
+
Insert empy lines around all blocks
在所有代码段之间加入空格
-
+
在多层嵌套括号的最外侧加入空格
-
+
在括号两侧加入空格
-
+
填充2
-
+
删除所有空行。不影响填充选项自动插入的空行。
-
+
将指针运算符('*')放在:
-
+
将连续的多个空行合并成一个。不影响填充选项自动插入的空行。
-
-
+
+
类型侧(左侧)
-
+
使用前一行的缩进空格填充空行
-
-
+
+
中间
-
+
<html><head/><body><p>预定义排版方案说明</p></body></html>
-
-
+
+
名称侧(右侧)
-
+
删除括号周围的多余空格
-
+
将引用运算符('&')放在:
-
-
+
+
不变
-
+
其它1
-
+
对单行条件('if','while','else')语句分行
-
+
用花括号括起单行条件体
-
+
对结束语句('else','catch')和它之前的花括号断行
-
+
删除括起单行条件体语句的花括号
-
+
将'else if'语句断成两行
-
+
对条件和条件体语句在同一行上的,删除括起条件体语句的花括号
-
+
其它2
-
+
将函数声明中的函数名和返回值类型放在同一行
-
+
将函数声明中的函数名和返回值类型断成两行
-
+
将函数定义中的函数名和返回值类型断成两行
-
+
将函数定义中的函数名和返回值类型放在同一行
-
+
不对同一行上的多个代码段断行
-
+
不对同一行上的多条语句断行
-
+
其它3
-
+
在断行时,将逻辑条件放在前一行的末尾
-
+
关闭模板定义末尾的尖括号
-
+
删除多行注释前的'*'并缩进注释内容
-
+
对超过指定长度的行断行
-
+
字符
@@ -1691,179 +1691,187 @@ Are you really want to continue?
FormatterStyleModel
-
+
缺省
-
+
左花括号不变,右花括号单独一行。
-
+
Allman
-
-
-
+
花括号单独一行。
-
+
Java
-
+
+
+ 花括号不断行。
+
+
+
- Kernighan & Ritchie
+ K&R
-
+
+
+ Linux风格花括号
+
+
+
- Kernighan & Ritchie
+ Stroustrup
-
+
Linux风格花括号,对条件结束语句(如do-while的while)断行。
-
+
Whitesmith
-
+
花括号独立成行,并且缩进。
-
+
类代码段和switch代码段缩进。
-
+
VTK
-
+
除左花括号外,其他花括号独立断行且缩进。
-
+
Ratliff
-
+
花括号不断行,但是缩进
-
+
GNU
-
+
花括号短号,代码段缩进
-
+
Linux
-
+
Linux风格花括号,最小条件缩进为1.5单位。
-
+
Horstmann
-
+
Run-in花括号,switch语句缩进
-
+
One True Brace
-
+
Linux封号花括号,所有条件语句条件花括号
-
+
Google
-
+
花括号不断行,类访问限定符缩进
-
+
Mozilla
-
+
Linux风格花括号, 结构和枚举的花括号断行, 命名空间的花括号不断行。
-
+
Webkit
-
+
Linux风格花括号, 条件结束语句(如do-while的while)不断行
-
+
Pico
-
+
Run-in左花括号,右花括号不断行
-
+
启用保持单行代码段和保持多语句单行选项。
-
+
Lisp
-
+
花括号不断行。
-
+
启用保持多语句单行选项。
@@ -2912,7 +2920,7 @@ Are you really want to continue?
无标题
-
+
下标"%1"越界
diff --git a/RedPandaIDE/codes.qrc b/RedPandaIDE/codes.qrc
new file mode 100644
index 00000000..8c48bfa0
--- /dev/null
+++ b/RedPandaIDE/codes.qrc
@@ -0,0 +1,5 @@
+
+
+ resources/formatdemo.cpp
+
+
diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp
index 81157740..b4114415 100644
--- a/RedPandaIDE/settings.cpp
+++ b/RedPandaIDE/settings.cpp
@@ -2704,6 +2704,199 @@ Settings::CodeFormatter::CodeFormatter(Settings *settings):
}
+QStringList Settings::CodeFormatter::getArguments()
+{
+ QStringList result;
+ switch(mBraceStyle) {
+ case FormatterBraceStyle::fbsDefault:
+ break;
+ case FormatterBraceStyle::fbsAllman:
+ result.append("--style=allman");
+ break;
+ case FormatterBraceStyle::fbsJava:
+ result.append("--style=java");
+ break;
+ case FormatterBraceStyle::fbsKR:
+ result.append("--style=kr");
+ break;
+ case FormatterBraceStyle::fbsStroustrup:
+ result.append("--style=stroustrup");
+ break;
+ case FormatterBraceStyle::fbsWitesmith:
+ result.append("--style=whitesmith");
+ break;
+ case FormatterBraceStyle::fbsVtk:
+ result.append("--style=vtk");
+ break;
+ case FormatterBraceStyle::fbsRatliff:
+ result.append("--style=ratliff");
+ break;
+ case FormatterBraceStyle::fbsGNU:
+ result.append("--style=gnu");
+ break;
+ case FormatterBraceStyle::fbsLinux:
+ result.append("--style=linux");
+ break;
+ case FormatterBraceStyle::fbsHorstmann:
+ result.append("--style=horstmann");
+ break;
+ case FormatterBraceStyle::fbs1TBS:
+ result.append("--style=1tbs");
+ break;
+ case FormatterBraceStyle::fbsGoogle:
+ result.append("--style=google");
+ break;
+ case FormatterBraceStyle::fbsMozilla:
+ result.append("--style=mozilla");
+ break;
+ case FormatterBraceStyle::fbsWebkit:
+ result.append("--style=webkit");
+ break;
+ case FormatterBraceStyle::fbsPico:
+ result.append("--style=pico");
+ break;
+ case FormatterBraceStyle::fbsLisp:
+ result.append("--style=lisp");
+ break;
+ };
+ switch(mIndentStyle) {
+ case FormatterIndentType::fitTab:
+ result.append(QString("--indent=tab=%1").arg(mTabWidth));
+ break;
+ case FormatterIndentType::fitSpace:
+ result.append(QString("--indent=spaces=%1").arg(mTabWidth));
+ break;
+ }
+ if (mAttachNamespaces)
+ result.append("--attach-namespaces");
+ if (mAttachClasses)
+ result.append("--attach-classes");
+ if (mAttachInlines)
+ result.append("--attach-inlines");
+ if (mAttachExternC)
+ result.append("--attach-extern-c");
+ if (mAttachClosingWhile)
+ result.append("--attach-closing-while");
+ if (mIndentClasses)
+ result.append("--indent-classes");
+ if (mIndentModifiers)
+ result.append("--indent-modifiers");
+ if (mIndentSwitches)
+ result.append("--indent-switches");
+ if (mIndentCases)
+ result.append("--indent-cases");
+ if (mIndentNamespaces)
+ result.append("--indent-namespaces");
+ if (mIndentAfterParens)
+ result.append("--indent-after-parens");
+ if (mIndentContinuation!=1)
+ result.append(QString("--indent-continuation=%1").arg(mIndentContinuation));
+ if (mIndentLabels)
+ result.append("--indent-labels");
+ if (mIndentPreprocBlock)
+ result.append("--indent-preproc-block");
+ if (mIndentPreprocCond)
+ result.append("--indent-preproc-cond");
+ if (mIndentPreprocDefine)
+ result.append("--indent-preproc-define");
+ if (mIndentCol1Comments)
+ result.append("--indent-col1-comments");
+ if (mMinConditionalIndent!=2)
+ result.append(QString("--min-conditional-indent=%1").arg(mMinConditionalIndent));
+ if (mMaxContinuationIndent!=40)
+ result.append(QString("--max-continuation-indent=%1").arg(mMaxContinuationIndent));
+ if (mBreakBlocks)
+ result.append("--break-blocks");
+ if (mBreakBlocksAll)
+ result.append("--break-blocks=all");
+ if (mPadOper)
+ result.append("--pad-oper");
+ if (mPadComma)
+ result.append("--pad-comma");
+ if (mPadParen)
+ result.append("--pad-paren");
+ if (mPadParenOut)
+ result.append("--pad-paren-out");
+ if (mPadFirstParenOut)
+ result.append("--pad-first-paren-out");
+ if (mPadParenIn)
+ result.append("--pad-paren-in");
+ if (mPadHeader)
+ result.append("--pad-header");
+ if (mUnpadParen)
+ result.append("--unpad-paren");
+ if (mDeleteEmptyLines)
+ result.append("--delete-empty-lines");
+ if (mDeleteMultipleEmptyLines)
+ result.append("--delete-multiple-empty-lines");
+ if (mFillEmptyLines)
+ result.append("--fill-empty-lines");
+ switch(mAlignPointerStyle) {
+ case FormatterOperatorAlign::foaNone:
+ break;
+ case FormatterOperatorAlign::foaType:
+ result.append("--align-pointer=type");
+ break;
+ case FormatterOperatorAlign::foaMiddle:
+ result.append("--align-pointer=middle");
+ break;
+ case FormatterOperatorAlign::foaName:
+ result.append("--align-pointer=name");
+ break;
+ }
+ switch(mAlignReferenceStyle) {
+ case FormatterOperatorAlign::foaNone:
+ break;
+ case FormatterOperatorAlign::foaType:
+ result.append("--align-reference=type");
+ break;
+ case FormatterOperatorAlign::foaMiddle:
+ result.append("--align-reference=middle");
+ break;
+ case FormatterOperatorAlign::foaName:
+ result.append("--align-reference=name");
+ break;
+ }
+
+ if (mBreakClosingBraces)
+ result.append("--break-closing-braces");
+ if (mBreakElseIf)
+ result.append("--break-elseifs");
+ if (mBreakOneLineHeaders)
+ result.append("--break-one-line-headers");
+ if (mAddBraces)
+ result.append("--add-braces");
+ if (mAddOneLineBraces)
+ result.append("--add-one-line-braces");
+ if (mRemoveBraces)
+ result.append("--remove-braces");
+ if (mBreakReturnType)
+ result.append("--break-return-type");
+ if (mBreakReturnTypeDecl)
+ result.append("--break-return-type-decl");
+ if (mAttachReturnType)
+ result.append("--attach-return-type");
+ if (mAttachReturnTypeDecl)
+ result.append("--attach-return-type-decl");
+ if (mKeepOneLineBlocks)
+ result.append("--keep-one-line-blocks");
+ if (mKeepOneLineStatements)
+ result.append("--keep-one-line-statements");
+ if (mConvertTabs)
+ result.append("--convert-tabs");
+ if (mCloseTemplates)
+ result.append("--close-templates");
+ if (mRemoveCommentPrefix)
+ result.append("--remove-comment-prefix");
+ if (mBreakMaxCodeLength) {
+ result.append(QString("--max-code-length=%1").arg(mMaxCodeLength));
+ if (mBreakAfterLogical)
+ result.append("--break-after-logical");
+ }
+
+ return result;
+}
+
int Settings::CodeFormatter::indentStyle() const
{
return mIndentStyle;
diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h
index 0b377926..abd33bc7 100644
--- a/RedPandaIDE/settings.h
+++ b/RedPandaIDE/settings.h
@@ -468,6 +468,7 @@ public:
class CodeFormatter: public _Base {
public:
explicit CodeFormatter(Settings* settings);
+ QStringList getArguments();
int braceStyle() const;
void setBraceStyle(int newBraceStyle);
diff --git a/RedPandaIDE/settingsdialog/formattergeneralwidget.cpp b/RedPandaIDE/settingsdialog/formattergeneralwidget.cpp
index f3898ea4..51189aa2 100644
--- a/RedPandaIDE/settingsdialog/formattergeneralwidget.cpp
+++ b/RedPandaIDE/settingsdialog/formattergeneralwidget.cpp
@@ -11,7 +11,8 @@ FormatterGeneralWidget::FormatterGeneralWidget(const QString& name, const QStrin
connect(ui->cbBraceStyle, QOverload::of(&QComboBox::currentIndexChanged),
this, &FormatterGeneralWidget::onBraceStyleChanged);
ui->editDemo->setReadOnly(true);
- ui->editDemo->lines()->setText("int test;");
+ connect(this, &SettingsWidget::settingsChanged,
+ this, &FormatterGeneralWidget::updateDemo);
}
FormatterGeneralWidget::~FormatterGeneralWidget()
@@ -30,7 +31,13 @@ void FormatterGeneralWidget::onBraceStyleChanged()
void FormatterGeneralWidget::doLoad()
{
Settings::CodeFormatter& format = pSettings->codeFormatter();
- ui->cbBraceStyle->setCurrentIndex(format.braceStyle());
+ for (int i=0;istyle == format.braceStyle()) {
+ ui->cbBraceStyle->setCurrentIndex(i);
+ break;
+ }
+ }
if (format.indentStyle() == FormatterIndentType::fitSpace) {
ui->rbIndentSpaces->setChecked(true);
} else {
@@ -115,87 +122,13 @@ void FormatterGeneralWidget::doLoad()
ui->chkBreakMaxCodeLength->setChecked(format.breakMaxCodeLength());
ui->spinMaxCodeLength->setValue(format.maxCodeLength());
ui->chkBreakAfterLogical->setChecked(format.breakAfterLogical());
+ updateDemo();
}
void FormatterGeneralWidget::doSave()
{
Settings::CodeFormatter& format = pSettings->codeFormatter();
- if (ui->cbBraceStyle->currentIndex()>0)
- format.setBraceStyle(ui->cbBraceStyle->currentIndex());
- if (ui->rbIndentSpaces) {
- format.setIndentStyle(FormatterIndentType::fitSpace);
- } else {
- format.setIndentStyle(FormatterIndentType::fitTab);
- }
- format.setTabWidth(ui->spinTabSize->value());
- format.setAttachNamespaces(ui->chkAttachNamespaces->isChecked());
- format.setAttachClasses(ui->chkAttachClasses->isChecked());
- format.setAttachInlines(ui->chkAttachInline->isChecked());
- format.setAttachExternC(ui->chkAttachExternC->isChecked());
- format.setAttachClosingWhile(ui->chkAttachClosingWhile->isChecked());
- format.setIndentClasses(ui->chkIndentClasses->isChecked());
- format.setIndentModifiers(ui->chkIndentModifiers->isChecked());
- format.setIndentSwitches(ui->chkIndentSwiches->isChecked());
- format.setIndentCases(ui->chkIndentCases->isChecked());
- format.setIndentNamespaces(ui->chkIndentNamespaces->isChecked());
- format.setIndentAfterParens(ui->chkIndentAfterParens->isChecked());
- format.setIndentContinuation(ui->spinIndentContinuation->value());
- format.setIndentLabels(ui->chkIndentLabels->isChecked());
- format.setIndentPreprocBlock(ui->chkIndentPreprocBlock->isChecked());
- format.setIndentPreprocCond(ui->chkIndentPreprocCond->isChecked());
- format.setIndentPreprocDefine(ui->chkIndentPreprocDefine->isChecked());
- format.setIndentCol1Comments(ui->chkIndentCol1Comments->isChecked());
- format.setMinConditionalIndent(ui->spinMinConditionalIndent->value());
- format.setMaxContinuationIndent(ui->spinMaxContinuationIndent->value());
- format.setBreakBlocks(ui->chkBreakBlocks->isChecked());
- format.setBreakBlocksAll(ui->chkBreakBlocksAll->isChecked());
- format.setPadOper(ui->chkPadOper->isChecked());
- format.setPadComma(ui->chkPadComma->isChecked());
- format.setPadParen(ui->chkPadParen->isChecked());
- format.setPadParenOut(ui->chkPadParenOut->isChecked());
- format.setPadFirstParenOut(ui->chkPadFirstParenOut->isChecked());
- format.setPadParenIn(ui->chkPadParenIn->isChecked());
- format.setPadHeader(ui->chkPadHeader->isChecked());
- format.setUnpadParen(ui->chkUnpadParen->isChecked());
- format.setDeleteEmptyLines(ui->chkDeleteEmptyLines->isChecked());
- format.setDeleteMultipleEmptyLines(ui->chkDeleteMultipleEmptyLines->isChecked());
- format.setFillEmptyLines(ui->chkFillEmptyLines->isChecked());
- if (ui->rbAlignPointNone->isChecked()) {
- format.setAlignPointerStyle(FormatterOperatorAlign::foaNone);
- } else if (ui->rbAlignPointType->isChecked()) {
- format.setAlignPointerStyle(FormatterOperatorAlign::foaType);
- } else if (ui->rbAlignPointerMiddle->isChecked()) {
- format.setAlignPointerStyle(FormatterOperatorAlign::foaMiddle);
- } else if (ui->rbAlignPointerName->isChecked()) {
- format.setAlignPointerStyle(FormatterOperatorAlign::foaName);
- }
- if (ui->rbAlignReferenceNone->isChecked()) {
- format.setAlignReferenceStyle(FormatterOperatorAlign::foaNone);
- } else if (ui->rbAlignReferenceType->isChecked()) {
- format.setAlignReferenceStyle(FormatterOperatorAlign::foaType);
- } else if (ui->rbAlignReferenceMiddle->isChecked()) {
- format.setAlignReferenceStyle(FormatterOperatorAlign::foaMiddle);
- } else if (ui->rbAlignReferenceName->isChecked()) {
- format.setAlignReferenceStyle(FormatterOperatorAlign::foaName);
- }
- format.setBreakClosingBraces(ui->chkBreakClosingBraces->isChecked());
- format.setBreakElseIf(ui->chkBreakElseIf->isChecked());
- format.setBreakOneLineHeaders(ui->chkBreakOneLineHeaders->isChecked());
- format.setAddBraces(ui->chkAddBraces->isChecked());
- format.setAddOneLineBraces(ui->chkAddOneLineBraces->isChecked());
- format.setRemoveBraces(ui->chkRemoveBraces->isChecked());
- format.setBreakReturnType(ui->chkBreakReturnType->isChecked());
- format.setBreakReturnTypeDecl(ui->chkBreakReturnTypeDecl->isChecked());
- format.setAttachReturnType(ui->chkAttachReturnType->isChecked());
- format.setAttachReturnTypeDecl(ui->chkAttachReturnTypeDecl->isChecked());
- format.setKeepOneLineBlocks(ui->chkKeepOneLineBlocks->isChecked());
- format.setKeepOneLineStatements(ui->chkKeepOneLineStatements->isChecked());
- format.setConvertTabs(ui->chkConvertTabs->isChecked());
- format.setCloseTemplates(ui->chkCloseTemplates->isChecked());
- format.setRemoveCommentPrefix(ui->chkRemoveCommentPrefix->isChecked());
- format.setBreakMaxCodeLength(ui->chkBreakMaxCodeLength->isChecked());
- format.setMaxCodeLength(ui->spinMaxCodeLength->value());
- format.setBreakAfterLogical(ui->chkBreakAfterLogical->isChecked());
+ updateCodeFormatter(format);
format.save();
}
@@ -216,13 +149,13 @@ FormatterStyleModel::FormatterStyleModel(QObject *parent):QAbstractListModel(par
mStyles.append(
std::make_shared(
tr("Java"),
- tr("Broken braces."),
+ tr("Attached braces."),
FormatterBraceStyle::fbsJava)
);
mStyles.append(
std::make_shared(
tr("K&R"),
- tr("Broken braces."),
+ tr("Linux braces."),
FormatterBraceStyle::fbsKR)
);
mStyles.append(
@@ -267,7 +200,7 @@ FormatterStyleModel::FormatterStyleModel(QObject *parent):QAbstractListModel(par
std::make_shared(
tr("Horstmann"),
tr("Run-in braces, indented switches."),
- FormatterBraceStyle::fbsHorstman)
+ FormatterBraceStyle::fbsHorstmann)
);
mStyles.append(
std::make_shared(
@@ -362,3 +295,101 @@ void FormatterGeneralWidget::on_chkBreakMaxCodeLength_stateChanged(int)
ui->chkBreakAfterLogical->setEnabled(ui->chkBreakMaxCodeLength->isChecked());
}
+void FormatterGeneralWidget::updateDemo()
+{
+ QFile file(":/codes/formatdemo.cpp");
+ if (!file.open(QFile::ReadOnly))
+ return;
+ QByteArray content = file.readAll();
+
+ Settings::CodeFormatter formatter(nullptr);
+ updateCodeFormatter(formatter);
+
+ QByteArray newContent = runAndGetOutput("astyle.exe",
+ pSettings->dirs().app(),
+ formatter.getArguments(),
+ content);
+ ui->editDemo->lines()->setText(newContent);
+}
+
+void FormatterGeneralWidget::updateCodeFormatter(Settings::CodeFormatter &format)
+{
+ PFormatterStyleItem item = mStylesModel.getStyle(ui->cbBraceStyle->currentIndex());
+ if (item)
+ format.setBraceStyle(item->style);
+ if (ui->rbIndentSpaces) {
+ format.setIndentStyle(FormatterIndentType::fitSpace);
+ } else {
+ format.setIndentStyle(FormatterIndentType::fitTab);
+ }
+ format.setTabWidth(ui->spinTabSize->value());
+ format.setAttachNamespaces(ui->chkAttachNamespaces->isChecked());
+ format.setAttachClasses(ui->chkAttachClasses->isChecked());
+ format.setAttachInlines(ui->chkAttachInline->isChecked());
+ format.setAttachExternC(ui->chkAttachExternC->isChecked());
+ format.setAttachClosingWhile(ui->chkAttachClosingWhile->isChecked());
+ format.setIndentClasses(ui->chkIndentClasses->isChecked());
+ format.setIndentModifiers(ui->chkIndentModifiers->isChecked());
+ format.setIndentSwitches(ui->chkIndentSwiches->isChecked());
+ format.setIndentCases(ui->chkIndentCases->isChecked());
+ format.setIndentNamespaces(ui->chkIndentNamespaces->isChecked());
+ format.setIndentAfterParens(ui->chkIndentAfterParens->isChecked());
+ format.setIndentContinuation(ui->spinIndentContinuation->value());
+ format.setIndentLabels(ui->chkIndentLabels->isChecked());
+ format.setIndentPreprocBlock(ui->chkIndentPreprocBlock->isChecked());
+ format.setIndentPreprocCond(ui->chkIndentPreprocCond->isChecked());
+ format.setIndentPreprocDefine(ui->chkIndentPreprocDefine->isChecked());
+ format.setIndentCol1Comments(ui->chkIndentCol1Comments->isChecked());
+ format.setMinConditionalIndent(ui->spinMinConditionalIndent->value());
+ format.setMaxContinuationIndent(ui->spinMaxContinuationIndent->value());
+ format.setBreakBlocks(ui->chkBreakBlocks->isChecked());
+ format.setBreakBlocksAll(ui->chkBreakBlocksAll->isChecked());
+ format.setPadOper(ui->chkPadOper->isChecked());
+ format.setPadComma(ui->chkPadComma->isChecked());
+ format.setPadParen(ui->chkPadParen->isChecked());
+ format.setPadParenOut(ui->chkPadParenOut->isChecked());
+ format.setPadFirstParenOut(ui->chkPadFirstParenOut->isChecked());
+ format.setPadParenIn(ui->chkPadParenIn->isChecked());
+ format.setPadHeader(ui->chkPadHeader->isChecked());
+ format.setUnpadParen(ui->chkUnpadParen->isChecked());
+ format.setDeleteEmptyLines(ui->chkDeleteEmptyLines->isChecked());
+ format.setDeleteMultipleEmptyLines(ui->chkDeleteMultipleEmptyLines->isChecked());
+ format.setFillEmptyLines(ui->chkFillEmptyLines->isChecked());
+ if (ui->rbAlignPointNone->isChecked()) {
+ format.setAlignPointerStyle(FormatterOperatorAlign::foaNone);
+ } else if (ui->rbAlignPointType->isChecked()) {
+ format.setAlignPointerStyle(FormatterOperatorAlign::foaType);
+ } else if (ui->rbAlignPointerMiddle->isChecked()) {
+ format.setAlignPointerStyle(FormatterOperatorAlign::foaMiddle);
+ } else if (ui->rbAlignPointerName->isChecked()) {
+ format.setAlignPointerStyle(FormatterOperatorAlign::foaName);
+ }
+ if (ui->rbAlignReferenceNone->isChecked()) {
+ format.setAlignReferenceStyle(FormatterOperatorAlign::foaNone);
+ } else if (ui->rbAlignReferenceType->isChecked()) {
+ format.setAlignReferenceStyle(FormatterOperatorAlign::foaType);
+ } else if (ui->rbAlignReferenceMiddle->isChecked()) {
+ format.setAlignReferenceStyle(FormatterOperatorAlign::foaMiddle);
+ } else if (ui->rbAlignReferenceName->isChecked()) {
+ format.setAlignReferenceStyle(FormatterOperatorAlign::foaName);
+ }
+ format.setBreakClosingBraces(ui->chkBreakClosingBraces->isChecked());
+ format.setBreakElseIf(ui->chkBreakElseIf->isChecked());
+ format.setBreakOneLineHeaders(ui->chkBreakOneLineHeaders->isChecked());
+ format.setAddBraces(ui->chkAddBraces->isChecked());
+ format.setAddOneLineBraces(ui->chkAddOneLineBraces->isChecked());
+ format.setRemoveBraces(ui->chkRemoveBraces->isChecked());
+ format.setBreakReturnType(ui->chkBreakReturnType->isChecked());
+ format.setBreakReturnTypeDecl(ui->chkBreakReturnTypeDecl->isChecked());
+ format.setAttachReturnType(ui->chkAttachReturnType->isChecked());
+ format.setAttachReturnTypeDecl(ui->chkAttachReturnTypeDecl->isChecked());
+ format.setKeepOneLineBlocks(ui->chkKeepOneLineBlocks->isChecked());
+ format.setKeepOneLineStatements(ui->chkKeepOneLineStatements->isChecked());
+ format.setConvertTabs(ui->chkConvertTabs->isChecked());
+ format.setCloseTemplates(ui->chkCloseTemplates->isChecked());
+ format.setRemoveCommentPrefix(ui->chkRemoveCommentPrefix->isChecked());
+ format.setBreakMaxCodeLength(ui->chkBreakMaxCodeLength->isChecked());
+ format.setMaxCodeLength(ui->spinMaxCodeLength->value());
+ format.setBreakAfterLogical(ui->chkBreakAfterLogical->isChecked());
+}
+
diff --git a/RedPandaIDE/settingsdialog/formattergeneralwidget.h b/RedPandaIDE/settingsdialog/formattergeneralwidget.h
index 2a080d0a..a263bca9 100644
--- a/RedPandaIDE/settingsdialog/formattergeneralwidget.h
+++ b/RedPandaIDE/settingsdialog/formattergeneralwidget.h
@@ -5,6 +5,7 @@
#include
#include "settingswidget.h"
#include "../utils.h"
+#include "../settings.h"
namespace Ui {
class FormatterGeneralWidget;
@@ -46,6 +47,10 @@ private slots:
void on_chkBreakMaxCodeLength_stateChanged(int arg1);
+ void updateDemo();
+private:
+ void updateCodeFormatter(Settings::CodeFormatter& format);
+
private:
Ui::FormatterGeneralWidget *ui;
FormatterStyleModel mStylesModel;
diff --git a/RedPandaIDE/settingsdialog/formattergeneralwidget.ui b/RedPandaIDE/settingsdialog/formattergeneralwidget.ui
index 8306ba84..60ff7373 100644
--- a/RedPandaIDE/settingsdialog/formattergeneralwidget.ui
+++ b/RedPandaIDE/settingsdialog/formattergeneralwidget.ui
@@ -850,6 +850,12 @@
-
+
+
+ 0
+ 1
+
+
0
@@ -864,22 +870,6 @@
- -
-
-
- Qt::Vertical
-
-
- QSizePolicy::Expanding
-
-
-
- 20
- 40
-
-
-
-
@@ -893,7 +883,7 @@
-
+
diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp
index dfa2af3a..57f25710 100644
--- a/RedPandaIDE/utils.cpp
+++ b/RedPandaIDE/utils.cpp
@@ -92,7 +92,7 @@ bool isGreenEdition()
return gIsGreenEdition;
}
-QByteArray runAndGetOutput(const QString &cmd, const QString& workingDir, const QStringList& arguments, bool inheritEnvironment)
+QByteArray runAndGetOutput(const QString &cmd, const QString& workingDir, const QStringList& arguments, const QByteArray &inputContent, bool inheritEnvironment)
{
QProcess process;
QByteArray result;
@@ -111,6 +111,9 @@ QByteArray runAndGetOutput(const QString &cmd, const QString& workingDir, const
result.append(process.readAllStandardOutput());
});
process.start(cmd,arguments);
+ if (!inputContent.isEmpty()) {
+ process.write(inputContent);
+ }
process.closeWriteChannel();
process.waitForFinished();
return result;
diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h
index 83a56469..2893f275 100644
--- a/RedPandaIDE/utils.h
+++ b/RedPandaIDE/utils.h
@@ -63,7 +63,7 @@ enum FormatterBraceStyle {
fbsRatliff,
fbsGNU,
fbsLinux,
- fbsHorstman,
+ fbsHorstmann,
fbs1TBS,
fbsGoogle,
fbsMozilla,
@@ -111,7 +111,9 @@ const QByteArray GuessTextEncoding(const QByteArray& text);
bool isTextAllAscii(const QString& text);
-QByteArray runAndGetOutput(const QString& cmd, const QString& workingDir, const QStringList& arguments, bool inheritEnvironment = false);
+QByteArray runAndGetOutput(const QString& cmd, const QString& workingDir, const QStringList& arguments,
+ const QByteArray& inputContent = QByteArray(),
+ bool inheritEnvironment = false);
bool isNonPrintableAsciiChar(char ch);