- enhancement: assign a not saved editor to a problem
This commit is contained in:
parent
1cc36564de
commit
212fdc37b2
|
@ -58,6 +58,13 @@ struct WatchVar {
|
||||||
WatchVar * parent; //use raw point to prevent circular-reference
|
WatchVar * parent; //use raw point to prevent circular-reference
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class BreakpointType {
|
||||||
|
Breakpoint,
|
||||||
|
Watchpoint,
|
||||||
|
ReadWatchpoint,
|
||||||
|
WriteWatchpoint
|
||||||
|
};
|
||||||
|
|
||||||
struct Breakpoint {
|
struct Breakpoint {
|
||||||
int number; // breakpoint number
|
int number; // breakpoint number
|
||||||
QString type; // type of the breakpoint
|
QString type; // type of the breakpoint
|
||||||
|
|
|
@ -276,6 +276,8 @@ bool Editor::save(bool force, bool doReparse) {
|
||||||
|
|
||||||
bool Editor::saveAs(const QString &name, bool fromProject){
|
bool Editor::saveAs(const QString &name, bool fromProject){
|
||||||
QString newName = name;
|
QString newName = name;
|
||||||
|
QString oldName = mFilename;
|
||||||
|
bool firstSave = isNew();
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
QString selectedFileFilter;
|
QString selectedFileFilter;
|
||||||
QString defaultExt;
|
QString defaultExt;
|
||||||
|
@ -376,6 +378,8 @@ bool Editor::saveAs(const QString &name, bool fromProject){
|
||||||
setReadOnly(false);
|
setReadOnly(false);
|
||||||
updateCaption();
|
updateCaption();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit renamed(oldName, newName , firstSave);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -221,7 +221,8 @@ public:
|
||||||
const PCppParser &parser();
|
const PCppParser &parser();
|
||||||
|
|
||||||
void tab() override;
|
void tab() override;
|
||||||
|
signals:
|
||||||
|
void renamed(const QString& oldName, const QString& newName, bool firstSave);
|
||||||
private slots:
|
private slots:
|
||||||
void onStatusChanged(SynStatusChanges changes);
|
void onStatusChanged(SynStatusChanges changes);
|
||||||
void onGutterClicked(Qt::MouseButton button, int x, int y, int line);
|
void onGutterClicked(Qt::MouseButton button, int x, int y, int line);
|
||||||
|
|
|
@ -53,6 +53,7 @@ Editor* EditorList::newEditor(const QString& filename, const QByteArray& encodin
|
||||||
pMainWindow->fileSystemWatcher()->addPath(filename);
|
pMainWindow->fileSystemWatcher()->addPath(filename);
|
||||||
}
|
}
|
||||||
Editor * e = new Editor(parentPageControl,filename,encoding,inProject,newFile,parentPageControl);
|
Editor * e = new Editor(parentPageControl,filename,encoding,inProject,newFile,parentPageControl);
|
||||||
|
connect(e, &Editor::renamed, this, &EditorList::onEditorRenamed);
|
||||||
updateLayout();
|
updateLayout();
|
||||||
return e;
|
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
|
QTabWidget *EditorList::rightPageWidget() const
|
||||||
{
|
{
|
||||||
return mRightPageWidget;
|
return mRightPageWidget;
|
||||||
|
|
|
@ -78,13 +78,14 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void editorClosed();
|
void editorClosed();
|
||||||
|
void editorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTabWidget* getNewEditorPageControl() const;
|
QTabWidget* getNewEditorPageControl() const;
|
||||||
QTabWidget* getFocusedPageControl() const;
|
QTabWidget* getFocusedPageControl() const;
|
||||||
void showLayout(LayoutShowType layout);
|
void showLayout(LayoutShowType layout);
|
||||||
|
private slots:
|
||||||
|
void onEditorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave);
|
||||||
private:
|
private:
|
||||||
LayoutShowType mLayout;
|
LayoutShowType mLayout;
|
||||||
QTabWidget *mLeftPageWidget;
|
QTabWidget *mLeftPageWidget;
|
||||||
|
|
|
@ -112,6 +112,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
ui->EditorTabsRight,
|
ui->EditorTabsRight,
|
||||||
ui->splitterEditorPanel,
|
ui->splitterEditorPanel,
|
||||||
ui->EditorPanel);
|
ui->EditorPanel);
|
||||||
|
connect(mEditorList, &EditorList::editorRenamed,
|
||||||
|
this, &MainWindow::onEditorRenamed);
|
||||||
connect(mEditorList, &EditorList::editorClosed,
|
connect(mEditorList, &EditorList::editorClosed,
|
||||||
this, &MainWindow::onEditorClosed);
|
this, &MainWindow::onEditorClosed);
|
||||||
mProject = nullptr;
|
mProject = nullptr;
|
||||||
|
@ -2963,8 +2965,6 @@ void MainWindow::onLstProblemSetContextMenu(const QPoint &pos)
|
||||||
menuSetAnswer->setTitle(tr("Set answer to..."));
|
menuSetAnswer->setTitle(tr("Set answer to..."));
|
||||||
for (int i=0;i<mEditorList->pageCount();i++) {
|
for (int i=0;i<mEditorList->pageCount();i++) {
|
||||||
Editor *e = (*mEditorList)[i];
|
Editor *e = (*mEditorList)[i];
|
||||||
if (e->isNew())
|
|
||||||
continue;
|
|
||||||
QString filename = e->filename();
|
QString filename = e->filename();
|
||||||
QAction* action = new QAction(filename,menuSetAnswer);
|
QAction* action = new QAction(filename,menuSetAnswer);
|
||||||
action->setCheckable(true);
|
action->setCheckable(true);
|
||||||
|
@ -3038,6 +3038,11 @@ void MainWindow::onProblemSetIndexChanged(const QModelIndex ¤t, const QMod
|
||||||
} else {
|
} else {
|
||||||
ui->btnRemoveProblem->setEnabled(true);
|
ui->btnRemoveProblem->setEnabled(true);
|
||||||
POJProblem problem = mOJProblemSetModel.problem(idx.row());
|
POJProblem problem = mOJProblemSetModel.problem(idx.row());
|
||||||
|
if (problem && !problem->answerProgram.isEmpty()) {
|
||||||
|
Editor * editor =editorList()->getEditorByFilename(problem->answerProgram);
|
||||||
|
if (editor)
|
||||||
|
editor->activate();
|
||||||
|
}
|
||||||
mOJProblemModel.setProblem(problem);
|
mOJProblemModel.setProblem(problem);
|
||||||
updateProblemTitle();
|
updateProblemTitle();
|
||||||
if (mOJProblemModel.count()>0) {
|
if (mOJProblemModel.count()>0) {
|
||||||
|
@ -5318,6 +5323,13 @@ void MainWindow::newProjectUnitFile()
|
||||||
//editor->setModified(true);
|
//editor->setModified(true);
|
||||||
editor->activate();
|
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)
|
void MainWindow::on_EditorTabsLeft_currentChanged(int)
|
||||||
{
|
{
|
||||||
Editor * editor = mEditorList->getEditor(-1,ui->EditorTabsLeft);
|
Editor * editor = mEditorList->getEditor(-1,ui->EditorTabsLeft);
|
||||||
|
@ -6086,4 +6098,3 @@ void MainWindow::on_actionInterrupt_triggered()
|
||||||
mDebugger->interrupt();
|
mDebugger->interrupt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -249,6 +249,7 @@ private:
|
||||||
void newProjectUnitFile();
|
void newProjectUnitFile();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void onEditorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave);
|
||||||
void onAutoSaveTimeout();
|
void onAutoSaveTimeout();
|
||||||
void onFileChanged(const QString& path);
|
void onFileChanged(const QString& path);
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@
|
||||||
<enum>QTabWidget::West</enum>
|
<enum>QTabWidget::West</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>3</number>
|
<number>4</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="usesScrollButtons">
|
<property name="usesScrollButtons">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include "../utils.h"
|
#include "../utils.h"
|
||||||
#include "../iconsmanager.h"
|
#include "../iconsmanager.h"
|
||||||
|
#include "../systemconsts.h"
|
||||||
|
|
||||||
OJProblemSetModel::OJProblemSetModel(QObject *parent) : QAbstractListModel(parent)
|
OJProblemSetModel::OJProblemSetModel(QObject *parent) : QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
|
@ -104,7 +105,8 @@ 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;
|
if (fileExists(problem->answerProgram))
|
||||||
|
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;
|
||||||
|
@ -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
|
int OJProblemSetModel::rowCount(const QModelIndex &) const
|
||||||
{
|
{
|
||||||
return mProblemSet.problems.count();
|
return mProblemSet.problems.count();
|
||||||
|
|
|
@ -66,6 +66,8 @@ public:
|
||||||
void removeAllProblems();
|
void removeAllProblems();
|
||||||
void saveToFile(const QString& fileName);
|
void saveToFile(const QString& fileName);
|
||||||
void loadFromFile(const QString& fileName);
|
void loadFromFile(const QString& fileName);
|
||||||
|
void updateProblemAnswerFilename(const QString& oldFilename, const QString& newFilename);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void problemNameChanged(int index);
|
void problemNameChanged(int index);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue