- enhancement: set problem's answer source file

- enhancement: open the problem's answer source file in editor
This commit is contained in:
royqh1979 2021-11-06 14:49:11 +08:00
parent 7e8f73debd
commit bd26ad967d
8 changed files with 105 additions and 12 deletions

View File

@ -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 - 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, activate RedPanda C++ if it's minimized.
- enhancement: when problem from competitive companion received, show the problem and problem set views. - 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 Version 0.8 For Dev-C++ 7 Beta
- fix: find in the current file is not correcly saved in the search history - fix: find in the current file is not correcly saved in the search history

View File

@ -1,4 +1,4 @@
QT += core gui printsupport network QT += core gui printsupport network svg
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
@ -318,10 +318,3 @@ RESOURCES += \
translations.qrc 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 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

View File

@ -290,10 +290,11 @@ bool Editor::saveAs(const QString &name, bool fromProject){
} }
}); });
if (!dialog.exec()) { if (dialog.exec()!=QFileDialog::Accepted) {
return false; return false;
} }
newName = dialog.selectedFiles()[0]; newName = dialog.selectedFiles()[0];
QDir::setCurrent(extractFileDir(newName));
} }
// Update project information // Update project information

View File

@ -2619,9 +2619,68 @@ void MainWindow::onFilesViewContextMenu(const QPoint &pos)
void MainWindow::onLstProblemSetContextMenu(const QPoint &pos) void MainWindow::onLstProblemSetContextMenu(const QPoint &pos)
{ {
QMenu menu(this); QMenu menu(this);
menu.addAction(mProblem_Properties); QModelIndex idx = ui->lstProblemSet->currentIndex();
QModelIndex idx =ui->lstProblemCases->currentIndex();
mProblem_Properties->setEnabled(idx.isValid()); 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;i<mEditorList->pageCount();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)); menu.exec(ui->lstProblemSet->mapToGlobal(pos));
} }
@ -2637,6 +2696,7 @@ void MainWindow::onProblemSetIndexChanged(const QModelIndex &current, const QMod
ui->tabProblem->setEnabled(false); ui->tabProblem->setEnabled(false);
ui->lblProblem->clear(); ui->lblProblem->clear();
ui->lblProblem->setToolTip(""); ui->lblProblem->setToolTip("");
ui->tabProblem->setEnabled(false);
} else { } else {
ui->btnRemoveProblem->setEnabled(true); ui->btnRemoveProblem->setEnabled(true);
POJProblem problem = mOJProblemSetModel.problem(idx.row()); POJProblem problem = mOJProblemSetModel.problem(idx.row());
@ -2647,6 +2707,7 @@ void MainWindow::onProblemSetIndexChanged(const QModelIndex &current, const QMod
openCloseBottomPanel(true); openCloseBottomPanel(true);
ui->tabMessages->setCurrentWidget(ui->tabProblem); ui->tabMessages->setCurrentWidget(ui->tabProblem);
ui->tabProblem->setEnabled(true); ui->tabProblem->setEnabled(true);
ui->btnOpenProblemAnswer->setEnabled(!problem->answerProgram.isEmpty());
} }
} }
@ -3157,6 +3218,9 @@ void MainWindow::on_actionOpen_triggered()
QStringList files = QFileDialog::getOpenFileNames(pMainWindow, QStringList files = QFileDialog::getOpenFileNames(pMainWindow,
tr("Open"), QString(), pSystemConsts->defaultFileFilters().join(";;"), tr("Open"), QString(), pSystemConsts->defaultFileFilters().join(";;"),
&selectedFileFilter); &selectedFileFilter);
if (!files.isEmpty()) {
QDir::setCurrent(extractFileDir(files[0]));
}
openFiles(files); openFiles(files);
} catch (FileError e) { } catch (FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason()); QMessageBox::critical(this,tr("Error"),e.reason());
@ -5240,6 +5304,7 @@ void MainWindow::on_btnSaveProblemSet_clicked()
QDir().absolutePath(), QDir().absolutePath(),
tr("Problem Set Files (*.pbs)")); tr("Problem Set Files (*.pbs)"));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
QDir::setCurrent(extractFileDir(fileName));
try { try {
applyCurrentProblemCaseChanges(); applyCurrentProblemCaseChanges();
mOJProblemSetModel.saveToFile(fileName); mOJProblemSetModel.saveToFile(fileName);
@ -5256,9 +5321,10 @@ void MainWindow::on_btnLoadProblemSet_clicked()
QString fileName = QFileDialog::getOpenFileName( QString fileName = QFileDialog::getOpenFileName(
this, this,
tr("Load Problem Set"), tr("Load Problem Set"),
QDir().absolutePath(), QString(),
tr("Problem Set Files (*.pbs)")); tr("Problem Set Files (*.pbs)"));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
QDir::setCurrent(extractFileDir(fileName));
try { try {
mOJProblemSetModel.loadFromFile(fileName); mOJProblemSetModel.loadFromFile(fileName);
} catch (FileError& error) { } 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();
}
}

View File

@ -473,6 +473,8 @@ private slots:
void on_btnRemoveProblemCase_clicked(); void on_btnRemoveProblemCase_clicked();
void on_btnOpenProblemAnswer_clicked();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
EditorList *mEditorList; EditorList *mEditorList;

View File

@ -1223,6 +1223,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QToolButton" name="btnOpenProblemAnswer">
<property name="toolTip">
<string>Open Anwser Source File</string>
</property>
<property name="text">
<string>Open Anwser Source File</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/047-makefl.png</normaloff>:/icons/images/newlook24/047-makefl.png</iconset>
</property>
</widget>
</item>
<item> <item>
<widget class="Line" name="line"> <widget class="Line" name="line">
<property name="orientation"> <property name="orientation">

View File

@ -32,6 +32,7 @@ struct OJProblem {
QString name; QString name;
QString url; QString url;
QString description; QString description;
QString answerProgram;
QVector<POJProblemCase> cases; QVector<POJProblemCase> cases;
}; };

View File

@ -88,6 +88,7 @@ void OJProblemSetModel::saveToFile(const QString &fileName)
problemObj["name"]=problem->name; problemObj["name"]=problem->name;
problemObj["url"]=problem->url; problemObj["url"]=problem->url;
problemObj["description"]=problem->description; problemObj["description"]=problem->description;
problemObj["answer_program"] = problem->answerProgram;
QJsonArray cases; QJsonArray cases;
foreach (const POJProblemCase& problemCase, problem->cases) { foreach (const POJProblemCase& problemCase, problem->cases) {
QJsonObject caseObj; QJsonObject caseObj;
@ -133,6 +134,7 @@ void OJProblemSetModel::loadFromFile(const QString &fileName)
problem->name = problemObj["name"].toString(); problem->name = problemObj["name"].toString();
problem->url = problemObj["url"].toString(); problem->url = problemObj["url"].toString();
problem->description = problemObj["description"].toString(); problem->description = problemObj["description"].toString();
problem->answerProgram = problemObj["answer_program"].toString();
QJsonArray casesArray = problemObj["cases"].toArray(); QJsonArray casesArray = problemObj["cases"].toArray();
foreach (const QJsonValue& caseVal, casesArray) { foreach (const QJsonValue& caseVal, casesArray) {
QJsonObject caseObj = caseVal.toObject(); QJsonObject caseObj = caseVal.toObject();