- enhancement: support UTF-8 BOM files

This commit is contained in:
Roy Qu 2022-05-06 15:23:41 +08:00
parent 2e66a3163c
commit 7729ba0ebe
9 changed files with 789 additions and 708 deletions

View File

@ -5,6 +5,7 @@ Red Panda C++ Version 1.0.7
- enhancement: hide add charset option in project options dialog's compiler set page, when project compiler set is clang
- fix: When generating project's makefile for clang, don't add -fexec-charset / -finput-charset command line options
- fix: index of the longest line not correctly updated when inputting with auto completion open
- enhancement: support UTF-8 BOM files
Red Panda C++ Version 1.0.6
- fix: gcc compiler set name is not correct in Linux

View File

@ -469,18 +469,6 @@
<source>Can&apos;t start debugging.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Encoding not support</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Clang only support utf-8 encoding.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Strings in the program might be wrongly processed.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Can&apos;t find Console Pauser</source>
<translation type="unfinished"></translation>
@ -1343,6 +1331,10 @@
<source>UTF-8</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>UTF-8 BOM</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>EditorSnippetWidget</name>
@ -4444,6 +4436,14 @@
<source>This operation will remove all cases for the current problem.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Convert to UTF-8 BOM</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Encode in UTF-8 BOM</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NewClassDialog</name>
@ -6252,14 +6252,7 @@
</message>
</context>
<context>
<name>SynEdit</name>
<message>
<source>The highlighter seems to be in an infinite loop</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SynEditStringList</name>
<name>SynDocument</name>
<message>
<source>Can&apos;t open file &apos;%1&apos; for read!</source>
<translation type="unfinished"></translation>
@ -6269,6 +6262,13 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SynEdit</name>
<message>
<source>The highlighter seems to be in an infinite loop</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>TodoModel</name>
<message>

File diff suppressed because it is too large Load Diff

View File

@ -469,18 +469,6 @@
<source>Can&apos;t start debugging.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Encoding not support</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Clang only support utf-8 encoding.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Strings in the program might be wrongly processed.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Can&apos;t find Console Pauser</source>
<translation type="unfinished"></translation>
@ -1343,6 +1331,10 @@
<source>UTF-8</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>UTF-8 BOM</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>EditorSnippetWidget</name>
@ -4444,6 +4436,14 @@
<source>Line %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Convert to UTF-8 BOM</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Encode in UTF-8 BOM</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NewClassDialog</name>
@ -6252,14 +6252,7 @@
</message>
</context>
<context>
<name>SynEdit</name>
<message>
<source>The highlighter seems to be in an infinite loop</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SynEditStringList</name>
<name>SynDocument</name>
<message>
<source>Can&apos;t open file &apos;%1&apos; for read!</source>
<translation type="unfinished"></translation>
@ -6269,6 +6262,13 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SynEdit</name>
<message>
<source>The highlighter seems to be in an infinite loop</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>TodoModel</name>
<message>

View File

