- 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
|
||||
};
|
||||
|
||||
enum class BreakpointType {
|
||||
Breakpoint,
|
||||
Watchpoint,
|
||||
ReadWatchpoint,
|
||||
WriteWatchpoint
|
||||
};
|
||||
|
||||
struct Breakpoint {
|
||||
int number; // breakpoint number
|
||||
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){
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;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);
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<enum>QTabWidget::West</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>3</number>
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="usesScrollButtons">
|
||||
<bool>true</bool>
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <QJsonObject>
|
||||
#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();
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue