ui: IDE communication integration
* handled communication from VS to Coati and vice versa. * one bug still remains: Coati regards a tab as a single character while VS regards it as multiple characters. This causes offsets in communicated positions.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "qt/element/QtCodeArea.h"
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <QFont>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPainter>
|
||||
@@ -11,6 +12,7 @@
|
||||
#include "utility/messaging/type/MessageShowFile.h"
|
||||
#include "utility/messaging/type/MessageFocusIn.h"
|
||||
#include "utility/messaging/type/MessageFocusOut.h"
|
||||
#include "utility/messaging/type/MessageMoveIDECursor.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
#include "data/location/TokenLocation.h"
|
||||
@@ -249,12 +251,20 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event)
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
m_panningValue = -1;
|
||||
QTextCursor cursor = this->cursorForPosition(event->pos());
|
||||
std::vector<Id> locationIds = findLocationIdsForPosition(cursor.position());
|
||||
|
||||
if (locationIds.size())
|
||||
if (Qt::KeyboardModifier::ControlModifier && QApplication::keyboardModifiers())
|
||||
{
|
||||
MessageActivateTokenLocations(locationIds).dispatch();
|
||||
std::pair<int, int> lineColumn = toLineColumn(this->cursorForPosition(event->pos()).position());
|
||||
MessageMoveIDECursor(m_locationFile->getFilePath().str(), lineColumn.first, lineColumn.second).dispatch();
|
||||
}
|
||||
else
|
||||
{
|
||||
QTextCursor cursor = this->cursorForPosition(event->pos());
|
||||
std::vector<Id> locationIds = findLocationIdsForPosition(cursor.position());
|
||||
if (locationIds.size())
|
||||
{
|
||||
MessageActivateTokenLocations(locationIds).dispatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -566,6 +576,25 @@ int QtCodeArea::toTextEditPosition(int lineNumber, int columnNumber) const
|
||||
return position;
|
||||
}
|
||||
|
||||
std::pair<int, int> QtCodeArea::toLineColumn(int textEditPosition) const
|
||||
{
|
||||
int lineNumber = m_startLineNumber;
|
||||
for (int i = 0; i < document()->lineCount(); i++)
|
||||
{
|
||||
int nextTextEditPosition = textEditPosition - document()->findBlockByLineNumber(i).length();
|
||||
if (nextTextEditPosition >= 0)
|
||||
{
|
||||
textEditPosition = nextTextEditPosition;
|
||||
lineNumber++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return std::make_pair(lineNumber, textEditPosition);
|
||||
}
|
||||
|
||||
int QtCodeArea::startTextEditPosition() const
|
||||
{
|
||||
return 0;
|
||||
|
||||
@@ -114,6 +114,7 @@ private:
|
||||
bool locationBelongsToSnippet(TokenLocation* location) const;
|
||||
|
||||
int toTextEditPosition(int lineNumber, int columnNumber) const;
|
||||
std::pair<int, int> toLineColumn(int textEditPosition) const;
|
||||
int startTextEditPosition() const;
|
||||
int endTextEditPosition() const;
|
||||
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
QtIDECommunicationController::QtIDECommunicationController(QObject* parent)
|
||||
: m_tcpWrapper(parent)
|
||||
QtIDECommunicationController::QtIDECommunicationController(QObject* parent, StorageAccess* storageAccess)
|
||||
: IDECommunicationController(storageAccess)
|
||||
, m_tcpWrapper(parent)
|
||||
{
|
||||
m_tcpWrapper.setReadCallback(std::bind(&QtIDECommunicationController::handleIncomingMessage, this, std::placeholders::_1));
|
||||
}
|
||||
|
||||
@@ -7,11 +7,13 @@
|
||||
|
||||
#include "component/controller/IDECommunicationController.h"
|
||||
|
||||
class StorageAccess;
|
||||
|
||||
class QtIDECommunicationController
|
||||
: public IDECommunicationController
|
||||
{
|
||||
public:
|
||||
QtIDECommunicationController(QObject* parent);
|
||||
QtIDECommunicationController(QObject* parent, StorageAccess* storageAccess);
|
||||
~QtIDECommunicationController();
|
||||
|
||||
private:
|
||||
|
||||
@@ -10,7 +10,7 @@ QtNetworkFactory::~QtNetworkFactory()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<IDECommunicationController> QtNetworkFactory::createIDECommunicationController() const
|
||||
std::shared_ptr<IDECommunicationController> QtNetworkFactory::createIDECommunicationController(StorageAccess* storageAccess) const
|
||||
{
|
||||
return std::make_shared<QtIDECommunicationController>(nullptr);
|
||||
return std::make_shared<QtIDECommunicationController>(nullptr, storageAccess);
|
||||
}
|
||||
@@ -9,7 +9,7 @@ public:
|
||||
QtNetworkFactory();
|
||||
virtual ~QtNetworkFactory();
|
||||
|
||||
virtual std::shared_ptr<IDECommunicationController> createIDECommunicationController() const;
|
||||
virtual std::shared_ptr<IDECommunicationController> createIDECommunicationController(StorageAccess* storageAccess) const;
|
||||
};
|
||||
|
||||
#endif // QT_NETWORK_FACTORY_H
|
||||
@@ -2,23 +2,6 @@
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
QtTcpWrapper::QtTcpWrapper(QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_port(6667)
|
||||
, m_ip("127.0.0.1")
|
||||
{
|
||||
QHostAddress address(m_ip.c_str());
|
||||
|
||||
m_tcpServer = new QTcpServer(this);
|
||||
|
||||
connect(m_tcpServer, SIGNAL(newConnection()), this, SLOT(acceptConnection()));
|
||||
|
||||
if (!m_tcpServer->listen(QHostAddress::LocalHost, m_port))
|
||||
{
|
||||
LOG_ERROR_STREAM(<< "TCP server failed to start. Unable to listen for IDE plugin messages.");
|
||||
}
|
||||
}
|
||||
|
||||
QtTcpWrapper::QtTcpWrapper(QObject* parent, const std::string& ip, const quint16 port)
|
||||
: QObject(parent)
|
||||
, m_port(port)
|
||||
@@ -32,7 +15,7 @@ QtTcpWrapper::QtTcpWrapper(QObject* parent, const std::string& ip, const quint16
|
||||
|
||||
if (!m_tcpServer->listen(QHostAddress::LocalHost, m_port))
|
||||
{
|
||||
LOG_ERROR_STREAM(<< "TCP server failed to start. Unable to listen for IDE plugin messages.");
|
||||
LOG_ERROR_STREAM(<< "TCP server failed to start with error: \"" + m_tcpServer->errorString().toStdString() + "\". Unable to listen for IDE plugin messages.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,7 @@ class QtTcpWrapper : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtTcpWrapper(QObject* parent);
|
||||
QtTcpWrapper(QObject* parent, const std::string& ip, const quint16 port);
|
||||
QtTcpWrapper(QObject* parent, const std::string& ip = "127.0.0.1", const quint16 port = 6667);
|
||||
~QtTcpWrapper();
|
||||
|
||||
void sendMessage(const std::string& message) const;
|
||||
|
||||
@@ -39,7 +39,7 @@ std::shared_ptr<Application> Application::create(ViewFactory* viewFactory, Netwo
|
||||
ptr->m_mainView->hideStartScreen();
|
||||
}
|
||||
|
||||
ptr->m_ideCommunicationController = networkFactory->createIDECommunicationController();
|
||||
ptr->m_ideCommunicationController = networkFactory->createIDECommunicationController(ptr->m_storageCache.get());
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "component/controller/FeatureController.h"
|
||||
|
||||
#include "utility/messaging/type/MessageActivateTokens.h"
|
||||
#include "utility/messaging/type/MessageRefresh.h"
|
||||
|
||||
#include "data/access/StorageAccess.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
|
||||
#include "utility/messaging/type/MessageActivateTokens.h"
|
||||
#include "utility/messaging/type/MessageRefresh.h"
|
||||
|
||||
FeatureController::FeatureController(StorageAccess* storageAccess)
|
||||
: m_storageAccess(storageAccess)
|
||||
, m_activationTranslator(storageAccess)
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "component/controller/helper/ActivationTranslator.h"
|
||||
#include "component/controller/Controller.h"
|
||||
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageActivateEdge.h"
|
||||
#include "utility/messaging/type/MessageActivateFile.h"
|
||||
@@ -12,9 +15,6 @@
|
||||
#include "utility/messaging/type/MessageSwitchColorScheme.h"
|
||||
#include "utility/messaging/type/MessageZoom.h"
|
||||
|
||||
#include "component/controller/Controller.h"
|
||||
#include "component/controller/helper/ActivationTranslator.h"
|
||||
|
||||
class StorageAccess;
|
||||
|
||||
class FeatureController
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
#include "IDECommunicationController.h"
|
||||
|
||||
#include "utility/messaging/type/MessageActivateTokens.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/logging/logging.h"
|
||||
|
||||
#include "component/controller/helper/NetworkProtocolHelper.h"
|
||||
|
||||
IDECommunicationController::IDECommunicationController()
|
||||
IDECommunicationController::IDECommunicationController(StorageAccess* storageAccess)
|
||||
: m_storageAccess(storageAccess)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -21,7 +25,31 @@ void IDECommunicationController::handleIncomingMessage(const std::string& messag
|
||||
|
||||
if (parsedMessage.valid)
|
||||
{
|
||||
// TODO: set active token
|
||||
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)
|
||||
{
|
||||
MessageActivateTokenLocations(selectedLocationIds).dispatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,17 +3,19 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "component/controller/Controller.h"
|
||||
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageMoveIDECursor.h"
|
||||
|
||||
#include "component/controller/Controller.h"
|
||||
class StorageAccess;
|
||||
|
||||
class IDECommunicationController
|
||||
: public Controller
|
||||
, public MessageListener<MessageMoveIDECursor>
|
||||
{
|
||||
public:
|
||||
IDECommunicationController();
|
||||
IDECommunicationController(StorageAccess* storageAccess);
|
||||
virtual ~IDECommunicationController();
|
||||
|
||||
void handleIncomingMessage(const std::string& message);
|
||||
@@ -21,6 +23,8 @@ public:
|
||||
private:
|
||||
virtual void handleMessage(MessageMoveIDECursor* message);
|
||||
virtual void sendMessage(const std::string& message) const = 0;
|
||||
|
||||
StorageAccess* m_storageAccess;
|
||||
};
|
||||
|
||||
#endif // IDE_COMMUNICATION_CONTROLLER_H
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <memory>
|
||||
|
||||
class IDECommunicationController;
|
||||
class StorageAccess;
|
||||
|
||||
class NetworkFactory
|
||||
{
|
||||
@@ -11,7 +12,7 @@ public:
|
||||
NetworkFactory();
|
||||
virtual ~NetworkFactory();
|
||||
|
||||
virtual std::shared_ptr<IDECommunicationController> createIDECommunicationController() const = 0;
|
||||
virtual std::shared_ptr<IDECommunicationController> createIDECommunicationController(StorageAccess* storageAccess) const = 0;
|
||||
};
|
||||
|
||||
#endif // NETWORK_FACTORY_H
|
||||
@@ -12,29 +12,25 @@ NetworkProtocolHelper::NetworkMessage NetworkProtocolHelper::parseMessage(const
|
||||
{
|
||||
NetworkMessage networkMessage;
|
||||
|
||||
std::string tmpMessage = removeEndOfMessageToken(message);
|
||||
|
||||
size_t pos = tmpMessage.find(m_setActiveTokenPrefix);
|
||||
size_t pos = message.find(m_setActiveTokenPrefix);
|
||||
|
||||
if(pos != std::string::npos)
|
||||
{
|
||||
tmpMessage = "";
|
||||
std::string tmpMessage = "";
|
||||
getSubstringAfterString(message, m_divider, tmpMessage); // just get rid of message type
|
||||
tmpMessage = removeEndOfMessageToken(tmpMessage);
|
||||
|
||||
std::string fileLocation = getSubstringAfterString(tmpMessage, m_divider, tmpMessage);
|
||||
std::string row = getSubstringAfterString(tmpMessage, m_divider, tmpMessage);
|
||||
std::string column = tmpMessage; // getSubstringAfterString(tmpMessage, "", tmpMessage); // there should be nothing left in the message but the column number
|
||||
std::string column = tmpMessage; // there should be nothing left in the message but the column number
|
||||
|
||||
if(fileLocation.length() <= 0
|
||||
|| row.length() <= 0
|
||||
|| column.length() <= 0
|
||||
|| isDigits(row) == false
|
||||
|| isDigits(column) == false)
|
||||
{
|
||||
return networkMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(
|
||||
fileLocation.length() > 0
|
||||
&& row.length() > 0
|
||||
&& column.length() > 0
|
||||
&& isDigits(row)
|
||||
&& isDigits(column)
|
||||
){
|
||||
networkMessage.fileLocation = fileLocation;
|
||||
networkMessage.row = std::stoi(row);
|
||||
networkMessage.column = std::stoi(column);
|
||||
|
||||
Reference in New Issue
Block a user