Files
Sourcetrail/src/lib/component/controller/IDECommunicationController.cpp
T
malte_langkabel 1ad2dbe86e ui: status messages for IDE communication
* added status messages that are displayed when sending commands to the IDE.
* added status messages that are displayed when receiving commands from the IDE.
2015-10-30 11:34:28 +01:00

76 lines
2.2 KiB
C++

#include "IDECommunicationController.h"
#include "component/controller/helper/NetworkProtocolHelper.h"
#include "data/access/StorageAccess.h"
#include "data/location/TokenLocationFile.h"
#include "data/location/TokenLocation.h"
#include "utility/messaging/type/MessageActivateTokenLocations.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/logging/logging.h"
IDECommunicationController::IDECommunicationController(StorageAccess* storageAccess)
: m_storageAccess(storageAccess)
{
}
IDECommunicationController::~IDECommunicationController()
{
}
void IDECommunicationController::handleIncomingMessage(const std::string& message)
{
LOG_WARNING_STREAM(<< message);
NetworkProtocolHelper::NetworkMessage parsedMessage = NetworkProtocolHelper::parseMessage(message);
if (parsedMessage.valid)
{
const unsigned int cursorColumn = parsedMessage.column;
std::shared_ptr<TokenLocationFile> tokenLocationFile = m_storageAccess->getTokenLocationsForLinesInFile(
parsedMessage.fileLocation, parsedMessage.row, parsedMessage.row
);
std::vector<Id> selectedLocationIds;
tokenLocationFile->forEachStartTokenLocation(
[&](TokenLocation* startLocation)
{
if (startLocation->getColumnNumber() < cursorColumn)
{
TokenLocation* endLocation = startLocation->getOtherTokenLocation();
if (endLocation && endLocation->getColumnNumber() > cursorColumn)
{
selectedLocationIds.push_back(startLocation->getId());
}
}
}
);
if (selectedLocationIds.size() > 0)
{
MessageStatus("Activating a source location from external succeeded.").dispatch();
MessageActivateTokenLocations(selectedLocationIds).dispatch();
}
else
{
MessageStatus(
"Activating a source location from external failed. No symbol(s) have been found at the selected location."
).dispatch();
}
}
}
void IDECommunicationController::handleMessage(MessageMoveIDECursor* message)
{
std::string networkMessage = NetworkProtocolHelper::buildMessage(
message->FilePosition, message->Row, message->Column
);
MessageStatus(
"Jumping the external tool to the following location: " + message->FilePosition + ", row: " +
std::to_string(message->Row) + ", col: " + std::to_string(message->Column)
).dispatch();
sendMessage(networkMessage);
}