fix: click a non-existing header name will get an error

This commit is contained in:
Roy Qu 2022-10-18 23:22:29 +08:00
parent 29da40bb14
commit eed7fdcf56
5 changed files with 29 additions and 15 deletions

View File

@ -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 - 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: editor tooltip for #include_next is not correctly calculated
- fix: ctrl+click on #include_next header name doesn't open the right file - 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 - 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 Red Panda C++ Version 1.4

View File

@ -1210,9 +1210,11 @@ void Editor::mouseReleaseEvent(QMouseEvent *event)
if (mParser->isIncludeNextLine(s)) { if (mParser->isIncludeNextLine(s)) {
QString filename = mParser->getHeaderFileName(mFilename,s, true); QString filename = mParser->getHeaderFileName(mFilename,s, true);
pMainWindow->openFile(filename); pMainWindow->openFile(filename);
return;
} if (mParser->isIncludeLine(s)) { } if (mParser->isIncludeLine(s)) {
QString filename = mParser->getHeaderFileName(mFilename,s); QString filename = mParser->getHeaderFileName(mFilename,s);
pMainWindow->openFile(filename); pMainWindow->openFile(filename);
return;
} else { } else {
gotoDefinition(p); gotoDefinition(p);
return; return;

View File

@ -1243,6 +1243,8 @@ void MainWindow::openFiles(const QStringList &files)
Editor* MainWindow::openFile(const QString &filename, bool activate, QTabWidget* page) Editor* MainWindow::openFile(const QString &filename, bool activate, QTabWidget* page)
{ {
if (filename.isEmpty())
return nullptr;
Editor* editor = mEditorList->getOpenedEditorByFilename(filename); Editor* editor = mEditorList->getOpenedEditorByFilename(filename);
if (editor!=nullptr) { if (editor!=nullptr) {
if (activate) { if (activate) {

View File

@ -709,7 +709,7 @@ QString CppParser::getHeaderFileName(const QString &relativeTo, const QString &h
QString currentDir = includeTrailingPathDelimiter(extractFileDir(relativeTo)); QString currentDir = includeTrailingPathDelimiter(extractFileDir(relativeTo));
QStringList includes; QStringList includes;
QStringList projectIncludes; QStringList projectIncludes;
bool found; bool found=false;
if (fromNext && mPreprocessor->includePaths().contains(currentDir)) { if (fromNext && mPreprocessor->includePaths().contains(currentDir)) {
foreach(const QString& s, mPreprocessor->includePathList()) { foreach(const QString& s, mPreprocessor->includePathList()) {
if (found) { if (found) {

View File

@ -460,7 +460,7 @@ void CppPreprocessor::handleInclude(const QString &line, bool fromNext)
QString currentDir = includeTrailingPathDelimiter(extractFileDir(file->fileName)); QString currentDir = includeTrailingPathDelimiter(extractFileDir(file->fileName));
QStringList includes; QStringList includes;
QStringList projectIncludes; QStringList projectIncludes;
bool found; bool found=false;
if (fromNext && mIncludePaths.contains(currentDir)) { if (fromNext && mIncludePaths.contains(currentDir)) {
foreach(const QString& s, mIncludePathList) { foreach(const QString& s, mIncludePathList) {
if (found) { if (found) {
@ -499,18 +499,28 @@ void CppPreprocessor::handleInclude(const QString &line, bool fromNext)
void CppPreprocessor::handlePreprocessor(const QString &value) void CppPreprocessor::handlePreprocessor(const QString &value)
{ {
if (value.startsWith("define")) switch(value[0].unicode()) {
handleDefine(value); case 'd':
else if (value.startsWith("undef")) if (value.startsWith("define"))
handleUndefine(value); handleDefine(value);
else if (value.startsWith("if") break;
|| value.startsWith("else") || value.startsWith("elif") case 'e':
|| value.startsWith("endif")) if (value.startsWith("else") || value.startsWith("elif")
handleBranch(value); || value.startsWith("endif"))
else if (value.startsWith("include_next")) handleBranch(value);
handleInclude(value,true); break;
else if (value.startsWith("include")) case 'i':
handleInclude(value); 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) void CppPreprocessor::handleUndefine(const QString &line)