From d5e9cecef33f2ccad40033c52ef23ce5a25f0a36 Mon Sep 17 00:00:00 2001 From: Andreas Stallinger Date: Thu, 28 Jul 2016 14:16:15 +0200 Subject: [PATCH] logic: scroll code when no symbol Scrolling to line, when comming from plugin and the file is was modified. Since there we dont know from the position data if the symbol on position is the right one, we scroll to the line if modified. --- bin/app/data/gui/window/size_grip.png | Bin 3339 -> 672 bytes src/lib/CMakeLists.txt | 1 + .../component/controller/CodeController.cpp | 21 ++++++ src/lib/component/controller/CodeController.h | 3 + .../controller/FeatureController.cpp | 5 ++ .../controller/IDECommunicationController.cpp | 62 ++++++++++++------ src/lib/component/view/CodeView.h | 1 + .../messaging/type/MessageActivateFile.h | 4 +- .../messaging/type/MessageScrollToLine.h | 28 ++++++++ src/lib_gui/qt/element/QtCodeFile.cpp | 5 ++ src/lib_gui/qt/element/QtCodeFile.h | 1 + src/lib_gui/qt/element/QtCodeFileList.cpp | 13 ++++ src/lib_gui/qt/element/QtCodeFileList.h | 1 + src/lib_gui/qt/network/QtTcpWrapper.cpp | 2 +- src/lib_gui/qt/view/QtCodeView.cpp | 11 ++++ src/lib_gui/qt/view/QtCodeView.h | 3 + 16 files changed, 139 insertions(+), 22 deletions(-) create mode 100644 src/lib/utility/messaging/type/MessageScrollToLine.h diff --git a/bin/app/data/gui/window/size_grip.png b/bin/app/data/gui/window/size_grip.png index 3fd2023eb84f4043967d1cd8fb589b7b79679857..39246b9bcd083f4a94e5211c861c6b513e000227 100644 GIT binary patch delta 597 zcmeB{TEIF%Qi7R*fno0U#y3EUCEd~2k%3`jKlh(R*2xpO^imm&1AIbU|Ns9FlvS2j zAQA!93!l1^2h_t~666=mz+kZce#86o1^Wf&Cph#6cCtADr5KaE-CYEaj?aro`E+mj9{2)G6c=Q%z4^8f$a70Hqc>@N=g z(8zzeYOj`)*2kis>-g8UMy(dym=~GWc=dF0YvhBg-7(J_%JmDmEUG3-D!f0;GU5B9 ziUlun7d0;Wu3g(xdY)<#mn0?sqkZ%}8r^Sa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z;a#2HX_VV`h6$>#2ylYMam$@zR{%5lZSV-_$An0Q>bT}+ZB zNSM_!T>}STD=!J)R94~(w&7k8%y@ z0pG-JbOIFM0dArapa>68L?b{09^fqs0h;gvcn)5GCVUOtm6fQ27BB!lD=Se1eH1nY zAA|st@ZJkB4ezx88}Qx=um$g>0GsgM39t?Cl>is;-Ux67?}Y%D@XiIehIcB!2YBeH z3Wo|W^FHyr`jdYH4_$YI)~mvX;XA9sK=vuVYNu1c5j;RMGTf~J4&j^FIuqalJY8+B zCIa8&v@5_Pcz{={0z8ASfd^{>JcQ4zRfRo;FRUDeLxUexK#1_82?!N_6agW_4;BzQ z{2&1_z-tSL1zt-)Oz_GAVuM!_5F^??USRYt(U(5ieeu;8s35M2Vc zhPI@!^WF~K28Z4aj #include "utility/messaging/type/MessageStatus.h" +#include "utility/messaging/type/MessageScrollToLine.h" #include "utility/text/TextAccess.h" #include "utility/tracing.h" #include "utility/utility.h" @@ -234,6 +235,26 @@ void CodeController::handleMessage(MessageFocusOut* message) getView()->defocusTokenIds(); } +void CodeController::handleMessage(MessageScrollToLine* message) +{ + getView()->scrollToLine(message->filename, message->line); + + if ( message->isModified ) + { + MessageStatus( + "File was modified. Showing the File: " + message->filename + + " at line " + std::to_string(message->line) + " now. Please refresh." + ).dispatch(); + } + else + { + MessageStatus( + "Showing the File: " + message->filename + + " at line " + std::to_string(message->line) + "." + ).dispatch(); + } +} + void CodeController::handleMessage(MessageScrollCode* message) { if (message->isReplayed()) diff --git a/src/lib/component/controller/CodeController.h b/src/lib/component/controller/CodeController.h index 96ff7c58..b6c9f1d6 100644 --- a/src/lib/component/controller/CodeController.h +++ b/src/lib/component/controller/CodeController.h @@ -13,6 +13,7 @@ #include "utility/messaging/type/MessageFocusIn.h" #include "utility/messaging/type/MessageFocusOut.h" #include "utility/messaging/type/MessageScrollCode.h" +#include "utility/messaging/type/MessageScrollToLine.h" #include "utility/messaging/type/MessageSearchFullText.h" #include "utility/messaging/type/MessageShowErrors.h" #include "utility/messaging/type/MessageShowScope.h" @@ -37,6 +38,7 @@ class CodeController , public MessageListener , public MessageListener , public MessageListener + , public MessageListener , public MessageListener , public MessageListener , public MessageListener @@ -56,6 +58,7 @@ private: virtual void handleMessage(MessageFocusIn* message); virtual void handleMessage(MessageFocusOut* message); virtual void handleMessage(MessageScrollCode* message); + virtual void handleMessage(MessageScrollToLine* message); virtual void handleMessage(MessageSearchFullText* message); virtual void handleMessage(MessageShowErrors* message); virtual void handleMessage(MessageShowScope* message); diff --git a/src/lib/component/controller/FeatureController.cpp b/src/lib/component/controller/FeatureController.cpp index f2383c98..e49459c8 100644 --- a/src/lib/component/controller/FeatureController.cpp +++ b/src/lib/component/controller/FeatureController.cpp @@ -10,6 +10,7 @@ #include "utility/messaging/type/MessageRefresh.h" #include "utility/messaging/type/MessageShowErrors.h" #include "utility/messaging/type/MessageStatus.h" +#include "utility/messaging/type/MessageScrollToLine.h" FeatureController::FeatureController(StorageAccess* storageAccess) : m_storageAccess(storageAccess) @@ -76,6 +77,10 @@ void FeatureController::handleMessage(MessageActivateFile* message) msg.setKeepContent(message->keepContent()); msg.dispatchImmediately(); } + if( message->line > 0 ) + { + MessageScrollToLine(message->filePath.str(), message->line, true).dispatch(); + } } void FeatureController::handleMessage(MessageActivateNodes* message) diff --git a/src/lib/component/controller/IDECommunicationController.cpp b/src/lib/component/controller/IDECommunicationController.cpp index 9fb17749..77d2c01f 100644 --- a/src/lib/component/controller/IDECommunicationController.cpp +++ b/src/lib/component/controller/IDECommunicationController.cpp @@ -1,3 +1,5 @@ +#include +#include #include "IDECommunicationController.h" #include "data/access/StorageAccess.h" @@ -7,12 +9,11 @@ #include "utility/messaging/type/MessageActivateTokenLocations.h" #include "utility/messaging/type/MessageActivateWindow.h" #include "utility/messaging/type/MessageDispatchWhenLicenseValid.h" -#include "utility/messaging/type/MessageLoadProject.h" #include "utility/messaging/type/MessageProjectNew.h" #include "utility/messaging/type/MessageStatus.h" -#include "utility/logging/logging.h" - -#include "settings/ProjectSettings.h" +#include "utility/messaging/type/MessageActivateFile.h" +#include "utility/messaging/type/MessageScrollCode.h" +#include "utility/messaging/type/MessageScrollToLine.h" IDECommunicationController::IDECommunicationController(StorageAccess* storageAccess) : m_storageAccess(storageAccess) @@ -61,40 +62,61 @@ void IDECommunicationController::setEnabled(const bool enabled) m_enabled = enabled; } -void IDECommunicationController::handleSetActiveTokenMessage(const NetworkProtocolHelper::SetActiveTokenMessage& message) +void IDECommunicationController::handleSetActiveTokenMessage( + const NetworkProtocolHelper::SetActiveTokenMessage& message +) { if (message.valid) { const unsigned int cursorColumn = message.column; - std::shared_ptr tokenLocationFile = m_storageAccess->getTokenLocationsForLinesInFile( - message.fileLocation, message.row, message.row + if(FileSystem::getFileInfoForPath(message.fileLocation).lastWriteTime + == m_storageAccess->getFileInfoForFilePath(message.fileLocation).lastWriteTime) + { + // file was not modified + std::shared_ptr tokenLocationFile = m_storageAccess->getTokenLocationsForLinesInFile( + message.fileLocation, message.row, message.row ); - std::vector selectedLocationIds; - tokenLocationFile->forEachStartTokenLocation( - [&](TokenLocation* startLocation) - { - TokenLocation* endLocation = startLocation->getEndTokenLocation(); + std::vector selectedLocationIds; + tokenLocationFile->forEachStartTokenLocation( + [&](TokenLocation* startLocation) + { + TokenLocation* endLocation = startLocation->getEndTokenLocation(); - if (!startLocation->isScopeTokenLocation() && - startLocation->getColumnNumber() <= cursorColumn && endLocation->getColumnNumber() + 1 >= cursorColumn) + if (!startLocation->isScopeTokenLocation() + && startLocation->getColumnNumber() <= cursorColumn + && endLocation->getColumnNumber() + 1 >= cursorColumn) + { + selectedLocationIds.push_back(startLocation->getId()); + } + } + ); + + if (selectedLocationIds.size() > 0) { - selectedLocationIds.push_back(startLocation->getId()); + MessageStatus("Activating a source location from external succeeded.").dispatch(); + MessageDispatchWhenLicenseValid( + std::make_shared(selectedLocationIds) + ).dispatch(); + MessageActivateWindow().dispatch(); + return; } } - ); - if (selectedLocationIds.size() > 0) + Id fileId = m_storageAccess->getTokenIdForFileNode(message.fileLocation); + if( fileId > 0) { - MessageStatus("Activating a source location from external succeeded.").dispatch(); - MessageDispatchWhenLicenseValid(std::make_shared(selectedLocationIds)).dispatch(); + MessageDispatchWhenLicenseValid( + std::make_shared(message.fileLocation, message.row) + ).dispatchImmediately(); MessageActivateWindow().dispatch(); } else { MessageStatus( - "Activating a source location from external failed. No symbol(s) have been found at the selected location." + "Activating a source location from external failed. No file " + message.fileLocation + + " have been found at in indexed source." ).dispatch(); } } diff --git a/src/lib/component/view/CodeView.h b/src/lib/component/view/CodeView.h index 1d16df87..9b58d830 100644 --- a/src/lib/component/view/CodeView.h +++ b/src/lib/component/view/CodeView.h @@ -48,6 +48,7 @@ public: virtual void showContents() = 0; virtual void scrollToValue(int value) = 0; + virtual void scrollToLine(std::string filename, unsigned int line) = 0; private: CodeController* getController(); diff --git a/src/lib/utility/messaging/type/MessageActivateFile.h b/src/lib/utility/messaging/type/MessageActivateFile.h index bb0452a8..eb43393f 100644 --- a/src/lib/utility/messaging/type/MessageActivateFile.h +++ b/src/lib/utility/messaging/type/MessageActivateFile.h @@ -7,8 +7,9 @@ class MessageActivateFile: public Message { public: - MessageActivateFile(const FilePath& filePath) + MessageActivateFile(const FilePath& filePath, unsigned int line = 0) : filePath(filePath) + , line(line) { } @@ -23,6 +24,7 @@ public: } const FilePath filePath; + unsigned int line; }; #endif // MESSAGE_ACTIVATE_FILE_H diff --git a/src/lib/utility/messaging/type/MessageScrollToLine.h b/src/lib/utility/messaging/type/MessageScrollToLine.h new file mode 100644 index 00000000..73559f73 --- /dev/null +++ b/src/lib/utility/messaging/type/MessageScrollToLine.h @@ -0,0 +1,28 @@ +#ifndef MESSAGE_SCROLL_TO_LINE_h +#define MESSAGE_SCROLL_TO_LINE_h + +#include "utility/messaging/Message.h" + +class MessageScrollToLine + : public Message +{ +public: + MessageScrollToLine(std::string filename, unsigned int line, bool isModified = false) + : filename(filename) + , line(line) + , isModified(isModified) + { + setIsLogged(false); + } + + static const std::string getStaticType() + { + return "MessageScrollToLine"; + } + + std::string filename; + unsigned int line; + bool isModified; +}; + +#endif // MESSAGE_SCROLL_TO_LINE_h diff --git a/src/lib_gui/qt/element/QtCodeFile.cpp b/src/lib_gui/qt/element/QtCodeFile.cpp index 13ac7837..dca00832 100644 --- a/src/lib_gui/qt/element/QtCodeFile.cpp +++ b/src/lib_gui/qt/element/QtCodeFile.cpp @@ -264,6 +264,11 @@ QtCodeSnippet* QtCodeFile::insertCodeSnippet(const CodeSnippetParams& params) return snippet.get(); } +QtCodeSnippet* QtCodeFile::getFileSnippet() const +{ + return m_fileSnippet.get(); +} + QtCodeSnippet* QtCodeFile::findFirstActiveSnippet() const { if (m_locationFile) diff --git a/src/lib_gui/qt/element/QtCodeFile.h b/src/lib_gui/qt/element/QtCodeFile.h index 12514986..3b9f20d2 100644 --- a/src/lib_gui/qt/element/QtCodeFile.h +++ b/src/lib_gui/qt/element/QtCodeFile.h @@ -50,6 +50,7 @@ public: QtCodeSnippet* insertCodeSnippet(const CodeSnippetParams& params); QtCodeSnippet* findFirstActiveSnippet() const; + QtCodeSnippet* getFileSnippet() const; bool isCollapsedActiveFile() const; void updateContent(); diff --git a/src/lib_gui/qt/element/QtCodeFileList.cpp b/src/lib_gui/qt/element/QtCodeFileList.cpp index ef85633e..c54f2748 100644 --- a/src/lib_gui/qt/element/QtCodeFileList.cpp +++ b/src/lib_gui/qt/element/QtCodeFileList.cpp @@ -225,6 +225,19 @@ void QtCodeFileList::showContents() } } +void QtCodeFileList::scrollToLine(std::string filename, unsigned int line) +{ + for (std::shared_ptr file: m_files) + { + if( filename == file->getFilePath().str() ) + { + emit shouldScrollToSnippet(file->getFileSnippet(), line); + return; + } + } + +} + void QtCodeFileList::scrollToValue(int value) { m_value = value; diff --git a/src/lib_gui/qt/element/QtCodeFileList.h b/src/lib_gui/qt/element/QtCodeFileList.h index ef45ed4c..46032d72 100644 --- a/src/lib_gui/qt/element/QtCodeFileList.h +++ b/src/lib_gui/qt/element/QtCodeFileList.h @@ -64,6 +64,7 @@ public: void updateFiles(); void showContents(); void scrollToValue(int value); + void scrollToLine(std::string, unsigned int line); void scrollToActiveFileIfRequested(); private slots: diff --git a/src/lib_gui/qt/network/QtTcpWrapper.cpp b/src/lib_gui/qt/network/QtTcpWrapper.cpp index 462ae10c..c5b6329f 100644 --- a/src/lib_gui/qt/network/QtTcpWrapper.cpp +++ b/src/lib_gui/qt/network/QtTcpWrapper.cpp @@ -43,7 +43,7 @@ void QtTcpWrapper::sendMessage(const std::string& message) const data.append(message.c_str()); QTcpSocket socket; - socket.connectToHost(QHostAddress::LocalHost, 6666); + socket.connectToHost(QHostAddress::LocalHost, m_clientPort); if (socket.waitForConnected()) { diff --git a/src/lib_gui/qt/view/QtCodeView.cpp b/src/lib_gui/qt/view/QtCodeView.cpp index 7576c4d7..b89cd2a0 100644 --- a/src/lib_gui/qt/view/QtCodeView.cpp +++ b/src/lib_gui/qt/view/QtCodeView.cpp @@ -25,6 +25,7 @@ QtCodeView::QtCodeView(ViewLayout* viewLayout) , m_defocusTokenIdsFunctor(std::bind(&QtCodeView::doDefocusTokenIds, this)) , m_showContentsFunctor(std::bind(&QtCodeView::doShowContents, this)) , m_scrollToValueFunctor(std::bind(&QtCodeView::doScrollToValue, this, std::placeholders::_1)) + , m_scrollToLineFunctor(std::bind(&QtCodeView::doScrollToLine, this, std::placeholders::_1, std::placeholders::_2)) { m_widget = new QtCodeFileList(); setStyleSheet(); @@ -121,6 +122,11 @@ void QtCodeView::scrollToValue(int value) m_scrollToValueFunctor(value); } +void QtCodeView::scrollToLine(std::string filename, unsigned int line) +{ + m_scrollToLineFunctor(filename, line); +} + void QtCodeView::doRefreshView() { setStyleSheet(); @@ -232,6 +238,11 @@ void QtCodeView::doScrollToValue(int value) m_widget->scrollToValue(value); } +void QtCodeView::doScrollToLine(std::string filename, unsigned int line) +{ + m_widget->scrollToLine(filename, line); +} + void QtCodeView::setStyleSheet() const { utility::setWidgetBackgroundColor(m_widget, ColorScheme::getInstance()->getColor("code/background")); diff --git a/src/lib_gui/qt/view/QtCodeView.h b/src/lib_gui/qt/view/QtCodeView.h index d8192e11..a2a7bf35 100644 --- a/src/lib_gui/qt/view/QtCodeView.h +++ b/src/lib_gui/qt/view/QtCodeView.h @@ -47,6 +47,7 @@ public: virtual void showContents(); virtual void scrollToValue(int value); + virtual void scrollToLine(std::string filename, unsigned int line); private: void doRefreshView(); @@ -68,6 +69,7 @@ private: void doShowContents(); void doScrollToValue(int value); + void doScrollToLine(std::string filename, unsigned int line); void setStyleSheet() const; @@ -84,6 +86,7 @@ private: QtThreadedFunctor<> m_defocusTokenIdsFunctor; QtThreadedFunctor<> m_showContentsFunctor; QtThreadedFunctor m_scrollToValueFunctor; + QtThreadedFunctor m_scrollToLineFunctor; QtCodeFileList* m_widget;