From 1a00443f8996ccf59f36b93e081581a989c95e39 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Tue, 14 Sep 2021 12:10:43 +0800 Subject: [PATCH] work save: - change editor's encoding also change project unit's encoding Option - ascii encoding file don't add encoding info when generating project make file - make Settings Dialog more general --- RedPandaIDE/compiler/compiler.cpp | 7 +- RedPandaIDE/compiler/filecompiler.cpp | 2 +- RedPandaIDE/compiler/projectcompiler.cpp | 6 +- RedPandaIDE/compiler/stdincompiler.cpp | 2 +- RedPandaIDE/editor.cpp | 10 ++ RedPandaIDE/mainwindow.cpp | 26 ++- RedPandaIDE/settingsdialog/settingsdialog.cpp | 155 ++++++++++-------- RedPandaIDE/settingsdialog/settingsdialog.h | 53 +++--- RedPandaIDE/systemconsts.h | 2 + 9 files changed, 139 insertions(+), 124 deletions(-) diff --git a/RedPandaIDE/compiler/compiler.cpp b/RedPandaIDE/compiler/compiler.cpp index 336ee2d3..63540c04 100644 --- a/RedPandaIDE/compiler/compiler.cpp +++ b/RedPandaIDE/compiler/compiler.cpp @@ -1,6 +1,7 @@ #include "compiler.h" #include "utils.h" #include "compilermanager.h" +#include "../systemconsts.h" #include #include @@ -527,7 +528,11 @@ void Compiler::runCommand(const QString &cmd, const QString &arguments, const Q if (!cmdDir.isEmpty()) { QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QString path = env.value("PATH"); - path = cmdDir + ';' + path; + if (path.isEmpty()) { + path = cmdDir; + } else { + path = cmdDir + PATH_SEPARATOR + path; + } env.insert("PATH",path); process.setProcessEnvironment(env); } diff --git a/RedPandaIDE/compiler/filecompiler.cpp b/RedPandaIDE/compiler/filecompiler.cpp index 4f19508f..b487b245 100644 --- a/RedPandaIDE/compiler/filecompiler.cpp +++ b/RedPandaIDE/compiler/filecompiler.cpp @@ -68,7 +68,7 @@ bool FileCompiler::prepareForCompile() log(tr("Processing %1 source file:").arg(strFileType)); log("------------------"); log(tr("%1 Compiler: %2").arg(strFileType).arg(mCompiler)); - log(tr("Command: %1 %2").arg(QFileInfo(mCompiler).fileName()).arg(mArguments)); + log(tr("Command: %1 %2").arg(extractFileName(mCompiler)).arg(mArguments)); mDirectory = extractFileDir(mFilename); return true; } diff --git a/RedPandaIDE/compiler/projectcompiler.cpp b/RedPandaIDE/compiler/projectcompiler.cpp index 56e089b3..fbe1240c 100644 --- a/RedPandaIDE/compiler/projectcompiler.cpp +++ b/RedPandaIDE/compiler/projectcompiler.cpp @@ -324,10 +324,10 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file) QString encodingStr; if (mProject->options().addCharset) { if (unit->encoding() == ENCODING_AUTO_DETECT) { - if (unit->editor()) + if (unit->editor() && unit->editor()->fileEncoding()!=ENCODING_ASCII) encodingStr = QString(" -finput-charset=%1 -fexec-charset=%2") .arg(unit->editor()->fileEncoding(),getDefaultSystemEncoding()); - } else { + } else if (unit->encoding()!=ENCODING_ASCII) { encodingStr = QString(" -finput-charset=%1 -fexec-charset=%2") .arg(unit->encoding(),getDefaultSystemEncoding()); } @@ -447,7 +447,7 @@ bool ProjectCompiler::prepareForCompile() log(tr("Processing makefile:")); log("--------"); log(tr("- makefile processer: %1").arg(mCompiler)); - log(tr("- Command: %1 %2").arg(mCompiler).arg(mArguments)); + log(tr("- Command: %1 %2").arg(extractFileName(mCompiler)).arg(mArguments)); log(""); return true; diff --git a/RedPandaIDE/compiler/stdincompiler.cpp b/RedPandaIDE/compiler/stdincompiler.cpp index 5c4905b0..9bff0ab7 100644 --- a/RedPandaIDE/compiler/stdincompiler.cpp +++ b/RedPandaIDE/compiler/stdincompiler.cpp @@ -56,7 +56,7 @@ bool StdinCompiler::prepareForCompile() log(tr("Processing %1 source file:").arg(strFileType)); log("------------------"); log(tr("%1 Compiler: %2").arg(strFileType).arg(mCompiler)); - log(tr("Command: %1 %2").arg(QFileInfo(mCompiler).fileName()).arg(mArguments)); + log(tr("Command: %1 %2").arg(extractFileName(mCompiler)).arg(mArguments)); mDirectory = extractFileDir(mFilename); return true; } diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 6cab3ca2..968b8ed4 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -296,6 +296,16 @@ void Editor::setEncodingOption(const QByteArray& encoding) noexcept{ loadFile(); else pMainWindow->updateForEncodingInfo(); + if (mInProject) { + std::shared_ptr project = pMainWindow->project(); + if (project) { + int index = project->indexInUnits(this); + if (index>=0) { + PProjectUnit unit = project->units()[index]; + unit->setEncoding(mEncodingOption); + } + } + } } const QByteArray& Editor::fileEncoding() const noexcept{ return mFileEncoding; diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 5db55355..0a142b27 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1447,23 +1447,18 @@ void MainWindow::openShell(const QString &folder, const QString &shellCommand) }); QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QString path = env.value("PATH"); - + QStringList pathAdded; if (pSettings->compilerSets().defaultSet()) { foreach(const QString& dir, pSettings->compilerSets().defaultSet()->binDirs()) { -#ifdef Q_OS_WIN - path+=";"; -#else - path+=":"; -#endif - path+=dir; + pathAdded.append(dir); } } -#ifdef Q_OS_WIN - path+=";"; -#else - path+=":"; -#endif - path+=pSettings->dirs().app(); + pathAdded.append(pSettings->dirs().app()); + if (!path.isEmpty()) { + path+= PATH_SEPARATOR + pathAdded.join(PATH_SEPARATOR); + } else { + path = pathAdded.join(PATH_SEPARATOR); + } env.insert("PATH",path); process.setProcessEnvironment(env); process.startDetached(); @@ -1884,8 +1879,9 @@ void MainWindow::on_actionSaveAs_triggered() void MainWindow::on_actionOptions_triggered() { bool oldCodeCompletion = pSettings->codeCompletion().enabled(); - SettingsDialog settingsDialog; - settingsDialog.exec(); + PSettingsDialog settingsDialog = SettingsDialog::optionDialog(); + settingsDialog->exec(); + bool newCodeCompletion = pSettings->codeCompletion().enabled(); if (!oldCodeCompletion && newCodeCompletion) { Editor *e = mEditorList->getEditor(); diff --git a/RedPandaIDE/settingsdialog/settingsdialog.cpp b/RedPandaIDE/settingsdialog/settingsdialog.cpp index 16a417a5..1e8759cb 100644 --- a/RedPandaIDE/settingsdialog/settingsdialog.cpp +++ b/RedPandaIDE/settingsdialog/settingsdialog.cpp @@ -32,77 +32,6 @@ SettingsDialog::SettingsDialog(QWidget *parent) : ui->btnApply->setEnabled(false); - pEnvironmentAppearenceWidget = new EnvironmentAppearenceWidget(tr("Appearence"),tr("Environment")); - pEnvironmentAppearenceWidget->init(); - addWidget(pEnvironmentAppearenceWidget); - - pCompilerSetOptionWidget = new CompilerSetOptionWidget(tr("Compiler Set"),tr("Compiler")); - pCompilerSetOptionWidget->init(); - addWidget(pCompilerSetOptionWidget); - - pCompilerAutolinkWidget = new CompilerAutolinkWidget(tr("Auto Link"),tr("Compiler")); - pCompilerAutolinkWidget->init(); - addWidget(pCompilerAutolinkWidget); - - pEditorGeneralWidget = new EditorGeneralWidget(tr("General"),tr("Editor")); - pEditorGeneralWidget->init(); - addWidget(pEditorGeneralWidget); - - pEditorFontWidget = new EditorFontWidget(tr("Font"),tr("Editor")); - pEditorFontWidget->init(); - addWidget(pEditorFontWidget); - - pEditorClipboardWidget = new EditorClipboardWidget(tr("Copy & Export"),tr("Editor")); - pEditorClipboardWidget->init(); - addWidget(pEditorClipboardWidget); - - pEditorColorSchemeWidget = new EditorColorSchemeWidget(tr("Color"),tr("Editor")); - pEditorColorSchemeWidget->init(); - addWidget(pEditorColorSchemeWidget); - - pEditorCodeCompletionWidget = new EditorCodeCompletionWidget(tr("Code Completion"),tr("Editor")); - pEditorCodeCompletionWidget->init(); - addWidget(pEditorCodeCompletionWidget); - - pEditorSymbolCompletionWidget = new EditorSymbolCompletionWidget(tr("Symbol Completion"),tr("Editor")); - pEditorSymbolCompletionWidget->init(); - addWidget(pEditorSymbolCompletionWidget); - - pEditorSyntaxCheckWidget = new EditorSyntaxCheckWidget(tr("Auto Syntax Checking"),tr("Editor")); - pEditorSyntaxCheckWidget->init(); - addWidget(pEditorSyntaxCheckWidget); - - pEditorAutoSaveWidget = new EditorAutoSaveWidget(tr("Auto save"),tr("Editor")); - pEditorAutoSaveWidget->init(); - addWidget(pEditorAutoSaveWidget); - - pEditorMiscWidget = new EditorMiscWidget(tr("Misc"),tr("Editor")); - pEditorMiscWidget->init(); - addWidget(pEditorMiscWidget); - - - pExecutorGeneralWidget = new ExecutorGeneralWidget(tr("General"),tr("Program Runner")); - pExecutorGeneralWidget->init(); - addWidget(pExecutorGeneralWidget); - - pDebugGeneralWidget = new DebugGeneralWidget(tr("General"),tr("Debugger")); - pDebugGeneralWidget->init(); - addWidget(pDebugGeneralWidget); - - pFormatterGeneralWidget = new FormatterGeneralWidget(tr("General"),tr("Code Formatter")); - pFormatterGeneralWidget->init(); - addWidget(pFormatterGeneralWidget); - - - ui->widgetsView->expandAll(); - //select the first widget of the first group - auto groupIndex = ui->widgetsView->model()->index(0,0); - auto widgetIndex = ui->widgetsView->model()->index(0,0, groupIndex); - ui->widgetsView->selectionModel()->setCurrentIndex( - widgetIndex, - QItemSelectionModel::Select - ); - on_widgetsView_clicked(widgetIndex); } SettingsDialog::~SettingsDialog() @@ -130,7 +59,89 @@ void SettingsDialog::addWidget(SettingsWidget *pWidget) pWidgetItem->setData(mSettingWidgets.count()-1, GetWidgetIndexRole); pGroupItem->appendRow(pWidgetItem); connect(pWidget, &SettingsWidget::settingsChanged, - this , &SettingsDialog::widget_settings_changed); + this , &SettingsDialog::widget_settings_changed); +} + +void SettingsDialog::selectFirstWidget() +{ + ui->widgetsView->expandAll(); + //select the first widget of the first group + auto groupIndex = ui->widgetsView->model()->index(0,0); + auto widgetIndex = ui->widgetsView->model()->index(0,0, groupIndex); + ui->widgetsView->selectionModel()->setCurrentIndex( + widgetIndex, + QItemSelectionModel::Select + ); + on_widgetsView_clicked(widgetIndex); +} + +PSettingsDialog SettingsDialog::optionDialog() +{ + PSettingsDialog dialog = std::make_shared(); + + SettingsWidget* widget = new EnvironmentAppearenceWidget(tr("Appearence"),tr("Environment")); + widget->init(); + dialog->addWidget(widget); + + widget = new CompilerSetOptionWidget(tr("Compiler Set"),tr("Compiler")); + widget->init(); + dialog->addWidget(widget); + + widget = new CompilerAutolinkWidget(tr("Auto Link"),tr("Compiler")); + widget->init(); + dialog->addWidget(widget); + + widget = new EditorGeneralWidget(tr("General"),tr("Editor")); + widget->init(); + dialog->addWidget(widget); + + widget = new EditorFontWidget(tr("Font"),tr("Editor")); + widget->init(); + dialog->addWidget(widget); + + widget = new EditorClipboardWidget(tr("Copy & Export"),tr("Editor")); + widget->init(); + dialog->addWidget(widget); + + widget = new EditorColorSchemeWidget(tr("Color"),tr("Editor")); + widget->init(); + dialog->addWidget(widget); + + widget = new EditorCodeCompletionWidget(tr("Code Completion"),tr("Editor")); + widget->init(); + dialog->addWidget(widget); + + widget = new EditorSymbolCompletionWidget(tr("Symbol Completion"),tr("Editor")); + widget->init(); + dialog->addWidget(widget); + + widget = new EditorSyntaxCheckWidget(tr("Auto Syntax Checking"),tr("Editor")); + widget->init(); + dialog->addWidget(widget); + + widget = new EditorAutoSaveWidget(tr("Auto save"),tr("Editor")); + widget->init(); + dialog->addWidget(widget); + + widget = new EditorMiscWidget(tr("Misc"),tr("Editor")); + widget->init(); + dialog->addWidget(widget); + + widget = new ExecutorGeneralWidget(tr("General"),tr("Program Runner")); + widget->init(); + dialog->addWidget(widget); + + widget = new DebugGeneralWidget(tr("General"),tr("Debugger")); + widget->init(); + dialog->addWidget(widget); + + widget = new FormatterGeneralWidget(tr("General"),tr("Code Formatter")); + widget->init(); + dialog->addWidget(widget); + + dialog->selectFirstWidget(); + + return dialog; } diff --git a/RedPandaIDE/settingsdialog/settingsdialog.h b/RedPandaIDE/settingsdialog/settingsdialog.h index a86e54e8..9547e562 100644 --- a/RedPandaIDE/settingsdialog/settingsdialog.h +++ b/RedPandaIDE/settingsdialog/settingsdialog.h @@ -10,22 +10,8 @@ namespace Ui { class SettingsDialog; } -class CompilerSetOptionWidget; -class CompilerAutolinkWidget; -class EditorGeneralWidget; -class EditorFontWidget; -class EditorClipboardWidget; -class EditorSymbolCompletionWidget; -class EditorColorSchemeWidget; -class EditorSyntaxCheckWidget; -class EditorCodeCompletionWidget; -class EditorAutoSaveWidget; -class EditorMiscWidget; -class EnvironmentAppearenceWidget; -class ExecutorGeneralWidget; -class DebugGeneralWidget; -class FormatterGeneralWidget; -class SettingsWidget; +class SettingsDialog; +using PSettingsDialog = std::shared_ptr; class SettingsDialog : public QDialog { Q_OBJECT @@ -38,6 +24,11 @@ public: ~SettingsDialog(); void addWidget(SettingsWidget* pWidget); + + void selectFirstWidget(); + + static PSettingsDialog optionDialog(); + private slots: void widget_settings_changed(bool value); void on_widgetsView_clicked(const QModelIndex &index); @@ -54,21 +45,21 @@ private: QList mSettingWidgets; QStandardItemModel model; - CompilerSetOptionWidget *pCompilerSetOptionWidget; - CompilerAutolinkWidget *pCompilerAutolinkWidget; - EditorGeneralWidget *pEditorGeneralWidget; - EditorFontWidget *pEditorFontWidget; - EditorClipboardWidget *pEditorClipboardWidget; - EditorColorSchemeWidget *pEditorColorSchemeWidget; - EnvironmentAppearenceWidget *pEnvironmentAppearenceWidget; - EditorSymbolCompletionWidget *pEditorSymbolCompletionWidget; - EditorCodeCompletionWidget *pEditorCodeCompletionWidget; - EditorSyntaxCheckWidget *pEditorSyntaxCheckWidget; - EditorAutoSaveWidget *pEditorAutoSaveWidget; - EditorMiscWidget *pEditorMiscWidget; - ExecutorGeneralWidget *pExecutorGeneralWidget; - DebugGeneralWidget *pDebugGeneralWidget; - FormatterGeneralWidget *pFormatterGeneralWidget; +// CompilerSetOptionWidget *pCompilerSetOptionWidget; +// CompilerAutolinkWidget *pCompilerAutolinkWidget; +// EditorGeneralWidget *pEditorGeneralWidget; +// EditorFontWidget *pEditorFontWidget; +// EditorClipboardWidget *pEditorClipboardWidget; +// EditorColorSchemeWidget *pEditorColorSchemeWidget; +// EnvironmentAppearenceWidget *pEnvironmentAppearenceWidget; +// EditorSymbolCompletionWidget *pEditorSymbolCompletionWidget; +// EditorCodeCompletionWidget *pEditorCodeCompletionWidget; +// EditorSyntaxCheckWidget *pEditorSyntaxCheckWidget; +// EditorAutoSaveWidget *pEditorAutoSaveWidget; +// EditorMiscWidget *pEditorMiscWidget; +// ExecutorGeneralWidget *pExecutorGeneralWidget; +// DebugGeneralWidget *pDebugGeneralWidget; +// FormatterGeneralWidget *pFormatterGeneralWidget; }; #endif // SETTINGSDIALOG_H diff --git a/RedPandaIDE/systemconsts.h b/RedPandaIDE/systemconsts.h index 300ed981..3e53535a 100644 --- a/RedPandaIDE/systemconsts.h +++ b/RedPandaIDE/systemconsts.h @@ -30,6 +30,7 @@ #ifdef Q_OS_WIN # define PATH_SENSITIVITY Qt::CaseInsensitive +# define PATH_SEPARATOR ";" # define NULL_FILE "NUL" # define EXECUTABLE_EXT "exe" # define STATIC_LIB_EXT "a" @@ -37,6 +38,7 @@ # define MAKEFILE_NAME "makefile.win" #elif Q_OS_LINUX # define PATH_SENSITIVITY Qt::CaseSensitive +# define PATH_SEPARATOR ":" # define NULL_FILE "/dev/null" # define EXECUTABLE_EXT "" # define STATIC_LIB_EXT "a"