ui: Create bookmarks from graph context menu for node under mouse cursor (issue #373)
bug id = 373
This commit is contained in:
@@ -22,7 +22,6 @@ const std::string BookmarkController::s_defaultCategoryName = "default";
|
||||
BookmarkController::BookmarkController(StorageAccess* storageAccess)
|
||||
: m_storageAccess(storageAccess)
|
||||
, m_bookmarkCache(storageAccess)
|
||||
, m_hasBookmarkForActiveToken(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -35,8 +34,6 @@ void BookmarkController::clear()
|
||||
m_activeNodeIds.clear();
|
||||
m_activeEdgeIds.clear();
|
||||
|
||||
m_hasBookmarkForActiveToken = false;
|
||||
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CANNOT_CREATE);
|
||||
}
|
||||
|
||||
@@ -66,16 +63,16 @@ std::vector<std::string> BookmarkController::getActiveTokenDisplayNames() const
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> BookmarkController::getDisplayNamesForNodeId(Id nodeId) const
|
||||
{
|
||||
return std::vector<std::string>({ getNodeDisplayName(nodeId) });
|
||||
}
|
||||
|
||||
std::vector<BookmarkCategory> BookmarkController::getAllBookmarkCategories() const
|
||||
{
|
||||
return m_storageAccess->getAllBookmarkCategories();
|
||||
}
|
||||
|
||||
bool BookmarkController::hasBookmarkForActiveToken() const
|
||||
{
|
||||
return m_hasBookmarkForActiveToken;
|
||||
}
|
||||
|
||||
std::shared_ptr<Bookmark> BookmarkController::getBookmarkForActiveToken() const
|
||||
{
|
||||
if (!m_activeEdgeIds.empty())
|
||||
@@ -103,6 +100,19 @@ std::shared_ptr<Bookmark> BookmarkController::getBookmarkForActiveToken() const
|
||||
return std::shared_ptr<Bookmark>();
|
||||
}
|
||||
|
||||
std::shared_ptr<Bookmark> BookmarkController::getBookmarkForNodeId(Id nodeId) const
|
||||
{
|
||||
for (std::shared_ptr<NodeBookmark> nodeBookmark: getAllNodeBookmarks())
|
||||
{
|
||||
if (nodeBookmark->getNodeIds().size() == 1 && nodeBookmark->getNodeIds()[0] == nodeId)
|
||||
{
|
||||
return std::make_shared<NodeBookmark>(*(nodeBookmark.get()));
|
||||
}
|
||||
}
|
||||
|
||||
return std::shared_ptr<Bookmark>();
|
||||
}
|
||||
|
||||
bool BookmarkController::canCreateBookmark() const
|
||||
{
|
||||
return m_activeNodeIds.size() || m_activeEdgeIds.size();
|
||||
@@ -191,7 +201,7 @@ void BookmarkController::handleMessage(MessageActivateBookmark* message)
|
||||
|
||||
for (Id nodeId: bookmark->getNodeIds())
|
||||
{
|
||||
activateNodes.addNode(nodeId, NameHierarchy());
|
||||
activateNodes.addNode(nodeId, m_storageAccess->getNameHierarchyForNodeId(nodeId));
|
||||
}
|
||||
|
||||
activateNodes.dispatch();
|
||||
@@ -210,12 +220,10 @@ void BookmarkController::handleMessage(MessageActivateTokens* message)
|
||||
|
||||
if (getBookmarkForActiveToken())
|
||||
{
|
||||
m_hasBookmarkForActiveToken = true;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_hasBookmarkForActiveToken = false;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
|
||||
}
|
||||
}
|
||||
@@ -227,12 +235,10 @@ void BookmarkController::handleMessage(MessageActivateTokens* message)
|
||||
|
||||
if (getBookmarkForActiveToken())
|
||||
{
|
||||
m_hasBookmarkForActiveToken = true;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_hasBookmarkForActiveToken = false;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
|
||||
}
|
||||
}
|
||||
@@ -248,17 +254,7 @@ void BookmarkController::handleMessage(MessageCreateBookmark* message)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Creating Edge Bookmark");
|
||||
|
||||
std::string displayName = message->displayName;
|
||||
if (displayName.empty())
|
||||
{
|
||||
std::vector<std::string> activeEdgeDisplayNames = getActiveEdgeDisplayNames();
|
||||
if (!activeEdgeDisplayNames.empty())
|
||||
{
|
||||
displayName = activeEdgeDisplayNames.front();
|
||||
}
|
||||
}
|
||||
|
||||
EdgeBookmark bookmark(0, displayName, message->comment, TimePoint::now(), category);
|
||||
EdgeBookmark bookmark(0, message->displayName, message->comment, TimePoint::now(), category);
|
||||
bookmark.setEdgeIds(m_activeEdgeIds);
|
||||
|
||||
if (!m_activeNodeIds.empty())
|
||||
@@ -276,24 +272,20 @@ void BookmarkController::handleMessage(MessageCreateBookmark* message)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Creating Node Bookmark");
|
||||
|
||||
std::string displayName = message->displayName;
|
||||
if (displayName.empty())
|
||||
NodeBookmark bookmark(0, message->displayName, message->comment, TimePoint::now(), category);
|
||||
if (message->nodeId)
|
||||
{
|
||||
std::vector<std::string> activeNodeDisplayNames = getActiveNodeDisplayNames();
|
||||
if (!activeNodeDisplayNames.empty())
|
||||
{
|
||||
displayName = activeNodeDisplayNames.front();
|
||||
}
|
||||
bookmark.addNodeId(message->nodeId);
|
||||
}
|
||||
else
|
||||
{
|
||||
bookmark.setNodeIds(m_activeNodeIds);
|
||||
}
|
||||
|
||||
NodeBookmark bookmark(0, displayName, message->comment, TimePoint::now(), category);
|
||||
bookmark.setNodeIds(m_activeNodeIds);
|
||||
m_storageAccess->addNodeBookmark(bookmark);
|
||||
}
|
||||
|
||||
m_bookmarkCache.clear();
|
||||
|
||||
m_hasBookmarkForActiveToken = true;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
|
||||
getView<BookmarkView>()->update();
|
||||
}
|
||||
@@ -315,7 +307,6 @@ void BookmarkController::handleMessage(MessageDeleteBookmark* message)
|
||||
|
||||
if (!getBookmarkForActiveToken())
|
||||
{
|
||||
m_hasBookmarkForActiveToken = false;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
|
||||
}
|
||||
|
||||
@@ -330,7 +321,6 @@ void BookmarkController::handleMessage(MessageDeleteBookmarkCategory* message)
|
||||
|
||||
if (!getBookmarkForActiveToken())
|
||||
{
|
||||
m_hasBookmarkForActiveToken = false;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
|
||||
}
|
||||
|
||||
@@ -347,7 +337,6 @@ void BookmarkController::handleMessage(MessageDeleteBookmarkForActiveTokens* mes
|
||||
|
||||
cleanBookmarkCategories();
|
||||
|
||||
m_hasBookmarkForActiveToken = false;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
|
||||
getView<BookmarkView>()->update();
|
||||
}
|
||||
|
||||
@@ -50,10 +50,12 @@ public:
|
||||
const MessageDisplayBookmarks::BookmarkFilter& filter, const MessageDisplayBookmarks::BookmarkOrder& order) const;
|
||||
|
||||
std::vector<std::string> getActiveTokenDisplayNames() const;
|
||||
std::vector<std::string> getDisplayNamesForNodeId(Id nodeId) const;
|
||||
|
||||
std::vector<BookmarkCategory> getAllBookmarkCategories() const;
|
||||
|
||||
bool hasBookmarkForActiveToken() const;
|
||||
std::shared_ptr<Bookmark> getBookmarkForActiveToken() const;
|
||||
std::shared_ptr<Bookmark> getBookmarkForNodeId(Id nodeId) const;
|
||||
|
||||
bool canCreateBookmark() const;
|
||||
|
||||
@@ -118,7 +120,6 @@ private:
|
||||
|
||||
std::vector<Id> m_activeNodeIds;
|
||||
std::vector<Id> m_activeEdgeIds;
|
||||
bool m_hasBookmarkForActiveToken;
|
||||
};
|
||||
|
||||
#endif // BOOKMARK_CONTROLLER_H
|
||||
|
||||
@@ -46,18 +46,39 @@ void BookmarkView::handleMessage(MessageDisplayBookmarks* message)
|
||||
|
||||
void BookmarkView::handleMessage(MessageDisplayBookmarkCreator* message)
|
||||
{
|
||||
if (!getController()->canCreateBookmark())
|
||||
if (!getController()->canCreateBookmark() && !message->nodeId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (getController()->hasBookmarkForActiveToken())
|
||||
if (message->nodeId)
|
||||
{
|
||||
displayBookmarkEditor(getController()->getBookmarkForActiveToken(), getController()->getAllBookmarkCategories());
|
||||
if (getController()->getBookmarkForNodeId(message->nodeId) != nullptr)
|
||||
{
|
||||
displayBookmarkEditor(
|
||||
getController()->getBookmarkForNodeId(message->nodeId),
|
||||
getController()->getAllBookmarkCategories()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
displayBookmarkCreator(
|
||||
getController()->getDisplayNamesForNodeId(message->nodeId),
|
||||
getController()->getAllBookmarkCategories(),
|
||||
message->nodeId
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
displayBookmarkCreator(getController()->getActiveTokenDisplayNames(), getController()->getAllBookmarkCategories());
|
||||
if (getController()->getBookmarkForActiveToken() != nullptr)
|
||||
{
|
||||
displayBookmarkEditor(getController()->getBookmarkForActiveToken(), getController()->getAllBookmarkCategories());
|
||||
}
|
||||
else
|
||||
{
|
||||
displayBookmarkCreator(getController()->getActiveTokenDisplayNames(), getController()->getAllBookmarkCategories(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ private:
|
||||
virtual void handleMessage(MessageDisplayBookmarkEditor* message);
|
||||
|
||||
virtual void displayBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks) = 0;
|
||||
virtual void displayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories) = 0;
|
||||
virtual void displayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories, Id nodeId) = 0;
|
||||
virtual void displayBookmarkEditor(std::shared_ptr<Bookmark> bookmark, const std::vector<BookmarkCategory>& categories) = 0;
|
||||
|
||||
MessageDisplayBookmarks::BookmarkFilter m_filter;
|
||||
|
||||
@@ -7,10 +7,11 @@ class MessageCreateBookmark
|
||||
: public Message<MessageCreateBookmark>
|
||||
{
|
||||
public:
|
||||
MessageCreateBookmark(const std::string& comment, const std::string& displayName, const std::string& categoryName)
|
||||
MessageCreateBookmark(const std::string& comment, const std::string& displayName, const std::string& categoryName, Id nodeId)
|
||||
: comment(comment)
|
||||
, displayName(displayName)
|
||||
, categoryName(categoryName)
|
||||
, nodeId(nodeId)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -26,6 +27,7 @@ public:
|
||||
const std::string comment;
|
||||
const std::string displayName;
|
||||
const std::string categoryName;
|
||||
const Id nodeId;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_CREATE_BOOKMARK_H
|
||||
@@ -8,6 +8,12 @@ class MessageDisplayBookmarkCreator
|
||||
{
|
||||
public:
|
||||
MessageDisplayBookmarkCreator()
|
||||
: nodeId(0)
|
||||
{
|
||||
}
|
||||
|
||||
MessageDisplayBookmarkCreator(Id nodeId)
|
||||
: nodeId(nodeId)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -15,6 +21,8 @@ public:
|
||||
{
|
||||
return "MessageDisplayBookmarkCreator";
|
||||
}
|
||||
|
||||
Id nodeId;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_DISPLAY_BOOKMARK_CREATOR_H
|
||||
@@ -8,12 +8,11 @@ class MessageEditBookmark
|
||||
: public Message<MessageEditBookmark>
|
||||
{
|
||||
public:
|
||||
MessageEditBookmark(const Id id, const std::string& comment, const std::string& displayName, const std::string& categoryName, const bool isEdge)
|
||||
MessageEditBookmark(Id id, const std::string& comment, const std::string& displayName, const std::string& categoryName)
|
||||
: bookmarkId(id)
|
||||
, comment(comment)
|
||||
, displayName(displayName)
|
||||
, categoryName(categoryName)
|
||||
, isEdge(isEdge)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -30,7 +29,6 @@ public:
|
||||
const std::string comment;
|
||||
const std::string displayName;
|
||||
const std::string categoryName;
|
||||
const bool isEdge;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_EDIT_BOOKMARK_H
|
||||
Reference in New Issue
Block a user