ui: added maximize button to CodeSnippets that opens the full file in a separate window
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
@@ -7,6 +7,8 @@ add_files(
|
||||
|
||||
qt/element/QtCodeFile.cpp
|
||||
qt/element/QtCodeFile.h
|
||||
qt/element/QtCodeFileList.cpp
|
||||
qt/element/QtCodeFileList.h
|
||||
qt/element/QtButton.cpp
|
||||
qt/element/QtButton.h
|
||||
qt/element/QtCodeSnippet.cpp
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
|
||||
#include "qt/element/QtCodeSnippet.h"
|
||||
|
||||
QtCodeFile::QtCodeFile(QtCodeView* parentView, const std::string& fileName, QWidget *parent)
|
||||
QtCodeFile::QtCodeFile(const std::string& fileName, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_parentView(parentView)
|
||||
, m_fileName(fileName)
|
||||
{
|
||||
setObjectName("code_file");
|
||||
@@ -42,8 +41,7 @@ void QtCodeFile::addCodeSnippet(
|
||||
const std::vector<Id>& activeTokenIds
|
||||
){
|
||||
std::shared_ptr<QtCodeSnippet> 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);
|
||||
|
||||
|
||||
@@ -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<std::shared_ptr<QtCodeSnippet> > m_snippets;
|
||||
const std::string m_fileName;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
#include "qt/element/QtCodeFileList.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#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<QFrame>(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<Id>& activeTokenIds
|
||||
){
|
||||
std::string fileName = FileSystem::fileName(locationFile.getFilePath());
|
||||
QtCodeFile* file = nullptr;
|
||||
|
||||
for (std::shared_ptr<QtCodeFile> filePtr : m_files)
|
||||
{
|
||||
if (filePtr->getFileName() == fileName)
|
||||
{
|
||||
file = filePtr.get();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!file)
|
||||
{
|
||||
std::shared_ptr<QtCodeFile> filePtr = std::make_shared<QtCodeFile>(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();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef QT_CODE_FILE_LIST
|
||||
#define QT_CODE_FILE_LIST
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <QFrame>
|
||||
#include <QScrollArea>
|
||||
|
||||
#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<Id>& activeTokenIds
|
||||
);
|
||||
|
||||
void clearCodeSnippets();
|
||||
|
||||
private:
|
||||
std::shared_ptr<QFrame> m_frame;
|
||||
std::vector<std::shared_ptr<QtCodeFile> > m_files;
|
||||
};
|
||||
|
||||
#endif // QT_CODE_FILE_LIST
|
||||
@@ -1,14 +1,17 @@
|
||||
#include "qt/element/QtCodeSnippet.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QtWidgets>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPainter>
|
||||
#include <QPushButton>
|
||||
|
||||
#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();
|
||||
|
||||
@@ -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<Id> m_activeTokenIds;
|
||||
std::vector<Annotation> m_annotations;
|
||||
int m_digits;
|
||||
|
||||
std::vector<Annotation> m_annotations;
|
||||
const std::string m_filePath;
|
||||
};
|
||||
|
||||
#endif // QT_CODE_SNIPPET_H
|
||||
|
||||
@@ -1,21 +1,14 @@
|
||||
#include "qt/view/QtCodeView.h"
|
||||
|
||||
#include <QFrame>
|
||||
#include <QScrollArea>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#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<QtViewWidgetWrapper>(std::make_shared<QScrollArea>()));
|
||||
setWidgetWrapper(std::make_shared<QtViewWidgetWrapper>(
|
||||
std::shared_ptr<QtCodeFileList>(createQtCodeFileList())
|
||||
));
|
||||
}
|
||||
|
||||
void QtCodeView::initView()
|
||||
{
|
||||
QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this);
|
||||
widget->setObjectName("code_view");
|
||||
|
||||
QScrollArea* scroll = dynamic_cast<QScrollArea*>(widget);
|
||||
m_frame = std::make_shared<QFrame>(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<QtCodeFile> filePtr : m_files)
|
||||
{
|
||||
if (filePtr->getFileName() == fileName)
|
||||
{
|
||||
file = filePtr.get();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!file)
|
||||
{
|
||||
QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this);
|
||||
std::shared_ptr<QtCodeFile> filePtr = std::make_shared<QtCodeFile>(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<QtCodeFileList*>(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());
|
||||
}
|
||||
|
||||
@@ -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<QFrame> m_frame;
|
||||
std::vector<std::shared_ptr<QtCodeFile> > m_files;
|
||||
void setStyleSheet(QWidget* widget) const;
|
||||
|
||||
QtThreadedFunctor<> m_refreshViewFunctor;
|
||||
QtThreadedFunctor<> m_clearCodeSnippetsFunctor;
|
||||
QtThreadedFunctor<const CodeSnippetParams> m_addCodeSnippetFunctor;
|
||||
QtThreadedFunctor<const CodeSnippetParams&> m_showCodeFileFunctor;
|
||||
QtThreadedFunctor<const CodeSnippetParams&> m_addCodeSnippetFunctor;
|
||||
};
|
||||
|
||||
# endif // QT_CODE_VIEW_H
|
||||
|
||||
@@ -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<QtViewWidgetWrapper*>(view->getWidgetWrapper());
|
||||
|
||||
|
||||
@@ -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<QWidget> widget);
|
||||
virtual ~QtViewWidgetWrapper();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 = TextAccess::createFromFile(message->filePath);
|
||||
params.code = textAccess->getText();
|
||||
|
||||
params.locationFile = m_locationAccess->getTokenLocationsForFile(message->filePath);
|
||||
getView()->showCodeFile(params);
|
||||
}
|
||||
|
||||
CodeView* CodeController::getView()
|
||||
{
|
||||
return Controller::getView<CodeView>();
|
||||
|
||||
@@ -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<MessageActivateToken>
|
||||
, public MessageListener<MessageRefresh>
|
||||
, public MessageListener<MessageShowFile>
|
||||
{
|
||||
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();
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -19,7 +19,7 @@ void View::setWidgetWrapper(std::shared_ptr<ViewWidgetWrapper> widgetWrapper)
|
||||
m_widgetWrapper = widgetWrapper;
|
||||
}
|
||||
|
||||
ViewWidgetWrapper* View::getWidgetWrapper()
|
||||
ViewWidgetWrapper* View::getWidgetWrapper() const
|
||||
{
|
||||
return m_widgetWrapper.get();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
void setComponent(Component* component);
|
||||
|
||||
void setWidgetWrapper(std::shared_ptr<ViewWidgetWrapper> widgetWrapper);
|
||||
ViewWidgetWrapper* getWidgetWrapper();
|
||||
ViewWidgetWrapper* getWidgetWrapper() const;
|
||||
|
||||
int getMinWidth() const;
|
||||
int getMinHeight() const;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -86,8 +86,9 @@ public:
|
||||
|
||||
// LocationAccess implementation
|
||||
virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector<Id>& 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:
|
||||
|
||||
@@ -14,8 +14,9 @@ class LocationAccess
|
||||
public:
|
||||
virtual ~LocationAccess();
|
||||
virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector<Id>& 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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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("");
|
||||
|
||||
@@ -14,8 +14,9 @@ public:
|
||||
|
||||
// LocationAccess implementation
|
||||
virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector<Id>& 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:
|
||||
|
||||
@@ -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<MessageShowFile>
|
||||
{
|
||||
public:
|
||||
MessageShowFile(const std::string& filePath, uint lineNumber, const std::vector<Id>& activeTokenIds)
|
||||
: filePath(filePath)
|
||||
, lineNumber(lineNumber)
|
||||
, activeTokenIds(activeTokenIds)
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageShowFile";
|
||||
}
|
||||
|
||||
const std::string filePath;
|
||||
const uint lineNumber;
|
||||
const std::vector<Id> activeTokenIds;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_SHOW_FILE_H
|
||||
Reference in New Issue
Block a user