- enhancement: add exec charset option to compiler set settings

This commit is contained in:
royqh1979@gmail.com 2022-01-24 11:23:30 +08:00
parent 722d02d688
commit 4797c15b04
16 changed files with 600 additions and 441 deletions

View File

@ -17,6 +17,7 @@ Red Panda C++ Version 0.13.3
- enhancement: highlighter for GLSL (OpenGL Shading Language)
- add a new template for raylib shader apps
- fix: project files' charset settings doesn't work correctly
- enhancement: add exec charset option to compiler set settings
Red Panda C++ Version 0.13.2
- fix: "delete and exit" button in the environtment / folder option page doesn't work correctly

File diff suppressed because it is too large Load Diff

View File

@ -282,6 +282,8 @@ QString Compiler::getCharsetArgument(const QByteArray& encoding)
if (compilerSet()->autoAddCharsetParams() && encoding != ENCODING_ASCII
&& compilerSet()->compilerType()!="Clang") {
QString encodingName;
QString execEncodingName;
QString compilerSetExecCharset = compilerSet()->execCharset();
QString systemEncodingName=pCharsetInfoManager->getDefaultSystemEncoding();
if (encoding == ENCODING_SYSTEM_DEFAULT) {
encodingName = systemEncodingName;
@ -290,8 +292,14 @@ QString Compiler::getCharsetArgument(const QByteArray& encoding)
} else {
encodingName = encoding;
}
if (compilerSetExecCharset == ENCODING_SYSTEM_DEFAULT
|| compilerSetExecCharset.isEmpty()) {
execEncodingName = systemEncodingName;
} else {
execEncodingName = compilerSetExecCharset;
}
result += QString(" -finput-charset=%1 -fexec-charset=%2")
.arg(encodingName,systemEncodingName);
.arg(encodingName, execEncodingName);
}
return result;
}

View File

@ -1631,6 +1631,16 @@ void Editor::deleteWord()
ExecuteCommand(SynEditorCommand::ecDeleteWord,QChar(),nullptr);
}
void Editor::deleteToWordStart()
{
ExecuteCommand(SynEditorCommand::ecDeleteWordStart,QChar(),nullptr);
}
void Editor::deleteToWordEnd()
{
ExecuteCommand(SynEditorCommand::ecDeleteWordEnd,QChar(),nullptr);
}
void Editor::deleteLine()
{
ExecuteCommand(SynEditorCommand::ecDeleteLine,QChar(),nullptr);

View File

@ -205,6 +205,8 @@ public:
bool notParsed();
void insertLine();
void deleteWord();
void deleteToWordStart();
void deleteToWordEnd();
void deleteLine();
void duplicateLine();
void deleteToEOL();

View File

@ -6160,3 +6160,21 @@ void MainWindow::on_actionInterrupt_triggered()
mDebugger->interrupt();
}
}
void MainWindow::on_actionDelete_Last_Word_triggered()
{
Editor *e=mEditorList->getEditor();
if (e) {
e->deleteToWordStart();
}
}
void MainWindow::on_actionDelete_to_Word_End_triggered()
{
Editor *e=mEditorList->getEditor();
if (e) {
e->deleteToWordEnd();
}
}

View File

@ -557,6 +557,10 @@ private slots:
void on_actionInterrupt_triggered();
void on_actionDelete_Last_Word_triggered();
void on_actionDelete_to_Word_End_triggered();
private:
Ui::MainWindow *ui;
EditorList *mEditorList;

View File

@ -540,7 +540,6 @@
<widget class="IssuesTable" name="tableIssues">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
@ -1395,7 +1394,7 @@
<x>0</x>
<y>0</y>
<width>1114</width>
<height>26</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -1469,6 +1468,8 @@
<addaction name="actionDelete_Line"/>
<addaction name="actionDuplicate_Line"/>
<addaction name="actionDelete_Word"/>
<addaction name="actionDelete_Last_Word"/>
<addaction name="actionDelete_to_Word_End"/>
<addaction name="actionDelete_to_BOL"/>
<addaction name="actionDelete_to_EOL"/>
</widget>
@ -2675,6 +2676,25 @@
<string>Interrupt</string>
</property>
</action>
<action name="actionDelete_Last_Word">
<property name="text">
<string>Delete To Word Begin</string>
</property>
<property name="toolTip">
<string>Delete To Word Begin</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+B</string>
</property>
</action>
<action name="actionDelete_to_Word_End">
<property name="text">
<string>Delete to Word End</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+E</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -217,7 +217,7 @@ void SynEditKeyStrokes::resetDefaults()
add(SynEditorCommand::ecDeleteChar, Qt::Key_Delete, Qt::NoModifier);
add(SynEditorCommand::ecDeleteLastChar, Qt::Key_Backspace, Qt::NoModifier);
add(SynEditorCommand::ecDeleteLastChar, Qt::Key_Backspace, Qt::ShiftModifier);
add(SynEditorCommand::ecDeleteLastWord, Qt::Key_Backspace, Qt::ControlModifier);
add(SynEditorCommand::ecDeleteWordStart, Qt::Key_Backspace, Qt::ControlModifier);
add(SynEditorCommand::ecUndo, Qt::Key_Backspace, Qt::AltModifier);
add(SynEditorCommand::ecRedo, Qt::Key_Backspace, Qt::AltModifier|Qt::ShiftModifier);
add(SynEditorCommand::ecLineBreak, Qt::Key_Return, Qt::NoModifier);

