diff --git a/NEWS.md b/NEWS.md index 3b0a4cb5..c83d8e0b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,6 +20,7 @@ Red Panda C++ Version 2.0 - enhancement: auto locate the last opened file in the project view after project creation - enhancement: separate compiler's language standard option for C / C++ - fix: compiler settings not correctly handled when create makefile + - enhancement: auto locate current open file in the project view panel Red Panda C++ Version 1.5 diff --git a/RedPandaIDE/compiler/compiler.cpp b/RedPandaIDE/compiler/compiler.cpp index 07ab4972..c8c4724b 100644 --- a/RedPandaIDE/compiler/compiler.cpp +++ b/RedPandaIDE/compiler/compiler.cpp @@ -113,7 +113,8 @@ QString Compiler::getFileNameFromOutputLine(QString &line) { break; } } - return temp; + QFileInfo info(temp); + return info.isRelative()?absolutePath(mDirectory,temp):cleanPath(temp); } int Compiler::getLineNumberFromOutputLine(QString &line) diff --git a/RedPandaIDE/compiler/projectcompiler.cpp b/RedPandaIDE/compiler/projectcompiler.cpp index 61436d60..396f8224 100644 --- a/RedPandaIDE/compiler/projectcompiler.cpp +++ b/RedPandaIDE/compiler/projectcompiler.cpp @@ -512,12 +512,6 @@ bool ProjectCompiler::prepareForRebuild() return true; } -QString ProjectCompiler::getFileNameFromOutputLine(QString &line) -{ - QString temp=Compiler::getFileNameFromOutputLine(line); - return absolutePath(mDirectory,temp); -} - bool ProjectCompiler::prepareForCompile() { if (!mProject) diff --git a/RedPandaIDE/compiler/projectcompiler.h b/RedPandaIDE/compiler/projectcompiler.h index d5f94077..1a829c63 100644 --- a/RedPandaIDE/compiler/projectcompiler.h +++ b/RedPandaIDE/compiler/projectcompiler.h @@ -50,10 +50,6 @@ private: protected: bool prepareForCompile() override; bool prepareForRebuild() override; - - // Compiler interface -protected: - QString getFileNameFromOutputLine(QString &line) override; }; #endif // PROJECTCOMPILER_H diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 12265b7f..d36b7e59 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -1298,6 +1298,9 @@ void Editor::showEvent(QShowEvent */*event*/) pMainWindow->updateForEncodingInfo(this); pMainWindow->updateStatusbarForLineCol(this); pMainWindow->updateForStatusbarModeInfo(this); + if (inProject()) { + pMainWindow->setProjectCurrentFile(mFilename); + } setHideTime(QDateTime::currentDateTime()); } diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 0e58bd46..2f9cf3de 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1271,6 +1271,21 @@ void MainWindow::updateStatusbarMessage(const QString &s) ui->statusbar->showMessage(s); } +void MainWindow::setProjectCurrentFile(const QString &filename) +{ + if (!mProject) + return; + PProjectUnit unit = mProject->findUnit(filename); + if (!unit) + return; + QModelIndex index = mProject->model()->getNodeIndex(unit->node().get()); + index = mProjectProxyModel->mapFromSource(index); + if (index.isValid()) { + ui->projectView->expand(index); + ui->projectView->setCurrentIndex(index); + } +} + void MainWindow::openFiles(const QStringList &files) { mEditorList->beginUpdate(); @@ -6304,12 +6319,8 @@ void MainWindow::on_actionAdd_to_project_triggered() if (newUnit) { QModelIndex index = mProject->model()->getNodeIndex(newUnit->node().get()); index = mProjectProxyModel->mapFromSource(index); - QModelIndex parentIndex = mProject->model()->getParentIndex(newUnit->node().get()); - parentIndex = mProjectProxyModel->mapFromSource(parentIndex); - if (parentIndex.isValid()) { - ui->projectView->expand(parentIndex); - } if (index.isValid()) { + ui->projectView->expand(index); ui->projectView->setCurrentIndex(index); } } @@ -6740,14 +6751,10 @@ void MainWindow::onProjectViewNodeRenamed() void MainWindow::setProjectViewCurrentNode(PProjectModelNode node) { if (node) { - QModelIndex parentIndex = mProject->model()->getParentIndex(node.get()); - parentIndex = mProjectProxyModel->mapFromSource(parentIndex); - if (parentIndex.isValid()) { - ui->projectView->expand(parentIndex); - } QModelIndex index = mProject->model()->getNodeIndex(node.get()); index = mProjectProxyModel->mapFromSource(index); if (index.isValid()) { + ui->projectView->expand(index); ui->projectView->setCurrentIndex(index); } } diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index d861611c..274902f8 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -114,6 +114,7 @@ public: void updateForStatusbarModeInfo(bool clear=false); void updateForStatusbarModeInfo(const Editor* editor, bool clear=false); void updateStatusbarMessage(const QString& s); + void setProjectCurrentFile(const QString& filename); void updateEditorSettings(); void updateEditorBookmarks(); void updateEditorBreakpoints();