From dea79f701b8dc3ca44e1c790e649f7fbccd566e4 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Sun, 27 Jul 2014 16:13:59 +0200 Subject: [PATCH] ui: added maximize button to CodeSnippets that opens the full file in a separate window --- bin/app/data/gui/code_view/code_view.css | 18 +++- .../gui/code_view/images/button_maximize.png | Bin 0 -> 1267 bytes src/app/CMakeLists.txt | 2 + src/app/qt/element/QtCodeFile.cpp | 6 +- src/app/qt/element/QtCodeFile.h | 4 +- src/app/qt/element/QtCodeFileList.cpp | 63 ++++++++++++ src/app/qt/element/QtCodeFileList.h | 37 +++++++ src/app/qt/element/QtCodeSnippet.cpp | 44 ++++++-- src/app/qt/element/QtCodeSnippet.h | 18 ++-- src/app/qt/view/QtCodeView.cpp | 94 +++++++----------- src/app/qt/view/QtCodeView.h | 20 ++-- src/app/qt/view/QtViewWidgetWrapper.cpp | 2 +- src/app/qt/view/QtViewWidgetWrapper.h | 2 +- src/lib/CMakeLists.txt | 1 + .../component/controller/CodeController.cpp | 13 +++ src/lib/component/controller/CodeController.h | 3 + src/lib/component/view/CodeView.h | 3 +- src/lib/component/view/View.cpp | 2 +- src/lib/component/view/View.h | 2 +- src/lib/data/Storage.cpp | 32 ++++-- src/lib/data/Storage.h | 3 +- src/lib/data/access/LocationAccess.h | 3 +- src/lib/data/access/LocationAccessProxy.cpp | 19 +++- src/lib/data/access/LocationAccessProxy.h | 3 +- .../utility/messaging/type/MessageShowFile.h | 27 +++++ 25 files changed, 309 insertions(+), 112 deletions(-) create mode 100644 bin/app/data/gui/code_view/images/button_maximize.png create mode 100644 src/app/qt/element/QtCodeFileList.cpp create mode 100644 src/app/qt/element/QtCodeFileList.h create mode 100644 src/lib/utility/messaging/type/MessageShowFile.h diff --git a/bin/app/data/gui/code_view/code_view.css b/bin/app/data/gui/code_view/code_view.css index 4c1e83fa..c9e978cc 100644 --- a/bin/app/data/gui/code_view/code_view.css +++ b/bin/app/data/gui/code_view/code_view.css @@ -1,4 +1,4 @@ -#code_view #code_file QLabel#title_label { +#code_file #title_label { background-color: rgb(220,220,220); border-top-right-radius: 10px; font-family: "Source Code Pro"; @@ -6,14 +6,26 @@ padding: 4px 12px; } -#code_view #code_file #code_snippet { +#code_snippet { font-family: "Source Code Pro"; font-size: 14px; margin-bottom: 2px; } -#code_view #code_file #code_snippet #line_number_area { +#code_snippet #line_number_area { background-color: white; font-family: "Source Code Pro"; font-size: 14px; } + +#code_snippet #maximize_button { + border: none; + border-image: none; + margin: 5px; + max-height: 16px; + max-width: 16px; +} + +#code_snippet #maximize_button:enabled { + border-image: url(data/gui/code_view/images/button_maximize.png); +} diff --git a/bin/app/data/gui/code_view/images/button_maximize.png b/bin/app/data/gui/code_view/images/button_maximize.png new file mode 100644 index 0000000000000000000000000000000000000000..01830e9603df36a8930ccc6446b552edfc0ab959 GIT binary patch literal 1267 zcmVv@5{30%Zm23J5C@R{*Zy;R;?m*Vto6IMIm%5@$}{s~az-g$BCq`nk~OB$b+A z+kHPyRo$k3v=XlS`}@dLEmIm?*SXH4#FQ!5&s--*M@Lhs&#Q$6pMp&Q+FZ9B{VM_! zn{r3BBtTjSgcDObT!+xulv}Dp!_fgjkONLlITO}uj7+&PVB$&uF(3%Qxx?njX0vu} zz>KyM2!rUE(o~zJi79v^3VoKnx6m@OO)ws60*B zv4N75y->~4aQ3mnFcd%gBgZ0~L-+=U3QDV6CTG!rAq$EI3|UY#V90`^3&Ln|2M*=e zVUf|7E&!t`Wi++7x2JY?cGiCG?d?r{e0)e45+CNxQ*=%kbZk^HlDHJVLGvkI%I*Vk9|^72ypIyHPLWeGq41OgBM zfdB+RAOHan$hUr}&-HIs-e=KzzK4eg=Qq89YYg)$A%{%yy%eKqjU56Ba>z5{AV$w{ zh%|?U+AtVe6tS2Md*KoR?nvh$a7lQ@X&`rqM{wQ2AyOT}yVQ&klVJKfCL{eW>lSed zrmxtifxsaF9kKv~Ei*!Fyla%+*lhmw`wimbUEg9}o6i)HB>GJT=iiiM{Xlh%IC;}T ztQUarKC=_V%DE<4d-^W>3Ac}UIag+kGl4KUWbY2M@?|?-*NPH^+__^V5bpg4h@F$X zBQ6XiMG})B?1^G|x#|Nefp7-dMI5cEyKcMjwG-v|XgD-od}8nf6`4aORLXw?yjmG?{3_LByu?T`zFbzMh7M#{{Oi zVIU?9V&vnWY2Q!BVCZBS>3coWsOj1lh+shGnld`fIx5@= z4b(x?l7MlZ6P>pjNCq5oPMd32&04~pG%X{GLqiY?WJS|PU>aN(*{eR`oPlcEAR&>y d4E(& activeTokenIds ){ std::shared_ptr snippet( - new QtCodeSnippet(m_parentView, startLineNumber, code, locationFile, activeTokenIds, this) - ); + new QtCodeSnippet(startLineNumber, code, locationFile, activeTokenIds, this)); layout()->addWidget(snippet.get()); m_snippets.push_back(snippet); diff --git a/src/app/qt/element/QtCodeFile.h b/src/app/qt/element/QtCodeFile.h index 8a632e18..9f9c6a39 100644 --- a/src/app/qt/element/QtCodeFile.h +++ b/src/app/qt/element/QtCodeFile.h @@ -10,13 +10,12 @@ #include "utility/types.h" class QtCodeSnippet; -class QtCodeView; class TokenLocationFile; class QtCodeFile : public QWidget { public: - QtCodeFile(QtCodeView* parentView, const std::string& fileName, QWidget *parent); + QtCodeFile(const std::string& fileName, QWidget *parent = 0); virtual ~QtCodeFile(); const std::string& getFileName() const; @@ -29,7 +28,6 @@ public: ); private: - QtCodeView* m_parentView; std::vector > m_snippets; const std::string m_fileName; }; diff --git a/src/app/qt/element/QtCodeFileList.cpp b/src/app/qt/element/QtCodeFileList.cpp new file mode 100644 index 00000000..9ce10ccc --- /dev/null +++ b/src/app/qt/element/QtCodeFileList.cpp @@ -0,0 +1,63 @@ +#include "qt/element/QtCodeFileList.h" + +#include + +#include "data/location/TokenLocationFile.h" +#include "qt/element/QtCodeFile.h" +#include "utility/FileSystem.h" + +QtCodeFileList::QtCodeFileList(QWidget* parent) + : QScrollArea(parent) +{ + m_frame = std::make_shared(this); + + QVBoxLayout* layout = new QVBoxLayout(m_frame.get()); + layout->setSpacing(10); + layout->setContentsMargins(15, 15, 15, 15); + layout->setAlignment(Qt::AlignTop); + m_frame->setLayout(layout); + + setWidgetResizable(true); + setWidget(m_frame.get()); + + setObjectName("code_file_list"); +} + +QtCodeFileList::~QtCodeFileList() +{ +} + +void QtCodeFileList::addCodeSnippet( + int startLineNumber, + const std::string& code, + const TokenLocationFile& locationFile, + const std::vector& activeTokenIds +){ + std::string fileName = FileSystem::fileName(locationFile.getFilePath()); + QtCodeFile* file = nullptr; + + for (std::shared_ptr filePtr : m_files) + { + if (filePtr->getFileName() == fileName) + { + file = filePtr.get(); + break; + } + } + + if (!file) + { + std::shared_ptr filePtr = std::make_shared(fileName, this); + m_files.push_back(filePtr); + + file = filePtr.get(); + m_frame->layout()->addWidget(file); + } + + file->addCodeSnippet(startLineNumber, code, locationFile, activeTokenIds); +} + +void QtCodeFileList::clearCodeSnippets() +{ + m_files.clear(); +} diff --git a/src/app/qt/element/QtCodeFileList.h b/src/app/qt/element/QtCodeFileList.h new file mode 100644 index 00000000..18334f65 --- /dev/null +++ b/src/app/qt/element/QtCodeFileList.h @@ -0,0 +1,37 @@ +#ifndef QT_CODE_FILE_LIST +#define QT_CODE_FILE_LIST + +#include +#include + +#include +#include + +#include "utility/types.h" + +class QtCodeFile; +class TokenLocationFile; + +class QtCodeFileList: public QScrollArea +{ + Q_OBJECT + +public: + QtCodeFileList(QWidget* parent = 0); + virtual ~QtCodeFileList(); + + void addCodeSnippet( + int startLineNumber, + const std::string& code, + const TokenLocationFile& locationFile, + const std::vector& activeTokenIds + ); + + void clearCodeSnippets(); + +private: + std::shared_ptr m_frame; + std::vector > m_files; +}; + +#endif // QT_CODE_FILE_LIST diff --git a/src/app/qt/element/QtCodeSnippet.cpp b/src/app/qt/element/QtCodeSnippet.cpp index 2e866dde..f9fb1140 100644 --- a/src/app/qt/element/QtCodeSnippet.cpp +++ b/src/app/qt/element/QtCodeSnippet.cpp @@ -1,14 +1,17 @@ #include "qt/element/QtCodeSnippet.h" #include -#include +#include +#include +#include #include "ApplicationSettings.h" #include "data/location/TokenLocation.h" #include "data/location/TokenLocationFile.h" #include "data/location/TokenLocationLine.h" #include "qt/utility/QtHighLighter.h" -#include "qt/view/QtCodeView.h" +#include "utility/messaging/type/MessageActivateToken.h" +#include "utility/messaging/type/MessageShowFile.h" QtCodeSnippet::LineNumberArea::LineNumberArea(QtCodeSnippet *codeSnippet) : QWidget(codeSnippet) @@ -33,7 +36,6 @@ void QtCodeSnippet::LineNumberArea::paintEvent(QPaintEvent *event) QtCodeSnippet::QtCodeSnippet( - QtCodeView* parentView, int startLineNumber, const std::string& code, const TokenLocationFile& locationFile, @@ -41,10 +43,10 @@ QtCodeSnippet::QtCodeSnippet( QWidget *parent ) : QPlainTextEdit(parent) - , m_parentView(parentView) , m_startLineNumber(startLineNumber) , m_activeTokenIds(activeTokenIds) , m_digits(0) + , m_filePath(locationFile.getFilePath()) { setObjectName("code_snippet"); m_lineNumberArea = new LineNumberArea(this); @@ -66,9 +68,22 @@ QtCodeSnippet::QtCodeSnippet( setPlainText(QString::fromUtf8(displayCode.c_str())); annotateText(locationFile); + QHBoxLayout* layout = new QHBoxLayout(); + layout->setMargin(0); + layout->setSpacing(0); + layout->setAlignment(Qt::AlignTop); + setLayout(layout); + + m_maximizeButton = new QPushButton(this); + m_maximizeButton->setObjectName("maximize_button"); + m_maximizeButton->setEnabled(false); + layout->addWidget(m_maximizeButton); + layout->setAlignment(m_maximizeButton, Qt::AlignRight); + connect(m_maximizeButton, SIGNAL(clicked()), this, SLOT(clickedMaximizeButton())); + connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int))); - connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(clickTokenLocation())); + connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(clickedTokenLocation())); connect(this, SIGNAL(selectionChanged()), this, SLOT(clearSelection())); m_digits = lineNumberDigits(); @@ -213,6 +228,16 @@ void QtCodeSnippet::showEvent(QShowEvent* event) setMaximumHeight(sizeHint().height()); } +void QtCodeSnippet::enterEvent(QEvent* event) +{ + m_maximizeButton->setEnabled(true); +} + +void QtCodeSnippet::leaveEvent(QEvent* event) +{ + m_maximizeButton->setEnabled(false); +} + void QtCodeSnippet::updateLineNumberAreaWidth(int /* newBlockCount */) { setViewportMargins(lineNumberAreaWidth(), 0, 0, 0); @@ -235,7 +260,7 @@ void QtCodeSnippet::updateLineNumberArea(const QRect &rect, int dy) } } -void QtCodeSnippet::clickTokenLocation() +void QtCodeSnippet::clickedTokenLocation() { int clickPosition = textCursor().position(); int diff = endTextEditPosition() + 1; @@ -256,10 +281,15 @@ void QtCodeSnippet::clickTokenLocation() if (tokenId) { - m_parentView->activateToken(tokenId); + MessageActivateToken(tokenId).dispatch(); } } +void QtCodeSnippet::clickedMaximizeButton() +{ + MessageShowFile(m_filePath, m_startLineNumber, m_activeTokenIds).dispatch(); +} + void QtCodeSnippet::clearSelection() { QTextCursor cursor = textCursor(); diff --git a/src/app/qt/element/QtCodeSnippet.h b/src/app/qt/element/QtCodeSnippet.h index a0e6c1ed..a3adc386 100644 --- a/src/app/qt/element/QtCodeSnippet.h +++ b/src/app/qt/element/QtCodeSnippet.h @@ -8,9 +8,9 @@ #include "utility/types.h" class QPaintEvent; +class QPushButton; class QResizeEvent; class QSize; -class QtCodeView; class QtHighlighter; class QWidget; class TokenLocationFile; @@ -29,14 +29,13 @@ public: QSize sizeHint() const; protected: - void paintEvent(QPaintEvent *event); + void paintEvent(QPaintEvent* event); private: QtCodeSnippet *m_codeSnippet; }; QtCodeSnippet( - QtCodeView* parentView, int startLineNumber, const std::string& code, const TokenLocationFile& locationFile, @@ -57,11 +56,14 @@ public: protected: virtual void resizeEvent(QResizeEvent *event); virtual void showEvent(QShowEvent* event); + virtual void enterEvent(QEvent* event); + virtual void leaveEvent(QEvent* event); private slots: void updateLineNumberAreaWidth(int newBlockCount); void updateLineNumberArea(const QRect &, int); - void clickTokenLocation(); + void clickedTokenLocation(); + void clickedMaximizeButton(); void clearSelection(); private: @@ -76,15 +78,17 @@ private: int startTextEditPosition() const; int endTextEditPosition() const; - QtCodeView* m_parentView; QtHighlighter* m_highlighter; - QWidget *m_lineNumberArea; + QWidget* m_lineNumberArea; + QPushButton* m_maximizeButton; + const int m_startLineNumber; const std::vector m_activeTokenIds; + std::vector m_annotations; int m_digits; - std::vector m_annotations; + const std::string m_filePath; }; #endif // QT_CODE_SNIPPET_H diff --git a/src/app/qt/view/QtCodeView.cpp b/src/app/qt/view/QtCodeView.cpp index 0d6c4970..1654de53 100644 --- a/src/app/qt/view/QtCodeView.cpp +++ b/src/app/qt/view/QtCodeView.cpp @@ -1,21 +1,14 @@ #include "qt/view/QtCodeView.h" -#include -#include -#include - -#include "data/location/TokenLocationFile.h" -#include "qt/element/QtCodeFile.h" -#include "qt/utility/utilityQt.h" +#include "qt/element/QtCodeFileList.h" #include "qt/view/QtViewWidgetWrapper.h" -#include "utility/FileSystem.h" -#include "utility/messaging/type/MessageActivateToken.h" #include "utility/text/TextAccess.h" QtCodeView::QtCodeView(ViewLayout* viewLayout) : CodeView(viewLayout) , m_refreshViewFunctor(std::bind(&QtCodeView::doRefreshView, this)) , m_clearCodeSnippetsFunctor(std::bind(&QtCodeView::doClearCodeSnippets, this)) + , m_showCodeFileFunctor(std::bind(&QtCodeView::doShowCodeFile, this, std::placeholders::_1)) , m_addCodeSnippetFunctor(std::bind(&QtCodeView::doAddCodeSnippet, this, std::placeholders::_1)) { } @@ -26,27 +19,13 @@ QtCodeView::~QtCodeView() void QtCodeView::createWidgetWrapper() { - setWidgetWrapper(std::make_shared(std::make_shared())); + setWidgetWrapper(std::make_shared( + std::shared_ptr(createQtCodeFileList()) + )); } void QtCodeView::initView() { - QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this); - widget->setObjectName("code_view"); - - QScrollArea* scroll = dynamic_cast(widget); - m_frame = std::make_shared(scroll); - - QVBoxLayout* layout = new QVBoxLayout(m_frame.get()); - layout->setSpacing(10); - layout->setContentsMargins(15, 15, 15, 15); - layout->setAlignment(Qt::AlignTop); - m_frame->setLayout(layout); - - scroll->setWidgetResizable(true); - scroll->setWidget(m_frame.get()); - - setStyleSheet(); } void QtCodeView::refreshView() @@ -54,7 +33,12 @@ void QtCodeView::refreshView() m_refreshViewFunctor(); } -void QtCodeView::addCodeSnippet(const CodeSnippetParams params) +void QtCodeView::showCodeFile(const CodeSnippetParams& params) +{ + m_showCodeFileFunctor(params); +} + +void QtCodeView::addCodeSnippet(const CodeSnippetParams& params) { m_addCodeSnippetFunctor(params); } @@ -64,51 +48,41 @@ void QtCodeView::clearCodeSnippets() m_clearCodeSnippetsFunctor(); } -void QtCodeView::activateToken(Id tokenId) const -{ - MessageActivateToken message(tokenId); - message.dispatch(); -} - void QtCodeView::doRefreshView() { - setStyleSheet(); + setStyleSheet(getQtCodeFileList()); } -void QtCodeView::doAddCodeSnippet(const CodeSnippetParams params) +void QtCodeView::doShowCodeFile(const CodeSnippetParams& params) { - std::string fileName = FileSystem::fileName(params.locationFile.getFilePath()); - QtCodeFile* file = nullptr; + QtCodeFileList* list = createQtCodeFileList(); + list->addCodeSnippet(1, params.code, params.locationFile, params.activeTokenIds); + list->show(); +} - for (std::shared_ptr filePtr : m_files) - { - if (filePtr->getFileName() == fileName) - { - file = filePtr.get(); - break; - } - } - - if (!file) - { - QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this); - std::shared_ptr filePtr = std::make_shared(this, fileName, widget); - - m_files.push_back(filePtr); - file = filePtr.get(); - m_frame->layout()->addWidget(file); - } - - file->addCodeSnippet(params.startLineNumber, params.code, params.locationFile, params.activeTokenIds); +void QtCodeView::doAddCodeSnippet(const CodeSnippetParams& params) +{ + getQtCodeFileList()->addCodeSnippet(params.startLineNumber, params.code, params.locationFile, params.activeTokenIds); } void QtCodeView::doClearCodeSnippets() { - m_files.clear(); + getQtCodeFileList()->clearCodeSnippets(); } -void QtCodeView::setStyleSheet() +QtCodeFileList* QtCodeView::getQtCodeFileList() const +{ + return dynamic_cast(QtViewWidgetWrapper::getWidgetOfView(this)); +} + +QtCodeFileList* QtCodeView::createQtCodeFileList() const +{ + QtCodeFileList* list = new QtCodeFileList(); + setStyleSheet(list); + return list; +} + +void QtCodeView::setStyleSheet(QWidget* widget) const { - QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this); widget->setStyleSheet(TextAccess::createFromFile("data/gui/code_view/code_view.css")->getText().c_str()); } diff --git a/src/app/qt/view/QtCodeView.h b/src/app/qt/view/QtCodeView.h index f657a929..b25a7f44 100644 --- a/src/app/qt/view/QtCodeView.h +++ b/src/app/qt/view/QtCodeView.h @@ -9,7 +9,8 @@ #include "utility/types.h" class QFrame; -class QtCodeFile; +class QtCodeFileList; +class QWidget; class QtCodeView: public CodeView { @@ -23,24 +24,25 @@ public: virtual void refreshView(); // CodeView implementation - virtual void addCodeSnippet(const CodeSnippetParams params); + virtual void showCodeFile(const CodeSnippetParams& params); + virtual void addCodeSnippet(const CodeSnippetParams& params); virtual void clearCodeSnippets(); - void activateToken(Id tokenId) const; - private: void doRefreshView(); - void doAddCodeSnippet(const CodeSnippetParams params); + void doShowCodeFile(const CodeSnippetParams& params); + void doAddCodeSnippet(const CodeSnippetParams& params); void doClearCodeSnippets(); - void setStyleSheet(); + QtCodeFileList* getQtCodeFileList() const; + QtCodeFileList* createQtCodeFileList() const; - std::shared_ptr m_frame; - std::vector > m_files; + void setStyleSheet(QWidget* widget) const; QtThreadedFunctor<> m_refreshViewFunctor; QtThreadedFunctor<> m_clearCodeSnippetsFunctor; - QtThreadedFunctor m_addCodeSnippetFunctor; + QtThreadedFunctor m_showCodeFileFunctor; + QtThreadedFunctor m_addCodeSnippetFunctor; }; # endif // QT_CODE_VIEW_H diff --git a/src/app/qt/view/QtViewWidgetWrapper.cpp b/src/app/qt/view/QtViewWidgetWrapper.cpp index 4d5e9d9c..4c66e1ac 100644 --- a/src/app/qt/view/QtViewWidgetWrapper.cpp +++ b/src/app/qt/view/QtViewWidgetWrapper.cpp @@ -3,7 +3,7 @@ #include "component/view/View.h" #include "utility/logging/logging.h" -QWidget* QtViewWidgetWrapper::getWidgetOfView(View* view) +QWidget* QtViewWidgetWrapper::getWidgetOfView(const View* view) { QtViewWidgetWrapper* widgetWrapper = dynamic_cast(view->getWidgetWrapper()); diff --git a/src/app/qt/view/QtViewWidgetWrapper.h b/src/app/qt/view/QtViewWidgetWrapper.h index 4df7fece..9d52a36f 100644 --- a/src/app/qt/view/QtViewWidgetWrapper.h +++ b/src/app/qt/view/QtViewWidgetWrapper.h @@ -12,7 +12,7 @@ class View; class QtViewWidgetWrapper: public ViewWidgetWrapper { public: - static QWidget* getWidgetOfView(View* view); + static QWidget* getWidgetOfView(const View* view); QtViewWidgetWrapper(std::shared_ptr widget); virtual ~QtViewWidgetWrapper(); diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index edb582c6..73869549 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -162,6 +162,7 @@ add_files( utility/messaging/type/MessageLoadProject.h utility/messaging/type/MessageLoadSource.h utility/messaging/type/MessageRefresh.h + utility/messaging/type/MessageShowFile.h utility/messaging/Message.h utility/messaging/MessageBase.h diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index 6b16c4f5..caaad846 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -67,6 +67,19 @@ void CodeController::handleMessage(MessageRefresh* message) getView()->refreshView(); } +void CodeController::handleMessage(MessageShowFile* message) +{ + CodeView::CodeSnippetParams params; + params.startLineNumber = message->lineNumber; + params.activeTokenIds = message->activeTokenIds; + + std::shared_ptr textAccess = TextAccess::createFromFile(message->filePath); + params.code = textAccess->getText(); + + params.locationFile = m_locationAccess->getTokenLocationsForFile(message->filePath); + getView()->showCodeFile(params); +} + CodeView* CodeController::getView() { return Controller::getView(); diff --git a/src/lib/component/controller/CodeController.h b/src/lib/component/controller/CodeController.h index fac025c1..98fbef60 100644 --- a/src/lib/component/controller/CodeController.h +++ b/src/lib/component/controller/CodeController.h @@ -7,6 +7,7 @@ #include "utility/messaging/MessageListener.h" #include "utility/messaging/type/MessageActivateToken.h" #include "utility/messaging/type/MessageRefresh.h" +#include "utility/messaging/type/MessageShowFile.h" #include "utility/types.h" class CodeView; @@ -24,6 +25,7 @@ class CodeController : public Controller , public MessageListener , public MessageListener + , public MessageListener { public: CodeController(GraphAccess* graphAccess, LocationAccess* locationAccess); @@ -34,6 +36,7 @@ public: private: virtual void handleMessage(MessageActivateToken* message); virtual void handleMessage(MessageRefresh* message); + virtual void handleMessage(MessageShowFile* message); CodeView* getView(); diff --git a/src/lib/component/view/CodeView.h b/src/lib/component/view/CodeView.h index c97b6eae..5689c617 100644 --- a/src/lib/component/view/CodeView.h +++ b/src/lib/component/view/CodeView.h @@ -25,7 +25,8 @@ public: virtual std::string getName() const; - virtual void addCodeSnippet(const CodeSnippetParams params) = 0; + virtual void showCodeFile(const CodeSnippetParams& params) = 0; + virtual void addCodeSnippet(const CodeSnippetParams& params) = 0; virtual void clearCodeSnippets() = 0; private: diff --git a/src/lib/component/view/View.cpp b/src/lib/component/view/View.cpp index 885b1d3e..13faea36 100644 --- a/src/lib/component/view/View.cpp +++ b/src/lib/component/view/View.cpp @@ -19,7 +19,7 @@ void View::setWidgetWrapper(std::shared_ptr widgetWrapper) m_widgetWrapper = widgetWrapper; } -ViewWidgetWrapper* View::getWidgetWrapper() +ViewWidgetWrapper* View::getWidgetWrapper() const { return m_widgetWrapper.get(); } diff --git a/src/lib/component/view/View.h b/src/lib/component/view/View.h index 501e5416..a4a5f8ee 100644 --- a/src/lib/component/view/View.h +++ b/src/lib/component/view/View.h @@ -27,7 +27,7 @@ public: void setComponent(Component* component); void setWidgetWrapper(std::shared_ptr widgetWrapper); - ViewWidgetWrapper* getWidgetWrapper(); + ViewWidgetWrapper* getWidgetWrapper() const; int getMinWidth() const; int getMinHeight() const; diff --git a/src/lib/data/Storage.cpp b/src/lib/data/Storage.cpp index 5ed2cf94..7051c968 100644 --- a/src/lib/data/Storage.cpp +++ b/src/lib/data/Storage.cpp @@ -469,19 +469,39 @@ TokenLocationCollection Storage::getTokenLocationsForLocationIds(const std::vect return ret; } -TokenLocationFile Storage::getTokenLocationsForLinesInFile( - const std::string& fileName, unsigned int firstLineNumber, unsigned int lastLineNumber -) const +TokenLocationFile Storage::getTokenLocationsForFile(const std::string& filePath) const { - TokenLocationFile ret(fileName); + TokenLocationFile ret(filePath); - TokenLocationFile* locationFile = m_locationCollection.findTokenLocationFileByPath(fileName); + TokenLocationFile* locationFile = m_locationCollection.findTokenLocationFileByPath(filePath); if (!locationFile) { return ret; } - for (unsigned int i = firstLineNumber; i <= lastLineNumber; i++) + locationFile->forEachTokenLocation( + [&](TokenLocation* tokenLocation) -> void + { + ret.addTokenLocationAsPlainCopy(tokenLocation); + } + ); + + return ret; +} + +TokenLocationFile Storage::getTokenLocationsForLinesInFile( + const std::string& filePath, uint firstLineNumber, uint lastLineNumber +) const +{ + TokenLocationFile ret(filePath); + + TokenLocationFile* locationFile = m_locationCollection.findTokenLocationFileByPath(filePath); + if (!locationFile) + { + return ret; + } + + for (uint i = firstLineNumber; i <= lastLineNumber; i++) { TokenLocationLine* locationLine = locationFile->findTokenLocationLineByNumber(i); if (!locationLine) diff --git a/src/lib/data/Storage.h b/src/lib/data/Storage.h index 55e93be2..21a3ea5c 100644 --- a/src/lib/data/Storage.h +++ b/src/lib/data/Storage.h @@ -86,8 +86,9 @@ public: // LocationAccess implementation virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector& locationIds) const; + virtual TokenLocationFile getTokenLocationsForFile(const std::string& filePath) const; virtual TokenLocationFile getTokenLocationsForLinesInFile( - const std::string& fileName, unsigned int firstLineNumber, unsigned int lastLineNumber + const std::string& filePath, uint firstLineNumber, uint lastLineNumber ) const; private: diff --git a/src/lib/data/access/LocationAccess.h b/src/lib/data/access/LocationAccess.h index ab3284e3..8a73ff9b 100644 --- a/src/lib/data/access/LocationAccess.h +++ b/src/lib/data/access/LocationAccess.h @@ -14,8 +14,9 @@ class LocationAccess public: virtual ~LocationAccess(); virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector& locationIds) const = 0; + virtual TokenLocationFile getTokenLocationsForFile(const std::string& filePath) const = 0; virtual TokenLocationFile getTokenLocationsForLinesInFile( - const std::string& fileName, unsigned int firstLineNumber, unsigned int lastLineNumber + const std::string& filePath, uint firstLineNumber, uint lastLineNumber ) const = 0; }; diff --git a/src/lib/data/access/LocationAccessProxy.cpp b/src/lib/data/access/LocationAccessProxy.cpp index 40fffe21..78dc5368 100644 --- a/src/lib/data/access/LocationAccessProxy.cpp +++ b/src/lib/data/access/LocationAccessProxy.cpp @@ -39,14 +39,23 @@ TokenLocationCollection LocationAccessProxy::getTokenLocationsForLocationIds(con return TokenLocationCollection(); } - -TokenLocationFile LocationAccessProxy::getTokenLocationsForLinesInFile( - const std::string& fileName, unsigned int firstLineNumber, unsigned int lastLineNumber -) const +TokenLocationFile LocationAccessProxy::getTokenLocationsForFile(const std::string& filePath) const { if (hasSubject()) { - return m_subject->getTokenLocationsForLinesInFile(fileName, firstLineNumber, lastLineNumber); + return m_subject->getTokenLocationsForFile(filePath); + } + + return TokenLocationFile(""); +} + +TokenLocationFile LocationAccessProxy::getTokenLocationsForLinesInFile( + const std::string& filePath, uint firstLineNumber, uint lastLineNumber +) const +{ + if (hasSubject()) + { + return m_subject->getTokenLocationsForLinesInFile(filePath, firstLineNumber, lastLineNumber); } return TokenLocationFile(""); diff --git a/src/lib/data/access/LocationAccessProxy.h b/src/lib/data/access/LocationAccessProxy.h index fe8c1ce9..53ada5ab 100644 --- a/src/lib/data/access/LocationAccessProxy.h +++ b/src/lib/data/access/LocationAccessProxy.h @@ -14,8 +14,9 @@ public: // LocationAccess implementation virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector& locationIds) const; + virtual TokenLocationFile getTokenLocationsForFile(const std::string& filePath) const; virtual TokenLocationFile getTokenLocationsForLinesInFile( - const std::string& fileName, unsigned int firstLineNumber, unsigned int lastLineNumber + const std::string& filePath, uint firstLineNumber, uint lastLineNumber ) const; private: diff --git a/src/lib/utility/messaging/type/MessageShowFile.h b/src/lib/utility/messaging/type/MessageShowFile.h new file mode 100644 index 00000000..8edee258 --- /dev/null +++ b/src/lib/utility/messaging/type/MessageShowFile.h @@ -0,0 +1,27 @@ +#ifndef MESSAGE_SHOW_FILE_H +#define MESSAGE_SHOW_FILE_H + +#include "utility/messaging/Message.h" +#include "utility/types.h" + +class MessageShowFile: public Message +{ +public: + MessageShowFile(const std::string& filePath, uint lineNumber, const std::vector& activeTokenIds) + : filePath(filePath) + , lineNumber(lineNumber) + , activeTokenIds(activeTokenIds) + { + } + + static const std::string getStaticType() + { + return "MessageShowFile"; + } + + const std::string filePath; + const uint lineNumber; + const std::vector activeTokenIds; +}; + +#endif // MESSAGE_SHOW_FILE_H