@ -388,11 +388,13 @@ void MainWindow::updateForEncodingInfo(bool clear) {
ui->actionAuto_Detect->setChecked(editor->encodingOption() == ENCODING_AUTO_DETECT);
ui->actionEncode_in_ANSI->setChecked(editor->encodingOption() == ENCODING_SYSTEM_DEFAULT);
ui->actionEncode_in_UTF_8->setChecked(editor->encodingOption() == ENCODING_UTF8);
ui->actionEncode_in_UTF_8->setChecked(editor->encodingOption() == ENCODING_UTF8_BOM);
} else {
mFileEncodingStatus->setText("");
ui->actionAuto_Detect->setChecked(false);
ui->actionEncode_in_ANSI->setChecked(false);
ui->actionEncode_in_UTF_8->setChecked(false);
ui->actionEncode_in_UTF_8_BOM->setChecked(false);
}
}
@ -409,9 +411,11 @@ void MainWindow::updateEditorActions()
ui->actionAuto_Detect->setEnabled(false);
ui->actionEncode_in_ANSI->setEnabled(false);
ui->actionEncode_in_UTF_8->setEnabled(false);
ui->actionEncode_in_UTF_8_BOM->setEnabled(false);
mMenuEncoding->setEnabled(false);
ui->actionConvert_to_ANSI->setEnabled(false);
ui->actionConvert_to_UTF_8->setEnabled(false);
ui->actionConvert_to_UTF_8_BOM->setEnabled(false);
ui->actionCopy->setEnabled(false);
ui->actionCut->setEnabled(false);
ui->actionFoldAll->setEnabled(false);
@ -454,10 +458,12 @@ void MainWindow::updateEditorActions()
ui->actionAuto_Detect->setEnabled(true);
ui->actionEncode_in_ANSI->setEnabled(true);
ui->actionEncode_in_UTF_8->setEnabled(true);
ui->actionEncode_in_UTF_8_BOM->setEnabled(true);
mMenuEncoding->setEnabled(true);
ui->actionConvert_to_ANSI->setEnabled(e->encodingOption()!=ENCODING_SYSTEM_DEFAULT
&& e->fileEncoding()!=ENCODING_SYSTEM_DEFAULT);
ui->actionConvert_to_UTF_8->setEnabled(e->encodingOption()!=ENCODING_UTF8 && e->fileEncoding()!=ENCODING_UTF8);
ui->actionConvert_to_UTF_8_BOM->setEnabled(e->encodingOption()!=ENCODING_UTF8_BOM && e->fileEncoding()!=ENCODING_UTF8_BOM);
ui->actionCopy->setEnabled(e->selAvail());
ui->actionCut->setEnabled(e->selAvail());
@ -2671,11 +2677,13 @@ void MainWindow::buildEncodingMenu()
mMenuEncoding->addAction(ui->actionAuto_Detect);
mMenuEncoding->addAction(ui->actionEncode_in_ANSI);
mMenuEncoding->addAction(ui->actionEncode_in_UTF_8);
mMenuEncoding->addAction(ui->actionEncode_in_UTF_8_BOM);
mMenuEncoding->addMenu(menuCharsets);
mMenuEncoding->addSeparator();
mMenuEncoding->addAction(ui->actionConvert_to_ANSI);
mMenuEncoding->addAction(ui->actionConvert_to_UTF_8);
mMenuEncoding->addAction(ui->actionConvert_to_UTF_8_BOM);
QList<PCharsetInfo> charsetsForLocale = pCharsetInfoManager->findCharsetByLocale(pCharsetInfoManager->localeName());
@ -2702,6 +2710,7 @@ void MainWindow::buildEncodingMenu()
ui->actionAuto_Detect->setCheckable(true);
ui->actionEncode_in_ANSI->setCheckable(true);
ui->actionEncode_in_UTF_8->setCheckable(true);
ui->actionEncode_in_UTF_8_BOM->setCheckable(true);
}
void MainWindow::maximizeEditor()
@ -7656,3 +7665,30 @@ void MainWindow::on_actionMove_Selection_Down_triggered()
editor->moveSelDown();
}
}
void MainWindow::on_actionConvert_to_UTF_8_BOM_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor == nullptr)
return;
if (QMessageBox::warning(this,tr("Confirm Convertion"),
tr("The editing file will be saved using %1 encoding. <br />This operation can't be reverted. <br />Are you sure to continue?")
.arg(ENCODING_UTF8_BOM),
QMessageBox::Yes, QMessageBox::No)!=QMessageBox::Yes)
return;
editor->convertToEncoding(ENCODING_UTF8_BOM);
}
void MainWindow::on_actionEncode_in_UTF_8_BOM_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor == nullptr)
return;
try {
editor->setEncodingOption(ENCODING_UTF8_BOM);
} catch(FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason());
}
}

View File

@ -668,6 +668,10 @@ private slots:
void on_actionMove_Selection_Down_triggered();
void on_actionConvert_to_UTF_8_BOM_triggered();
void on_actionEncode_in_UTF_8_BOM_triggered();
private:
Ui::MainWindow *ui;
EditorList *mEditorList;

View File

@ -545,7 +545,7 @@
<enum>QTabWidget::South</enum>
</property>
<property name="currentIndex">
<number>3</number>
<number>4</number>
</property>
<property name="iconSize">
<size>
@ -3042,6 +3042,16 @@
<string>Ctrl+Shift+Down</string>
</property>
</action>
<action name="actionConvert_to_UTF_8_BOM">
<property name="text">
<string>Convert to UTF-8 BOM</string>
</property>
</action>
<action name="actionEncode_in_UTF_8_BOM">
<property name="text">
<string>Encode in UTF-8 BOM</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -47,7 +47,8 @@ void EditorMiscWidget::doLoad()
QByteArray defaultEncoding = pSettings->editor().defaultEncoding();
if (defaultEncoding == ENCODING_AUTO_DETECT
|| defaultEncoding == ENCODING_SYSTEM_DEFAULT
|| defaultEncoding == ENCODING_UTF8) {
|| defaultEncoding == ENCODING_UTF8
|| defaultEncoding == ENCODING_UTF8_BOM) {
int index =ui->cbEncoding->findData(defaultEncoding);
ui->cbEncoding->setCurrentIndex(index);
ui->cbEncodingDetail->clear();
@ -89,6 +90,7 @@ void EditorMiscWidget::init()
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);
}
@ -100,7 +102,8 @@ void EditorMiscWidget::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
|| userData == ENCODING_UTF8_BOM) {
ui->cbEncodingDetail->setVisible(false);
ui->cbEncodingDetail->clear();
} else {

View File

@ -37,6 +37,7 @@ SystemConsts::SystemConsts(): mDefaultFileFilters()
mCodecNames.append(ENCODING_AUTO_DETECT);
mCodecNames.append(ENCODING_SYSTEM_DEFAULT);
mCodecNames.append(ENCODING_UTF8);
mCodecNames.append(ENCODING_UTF8_BOM);
QStringList codecNames;
QSet<QByteArray> codecAlias;
codecAlias.insert("system");