diff --git a/NEWS.md b/NEWS.md index 5853d344..05615432 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,9 @@ Red Panda C++ Version 2.17 - enhancement: Show mousetip for numbers in the GNU assembly file. - enhancement: Open offline gnu as/x86 assembly manual if exists. - fix: Hex number with 'f' in not is not correctly colored. + - fix: After project's default encoding is changed in the project options dialog, all project files' encoding are wrongly setted to the new encoding.(They should be "Project default") + - enhancement: Make project's default encoding setting in the project options dialog more user friendly. + - fix: In project options dialog's file page, Project's default encoding name is not updated when it's changed. Red Panda C++ Version 2.16 diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index a23beb81..ea779e2e 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -1131,7 +1131,8 @@ void Project::setEncoding(const QByteArray &encoding) continue; Editor * e=unitEditor(unit); if (e) { - e->setEncodingOption(mOptions.encoding); + e->setEncodingOption(ENCODING_PROJECT); + unit->setEncoding(ENCODING_PROJECT); } } } diff --git a/RedPandaIDE/settingsdialog/projectfileswidget.cpp b/RedPandaIDE/settingsdialog/projectfileswidget.cpp index bf2ead97..1f7ccace 100644 --- a/RedPandaIDE/settingsdialog/projectfileswidget.cpp +++ b/RedPandaIDE/settingsdialog/projectfileswidget.cpp @@ -255,7 +255,11 @@ void ProjectFilesWidget::init() ui->spinPriority->setMaximum(9999); ui->cbEncodingDetail->setVisible(false); ui->cbEncoding->clear(); - ui->cbEncoding->addItem(tr("Project(%1)").arg(QString(pMainWindow->project()->options().encoding)),ENCODING_PROJECT); + if (pMainWindow->project()->options().encoding==ENCODING_SYSTEM_DEFAULT) { + ui->cbEncoding->addItem(tr("Project(%1)").arg(tr("ANSI"),ENCODING_PROJECT)); + } else { + ui->cbEncoding->addItem(tr("Project(%1)").arg(QString(pMainWindow->project()->options().encoding)),ENCODING_PROJECT); + } ui->cbEncoding->addItem(tr("ANSI"),ENCODING_SYSTEM_DEFAULT); ui->cbEncoding->addItem(tr("UTF-8"),ENCODING_UTF8); foreach (const QString& langName, pCharsetInfoManager->languageNames()) { @@ -264,6 +268,17 @@ void ProjectFilesWidget::init() SettingsWidget::init(); } +void ProjectFilesWidget::showEvent(QShowEvent *event) +{ + if (ui->cbEncoding->count()>0) { + if (pMainWindow->project()->options().encoding==ENCODING_SYSTEM_DEFAULT) { + ui->cbEncoding->setItemText(0,tr("Project(%1)").arg(tr("ANSI"))); + } else { + ui->cbEncoding->setItemText(0,tr("Project(%1)").arg(QString(pMainWindow->project()->options().encoding))); + } + } +} + void ProjectFilesWidget::on_cbEncodingDetail_currentTextChanged(const QString &) { diff --git a/RedPandaIDE/settingsdialog/projectfileswidget.h b/RedPandaIDE/settingsdialog/projectfileswidget.h index 49984107..608a0216 100644 --- a/RedPandaIDE/settingsdialog/projectfileswidget.h +++ b/RedPandaIDE/settingsdialog/projectfileswidget.h @@ -63,6 +63,10 @@ private slots: public: void init() override; + + // QWidget interface +protected: + void showEvent(QShowEvent *event) override; }; #endif // PROJECTFILESWIDGET_H diff --git a/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp b/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp index 5712963f..a565045a 100644 --- a/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp +++ b/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp @@ -21,6 +21,7 @@ #include "settings.h" #include "../systemconsts.h" #include "../iconsmanager.h" +#include "qt_utils/charsetinfo.h" #include #include @@ -79,7 +80,26 @@ void ProjectGeneralWidget::doLoad() .arg(totalCount).arg(srcCount).arg(headerCount) .arg(resCount).arg(otherCount)); - ui->cbDefaultEncoding->setCurrentText(project->options().encoding); + QByteArray defaultEncoding = project->options().encoding; + if (defaultEncoding == ENCODING_AUTO_DETECT + || defaultEncoding == ENCODING_SYSTEM_DEFAULT + || defaultEncoding == ENCODING_UTF8 + || defaultEncoding == ENCODING_UTF8_BOM) { + int index =ui->cbEncoding->findData(defaultEncoding); + ui->cbEncoding->setCurrentIndex(index); + ui->cbEncodingDetail->clear(); + ui->cbEncodingDetail->setVisible(false); + } else { + QString language = pCharsetInfoManager->findLanguageByCharsetName(defaultEncoding); + ui->cbEncoding->setCurrentText(language); + ui->cbEncodingDetail->setVisible(true); + ui->cbEncodingDetail->clear(); + QList infos = pCharsetInfoManager->findCharsetsByLanguageName(language); + foreach (const PCharsetInfo& info, infos) { + ui->cbEncodingDetail->addItem(info->name); + } + ui->cbEncodingDetail->setCurrentText(defaultEncoding); + } ui->lstType->setCurrentRow( static_cast(project->options().type)); @@ -97,7 +117,11 @@ void ProjectGeneralWidget::doSave() return; project->setName(ui->txtName->text().trimmed()); - project->setEncoding(ui->cbDefaultEncoding->currentText().toUtf8()); + if (ui->cbEncodingDetail->isVisible()) { + project->setEncoding(ui->cbEncodingDetail->currentText().toUtf8()); + } else { + project->setEncoding(ui->cbEncoding->currentData().toByteArray()); + } int row = std::max(0,ui->lstType->currentRow()); project->options().type = static_cast(row); @@ -164,13 +188,35 @@ void ProjectGeneralWidget::on_btnRemove_clicked() setSettingsChanged(); } +void ProjectGeneralWidget::on_cbEncoding_currentTextChanged(const QString &arg1) +{ + QString userData = ui->cbEncoding->currentData().toString(); + if (userData == ENCODING_AUTO_DETECT + || userData == ENCODING_SYSTEM_DEFAULT + || userData == ENCODING_UTF8 + || userData == ENCODING_UTF8_BOM) { + ui->cbEncodingDetail->setVisible(false); + ui->cbEncodingDetail->clear(); + } else { + ui->cbEncodingDetail->setVisible(true); + ui->cbEncodingDetail->clear(); + QList infos = pCharsetInfoManager->findCharsetsByLanguageName(userData); + foreach (const PCharsetInfo& info, infos) { + ui->cbEncodingDetail->addItem(info->name); + } + } +} + void ProjectGeneralWidget::init() { - ui->cbDefaultEncoding->clear(); - QStringList codecNames=pSystemConsts->codecNames(); - //project encoding shouldn't be auto - codecNames.removeAll(ENCODING_AUTO_DETECT); - ui->cbDefaultEncoding->addItems(codecNames); + ui->cbEncodingDetail->setVisible(false); + ui->cbEncoding->clear(); + ui->cbEncoding->addItem(tr("ANSI"),ENCODING_SYSTEM_DEFAULT); + ui->cbEncoding->addItem(tr("UTF-8"),ENCODING_UTF8); + ui->cbEncoding->addItem(tr("UTF-8 BOM"),ENCODING_UTF8_BOM); + foreach (const QString& langName, pCharsetInfoManager->languageNames()) { + ui->cbEncoding->addItem(langName,langName); + } SettingsWidget::init(); } diff --git a/RedPandaIDE/settingsdialog/projectgeneralwidget.h b/RedPandaIDE/settingsdialog/projectgeneralwidget.h index 3366f4dd..93501d27 100644 --- a/RedPandaIDE/settingsdialog/projectgeneralwidget.h +++ b/RedPandaIDE/settingsdialog/projectgeneralwidget.h @@ -44,6 +44,7 @@ protected: private slots: void on_btnBrowse_clicked(); void on_btnRemove_clicked(); + void on_cbEncoding_currentTextChanged(const QString &arg1); // SettingsWidget interface public: diff --git a/RedPandaIDE/settingsdialog/projectgeneralwidget.ui b/RedPandaIDE/settingsdialog/projectgeneralwidget.ui index 9a6f7fbb..ae18db5c 100644 --- a/RedPandaIDE/settingsdialog/projectgeneralwidget.ui +++ b/RedPandaIDE/settingsdialog/projectgeneralwidget.ui @@ -52,9 +52,6 @@ - - - @@ -281,6 +278,43 @@ + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + diff --git a/libs/qsynedit/qsynedit/painter.cpp b/libs/qsynedit/qsynedit/painter.cpp index a0360ee8..6eadf0eb 100644 --- a/libs/qsynedit/qsynedit/painter.cpp +++ b/libs/qsynedit/qsynedit/painter.cpp @@ -751,8 +751,8 @@ void QSynEditPainter::paintFoldAttributes() // Paint collapsed lines using changed pen if (edit->mCodeFolding.showCollapsedLine) { painter->setPen(edit->mCodeFolding.collapsedLineColor); - for (int i=0; i< edit->mAllFoldRanges.count();i++) { - PCodeFoldingRange range = edit->mAllFoldRanges[i]; + for (int i=0; i< edit->mAllFoldRanges->count();i++) { + PCodeFoldingRange range = (*edit->mAllFoldRanges)[i]; if (range->collapsed && !range->parentCollapsed() && (range->fromLine <= vLastLine) && (range->fromLine >= vFirstLine) ) { // Get starting and end points diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index 254b13c9..81fee7af 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -149,6 +149,7 @@ QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent), mContentImage = std::make_shared(clientWidth()*dpr,clientHeight()*dpr,QImage::Format_ARGB32); mContentImage->setDevicePixelRatio(dpr); + mAllFoldRanges = std::make_shared(); mUseCodeFolding = true; m_blinkTimerId = 0; m_blinkStatus = 0; @@ -947,8 +948,8 @@ int QSynEdit::lineToRow(int aLine) const int QSynEdit::foldRowToLine(int Row) const { int result = Row; - for (int i=0;icount();i++) { + PCodeFoldingRange range = (*mAllFoldRanges)[i]; if (range->collapsed && !range->parentCollapsed() && range->fromLine < result) { result += range->linesCollapsed; } @@ -959,8 +960,8 @@ int QSynEdit::foldRowToLine(int Row) const int QSynEdit::foldLineToRow(int Line) const { int result = Line; - for (int i=mAllFoldRanges.count()-1;i>=0;i--) { - PCodeFoldingRange range =mAllFoldRanges[i]; + for (int i=mAllFoldRanges->count()-1;i>=0;i--) { + PCodeFoldingRange range =(*mAllFoldRanges)[i]; if (range->collapsed && !range->parentCollapsed()) { // Line is found after fold if (range->toLine < Line) @@ -1223,8 +1224,8 @@ bool QSynEdit::inputMethodOn() void QSynEdit::collapseAll() { incPaintLock(); - for (int i = mAllFoldRanges.count()-1;i>=0;i--){ - collapse(mAllFoldRanges[i]); + for (int i = mAllFoldRanges->count()-1;i>=0;i--){ + collapse((*mAllFoldRanges)[i]); } decPaintLock(); } @@ -1232,8 +1233,8 @@ void QSynEdit::collapseAll() void QSynEdit::unCollpaseAll() { incPaintLock(); - for (int i = mAllFoldRanges.count()-1;i>=0;i--){ - uncollapse(mAllFoldRanges[i]); + for (int i = mAllFoldRanges->count()-1;i>=0;i--){ + uncollapse((*mAllFoldRanges)[i]); } decPaintLock(); } @@ -3428,8 +3429,8 @@ void QSynEdit::collapse(PCodeFoldingRange FoldRange) void QSynEdit::foldOnListInserted(int Line, int Count) { // Delete collapsed inside selection - for (int i = mAllFoldRanges.count()-1;i>=0;i--) { - PCodeFoldingRange range = mAllFoldRanges[i]; + for (int i = mAllFoldRanges->count()-1;i>=0;i--) { + PCodeFoldingRange range = (*mAllFoldRanges)[i]; if (range->fromLine == Line - 1) {// insertion starts at fold line if (range->collapsed) uncollapse(range); @@ -3441,13 +3442,13 @@ void QSynEdit::foldOnListInserted(int Line, int Count) void QSynEdit::foldOnListDeleted(int Line, int Count) { // Delete collapsed inside selection - for (int i = mAllFoldRanges.count()-1;i>=0;i--) { - PCodeFoldingRange range = mAllFoldRanges[i]; + for (int i = mAllFoldRanges->count()-1;i>=0;i--) { + PCodeFoldingRange range = (*mAllFoldRanges)[i]; if (range->fromLine == Line && Count == 1) {// open up because we are messing with the starting line if (range->collapsed) uncollapse(range); } else if (range->fromLine >= Line - 1 && range->fromLine < Line + Count) // delete inside affectec area - mAllFoldRanges.remove(i); + mAllFoldRanges->remove(i); else if (range->fromLine >= Line + Count) // Move after affected area range->move(-Count); @@ -3457,7 +3458,7 @@ void QSynEdit::foldOnListDeleted(int Line, int Count) void QSynEdit::foldOnListCleared() { - mAllFoldRanges.clear(); + mAllFoldRanges->clear(); } void QSynEdit::rescanFolds() @@ -3473,8 +3474,6 @@ void QSynEdit::rescanFolds() invalidateGutter(); } -static void null_deleter(CodeFoldingRanges *) {} - void QSynEdit::rescanForFoldRanges() { // Delete all uncollapsed folds @@ -3485,13 +3484,13 @@ void QSynEdit::rescanForFoldRanges() // } // Did we leave any collapsed folds and are we viewing a code file? - if (mAllFoldRanges.count() > 0) { + if (mAllFoldRanges->count() > 0) { QMap rangeIndexes; - foreach(const PCodeFoldingRange& r, mAllFoldRanges.ranges()) { + foreach(const PCodeFoldingRange& r, mAllFoldRanges->ranges()) { if (r->collapsed) rangeIndexes.insert(QString("%1-%2").arg(r->fromLine).arg(r->toLine),r); } - mAllFoldRanges.clear(); + mAllFoldRanges->clear(); // Add folds to a separate list PCodeFoldingRanges temporaryAllFoldRanges = std::make_shared(); scanForFoldRanges(temporaryAllFoldRanges); @@ -3507,11 +3506,11 @@ void QSynEdit::rescanForFoldRanges() tempFoldRange->collapsed=true; tempFoldRange->linesCollapsed=r2->linesCollapsed; } - mAllFoldRanges.add(tempFoldRange); + mAllFoldRanges->add(tempFoldRange); } } else { // We ended up with no folds after deleting, just pass standard data... - PCodeFoldingRanges temp(&mAllFoldRanges, null_deleter); + PCodeFoldingRanges temp{mAllFoldRanges}; scanForFoldRanges(temp); } } @@ -3612,10 +3611,10 @@ void QSynEdit::findSubFoldRange(PCodeFoldingRanges topFoldRanges, PCodeFoldingRa PCodeFoldingRange QSynEdit::collapsedFoldStartAtLine(int Line) { - for (int i = 0; i< mAllFoldRanges.count() - 1; i++ ) { - if (mAllFoldRanges[i]->collapsed && mAllFoldRanges[i]->fromLine == Line) { - return mAllFoldRanges[i]; - } else if (mAllFoldRanges[i]->fromLine > Line) { + for (int i = 0; i< mAllFoldRanges->count() - 1; i++ ) { + if ((*mAllFoldRanges)[i]->collapsed && (*mAllFoldRanges)[i]->fromLine == Line) { + return (*mAllFoldRanges)[i]; + } else if ((*mAllFoldRanges)[i]->fromLine > Line) { break; // sorted by line. don't bother scanning further } } @@ -3629,8 +3628,8 @@ void QSynEdit::initializeCaret() PCodeFoldingRange QSynEdit::foldStartAtLine(int Line) const { - for (int i = 0; icount();i++) { + PCodeFoldingRange range = (*mAllFoldRanges)[i]; if (range->fromLine == Line ){ return range; } else if (range->fromLine>Line) @@ -3641,8 +3640,8 @@ PCodeFoldingRange QSynEdit::foldStartAtLine(int Line) const bool QSynEdit::foldCollapsedBetween(int startLine, int endLine) const { - for (int i = 0; icount();i++) { + PCodeFoldingRange range = (*mAllFoldRanges)[i]; if (startLine >=range->fromLine && range->fromLine<=endLine && (range->collapsed || range->parentCollapsed())){ return true; @@ -3696,32 +3695,32 @@ QString QSynEdit::substringByColumns(const QString &s, int startColumn, int &col return result; } -PCodeFoldingRange QSynEdit::foldAroundLine(int Line) +PCodeFoldingRange QSynEdit::foldAroundLine(int line) { - return foldAroundLineEx(Line,false,false,false); + return foldAroundLineEx(line,false,false,false); } -PCodeFoldingRange QSynEdit::foldAroundLineEx(int Line, bool WantCollapsed, bool AcceptFromLine, bool AcceptToLine) +PCodeFoldingRange QSynEdit::foldAroundLineEx(int line, bool wantCollapsed, bool acceptFromLine, bool acceptToLine) { // Check global list - PCodeFoldingRange Result = checkFoldRange(&mAllFoldRanges, Line, WantCollapsed, AcceptFromLine, AcceptToLine); + PCodeFoldingRange result = checkFoldRange(mAllFoldRanges, line, wantCollapsed, acceptFromLine, acceptToLine); // Found an item in the top level list? - if (Result) { + if (result) { while (true) { - PCodeFoldingRange ResultChild = checkFoldRange(Result->subFoldRanges.get(), Line, WantCollapsed, AcceptFromLine, AcceptToLine); + PCodeFoldingRange ResultChild = checkFoldRange(result->subFoldRanges, line, wantCollapsed, acceptFromLine, acceptToLine); if (!ResultChild) break; - Result = ResultChild; // repeat for this one + result = ResultChild; // repeat for this one } } - return Result; + return result; } -PCodeFoldingRange QSynEdit::checkFoldRange(CodeFoldingRanges *FoldRangeToCheck, int Line, bool WantCollapsed, bool AcceptFromLine, bool AcceptToLine) +PCodeFoldingRange QSynEdit::checkFoldRange(PCodeFoldingRanges foldRangesToCheck, int Line, bool WantCollapsed, bool AcceptFromLine, bool AcceptToLine) { - for (int i = 0; i< FoldRangeToCheck->count(); i++) { - PCodeFoldingRange range = (*FoldRangeToCheck)[i]; + for (int i = 0; i< foldRangesToCheck->count(); i++) { + PCodeFoldingRange range = (*foldRangesToCheck)[i]; if (((range->fromLine < Line) || ((range->fromLine <= Line) && AcceptFromLine)) && ((range->toLine > Line) || ((range->toLine >= Line) && AcceptToLine))) { if (range->collapsed == WantCollapsed) { @@ -3734,8 +3733,8 @@ PCodeFoldingRange QSynEdit::checkFoldRange(CodeFoldingRanges *FoldRangeToCheck, PCodeFoldingRange QSynEdit::foldEndAtLine(int Line) { - for (int i = 0; icount();i++) { + PCodeFoldingRange range = (*mAllFoldRanges)[i]; if (range->toLine == Line ){ return range; } else if (range->fromLine>Line) diff --git a/libs/qsynedit/qsynedit/qsynedit.h b/libs/qsynedit/qsynedit/qsynedit.h index 94c2fc42..01679d29 100644 --- a/libs/qsynedit/qsynedit/qsynedit.h +++ b/libs/qsynedit/qsynedit/qsynedit.h @@ -520,10 +520,10 @@ private: PCodeFoldingRange foldStartAtLine(int Line) const; bool foldCollapsedBetween(int startLine, int endLine) const; QString substringByColumns(const QString& s, int startColumn, int& colLen); - PCodeFoldingRange foldAroundLine(int Line); - PCodeFoldingRange foldAroundLineEx(int Line, bool WantCollapsed, bool AcceptFromLine, bool AcceptToLine); - PCodeFoldingRange checkFoldRange(CodeFoldingRanges* FoldRangeToCheck,int Line, bool WantCollapsed, bool AcceptFromLine, bool AcceptToLine); - PCodeFoldingRange foldEndAtLine(int Line); + PCodeFoldingRange foldAroundLine(int line); + PCodeFoldingRange foldAroundLineEx(int line, bool wantCollapsed, bool acceptFromLine, bool acceptToLine); + PCodeFoldingRange checkFoldRange(PCodeFoldingRanges foldRangesToCheck,int line, bool wantCollapsed, bool AcceptFromLine, bool AcceptToLine); + PCodeFoldingRange foldEndAtLine(int line); void paintCaret(QPainter& painter, const QRect rcClip); int textOffset() const; EditCommand TranslateKeyCode(int key, Qt::KeyboardModifiers modifiers); @@ -639,7 +639,7 @@ private slots: private: std::shared_ptr mContentImage; - CodeFoldingRanges mAllFoldRanges; + PCodeFoldingRanges mAllFoldRanges; CodeFoldingOptions mCodeFolding; int mEditingCount; bool mUseCodeFolding;