diff --git a/NEWS.md b/NEWS.md index 8398ff76..0d0a05d5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,8 @@ Version 0.8.1 For Dev-C++ 7 Beta - fix: Red Panda C++ will freeze when receiving contents from Competitve Companion in chrome/edge - enhancement: when problem from competitive companion received, activate RedPanda C++ if it's minimized. - enhancement: when problem from competitive companion received, show the problem and problem set views. + - enhancement: set problem's answer source file + - enhancement: open the problem's answer source file in editor Version 0.8 For Dev-C++ 7 Beta - fix: find in the current file is not correcly saved in the search history diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 4cb25b6f..6008b824 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -1,4 +1,4 @@ -QT += core gui printsupport network +QT += core gui printsupport network svg greaterThan(QT_MAJOR_VERSION, 4): QT += widgets @@ -318,10 +318,3 @@ RESOURCES += \ translations.qrc RC_ICONS = images/devcpp.ico images/associations/c.ico images/associations/cpp.ico images/associations/h.ico images/associations/hpp.ico images/associations/dev.ico - -#win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../QScintilla/src/release/ -lqscintilla2_qt5d -#else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../QScintilla/src/debug/ -lqscintilla2_qt5d -#else:unix: LIBS += -L$$OUT_PWD/../../QScintilla/src/ -lqscintilla2_qt5d - -#INCLUDEPATH += $$PWD/../../QScintilla/src -#DEPENDPATH += $$PWD/../../QScintilla/src diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index bf2104db..e68fd535 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -290,10 +290,11 @@ bool Editor::saveAs(const QString &name, bool fromProject){ } }); - if (!dialog.exec()) { + if (dialog.exec()!=QFileDialog::Accepted) { return false; } newName = dialog.selectedFiles()[0]; + QDir::setCurrent(extractFileDir(newName)); } // Update project information diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 4fa2d309..81f0e4a4 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -2619,9 +2619,68 @@ void MainWindow::onFilesViewContextMenu(const QPoint &pos) void MainWindow::onLstProblemSetContextMenu(const QPoint &pos) { QMenu menu(this); - menu.addAction(mProblem_Properties); - QModelIndex idx =ui->lstProblemCases->currentIndex(); + QModelIndex idx = ui->lstProblemSet->currentIndex(); mProblem_Properties->setEnabled(idx.isValid()); + if (idx.isValid()) { + POJProblem problem = mOJProblemSetModel.problem(idx.row()); + QMenu * menuSetAnswer = new QMenu(&menu); + QActionGroup *actionGroup = new QActionGroup(menuSetAnswer); + bool answerFound=false; + menuSetAnswer->setTitle(tr("Set answer to...")); + for (int i=0;ipageCount();i++) { + Editor *e = (*mEditorList)[i]; + if (e->isNew()) + continue; + QString filename = e->filename(); + QAction* action = new QAction(filename,menuSetAnswer); + action->setCheckable(true); + action->setActionGroup(actionGroup); + + if (filename.compare(problem->answerProgram, PATH_SENSITIVITY)==0) { + action->setChecked(true); + answerFound = true; + } + menuSetAnswer->addAction(action); + } + if (!answerFound && !problem->answerProgram.isEmpty()) { + QAction* action = new QAction(problem->answerProgram,menuSetAnswer); + action->setCheckable(true); + action->setChecked(true); + action->setActionGroup(actionGroup); + menuSetAnswer->addAction(action); + } + connect(actionGroup, &QActionGroup::triggered, + [problem,this](QAction* action) { + if (action->text().compare(problem->answerProgram, PATH_SENSITIVITY) + !=0) + problem->answerProgram = action->text(); + else + problem->answerProgram = ""; + if (problem == mOJProblemModel.problem()) { + ui->btnOpenProblemAnswer->setEnabled(!problem->answerProgram.isEmpty()); + } + }); + QAction * action = new QAction(tr("select other file..."),menuSetAnswer); + connect(action, &QAction::triggered, + [problem,this](){ + QString filename = QFileDialog::getOpenFileName( + this, + tr("Select Answer Source File"), + QString(), + tr("C/C++Source Files (*.c *.cpp *.cc *.cxx") + ); + if (!filename.isEmpty()) { + QDir::setCurrent(extractFileDir(filename)); + problem->answerProgram = filename; + if (problem == mOJProblemModel.problem()) { + ui->btnOpenProblemAnswer->setEnabled(!problem->answerProgram.isEmpty()); + } + } + }); + menuSetAnswer->addAction(action); + menu.addMenu(menuSetAnswer); + } + menu.addAction(mProblem_Properties); menu.exec(ui->lstProblemSet->mapToGlobal(pos)); } @@ -2637,6 +2696,7 @@ void MainWindow::onProblemSetIndexChanged(const QModelIndex ¤t, const QMod ui->tabProblem->setEnabled(false); ui->lblProblem->clear(); ui->lblProblem->setToolTip(""); + ui->tabProblem->setEnabled(false); } else { ui->btnRemoveProblem->setEnabled(true); POJProblem problem = mOJProblemSetModel.problem(idx.row()); @@ -2647,6 +2707,7 @@ void MainWindow::onProblemSetIndexChanged(const QModelIndex ¤t, const QMod openCloseBottomPanel(true); ui->tabMessages->setCurrentWidget(ui->tabProblem); ui->tabProblem->setEnabled(true); + ui->btnOpenProblemAnswer->setEnabled(!problem->answerProgram.isEmpty()); } } @@ -3157,6 +3218,9 @@ void MainWindow::on_actionOpen_triggered() QStringList files = QFileDialog::getOpenFileNames(pMainWindow, tr("Open"), QString(), pSystemConsts->defaultFileFilters().join(";;"), &selectedFileFilter); + if (!files.isEmpty()) { + QDir::setCurrent(extractFileDir(files[0])); + } openFiles(files); } catch (FileError e) { QMessageBox::critical(this,tr("Error"),e.reason()); @@ -5240,6 +5304,7 @@ void MainWindow::on_btnSaveProblemSet_clicked() QDir().absolutePath(), tr("Problem Set Files (*.pbs)")); if (!fileName.isEmpty()) { + QDir::setCurrent(extractFileDir(fileName)); try { applyCurrentProblemCaseChanges(); mOJProblemSetModel.saveToFile(fileName); @@ -5256,9 +5321,10 @@ void MainWindow::on_btnLoadProblemSet_clicked() QString fileName = QFileDialog::getOpenFileName( this, tr("Load Problem Set"), - QDir().absolutePath(), + QString(), tr("Problem Set Files (*.pbs)")); if (!fileName.isEmpty()) { + QDir::setCurrent(extractFileDir(fileName)); try { mOJProblemSetModel.loadFromFile(fileName); } catch (FileError& error) { @@ -5312,3 +5378,15 @@ void MainWindow::on_btnRemoveProblemCase_clicked() } } + +void MainWindow::on_btnOpenProblemAnswer_clicked() +{ + POJProblem problem = mOJProblemModel.problem(); + if (!problem || problem->answerProgram.isEmpty()) + return; + Editor *e = mEditorList->getEditorByFilename(problem->answerProgram); + if (e) { + e->activate(); + } +} + diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index b896f0e2..db3b793a 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -473,6 +473,8 @@ private slots: void on_btnRemoveProblemCase_clicked(); + void on_btnOpenProblemAnswer_clicked(); + private: Ui::MainWindow *ui; EditorList *mEditorList; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index fa230aa6..51ffba99 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -1223,6 +1223,20 @@ + + + + Open Anwser Source File + + + Open Anwser Source File + + + + :/icons/images/newlook24/047-makefl.png:/icons/images/newlook24/047-makefl.png + + + diff --git a/RedPandaIDE/problems/ojproblemset.h b/RedPandaIDE/problems/ojproblemset.h index 9eb07bf2..9f7181aa 100644 --- a/RedPandaIDE/problems/ojproblemset.h +++ b/RedPandaIDE/problems/ojproblemset.h @@ -32,6 +32,7 @@ struct OJProblem { QString name; QString url; QString description; + QString answerProgram; QVector cases; }; diff --git a/RedPandaIDE/widgets/ojproblemsetmodel.cpp b/RedPandaIDE/widgets/ojproblemsetmodel.cpp index 2917f431..8aeb999b 100644 --- a/RedPandaIDE/widgets/ojproblemsetmodel.cpp +++ b/RedPandaIDE/widgets/ojproblemsetmodel.cpp @@ -88,6 +88,7 @@ void OJProblemSetModel::saveToFile(const QString &fileName) problemObj["name"]=problem->name; problemObj["url"]=problem->url; problemObj["description"]=problem->description; + problemObj["answer_program"] = problem->answerProgram; QJsonArray cases; foreach (const POJProblemCase& problemCase, problem->cases) { QJsonObject caseObj; @@ -133,6 +134,7 @@ void OJProblemSetModel::loadFromFile(const QString &fileName) problem->name = problemObj["name"].toString(); problem->url = problemObj["url"].toString(); problem->description = problemObj["description"].toString(); + problem->answerProgram = problemObj["answer_program"].toString(); QJsonArray casesArray = problemObj["cases"].toArray(); foreach (const QJsonValue& caseVal, casesArray) { QJsonObject caseObj = caseVal.toObject();