- 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 - 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: 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 - 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 Red Panda C++ Version 1.0.6
- fix: gcc compiler set name is not correct in Linux - fix: gcc compiler set name is not correct in Linux

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -469,18 +469,6 @@
<source>Can&apos;t start debugging.</source> <source>Can&apos;t start debugging.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </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> <message>
<source>Can&apos;t find Console Pauser</source> <source>Can&apos;t find Console Pauser</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -1343,6 +1331,10 @@
<source>UTF-8</source> <source>UTF-8</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>UTF-8 BOM</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>EditorSnippetWidget</name> <name>EditorSnippetWidget</name>
@ -4444,6 +4436,14 @@
<source>Line %1</source> <source>Line %1</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </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>
<context> <context>
<name>NewClassDialog</name> <name>NewClassDialog</name>
@ -6252,14 +6252,7 @@
</message> </message>
</context> </context>
<context> <context>
<name>SynEdit</name> <name>SynDocument</name>
<message>
<source>The highlighter seems to be in an infinite loop</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SynEditStringList</name>
<message> <message>
<source>Can&apos;t open file &apos;%1&apos; for read!</source> <source>Can&apos;t open file &apos;%1&apos; for read!</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -6269,6 +6262,13 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>SynEdit</name>
<message>
<source>The highlighter seems to be in an infinite loop</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>TodoModel</name> <name>TodoModel</name>
<message> <message>

View File

