diff --git a/NEWS.md b/NEWS.md index a1b8c30d..37e85c9b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ Red Panda C++ Version 1.0.4 - fix: hide function tips, when move or resize the main window - enhancement: add help link for regular expression in search dialog + - enhancement: remember current problem set's filename Red Panda C++ Version 1.0.3 - fix: when oj problem grabbed by competitive companion received, diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index ba841516..8c82fd2e 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -6653,12 +6653,20 @@ void MainWindow::on_btnRemoveProblem_clicked() void MainWindow::on_btnSaveProblemSet_clicked() { - QString fileName = QFileDialog::getSaveFileName( - this, - tr("Save Problem Set"), - QDir().absolutePath(), - tr("Problem Set Files (*.pbs)")); - if (!fileName.isEmpty()) { + QFileDialog dialog(this); + dialog.setWindowTitle(tr("Save Problem Set")); + if (!mOJProblemSetModel.exportFilename().isEmpty()) { + dialog.setDirectory(mOJProblemSetModel.exportFilename()); + dialog.selectFile(mOJProblemSetModel.exportFilename()); + } else { + dialog.setDirectory(QDir().absolutePath()); + } + dialog.setNameFilter(tr("Problem Set Files (*.pbs)")); + dialog.setDefaultSuffix("pbs"); + dialog.setFileMode(QFileDialog::AnyFile); + dialog.setAcceptMode(QFileDialog::AcceptSave); + if (dialog.exec() == QDialog::Accepted) { + QString fileName=dialog.selectedFiles()[0]; QFileInfo fileInfo(fileName); if (fileInfo.suffix().isEmpty()) { fileName.append(".pbs"); diff --git a/RedPandaIDE/problems/ojproblemset.h b/RedPandaIDE/problems/ojproblemset.h index 90389e65..9bece8ee 100644 --- a/RedPandaIDE/problems/ojproblemset.h +++ b/RedPandaIDE/problems/ojproblemset.h @@ -63,6 +63,7 @@ using POJProblem = std::shared_ptr; struct OJProblemSet { QString name; QVector problems; + QString exportFilename; }; using POJProblemSet = std::shared_ptr; diff --git a/RedPandaIDE/widgets/ojproblemsetmodel.cpp b/RedPandaIDE/widgets/ojproblemsetmodel.cpp index 2aab4439..c44ca7f9 100644 --- a/RedPandaIDE/widgets/ojproblemsetmodel.cpp +++ b/RedPandaIDE/widgets/ojproblemsetmodel.cpp @@ -34,6 +34,7 @@ void OJProblemSetModel::clear() { beginResetModel(); mProblemSet.problems.clear(); + mProblemSet.exportFilename.clear(); endResetModel(); } @@ -54,11 +55,16 @@ void OJProblemSetModel::rename(const QString &newName) mProblemSet.name = newName; } -QString OJProblemSetModel::name() +QString OJProblemSetModel::name() const { return mProblemSet.name; } +QString OJProblemSetModel::exportFilename() const +{ + return mProblemSet.exportFilename; +} + void OJProblemSetModel::addProblem(POJProblem problem) { beginInsertRows(QModelIndex(), mProblemSet.problems.count(), mProblemSet.problems.count()); @@ -98,6 +104,7 @@ void OJProblemSetModel::saveToFile(const QString &fileName) QFile file(fileName); if (file.open(QFile::WriteOnly | QFile::Truncate)) { QJsonObject obj; + mProblemSet.exportFilename=fileName; obj["name"]=mProblemSet.name; QJsonArray problemsArray; foreach (const POJProblem& problem, mProblemSet.problems) { diff --git a/RedPandaIDE/widgets/ojproblemsetmodel.h b/RedPandaIDE/widgets/ojproblemsetmodel.h index 25ae598f..ea7e1d8d 100644 --- a/RedPandaIDE/widgets/ojproblemsetmodel.h +++ b/RedPandaIDE/widgets/ojproblemsetmodel.h @@ -63,7 +63,8 @@ public: int count(); void create(const QString& name); void rename(const QString& newName); - QString name(); + QString name() const; + QString exportFilename() const; void addProblem(POJProblem problem); POJProblem problem(int index); void removeProblem(int index);