diff --git a/NEWS.md b/NEWS.md index 1490f8bf..ead59b3b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -27,7 +27,7 @@ Red Panda C++ Version 1.5 - enhancement: When open a project, let user choose weither open it in new window or replace the already openned project - fix: editor tooltip for #include_next is not correctly calculated - fix: ctrl+click on #include_next header name doesn't open the right file - - enhancement: parser used for non-project C files won't find header files in C++ include folders. + - enhancement: parser used for non-project C files won't search header files in C++ include folders. - fix: toggle block comment/delete to word begin/delete to word end are not correctly disabled when editor not open Red Panda C++ Version 1.4 diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index d3fe55ea..3cbbeb93 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -1210,9 +1210,11 @@ void Editor::mouseReleaseEvent(QMouseEvent *event) if (mParser->isIncludeNextLine(s)) { QString filename = mParser->getHeaderFileName(mFilename,s, true); pMainWindow->openFile(filename); + return; } if (mParser->isIncludeLine(s)) { QString filename = mParser->getHeaderFileName(mFilename,s); pMainWindow->openFile(filename); + return; } else { gotoDefinition(p); return; diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 72c82887..6dcb5b11 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1243,6 +1243,8 @@ void MainWindow::openFiles(const QStringList &files) Editor* MainWindow::openFile(const QString &filename, bool activate, QTabWidget* page) { + if (filename.isEmpty()) + return nullptr; Editor* editor = mEditorList->getOpenedEditorByFilename(filename); if (editor!=nullptr) { if (activate) { diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index b7950ef6..3aa9029a 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -709,7 +709,7 @@ QString CppParser::getHeaderFileName(const QString &relativeTo, const QString &h QString currentDir = includeTrailingPathDelimiter(extractFileDir(relativeTo)); QStringList includes; QStringList projectIncludes; - bool found; + bool found=false; if (fromNext && mPreprocessor->includePaths().contains(currentDir)) { foreach(const QString& s, mPreprocessor->includePathList()) { if (found) { diff --git a/RedPandaIDE/parser/cpppreprocessor.cpp b/RedPandaIDE/parser/cpppreprocessor.cpp index d08ada4f..6c007083 100644 --- a/RedPandaIDE/parser/cpppreprocessor.cpp +++ b/RedPandaIDE/parser/cpppreprocessor.cpp @@ -460,7 +460,7 @@ void CppPreprocessor::handleInclude(const QString &line, bool fromNext) QString currentDir = includeTrailingPathDelimiter(extractFileDir(file->fileName)); QStringList includes; QStringList projectIncludes; - bool found; + bool found=false; if (fromNext && mIncludePaths.contains(currentDir)) { foreach(const QString& s, mIncludePathList) { if (found) { @@ -499,18 +499,28 @@ void CppPreprocessor::handleInclude(const QString &line, bool fromNext) void CppPreprocessor::handlePreprocessor(const QString &value) { - if (value.startsWith("define")) - handleDefine(value); - else if (value.startsWith("undef")) - handleUndefine(value); - else if (value.startsWith("if") - || value.startsWith("else") || value.startsWith("elif") - || value.startsWith("endif")) - handleBranch(value); - else if (value.startsWith("include_next")) - handleInclude(value,true); - else if (value.startsWith("include")) - handleInclude(value); + switch(value[0].unicode()) { + case 'd': + if (value.startsWith("define")) + handleDefine(value); + break; + case 'e': + if (value.startsWith("else") || value.startsWith("elif") + || value.startsWith("endif")) + handleBranch(value); + break; + case 'i': + if (value.startsWith("if")) + handleBranch(value); + else if (value.startsWith("include")) + handleInclude(value, value.startsWith("include_next")); + break; + case 'u': + if (value.startsWith("undef")) + handleUndefine(value); + break; + + } } void CppPreprocessor::handleUndefine(const QString &line)