View File

@ -135,8 +135,8 @@ enum class SynEditorCommand {
ecDeleteLastChar = 501, // Delete last char (i.e. backspace key)
ecDeleteChar = 502, // Delete char at cursor (i.e. delete key)
ecDeleteWord = 503, // Delete from cursor to end of word
ecDeleteLastWord = 504, // Delete from cursor to start of word
ecDeleteWordEnd = 503, // Delete from cursor to end of word
ecDeleteWordStart = 504, // Delete from cursor to start of word
ecDeleteBOL = 505, // Delete from cursor to beginning of line
ecDeleteEOL = 506, // Delete from cursor to end of line
ecDeleteLine = 507, // Delete current line
@ -148,6 +148,7 @@ enum class SynEditorCommand {
ecMoveSelUp = 513, // Move selection up
ecMoveSelDown = 514, // Move selection down
ecImeStr = 550, // Insert character(s) from IME
ecDeleteWord = 551, // Delete current Word
ecUndo = 601, // Perform undo if available
ecRedo = 602, // Perform redo if available

View File

@ -1373,8 +1373,8 @@ BufferCoord SynEdit::wordEndEx(const BufferCoord &XY)
// valid line?
if ((CY >= 1) && (CY <= mLines->count())) {
QString Line = mLines->getString(CY - 1);
if (CX <= Line.length() && CX-2>=0) {
if (isWordChar(Line[CX - 2]))
if (CX <= Line.length() && CX-1>=0) {
if (isWordChar(Line[CX - 1]))
CX = StrScanForNonWordChar(Line, CX);
if (CX == 0)
CX = Line.length() + 1;
@ -2022,12 +2022,27 @@ void SynEdit::doDeleteToEOL()
deleteFromTo(caretXY(),BufferCoord{lineText().length()+1,mCaretY});
}
void SynEdit::doDeleteLastWord()
void SynEdit::doDeleteToWordStart()
{
if (mReadOnly)
return;
BufferCoord start = prevWordPos();
BufferCoord end = wordEndEx(start);
BufferCoord start = wordStart();
BufferCoord end = caretXY();
if (start==end) {
start = prevWordPos();
}
deleteFromTo(start,end);
}
void SynEdit::doDeleteToWordEnd()
{
if (mReadOnly)
return;
BufferCoord start = caretXY();
BufferCoord end = wordEnd();
if (start == end) {
end = wordEndEx(nextWordPos());
}
deleteFromTo(start,end);
}
@ -5099,8 +5114,8 @@ int SynEdit::insertTextByNormalMode(const QString &Value)
sLeftSide = GetLeftSpacing(calcIndentSpaces(caretY,s,true),true);
}
Str = sLeftSide + s;
}
Str = Value.mid(0, P - Start);
} else
Str = sLeftSide + Value.mid(0, P - Start);
properSetLine(caretY - 1, Str);
mLines->insertLines(caretY, CountLines(Value,P));
} else {
@ -5426,8 +5441,11 @@ void SynEdit::ExecuteCommand(SynEditorCommand Command, QChar AChar, void *pData)
case SynEditorCommand::ecDeleteEOL:
doDeleteToEOL();
break;
case SynEditorCommand::ecDeleteLastWord:
doDeleteLastWord();
case SynEditorCommand::ecDeleteWordStart:
doDeleteToWordStart();
break;
case SynEditorCommand::ecDeleteWordEnd:
doDeleteToWordEnd();
break;
case SynEditorCommand::ecDeleteBOL:
doDeleteFromBOL();

View File

@ -553,7 +553,8 @@ private:
void doDeleteCurrentChar();
void doDeleteWord();
void doDeleteToEOL();
void doDeleteLastWord();
void doDeleteToWordStart();
void doDeleteToWordEnd();
void doDeleteFromBOL();
void doDeleteLine();
void doSelecteLine();

View File

@ -1387,6 +1387,7 @@ void Settings::Editor::setTabToSpaces(bool tabToSpaces)
Settings::CompilerSet::CompilerSet(const QString& compilerFolder):
mAutoAddCharsetParams(true),
mExecCharset(ENCODING_SYSTEM_DEFAULT),
mStaticLink(true)
{
if (!compilerFolder.isEmpty()) {
@ -2307,14 +2308,14 @@ QByteArray Settings::CompilerSet::getCompilerOutput(const QString &binDir, const
return result.trimmed();
}
const QString &Settings::CompilerSet::execCharser() const
const QString &Settings::CompilerSet::execCharset() const
{
return mExecCharser;
return mExecCharset;
}
void Settings::CompilerSet::setExecCharser(const QString &newExecCharser)
void Settings::CompilerSet::setExecCharset(const QString &newExecCharset)
{
mExecCharser = newExecCharser;
mExecCharset = newExecCharset;
}
const QString &Settings::CompilerSet::debugServer() const
@ -2760,7 +2761,7 @@ void Settings::CompilerSets::saveSet(int index)
mSettings->mSettings.setValue("customLinkParams", pSet->customLinkParams());
mSettings->mSettings.setValue("AddCharset", pSet->autoAddCharsetParams());
mSettings->mSettings.setValue("StaticLink", pSet->staticLink());
mSettings->mSettings.setValue("ExecCharser", pSet->execCharser());
mSettings->mSettings.setValue("ExecCharset", pSet->execCharset());
// Misc. properties
mSettings->mSettings.setValue("DumpMachine", pSet->dumpMachine());
@ -2820,13 +2821,16 @@ Settings::PCompilerSet Settings::CompilerSets::loadSet(int index)
pSet->setIniOptions(mSettings->mSettings.value("Options").toByteArray());
// Save extra 'general' options
pSet->setUseCustomCompileParams(mSettings->mSettings.value("useCustomCompileParams").toBool());
pSet->setUseCustomCompileParams(mSettings->mSettings.value("useCustomCompileParams", false).toBool());
pSet->setCustomCompileParams(mSettings->mSettings.value("customCompileParams").toString());
pSet->setUseCustomLinkParams(mSettings->mSettings.value("useCustomLinkParams").toBool());
pSet->setUseCustomLinkParams(mSettings->mSettings.value("useCustomLinkParams", false).toBool());
pSet->setCustomLinkParams(mSettings->mSettings.value("customLinkParams").toString());
pSet->setAutoAddCharsetParams(mSettings->mSettings.value("AddCharset").toBool());
pSet->setStaticLink(mSettings->mSettings.value("StaticLink").toBool());
pSet->setExecCharser(mSettings->mSettings.value("ExecCharser").toString());
pSet->setAutoAddCharsetParams(mSettings->mSettings.value("AddCharset", true).toBool());
pSet->setStaticLink(mSettings->mSettings.value("StaticLink", false).toBool());
pSet->setExecCharset(mSettings->mSettings.value("ExecCharset", ENCODING_SYSTEM_DEFAULT).toString());
if (pSet->execCharset().isEmpty()) {
pSet->setExecCharset(ENCODING_SYSTEM_DEFAULT);
}
pSet->setDumpMachine(mSettings->mSettings.value("DumpMachine").toString());
pSet->setVersion(mSettings->mSettings.value("Version").toString());

View File

@ -1177,8 +1177,8 @@ public:
int compilerSetType() const;
void setCompilerSetType(int newCompilerSetType);
const QString &execCharser() const;
void setExecCharser(const QString &newExecCharser);
const QString &execCharset() const;
void setExecCharset(const QString &newExecCharset);
private:
// Initialization
@ -1225,7 +1225,7 @@ public:
QString mCustomCompileParams;
QString mCustomLinkParams;
bool mAutoAddCharsetParams;
QString mExecCharser;
QString mExecCharset;
bool mStaticLink;
// Options

View File

@ -59,9 +59,9 @@ CompilerSetOptionWidget::~CompilerSetOptionWidget()
void CompilerSetOptionWidget::init()
{
ui->cbEncoding->setVisible(false);
ui->cbEncodingDetails->setVisible(false);
ui->cbEncoding->clear();
ui->cbEncoding->addItem(tr("Auto detect"),ENCODING_AUTO_DETECT);
ui->cbEncoding->addItem(tr("ANSI"),ENCODING_SYSTEM_DEFAULT);
ui->cbEncoding->addItem(tr("UTF-8"),ENCODING_UTF8);
foreach (const QString& langName, pCharsetInfoManager->languageNames()) {
@ -143,6 +143,26 @@ static void loadCompilerSetSettings(Settings::PCompilerSet pSet, Ui::CompilerSet
ui->txtGDBServer->setText(pSet->debugServer());
ui->txtResourceCompiler->setText(pSet->resourceCompiler());
ui->txtProfiler->setText(pSet->profiler());
ui->cbEncoding->setVisible(pSet->autoAddCharsetParams());
if (pSet->execCharset() == ENCODING_AUTO_DETECT
|| pSet->execCharset() == ENCODING_SYSTEM_DEFAULT
|| pSet->execCharset() == ENCODING_UTF8) {
ui->cbEncoding->setCurrentText(pSet->execCharset());
ui->cbEncodingDetails->clear();
ui->cbEncodingDetails->setVisible(false);
} else {
QString encoding = pSet->execCharset();
QString language = pCharsetInfoManager->findLanguageByCharsetName(encoding);
ui->cbEncoding->setCurrentText(language);
ui->cbEncodingDetails->setVisible(true);
ui->cbEncodingDetails->clear();
QList<PCharsetInfo> infos = pCharsetInfoManager->findCharsetsByLanguageName(language);
foreach (const PCharsetInfo& info, infos) {
ui->cbEncodingDetails->addItem(info->name);
}
ui->cbEncodingDetails->setCurrentText(encoding);
}
}
void CompilerSetOptionWidget::doLoad()
@ -198,7 +218,6 @@ void CompilerSetOptionWidget::reloadCurrentCompilerSet()
mLibDirWidget->setDirList(pSet->libDirs());
mCIncludeDirWidget->setDirList(pSet->CIncludeDirs());
mCppIncludeDirWidget->setDirList(pSet->CppIncludeDirs());
}
void CompilerSetOptionWidget::saveCurrentCompilerSet()
@ -226,6 +245,12 @@ void CompilerSetOptionWidget::saveCurrentCompilerSet()
pSet->CIncludeDirs()=mCIncludeDirWidget->dirList();
pSet->CppIncludeDirs()=mCppIncludeDirWidget->dirList();
if (ui->cbEncodingDetails->isVisible()) {
pSet->setExecCharset(ui->cbEncodingDetails->currentText());
} else {
pSet->setExecCharset(ui->cbEncoding->currentText());
}
//read values in the options widget
QTabWidget* pTab = ui->optionTabs;
for (int i=0;i<pTab->count();i++) {
@ -324,3 +349,28 @@ void CompilerSetOptionWidget::updateIcons()
pIconsManager->setIcon(ui->btnChooseProfiler, IconsManager::ACTION_FILE_OPEN_FOLDER);
pIconsManager->setIcon(ui->btnChooseResourceCompiler, IconsManager::ACTION_FILE_OPEN_FOLDER);
}
void CompilerSetOptionWidget::on_cbEncoding_currentTextChanged(const QString &arg1)
{
QString userData = ui->cbEncoding->currentData().toString();
if (userData == ENCODING_AUTO_DETECT
|| userData == ENCODING_SYSTEM_DEFAULT
|| userData == ENCODING_UTF8) {
ui->cbEncodingDetails->setVisible(false);
ui->cbEncodingDetails->clear();
} else {
ui->cbEncodingDetails->setVisible(true);
ui->cbEncodingDetails->clear();
QList<PCharsetInfo> infos = pCharsetInfoManager->findCharsetsByLanguageName(userData);
foreach (const PCharsetInfo& info, infos) {
ui->cbEncodingDetails->addItem(info->name);
}
}
}
void CompilerSetOptionWidget::on_cbEncodingDetails_currentTextChanged(const QString &arg1)
{
}

View File

@ -61,6 +61,8 @@ private slots:
void on_btnRemoveCompilerSet_pressed();
void updateIcons();
void on_cbEncoding_currentTextChanged(const QString &arg1);
void on_cbEncodingDetails_currentTextChanged(const QString &arg1);
};
#endif // COMPILERSETOPTIONWIDGET_H