logic: improvements for IDE communication

* fixed Sublime Text plugin to correctly send messages
* activate and focus Coati window when receiving a message
* extended lookup range for activate token message from plugin
This commit is contained in:
Eberhard Graether
2015-11-13 13:09:22 +01:00
parent df7c5ea9b7
commit 3c2804797a
9 changed files with 63 additions and 13 deletions
@@ -71,7 +71,8 @@ class SetActiveTokenCommand(sublime_plugin.TextCommand):
col += 1 # cols returned by rowcol() are 0-based.
row += 1 # rows returned by rowcol() are 0-based.
message = "setActiveToken" + MESSAGE_SPLIT_STRING + filePath + MESSAGE_SPLIT_STRING + str(row) + MESSAGE_SPLIT_STRING + str(col) + "<EOM>"
text = "setActiveToken" + MESSAGE_SPLIT_STRING + filePath + MESSAGE_SPLIT_STRING + str(row) + MESSAGE_SPLIT_STRING + str(col) + "<EOM>"
data = text.encode()
settings = sublime.load_settings('CoatiCommunicator.sublime-settings')
host_ip = settings.get('host_ip')
@@ -79,5 +80,5 @@ class SetActiveTokenCommand(sublime_plugin.TextCommand):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host_ip, plugin_to_coati_port))
s.send(message)
s.send(data)
s.close()
+14
View File
@@ -6,6 +6,7 @@
QtMainView::QtMainView()
: m_setTitleFunctor(std::bind(&QtMainView::doSetTitle, this, std::placeholders::_1))
, m_activateWindowFunctor(std::bind(&QtMainView::doActivateWindow, this))
{
m_window = std::make_shared<QtMainWindow>();
m_window->show();
@@ -74,7 +75,20 @@ void QtMainView::setTitle(const std::string& title)
m_setTitleFunctor(title);
}
void QtMainView::activateWindow()
{
m_activateWindowFunctor();
}
void QtMainView::doSetTitle(const std::string& title)
{
m_window->setWindowTitle(QString::fromStdString(title));
}
void QtMainView::doActivateWindow()
{
// It's platform dependent which of these commands does the right thing, for now we just use them all at once.
m_window->activateWindow();
m_window->raise();
m_window->setFocus(Qt::ActiveWindowFocusReason);
}
+3
View File
@@ -35,14 +35,17 @@ public:
// MainView implementation
virtual void hideStartScreen();
virtual void setTitle(const std::string& title);
virtual void activateWindow();
private:
void doSetTitle(const std::string& title);
void doActivateWindow();
std::shared_ptr<QtMainWindow> m_window;
std::vector<View*> m_views;
QtThreadedFunctor<const std::string&> m_setTitleFunctor;
QtThreadedFunctor<> m_activateWindowFunctor;
};
#endif // QT_MAIN_VIEW_H
+5
View File
@@ -108,6 +108,11 @@ void Application::saveProject(const FilePath& projectSettingsFilePath)
}
}
void Application::handleMessage(MessageActivateWindow* message)
{
m_mainView->activateWindow();
}
void Application::handleMessage(MessageFinishedParsing* message)
{
m_project->logStats();
+4 -1
View File
@@ -6,6 +6,7 @@
#include "component/ComponentManager.h"
#include "Project.h"
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageActivateWindow.h"
#include "utility/messaging/type/MessageFinishedParsing.h"
#include "utility/messaging/type/MessageLoadProject.h"
#include "utility/messaging/type/MessageRefresh.h"
@@ -19,7 +20,8 @@ class StorageCache;
class Version;
class Application
: public MessageListener<MessageFinishedParsing>
: public MessageListener<MessageActivateWindow>
, public MessageListener<MessageFinishedParsing>
, public MessageListener<MessageLoadProject>
, public MessageListener<MessageRefresh>
, public MessageListener<MessageSaveProject>
@@ -37,6 +39,7 @@ public:
private:
Application();
virtual void handleMessage(MessageActivateWindow* message);
virtual void handleMessage(MessageFinishedParsing* message);
virtual void handleMessage(MessageLoadProject* message);
virtual void handleMessage(MessageRefresh* message);
+1
View File
@@ -249,6 +249,7 @@ add_files(
utility/messaging/type/MessageActivateNodes.h
utility/messaging/type/MessageActivateTokenLocations.h
utility/messaging/type/MessageActivateTokens.h
utility/messaging/type/MessageActivateWindow.h
utility/messaging/type/MessageAutoRefreshChanged.h
utility/messaging/type/MessageDeactivateEdge.h
utility/messaging/type/MessageFind.h
@@ -6,6 +6,7 @@
#include "data/location/TokenLocation.h"
#include "utility/messaging/type/MessageActivateTokenLocations.h"
#include "utility/messaging/type/MessageActivateWindow.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/logging/logging.h"
@@ -23,7 +24,7 @@ void IDECommunicationController::handleIncomingMessage(const std::string& messag
LOG_WARNING_STREAM(<< message);
NetworkProtocolHelper::NetworkMessage parsedMessage = NetworkProtocolHelper::parseMessage(message);
if (parsedMessage.valid)
{
const unsigned int cursorColumn = parsedMessage.column;
@@ -36,13 +37,12 @@ void IDECommunicationController::handleIncomingMessage(const std::string& messag
tokenLocationFile->forEachStartTokenLocation(
[&](TokenLocation* startLocation)
{
if (startLocation->getColumnNumber() < cursorColumn)
TokenLocation* endLocation = startLocation->getEndTokenLocation();
if (!startLocation->isScopeTokenLocation() &&
startLocation->getColumnNumber() <= cursorColumn && endLocation->getColumnNumber() + 1 >= cursorColumn)
{
TokenLocation* endLocation = startLocation->getOtherTokenLocation();
if (endLocation && endLocation->getColumnNumber() > cursorColumn)
{
selectedLocationIds.push_back(startLocation->getId());
}
selectedLocationIds.push_back(startLocation->getId());
}
}
);
@@ -51,6 +51,7 @@ void IDECommunicationController::handleIncomingMessage(const std::string& messag
{
MessageStatus("Activating a source location from external succeeded.").dispatch();
MessageActivateTokenLocations(selectedLocationIds).dispatch();
MessageActivateWindow().dispatch();
}
else
{
@@ -66,9 +67,9 @@ 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: " +
"Jumping the external tool to the following location: " + message->FilePosition + ", row: " +
std::to_string(message->Row) + ", col: " + std::to_string(message->Column)
).dispatch();
+3 -1
View File
@@ -5,7 +5,8 @@
#include "component/view/ViewLayout.h"
class MainView: public ViewLayout
class MainView
: public ViewLayout
{
public:
MainView();
@@ -13,6 +14,7 @@ public:
virtual void hideStartScreen() = 0;
virtual void setTitle(const std::string& title) = 0;
virtual void activateWindow() = 0;
};
#endif // MAIN_VIEW_H
@@ -0,0 +1,20 @@
#ifndef MESSAGE_ACTIVATE_WINDOW_H
#define MESSAGE_ACTIVATE_WINDOW_H
#include "utility/messaging/Message.h"
class MessageActivateWindow
: public Message<MessageActivateWindow>
{
public:
MessageActivateWindow()
{
}
static const std::string getStaticType()
{
return "MessageActivateWindow";
}
};
#endif // MESSAGE_ACTIVATE_WINDOW_H