ui: Display scope name at bottom of snippet if available
* Show scope name at bottom looking like top one * Refactored CodeSnippetParams out of CodeView and use them everywhere * Fixed border radius clipping problem at bottom of file by defining a small padding * Scroll to line number when inserting a scope
This commit is contained in:
@@ -9,13 +9,14 @@
|
||||
#code_file {
|
||||
background-color: <color:code/snippet/background>;
|
||||
border: 2px solid <color:code/file/background>;
|
||||
border-radius: 14px;
|
||||
border-radius: 12px;
|
||||
padding-bottom: 7px;
|
||||
}
|
||||
|
||||
#code_file #title_widget {
|
||||
background-color: <color:code/file/background>;
|
||||
border-top-left-radius: 10px;
|
||||
border-top-right-radius: 10px;
|
||||
border-top-left-radius: 7px;
|
||||
border-top-right-radius: 7px;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
@@ -60,11 +61,6 @@
|
||||
padding-top: 0px;
|
||||
}
|
||||
|
||||
#code_file #code_snippet[isLast=true] {
|
||||
border-bottom-left-radius: 12px;
|
||||
border-bottom-right-radius: 12px;
|
||||
}
|
||||
|
||||
#code_file #code_snippet #scope_name, #code_file #code_snippet #dots {
|
||||
background-color: <color:code/snippet/title/background>;
|
||||
color: <color:code/snippet/title/text>;
|
||||
@@ -92,10 +88,6 @@
|
||||
color: <color:code/snippet/line_number/text>;
|
||||
}
|
||||
|
||||
#code_file #code_snippet[isLast=true] #line_number_area {
|
||||
border-bottom-left-radius: 12px;
|
||||
}
|
||||
|
||||
#code_area {
|
||||
background-color: transparent;
|
||||
color: <color:code/snippet/syntax/normal>;
|
||||
|
||||
@@ -39,6 +39,8 @@ add_files(
|
||||
component/controller/UndoRedoController.cpp
|
||||
component/controller/UndoRedoController.h
|
||||
|
||||
component/view/helper/CodeSnippetParams.cpp
|
||||
component/view/helper/CodeSnippetParams.h
|
||||
component/view/CodeView.cpp
|
||||
component/view/CodeView.h
|
||||
component/view/CompositeView.cpp
|
||||
|
||||
@@ -29,10 +29,10 @@ const uint CodeController::s_lineRadius = 2;
|
||||
void CodeController::handleMessage(MessageActivateAll* message)
|
||||
{
|
||||
std::vector<std::string> errorMessages;
|
||||
std::vector<CodeView::CodeSnippetParams> snippets = getSnippetsForErrorLocations(&errorMessages);
|
||||
std::vector<CodeSnippetParams> snippets = getSnippetsForErrorLocations(&errorMessages);
|
||||
|
||||
StorageStats stats = m_storageAccess->getStorageStats();
|
||||
CodeView::CodeSnippetParams statsSnippet;
|
||||
CodeSnippetParams statsSnippet;
|
||||
|
||||
statsSnippet.startLineNumber = 1;
|
||||
statsSnippet.endLineNumber = 1;
|
||||
@@ -157,9 +157,9 @@ void CodeController::handleMessage(MessageChangeFileView* message)
|
||||
case MessageChangeFileView::FILE_MAXIMIZED:
|
||||
if (message->needsData)
|
||||
{
|
||||
CodeView::CodeSnippetParams params;
|
||||
params.startLineNumber = 0;
|
||||
params.endLineNumber = 0;
|
||||
CodeSnippetParams params;
|
||||
params.startLineNumber = 1;
|
||||
params.refCount = -1;
|
||||
|
||||
std::shared_ptr<TextAccess> textAccess = m_storageAccess->getFileContent(message->filePath);
|
||||
params.code = textAccess->getText();
|
||||
@@ -213,7 +213,7 @@ void CodeController::handleMessage(MessageScrollCode* message)
|
||||
void CodeController::handleMessage(MessageShowErrors* message)
|
||||
{
|
||||
std::vector<std::string> errorMessages;
|
||||
std::vector<CodeView::CodeSnippetParams> snippets = getSnippetsForErrorLocations(&errorMessages);
|
||||
std::vector<CodeSnippetParams> snippets = getSnippetsForErrorLocations(&errorMessages);
|
||||
|
||||
CodeView* view = getView();
|
||||
view->setErrorMessages(errorMessages);
|
||||
@@ -234,7 +234,7 @@ void CodeController::handleMessage(MessageShowScope* message)
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<CodeView::CodeSnippetParams> snippets = getSnippetsForActiveTokenLocations(collection.get(), 0);
|
||||
std::vector<CodeSnippetParams> snippets = getSnippetsForActiveTokenLocations(collection.get(), 0);
|
||||
|
||||
if (snippets.size() != 1)
|
||||
{
|
||||
@@ -260,10 +260,10 @@ void CodeController::showContents(MessageBase* message)
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocations(
|
||||
std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocations(
|
||||
const TokenLocationCollection* collection, Id declarationId
|
||||
) const {
|
||||
std::vector<CodeView::CodeSnippetParams> snippets;
|
||||
std::vector<CodeSnippetParams> snippets;
|
||||
|
||||
collection->forEachTokenLocationFile(
|
||||
[&](std::shared_ptr<TokenLocationFile> file) -> void
|
||||
@@ -281,9 +281,9 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTok
|
||||
|
||||
if (isDeclarationFile || collection->getTokenLocationFileCount() < 5 || file->isWholeCopy)
|
||||
{
|
||||
std::vector<CodeView::CodeSnippetParams> fileSnippets = getSnippetsForActiveTokenLocationsInFile(file);
|
||||
std::vector<CodeSnippetParams> fileSnippets = getSnippetsForActiveTokenLocationsInFile(file);
|
||||
|
||||
for (CodeView::CodeSnippetParams& snippet : fileSnippets)
|
||||
for (CodeSnippetParams& snippet : fileSnippets)
|
||||
{
|
||||
snippet.isDeclaration = isDeclarationFile;
|
||||
}
|
||||
@@ -292,7 +292,7 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTok
|
||||
}
|
||||
else
|
||||
{
|
||||
CodeView::CodeSnippetParams params;
|
||||
CodeSnippetParams params;
|
||||
params.locationFile = file;
|
||||
params.refCount = file->getUnscopedStartTokenLocationCount();
|
||||
params.modificationTime = m_storageAccess->getFileModificationTime(file->getFilePath());
|
||||
@@ -303,19 +303,19 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTok
|
||||
}
|
||||
);
|
||||
|
||||
std::sort(snippets.begin(), snippets.end(), CodeView::CodeSnippetParams::sort);
|
||||
std::sort(snippets.begin(), snippets.end(), CodeSnippetParams::sort);
|
||||
|
||||
return snippets;
|
||||
}
|
||||
|
||||
std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocationsInFile(
|
||||
std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocationsInFile(
|
||||
std::shared_ptr<TokenLocationFile> file
|
||||
) const {
|
||||
std::vector<CodeView::CodeSnippetParams> fileSnippets = getSnippetsForFile(file);
|
||||
std::vector<CodeSnippetParams> fileSnippets = getSnippetsForFile(file);
|
||||
|
||||
if (!file->isWholeCopy)
|
||||
{
|
||||
for (CodeView::CodeSnippetParams& params : fileSnippets)
|
||||
for (CodeSnippetParams& params : fileSnippets)
|
||||
{
|
||||
params.locationFile = m_storageAccess->getTokenLocationsForLinesInFile(
|
||||
file->getFilePath().str(), params.startLineNumber, params.endLineNumber);
|
||||
@@ -325,7 +325,7 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTok
|
||||
return fileSnippets;
|
||||
}
|
||||
|
||||
std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForFile(std::shared_ptr<TokenLocationFile> file) const
|
||||
std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(std::shared_ptr<TokenLocationFile> file) const
|
||||
{
|
||||
std::shared_ptr<TextAccess> textAccess = m_storageAccess->getFileContent(file->getFilePath());
|
||||
|
||||
@@ -365,10 +365,10 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForFile(std:
|
||||
}
|
||||
|
||||
const int snippetExpandRange = ApplicationSettings::getInstance()->getCodeSnippetExpandRange();
|
||||
std::vector<CodeView::CodeSnippetParams> snippets;
|
||||
std::vector<CodeSnippetParams> snippets;
|
||||
for (const SnippetMerger::Range& range: ranges)
|
||||
{
|
||||
CodeView::CodeSnippetParams params;
|
||||
CodeSnippetParams params;
|
||||
params.locationFile = file;
|
||||
params.refCount = file->getUnscopedStartTokenLocationCount();
|
||||
params.startLineNumber = std::max<int>(1, range.start.row - (range.start.strong ? 0 : snippetExpandRange));
|
||||
@@ -402,6 +402,27 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForFile(std:
|
||||
params.title = file->getFilePath().str();
|
||||
}
|
||||
|
||||
|
||||
TokenLocationLine* lastUsedLine = nullptr;
|
||||
for (size_t i = params.endLineNumber; i >= params.startLineNumber && lastUsedLine == nullptr; i--)
|
||||
{
|
||||
lastUsedLine = tempFile->findTokenLocationLineByNumber(i);
|
||||
}
|
||||
|
||||
params.footerId = 0;
|
||||
if (lastUsedLine && lastUsedLine->getTokenLocations().size())
|
||||
{
|
||||
m_storageAccess->getTokenLocationOfParentScope(
|
||||
lastUsedLine->getTokenLocations().begin()->second.get()
|
||||
)->forEachStartTokenLocation( // this TokenLocationFile only contains a single StartTokenLocation.
|
||||
[&](TokenLocation* location)
|
||||
{
|
||||
params.footer = m_storageAccess->getNameHierarchyForNodeWithId(location->getTokenId()).getFullName();
|
||||
params.footerId = location->getId();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
for (const std::string& line: textAccess->getLines(params.startLineNumber, params.endLineNumber))
|
||||
{
|
||||
params.code += line;
|
||||
@@ -449,17 +470,17 @@ std::shared_ptr<SnippetMerger> CodeController::buildMergerHierarchy(
|
||||
return currentMerger;
|
||||
}
|
||||
|
||||
std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForErrorLocations(
|
||||
std::vector<CodeSnippetParams> CodeController::getSnippetsForErrorLocations(
|
||||
std::vector<std::string>* errorMessages)
|
||||
const {
|
||||
TokenLocationCollection errorCollection = m_storageAccess->getErrorTokenLocations(errorMessages);
|
||||
|
||||
std::vector<CodeView::CodeSnippetParams> snippets;
|
||||
std::vector<CodeSnippetParams> snippets;
|
||||
|
||||
errorCollection.forEachTokenLocationFile(
|
||||
[&](std::shared_ptr<TokenLocationFile> file) -> void
|
||||
{
|
||||
std::vector<CodeView::CodeSnippetParams> fileSnippets = getSnippetsForFile(file);
|
||||
std::vector<CodeSnippetParams> fileSnippets = getSnippetsForFile(file);
|
||||
snippets.insert(snippets.end(), fileSnippets.begin(), fileSnippets.end());
|
||||
}
|
||||
);
|
||||
|
||||
@@ -56,15 +56,15 @@ private:
|
||||
CodeView* getView();
|
||||
void showContents(MessageBase* message);
|
||||
|
||||
std::vector<CodeView::CodeSnippetParams> getSnippetsForActiveTokenLocations(
|
||||
std::vector<CodeSnippetParams> getSnippetsForActiveTokenLocations(
|
||||
const TokenLocationCollection* collection, Id declarationId) const;
|
||||
std::vector<CodeView::CodeSnippetParams> getSnippetsForActiveTokenLocationsInFile(
|
||||
std::vector<CodeSnippetParams> getSnippetsForActiveTokenLocationsInFile(
|
||||
std::shared_ptr<TokenLocationFile>) const;
|
||||
std::vector<CodeView::CodeSnippetParams> getSnippetsForFile(std::shared_ptr<TokenLocationFile> file) const;
|
||||
std::vector<CodeSnippetParams> getSnippetsForFile(std::shared_ptr<TokenLocationFile> file) const;
|
||||
std::shared_ptr<SnippetMerger> buildMergerHierarchy(
|
||||
TokenLocation* location, SnippetMerger& fileScopedMerger, std::map<int, std::shared_ptr<SnippetMerger>>& mergers) const;
|
||||
|
||||
std::vector<CodeView::CodeSnippetParams> getSnippetsForErrorLocations(std::vector<std::string>* errorMessages) const;
|
||||
std::vector<CodeSnippetParams> getSnippetsForErrorLocations(std::vector<std::string>* errorMessages) const;
|
||||
|
||||
std::vector<std::string> getProjectDescription(TokenLocationFile* locationFile) const;
|
||||
|
||||
|
||||
@@ -3,71 +3,6 @@
|
||||
#include "component/controller/CodeController.h"
|
||||
#include "utility/file/FileSystem.h"
|
||||
|
||||
CodeView::CodeSnippetParams::CodeSnippetParams()
|
||||
: startLineNumber(0)
|
||||
, endLineNumber(0)
|
||||
, titleId(0)
|
||||
, locationFile()
|
||||
, refCount(0)
|
||||
, isActive(false)
|
||||
, isDeclaration(false)
|
||||
, isCollapsed(false)
|
||||
{
|
||||
}
|
||||
|
||||
bool CodeView::CodeSnippetParams::sort(const CodeSnippetParams& a, const CodeSnippetParams& b)
|
||||
{
|
||||
// sort active snippet first
|
||||
if (a.isActive && !b.isActive)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (!a.isActive && b.isActive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// sort declarations
|
||||
if (a.isDeclaration && !b.isDeclaration)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (!a.isDeclaration && b.isDeclaration)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// sort whole files
|
||||
if (a.locationFile->isWholeCopy && !b.locationFile->isWholeCopy)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (!a.locationFile->isWholeCopy && b.locationFile->isWholeCopy)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const FilePath& aFilePath = a.locationFile->getFilePath();
|
||||
const FilePath& bFilePath = b.locationFile->getFilePath();
|
||||
|
||||
// different files
|
||||
if (aFilePath != bFilePath)
|
||||
{
|
||||
// first header
|
||||
if (aFilePath.withoutExtension() == bFilePath.withoutExtension())
|
||||
{
|
||||
return aFilePath.extension() > bFilePath.extension();
|
||||
}
|
||||
// alphabetical filepath without extension
|
||||
else
|
||||
{
|
||||
return aFilePath.withoutExtension().fileName() < bFilePath.withoutExtension().fileName();
|
||||
}
|
||||
}
|
||||
|
||||
return a.startLineNumber < b.startLineNumber;
|
||||
}
|
||||
|
||||
CodeView::CodeView(ViewLayout* viewLayout)
|
||||
: View(viewLayout)
|
||||
{
|
||||
|
||||
@@ -3,14 +3,15 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
#include "component/view/helper/CodeSnippetParams.h"
|
||||
#include "component/view/View.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "utility/TimePoint.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class CodeController;
|
||||
|
||||
class CodeView: public View
|
||||
class CodeView
|
||||
: public View
|
||||
{
|
||||
public:
|
||||
enum FileState
|
||||
@@ -20,31 +21,6 @@ public:
|
||||
FILE_MAXIMIZED
|
||||
};
|
||||
|
||||
struct CodeSnippetParams
|
||||
{
|
||||
CodeSnippetParams();
|
||||
|
||||
// comparefunction for snippetsorting
|
||||
static bool sort(const CodeSnippetParams& a, const CodeSnippetParams& b);
|
||||
|
||||
uint startLineNumber;
|
||||
uint endLineNumber;
|
||||
|
||||
std::string title;
|
||||
std::string code;
|
||||
|
||||
Id titleId;
|
||||
TimePoint modificationTime;
|
||||
|
||||
std::shared_ptr<TokenLocationFile> locationFile;
|
||||
|
||||
int refCount;
|
||||
|
||||
bool isActive;
|
||||
bool isDeclaration;
|
||||
bool isCollapsed;
|
||||
};
|
||||
|
||||
CodeView(ViewLayout* viewLayout);
|
||||
virtual ~CodeView();
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#include "component/view/helper/CodeSnippetParams.h"
|
||||
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
|
||||
CodeSnippetParams::CodeSnippetParams()
|
||||
: startLineNumber(0)
|
||||
, endLineNumber(0)
|
||||
, titleId(0)
|
||||
, footerId(0)
|
||||
, locationFile()
|
||||
, refCount(0)
|
||||
, isActive(false)
|
||||
, isDeclaration(false)
|
||||
, isCollapsed(false)
|
||||
{
|
||||
}
|
||||
|
||||
bool CodeSnippetParams::sort(const CodeSnippetParams& a, const CodeSnippetParams& b)
|
||||
{
|
||||
// sort active snippet first
|
||||
if (a.isActive && !b.isActive)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (!a.isActive && b.isActive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// sort declarations
|
||||
if (a.isDeclaration && !b.isDeclaration)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (!a.isDeclaration && b.isDeclaration)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// sort whole files
|
||||
if (a.locationFile->isWholeCopy && !b.locationFile->isWholeCopy)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (!a.locationFile->isWholeCopy && b.locationFile->isWholeCopy)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const FilePath& aFilePath = a.locationFile->getFilePath();
|
||||
const FilePath& bFilePath = b.locationFile->getFilePath();
|
||||
|
||||
// different files
|
||||
if (aFilePath != bFilePath)
|
||||
{
|
||||
// first header
|
||||
if (aFilePath.withoutExtension() == bFilePath.withoutExtension())
|
||||
{
|
||||
return aFilePath.extension() > bFilePath.extension();
|
||||
}
|
||||
// alphabetical filepath without extension
|
||||
else
|
||||
{
|
||||
return aFilePath.withoutExtension().fileName() < bFilePath.withoutExtension().fileName();
|
||||
}
|
||||
}
|
||||
|
||||
return a.startLineNumber < b.startLineNumber;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef CODE_SNIPPET_PARAMS_H
|
||||
#define CODE_SNIPPET_PARAMS_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "utility/TimePoint.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class TokenLocationFile;
|
||||
|
||||
struct CodeSnippetParams
|
||||
{
|
||||
CodeSnippetParams();
|
||||
|
||||
// comparefunction for snippetsorting
|
||||
static bool sort(const CodeSnippetParams& a, const CodeSnippetParams& b);
|
||||
|
||||
uint startLineNumber;
|
||||
uint endLineNumber;
|
||||
|
||||
std::string title;
|
||||
std::string footer;
|
||||
std::string code;
|
||||
|
||||
Id titleId;
|
||||
Id footerId;
|
||||
TimePoint modificationTime;
|
||||
|
||||
std::shared_ptr<TokenLocationFile> locationFile;
|
||||
|
||||
int refCount;
|
||||
|
||||
bool isActive;
|
||||
bool isDeclaration;
|
||||
bool isCollapsed;
|
||||
};
|
||||
|
||||
#endif // CODE_SNIPPET_PARAMS_H
|
||||
@@ -255,18 +255,21 @@ void QtCodeArea::setIsActiveFile(bool isActiveFile)
|
||||
m_isActiveFile = isActiveFile;
|
||||
}
|
||||
|
||||
QRectF QtCodeArea::getFirstActiveLineRect() const
|
||||
uint QtCodeArea::getFirstActiveLineNumber() const
|
||||
{
|
||||
int lineNumber = 0;
|
||||
for (const Annotation& annotation : m_annotations)
|
||||
{
|
||||
if (annotation.isActive)
|
||||
{
|
||||
lineNumber = annotation.startLine;
|
||||
break;
|
||||
return annotation.startLine;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QRectF QtCodeArea::getLineRectForLineNumber(uint lineNumber) const
|
||||
{
|
||||
QTextBlock block = document()->findBlockByLineNumber(lineNumber - m_startLineNumber);
|
||||
return blockBoundingGeometry(block);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,8 @@ public:
|
||||
|
||||
void setIsActiveFile(bool isActiveFile);
|
||||
|
||||
QRectF getFirstActiveLineRect() const;
|
||||
uint getFirstActiveLineNumber() const;
|
||||
QRectF getLineRectForLineNumber(uint lineNumber) const;
|
||||
|
||||
std::string getCode() const;
|
||||
|
||||
|
||||
@@ -102,10 +102,6 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeFileList* parent)
|
||||
connect(m_snippetButton, SIGNAL(clicked()), this, SLOT(clickedSnippetButton()));
|
||||
connect(m_maximizeButton, SIGNAL(clicked()), this, SLOT(clickedMaximizeButton()));
|
||||
|
||||
m_minimizePlaceholder = new QWidget(this);
|
||||
m_minimizePlaceholder->setMinimumHeight(5);
|
||||
layout->addWidget(m_minimizePlaceholder);
|
||||
|
||||
m_snippetLayout = new QVBoxLayout();
|
||||
layout->addLayout(m_snippetLayout);
|
||||
|
||||
@@ -147,22 +143,15 @@ const std::vector<std::string>& QtCodeFile::getErrorMessages() const
|
||||
return m_parent->getErrorMessages();
|
||||
}
|
||||
|
||||
void QtCodeFile::addCodeSnippet(
|
||||
uint startLineNumber,
|
||||
const std::string& title,
|
||||
Id titleId,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
int refCount
|
||||
){
|
||||
void QtCodeFile::addCodeSnippet(const CodeSnippetParams& params)
|
||||
{
|
||||
m_locationFile.reset();
|
||||
|
||||
std::shared_ptr<QtCodeSnippet> snippet(
|
||||
new QtCodeSnippet(startLineNumber, title, titleId, code, locationFile, this));
|
||||
std::shared_ptr<QtCodeSnippet> snippet(new QtCodeSnippet(params, this));
|
||||
|
||||
m_snippetLayout->addWidget(snippet.get());
|
||||
|
||||
if (locationFile->isWholeCopy)
|
||||
if (params.locationFile->isWholeCopy)
|
||||
{
|
||||
snippet->setProperty("isFirst", true);
|
||||
snippet->setProperty("isLast", true);
|
||||
@@ -174,7 +163,7 @@ void QtCodeFile::addCodeSnippet(
|
||||
}
|
||||
|
||||
setMaximized();
|
||||
if (refCount != -1)
|
||||
if (params.refCount != -1)
|
||||
{
|
||||
updateRefCount(0);
|
||||
}
|
||||
@@ -184,21 +173,14 @@ void QtCodeFile::addCodeSnippet(
|
||||
m_snippets.push_back(snippet);
|
||||
|
||||
updateSnippets();
|
||||
updateRefCount(refCount);
|
||||
updateRefCount(params.refCount);
|
||||
}
|
||||
|
||||
QtCodeSnippet* QtCodeFile::insertCodeSnippet(
|
||||
uint startLineNumber,
|
||||
const std::string& title,
|
||||
Id titleId,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
int refCount
|
||||
){
|
||||
QtCodeSnippet* QtCodeFile::insertCodeSnippet(const CodeSnippetParams& params)
|
||||
{
|
||||
m_locationFile.reset();
|
||||
|
||||
std::shared_ptr<QtCodeSnippet> snippet(
|
||||
new QtCodeSnippet(startLineNumber, title, titleId, code, locationFile, this));
|
||||
std::shared_ptr<QtCodeSnippet> snippet(new QtCodeSnippet(params, this));
|
||||
|
||||
size_t i = 0;
|
||||
while (i < m_snippets.size())
|
||||
@@ -232,7 +214,7 @@ QtCodeSnippet* QtCodeFile::insertCodeSnippet(
|
||||
m_snippets.insert(m_snippets.begin() + i, snippet);
|
||||
|
||||
updateSnippets();
|
||||
updateRefCount(refCount);
|
||||
updateRefCount(params.refCount);
|
||||
|
||||
return snippet.get();
|
||||
}
|
||||
@@ -325,8 +307,6 @@ void QtCodeFile::setMinimized()
|
||||
m_snippetButton->setEnabled(true);
|
||||
}
|
||||
m_maximizeButton->setEnabled(true);
|
||||
|
||||
m_minimizePlaceholder->show();
|
||||
}
|
||||
|
||||
void QtCodeFile::setSnippets()
|
||||
@@ -344,8 +324,6 @@ void QtCodeFile::setSnippets()
|
||||
m_minimizeButton->setEnabled(true);
|
||||
m_snippetButton->setEnabled(false);
|
||||
m_maximizeButton->setEnabled(true);
|
||||
|
||||
m_minimizePlaceholder->hide();
|
||||
}
|
||||
|
||||
void QtCodeFile::setMaximized()
|
||||
@@ -366,8 +344,6 @@ void QtCodeFile::setMaximized()
|
||||
m_snippetButton->setEnabled(true);
|
||||
}
|
||||
m_maximizeButton->setEnabled(false);
|
||||
|
||||
m_minimizePlaceholder->hide();
|
||||
}
|
||||
|
||||
void QtCodeFile::clickedTitleBar()
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "utility/messaging/type/MessageWindowFocus.h"
|
||||
#include "qt/utility/QtThreadedFunctor.h"
|
||||
|
||||
#include "component/view/helper/CodeSnippetParams.h"
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QtCodeFileList;
|
||||
@@ -40,23 +42,8 @@ public:
|
||||
const std::vector<Id>& getFocusedTokenIds() const;
|
||||
const std::vector<std::string>& getErrorMessages() const;
|
||||
|
||||
void addCodeSnippet(
|
||||
uint startLineNumber,
|
||||
const std::string& title,
|
||||
Id titleId,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
int refCount
|
||||
);
|
||||
|
||||
QtCodeSnippet* insertCodeSnippet(
|
||||
uint startLineNumber,
|
||||
const std::string& title,
|
||||
Id titleId,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
int refCount
|
||||
);
|
||||
void addCodeSnippet(const CodeSnippetParams& params);
|
||||
QtCodeSnippet* insertCodeSnippet(const CodeSnippetParams& params);
|
||||
|
||||
QtCodeSnippet* findFirstActiveSnippet() const;
|
||||
bool isCollapsedActiveFile() const;
|
||||
@@ -104,7 +91,6 @@ private:
|
||||
QVBoxLayout* m_snippetLayout;
|
||||
std::vector<std::shared_ptr<QtCodeSnippet>> m_snippets;
|
||||
std::shared_ptr<QtCodeSnippet> m_fileSnippet;
|
||||
QWidget* m_minimizePlaceholder;
|
||||
|
||||
const FilePath m_filePath;
|
||||
TimePoint m_modificationTime;
|
||||
|
||||
@@ -33,7 +33,7 @@ QtCodeFileList::QtCodeFileList(QWidget* parent)
|
||||
setWidget(m_frame.get());
|
||||
|
||||
connect(this->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(scrolled(int)));
|
||||
connect(this, SIGNAL(shouldScrollToSnippet(QtCodeSnippet*)), this, SLOT(scrollToSnippet(QtCodeSnippet*)), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(shouldScrollToSnippet(QtCodeSnippet*, uint)), this, SLOT(scrollToSnippet(QtCodeSnippet*, uint)), Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
QtCodeFileList::~QtCodeFileList()
|
||||
@@ -46,27 +46,21 @@ QSize QtCodeFileList::sizeHint() const
|
||||
}
|
||||
|
||||
void QtCodeFileList::addCodeSnippet(
|
||||
uint startLineNumber,
|
||||
const std::string& title,
|
||||
Id titleId,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
int refCount,
|
||||
TimePoint modificationTime,
|
||||
const CodeSnippetParams& params,
|
||||
bool insert
|
||||
){
|
||||
QtCodeFile* file = getFile(locationFile->getFilePath());
|
||||
QtCodeFile* file = getFile(params.locationFile->getFilePath());
|
||||
|
||||
if (insert)
|
||||
{
|
||||
QtCodeSnippet* snippet = file->insertCodeSnippet(startLineNumber, title, titleId, code, locationFile, refCount);
|
||||
emit shouldScrollToSnippet(snippet);
|
||||
QtCodeSnippet* snippet = file->insertCodeSnippet(params);
|
||||
emit shouldScrollToSnippet(snippet, params.startLineNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
file->addCodeSnippet(startLineNumber, title, titleId, code, locationFile, refCount);
|
||||
file->addCodeSnippet(params);
|
||||
}
|
||||
file->setModificationTime(modificationTime);
|
||||
file->setModificationTime(params.modificationTime);
|
||||
}
|
||||
|
||||
void QtCodeFileList::addFile(std::shared_ptr<TokenLocationFile> locationFile, int refCount, TimePoint modificationTime)
|
||||
@@ -136,7 +130,7 @@ void QtCodeFileList::showFirstActiveSnippet(bool scrollTo)
|
||||
|
||||
if (scrollTo)
|
||||
{
|
||||
emit shouldScrollToSnippet(snippet);
|
||||
emit shouldScrollToSnippet(snippet, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,9 +201,17 @@ void QtCodeFileList::scrolled(int value)
|
||||
MessageScrollCode(value).dispatch();
|
||||
}
|
||||
|
||||
void QtCodeFileList::scrollToSnippet(QtCodeSnippet* snippet)
|
||||
void QtCodeFileList::scrollToSnippet(QtCodeSnippet* snippet, uint lineNumber)
|
||||
{
|
||||
this->ensureWidgetVisibleAnimated(snippet, snippet->getFirstActiveLineRect());
|
||||
if (lineNumber == 0)
|
||||
{
|
||||
lineNumber = snippet->getFirstActiveLineNumber();
|
||||
}
|
||||
|
||||
if (lineNumber)
|
||||
{
|
||||
this->ensureWidgetVisibleAnimated(snippet, snippet->getLineRectForLineNumber(lineNumber));
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeFileList::setValue()
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "utility/TimePoint.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
#include "component/view/helper/CodeSnippetParams.h"
|
||||
|
||||
class QtCodeFile;
|
||||
class QtCodeSnippet;
|
||||
class TokenLocationFile;
|
||||
@@ -21,7 +23,7 @@ class QtCodeFileList
|
||||
Q_OBJECT
|
||||
|
||||
signals:
|
||||
void shouldScrollToSnippet(QtCodeSnippet* widget);
|
||||
void shouldScrollToSnippet(QtCodeSnippet* widget, uint lineNumber);
|
||||
|
||||
public:
|
||||
QtCodeFileList(QWidget* parent = 0);
|
||||
@@ -29,17 +31,7 @@ public:
|
||||
|
||||
virtual QSize sizeHint() const;
|
||||
|
||||
void addCodeSnippet(
|
||||
uint startLineNumber,
|
||||
const std::string& title,
|
||||
Id titleId,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
int refCount,
|
||||
TimePoint modificationTime,
|
||||
bool insert = false
|
||||
);
|
||||
|
||||
void addCodeSnippet(const CodeSnippetParams& params, bool insert = false);
|
||||
void addFile(std::shared_ptr<TokenLocationFile> locationFile, int refCount, TimePoint modificationTime);
|
||||
|
||||
void clearCodeSnippets();
|
||||
@@ -70,7 +62,7 @@ public:
|
||||
|
||||
private slots:
|
||||
void scrolled(int value);
|
||||
void scrollToSnippet(QtCodeSnippet* snippet);
|
||||
void scrollToSnippet(QtCodeSnippet* snippet, uint lineNumber);
|
||||
void setValue();
|
||||
|
||||
private:
|
||||
|
||||
@@ -44,32 +44,27 @@ std::shared_ptr<QtCodeSnippet> QtCodeSnippet::merged(QtCodeSnippet* a, QtCodeSni
|
||||
}
|
||||
code += secondCode.substr(secondCodeStartIndex, secondCode.npos);
|
||||
|
||||
std::string title = first->m_titleString;
|
||||
CodeSnippetParams params;
|
||||
params.startLineNumber = first->getStartLineNumber();
|
||||
params.title = first->m_titleString;
|
||||
params.titleId = first->m_titleId;
|
||||
params.footer = second->m_footerString;
|
||||
params.footerId = second->m_footerId;
|
||||
params.code = code;
|
||||
params.locationFile = locationFile;
|
||||
|
||||
return std::shared_ptr<QtCodeSnippet>(new QtCodeSnippet(
|
||||
first->getStartLineNumber(),
|
||||
title,
|
||||
first->m_titleId,
|
||||
code,
|
||||
locationFile,
|
||||
file
|
||||
));
|
||||
return std::shared_ptr<QtCodeSnippet>(new QtCodeSnippet(params, file));
|
||||
}
|
||||
|
||||
QtCodeSnippet::QtCodeSnippet(
|
||||
uint startLineNumber,
|
||||
const std::string& title,
|
||||
Id titleId,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
QtCodeFile* file
|
||||
)
|
||||
QtCodeSnippet::QtCodeSnippet(const CodeSnippetParams& params, QtCodeFile* file)
|
||||
: QFrame(file)
|
||||
, m_titleId(titleId)
|
||||
, m_titleString(title)
|
||||
, m_dots(nullptr)
|
||||
, m_titleId(params.titleId)
|
||||
, m_titleString(params.title)
|
||||
, m_footerId(params.footerId)
|
||||
, m_footerString(params.footer)
|
||||
, m_title(nullptr)
|
||||
, m_codeArea(std::make_shared<QtCodeArea>(startLineNumber, code, locationFile, file, this))
|
||||
, m_footer(nullptr)
|
||||
, m_codeArea(std::make_shared<QtCodeArea>(params.startLineNumber, params.code, params.locationFile, file, this))
|
||||
{
|
||||
setObjectName("code_snippet");
|
||||
|
||||
@@ -81,28 +76,20 @@ QtCodeSnippet::QtCodeSnippet(
|
||||
|
||||
if (m_titleString.size())
|
||||
{
|
||||
QHBoxLayout* titleLayout = new QHBoxLayout();
|
||||
titleLayout->setMargin(0);
|
||||
titleLayout->setSpacing(0);
|
||||
titleLayout->setAlignment(Qt::AlignLeft);
|
||||
layout->addLayout(titleLayout);
|
||||
|
||||
m_dots = new QPushButton(this);
|
||||
m_dots->setObjectName("dots");
|
||||
m_dots->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
||||
titleLayout->addWidget(m_dots);
|
||||
|
||||
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
|
||||
m_title->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
titleLayout->addWidget(m_title);
|
||||
|
||||
m_title = createScopeLine(layout);
|
||||
m_title->setText(FilePath(m_titleString).fileName().c_str());
|
||||
connect(m_title, SIGNAL(clicked()), this, SLOT(clickedTitle()));
|
||||
}
|
||||
|
||||
layout->addWidget(m_codeArea.get());
|
||||
|
||||
if (m_footerString.size())
|
||||
{
|
||||
m_footer = createScopeLine(layout);
|
||||
m_footer->setText(FilePath(m_footerString).fileName().c_str());
|
||||
connect(m_footer, SIGNAL(clicked()), this, SLOT(clickedFooter()));
|
||||
}
|
||||
|
||||
updateDots();
|
||||
}
|
||||
|
||||
@@ -152,9 +139,14 @@ void QtCodeSnippet::setIsActiveFile(bool isActiveFile)
|
||||
m_codeArea->setIsActiveFile(isActiveFile);
|
||||
}
|
||||
|
||||
QRectF QtCodeSnippet::getFirstActiveLineRect() const
|
||||
uint QtCodeSnippet::getFirstActiveLineNumber() const
|
||||
{
|
||||
return m_codeArea->getFirstActiveLineRect();
|
||||
return m_codeArea->getFirstActiveLineNumber();
|
||||
}
|
||||
|
||||
QRectF QtCodeSnippet::getLineRectForLineNumber(uint lineNumber) const
|
||||
{
|
||||
return m_codeArea->getLineRectForLineNumber(lineNumber);
|
||||
}
|
||||
|
||||
std::string QtCodeSnippet::getCode() const
|
||||
@@ -183,13 +175,43 @@ void QtCodeSnippet::clickedTitle()
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeSnippet::clickedFooter()
|
||||
{
|
||||
if (m_footerId > 0)
|
||||
{
|
||||
MessageShowScope(m_footerId).dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
QPushButton* QtCodeSnippet::createScopeLine(QBoxLayout* layout)
|
||||
{
|
||||
QHBoxLayout* lineLayout = new QHBoxLayout();
|
||||
lineLayout->setMargin(0);
|
||||
lineLayout->setSpacing(0);
|
||||
lineLayout->setAlignment(Qt::AlignLeft);
|
||||
layout->addLayout(lineLayout);
|
||||
|
||||
QPushButton* dots = new QPushButton(this);
|
||||
dots->setObjectName("dots");
|
||||
dots->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
||||
lineLayout->addWidget(dots);
|
||||
m_dots.push_back(dots);
|
||||
|
||||
QPushButton* line = new QPushButton(this);
|
||||
line->setObjectName("scope_name");
|
||||
line->minimumSizeHint(); // force font loading
|
||||
line->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
||||
line->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
lineLayout->addWidget(line);
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
void QtCodeSnippet::updateDots()
|
||||
{
|
||||
if (!m_dots)
|
||||
for (QPushButton* dots : m_dots)
|
||||
{
|
||||
return;
|
||||
dots->setText(QString::fromStdString(std::string(lineNumberDigits(), '.')));
|
||||
dots->setMinimumWidth(m_codeArea->lineNumberAreaWidth());
|
||||
}
|
||||
|
||||
m_dots->setText(QString::fromStdString(std::string(lineNumberDigits(), '.')));
|
||||
m_dots->setMinimumWidth(m_codeArea->lineNumberAreaWidth());
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
|
||||
#include "qt/element/QtCodeArea.h"
|
||||
|
||||
#include "component/view/helper/CodeSnippetParams.h"
|
||||
|
||||
class QBoxLayout;
|
||||
class QPushButton;
|
||||
class QtCodeFile;
|
||||
class TokenLocationFile;
|
||||
@@ -22,14 +25,7 @@ class QtCodeSnippet
|
||||
public:
|
||||
static std::shared_ptr<QtCodeSnippet> merged(QtCodeSnippet* a, QtCodeSnippet* b, QtCodeFile* file);
|
||||
|
||||
QtCodeSnippet(
|
||||
uint startLineNumber,
|
||||
const std::string& title,
|
||||
Id titleId,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
QtCodeFile* file
|
||||
);
|
||||
QtCodeSnippet(const CodeSnippetParams& params, QtCodeFile* file);
|
||||
virtual ~QtCodeSnippet();
|
||||
|
||||
QtCodeFile* getFile() const;
|
||||
@@ -46,7 +42,8 @@ public:
|
||||
|
||||
void setIsActiveFile(bool isActiveFile);
|
||||
|
||||
QRectF getFirstActiveLineRect() const;
|
||||
uint getFirstActiveLineNumber() const;
|
||||
QRectF getLineRectForLineNumber(uint lineNumber) const;
|
||||
|
||||
std::string getCode() const;
|
||||
|
||||
@@ -55,15 +52,22 @@ protected:
|
||||
|
||||
private slots:
|
||||
void clickedTitle();
|
||||
void clickedFooter();
|
||||
|
||||
private:
|
||||
QPushButton* createScopeLine(QBoxLayout* layout);
|
||||
void updateDots();
|
||||
|
||||
Id m_titleId;
|
||||
std::string m_titleString;
|
||||
|
||||
QPushButton* m_dots;
|
||||
Id m_footerId;
|
||||
std::string m_footerString;
|
||||
|
||||
std::vector<QPushButton*> m_dots;
|
||||
|
||||
QPushButton* m_title;
|
||||
QPushButton* m_footer;
|
||||
std::shared_ptr<QtCodeArea> m_codeArea;
|
||||
};
|
||||
|
||||
|
||||
@@ -127,15 +127,7 @@ void QtCodeView::doShowCodeSnippets(const std::vector<CodeSnippetParams>& snippe
|
||||
}
|
||||
else
|
||||
{
|
||||
m_widget->addCodeSnippet(
|
||||
params.startLineNumber,
|
||||
params.title,
|
||||
params.titleId,
|
||||
params.code,
|
||||
params.locationFile,
|
||||
params.refCount,
|
||||
params.modificationTime
|
||||
);
|
||||
m_widget->addCodeSnippet(params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,16 +138,7 @@ void QtCodeView::doAddCodeSnippets(const std::vector<CodeSnippetParams>& snippet
|
||||
{
|
||||
for (const CodeSnippetParams& params : snippets)
|
||||
{
|
||||
m_widget->addCodeSnippet(
|
||||
params.startLineNumber,
|
||||
params.title,
|
||||
params.titleId,
|
||||
params.code,
|
||||
params.locationFile,
|
||||
params.refCount,
|
||||
params.modificationTime,
|
||||
insert
|
||||
);
|
||||
m_widget->addCodeSnippet(params, insert);
|
||||
}
|
||||
|
||||
setStyleSheet(); // so property "isLast" of QtCodeSnippet is computed correctly
|
||||
@@ -165,7 +148,7 @@ void QtCodeView::doAddCodeSnippets(const std::vector<CodeSnippetParams>& snippet
|
||||
|
||||
void QtCodeView::doShowCodeFile(const CodeSnippetParams& params)
|
||||
{
|
||||
m_widget->addCodeSnippet(1, params.title, 0, params.code, params.locationFile, -1, params.modificationTime);
|
||||
m_widget->addCodeSnippet(params);
|
||||
}
|
||||
|
||||
void QtCodeView::doSetFileState(const FilePath filePath, FileState state)
|
||||
|
||||
Reference in New Issue
Block a user