From 14254a2f15216a55994c3176f8eb7366a8a04ad9 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Thu, 4 Nov 2021 22:56:11 +0800 Subject: [PATCH] - fix: Results of "find symbol usage" in project not correctly set in the search result view --- NEWS.md | 1 + RedPandaIDE/cpprefacter.cpp | 50 +++++++++--------------- RedPandaIDE/cpprefacter.h | 6 --- RedPandaIDE/widgets/searchresultview.cpp | 27 +++++++------ RedPandaIDE/widgets/searchresultview.h | 6 +-- 5 files changed, 38 insertions(+), 52 deletions(-) diff --git a/NEWS.md b/NEWS.md index b156d0cc..354302ae 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ Version 0.7.9 - fix: hit info not correctly displayed in the search result view - fix: If find in files found no hits, search result view will not be shown. - fix: wront indents when paste one line content + - fix: Results of "find symbol usage" in project not correctly set in the search result view Version 0.7.8 - enhancement: In problem view's output control, indicates which line is different with the expected diff --git a/RedPandaIDE/cpprefacter.cpp b/RedPandaIDE/cpprefacter.cpp index 2a2c783a..8027fdd1 100644 --- a/RedPandaIDE/cpprefacter.cpp +++ b/RedPandaIDE/cpprefacter.cpp @@ -35,23 +35,33 @@ bool CppRefacter::findOccurence(Editor *editor, const BufferCoord &pos) std::shared_ptr project = pMainWindow->project(); if (editor->inProject() && project) { + PSearchResults results = pMainWindow->searchResultModel()->addSearchResults( + statement->fullName, + SearchFileScope::wholeProject + ); foreach (const PProjectUnit& unit, project->units()) { if (isCfile(unit->fileName()) || isHfile(unit->fileName())) { - findOccurenceInFile( - phrase, - unit->fileName(), - statement, - pos.Line, - editor->parser()); + PSearchResultTreeItem item = findOccurenceInFile( + unit->fileName(), + statement, + editor->parser()); + if (item && !(item->results.isEmpty())) { + results->results.append(item); + } } } } else { - findOccurenceInFile( - phrase, + PSearchResults results = pMainWindow->searchResultModel()->addSearchResults( + statement->fullName, + SearchFileScope::currentFile + ); + PSearchResultTreeItem item = findOccurenceInFile( editor->filename(), statement, - pos.Line, editor->parser()); + if (item && !(item->results.isEmpty())) { + results->results.append(item); + } } pMainWindow->searchResultModel()->notifySearchResultsUpdated(); return true; @@ -241,25 +251,3 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement & realEncoding); } } - -void CppRefacter::findOccurenceInFile( - const QString& phrase, - const QString &filename, - const PStatement &statement, - int line, - const PCppParser &parser) -{ - PSearchResults results = pMainWindow->searchResultModel()->addSearchResults( - phrase, - filename, - line - ); - - PSearchResultTreeItem item = findOccurenceInFile( - filename, - statement, - parser); - if (item && !(item->results.isEmpty())) { - results->results.append(item); - } -} diff --git a/RedPandaIDE/cpprefacter.h b/RedPandaIDE/cpprefacter.h index 44d5ae74..9073f27b 100644 --- a/RedPandaIDE/cpprefacter.h +++ b/RedPandaIDE/cpprefacter.h @@ -19,12 +19,6 @@ public: void renameSymbol(Editor* editor, const BufferCoord& pos, const QString& word, const QString& newWord); signals: private: - void findOccurenceInFile( - const QString& phrase, - const QString& filename, - const PStatement& statement, - int line, - const PCppParser& parser); PSearchResultTreeItem findOccurenceInFile( const QString& filename, const PStatement& statement, diff --git a/RedPandaIDE/widgets/searchresultview.cpp b/RedPandaIDE/widgets/searchresultview.cpp index 5554ed35..4f99dd06 100644 --- a/RedPandaIDE/widgets/searchresultview.cpp +++ b/RedPandaIDE/widgets/searchresultview.cpp @@ -31,15 +31,17 @@ PSearchResults SearchResultModel::addSearchResults(const QString &keyword, SynSe return results; } -PSearchResults SearchResultModel::addSearchResults(const QString &keyword, const QString &filename, int symbolLine) +PSearchResults SearchResultModel::addSearchResults( + const QString& symbolFullname, + SearchFileScope scope) { int index=-1; for (int i=0;isearchType == SearchType::FindOccurences - && results->keyword == keyword - && results->filename == filename - && results->symbolLine == symbolLine) { + && results->scope == scope + && results->keyword == symbolFullname + ) { index=i; break; } @@ -51,10 +53,10 @@ PSearchResults SearchResultModel::addSearchResults(const QString &keyword, const mSearchResults.pop_back(); } PSearchResults results = std::make_shared(); - results->keyword = keyword; - results->filename = filename; - results->symbolLine = symbolLine; + results->keyword = symbolFullname; + results->filename = ""; results->searchType = SearchType::FindOccurences; + results->scope = scope; mSearchResults.push_front(results); mCurrentIndex = 0; return results; @@ -367,10 +369,13 @@ QVariant SearchResultListModel::data(const QModelIndex &index, int role) const return tr("Open Files:") + QString(" \"%1\"").arg(results->keyword); } } else if (results->searchType == SearchType::FindOccurences) { - return tr("References to symbol \'%1\' at '%2':%3") - .arg(results->keyword) - .arg(extractFileName(results->filename)) - .arg(results->symbolLine); + if (results->scope == SearchFileScope::currentFile) { + return tr("Find Usages in Current File: '%1'") + .arg(results->keyword); + } else { + return tr("Find Usages in Project: '%1'") + .arg(results->keyword); + } } } return QVariant(); diff --git a/RedPandaIDE/widgets/searchresultview.h b/RedPandaIDE/widgets/searchresultview.h index 9c9781e1..026c1645 100644 --- a/RedPandaIDE/widgets/searchresultview.h +++ b/RedPandaIDE/widgets/searchresultview.h @@ -35,7 +35,6 @@ struct SearchResults{ SearchFileScope scope; SearchType searchType; QString filename; - int symbolLine; QList results; }; @@ -48,9 +47,8 @@ public: PSearchResults addSearchResults(const QString& keyword,SynSearchOptions options, SearchFileScope scope); PSearchResults addSearchResults( - const QString& keyword, - const QString& filename, - int symbolLine); + const QString& symbolFullname, + SearchFileScope scope); PSearchResults results(int index); void notifySearchResultsUpdated(); int currentIndex() const;