@ -388,11 +388,13 @@ void MainWindow::updateForEncodingInfo(bool clear) {
ui->actionAuto_Detect->setChecked(editor->encodingOption() == ENCODING_AUTO_DETECT); ui->actionAuto_Detect->setChecked(editor->encodingOption() == ENCODING_AUTO_DETECT);
ui->actionEncode_in_ANSI->setChecked(editor->encodingOption() == ENCODING_SYSTEM_DEFAULT); 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);
ui->actionEncode_in_UTF_8->setChecked(editor->encodingOption() == ENCODING_UTF8_BOM);
} else { } else {
mFileEncodingStatus->setText(""); mFileEncodingStatus->setText("");
ui->actionAuto_Detect->setChecked(false); ui->actionAuto_Detect->setChecked(false);
ui->actionEncode_in_ANSI->setChecked(false); ui->actionEncode_in_ANSI->setChecked(false);
ui->actionEncode_in_UTF_8->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->actionAuto_Detect->setEnabled(false);
ui->actionEncode_in_ANSI->setEnabled(false); ui->actionEncode_in_ANSI->setEnabled(false);
ui->actionEncode_in_UTF_8->setEnabled(false); ui->actionEncode_in_UTF_8->setEnabled(false);
ui->actionEncode_in_UTF_8_BOM->setEnabled(false);
mMenuEncoding->setEnabled(false); mMenuEncoding->setEnabled(false);
ui->actionConvert_to_ANSI->setEnabled(false); ui->actionConvert_to_ANSI->setEnabled(false);
ui->actionConvert_to_UTF_8->setEnabled(false); ui->actionConvert_to_UTF_8->setEnabled(false);
ui->actionConvert_to_UTF_8_BOM->setEnabled(false);
ui->actionCopy->setEnabled(false); ui->actionCopy->setEnabled(false);
ui->actionCut->setEnabled(false); ui->actionCut->setEnabled(false);
ui->actionFoldAll->setEnabled(false); ui->actionFoldAll->setEnabled(false);
@ -454,10 +458,12 @@ void MainWindow::updateEditorActions()
ui->actionAuto_Detect->setEnabled(true); ui->actionAuto_Detect->setEnabled(true);
ui->actionEncode_in_ANSI->setEnabled(true); ui->actionEncode_in_ANSI->setEnabled(true);
ui->actionEncode_in_UTF_8->setEnabled(true); ui->actionEncode_in_UTF_8->setEnabled(true);
ui->actionEncode_in_UTF_8_BOM->setEnabled(true);
mMenuEncoding->setEnabled(true); mMenuEncoding->setEnabled(true);
ui->actionConvert_to_ANSI->setEnabled(e->encodingOption()!=ENCODING_SYSTEM_DEFAULT ui->actionConvert_to_ANSI->setEnabled(e->encodingOption()!=ENCODING_SYSTEM_DEFAULT
&& e->fileEncoding()!=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->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->actionCopy->setEnabled(e->selAvail());
ui->actionCut->setEnabled(e->selAvail()); ui->actionCut->setEnabled(e->selAvail());
@ -2671,11 +2677,13 @@ void MainWindow::buildEncodingMenu()
mMenuEncoding->addAction(ui->actionAuto_Detect); mMenuEncoding->addAction(ui->actionAuto_Detect);
mMenuEncoding->addAction(ui->actionEncode_in_ANSI); mMenuEncoding->addAction(ui->actionEncode_in_ANSI);
mMenuEncoding->addAction(ui->actionEncode_in_UTF_8); mMenuEncoding->addAction(ui->actionEncode_in_UTF_8);
mMenuEncoding->addAction(ui->actionEncode_in_UTF_8_BOM);
mMenuEncoding->addMenu(menuCharsets); mMenuEncoding->addMenu(menuCharsets);
mMenuEncoding->addSeparator(); mMenuEncoding->addSeparator();
mMenuEncoding->addAction(ui->actionConvert_to_ANSI); mMenuEncoding->addAction(ui->actionConvert_to_ANSI);
mMenuEncoding->addAction(ui->actionConvert_to_UTF_8); mMenuEncoding->addAction(ui->actionConvert_to_UTF_8);
mMenuEncoding->addAction(ui->actionConvert_to_UTF_8_BOM);
QList<PCharsetInfo> charsetsForLocale = pCharsetInfoManager->findCharsetByLocale(pCharsetInfoManager->localeName()); QList<PCharsetInfo> charsetsForLocale = pCharsetInfoManager->findCharsetByLocale(pCharsetInfoManager->localeName());
@ -2702,6 +2710,7 @@ void MainWindow::buildEncodingMenu()
ui->actionAuto_Detect->setCheckable(true); ui->actionAuto_Detect->setCheckable(true);
ui->actionEncode_in_ANSI->setCheckable(true); ui->actionEncode_in_ANSI->setCheckable(true);
ui->actionEncode_in_UTF_8->setCheckable(true); ui->actionEncode_in_UTF_8->setCheckable(true);
ui->actionEncode_in_UTF_8_BOM->setCheckable(true);
} }
void MainWindow::maximizeEditor() void MainWindow::maximizeEditor()
@ -7656,3 +7665,30 @@ void MainWindow::on_actionMove_Selection_Down_triggered()
editor->moveSelDown(); 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_actionMove_Selection_Down_triggered();
void on_actionConvert_to_UTF_8_BOM_triggered();
void on_actionEncode_in_UTF_8_BOM_triggered();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
EditorList *mEditorList; EditorList *mEditorList;

View File

@ -545,7 +545,7 @@
<enum>QTabWidget::South</enum> <enum>QTabWidget::South</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>3</number> <number>4</number>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -3042,6 +3042,16 @@
<string>Ctrl+Shift+Down</string> <string>Ctrl+Shift+Down</string>
</property> </property>
</action> </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> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -47,7 +47,8 @@ void EditorMiscWidget::doLoad()
QByteArray defaultEncoding = pSettings->editor().defaultEncoding(); QByteArray defaultEncoding = pSettings->editor().defaultEncoding();
if (defaultEncoding == ENCODING_AUTO_DETECT if (defaultEncoding == ENCODING_AUTO_DETECT
|| defaultEncoding == ENCODING_SYSTEM_DEFAULT || defaultEncoding == ENCODING_SYSTEM_DEFAULT
|| defaultEncoding == ENCODING_UTF8) { || defaultEncoding == ENCODING_UTF8
|| defaultEncoding == ENCODING_UTF8_BOM) {
int index =ui->cbEncoding->findData(defaultEncoding); int index =ui->cbEncoding->findData(defaultEncoding);
ui->cbEncoding->setCurrentIndex(index); ui->cbEncoding->setCurrentIndex(index);
ui->cbEncodingDetail->clear(); ui->cbEncodingDetail->clear();
@ -89,6 +90,7 @@ void EditorMiscWidget::init()
ui->cbEncoding->clear(); ui->cbEncoding->clear();
ui->cbEncoding->addItem(tr("ANSI"),ENCODING_SYSTEM_DEFAULT); ui->cbEncoding->addItem(tr("ANSI"),ENCODING_SYSTEM_DEFAULT);
ui->cbEncoding->addItem(tr("UTF-8"),ENCODING_UTF8); ui->cbEncoding->addItem(tr("UTF-8"),ENCODING_UTF8);
ui->cbEncoding->addItem(tr("UTF-8 BOM"),ENCODING_UTF8_BOM);
foreach (const QString& langName, pCharsetInfoManager->languageNames()) { foreach (const QString& langName, pCharsetInfoManager->languageNames()) {
ui->cbEncoding->addItem(langName,langName); ui->cbEncoding->addItem(langName,langName);
} }
@ -100,7 +102,8 @@ void EditorMiscWidget::on_cbEncoding_currentTextChanged(const QString &/*arg1*/)
QString userData = ui->cbEncoding->currentData().toString(); QString userData = ui->cbEncoding->currentData().toString();
if (userData == ENCODING_AUTO_DETECT if (userData == ENCODING_AUTO_DETECT
|| userData == ENCODING_SYSTEM_DEFAULT || userData == ENCODING_SYSTEM_DEFAULT
|| userData == ENCODING_UTF8) { || userData == ENCODING_UTF8
|| userData == ENCODING_UTF8_BOM) {
ui->cbEncodingDetail->setVisible(false); ui->cbEncodingDetail->setVisible(false);
ui->cbEncodingDetail->clear(); ui->cbEncodingDetail->clear();
} else { } else {

View File

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