ui: clickable file scope

* When content that is shown in a snippet is located in the file scope, the snippet's title bar displays the file's name. Clicking this name has the same effect as maximizing the file (the file's entire content is shown but the file symbol is not activated).
This commit is contained in:
malte_langkabel
2015-10-15 12:24:24 +02:00
parent 0664f9a81b
commit e1683d047a
3 changed files with 19 additions and 6 deletions
+10 -4
View File
@@ -4,6 +4,7 @@
#include <QPushButton>
#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> 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<QtCodeSnippet>(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<QtCodeArea>(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()
+1
View File
@@ -49,6 +49,7 @@ private:
void updateDots();
Id m_titleId;
std::string m_titleString;
QPushButton* m_dots;
QPushButton* m_title;
@@ -260,7 +260,6 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForFile(std:
params.startLineNumber = std::max<int>(1, range.start.row - (range.start.strong ? 0 : snippetExpandRange));
params.endLineNumber = std::min<int>(textAccess->getLineCount(), range.end.row + (range.end.strong ? 0 : snippetExpandRange));
std::shared_ptr<TokenLocationFile> tempFile =
m_storageAccess->getTokenLocationsForLinesInFile(file->getFilePath().str(), params.startLineNumber, params.endLineNumber);
TokenLocationLine* firstUsedLine = nullptr;
@@ -269,9 +268,12 @@ std::vector<CodeView::CodeSnippetParams> 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<CodeView::CodeSnippetParams> 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))
{