logic: code controller

- Renamed MessageActivateTokenLocation to MessageActivateToken, since it uses the Token id (not the TokenLocation id).
- Implemented CodeController to add one snippet for each location where the activated token occurred.
- Added Semaphore to QtThreadedFunctor to prevent an evil race-condition.
- CodeView dispatches message when a token is clicked.
This commit is contained in:
malte_langkabel
2014-07-03 16:03:06 +02:00
parent 4c7bbbe28e
commit 4ae6f4a04a
17 changed files with 183 additions and 44 deletions
+31 -10
View File
@@ -3,6 +3,8 @@
#include "component/view/CodeView.h"
#include "data/access/LocationAccess.h"
#include "data/location/TokenLocation.h"
#include "data/location/TokenLocationCollection.h"
#include "data/location/TokenLocationFile.h"
#include "utility/text/TextAccess.h"
#include "utility/logging/logging.h"
@@ -17,20 +19,39 @@ CodeController::~CodeController()
{
}
void CodeController::setActiveTokenLocationId(Id id)
void CodeController::setActiveTokenId(Id id)
{
TokenLocation* tokenLocation = m_locationAccess->getTokenLocation(id);
if (tokenLocation)
{
getView()->clearCodeSnippets();
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(tokenLocation->getFilePath());
// getView()->addCodeSnippet(textAccess->getText());
}
const unsigned int lineRadius = 2;
getView()->clearCodeSnippets();
TokenLocationCollection collection = m_locationAccess->getTokenLocationsForTokenId(id);
collection.forEachTokenLocation([&] (TokenLocation* tokenLocation) -> void {
if (tokenLocation->isStartTokenLocation())
{
const std::string filePath = tokenLocation->getFilePath();
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(filePath);
unsigned int firstLineNumber = std::max<int>(1, tokenLocation->getLineNumber() - lineRadius);
unsigned int lastLineNumber = std::min<int>(
textAccess->getLineCount(), tokenLocation->getEndTokenLocation()->getLineNumber() + lineRadius
);
std::string text;
for (std::string line: textAccess->getLines(firstLineNumber, lastLineNumber))
{
text += line;
}
TokenLocationFile tokenLocationFile = m_locationAccess->getTokenLocationsForLinesInFile(filePath, firstLineNumber, lastLineNumber);
getView()->addCodeSnippet(text, tokenLocationFile, firstLineNumber);
}
});
}
void CodeController::handleMessage(MessageActivateTokenLocation* message)
void CodeController::handleMessage(MessageActivateToken* message)
{
setActiveTokenLocationId(1);
setActiveTokenId(message->tokenId);
}
CodeView* CodeController::getView()