From 527fc3b6346159e9703e517cfc80cd882017d640 Mon Sep 17 00:00:00 2001 From: royqh1979 Date: Sat, 11 Sep 2021 11:42:20 +0800 Subject: [PATCH] work save --- RedPandaIDE/mainwindow.cpp | 187 +++++++++++++++++++++++++++++++------ RedPandaIDE/mainwindow.h | 3 + RedPandaIDE/mainwindow.ui | 21 ++++- RedPandaIDE/project.cpp | 55 +++++++++-- RedPandaIDE/project.h | 4 + RedPandaIDE/settings.cpp | 10 ++ RedPandaIDE/settings.h | 1 + 7 files changed, 243 insertions(+), 38 deletions(-) diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 241e460f..5f27400f 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -9,6 +9,7 @@ #include "debugger.h" #include "widgets/cpudialog.h" #include "widgets/filepropertiesdialog.h" +#include "project.h" #include #include @@ -60,6 +61,7 @@ MainWindow::MainWindow(QWidget *parent) ui->EditorTabsRight, ui->splitterEditorPanel, ui->EditorPanel); + mProject = nullptr; setAcceptDrops(true); setupActions(); ui->EditorTabsRight->setVisible(false); @@ -366,54 +368,96 @@ void MainWindow::updateAppTitle() { QString appName("Red Panda Dev-C++"); Editor *e = mEditorList->getEditor(); - QString str; QCoreApplication *app = QApplication::instance(); if (e && !e->inProject()) { + QString str; if (e->modified()) str = e->filename() + " [*]"; else str = e->filename(); if (mDebugger->executing()) { setWindowTitle(QString("%1 - [%2] - %3 %4") - .arg(str,appName,tr("Debugging"),DEVCPP_VERSION)); + .arg(str,tr("Debugging"),appName,DEVCPP_VERSION)); app->setApplicationName(QString("%1 - [%2] - %3") - .arg(str,appName,tr("Debugging"))); + .arg(str,tr("Debugging"),appName)); } else if (mCompilerManager->running()) { setWindowTitle(QString("%1 - [%2] - %3 %4") - .arg(str,appName,tr("Running"),DEVCPP_VERSION)); + .arg(str,tr("Running"),appName,DEVCPP_VERSION)); app->setApplicationName(QString("%1 - [%2] - %3") - .arg(str,appName,tr("Running"))); + .arg(str,tr("Running"),appName)); } else if (mCompilerManager->compiling()) { setWindowTitle(QString("%1 - [%2] - %3 %4") - .arg(str,appName,tr("Compiling"),DEVCPP_VERSION)); + .arg(str,tr("Compiling"),appName,DEVCPP_VERSION)); app->setApplicationName(QString("%1 - [%2] - %3") - .arg(str,appName,tr("Compiling"))); + .arg(str,tr("Compiling"),appName)); } else { this->setWindowTitle(QString("%1 - %2 %3") .arg(str,appName,DEVCPP_VERSION)); app->setApplicationName(QString("%1 - %2") .arg(str,appName)); } - } -// else if Assigned(fProject) then begin -// if fDebugger.Executing then begin -// Caption := Format('%s - [%s] - [Debugging] - %s %s', -// [fProject.Name, ExtractFilename(fProject.Filename), appName, DEVCPP_VERSION]); -// Application.Title := Format('%s - [Debugging] - %s', [fProject.Name, appName]); -// end else if devExecutor.Running then begin -// Caption := Format('%s - [%s] - [Executing] - %s %s', -// [fProject.Name, ExtractFilename(fProject.Filename), appName, DEVCPP_VERSION]); -// Application.Title := Format('%s - [Executing] - %s', [fProject.Name, appName]); -// end else if fCompiler.Compiling then begin -// Caption := Format('%s - [%s] - [Compiling] - %s %s', -// [fProject.Name, ExtractFilename(fProject.Filename), appName, DEVCPP_VERSION]); -// Application.Title := Format('%s - [Compiling] - %s', [fProject.Name, appName]); -// end else begin -// Caption := Format('%s - [%s] - %s %s', -// [fProject.Name, ExtractFilename(fProject.Filename), appName, DEVCPP_VERSION]); -// Application.Title := Format('%s - %s', [fProject.Name, appName]); -// end; - else { + } else if (e && e->inProject() && mProject) { + QString str,str2; + if (mProject->modified()) + str = mProject->name() + " [*]"; + else + str = mProject->name(); + if (e->modified()) + str2 = extractFileName(e->filename()) + " [*]"; + else + str2 = extractFileName(e->filename()); + if (mDebugger->executing()) { + setWindowTitle(QString("%1 - %2 [%3] - %4 %5") + .arg(str,str2, + tr("Debugging"),appName,DEVCPP_VERSION)); + app->setApplicationName(QString("%1 - [%2] - %3") + .arg(str,tr("Debugging"),appName)); + } else if (mCompilerManager->running()) { + setWindowTitle(QString("%1 - %2 [%3] - %4 %5") + .arg(str,str2, + tr("Running"),appName,DEVCPP_VERSION)); + app->setApplicationName(QString("%1 - [%2] - %3") + .arg(str,tr("Running"),appName)); + } else if (mCompilerManager->compiling()) { + setWindowTitle(QString("%1 - %2 [%3] - %4 %5") + .arg(str,str2, + tr("Compiling"),appName,DEVCPP_VERSION)); + app->setApplicationName(QString("%1 - [%2] - %3") + .arg(str,tr("Compiling"),appName)); + } else { + setWindowTitle(QString("%1 - %2 %3") + .arg(str,appName,DEVCPP_VERSION)); + app->setApplicationName(QString("%1 - %2") + .arg(str,appName)); + } + } else if (mProject) { + QString str,str2; + if (mProject->modified()) + str = mProject->name() + " [*]"; + else + str = mProject->name(); + if (mDebugger->executing()) { + setWindowTitle(QString("%1 - [%2] - %3 %4") + .arg(str,tr("Debugging"),appName,DEVCPP_VERSION)); + app->setApplicationName(QString("%1 - [%2] - %3") + .arg(str,tr("Debugging"),appName)); + } else if (mCompilerManager->running()) { + setWindowTitle(QString("%1 - [%2] - %3 %4") + .arg(str,tr("Running"),appName,DEVCPP_VERSION)); + app->setApplicationName(QString("%1 - [%2] - %3") + .arg(str,tr("Running"),appName)); + } else if (mCompilerManager->compiling()) { + setWindowTitle(QString("%1 - [%2] - %3 %4") + .arg(str,tr("Compiling"),appName,DEVCPP_VERSION)); + app->setApplicationName(QString("%1 - [%2] - %3") + .arg(str,tr("Compiling"),appName)); + } else { + this->setWindowTitle(QString("%1 - %2 %3") + .arg(str,appName,DEVCPP_VERSION)); + app->setApplicationName(QString("%1 - %2") + .arg(str,appName)); + } + } else { setWindowTitle(QString("%1 %2").arg(appName,DEVCPP_VERSION)); app->setApplicationName(QString("%1").arg(appName)); } @@ -576,6 +620,7 @@ void MainWindow::openFile(const QString &filename) return; } try { + pSettings->history().removeFile(filename); editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT, false,false); editor->activate(); @@ -585,6 +630,81 @@ void MainWindow::openFile(const QString &filename) } } +void MainWindow::openProject(const QString &filename) +{ + if (!fileExists(filename)) { + return; + } + if (mProject) { + QString s; + if (mProject->name().isEmpty()) + s = mProject->filename(); + else + s = mProject->name(); + if (QMessageBox::question(this, + tr("Close project"), + tr("Are you sure you want to close %1?") + .arg(s), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::Yes) == QMessageBox::Yes) { + closeProject(false); + } else { + return; + } + } + ui->tabProject->setVisible(true); + ui->tabInfos->setCurrentWidget(ui->tabProject); + openCloseLeftPanel(true); +// { +// LeftPageControl.ActivePage := LeftProjectSheet; +// fLeftPageControlChanged := False; +// ClassBrowser.TabVisible:= False; +// } + + // Only update class browser once + mClassBrowserModel.beginUpdate(); + { + auto action = finally([this]{ + mClassBrowserModel.endUpdate(); + }); + mProject = new Project(filename,DEV_INTERNAL_OPEN); + pSettings->history().removeFile(filename); + + // // if project manager isn't open then open it + // if not devData.ShowLeftPages then + // actProjectManager.Execute; + checkForDllProfiling(); + updateAppTitle(); + updateCompilerSet(); + + //parse the project + // UpdateClassBrowsing; + scanActiveProject(true); + mProject->doAutoOpen(); + + //update editor's inproject flag + for (int i=0;iunits().count();i++) { + PProjectUnit unit = mProject->units()[i]; + Editor* e = mEditorList->getOpenedEditorByFilename(unit->filename()); + if (e) { + unit->setEditor(e); + unit->setEncoding(e->encodingOption()); + e->setInProject(true); + } else { + unit->setEditor(nullptr); + e->setInProject(false); + } + } + + Editor * e = mEditorList->getEditor(); + if (e) { + checkSyntaxInBack(e); + } + updateClassBrowserForEditor(e); + } + updateForEncodingInfo(); +} + void MainWindow::setupActions() { } @@ -592,12 +712,18 @@ void MainWindow::setupActions() { void MainWindow::updateCompilerSet() { mCompilerSet->clear(); - int index=pSettings->compilerSets().defaultIndex(); for (size_t i=0;icompilerSets().list().size();i++) { mCompilerSet->addItem(pSettings->compilerSets().list()[i]->name()); } + int index=pSettings->compilerSets().defaultIndex(); + if (mProject) { + Editor *e = mEditorList->getEditor(); + if ( !e || e->inProject()) { + index = mProject->options().compilerSet; + } + } if (index < 0 || index>=mCompilerSet->count()) { - index = 0; + index = pSettings->compilerSets().defaultIndex(); } mCompilerSet->setCurrentIndex(index); } @@ -614,6 +740,9 @@ void MainWindow::checkSyntaxInBack(Editor *e) if (e==nullptr) return; + if (!pSettings->editor().syntaxCheck()) { + return; + } // if not devEditor.AutoCheckSyntax then // Exit; //not c or cpp file diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 537d67d0..9064d6e0 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -29,6 +29,7 @@ class Debugger; class CPUDialog; class QPlainTextEdit; class SearchDialog; +class Project; class MainWindow : public QMainWindow { @@ -124,6 +125,7 @@ public slots: private: void openFiles(const QStringList& files); void openFile(const QString& filename); + void openProject(const QString& filename); CompileTarget getCompileTarget(); bool debugInferiorhasBreakpoint(); void setupActions(); @@ -315,6 +317,7 @@ private: bool mQuitting; QElapsedTimer mParserTimer; QFileSystemWatcher mFileSystemWatcher; + Project* mProject; std::shared_ptr mCompletionPopup; std::shared_ptr mHeaderCompletionPopup; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index c65d8c07..10f2112c 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -85,7 +85,7 @@ QTabWidget::West - 2 + 0 true @@ -94,6 +94,23 @@ Project + + + 0 + + + 0 + + + 0 + + + 0 + + + + + @@ -772,7 +789,7 @@ 0 0 946 - 25 + 22 diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 10392041..74399bb7 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -466,9 +466,9 @@ bool Project::saveUnits() for (int idx = 0; idx < mUnits.count(); idx++) { PProjectUnit unit = mUnits[idx]; bool rd_only = false; - mIniFile->beginGroup(QString("Unit%1").arg(count+1); + mIniFile->beginGroup(QString("Unit%1").arg(count+1)); if (unit->modified() && fileExists(unit->fileName()) - && isReadonly(unit->fileName)) { + && isReadOnly(unit->fileName())) { // file is read-only QMessageBox::critical(pMainWindow, tr("Can't save file"), @@ -1376,6 +1376,11 @@ void Project::updateFolderNode(PFolderNode node) } } +const QList &Project::units() const +{ + return mUnits; +} + const ProjectOptions &Project::options() const { return mOptions; @@ -1386,6 +1391,11 @@ void Project::setOptions(const ProjectOptions &newOptions) mOptions = newOptions; } +const ProjectModel *Project::model() const +{ + return &mModel; +} + const PFolderNode &Project::node() const { return mNode; @@ -1621,6 +1631,39 @@ void ProjectModel::endUpdate() endResetModel(); } +QModelIndex ProjectModel::index(int row, int column, const QModelIndex &parent) const +{ + if (!parent.isValid()) { + return createIndex(row,column,mProject->node().get()); + } + FolderNode* parentNode = static_cast(parent.internalPointer()); + if (!parentNode) { + return QModelIndex(); + } + return createIndex(row,column,parentNode->children[row].get()); +} + +QModelIndex ProjectModel::parent(const QModelIndex &child) const +{ + if (!child.isValid()) + return QModelIndex(); + FolderNode * node = static_cast(child.internalPointer()); + if (!node) + return QModelIndex(); + PFolderNode parent = node->parent.lock(); + if (!parent) // root node + return QModelIndex(); + PFolderNode grand = parent->parent.lock(); + if (!grand) { + return createIndex(0,0,parent.get()); + } + + int row = grand->children.indexOf(parent); + if (row<0) + return QModelIndex(); + return createIndex(row,0,parent.get()); +} + int ProjectModel::rowCount(const QModelIndex &parent) const { if (!parent.isValid()) @@ -1645,10 +1688,8 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const FolderNode* p = static_cast(index.internalPointer()); if (!p) return QVariant(); - - return p->children.count(); - } else { - return mProject->node()->children.count(); + if (role == Qt::DisplayRole) { + return p->text; } - + return QVariant(); } diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h index 4e5cc825..f25dbefc 100644 --- a/RedPandaIDE/project.h +++ b/RedPandaIDE/project.h @@ -225,6 +225,10 @@ public: const ProjectOptions &options() const; void setOptions(const ProjectOptions &newOptions); + const ProjectModel* model() const; + + const QList &units() const; + signals: void nodesChanged(); void modifyChanged(bool value); diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index f0984852..606f3e4e 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -2658,6 +2658,16 @@ bool Settings::History::addToOpenedFiles(const QString &filename) } +void Settings::History::removeFile(const QString &filename) +{ + int index = mOpenedFiles.indexOf(filename); + if (index>=0) { + mOpenedFiles.removeAt(index); + } + save(); + return; +} + void Settings::History::doSave() { saveValue("opened_files", mOpenedFiles); diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index a48259b1..9f8a56b2 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -680,6 +680,7 @@ public: const QStringList& openedFiles() const; const QStringList& openedProjects() const; bool addToOpenedFiles(const QString& filename); + void removeFile(const QString& filename); private: QStringList mOpenedFiles; QStringList mOpenedProjects;