diff --git a/src/app/qt/element/QtCodeSnippet.cpp b/src/app/qt/element/QtCodeSnippet.cpp index e863b31f..299be014 100644 --- a/src/app/qt/element/QtCodeSnippet.cpp +++ b/src/app/qt/element/QtCodeSnippet.cpp @@ -4,6 +4,7 @@ #include #include "utility/messaging/type/MessageShowScope.h" +#include "utility/messaging/type/MessageShowFile.h" #include "utility/text/TextAccess.h" #include "data/location/TokenLocationFile.h" @@ -40,7 +41,7 @@ std::shared_ptr QtCodeSnippet::merged(QtCodeSnippet* a, QtCodeSni code += line; } - std::string title = first->m_title ? first->m_title->text().toStdString() : ""; + std::string title = first->m_titleString; return std::shared_ptr(new QtCodeSnippet( first->getStartLineNumber(), @@ -62,6 +63,7 @@ QtCodeSnippet::QtCodeSnippet( ) : QFrame(file) , m_titleId(titleId) + , m_titleString(title) , m_dots(nullptr) , m_title(nullptr) , m_codeArea(std::make_shared(startLineNumber, code, locationFile, file, this)) @@ -74,7 +76,7 @@ QtCodeSnippet::QtCodeSnippet( layout->setAlignment(Qt::AlignTop); setLayout(layout); - if (title.size()) + if (m_titleString.size()) { QHBoxLayout* titleLayout = new QHBoxLayout(); titleLayout->setMargin(0); @@ -87,7 +89,7 @@ QtCodeSnippet::QtCodeSnippet( m_dots->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac titleLayout->addWidget(m_dots); - m_title = new QPushButton(title.c_str(), this); + m_title = new QPushButton(FilePath(m_titleString).fileName().c_str(), this); m_title->setObjectName("scope_name"); m_title->minimumSizeHint(); // force font loading m_title->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac @@ -139,10 +141,14 @@ bool QtCodeSnippet::isActive() const void QtCodeSnippet::clickedTitle() { - if (m_titleId) + if (m_titleId > 0) { MessageShowScope(m_titleId).dispatch(); } + else + { + MessageShowFile(FilePath(m_titleString), 0, 0).dispatch(); + } } void QtCodeSnippet::updateDots() diff --git a/src/app/qt/element/QtCodeSnippet.h b/src/app/qt/element/QtCodeSnippet.h index 8f0beeb4..55585ff1 100644 --- a/src/app/qt/element/QtCodeSnippet.h +++ b/src/app/qt/element/QtCodeSnippet.h @@ -49,6 +49,7 @@ private: void updateDots(); Id m_titleId; + std::string m_titleString; QPushButton* m_dots; QPushButton* m_title; diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index 898c524a..d2c995a1 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -260,7 +260,6 @@ std::vector CodeController::getSnippetsForFile(std: params.startLineNumber = std::max(1, range.start.row - (range.start.strong ? 0 : snippetExpandRange)); params.endLineNumber = std::min(textAccess->getLineCount(), range.end.row + (range.end.strong ? 0 : snippetExpandRange)); - std::shared_ptr tempFile = m_storageAccess->getTokenLocationsForLinesInFile(file->getFilePath().str(), params.startLineNumber, params.endLineNumber); TokenLocationLine* firstUsedLine = nullptr; @@ -269,9 +268,12 @@ std::vector CodeController::getSnippetsForFile(std: firstUsedLine = tempFile->findTokenLocationLineByNumber(i); } + params.titleId = 0; if (firstUsedLine && firstUsedLine->getTokenLocations().size()) { - m_storageAccess->getTokenLocationOfParentScope(firstUsedLine->getTokenLocations().begin()->second.get())->forEachStartTokenLocation( + m_storageAccess->getTokenLocationOfParentScope( + firstUsedLine->getTokenLocations().begin()->second.get() + )->forEachStartTokenLocation( // this TokenLocationFile only contains a single StartTokenLocation. [&](TokenLocation* location) { params.title = m_storageAccess->getNameHierarchyForNodeWithId(location->getTokenId()).getFullName(); @@ -279,6 +281,10 @@ std::vector CodeController::getSnippetsForFile(std: } ); } + if (!file->isWholeCopy && params.titleId == 0) + { + params.title = file->getFilePath().str(); + } for (const std::string& line: textAccess->getLines(params.startLineNumber, params.endLineNumber)) {