diff --git a/NEWS.md b/NEWS.md index f05a1013..d55e764c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -18,6 +18,7 @@ Version 0.6.0 - implement: open files pasted by clipboard - fix: code fold parsing not correct - enhancement: support #include_next (and clang libc++) + - fix: hide popup windows when the editor is closed Version 0.5.0 - enhancement: support C++ using type alias; diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 12f8e764..d011acaa 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -472,12 +472,6 @@ void Editor::focusOutEvent(QFocusEvent *event) this, &SynEdit::invalidate); } - if (mHeaderCompletionPopup) - mHeaderCompletionPopup->hide(); - if (mCompletionPopup) - mCompletionPopup->hide(); - if (pMainWindow->functionTip()) - pMainWindow->functionTip()->hide(); //pMainWindow->updateClassBrowserForEditor(nullptr); pMainWindow->updateEditorActions(); pMainWindow->updateStatusbarForLineCol(); @@ -1074,6 +1068,16 @@ void Editor::inputMethodEvent(QInputMethodEvent *event) } } +void Editor::closeEvent(QCloseEvent *) +{ + if (mHeaderCompletionPopup) + mHeaderCompletionPopup->hide(); + if (mCompletionPopup) + mCompletionPopup->hide(); + if (pMainWindow->functionTip()) + pMainWindow->functionTip()->hide(); +} + void Editor::copyToClipboard() { if (pSettings->editor().copySizeLimit()) { diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index 138932d5..ea9d4d73 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -289,6 +289,10 @@ protected: // QWidget interface protected: void inputMethodEvent(QInputMethodEvent *) override; + + // QWidget interface +protected: + void closeEvent(QCloseEvent *event) override; }; QString getWordAtPosition(SynEdit* editor, diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 83634581..2be16a47 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -558,8 +558,8 @@ QSet CppParser::getFileUsings(const QString &filename) QString CppParser::getHeaderFileName(const QString &relativeTo, const QString &line) { QMutexLocker locker(&mMutex); - return ::getHeaderFilename(relativeTo, line, mPreprocessor.includePaths(), - mPreprocessor.projectIncludePaths()); + return ::getHeaderFilename(relativeTo, line, mPreprocessor.includePathList(), + mPreprocessor.projectIncludePathList()); } StatementKind CppParser::getKindOfStatement(const PStatement& statement) diff --git a/RedPandaIDE/parser/cpppreprocessor.cpp b/RedPandaIDE/parser/cpppreprocessor.cpp index b0ad374f..e64597ee 100644 --- a/RedPandaIDE/parser/cpppreprocessor.cpp +++ b/RedPandaIDE/parser/cpppreprocessor.cpp @@ -4,6 +4,7 @@ #include #include #include +#include CppPreprocessor::CppPreprocessor() { @@ -214,14 +215,18 @@ void CppPreprocessor::dumpIncludesListTo(const QString &fileName) const void CppPreprocessor::addIncludePath(const QString &fileName) { - mIncludePaths.insert(fileName); - mIncludePathList.append(fileName); + if (!mIncludePaths.contains(fileName)) { + mIncludePaths.insert(fileName); + mIncludePathList.append(fileName); + } } void CppPreprocessor::addProjectIncludePath(const QString &fileName) { - mProjectIncludePaths.insert(fileName); - mProjectIncludeList.append(fileName); + if (!mProjectIncludePaths.contains(fileName)) { + mProjectIncludePaths.insert(fileName); + mProjectIncludePathList.append(fileName); + } } void CppPreprocessor::clearIncludePaths() @@ -233,7 +238,7 @@ void CppPreprocessor::clearIncludePaths() void CppPreprocessor::clearProjectIncludePaths() { mProjectIncludePaths.clear(); - mProjectIncludeList.clear(); + mProjectIncludePathList.clear(); } QString CppPreprocessor::getNextPreprocessor() @@ -356,28 +361,30 @@ void CppPreprocessor::handleInclude(const QString &line, bool fromNext) QString fileName; // Get full header file name QString currentDir = includeTrailingPathDelimiter(extractFileDir(file->fileName)); - QSet includes; - QSet projectIncludes; - if (fromNext && mIncludePaths.contains(currentDir)) { - bool found = false; - foreach(const QString& s, mIncludePathList) { - if (found) - includes.insert(s); - if (s == currentDir) - found = true; + QStringList includes; + QStringList projectIncludes; + bool found; + if (fromNext && mIncludePaths.contains(currentDir)) + found = false; + else + found = true; + foreach(const QString& s, mIncludePathList) { + if (found) { + includes.append(s); } - } else - includes = mIncludePaths; - if (fromNext && mProjectIncludePaths.contains(currentDir)) { - bool found = false; - foreach(const QString& s, mProjectIncludeList) { - if (found) - projectIncludes.insert(s); - if (s == currentDir) - found = true; - } - } else - projectIncludes = mProjectIncludePaths; + if (s == currentDir) + found = true; + } + if (fromNext && mProjectIncludePaths.contains(currentDir)) + found = false; + else + found = true; + foreach(const QString& s, mProjectIncludePathList) { + if (found) + projectIncludes.append(s); + if (s == currentDir) + found = true; + } fileName = getHeaderFilename( file->fileName, line, @@ -403,10 +410,10 @@ void CppPreprocessor::handlePreprocessor(const QString &value) || value.startsWith("else") || value.startsWith("elif") || value.startsWith("endif")) handleBranch(value); - else if (value.startsWith("include")) - handleInclude(value); else if (value.startsWith("include_next")) handleInclude(value,true); + else if (value.startsWith("include")) + handleInclude(value); } void CppPreprocessor::handleUndefine(const QString &line) @@ -1710,6 +1717,16 @@ int CppPreprocessor::evaluateExpression(QString line) return result; } +const QList &CppPreprocessor::projectIncludePathList() const +{ + return mProjectIncludePathList; +} + +const QList &CppPreprocessor::includePathList() const +{ + return mIncludePathList; +} + const DefineMap &CppPreprocessor::hardDefines() const { return mHardDefines; diff --git a/RedPandaIDE/parser/cpppreprocessor.h b/RedPandaIDE/parser/cpppreprocessor.h index 8a2cbf47..2526bb07 100644 --- a/RedPandaIDE/parser/cpppreprocessor.h +++ b/RedPandaIDE/parser/cpppreprocessor.h @@ -76,6 +76,10 @@ public: const DefineMap &hardDefines() const; + const QList &includePathList() const; + + const QList &projectIncludePathList() const; + signals: private: @@ -189,7 +193,7 @@ private: QSet mProjectIncludePaths; //we also need include paths in order (for #include_next) QList mIncludePathList; - QList mProjectIncludeList; + QList mProjectIncludePathList; bool mParseSystem; bool mParseLocal; diff --git a/RedPandaIDE/parser/parserutils.cpp b/RedPandaIDE/parser/parserutils.cpp index 5e599b7a..6ba40616 100644 --- a/RedPandaIDE/parser/parserutils.cpp +++ b/RedPandaIDE/parser/parserutils.cpp @@ -294,7 +294,7 @@ void initParser() } QString getHeaderFilename(const QString &relativeTo, const QString &line, - const QSet& includePaths, const QSet& projectIncludePaths) { + const QStringList& includePaths, const QStringList& projectIncludePaths) { QString result = ""; // Handle <> @@ -341,7 +341,7 @@ QString getLocalHeaderFilename(const QString &relativeTo, const QString &fileNam return ""; } -QString getSystemHeaderFilename(const QString &fileName, const QSet& includePaths) +QString getSystemHeaderFilename(const QString &fileName, const QStringList& includePaths) { // Search compiler include directories diff --git a/RedPandaIDE/parser/parserutils.h b/RedPandaIDE/parser/parserutils.h index a8d95f80..3e3f04de 100644 --- a/RedPandaIDE/parser/parserutils.h +++ b/RedPandaIDE/parser/parserutils.h @@ -196,11 +196,11 @@ extern QSet STLElementMethods; void initParser(); QString getHeaderFilename(const QString& relativeTo, const QString& line, - const QSet& includePaths, const QSet& projectIncludePaths); + const QStringList& includePaths, const QStringList& projectIncludePaths); QString getLocalHeaderFilename(const QString& relativeTo, const QString& fileName); -QString getSystemHeaderFilename(const QString& fileName, const QSet& includePaths); +QString getSystemHeaderFilename(const QString& fileName, const QStringList& includePaths); bool isSystemHeaderFile(const QString& fileName, const QSet& includePaths); bool isHfile(const QString& filename); bool isCfile(const QString& filename); diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index eed5cd7d..829232b1 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -557,16 +557,16 @@ void resetCppParser(std::shared_ptr parser) Settings::PCompilerSet compilerSet = pSettings->compilerSets().defaultSet(); parser->clearIncludePaths(); if (compilerSet) { - for (QString file:compilerSet->CIncludeDirs()) { + foreach (const QString& file,compilerSet->CppIncludeDirs()) { parser->addIncludePath(file); } - for (QString file:compilerSet->CppIncludeDirs()) { + foreach (const QString& file,compilerSet->CIncludeDirs()) { parser->addIncludePath(file); } - for (QString file:compilerSet->defaultCIncludeDirs()) { + foreach (const QString& file,compilerSet->defaultCppIncludeDirs()) { parser->addIncludePath(file); } - for (QString file:compilerSet->defaultCppIncludeDirs()) { + foreach (const QString& file,compilerSet->defaultCIncludeDirs()) { parser->addIncludePath(file); } //TODO: Add default include dirs last, just like gcc does