diff --git a/NEWS.md b/NEWS.md index 898c3c77..65caeec6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ Version 0.7.7 - 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). 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/compiler/ojproblemcasesrunner.cpp b/RedPandaIDE/compiler/ojproblemcasesrunner.cpp index a3dfedc2..e1def83b 100644 --- a/RedPandaIDE/compiler/ojproblemcasesrunner.cpp +++ b/RedPandaIDE/compiler/ojproblemcasesrunner.cpp @@ -21,9 +21,9 @@ OJProblemCasesRunner::OJProblemCasesRunner(const QString& filename, const QStrin void OJProblemCasesRunner::runCase(int index,POJProblemCase problemCase) { - emit caseStarted(problemCase->getId(),mProblemCases.count(),index); + emit caseStarted(problemCase->getId(),index, mProblemCases.count()); auto action = finally([this,&index, &problemCase]{ - emit caseFinished(problemCase->getId(),mProblemCases.count(),index); + emit caseFinished(problemCase->getId(), index, mProblemCases.count()); }); QProcess process; bool errorOccurred = false; diff --git a/RedPandaIDE/compiler/ojproblemcasesrunner.h b/RedPandaIDE/compiler/ojproblemcasesrunner.h index aeecef07..3a727659 100644 --- a/RedPandaIDE/compiler/ojproblemcasesrunner.h +++ b/RedPandaIDE/compiler/ojproblemcasesrunner.h @@ -14,8 +14,8 @@ public: explicit OJProblemCasesRunner(const QString& filename, const QString& arguments, const QString& workDir, POJProblemCase problemCase, QObject *parent = nullptr); signals: - void caseStarted(const QString& id, int total, int current); - void caseFinished(const QString& id, int total, int current); + void caseStarted(const QString& id, int current, int total); + void caseFinished(const QString& id, int current, int total); private: void runCase(int index, POJProblemCase problemCase); private: diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 2e5fcc70..cd619af7 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -222,29 +222,27 @@ bool Editor::save(bool force, bool doReparse) { if (this->mIsNew && !force) { return saveAs(); } - QFileInfo info(mFilename); //is this file writable; - if (!force && !info.isWritable()) { - QMessageBox::critical(pMainWindow,tr("Error"), - tr("File %1 is not writable!").arg(mFilename)); - return false; - } - if (this->modified()|| force) { - pMainWindow->fileSystemWatcher()->removePath(mFilename); - try { - saveFile(mFilename); - pMainWindow->fileSystemWatcher()->addPath(mFilename); - setModified(false); - mIsNew = false; - this->updateCaption(); - } catch (SaveException& exception) { - if (!force) { - QMessageBox::critical(pMainWindow,tr("Error"), - exception.reason()); - } - pMainWindow->fileSystemWatcher()->addPath(mFilename); - return false; + pMainWindow->fileSystemWatcher()->removePath(mFilename); + try { +// QFileInfo info(mFilename); +// if (!force && !info.isWritable()) { +// QMessageBox::critical(pMainWindow,tr("Error"), +// tr("File %1 is not writable!").arg(mFilename)); +// return false; +// } + saveFile(mFilename); + pMainWindow->fileSystemWatcher()->addPath(mFilename); + setModified(false); + mIsNew = false; + this->updateCaption(); + } catch (SaveException& exception) { + if (!force) { + QMessageBox::critical(pMainWindow,tr("Error"), + exception.reason()); } + pMainWindow->fileSystemWatcher()->addPath(mFilename); + return false; } if (doReparse && mParser) { diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 4c6e4d40..93b7f368 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -205,6 +205,9 @@ MainWindow::MainWindow(QWidget *parent) connect(mSearchResultTreeModel.get() , &QAbstractItemModel::modelReset, ui->searchView,&QTreeView::expandAll); ui->replacePanel->setVisible(false); + ui->tabProblem->setEnabled(false); + ui->btnRemoveProblem->setEnabled(false); + ui->btnRemoveProblemCase->setEnabled(false); mOJProblemSetNameCounter=1; mOJProblemSetModel.rename(tr("Problem Set %1").arg(mOJProblemSetNameCounter)); @@ -216,6 +219,9 @@ MainWindow::MainWindow(QWidget *parent) connect(ui->lstProblemCases->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &MainWindow::onProblemCaseIndexChanged); + connect(&mOJProblemSetModel, &OJProblemSetModel::problemNameChanged, + this , &MainWindow::onProblemNameChanged); + ui->pbProblemCases->setVisible(false); //files view ui->treeFiles->setModel(&mFileSystemModel); @@ -1135,6 +1141,8 @@ void MainWindow::runExecutable(const QString &exeName,const QString &filename,Ru if (problem) { mCompilerManager->runProblem(exeName,params,QFileInfo(exeName).absolutePath(), problem->cases); + openCloseBottomPanel(true); + ui->tabMessages->setCurrentWidget(ui->tabProblem); } } else if (runType == RunType::CurrentProblemCase) { QModelIndex index = ui->lstProblemCases->currentIndex(); @@ -1142,6 +1150,8 @@ void MainWindow::runExecutable(const QString &exeName,const QString &filename,Ru POJProblemCase problemCase =mOJProblemModel.getCase(index.row()); mCompilerManager->runProblem(exeName,params,QFileInfo(exeName).absolutePath(), problemCase); + openCloseBottomPanel(true); + ui->tabMessages->setCurrentWidget(ui->tabProblem); } } updateAppTitle(); @@ -2518,24 +2528,22 @@ void MainWindow::onFilesViewContextMenu(const QPoint &pos) void MainWindow::onProblemSetIndexChanged(const QModelIndex ¤t, const QModelIndex &previous) { QModelIndex idx = current; -// if (previous.isValid()) { -// QModelIndex caseIdx = ui->lstProblemCases->currentIndex(); -// if (caseIdx.isValid()) { -// POJProblemCase problemCase = mOJProblemModel.getCase(caseIdx.row()); -// problemCase->input = ui->txtProblemCaseInput->toPlainText(); -// problemCase->expected = ui->txtProblemCaseExpected->toPlainText(); -// problemCase->output = ui->txtProblemCaseOutput->toPlainText(); -// } -// } if (!idx.isValid()) { ui->btnRemoveProblem->setEnabled(false); + mOJProblemModel.setProblem(nullptr); + ui->txtProblemCaseExpected->clear(); + ui->txtProblemCaseInput->clear(); + ui->txtProblemCaseOutput->clear(); + ui->tabProblem->setEnabled(false); } else { ui->btnRemoveProblem->setEnabled(true); POJProblem problem = mOJProblemSetModel.problem(idx.row()); mOJProblemModel.setProblem(problem); ui->lblProblem->setText(problem->name); + ui->lstProblemCases->setCurrentIndex(mOJProblemModel.index(0,0)); openCloseBottomPanel(true); ui->tabMessages->setCurrentWidget(ui->tabProblem); + ui->tabProblem->setEnabled(true); } } @@ -2569,6 +2577,15 @@ void MainWindow::onProblemCaseIndexChanged(const QModelIndex ¤t, const QMo ui->txtProblemCaseOutput->setReadOnly(true); } +void MainWindow::onProblemNameChanged(int index) +{ + QModelIndex idx = ui->lstProblemSet->currentIndex(); + if (idx.isValid() && index == idx.row()) { + POJProblem problem = mOJProblemSetModel.problem(idx.row()); + ui->lblProblem->setText(problem->name); + } +} + void MainWindow::onShowInsertCodeSnippetMenu() { mMenuInsertCodeSnippet->clear(); @@ -2894,6 +2911,7 @@ void MainWindow::onFileChanged(const QString &path) e->setModified(true); e->updateCaption(); } + mFileSystemWatcher.removePath(e->filename()); } } } @@ -3332,12 +3350,14 @@ void MainWindow::onRunFinished() void MainWindow::onRunProblemFinished() { + ui->pbProblemCases->setVisible(false); updateCompileActions(); updateAppTitle(); } void MainWindow::onOJProblemCaseStarted(const QString& id,int current, int total) { + ui->pbProblemCases->setVisible(true); ui->pbProblemCases->setMaximum(total); ui->pbProblemCases->setValue(current); int row = mOJProblemModel.getCaseIndexById(id); @@ -5021,6 +5041,7 @@ void MainWindow::on_btnLoadProblemSet_clicked() } } ui->lblProblemSet->setText(mOJProblemSetModel.name()); + ui->lstProblemSet->setCurrentIndex(mOJProblemSetModel.index(0,0)); } diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index c3595f33..1011a66b 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -226,6 +226,7 @@ private slots: void onFilesViewContextMenu(const QPoint& pos); void onProblemSetIndexChanged(const QModelIndex ¤t, const QModelIndex &previous); void onProblemCaseIndexChanged(const QModelIndex ¤t, const QModelIndex &previous); + void onProblemNameChanged(int index); void onShowInsertCodeSnippetMenu(); diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 76a0d85d..7081fa95 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -1234,8 +1234,17 @@ + + + 0 + 0 + + + + 0 + - 24 + 0 %v/%m diff --git a/RedPandaIDE/widgets/ojproblemsetmodel.cpp b/RedPandaIDE/widgets/ojproblemsetmodel.cpp index 5ed5de80..b7d9a3ec 100644 --- a/RedPandaIDE/widgets/ojproblemsetmodel.cpp +++ b/RedPandaIDE/widgets/ojproblemsetmodel.cpp @@ -57,7 +57,9 @@ POJProblem OJProblemSetModel::problem(int index) void OJProblemSetModel::removeProblem(int index) { Q_ASSERT(index>=0 && index < mProblemSet.problems.count()); + beginRemoveRows(QModelIndex(),index,index); mProblemSet.problems.removeAt(index); + endRemoveRows(); } bool OJProblemSetModel::problemNameUsed(const QString &name) @@ -169,6 +171,7 @@ bool OJProblemSetModel::setData(const QModelIndex &index, const QVariant &value, QString s = value.toString(); if (!s.isEmpty()) { mProblemSet.problems[index.row()]->name = s; + emit problemNameChanged(index.row()); return true; } } diff --git a/RedPandaIDE/widgets/ojproblemsetmodel.h b/RedPandaIDE/widgets/ojproblemsetmodel.h index 8d4f04c9..d1edf0c7 100644 --- a/RedPandaIDE/widgets/ojproblemsetmodel.h +++ b/RedPandaIDE/widgets/ojproblemsetmodel.h @@ -48,6 +48,9 @@ public: void removeAllProblems(); void saveToFile(const QString& fileName); void loadFromFile(const QString& fileName); +signals: + void problemNameChanged(int index); + private: OJProblemSet mProblemSet;