ui: Improved scrolling and layouting in QtCodeView and colored locations of active TokenId differently
This commit is contained in:
@@ -29,6 +29,7 @@ void CodeController::setActiveTokenId(Id id)
|
||||
collection.forEachTokenLocation([&] (TokenLocation* tokenLocation) -> void {
|
||||
if (tokenLocation->isStartTokenLocation())
|
||||
{
|
||||
CodeView::CodeSnippetParams params;
|
||||
const std::string filePath = tokenLocation->getFilePath();
|
||||
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(filePath);
|
||||
|
||||
@@ -37,14 +38,17 @@ void CodeController::setActiveTokenId(Id id)
|
||||
textAccess->getLineCount(), tokenLocation->getEndTokenLocation()->getLineNumber() + lineRadius
|
||||
);
|
||||
|
||||
std::string text;
|
||||
for (std::string line: textAccess->getLines(firstLineNumber, lastLineNumber))
|
||||
{
|
||||
text += line;
|
||||
params.code += line;
|
||||
}
|
||||
|
||||
TokenLocationFile tokenLocationFile = m_locationAccess->getTokenLocationsForLinesInFile(filePath, firstLineNumber, lastLineNumber);
|
||||
getView()->addCodeSnippet(text, tokenLocationFile, firstLineNumber);
|
||||
params.startLineNumber = firstLineNumber;
|
||||
params.locationFile =
|
||||
m_locationAccess->getTokenLocationsForLinesInFile(filePath, firstLineNumber, lastLineNumber);
|
||||
params.activeTokenId = id;
|
||||
|
||||
getView()->addCodeSnippet(params);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
#include "component/controller/CodeController.h"
|
||||
|
||||
CodeView::CodeSnippetParams::CodeSnippetParams()
|
||||
: locationFile("")
|
||||
{
|
||||
}
|
||||
|
||||
CodeView::CodeView(ViewLayout* viewLayout)
|
||||
: View(viewLayout, Vec2i(100, 100))
|
||||
{
|
||||
|
||||
@@ -2,19 +2,30 @@
|
||||
#define CODE_VIEW_H
|
||||
|
||||
#include "component/view/View.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class CodeController;
|
||||
class TokenLocationFile;
|
||||
|
||||
class CodeView: public View
|
||||
{
|
||||
public:
|
||||
struct CodeSnippetParams
|
||||
{
|
||||
CodeSnippetParams();
|
||||
|
||||
std::string code;
|
||||
TokenLocationFile locationFile;
|
||||
int startLineNumber;
|
||||
Id activeTokenId;
|
||||
};
|
||||
|
||||
CodeView(ViewLayout* viewLayout);
|
||||
virtual ~CodeView();
|
||||
|
||||
virtual std::string getName() const;
|
||||
|
||||
virtual void addCodeSnippet(const std::string& str, const TokenLocationFile& locationFile, int startLineNumber) = 0;
|
||||
virtual void addCodeSnippet(const CodeSnippetParams params) = 0;
|
||||
virtual void clearCodeSnippets() = 0;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user