From b70144532ec609f3e31b5934dab9d058f1f202ed Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Fri, 17 Sep 2021 13:35:50 +0800 Subject: [PATCH] work save --- RedPandaIDE/editor.cpp | 12 +++++++ RedPandaIDE/mainwindow.cpp | 65 ++++++++++++++++++++++++++++++++++++++ RedPandaIDE/mainwindow.h | 4 +++ RedPandaIDE/mainwindow.ui | 4 +-- RedPandaIDE/project.cpp | 13 ++++++-- RedPandaIDE/project.h | 3 +- 6 files changed, 96 insertions(+), 5 deletions(-) diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 84a421f7..0e5075ba 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -246,6 +246,15 @@ bool Editor::saveAs(){ return false; } QString newName = dialog.selectedFiles()[0]; + + // Update project information + if (mInProject && pMainWindow->project()) { + int unitIndex = pMainWindow->project()->indexInUnits(mFilename); + if (unitIndex>=0) { + pMainWindow->project()->saveUnitAs(unitIndex,newName); + } + } + pMainWindow->fileSystemWatcher()->removePath(mFilename); if (pSettings->codeCompletion().enabled() && mParser) mParser->invalidateFile(mFilename); @@ -281,6 +290,9 @@ bool Editor::saveAs(){ setUseCodeFolding(false); } setHighlighter(newHighlighter); + if (!newHighlighter || newHighlighter->getName() != SYN_HIGHLIGHTER_CPP) { + mSyntaxIssues.clear(); + } applyColorScheme(pSettings->editor().colorScheme()); reparse(); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 732a07c7..5708a9d9 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1690,6 +1690,7 @@ void MainWindow::updateProjectView() { if (mProject) { ui->projectView->setModel(mProject->model()); + ui->projectView->expandAll(); openCloseLeftPanel(true); ui->tabProject->setVisible(true); ui->tabInfos->setCurrentWidget(ui->tabProject); @@ -2979,6 +2980,70 @@ void MainWindow::on_actionNew_Project_triggered() void MainWindow::on_actionSaveAll_triggered() { + // Pause the change notifier + bool oldBlock = mFileSystemWatcher.blockSignals(true); + auto action = finally([oldBlock,this] { + mFileSystemWatcher.blockSignals(oldBlock); + }); + if (mProject) { + mProject->saveAll(); + } + // Make changes to files + for (int i=0;ipageCount();i++) { + Editor * e= (*mEditorList)[i]; + if (e->modified() && !e->inProject()) { + if (!e->save()) + break; + } + } + updateAppTitle(); +} + + +void MainWindow::on_actionProject_New_File_triggered() +{ + int idx = -1; + if (!mProject) + return; + QModelIndex current = ui->projectView->currentIndex(); + FolderNode * node = nullptr; + if (current.isValid()) { + node = static_cast(current.internalPointer()); + } + PProjectUnit newUnit = mProject->newUnit( + mProject->pointerToNode(node) ); + idx = mProject->units().count()-1; + updateProjectView(); + Editor * editor = mProject->openUnit(idx); + editor->setModified(true); + editor->activate(); +} + + +void MainWindow::on_actionAdd_to_project_triggered() +{ + if (!mProject) + return; + QFileDialog dialog(this,tr("Add to project"), + mProject->directory(), + pSystemConsts->defaultFileFilters().join(";;")); + dialog.setFileMode(QFileDialog::ExistingFiles); + dialog.setOption(QFileDialog::DontConfirmOverwrite,true); + if (dialog.exec()) { + QModelIndex current = ui->projectView->currentIndex(); + FolderNode * node = nullptr; + if (current.isValid()) { + node = static_cast(current.internalPointer()); + } + PFolderNode folderNode = mProject->pointerToNode(node); + foreach (const QString& filename, dialog.selectedFiles()) { + mProject->addUnit(filename,folderNode,false); + mProject->cppParser()->addFileToScan(filename); + } + mProject->rebuildNodes(); + parseFileList(mProject->cppParser()); + updateProjectView(); + } } diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 9c1e78e9..4462f76b 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -314,6 +314,10 @@ private slots: void on_actionSaveAll_triggered(); + void on_actionProject_New_File_triggered(); + + void on_actionAdd_to_project_triggered(); + private: Ui::MainWindow *ui; EditorList *mEditorList; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 200e7dc9..9be0ed35 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -873,7 +873,7 @@ Project - + @@ -1640,7 +1640,7 @@ New Project... - + :/icons/images/newlook24/050-newsrc.png:/icons/images/newlook24/050-newsrc.png diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index ca86c6e8..de5684d0 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -274,7 +274,7 @@ Editor *Project::openUnit(int index) } QByteArray encoding; encoding = unit->encoding(); - editor = pMainWindow->editorList()->newEditor(fullPath, encoding, true, false); + editor = pMainWindow->editorList()->newEditor(fullPath, encoding, true, unit->isNew()); editor->setInProject(true); unit->setEditor(editor); unit->setEncoding(encoding); @@ -531,7 +531,7 @@ bool Project::saveUnits() case FileType::WindowsResourceSource: unit->setFolder("Resources"); } - + unit->setNew(false); ini.SetValue(groupName,"Folder", toByteArray(unit->folder())); ini.SetLongValue(groupName,"Compile", unit->compile()); ini.SetLongValue(groupName,"Link", unit->link()); @@ -578,6 +578,15 @@ void Project::updateNodeIndexes() mUnits[idx]->node()->unitIndex = idx; } +PFolderNode Project::pointerToNode(FolderNode *p) +{ + foreach (const PFolderNode& node , mFolderNodes) { + if (node.get()==p) + return node; + } + return PFolderNode(); +} + bool Project::assignTemplate(const std::shared_ptr aTemplate) { if (!aTemplate) { diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h index 811db295..36654b32 100644 --- a/RedPandaIDE/project.h +++ b/RedPandaIDE/project.h @@ -134,7 +134,7 @@ public: PFolderNode makeNewFileNode(const QString& s, bool isFolder, PFolderNode newParent); PFolderNode makeProjectNode(); PProjectUnit newUnit(PFolderNode parentNode, - const QString& customFileName); + const QString& customFileName=""); Editor* openUnit(int index); void rebuildNodes(); bool removeEditor(int index, bool doClose); @@ -151,6 +151,7 @@ public: void sortUnitsByAlpha(); void updateFolders(); void updateNodeIndexes(); + PFolderNode pointerToNode(FolderNode * p); //void showOptions(); bool assignTemplate(const std::shared_ptr aTemplate);