diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 2b1479a1..7ce3dc5e 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -87,6 +87,12 @@ MainWindow::MainWindow(QWidget *parent) ui->actionEncode_in_ANSI->setCheckable(true); ui->actionEncode_in_UTF_8->setCheckable(true); + mMenuRecentFiles = new QMenu(); + mMenuRecentFiles->setTitle(tr("Recent Files")); + ui->menuFile->insertMenu(ui->actionExit, mMenuRecentFiles); + ui->menuFile->insertSeparator(ui->actionExit); + rebuildOpenedFileHisotryMenu(); + mCPUDialog = nullptr; updateEditorActions(); @@ -330,6 +336,30 @@ void MainWindow::updateDebugEval(const QString &value) ui->txtEvalOutput->appendPlainText(value); } +void MainWindow::rebuildOpenedFileHisotryMenu() +{ + mMenuRecentFiles->clear(); + for (QAction* action:mRecentFileActions) { + action->setParent(nullptr); + action->deleteLater(); + } + mRecentFileActions.clear(); + if (pSettings->history().openedFiles().size()==0) { + mMenuRecentFiles->setEnabled(false); + } else { + mMenuRecentFiles->setEnabled(true); + for (QString filename: pSettings->history().openedFiles()) { + QAction* action = new QAction(); + action->setText(filename); + connect(action, &QAction::triggered, [=,this](bool checked = false){ + this->openFile(filename); + }); + mRecentFileActions.append(action); + } + mMenuRecentFiles->addActions(mRecentFileActions); + } +} + QPlainTextEdit *MainWindow::txtLocals() { return ui->txtLocals; @@ -1456,3 +1486,8 @@ void MainWindow::on_txtEvaludate_returnPressed() mDebugger->sendCommand("print",s,false); } } + +void MainWindow::on_actionExit_triggered() +{ + close(); +} diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 55e03f82..8312eeb4 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -68,13 +68,14 @@ public: void changeDebugOutputLastline(const QString& text); void updateDebugEval(const QString& value); + void rebuildOpenedFileHisotryMenu(); + QPlainTextEdit* txtLocals(); CPUDialog *cpuDialog() const; Debugger *debugger() const; - protected: void openFiles(const QStringList& files); void openFile(const QString& filename); @@ -165,6 +166,8 @@ private slots: void on_txtEvaludate_returnPressed(); + void on_actionExit_triggered(); + public slots: void onCompileLog(const QString& msg); void onCompileIssue(PCompileIssue issue); @@ -188,10 +191,12 @@ private: QLabel *mFileModeStatus; QMenu *mMenuEncoding; QMenu *mMenuEncodingList; + QMenu *mMenuRecentFiles; QComboBox *mCompilerSet; CompilerManager *mCompilerManager; Debugger *mDebugger; CPUDialog *mCPUDialog; + QList mRecentFileActions; bool mMessageControlChanged; bool mTabMessagesTogglingState; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 703cf0ff..d1763c35 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -566,6 +566,8 @@ + + @@ -573,9 +575,9 @@ - + - Run + Execute @@ -614,7 +616,7 @@ - + @@ -1078,6 +1080,11 @@ View CPU Window... + + + Exit + + diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 7addfeb8..4e8db11c 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -22,7 +22,8 @@ Settings::Settings(const QString &filename): mEnvironment(this), mCompilerSets(this), mExecutor(this), - mDebugger(this) + mDebugger(this), + mHistory(this) { } @@ -2350,16 +2351,29 @@ Settings::History::History(Settings *settings):_Base(settings, SETTING_HISTORY) } +QStringList &Settings::History::openedFiles() +{ + return mOpenedFiles; +} + +QStringList &Settings::History::openedProjects() +{ + return mOpenedProjects; +} + bool Settings::History::addToOpenedFiles(const QString &filename) { if (!QFile(filename).exists()) return false; - if (openedFiles().indexOf(filename)>=0) - return false; - if (openedFiles().size()>=15) { - openedFiles().pop_front(); + int index = mOpenedFiles.indexOf(filename); + if (index>=0) { + mOpenedFiles.removeAt(index); } - openedFiles().append(filename); + if (mOpenedFiles.size()>=15) { + mOpenedFiles.pop_back(); + } + mOpenedFiles.push_front(filename); + save(); return true; } diff --git a/RedPandaIDE/widgets/cpudialog.cpp b/RedPandaIDE/widgets/cpudialog.cpp index 2cf03223..2f7f142a 100644 --- a/RedPandaIDE/widgets/cpudialog.cpp +++ b/RedPandaIDE/widgets/cpudialog.cpp @@ -75,9 +75,13 @@ void CPUDialog::closeEvent(QCloseEvent *event) void CPUDialog::on_rdIntel_toggled(bool) { sendSyntaxCommand(); + pSettings->debugger().setUseIntelStyle(ui->rdIntel->isChecked()); + pSettings->debugger().save(); } void CPUDialog::on_rdATT_toggled(bool) { sendSyntaxCommand(); + pSettings->debugger().setUseIntelStyle(ui->rdIntel->isChecked()); + pSettings->debugger().save(); }