diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 5dbde185..70f8afc2 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -5117,10 +5117,7 @@ void Editor::reformat(bool doReparse) // onLinesDeleted(1,lineCount()); QByteArray content = text().toUtf8(); QStringList args = pSettings->codeFormatter().getArguments(); - QByteArray newContent = runAndGetOutput(pSettings->environment().AStylePath(), - extractFileDir(pSettings->environment().AStylePath()), - args, - content); + QByteArray newContent = reformatContentUsingAstyle(content,args); if (newContent.isEmpty()) return; replaceContent(QString::fromUtf8(newContent), doReparse); diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 4645014b..1c5d97f2 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -5032,8 +5032,6 @@ QStringList Settings::CodeFormatter::getArguments() 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) { @@ -5401,16 +5399,6 @@ void Settings::CodeFormatter::setDeleteEmptyLines(bool newDeleteEmptyLines) mDeleteEmptyLines = newDeleteEmptyLines; } -bool Settings::CodeFormatter::deleteMultipleEmptyLines() const -{ - return mDeleteMultipleEmptyLines; -} - -void Settings::CodeFormatter::setDeleteMultipleEmptyLines(bool newDeleteMultipleEmptyLines) -{ - mDeleteMultipleEmptyLines = newDeleteMultipleEmptyLines; -} - bool Settings::CodeFormatter::fillEmptyLines() const { return mFillEmptyLines; @@ -5676,7 +5664,6 @@ void Settings::CodeFormatter::doSave() saveValue("pad_header",mPadHeader); saveValue("unpad_paren",mUnpadParen); saveValue("delete_empty_lines",mDeleteEmptyLines); - saveValue("delete_multiple_empty_lines",mDeleteMultipleEmptyLines); saveValue("fill_empty_lines",mFillEmptyLines); saveValue("align_pointer_style",mAlignPointerStyle); saveValue("align_reference_style",mAlignReferenceStyle); @@ -5735,7 +5722,6 @@ void Settings::CodeFormatter::doLoad() mPadHeader = boolValue("pad_header",true); mUnpadParen = boolValue("unpad_paren",false); mDeleteEmptyLines = boolValue("delete_empty_lines",false); - mDeleteMultipleEmptyLines = boolValue("delete_multiple_empty_lines",false); mFillEmptyLines = boolValue("fill_empty_lines",false); mAlignPointerStyle = intValue("align_pointer_style", FormatterOperatorAlign::foaNone); mAlignReferenceStyle = intValue("align_reference_style", FormatterOperatorAlign::foaNone); diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index d1b00adf..f51e9f28 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -764,8 +764,6 @@ public: void setUnpadParen(bool newUnpadParen); bool deleteEmptyLines() const; void setDeleteEmptyLines(bool newDeleteEmptyLines); - bool deleteMultipleEmptyLines() const; - void setDeleteMultipleEmptyLines(bool newDeleteMultipleEmptyLines); bool fillEmptyLines() const; void setFillEmptyLines(bool newFillEmptyLines); int alignPointerStyle() const; @@ -851,7 +849,6 @@ public: bool mPadHeader; bool mUnpadParen; bool mDeleteEmptyLines; - bool mDeleteMultipleEmptyLines; bool mFillEmptyLines; int mAlignPointerStyle; int mAlignReferenceStyle; diff --git a/RedPandaIDE/settingsdialog/formattergeneralwidget.cpp b/RedPandaIDE/settingsdialog/formattergeneralwidget.cpp index 649e86b9..5f68a681 100644 --- a/RedPandaIDE/settingsdialog/formattergeneralwidget.cpp +++ b/RedPandaIDE/settingsdialog/formattergeneralwidget.cpp @@ -97,7 +97,6 @@ void FormatterGeneralWidget::doLoad() ui->chkPadHeader->setChecked(format.padHeader()); ui->chkUnpadParen->setChecked(format.unpadParen()); ui->chkDeleteEmptyLines->setChecked(format.deleteEmptyLines()); - ui->chkDeleteMultipleEmptyLines->setChecked(format.deleteMultipleEmptyLines()); ui->chkFillEmptyLines->setChecked(format.fillEmptyLines()); switch(format.alignPointerStyle()) { case FormatterOperatorAlign::foaNone: @@ -320,6 +319,10 @@ void FormatterGeneralWidget::on_chkBreakMaxCodeLength_stateChanged(int) void FormatterGeneralWidget::updateDemo() { + if (!fileExists(pSettings->environment().AStylePath())) { + ui->editDemo->document()->setText(Editor::tr("Can't find astyle in \"%1\".").arg(pSettings->environment().AStylePath())); + return; + } QFile file(":/codes/formatdemo.cpp"); if (!file.open(QFile::ReadOnly)) return; @@ -327,11 +330,7 @@ void FormatterGeneralWidget::updateDemo() Settings::CodeFormatter formatter(nullptr); updateCodeFormatter(formatter); - - QByteArray newContent = runAndGetOutput(pSettings->environment().AStylePath(), - extractFileDir(pSettings->environment().AStylePath()), - formatter.getArguments(), - content); + QByteArray newContent = reformatContentUsingAstyle(content, formatter.getArguments()); ui->editDemo->document()->setText(newContent); } @@ -376,7 +375,6 @@ void FormatterGeneralWidget::updateCodeFormatter(Settings::CodeFormatter &format 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); diff --git a/RedPandaIDE/settingsdialog/formattergeneralwidget.ui b/RedPandaIDE/settingsdialog/formattergeneralwidget.ui index b688d776..d32f9c7a 100644 --- a/RedPandaIDE/settingsdialog/formattergeneralwidget.ui +++ b/RedPandaIDE/settingsdialog/formattergeneralwidget.ui @@ -71,7 +71,7 @@ - 0 + 2 @@ -362,6 +362,19 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -369,6 +382,27 @@ Indentation 2 + + + + Indent line comments that start in column one + + + + + + + Indent multi-line preprocessor #define statements + + + + + + + Indent switch blocks + + + @@ -376,6 +410,34 @@ + + + + Indent preprocessor conditional statements + + + + + + + Indent after parenthesis '(' or assignment '=' + + + + + + + Indent class access modifiers + + + + + + + Indent cases + + + @@ -390,41 +452,6 @@ - - - - Indent class access modifiers - - - - - - - Indent after parenthesis '(' or assignment '=' - - - - - - - Indent preprocessor conditional statements - - - - - - - Indent multi-line preprocessor #define statements - - - - - - - Indent line comments that start in column one - - - @@ -432,19 +459,18 @@ - - - - Indent switch blocks + + + + Qt::Vertical - - - - - - Indent cases + + + 20 + 40 + - + @@ -453,10 +479,10 @@ Padding 1 - - + + - Insert spaces around operators + Insert spaces around parenthesis @@ -488,10 +514,10 @@ - - + + - Insert empty lines arround unrelated blocks + Insert spaces around first parenthesis in a series on the out side only @@ -502,20 +528,33 @@ - - + + - Insert spaces around first parenthesis in a series on the out side only + Insert empty lines arround unrelated blocks - - + + - Insert spaces around parenthesis + Insert spaces around operators + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -523,38 +562,34 @@ Padding 2 - - + + - Remove all empty lines. It will NOT delete lines added by the padding options. + none + + pointerBtnGroup + - - + + - Attach a pointer operator to its : - - - - - - - Remove all consecutive empty lines. It will NOT delete lines added by the padding options. - - - - - - - type(left) + none referenceBtnGroup - + + + + Remove unnecessary space adding around parenthesis + + + + type(left) @@ -564,7 +599,78 @@ - + + + + name(right) + + + pointerBtnGroup + + + + + + + middle + + + referenceBtnGroup + + + + + + + Attach a pointer operator to its : + + + + + + + type(left) + + + referenceBtnGroup + + + + + + + name(right) + + + referenceBtnGroup + + + + + + + Remove all empty lines. It will NOT delete lines added by the padding options. + + + + + + + Fill empty lines with the white space of the previous lines. + + + + + + + middle + + + pointerBtnGroup + + + + Qt::Horizontal @@ -577,86 +683,25 @@ - - - - middle - - - referenceBtnGroup - - - - - - - Fill empty lines with the white space of the previous lines. - - - - - - - name(right) - - - referenceBtnGroup - - - - - - - middle - - - pointerBtnGroup - - - - - - - name(right) - - - pointerBtnGroup - - - - - - - Remove unnecessary space adding around parenthesis - - - - + Attach a reference operator to its : - - - - none + + + + Qt::Vertical - - pointerBtnGroup - - - - - - - none + + + 20 + 40 + - - referenceBtnGroup - - + @@ -665,10 +710,10 @@ Other 1 - - + + - Break one line headers ('if','while','else'...) from the statement on the same line + Add braces to unbraced one line conditional statements @@ -679,10 +724,10 @@ - - + + - Break braces before close headers ('else','catch"...) + Break one line headers ('if','while','else'...) from the statement on the same line @@ -693,6 +738,13 @@ + + + + Break braces before close headers ('else','catch"...) + + + @@ -700,12 +752,18 @@ - - - - Add braces to unbraced one line conditional statements + + + + Qt::Vertical - + + + 20 + 40 + + + @@ -714,10 +772,10 @@ Other 2 - - + + - Break return type from the function name in its definition + Attach return type to the function name in its definition @@ -728,10 +786,10 @@ - - + + - Attach return type to the function name in its definition + Break return type from the function name in its definition @@ -756,6 +814,19 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -924,7 +995,6 @@ chkPadHeader chkUnpadParen chkDeleteEmptyLines - chkDeleteMultipleEmptyLines chkFillEmptyLines rbAlignPointNone rbAlignPointType diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index 351a1156..d723ec26 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -402,7 +402,28 @@ QByteArray runAndGetOutput(const QString &cmd, const QString& workingDir, const process.closeWriteChannel(); process.waitForFinished(); if (errorOccurred) { - result += process.errorString().toLocal8Bit(); + switch(process.error()) { + case QProcess::FailedToStart: + result += "Failed to start process!"; + break; + case QProcess::Crashed: + result += "Process crashed!"; + break; + case QProcess::Timedout: + result += "Timeout!"; + break; + case QProcess::ReadError: + result += "Read Error:"; + break; + case QProcess::WriteError: + result += "Write Error:"; + break; + case QProcess::UnknownError: + result += "Unknown Error:"; + break; + } + + //result += process.errorString().toLocal8Bit(); } return result; } @@ -744,3 +765,16 @@ std::tuple wrapCommandFor { return wrapCommandForTerminalEmulator(terminal, parseArguments(argsPattern, Settings::Environment::terminalArgsPatternMagicVariables(), false), payloadArgsWithArgv0); } + +QByteArray reformatContentUsingAstyle(const QByteArray &content, const QStringList &arguments) +{ + QProcessEnvironment env; + env.insert("LANG","en"); + QByteArray newContent = runAndGetOutput(pSettings->environment().AStylePath(), + extractFileDir(pSettings->environment().AStylePath()), + arguments, + content, + false, + env); + return newContent; +} diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h index 7fb3c251..cf4f8100 100644 --- a/RedPandaIDE/utils.h +++ b/RedPandaIDE/utils.h @@ -148,6 +148,8 @@ QByteArray runAndGetOutput(const QString& cmd, const QString& workingDir, const bool inheritEnvironment = false, const QProcessEnvironment& env = QProcessEnvironment() ); +QByteArray reformatContentUsingAstyle(const QByteArray& content, const QStringList& arguments); + void openFileFolderInExplorer(const QString& path); void executeFile(const QString& fileName,