diff --git a/NEWS.md b/NEWS.md index cc186b5d..fbe63aa2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,11 +1,13 @@ Version 0.7.7 + - enhancement: Problem Set + - enhancement: Competitive Companion Support - change: "save" action will be enabled no matter contents in the current editor is modified or not - fix: focus not correctly set when the current editor is closed - fix: can't parse old c-style enum variable definition like "enum Test test;" - fix: remove the file change monitor if it's remove from the disk - fix: don't test if a file is writable before save to it (because qt can't do that test reliably). - - enhancement: Problem Set - - enhancement: Competitive Companion Support + - fix: when search in project, files opened for search shouldn't be parsed for symbols. + - fix: when search in project, the search history is not correctly updated. Version 0.7.6 - change: don't auto insert a new line when input an enter between '(' and ')' or between '[' and ']' (indent instead) diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index a2c900e0..fe5e1f84 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -54,6 +54,7 @@ SOURCES += \ settingsdialog/environmentfileassociationwidget.cpp \ settingsdialog/environmentfolderswidget.cpp \ settingsdialog/environmentshortcutwidget.cpp \ + settingsdialog/executorproblemsetwidget.cpp \ settingsdialog/formattergeneralwidget.cpp \ settingsdialog/projectcompileparamaterswidget.cpp \ settingsdialog/projectcompilerwidget.cpp \ @@ -173,6 +174,7 @@ HEADERS += \ settingsdialog/environmentfileassociationwidget.h \ settingsdialog/environmentfolderswidget.h \ settingsdialog/environmentshortcutwidget.h \ + settingsdialog/executorproblemsetwidget.h \ settingsdialog/formattergeneralwidget.h \ settingsdialog/projectcompileparamaterswidget.h \ settingsdialog/projectcompilerwidget.h \ @@ -262,6 +264,7 @@ FORMS += \ settingsdialog/environmentfileassociationwidget.ui \ settingsdialog/environmentfolderswidget.ui \ settingsdialog/environmentshortcutwidget.ui \ + settingsdialog/executorproblemsetwidget.ui \ settingsdialog/formattergeneralwidget.ui \ settingsdialog/projectcompileparamaterswidget.ui \ settingsdialog/projectcompilerwidget.ui \ diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index c8fec49a..84b7abac 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -536,10 +536,32 @@ void MainWindow::applySettings() qApp->setFont(font); this->setFont(font); - if (!mTcpServer.listen(QHostAddress::LocalHost,10045)) { - QMessageBox::critical(nullptr, - tr("Listen failed"), - tr("Can't listen to port %1").arg(10045)); + mTcpServer.close(); + int idxProblem = ui->tabMessages->indexOf(ui->tabProblem); + ui->tabMessages->setTabEnabled(idxProblem,pSettings->executor().enableProblemSet()); + int idxProblemSet = ui->tabInfos->indexOf(ui->tabProblemSet); + ui->tabInfos->setTabEnabled(idxProblemSet,pSettings->executor().enableProblemSet()); + if (pSettings->executor().enableProblemSet()) { + if (pSettings->executor().enableCompetitiveCompanion()) { + if (!mTcpServer.listen(QHostAddress::LocalHost,pSettings->executor().competivieCompanionPort())) { + QMessageBox::critical(nullptr, + tr("Listen failed"), + tr("Can't listen to port %1 form Competitve Companion.").arg(10045) + + "
" + +tr("You can turn off competitive companion support in the Problem Set options.") + + "
" + +tr("Or You can choose a different port number and try again.")); + } + } + if (idxProblem<0) + ui->tabMessages->addTab(ui->tabProblem,tr("Problem")); + if (idxProblemSet<0) + ui->tabInfos->addTab(ui->tabProblemSet, tr("Problem Set")); + } else { + if (idxProblem>=0) + ui->tabMessages->removeTab(idxProblem); + if (idxProblemSet>=0) + ui->tabInfos->removeTab(idxProblemSet); } updateDebuggerSettings(); } @@ -3118,7 +3140,7 @@ void MainWindow::closeEvent(QCloseEvent *event) { } } - + mTcpServer.close(); mCompilerManager->stopCompile(); mCompilerManager->stopRun(); if (!mShouldRemoveAllSettings) diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 94eecb5e..ac9d1bbf 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -2757,6 +2757,36 @@ void Settings::Executor::setInputFilename(const QString &newInputFilename) mInputFilename = newInputFilename; } +int Settings::Executor::competivieCompanionPort() const +{ + return mCompetivieCompanionPort; +} + +void Settings::Executor::setCompetivieCompanionPort(int newCompetivieCompanionPort) +{ + mCompetivieCompanionPort = newCompetivieCompanionPort; +} + +bool Settings::Executor::enableCompetitiveCompanion() const +{ + return mEnableCompetitiveCompanion; +} + +void Settings::Executor::setEnableCompetitiveCompanion(bool newEnableCompetitiveCompanion) +{ + mEnableCompetitiveCompanion = newEnableCompetitiveCompanion; +} + +bool Settings::Executor::enableProblemSet() const +{ + return mEnableProblemSet; +} + +void Settings::Executor::setEnableProblemSet(bool newEnableProblemSet) +{ + mEnableProblemSet = newEnableProblemSet; +} + void Settings::Executor::doSave() { saveValue("pause_console", mPauseConsole); @@ -2765,6 +2795,8 @@ void Settings::Executor::doSave() saveValue("params",mParams); saveValue("redirect_input",mRedirectInput); saveValue("input_filename",mInputFilename); + //problem set + } bool Settings::Executor::pauseConsole() const @@ -2786,6 +2818,9 @@ void Settings::Executor::doLoad() mRedirectInput = boolValue("redirect_input",false); mInputFilename = stringValue("input_filename",""); + mEnableProblemSet = boolValue("enable_proble_set",true); + mEnableCompetitiveCompanion = boolValue("enable_competivie_companion",true); + mCompetivieCompanionPort = intValue("competitive_companion_port",10045); } diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index 1ee758b2..e65c90e8 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -763,6 +763,15 @@ public: const QString &inputFilename() const; void setInputFilename(const QString &newInputFilename); + bool enableProblemSet() const; + void setEnableProblemSet(bool newEnableProblemSet); + + bool enableCompetitiveCompanion() const; + void setEnableCompetitiveCompanion(bool newEnableCompetitiveCompanion); + + int competivieCompanionPort() const; + void setCompetivieCompanionPort(int newCompetivieCompanionPort); + private: // general bool mPauseConsole; @@ -772,6 +781,11 @@ public: bool mRedirectInput; QString mInputFilename; + //Problem Set + bool mEnableProblemSet; + bool mEnableCompetitiveCompanion; + int mCompetivieCompanionPort; + protected: void doSave() override; void doLoad() override; diff --git a/RedPandaIDE/settingsdialog/executorproblemsetwidget.cpp b/RedPandaIDE/settingsdialog/executorproblemsetwidget.cpp new file mode 100644 index 00000000..b07438fb --- /dev/null +++ b/RedPandaIDE/settingsdialog/executorproblemsetwidget.cpp @@ -0,0 +1,32 @@ +#include "executorproblemsetwidget.h" +#include "ui_executorproblemsetwidget.h" +#include "../settings.h" +#include "../mainwindow.h" + +ExecutorProblemSetWidget::ExecutorProblemSetWidget(const QString& name, const QString& group, QWidget *parent): + SettingsWidget(name,group,parent), + ui(new Ui::ExecutorProblemSetWidget) +{ + ui->setupUi(this); +} + +ExecutorProblemSetWidget::~ExecutorProblemSetWidget() +{ + delete ui; +} + +void ExecutorProblemSetWidget::doLoad() +{ + ui->grpProblemSet->setChecked(pSettings->executor().enableProblemSet()); + ui->grpCompetitiveCompanion->setChecked(pSettings->executor().enableCompetitiveCompanion()); + ui->spinPortNumber->setValue(pSettings->executor().competivieCompanionPort()); +} + +void ExecutorProblemSetWidget::doSave() +{ + pSettings->executor().setEnableProblemSet(ui->grpProblemSet->isChecked()); + pSettings->executor().setEnableCompetitiveCompanion(ui->grpCompetitiveCompanion->isChecked()); + pSettings->executor().setCompetivieCompanionPort(ui->spinPortNumber->value()); + pSettings->executor().save(); + pMainWindow->applySettings(); +} diff --git a/RedPandaIDE/settingsdialog/executorproblemsetwidget.h b/RedPandaIDE/settingsdialog/executorproblemsetwidget.h new file mode 100644 index 00000000..cbae0196 --- /dev/null +++ b/RedPandaIDE/settingsdialog/executorproblemsetwidget.h @@ -0,0 +1,26 @@ +#ifndef EXECUTORPROBLEMSETWIDGET_H +#define EXECUTORPROBLEMSETWIDGET_H + +#include +#include "settingswidget.h" + +namespace Ui { +class ExecutorProblemSetWidget; +} + +class ExecutorProblemSetWidget : public SettingsWidget +{ + Q_OBJECT + +public: + explicit ExecutorProblemSetWidget(const QString& name, const QString& group, QWidget *parent = nullptr); + ~ExecutorProblemSetWidget(); + +private: + Ui::ExecutorProblemSetWidget *ui; +protected: + void doLoad() override; + void doSave() override; +}; + +#endif // EXECUTORPROBLEMSETWIDGET_H diff --git a/RedPandaIDE/settingsdialog/executorproblemsetwidget.ui b/RedPandaIDE/settingsdialog/executorproblemsetwidget.ui new file mode 100644 index 00000000..30ef1cf8 --- /dev/null +++ b/RedPandaIDE/settingsdialog/executorproblemsetwidget.ui @@ -0,0 +1,88 @@ + + + ExecutorProblemSetWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Enable Problem Set + + + true + + + + + + Listen for Competitive Companion + + + true + + + + + + 1025 + + + 65535 + + + + + + + Port Number + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + diff --git a/RedPandaIDE/settingsdialog/settingsdialog.cpp b/RedPandaIDE/settingsdialog/settingsdialog.cpp index fbfc64d5..4547eba3 100644 --- a/RedPandaIDE/settingsdialog/settingsdialog.cpp +++ b/RedPandaIDE/settingsdialog/settingsdialog.cpp @@ -19,6 +19,7 @@ #include "environmentfileassociationwidget.h" #include "environmentfolderswidget.h" #include "executorgeneralwidget.h" +#include "executorproblemsetwidget.h" #include "debuggeneralwidget.h" #include "formattergeneralwidget.h" #include "projectgeneralwidget.h" @@ -175,6 +176,10 @@ PSettingsDialog SettingsDialog::optionDialog() widget->init(); dialog->addWidget(widget); + widget = new ExecutorProblemSetWidget(tr("Problem Set"),tr("Program Runner")); + widget->init(); + dialog->addWidget(widget); + widget = new DebugGeneralWidget(tr("General"),tr("Debugger")); widget->init(); dialog->addWidget(widget); diff --git a/RedPandaIDE/widgets/searchdialog.cpp b/RedPandaIDE/widgets/searchdialog.cpp index fae38ccd..ad3a0568 100644 --- a/RedPandaIDE/widgets/searchdialog.cpp +++ b/RedPandaIDE/widgets/searchdialog.cpp @@ -262,8 +262,10 @@ void SearchDialog::on_btnExecute_clicked() Editor * e=pMainWindow->editorList()->operator[](i); if (e!=nullptr) { fileSearched++; - PSearchResultTreeItem parentItem = batchFindInEditor(e, - keyword); + PSearchResultTreeItem parentItem = batchFindInEditor( + e, + e->filename(), + keyword); int t = parentItem->results.size(); findCount+=t; if (t>0) { @@ -282,8 +284,10 @@ void SearchDialog::on_btnExecute_clicked() Editor * e= pMainWindow->editorList()->getEditor(); if (e!=nullptr) { fileSearched++; - PSearchResultTreeItem parentItem = batchFindInEditor(e, - keyword); + PSearchResultTreeItem parentItem = batchFindInEditor( + e, + e->filename(), + keyword); int t = parentItem->results.size(); findCount+=t; if (t>0) { @@ -303,8 +307,10 @@ void SearchDialog::on_btnExecute_clicked() QString curFilename = pMainWindow->project()->units()[i]->fileName(); if (e) { fileSearched++; - PSearchResultTreeItem parentItem = batchFindInEditor(e, - keyword); + PSearchResultTreeItem parentItem = batchFindInEditor( + e, + e->filename(), + keyword); int t = parentItem->results.size(); findCount+=t; if (t>0) { @@ -312,10 +318,14 @@ void SearchDialog::on_btnExecute_clicked() results->results.append(parentItem); } } else if (fileExists(curFilename)) { - Editor editor(nullptr,curFilename,ENCODING_AUTO_DETECT,false,false,nullptr); + SynEdit editor; + QByteArray realEncoding; + editor.lines()->loadFromFile(curFilename,ENCODING_AUTO_DETECT, realEncoding); fileSearched++; - PSearchResultTreeItem parentItem = batchFindInEditor(&editor, - keyword); + PSearchResultTreeItem parentItem = batchFindInEditor( + &editor, + curFilename, + keyword); int t = parentItem->results.size(); findCount+=t; if (t>0) { @@ -325,26 +335,14 @@ void SearchDialog::on_btnExecute_clicked() } } - // end else if rbProjectFiles.Checked then begin - // for I := 0 to MainForm.Project.Units.Count - 1 do begin - // e := MainForm.Project.Units[i].Editor; - // fCurFile := MainForm.Project.Units[i].FileName; - - // // file is already open, use memory - // if Assigned(e) then begin begin - // inc(fileSearched); - // t:=Execute(e->text, actiontype); - // Inc(findcount, t); - // if t>0 then - // inc(filehitted); - // end; + pMainWindow->searchResultModel()->notifySearchResultsUpdated(); } if (findCount>0) pMainWindow->showSearchPanel(actionType == SearchAction::ReplaceFiles); } } -int SearchDialog::execute(Editor *editor, const QString &sSearch, const QString &sReplace, SynSearchMathedProc matchCallback) +int SearchDialog::execute(SynEdit *editor, const QString &sSearch, const QString &sReplace, SynSearchMathedProc matchCallback) { if (editor==nullptr) return 0; @@ -369,7 +367,7 @@ int SearchDialog::execute(Editor *editor, const QString &sSearch, const QString mSearchEngine, matchCallback); } -std::shared_ptr SearchDialog::batchFindInEditor(Editor *e, const QString &keyword) +std::shared_ptr SearchDialog::batchFindInEditor(SynEdit *e, const QString& filename,const QString &keyword) { //backup BufferCoord caretBackup = e->caretXY(); @@ -379,13 +377,13 @@ std::shared_ptr SearchDialog::batchFindInEditor(Editor *e, int leftCharBackup = e->leftChar(); PSearchResultTreeItem parentItem = std::make_shared(); - parentItem->filename = e->filename(); + parentItem->filename = filename; parentItem->parent = nullptr; execute(e,keyword,"", - [e,&parentItem](const QString&, + [e,&parentItem, filename](const QString&, const QString&, int Line, int ch, int wordLen){ PSearchResultTreeItem item = std::make_shared(); - item->filename = e->filename(); + item->filename = filename; item->line = Line; item->start = ch; item->len = wordLen; diff --git a/RedPandaIDE/widgets/searchdialog.h b/RedPandaIDE/widgets/searchdialog.h index 3f68f9cb..efbc1af3 100644 --- a/RedPandaIDE/widgets/searchdialog.h +++ b/RedPandaIDE/widgets/searchdialog.h @@ -44,9 +44,9 @@ private slots: void on_btnExecute_clicked(); private: - int execute(Editor* editor, const QString& sSearch, + int execute(SynEdit* editor, const QString& sSearch, const QString& sReplace, SynSearchMathedProc matchCallback = nullptr); - std::shared_ptr batchFindInEditor(Editor* editor,const QString& keyword); + std::shared_ptr batchFindInEditor(SynEdit * editor,const QString& filename, const QString& keyword); private: Ui::SearchDialog *ui; QTabBar *mTabBar;