ui: Added show definition context menu action for graph nodes (issue #83)
* use 'show definition' context menu action or 'Ctrl/Cmd + Left Click' to show definition of node in code
This commit is contained in:
@@ -120,44 +120,49 @@ QtCodeSnippet* QtCodeFile::addCodeSnippet(const CodeSnippetParams& params)
|
||||
|
||||
QtCodeSnippet* QtCodeFile::insertCodeSnippet(const CodeSnippetParams& params)
|
||||
{
|
||||
QtCodeSnippet* snippet = new QtCodeSnippet(params, m_navigator, this);
|
||||
QtCodeSnippet* newSnippet = new QtCodeSnippet(params, m_navigator, this);
|
||||
|
||||
size_t i = 0;
|
||||
while (i < m_snippets.size())
|
||||
{
|
||||
uint start = snippet->getStartLineNumber();
|
||||
uint end = snippet->getEndLineNumber();
|
||||
uint start = newSnippet->getStartLineNumber();
|
||||
uint end = newSnippet->getEndLineNumber();
|
||||
|
||||
QtCodeSnippet* s = m_snippets[i];
|
||||
QtCodeSnippet* oldSnippet = m_snippets[i];
|
||||
|
||||
if (s->getEndLineNumber() + 1 < start)
|
||||
if (oldSnippet->getEndLineNumber() + 1 < start) // before
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
else if (s->getStartLineNumber() > end + 1)
|
||||
else if (oldSnippet->getStartLineNumber() > end + 1) // after
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (s->getStartLineNumber() < start || s->getEndLineNumber() > end)
|
||||
else if (oldSnippet->getStartLineNumber() <= start && oldSnippet->getEndLineNumber() >= end) // containing
|
||||
{
|
||||
newSnippet->deleteLater();
|
||||
return oldSnippet;
|
||||
}
|
||||
else if (oldSnippet->getStartLineNumber() < start || oldSnippet->getEndLineNumber() > end) // overlaping
|
||||
{
|
||||
m_navigator->clearSnippetReferences();
|
||||
snippet = QtCodeSnippet::merged(snippet, s, m_navigator, this);
|
||||
newSnippet = QtCodeSnippet::merged(newSnippet, oldSnippet, m_navigator, this);
|
||||
}
|
||||
|
||||
s->hide();
|
||||
m_snippetLayout->removeWidget(s);
|
||||
s->deleteLater();
|
||||
oldSnippet->hide();
|
||||
m_snippetLayout->removeWidget(oldSnippet);
|
||||
oldSnippet->deleteLater();
|
||||
|
||||
m_snippets.erase(m_snippets.begin() + i);
|
||||
}
|
||||
|
||||
m_snippetLayout->insertWidget(i, snippet);
|
||||
m_snippets.insert(m_snippets.begin() + i, snippet);
|
||||
m_snippetLayout->insertWidget(i, newSnippet);
|
||||
m_snippets.insert(m_snippets.begin() + i, newSnippet);
|
||||
|
||||
setSnippets();
|
||||
|
||||
return snippet;
|
||||
return newSnippet;
|
||||
}
|
||||
|
||||
void QtCodeFile::updateCodeSnippet(const CodeSnippetParams& params)
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "qt/utility/QtFileDialog.h"
|
||||
#include "qt/utility/utilityQt.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "utility/messaging/type/code/MessageCodeShowDefinition.h"
|
||||
#include "utility/messaging/type/MessageDisplayBookmarkCreator.h"
|
||||
#include "utility/messaging/type/MessageGraphNodeHide.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
@@ -51,29 +52,37 @@ QtGraphicsView::QtGraphicsView(QWidget* parent)
|
||||
m_zoomLabelTimer = std::make_shared<QTimer>(this);
|
||||
connect(m_zoomLabelTimer.get(), &QTimer::timeout, this, &QtGraphicsView::hideZoomLabel);
|
||||
|
||||
m_exportGraphAction = new QAction(tr("Save as Image"), this);
|
||||
m_exportGraphAction->setStatusTip(tr("Save this graph as image file"));
|
||||
m_exportGraphAction->setToolTip(tr("Save this graph as image file"));
|
||||
m_exportGraphAction = new QAction("Save as Image", this);
|
||||
m_exportGraphAction->setStatusTip("Save this graph as image file");
|
||||
m_exportGraphAction->setToolTip("Save this graph as image file");
|
||||
connect(m_exportGraphAction, &QAction::triggered, this, &QtGraphicsView::exportGraph);
|
||||
|
||||
m_copyNodeNameAction = new QAction(tr("Copy Name"), this);
|
||||
m_copyNodeNameAction->setStatusTip(tr("Copies the name of this node to the clipboard"));
|
||||
m_copyNodeNameAction->setToolTip(tr("Copies the name of this node to the clipboard"));
|
||||
m_copyNodeNameAction = new QAction("Copy Name", this);
|
||||
m_copyNodeNameAction->setStatusTip("Copies the name of this node to the clipboard");
|
||||
m_copyNodeNameAction->setToolTip("Copies the name of this node to the clipboard");
|
||||
connect(m_copyNodeNameAction, &QAction::triggered, this, &QtGraphicsView::copyNodeName);
|
||||
|
||||
m_hideNodeAction = new QAction(tr("Hide Node (Alt + Left Click)"), this);
|
||||
m_hideNodeAction->setStatusTip(tr("Hide the node from this graph"));
|
||||
m_hideNodeAction->setToolTip(tr("Hide the node from this graph"));
|
||||
m_showDefinitionAction = new QAction("Show Definition (Ctrl + Left Click)", this);
|
||||
#if defined(Q_OS_MAC)
|
||||
m_showDefinitionAction->setText("Show Definition (Cmd + Left Click)");
|
||||
#endif
|
||||
m_showDefinitionAction->setStatusTip("Show definition of this symbol in the code");
|
||||
m_showDefinitionAction->setToolTip("Show definition of this symbol in the code");
|
||||
connect(m_showDefinitionAction, &QAction::triggered, this, &QtGraphicsView::showDefinition);
|
||||
|
||||
m_hideNodeAction = new QAction("Hide Node (Alt + Left Click)", this);
|
||||
m_hideNodeAction->setStatusTip("Hide the node from this graph");
|
||||
m_hideNodeAction->setToolTip("Hide the node from this graph");
|
||||
connect(m_hideNodeAction, &QAction::triggered, this, &QtGraphicsView::hideNode);
|
||||
|
||||
m_hideEdgeAction = new QAction(tr("Hide Edge (Alt + Left Click)"), this);
|
||||
m_hideEdgeAction->setStatusTip(tr("Hide the edge from this graph"));
|
||||
m_hideEdgeAction->setToolTip(tr("Hide the edge from this graph"));
|
||||
m_hideEdgeAction = new QAction("Hide Edge (Alt + Left Click)", this);
|
||||
m_hideEdgeAction->setStatusTip("Hide the edge from this graph");
|
||||
m_hideEdgeAction->setToolTip("Hide the edge from this graph");
|
||||
connect(m_hideEdgeAction, &QAction::triggered, this, &QtGraphicsView::hideEdge);
|
||||
|
||||
m_bookmarkNodeAction = new QAction(tr("Bookmark Node"), this);
|
||||
m_bookmarkNodeAction->setStatusTip(tr("Create a bookmark for this node"));
|
||||
m_bookmarkNodeAction->setToolTip(tr("Create a bookmark for this node"));
|
||||
m_bookmarkNodeAction = new QAction("Bookmark Node", this);
|
||||
m_bookmarkNodeAction->setStatusTip("Create a bookmark for this node");
|
||||
m_bookmarkNodeAction->setToolTip("Create a bookmark for this node");
|
||||
connect(m_bookmarkNodeAction, &QAction::triggered, this, &QtGraphicsView::bookmarkNode);
|
||||
|
||||
m_zoomState = new QPushButton(this);
|
||||
@@ -354,6 +363,7 @@ void QtGraphicsView::contextMenuEvent(QContextMenuEvent* event)
|
||||
}
|
||||
}
|
||||
|
||||
m_showDefinitionAction->setEnabled(m_hideNodeId);
|
||||
m_hideNodeAction->setEnabled(m_hideNodeId);
|
||||
m_hideEdgeAction->setEnabled(m_hideEdgeId);
|
||||
m_bookmarkNodeAction->setEnabled(m_bookmarkNodeId);
|
||||
@@ -366,8 +376,9 @@ void QtGraphicsView::contextMenuEvent(QContextMenuEvent* event)
|
||||
menu.addAction(m_exportGraphAction);
|
||||
|
||||
menu.addSeparator();
|
||||
menu.addAction(m_hideEdgeAction);
|
||||
menu.addAction(m_showDefinitionAction);
|
||||
menu.addAction(m_hideNodeAction);
|
||||
menu.addAction(m_hideEdgeAction);
|
||||
menu.addAction(m_bookmarkNodeAction);
|
||||
|
||||
menu.addSeparator();
|
||||
@@ -521,6 +532,11 @@ void QtGraphicsView::copyNodeName()
|
||||
QApplication::clipboard()->setText(QString::fromStdWString(m_clipboardNodeName));
|
||||
}
|
||||
|
||||
void QtGraphicsView::showDefinition()
|
||||
{
|
||||
MessageCodeShowDefinition(m_hideNodeId).dispatch();
|
||||
}
|
||||
|
||||
void QtGraphicsView::hideNode()
|
||||
{
|
||||
MessageGraphNodeHide(m_hideNodeId).dispatch();
|
||||
|
||||
@@ -57,6 +57,7 @@ private slots:
|
||||
|
||||
void exportGraph();
|
||||
void copyNodeName();
|
||||
void showDefinition();
|
||||
void hideNode();
|
||||
void hideEdge();
|
||||
void bookmarkNode();
|
||||
@@ -94,6 +95,7 @@ private:
|
||||
|
||||
QAction* m_exportGraphAction;
|
||||
QAction* m_copyNodeNameAction;
|
||||
QAction* m_showDefinitionAction;
|
||||
QAction* m_hideNodeAction;
|
||||
QAction* m_hideEdgeAction;
|
||||
QAction* m_bookmarkNodeAction;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "qt/utility/utilityQt.h"
|
||||
#include "qt/view/graphElements/nodeComponents/QtGraphNodeComponent.h"
|
||||
#include "qt/view/graphElements/QtGraphEdge.h"
|
||||
#include "utility/messaging/type/code/MessageCodeShowDefinition.h"
|
||||
#include "utility/messaging/type/MessageGraphNodeHide.h"
|
||||
#include "utility/messaging/type/MessageGraphNodeMove.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
@@ -400,6 +401,20 @@ void QtGraphNode::onHide()
|
||||
}
|
||||
}
|
||||
|
||||
void QtGraphNode::onShowDefinition()
|
||||
{
|
||||
Id tokenId = getTokenId();
|
||||
|
||||
if (tokenId)
|
||||
{
|
||||
MessageCodeShowDefinition(tokenId).dispatch();
|
||||
}
|
||||
else if (getParent())
|
||||
{
|
||||
getParent()->onShowDefinition();
|
||||
}
|
||||
}
|
||||
|
||||
void QtGraphNode::mousePressEvent(QGraphicsSceneMouseEvent* event)
|
||||
{
|
||||
event->ignore();
|
||||
|
||||
@@ -98,6 +98,7 @@ public:
|
||||
|
||||
virtual void onClick();
|
||||
virtual void onHide();
|
||||
virtual void onShowDefinition();
|
||||
virtual void moved(const Vec2i& oldPosition);
|
||||
|
||||
virtual void updateStyle() = 0;
|
||||
|
||||
@@ -39,6 +39,10 @@ void QtGraphNodeComponentClickable::nodeMouseReleaseEvent(QGraphicsSceneMouseEve
|
||||
{
|
||||
m_graphNode->onHide();
|
||||
}
|
||||
else if (event->modifiers() & Qt::ControlModifier)
|
||||
{
|
||||
m_graphNode->onShowDefinition();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_graphNode->onClick();
|
||||
|
||||
Reference in New Issue
Block a user