diff --git a/RedPandaIDE/debugger.h b/RedPandaIDE/debugger.h index 6e164834..34be6909 100644 --- a/RedPandaIDE/debugger.h +++ b/RedPandaIDE/debugger.h @@ -58,6 +58,13 @@ struct WatchVar { WatchVar * parent; //use raw point to prevent circular-reference }; +enum class BreakpointType { + Breakpoint, + Watchpoint, + ReadWatchpoint, + WriteWatchpoint +}; + struct Breakpoint { int number; // breakpoint number QString type; // type of the breakpoint diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index b65e6d6e..cf9d7827 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -276,6 +276,8 @@ bool Editor::save(bool force, bool doReparse) { bool Editor::saveAs(const QString &name, bool fromProject){ QString newName = name; + QString oldName = mFilename; + bool firstSave = isNew(); if (name.isEmpty()) { QString selectedFileFilter; QString defaultExt; @@ -376,6 +378,8 @@ bool Editor::saveAs(const QString &name, bool fromProject){ setReadOnly(false); updateCaption(); } + + emit renamed(oldName, newName , firstSave); return true; } diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index 86ec2c4f..de3997ed 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -221,7 +221,8 @@ public: const PCppParser &parser(); void tab() override; - +signals: + void renamed(const QString& oldName, const QString& newName, bool firstSave); private slots: void onStatusChanged(SynStatusChanges changes); void onGutterClicked(Qt::MouseButton button, int x, int y, int line); diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp index 7284bfda..9206d7a4 100644 --- a/RedPandaIDE/editorlist.cpp +++ b/RedPandaIDE/editorlist.cpp @@ -53,6 +53,7 @@ Editor* EditorList::newEditor(const QString& filename, const QByteArray& encodin pMainWindow->fileSystemWatcher()->addPath(filename); } Editor * e = new Editor(parentPageControl,filename,encoding,inProject,newFile,parentPageControl); + connect(e, &Editor::renamed, this, &EditorList::onEditorRenamed); updateLayout(); return e; } @@ -100,6 +101,11 @@ void EditorList::showLayout(LayoutShowType layout) } } +void EditorList::onEditorRenamed(const QString &oldFilename, const QString &newFilename, bool firstSave) +{ + emit editorRenamed(oldFilename, newFilename, firstSave); +} + QTabWidget *EditorList::rightPageWidget() const { return mRightPageWidget; diff --git a/RedPandaIDE/editorlist.h b/RedPandaIDE/editorlist.h index 0f26fbdc..7911fb1a 100644 --- a/RedPandaIDE/editorlist.h +++ b/RedPandaIDE/editorlist.h @@ -78,13 +78,14 @@ public: signals: void editorClosed(); + void editorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave); private: QTabWidget* getNewEditorPageControl() const; QTabWidget* getFocusedPageControl() const; void showLayout(LayoutShowType layout); - - +private slots: + void onEditorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave); private: LayoutShowType mLayout; QTabWidget *mLeftPageWidget; diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index f47e44f3..0633e75b 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -112,6 +112,8 @@ MainWindow::MainWindow(QWidget *parent) ui->EditorTabsRight, ui->splitterEditorPanel, ui->EditorPanel); + connect(mEditorList, &EditorList::editorRenamed, + this, &MainWindow::onEditorRenamed); connect(mEditorList, &EditorList::editorClosed, this, &MainWindow::onEditorClosed); mProject = nullptr; @@ -2963,8 +2965,6 @@ void MainWindow::onLstProblemSetContextMenu(const QPoint &pos) 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); @@ -3038,6 +3038,11 @@ void MainWindow::onProblemSetIndexChanged(const QModelIndex ¤t, const QMod } else { ui->btnRemoveProblem->setEnabled(true); POJProblem problem = mOJProblemSetModel.problem(idx.row()); + if (problem && !problem->answerProgram.isEmpty()) { + Editor * editor =editorList()->getEditorByFilename(problem->answerProgram); + if (editor) + editor->activate(); + } mOJProblemModel.setProblem(problem); updateProblemTitle(); if (mOJProblemModel.count()>0) { @@ -5318,6 +5323,13 @@ void MainWindow::newProjectUnitFile() //editor->setModified(true); editor->activate(); } + +void MainWindow::onEditorRenamed(const QString &oldFilename, const QString &newFilename, bool firstSave) +{ + if (firstSave) + mOJProblemSetModel.updateProblemAnswerFilename(oldFilename, newFilename); +} + void MainWindow::on_EditorTabsLeft_currentChanged(int) { Editor * editor = mEditorList->getEditor(-1,ui->EditorTabsLeft); @@ -6086,4 +6098,3 @@ void MainWindow::on_actionInterrupt_triggered() mDebugger->interrupt(); } } - diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 9bf90dd0..6ce02b47 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -249,6 +249,7 @@ private: void newProjectUnitFile(); private slots: + void onEditorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave); void onAutoSaveTimeout(); void onFileChanged(const QString& path); diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 98ae78af..c0ab77b7 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -85,7 +85,7 @@ QTabWidget::West - 3 + 4 true diff --git a/RedPandaIDE/widgets/ojproblemsetmodel.cpp b/RedPandaIDE/widgets/ojproblemsetmodel.cpp index ac191cc3..d174074b 100644 --- a/RedPandaIDE/widgets/ojproblemsetmodel.cpp +++ b/RedPandaIDE/widgets/ojproblemsetmodel.cpp @@ -23,6 +23,7 @@ #include #include "../utils.h" #include "../iconsmanager.h" +#include "../systemconsts.h" OJProblemSetModel::OJProblemSetModel(QObject *parent) : QAbstractListModel(parent) { @@ -104,7 +105,8 @@ void OJProblemSetModel::saveToFile(const QString &fileName) problemObj["name"]=problem->name; problemObj["url"]=problem->url; problemObj["description"]=problem->description; - problemObj["answer_program"] = problem->answerProgram; + if (fileExists(problem->answerProgram)) + problemObj["answer_program"] = problem->answerProgram; QJsonArray cases; foreach (const POJProblemCase& problemCase, problem->cases) { QJsonObject caseObj; @@ -170,6 +172,15 @@ void OJProblemSetModel::loadFromFile(const QString &fileName) } } +void OJProblemSetModel::updateProblemAnswerFilename(const QString &oldFilename, const QString &newFilename) +{ + foreach (POJProblem problem, mProblemSet.problems) { + if (QString::compare(problem->answerProgram,oldFilename,PATH_SENSITIVITY)==0) { + problem->answerProgram = newFilename; + } + } +} + int OJProblemSetModel::rowCount(const QModelIndex &) const { return mProblemSet.problems.count(); diff --git a/RedPandaIDE/widgets/ojproblemsetmodel.h b/RedPandaIDE/widgets/ojproblemsetmodel.h index 778d443e..5b4d78d4 100644 --- a/RedPandaIDE/widgets/ojproblemsetmodel.h +++ b/RedPandaIDE/widgets/ojproblemsetmodel.h @@ -66,6 +66,8 @@ public: void removeAllProblems(); void saveToFile(const QString& fileName); void loadFromFile(const QString& fileName); + void updateProblemAnswerFilename(const QString& oldFilename, const QString& newFilename); + signals: void problemNameChanged(int index);