ui: bookmarks
can now bookmark tokens
This commit is contained in:
@@ -13,6 +13,8 @@ add_files(
|
||||
component/controller/helper/SnippetMerger.cpp
|
||||
component/controller/helper/SnippetMerger.h
|
||||
|
||||
component/controller/BookmarkController.cpp
|
||||
component/controller/BookmarkController.h
|
||||
component/controller/CodeController.cpp
|
||||
component/controller/CodeController.h
|
||||
component/controller/Controller.cpp
|
||||
@@ -42,6 +44,8 @@ add_files(
|
||||
|
||||
component/view/helper/CodeSnippetParams.cpp
|
||||
component/view/helper/CodeSnippetParams.h
|
||||
component/view/BookmarkView.cpp
|
||||
component/view/BookmarkView.h
|
||||
component/view/CodeView.cpp
|
||||
component/view/CodeView.h
|
||||
component/view/CompositeView.cpp
|
||||
@@ -92,6 +96,15 @@ add_files(
|
||||
data/access/StorageAccessProxy.cpp
|
||||
data/access/StorageAccessProxy.h
|
||||
|
||||
data/bookmark/Bookmark.cpp
|
||||
data/bookmark/Bookmark.h
|
||||
data/bookmark/BookmarkCategory.cpp
|
||||
data/bookmark/BookmarkCategory.h
|
||||
data/bookmark/EdgeBookmark.cpp
|
||||
data/bookmark/EdgeBookmark.h
|
||||
data/bookmark/NodeBookmark.cpp
|
||||
data/bookmark/NodeBookmark.h
|
||||
|
||||
data/fulltextsearch/FullTextSearchIndex.cpp
|
||||
data/fulltextsearch/FullTextSearchIndex.h
|
||||
data/fulltextsearch/SuffixArray.cpp
|
||||
@@ -249,6 +262,7 @@ add_files(
|
||||
utility/math/VectorBase.h
|
||||
|
||||
utility/messaging/type/MessageActivateAll.h
|
||||
utility/messaging/type/MessageActivateBookmark.h
|
||||
utility/messaging/type/MessageActivateEdge.h
|
||||
utility/messaging/type/MessageActivateFile.h
|
||||
utility/messaging/type/MessageActivateLocalSymbols.h
|
||||
@@ -264,8 +278,17 @@ add_files(
|
||||
utility/messaging/type/MessageCodeReference.h
|
||||
utility/messaging/type/MessageCodeViewExpandedInitialFiles.h
|
||||
utility/messaging/type/MessageColorSchemeTest.h
|
||||
utility/messaging/type/MessageCreateBookmark.h
|
||||
utility/messaging/type/MessageCreateBookmarkCategory.h
|
||||
utility/messaging/type/MessageDeactivateEdge.h
|
||||
utility/messaging/type/MessageDeleteBookmark.h
|
||||
utility/messaging/type/MessageDeleteBookmarkCategoryWithBookmarks.h
|
||||
utility/messaging/type/MessageDeleteBookmarkForActiveTokens.h
|
||||
utility/messaging/type/MessageDispatchWhenLicenseValid.h
|
||||
utility/messaging/type/MessageDisplayBookmarkCreator.h
|
||||
utility/messaging/type/MessageDisplayBookmarkEditor.h
|
||||
utility/messaging/type/MessageDisplayBookmarks.h
|
||||
utility/messaging/type/MessageEditBookmark.h
|
||||
utility/messaging/type/MessageEnteredLicense.h
|
||||
utility/messaging/type/MessageErrorFilterChanged.h
|
||||
utility/messaging/type/MessageFind.h
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "component/ComponentFactory.h"
|
||||
|
||||
#include "component/Component.h"
|
||||
#include "component/controller/BookmarkController.h"
|
||||
#include "component/controller/CodeController.h"
|
||||
#include "component/controller/ErrorController.h"
|
||||
#include "component/controller/FeatureController.h"
|
||||
@@ -11,6 +12,7 @@
|
||||
#include "component/controller/StatusBarController.h"
|
||||
#include "component/controller/StatusController.h"
|
||||
#include "component/controller/UndoRedoController.h"
|
||||
#include "component/view/BookmarkView.h"
|
||||
#include "component/view/CodeView.h"
|
||||
#include "component/view/ErrorView.h"
|
||||
#include "component/view/GraphView.h"
|
||||
@@ -48,6 +50,14 @@ StorageAccess* ComponentFactory::getStorageAccess() const
|
||||
return m_storageAccess;
|
||||
}
|
||||
|
||||
std::shared_ptr<Component> ComponentFactory::createBookmarkComponent(ViewLayout* viewLayout)
|
||||
{
|
||||
std::shared_ptr<BookmarkView> view = m_viewFactory->createBookmarkView(viewLayout);
|
||||
std::shared_ptr<BookmarkController> controller = std::make_shared<BookmarkController>(m_storageAccess);
|
||||
|
||||
return std::make_shared<Component>(view, controller);
|
||||
}
|
||||
|
||||
std::shared_ptr<Component> ComponentFactory::createCodeComponent(ViewLayout* viewLayout)
|
||||
{
|
||||
std::shared_ptr<CodeView> view = m_viewFactory->createCodeView(viewLayout);
|
||||
|
||||
@@ -19,6 +19,7 @@ public:
|
||||
ViewFactory* getViewFactory() const;
|
||||
StorageAccess* getStorageAccess() const;
|
||||
|
||||
std::shared_ptr<Component> createBookmarkComponent(ViewLayout* viewLayout);
|
||||
std::shared_ptr<Component> createCodeComponent(ViewLayout* viewLayout);
|
||||
std::shared_ptr<Component> createErrorComponent(ViewLayout* viewLayout);
|
||||
std::shared_ptr<Component> createFeatureComponent();
|
||||
|
||||
@@ -33,6 +33,9 @@ void ComponentManager::setup(ViewLayout* viewLayout)
|
||||
m_componentFactory->getViewFactory()->createCompositeView(viewLayout, CompositeView::DIRECTION_HORIZONTAL, "Search");
|
||||
m_compositeViews.push_back(compositeView);
|
||||
|
||||
std::shared_ptr<Component> bookmarkComponent = m_componentFactory->createBookmarkComponent(compositeView.get());
|
||||
m_components.push_back(bookmarkComponent);
|
||||
|
||||
std::shared_ptr<Component> undoRedoComponent = m_componentFactory->createUndoRedoComponent(compositeView.get());
|
||||
m_components.push_back(undoRedoComponent);
|
||||
|
||||
|
||||
@@ -0,0 +1,727 @@
|
||||
#include "BookmarkController.h"
|
||||
|
||||
#include "component/view/BookmarkView.h"
|
||||
|
||||
#include "data/access/StorageAccess.h"
|
||||
#include "data/bookmark/Bookmark.h"
|
||||
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationCollection.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
|
||||
#include "utility/messaging/type/MessageActivateEdge.h"
|
||||
#include "utility/messaging/type/MessageActivateNodes.h"
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
#include "data/bookmark/EdgeBookmark.h"
|
||||
#include "data/bookmark/NodeBookmark.h"
|
||||
|
||||
const std::string BookmarkController::m_edgeSeperatorToken = "=>";
|
||||
|
||||
BookmarkController::BookmarkController(StorageAccess* storageAccess)
|
||||
: m_storageAccess(storageAccess)
|
||||
, m_activeTokens()
|
||||
, m_activeTokenNames()
|
||||
, m_activeTokenDisplayNames()
|
||||
, m_activeTokenTypes()
|
||||
, m_activeEdges()
|
||||
, m_activeEdgeNames()
|
||||
, m_activeEdgeDisplayNames()
|
||||
, m_activeEdgeTypes()
|
||||
, m_activeTokenExists(false)
|
||||
{
|
||||
}
|
||||
|
||||
BookmarkController::~BookmarkController()
|
||||
{
|
||||
}
|
||||
|
||||
void BookmarkController::clear()
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> BookmarkController::getAllBookmarks() const
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Retrieving all bookmarks");
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> bookmarks;
|
||||
|
||||
std::vector<NodeBookmark> nodeBookmarks = m_storageAccess->getAllNodeBookmarks();
|
||||
|
||||
for (unsigned int i = 0; i < nodeBookmarks.size(); i++)
|
||||
{
|
||||
bookmarks.push_back(std::make_shared<NodeBookmark>(nodeBookmarks[i]));
|
||||
}
|
||||
|
||||
std::vector<EdgeBookmark> edgeBookmarks = m_storageAccess->getAllEdgeBookmarks();
|
||||
|
||||
for (unsigned int i = 0; i < edgeBookmarks.size(); i++)
|
||||
{
|
||||
bookmarks.push_back(std::make_shared<EdgeBookmark>(edgeBookmarks[i]));
|
||||
}
|
||||
|
||||
// std::vector<Bookmark> bookmarks = m_storageAccess->getAllBookmarks();
|
||||
|
||||
// check whether bookmarks are still valid (so, no referenced tokens have been removed)
|
||||
for (unsigned int i = 0; i < bookmarks.size(); i++)
|
||||
{
|
||||
for (unsigned int j = 0; j < bookmarks[i]->getTokenNames().size(); j++)
|
||||
{
|
||||
std::string name = bookmarks[i]->getTokenNames()[j];
|
||||
int type = bookmarks[i]->getTokenTypes()[j];
|
||||
|
||||
bool exists = false;
|
||||
|
||||
if (dynamic_cast<EdgeBookmark*>(bookmarks[i].get()) != NULL)
|
||||
{
|
||||
TempEdge tmpEdge = getEdge(name, type);
|
||||
|
||||
exists = m_storageAccess->checkEdgeExists(tmpEdge.edgeId);
|
||||
}
|
||||
else
|
||||
{
|
||||
exists = m_storageAccess->checkNodeExistsByName(name);
|
||||
}
|
||||
|
||||
std::vector<Id> tokenIds = bookmarks[i]->getTokenIds();
|
||||
|
||||
bookmarks[i]->setValid(exists);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return bookmarks;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> BookmarkController::getBookmarks(const MessageDisplayBookmarks::BookmarkFilter& filter, const MessageDisplayBookmarks::BookmarkOrder& order) const
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Retrieving bookmarks with filter '" << std::to_string(filter) << "' and order '" << std::to_string(order) << "'");
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> bookmarks = getAllBookmarks();
|
||||
|
||||
int bookmarkCount = bookmarks.size();
|
||||
bookmarks = getFilteredBookmarks(bookmarks, filter);
|
||||
|
||||
bookmarkCount = bookmarks.size();
|
||||
bookmarks = getOrderedBookmarks(bookmarks, order);
|
||||
|
||||
return bookmarks;
|
||||
}
|
||||
|
||||
std::vector<std::string> BookmarkController::getActiveTokenNames() const
|
||||
{
|
||||
return m_activeTokenNames;
|
||||
}
|
||||
|
||||
std::vector<std::string> BookmarkController::getActiveTokenDisplayNames() const
|
||||
{
|
||||
if (m_activeEdgeDisplayNames.size() > 0)
|
||||
{
|
||||
return m_activeEdgeDisplayNames;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_activeTokenDisplayNames;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<BookmarkCategory> BookmarkController::getAllBookmarkCategories() const
|
||||
{
|
||||
return m_storageAccess->getAllBookmarkCategories();
|
||||
}
|
||||
|
||||
bool BookmarkController::activeTokenExists() const
|
||||
{
|
||||
return m_activeTokenExists;
|
||||
}
|
||||
|
||||
std::shared_ptr<Bookmark> BookmarkController::getBookmarkForActiveToken() const
|
||||
{
|
||||
if (m_activeEdgeNames.size() > 0)
|
||||
{
|
||||
std::vector<EdgeBookmark> bookmarks = m_storageAccess->getAllEdgeBookmarks();
|
||||
|
||||
for (unsigned int i = 0; i < bookmarks.size(); i++)
|
||||
{
|
||||
if (bookmarks[i].getTokenNames() == m_activeEdgeNames)
|
||||
{
|
||||
return std::make_shared<EdgeBookmark>(bookmarks[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<NodeBookmark> bookmarks = m_storageAccess->getAllNodeBookmarks();
|
||||
|
||||
for (unsigned int i = 0; i < bookmarks.size(); i++)
|
||||
{
|
||||
if (bookmarks[i].getTokenNames() == m_activeTokenNames)
|
||||
{
|
||||
return std::make_shared<NodeBookmark>(bookmarks[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void BookmarkController::handleMessage(MessageActivateBookmark* message)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Attempting to activate Bookmark");
|
||||
|
||||
if (dynamic_cast<EdgeBookmark*>(message->bookmark.get()) != NULL)
|
||||
{
|
||||
EdgeBookmark* bookmark = dynamic_cast<EdgeBookmark*>(message->bookmark.get());
|
||||
|
||||
NodeBookmark baseBookmark = bookmark->getBaseBookmark();
|
||||
|
||||
MessageActivateNodes activateNodes;
|
||||
|
||||
for (unsigned int i = 0; i < baseBookmark.getTokenNames().size(); i++)
|
||||
{
|
||||
NameHierarchy nh = NameHierarchy::deserialize(baseBookmark.getTokenNames()[i]);
|
||||
activateNodes.addNode(nh);
|
||||
}
|
||||
|
||||
activateNodes.dispatch();
|
||||
|
||||
NameHierarchy source;
|
||||
NameHierarchy target;
|
||||
for (unsigned int i = 0; i < bookmark->getTokenNames().size(); i++)
|
||||
{
|
||||
int tokenType = bookmark->getTokenTypes()[i];
|
||||
TempEdge tmpEdge = getEdge(bookmark->getTokenNames()[i], tokenType);
|
||||
|
||||
MessageActivateEdge activateEdge(tmpEdge.edgeId, Edge::intToType(tokenType), tmpEdge.source, tmpEdge.target);
|
||||
activateEdge.dispatch();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NodeBookmark* bookmark = dynamic_cast<NodeBookmark*>(message->bookmark.get());
|
||||
|
||||
MessageActivateNodes activateNodes;
|
||||
|
||||
for (unsigned int i = 0; i < bookmark->getTokenNames().size(); i++)
|
||||
{
|
||||
NameHierarchy nh = NameHierarchy::deserialize(bookmark->getTokenNames()[i]);
|
||||
activateNodes.addNode(nh);
|
||||
}
|
||||
|
||||
activateNodes.dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarkController::handleMessage(MessageActivateTokens* message)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Registering new active token");
|
||||
|
||||
if (message->isEdge)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Registering new Edge");
|
||||
|
||||
std::vector<std::string> tokenNames;
|
||||
std::vector<std::string> tokenDisplayNames;
|
||||
std::vector<int> tokenTypes;
|
||||
|
||||
for (unsigned int i = 0; i < message->tokenIds.size(); i++)
|
||||
{
|
||||
StorageEdge edge = m_storageAccess->getEdgeById(message->tokenIds[i]);
|
||||
|
||||
int typeId = edge.type;
|
||||
|
||||
tokenTypes.push_back(typeId);
|
||||
|
||||
NameHierarchy sourceHierarchy = m_storageAccess->getNameHierarchyForNodeWithId(edge.sourceNodeId);
|
||||
NameHierarchy targetHierarchy = m_storageAccess->getNameHierarchyForNodeWithId(edge.targetNodeId);
|
||||
|
||||
std::string sourceNode = NameHierarchy::serialize(sourceHierarchy);
|
||||
std::string targetNode = NameHierarchy::serialize(targetHierarchy);
|
||||
|
||||
std::string tokenName = sourceNode + m_edgeSeperatorToken + targetNode;
|
||||
|
||||
tokenNames.push_back(tokenName);
|
||||
|
||||
tokenDisplayNames.push_back(sourceHierarchy.getRawName() + m_edgeSeperatorToken + targetHierarchy.getRawName());
|
||||
}
|
||||
|
||||
m_activeEdges = message->tokenIds;
|
||||
m_activeEdgeNames = tokenNames;
|
||||
m_activeEdgeTypes = tokenTypes;
|
||||
m_activeEdgeDisplayNames = tokenDisplayNames;
|
||||
|
||||
if (m_storageAccess->checkEdgeBookmarkExistsByTokens(tokenNames))
|
||||
{
|
||||
m_activeTokenExists = true;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_activeTokenExists = false;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Registering new Node");
|
||||
|
||||
m_activeTokens = message->tokenIds;
|
||||
m_activeTokenNames = getTokenNames(m_activeTokens);
|
||||
m_activeTokenTypes = getTokenTypes(m_activeTokens);
|
||||
m_activeTokenDisplayNames = getTokenDisplayNames(m_activeTokens);
|
||||
|
||||
m_activeEdges.clear();
|
||||
m_activeEdgeNames.clear();
|
||||
m_activeEdgeTypes.clear();
|
||||
m_activeEdgeDisplayNames.clear();
|
||||
|
||||
if (m_storageAccess->checkNodeBookmarkExistsByTokens(m_activeTokenNames))
|
||||
{
|
||||
m_activeTokenExists = true;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_activeTokenExists = false;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarkController::handleMessage(MessageCreateBookmark* message)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Attempting to create new bookmark");
|
||||
|
||||
if (m_activeTokens.size() > 0)
|
||||
{
|
||||
if (m_activeEdges.size() > 0)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Creating Edge Bookmark");
|
||||
|
||||
std::string displayName = message->displayName;
|
||||
if (displayName.size() <= 0)
|
||||
{
|
||||
displayName = getDisplayName(m_activeTokens[0]);
|
||||
}
|
||||
|
||||
EdgeBookmark bookmark(displayName, m_activeTokens, m_activeTokenNames, message->comment, TimePoint::now());
|
||||
|
||||
bookmark.setDisplayName(message->displayName);
|
||||
bookmark.setComment(message->comment);
|
||||
bookmark.setTokenTypes(m_activeTokenTypes);
|
||||
|
||||
BookmarkCategory category;
|
||||
category.setName(message->categoryName);
|
||||
|
||||
bookmark.setCategory(category);
|
||||
|
||||
bookmark.setEdgeTokenIds(m_activeEdges);
|
||||
bookmark.setEdgeTokenNames(m_activeEdgeNames);
|
||||
bookmark.setEdgeTokenTypes(m_activeEdgeTypes);
|
||||
|
||||
Id id = m_storageAccess->addEdgeBookmark(bookmark);
|
||||
|
||||
bookmark.setId(id);
|
||||
|
||||
m_activeTokenExists = true;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
|
||||
getView<BookmarkView>()->update();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Creating Node Bookmark");
|
||||
|
||||
std::string displayName = message->displayName;
|
||||
if (displayName.size() <= 0)
|
||||
{
|
||||
displayName = getDisplayName(m_activeTokens[0]);
|
||||
}
|
||||
|
||||
NodeBookmark bookmark(displayName, m_activeTokens, m_activeTokenNames, message->comment, TimePoint::now());
|
||||
|
||||
bookmark.setTokenTypes(m_activeTokenTypes);
|
||||
|
||||
BookmarkCategory category;
|
||||
category.setName(message->categoryName);
|
||||
|
||||
bookmark.setCategory(category);
|
||||
|
||||
Id id = m_storageAccess->addNodeBookmark(bookmark);
|
||||
|
||||
bookmark.setId(id);
|
||||
|
||||
m_activeTokenExists = true;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
|
||||
getView<BookmarkView>()->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarkController::handleMessage(MessageCreateBookmarkCategory* message)
|
||||
{
|
||||
std::string categoryName = message->name;
|
||||
LOG_INFO_STREAM(<< "Attempting to create new Bookmark category '" << categoryName << "'");
|
||||
|
||||
if (m_storageAccess->checkBookmarkCategoryExists(message->name) == false)
|
||||
{
|
||||
BookmarkCategory category;
|
||||
category.setName(message->name);
|
||||
|
||||
m_storageAccess->addBookmarkCategory(category);
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarkController::handleMessage(MessageDeleteBookmark* message)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Attempting to delete Bookmark " << std::to_string(message->bookmarkId));
|
||||
|
||||
if (message->isEdge)
|
||||
{
|
||||
m_storageAccess->removeEdgeBookmark(message->bookmarkId);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_storageAccess->removeNodeBookmark(message->bookmarkId);
|
||||
}
|
||||
|
||||
cleanBookmarkCategories();
|
||||
|
||||
getView<BookmarkView>()->update();
|
||||
}
|
||||
|
||||
void BookmarkController::handleMessage(MessageDeleteBookmarkCategoryWithBookmarks* message)
|
||||
{
|
||||
std::vector<BookmarkCategory> categories = m_storageAccess->getAllBookmarkCategories();
|
||||
|
||||
for (unsigned int i = 0; i < categories.size(); i++)
|
||||
{
|
||||
if (categories[i].getId() == message->categoryId)
|
||||
{
|
||||
std::vector<NodeBookmark> nodeBookmarks = m_storageAccess->getAllNodeBookmarks();
|
||||
for (unsigned int j = 0; j < nodeBookmarks.size(); j++)
|
||||
{
|
||||
if (nodeBookmarks[j].getCategory().getName() == categories[i].getName())
|
||||
{
|
||||
m_storageAccess->removeNodeBookmark(nodeBookmarks[j].getId());
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<EdgeBookmark> edgeBookmarks = m_storageAccess->getAllEdgeBookmarks();
|
||||
for (unsigned int j = 0; j < edgeBookmarks.size(); j++)
|
||||
{
|
||||
if (edgeBookmarks[j].getCategory().getName() == categories[i].getName())
|
||||
{
|
||||
m_storageAccess->removeEdgeBookmark(edgeBookmarks[j].getId());
|
||||
}
|
||||
}
|
||||
|
||||
cleanBookmarkCategories();
|
||||
getView<BookmarkView>()->update();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarkController::handleMessage(MessageDeleteBookmarkForActiveTokens* message)
|
||||
{
|
||||
std::shared_ptr<Bookmark> bookmark = getBookmarkForActiveToken();
|
||||
|
||||
if (bookmark != NULL)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Deleting bookmark " << bookmark->getDisplayName());
|
||||
|
||||
if (dynamic_cast<EdgeBookmark*>(bookmark.get()) != NULL)
|
||||
{
|
||||
m_storageAccess->removeEdgeBookmark(bookmark->getId());
|
||||
}
|
||||
else if(dynamic_cast<NodeBookmark*>(bookmark.get()) != NULL)
|
||||
{
|
||||
m_storageAccess->removeNodeBookmark(bookmark->getId());
|
||||
}
|
||||
|
||||
cleanBookmarkCategories();
|
||||
|
||||
m_activeTokenExists = false;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
|
||||
getView<BookmarkView>()->update();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING_STREAM(<< "No Bookmark to delete for active tokens.");
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarkController::handleMessage(MessageEditBookmark* message)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Attempting to update Bookmark " << std::to_string(message->bookmarkId));
|
||||
|
||||
if (message->isEdge)
|
||||
{
|
||||
EdgeBookmark bookmark = m_storageAccess->getEdgeBookmarkById(message->bookmarkId);
|
||||
|
||||
bookmark.setDisplayName(message->displayName);
|
||||
bookmark.setComment(message->comment);
|
||||
BookmarkCategory category;
|
||||
category.setName(message->categoryName);
|
||||
bookmark.setCategory(category);
|
||||
|
||||
m_storageAccess->editEdgeBookmark(bookmark);
|
||||
}
|
||||
else
|
||||
{
|
||||
NodeBookmark bookmark = m_storageAccess->getNodeBookmarkById(message->bookmarkId);
|
||||
|
||||
bookmark.setDisplayName(message->displayName);
|
||||
bookmark.setComment(message->comment);
|
||||
BookmarkCategory category;
|
||||
category.setName(message->categoryName);
|
||||
bookmark.setCategory(category);
|
||||
|
||||
m_storageAccess->editNodeBookmark(bookmark);
|
||||
}
|
||||
|
||||
getView<BookmarkView>()->update();
|
||||
}
|
||||
|
||||
void BookmarkController::handleMessage(MessageFinishedParsing* message)
|
||||
{
|
||||
getView<BookmarkView>()->enableDisplayBookmarks(true);
|
||||
}
|
||||
|
||||
std::vector<std::string> BookmarkController::getTokenNames(const std::vector<Id>& ids) const
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
|
||||
for (unsigned int i = 0; i < ids.size(); i++)
|
||||
{
|
||||
NameHierarchy nameHierarchy = m_storageAccess->getNameHierarchyForNodeWithId(ids[i]);
|
||||
names.push_back(NameHierarchy::serialize(nameHierarchy));
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
std::vector<std::string> BookmarkController::getTokenDisplayNames(const std::vector<Id>& ids) const
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
|
||||
for (unsigned int i = 0; i < ids.size(); i++)
|
||||
{
|
||||
NameHierarchy nameHierarchy = m_storageAccess->getNameHierarchyForNodeWithId(ids[i]);
|
||||
names.push_back(nameHierarchy.getRawName());
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
std::vector<int> BookmarkController::getTokenTypes(const std::vector<Id>& ids) const
|
||||
{
|
||||
std::vector<int> types;
|
||||
|
||||
for (unsigned int i = 0; i < ids.size(); i++)
|
||||
{
|
||||
int type = m_storageAccess->getNodeTypeForNodeWithId(ids[i]);
|
||||
types.push_back(type);
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
std::string BookmarkController::getDisplayName(Id id) const
|
||||
{
|
||||
NameHierarchy nameHierarchy = m_storageAccess->getNameHierarchyForNodeWithId(id);
|
||||
return nameHierarchy.getRawName();
|
||||
}
|
||||
|
||||
BookmarkController::TempEdge BookmarkController::getEdge(const std::string& tokenName, const int tokenType) const
|
||||
{
|
||||
std::pair<std::string, std::string> edgeTokens = seperateEdgeToken(tokenName);
|
||||
|
||||
NameHierarchy source = NameHierarchy::deserialize(edgeTokens.first);
|
||||
NameHierarchy target = NameHierarchy::deserialize(edgeTokens.second);
|
||||
|
||||
Id edgeId = m_storageAccess->getIdForEdge(Edge::intToType(tokenType), source, target);
|
||||
|
||||
TempEdge result;
|
||||
|
||||
result.edgeId = edgeId;
|
||||
result.source = source;
|
||||
result.target = target;
|
||||
result.type = tokenType;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> BookmarkController::seperateEdgeToken(const std::string& token) const
|
||||
{
|
||||
std::pair<std::string, std::string> result;
|
||||
|
||||
if (token.find(m_edgeSeperatorToken) != std::string::npos)
|
||||
{
|
||||
std::vector<std::string> st = utility::splitToVector(token, m_edgeSeperatorToken);
|
||||
|
||||
if (st.size() != 2)
|
||||
{
|
||||
LOG_ERROR_STREAM(<< "Invalid edge token found: " << token);
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.first = st[0];
|
||||
result.second = st[1];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> BookmarkController::getFilteredBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const MessageDisplayBookmarks::BookmarkFilter& filter) const
|
||||
{
|
||||
std::vector<std::shared_ptr<Bookmark>> result;
|
||||
|
||||
if (filter == MessageDisplayBookmarks::BookmarkFilter::ALL)
|
||||
{
|
||||
return bookmarks;
|
||||
}
|
||||
else if (filter == MessageDisplayBookmarks::BookmarkFilter::NODES)
|
||||
{
|
||||
for (unsigned int i = 0; i < bookmarks.size(); i++)
|
||||
{
|
||||
if (dynamic_cast<EdgeBookmark*>(bookmarks[i].get()) == NULL)
|
||||
{
|
||||
result.push_back(bookmarks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
else if (filter == MessageDisplayBookmarks::BookmarkFilter::EDGES)
|
||||
{
|
||||
for (unsigned int i = 0; i < bookmarks.size(); i++)
|
||||
{
|
||||
if (dynamic_cast<EdgeBookmark*>(bookmarks[i].get()) != NULL)
|
||||
{
|
||||
result.push_back(bookmarks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> BookmarkController::getOrderedBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const MessageDisplayBookmarks::BookmarkOrder& order) const
|
||||
{
|
||||
std::vector<std::shared_ptr<Bookmark>> result = bookmarks;
|
||||
|
||||
if (order == MessageDisplayBookmarks::BookmarkOrder::DATE_ASCENDING)
|
||||
{
|
||||
return getDateOrderedBookmarks(result, true);
|
||||
}
|
||||
else if (order == MessageDisplayBookmarks::BookmarkOrder::DATE_DESCENDING)
|
||||
{
|
||||
return getDateOrderedBookmarks(result, false);
|
||||
}
|
||||
else if (order == MessageDisplayBookmarks::BookmarkOrder::NAME_ASCENDING)
|
||||
{
|
||||
return getNameOrderedBookmarks(result, true);
|
||||
}
|
||||
else if (order == MessageDisplayBookmarks::BookmarkOrder::NAME_DESCENDING)
|
||||
{
|
||||
return getNameOrderedBookmarks(result, false);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> BookmarkController::getDateOrderedBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const bool ascending) const
|
||||
{
|
||||
std::vector<std::shared_ptr<Bookmark>> result = bookmarks;
|
||||
|
||||
std::sort(result.begin(), result.end(), BookmarkController::bookmarkDateCompare);
|
||||
|
||||
if (ascending == false)
|
||||
{
|
||||
std::reverse(result.begin(), result.end());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> BookmarkController::getNameOrderedBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const bool ascending) const
|
||||
{
|
||||
std::vector<std::shared_ptr<Bookmark>> result = bookmarks;
|
||||
|
||||
std::sort(result.begin(), result.end(), BookmarkController::bookmarkNameCompare);
|
||||
|
||||
if (ascending == false)
|
||||
{
|
||||
std::reverse(result.begin(), result.end());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void BookmarkController::cleanBookmarkCategories()
|
||||
{
|
||||
std::vector<std::shared_ptr<Bookmark>> bookmarks = getAllBookmarks();
|
||||
|
||||
std::vector<BookmarkCategory> categories = getAllBookmarkCategories();
|
||||
|
||||
for (unsigned int i = 0; i < categories.size(); i++)
|
||||
{
|
||||
BookmarkCategory category = categories[i];
|
||||
bool used = false;
|
||||
|
||||
for (unsigned int j = 0; j < bookmarks.size(); j++)
|
||||
{
|
||||
if (bookmarks[j]->getCategory().getName() == category.getName())
|
||||
{
|
||||
used = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (used == false)
|
||||
{
|
||||
m_storageAccess->removeBookmarkCategory(category.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool BookmarkController::bookmarkDateCompare(const std::shared_ptr<Bookmark> a, const std::shared_ptr<Bookmark> b)
|
||||
{
|
||||
return a->getTimeStamp() < b->getTimeStamp();
|
||||
}
|
||||
|
||||
bool BookmarkController::bookmarkNameCompare(const std::shared_ptr<Bookmark> a, const std::shared_ptr<Bookmark> b)
|
||||
{
|
||||
std::string aName = a->getDisplayName();
|
||||
std::string bName = b->getDisplayName();
|
||||
|
||||
aName = utility::toLowerCase(aName);
|
||||
bName = utility::toLowerCase(bName);
|
||||
|
||||
unsigned int i = 0;
|
||||
while (i < aName.length() && i < bName.length())
|
||||
{
|
||||
if (std::tolower(aName[i]) < std::tolower(bName[i]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (std::tolower(aName[i]) > std::tolower(bName[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
return aName.length() < bName.length();
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
#ifndef BOOKMARK_CONTROLLER_H
|
||||
#define BOOKMARK_CONTROLLER_H
|
||||
|
||||
#include "data/bookmark/Bookmark.h"
|
||||
#include "data/name/NameHierarchy.h"
|
||||
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageActivateBookmark.h"
|
||||
#include "utility/messaging/type/MessageActivateTokens.h"
|
||||
#include "utility/messaging/type/MessageCreateBookmark.h"
|
||||
#include "utility/messaging/type/MessageCreateBookmarkCategory.h"
|
||||
#include "utility/messaging/type/MessageDeleteBookmark.h"
|
||||
#include "utility/messaging/type/MessageDeleteBookmarkCategoryWithBookmarks.h"
|
||||
#include "utility/messaging/type/MessageDeleteBookmarkForActiveTokens.h"
|
||||
#include "utility/messaging/type/MessageDisplayBookmarks.h"
|
||||
#include "utility/messaging/type/MessageEditBookmark.h"
|
||||
#include "utility/messaging/type/MessageFinishedParsing.h"
|
||||
|
||||
#include "component/controller/Controller.h"
|
||||
|
||||
class StorageAccess;
|
||||
|
||||
class BookmarkController
|
||||
: public Controller
|
||||
, public MessageListener<MessageActivateBookmark>
|
||||
, public MessageListener<MessageActivateTokens>
|
||||
, public MessageListener<MessageCreateBookmark>
|
||||
, public MessageListener<MessageCreateBookmarkCategory>
|
||||
, public MessageListener<MessageDeleteBookmark>
|
||||
, public MessageListener<MessageDeleteBookmarkCategoryWithBookmarks>
|
||||
, public MessageListener<MessageDeleteBookmarkForActiveTokens>
|
||||
, public MessageListener<MessageEditBookmark>
|
||||
, public MessageListener<MessageFinishedParsing>
|
||||
{
|
||||
public:
|
||||
BookmarkController(StorageAccess* storageAccess);
|
||||
virtual ~BookmarkController();
|
||||
|
||||
virtual void clear();
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> getAllBookmarks() const;
|
||||
std::vector<std::shared_ptr<Bookmark>> getBookmarks(const MessageDisplayBookmarks::BookmarkFilter& filter, const MessageDisplayBookmarks::BookmarkOrder& order) const;
|
||||
|
||||
std::vector<std::string> getActiveTokenNames() const;
|
||||
std::vector<std::string> getActiveTokenDisplayNames() const;
|
||||
std::vector<BookmarkCategory> getAllBookmarkCategories() const;
|
||||
bool activeTokenExists() const;
|
||||
std::shared_ptr<Bookmark> getBookmarkForActiveToken() const; // or null if no bookmark for that token exists
|
||||
|
||||
private:
|
||||
struct TempEdge
|
||||
{
|
||||
public:
|
||||
Id edgeId;
|
||||
NameHierarchy source;
|
||||
NameHierarchy target;
|
||||
int type;
|
||||
};
|
||||
|
||||
virtual void handleMessage(MessageActivateBookmark* message);
|
||||
virtual void handleMessage(MessageActivateTokens* message);
|
||||
virtual void handleMessage(MessageCreateBookmark* message);
|
||||
virtual void handleMessage(MessageCreateBookmarkCategory* message);
|
||||
virtual void handleMessage(MessageDeleteBookmark* message);
|
||||
virtual void handleMessage(MessageDeleteBookmarkCategoryWithBookmarks* message);
|
||||
virtual void handleMessage(MessageDeleteBookmarkForActiveTokens* message);
|
||||
virtual void handleMessage(MessageEditBookmark* message);
|
||||
virtual void handleMessage(MessageFinishedParsing* message);
|
||||
|
||||
std::vector<std::string> getTokenNames(const std::vector<Id>& ids) const;
|
||||
std::vector<std::string> getTokenDisplayNames(const std::vector<Id>& ids) const;
|
||||
std::vector<int> getTokenTypes(const std::vector<Id>& ids) const;
|
||||
std::string getDisplayName(Id id) const;
|
||||
TempEdge getEdge(const std::string& tokenName, const int tokenType) const;
|
||||
|
||||
std::pair<std::string, std::string> seperateEdgeToken(const std::string& token) const;
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> getFilteredBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const MessageDisplayBookmarks::BookmarkFilter& filter) const;
|
||||
std::vector<std::shared_ptr<Bookmark>> getOrderedBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const MessageDisplayBookmarks::BookmarkOrder& order) const;
|
||||
std::vector<std::shared_ptr<Bookmark>> getDateOrderedBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const bool ascending) const;
|
||||
std::vector<std::shared_ptr<Bookmark>> getNameOrderedBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const bool ascending) const;
|
||||
|
||||
void cleanBookmarkCategories();
|
||||
|
||||
static bool bookmarkDateCompare(const std::shared_ptr<Bookmark> a, const std::shared_ptr<Bookmark> b);
|
||||
static bool bookmarkNameCompare(const std::shared_ptr<Bookmark> a, const std::shared_ptr<Bookmark> b);
|
||||
|
||||
static const std::string m_edgeSeperatorToken;
|
||||
|
||||
StorageAccess* m_storageAccess;
|
||||
std::vector<Id> m_activeTokens;
|
||||
std::vector<std::string> m_activeTokenNames;
|
||||
std::vector<std::string> m_activeTokenDisplayNames;
|
||||
std::vector<int> m_activeTokenTypes;
|
||||
|
||||
std::vector<Id> m_activeEdges;
|
||||
std::vector<std::string> m_activeEdgeNames;
|
||||
std::vector<std::string> m_activeEdgeDisplayNames;
|
||||
std::vector<int> m_activeEdgeTypes;
|
||||
|
||||
bool m_activeTokenExists;
|
||||
};
|
||||
|
||||
#endif // BOOKMARK_CONTROLLER_H
|
||||
@@ -69,6 +69,11 @@ void IDECommunicationController::setEnabled(const bool enabled)
|
||||
m_enabled = enabled;
|
||||
}
|
||||
|
||||
void IDECommunicationController::sendInitialPing()
|
||||
{
|
||||
sendMessage(NetworkProtocolHelper::buildPingMessage());
|
||||
}
|
||||
|
||||
void IDECommunicationController::handleSetActiveTokenMessage(
|
||||
const NetworkProtocolHelper::SetActiveTokenMessage& message
|
||||
)
|
||||
@@ -175,6 +180,7 @@ void IDECommunicationController::handlePing(const NetworkProtocolHelper::PingMes
|
||||
if (msg.ideId == "vs")
|
||||
{
|
||||
ideName = "Visual Studio";
|
||||
msg.ideName = ideName;
|
||||
}
|
||||
// TODO: add the other ides
|
||||
|
||||
|
||||
@@ -34,6 +34,9 @@ public:
|
||||
bool getEnabled() const;
|
||||
void setEnabled(const bool enabled);
|
||||
|
||||
protected:
|
||||
void sendInitialPing();
|
||||
|
||||
private:
|
||||
void handleSetActiveTokenMessage(const NetworkProtocolHelper::SetActiveTokenMessage& message);
|
||||
void handleCreateProjectMessage(const NetworkProtocolHelper::CreateProjectMessage& message);
|
||||
|
||||
@@ -35,6 +35,14 @@ void StatusBarController::handleMessage(MessageFinishedParsing* message)
|
||||
getView()->setErrorCount(errorCount);
|
||||
}
|
||||
|
||||
void StatusBarController::handleMessage(MessagePingReceived* message)
|
||||
{
|
||||
std::string status = "Connected to ";
|
||||
status += message->ideName;
|
||||
|
||||
getView()->showIdeStatus(status);
|
||||
}
|
||||
|
||||
void StatusBarController::handleMessage(MessageRefresh* message)
|
||||
{
|
||||
getView()->setErrorCount(m_storageAccess->getErrorCount());
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageClearErrorCount.h"
|
||||
#include "utility/messaging/type/MessageFinishedParsing.h"
|
||||
#include "utility/messaging/type/MessagePingReceived.h"
|
||||
#include "utility/messaging/type/MessageRefresh.h"
|
||||
#include "utility/messaging/type/MessageShowErrors.h"
|
||||
#include "utility/messaging/type/MessageStatus.h"
|
||||
@@ -19,6 +20,7 @@ class StatusBarController
|
||||
: public Controller
|
||||
, public MessageListener<MessageClearErrorCount>
|
||||
, public MessageListener<MessageFinishedParsing>
|
||||
, public MessageListener<MessagePingReceived>
|
||||
, public MessageListener<MessageRefresh>
|
||||
, public MessageListener<MessageShowErrors>
|
||||
, public MessageListener<MessageStatus>
|
||||
@@ -34,6 +36,7 @@ public:
|
||||
private:
|
||||
virtual void handleMessage(MessageClearErrorCount* message);
|
||||
virtual void handleMessage(MessageFinishedParsing* message);
|
||||
virtual void handleMessage(MessagePingReceived* message);
|
||||
virtual void handleMessage(MessageRefresh* message);
|
||||
virtual void handleMessage(MessageShowErrors* message);
|
||||
virtual void handleMessage(MessageStatus* message);
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
#include "component/view/BookmarkView.h"
|
||||
|
||||
#include "component/controller/BookmarkController.h"
|
||||
|
||||
BookmarkView::BookmarkView(ViewLayout* viewLayout)
|
||||
: View(viewLayout)
|
||||
, m_filter(MessageDisplayBookmarks::BookmarkFilter::ALL)
|
||||
, m_order(MessageDisplayBookmarks::BookmarkOrder::DATE_DESCENDING)
|
||||
{
|
||||
}
|
||||
|
||||
BookmarkView::~BookmarkView()
|
||||
{
|
||||
}
|
||||
|
||||
std::string BookmarkView::getName() const
|
||||
{
|
||||
return "BookmarkView";
|
||||
}
|
||||
|
||||
void BookmarkView::update()
|
||||
{
|
||||
if (bookmarkBrowserIsVisible())
|
||||
{
|
||||
displayBookmarks(getController()->getBookmarks(m_filter, m_order));
|
||||
}
|
||||
}
|
||||
|
||||
BookmarkController* BookmarkView::getController()
|
||||
{
|
||||
return View::getController<BookmarkController>();
|
||||
}
|
||||
|
||||
void BookmarkView::handleMessage(MessageDisplayBookmarks* message)
|
||||
{
|
||||
if (bookmarkBrowserIsVisible() == true)
|
||||
{
|
||||
m_filter = message->filter;
|
||||
m_order = message->order;
|
||||
|
||||
displayBookmarks(getController()->getBookmarks(message->filter, message->order));
|
||||
}
|
||||
|
||||
displayBookmarks(getController()->getBookmarks(m_filter, m_order));
|
||||
}
|
||||
|
||||
void BookmarkView::handleMessage(MessageDisplayBookmarkCreator* message)
|
||||
{
|
||||
std::vector<std::string> names = getController()->getActiveTokenDisplayNames();
|
||||
|
||||
if (getController()->activeTokenExists())
|
||||
{
|
||||
std::vector<BookmarkCategory> categories = getController()->getAllBookmarkCategories();
|
||||
|
||||
displayBookmarkEditor(getController()->getBookmarkForActiveToken(), categories);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned int i = 0; i < names.size(); i++)
|
||||
{
|
||||
std::string name = names[i];
|
||||
|
||||
// skip the first letter as to not insert a leading space
|
||||
for (unsigned int i = 1; i < name.size(); i++)
|
||||
{
|
||||
if (std::isupper(name[i]))
|
||||
{
|
||||
name.insert(i, 1, ' ');
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
names[i] = name;
|
||||
}
|
||||
|
||||
displayBookmarkCreator(names, getController()->getAllBookmarkCategories());
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarkView::handleMessage(MessageDisplayBookmarkEditor* message)
|
||||
{
|
||||
std::vector<BookmarkCategory> categories = getController()->getAllBookmarkCategories();
|
||||
|
||||
displayBookmarkEditor(message->bookmark, categories);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#ifndef BOOKMARK_VIEW_H
|
||||
#define BOOKMARK_VIEW_H
|
||||
|
||||
#include "data/bookmark/Bookmark.h"
|
||||
|
||||
#include "component/view/View.h"
|
||||
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageDisplayBookmarks.h"
|
||||
#include "utility/messaging/type/MessageDisplayBookmarkCreator.h"
|
||||
#include "utility/messaging/type/MessageDisplayBookmarkEditor.h"
|
||||
|
||||
class BookmarkController;
|
||||
|
||||
class BookmarkView
|
||||
: public View
|
||||
, public MessageListener<MessageDisplayBookmarks>
|
||||
, public MessageListener<MessageDisplayBookmarkCreator>
|
||||
, public MessageListener<MessageDisplayBookmarkEditor>
|
||||
{
|
||||
public:
|
||||
BookmarkView(ViewLayout* viewLayout);
|
||||
virtual ~BookmarkView();
|
||||
|
||||
virtual std::string getName() const;
|
||||
|
||||
enum CreateButtonState
|
||||
{
|
||||
CAN_CREATE = 0,
|
||||
CANNOT_CREATE,
|
||||
ALREADY_CREATED
|
||||
};
|
||||
|
||||
virtual void setCreateButtonState(const CreateButtonState& state) = 0;
|
||||
virtual void enableDisplayBookmarks(bool enable) = 0;
|
||||
|
||||
virtual void update();
|
||||
|
||||
virtual bool bookmarkBrowserIsVisible() const = 0;
|
||||
|
||||
private:
|
||||
BookmarkController* getController();
|
||||
|
||||
virtual void handleMessage(MessageDisplayBookmarks* message);
|
||||
virtual void handleMessage(MessageDisplayBookmarkCreator* message);
|
||||
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 displayBookmarkEditor(std::shared_ptr<Bookmark> bookmark, const std::vector<BookmarkCategory>& categories) = 0;
|
||||
|
||||
MessageDisplayBookmarks::BookmarkFilter m_filter;
|
||||
MessageDisplayBookmarks::BookmarkOrder m_order;
|
||||
};
|
||||
|
||||
#endif // BOOKMARK_VIEW_H
|
||||
@@ -16,6 +16,8 @@ public:
|
||||
virtual void showMessage(const std::string& message, bool isError, bool showLoader) = 0;
|
||||
virtual void setErrorCount(ErrorCountInfo errorCount) = 0;
|
||||
|
||||
virtual void showIdeStatus(const std::string& message) = 0;
|
||||
|
||||
protected:
|
||||
StatusBarController* getController();
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "component/view/CompositeView.h"
|
||||
|
||||
class BookmarkView;
|
||||
class CodeView;
|
||||
class DialogView;
|
||||
class ErrorView;
|
||||
@@ -31,6 +32,7 @@ public:
|
||||
ViewLayout* viewLayout, CompositeView::CompositeDirection direction, const std::string& name) const = 0;
|
||||
virtual std::shared_ptr<TabbedView> createTabbedView(ViewLayout* viewLayout, const std::string& name) const = 0;
|
||||
|
||||
virtual std::shared_ptr<BookmarkView> createBookmarkView(ViewLayout* viewLayout) const = 0;
|
||||
virtual std::shared_ptr<CodeView> createCodeView(ViewLayout* viewLayout) const = 0;
|
||||
virtual std::shared_ptr<ErrorView> createErrorView(ViewLayout* viewLayout) const = 0;
|
||||
virtual std::shared_ptr<GraphView> createGraphView(ViewLayout* viewLayout) const = 0;
|
||||
|
||||
@@ -167,6 +167,13 @@ void IntermediateStorage::addError(const std::string& message, const FilePath& f
|
||||
));
|
||||
}
|
||||
|
||||
Id IntermediateStorage::addBookmark(const Bookmark& bookmark)
|
||||
{
|
||||
m_bookmarks.push_back(bookmark);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void IntermediateStorage::forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const
|
||||
{
|
||||
for (std::map<Id, std::shared_ptr<StorageNode>>::const_iterator it = m_nodeIdsToData.begin(); it != m_nodeIdsToData.end(); it++)
|
||||
|
||||
@@ -27,6 +27,7 @@ public:
|
||||
virtual void addComponentAccess(Id nodeId , int type);
|
||||
virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
|
||||
virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed);
|
||||
virtual Id addBookmark(const Bookmark& bookmark);
|
||||
|
||||
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const;
|
||||
virtual void forEachFile(std::function<void(const StorageFile& /*data*/)> callback) const;
|
||||
@@ -65,6 +66,7 @@ private:
|
||||
std::vector<StorageComponentAccess> m_componentAccesses;
|
||||
std::vector<StorageCommentLocation> m_commentLocations;
|
||||
std::vector<StorageError> m_errors;
|
||||
std::vector<Bookmark> m_bookmarks;
|
||||
|
||||
Id m_nextId;
|
||||
};
|
||||
|
||||
@@ -149,6 +149,86 @@ void PersistentStorage::addError(
|
||||
);
|
||||
}
|
||||
|
||||
Id PersistentStorage::addNodeBookmark(const NodeBookmark& bookmark)
|
||||
{
|
||||
return m_sqliteStorage.addNodeBookmark(bookmark);
|
||||
}
|
||||
|
||||
Id PersistentStorage::addEdgeBookmark(const EdgeBookmark& bookmark)
|
||||
{
|
||||
return m_sqliteStorage.addEdgeBookmark(bookmark);
|
||||
}
|
||||
|
||||
Id PersistentStorage::addBookmarkCategory(const BookmarkCategory& category)
|
||||
{
|
||||
return m_sqliteStorage.addBookmarkCategory(category.getName());
|
||||
}
|
||||
|
||||
std::vector<NodeBookmark> PersistentStorage::getAllNodeBookmarks() const
|
||||
{
|
||||
return m_sqliteStorage.getAllNodeBookmarks();
|
||||
}
|
||||
|
||||
NodeBookmark PersistentStorage::getNodeBookmarkById(const Id bookmarkId) const
|
||||
{
|
||||
return m_sqliteStorage.getNodeBookmarkById(bookmarkId);
|
||||
}
|
||||
|
||||
bool PersistentStorage::checkNodeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const
|
||||
{
|
||||
return m_sqliteStorage.checkNodeBookmarkExistsByNames(tokenNames);
|
||||
}
|
||||
|
||||
void PersistentStorage::removeNodeBookmark(Id id)
|
||||
{
|
||||
m_sqliteStorage.removeNodeBookmark(id);
|
||||
}
|
||||
|
||||
void PersistentStorage::editNodeBookmark(const NodeBookmark& bookmark)
|
||||
{
|
||||
m_sqliteStorage.editNodeBookmark(bookmark);
|
||||
}
|
||||
|
||||
std::vector<EdgeBookmark> PersistentStorage::getAllEdgeBookmarks() const
|
||||
{
|
||||
return m_sqliteStorage.getAllEdgeBookmarks();
|
||||
}
|
||||
|
||||
EdgeBookmark PersistentStorage::getEdgeBookmarkById(const Id bookmarkId) const
|
||||
{
|
||||
return m_sqliteStorage.getEdgeBookmarkById(bookmarkId);
|
||||
}
|
||||
|
||||
bool PersistentStorage::checkEdgeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const
|
||||
{
|
||||
return m_sqliteStorage.checkEdgeBookmarkExistsByNames(tokenNames);
|
||||
}
|
||||
|
||||
void PersistentStorage::removeEdgeBookmark(Id id)
|
||||
{
|
||||
m_sqliteStorage.removeEdgeBookmark(id);
|
||||
}
|
||||
|
||||
void PersistentStorage::editEdgeBookmark(const EdgeBookmark& bookmark)
|
||||
{
|
||||
m_sqliteStorage.editEdgeBookmark(bookmark);
|
||||
}
|
||||
|
||||
bool PersistentStorage::checkBookmarkCategoryExists(const std::string& name) const
|
||||
{
|
||||
return m_sqliteStorage.checkBookmarkCategoryExists(name);
|
||||
}
|
||||
|
||||
std::vector<BookmarkCategory> PersistentStorage::getAllBookmarkCategories() const
|
||||
{
|
||||
return m_sqliteStorage.getAllBookmarkCategories();
|
||||
}
|
||||
|
||||
void PersistentStorage::removeBookmarkCategory(Id id)
|
||||
{
|
||||
m_sqliteStorage.removeBookmarkCategory(id);
|
||||
}
|
||||
|
||||
void PersistentStorage::forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageNode& node: m_sqliteStorage.getAll<StorageNode>())
|
||||
@@ -394,6 +474,11 @@ Id PersistentStorage::getIdForEdge(
|
||||
return m_sqliteStorage.getEdgeBySourceTargetType(sourceId, targetId, type).id;
|
||||
}
|
||||
|
||||
StorageEdge PersistentStorage::getEdgeById(Id edgeId) const
|
||||
{
|
||||
return m_sqliteStorage.getEdgeById(edgeId);
|
||||
}
|
||||
|
||||
NameHierarchy PersistentStorage::getNameHierarchyForNodeWithId(Id nodeId) const
|
||||
{
|
||||
TRACE();
|
||||
@@ -907,6 +992,11 @@ std::vector<Id> PersistentStorage::getActiveTokenIdsForId(Id tokenId, Id* declar
|
||||
return activeTokenIds;
|
||||
}
|
||||
|
||||
bool PersistentStorage::checkEdgeExists(Id edgeId) const
|
||||
{
|
||||
return m_sqliteStorage.checkEdgeExists(edgeId);
|
||||
}
|
||||
|
||||
std::vector<Id> PersistentStorage::getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const
|
||||
{
|
||||
TRACE();
|
||||
@@ -975,6 +1065,11 @@ std::vector<Id> PersistentStorage::getLocalSymbolIdsForLocationIds(const std::ve
|
||||
return utility::toVector(localSymbolIds);
|
||||
}
|
||||
|
||||
bool PersistentStorage::checkNodeExistsByName(const std::string& serializedName) const
|
||||
{
|
||||
return m_sqliteStorage.checkNodeExistsByName(serializedName);
|
||||
}
|
||||
|
||||
std::vector<Id> PersistentStorage::getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const
|
||||
{
|
||||
FilePath rootPath = getDbFilePath().parentDirectory();
|
||||
|
||||
@@ -37,6 +37,25 @@ public:
|
||||
virtual void addComponentAccess(Id nodeId , int type);
|
||||
virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
|
||||
virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed);
|
||||
virtual Id addNodeBookmark(const NodeBookmark& bookmark);
|
||||
virtual Id addEdgeBookmark(const EdgeBookmark& bookmark);
|
||||
virtual Id addBookmarkCategory(const BookmarkCategory& category);
|
||||
|
||||
virtual std::vector<NodeBookmark> getAllNodeBookmarks() const;
|
||||
virtual NodeBookmark getNodeBookmarkById(const Id bookmarkId) const;
|
||||
virtual bool checkNodeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const;
|
||||
virtual void removeNodeBookmark(Id id);
|
||||
virtual void editNodeBookmark(const NodeBookmark& bookmark);
|
||||
|
||||
virtual std::vector<EdgeBookmark> getAllEdgeBookmarks() const;
|
||||
virtual EdgeBookmark getEdgeBookmarkById(const Id bookmarkId) const;
|
||||
virtual bool checkEdgeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const;
|
||||
virtual void removeEdgeBookmark(Id id);
|
||||
virtual void editEdgeBookmark(const EdgeBookmark& bookmark);
|
||||
|
||||
virtual bool checkBookmarkCategoryExists(const std::string& name) const;
|
||||
virtual std::vector<BookmarkCategory> getAllBookmarkCategories() const;
|
||||
virtual void removeBookmarkCategory(Id id);
|
||||
|
||||
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const;
|
||||
virtual void forEachFile(std::function<void(const StorageFile& /*data*/)> callback) const;
|
||||
@@ -80,6 +99,7 @@ public:
|
||||
virtual Id getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) const;
|
||||
virtual Id getIdForEdge(
|
||||
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const;
|
||||
virtual StorageEdge getEdgeById(Id edgeId) const;
|
||||
|
||||
virtual NameHierarchy getNameHierarchyForNodeWithId(Id nodeId) const;
|
||||
virtual Node::NodeType getNodeTypeForNodeWithId(Id nodeId) const;
|
||||
@@ -97,8 +117,11 @@ public:
|
||||
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const;
|
||||
|
||||
virtual bool checkEdgeExists(Id edgeId) const;
|
||||
|
||||
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const;
|
||||
virtual std::vector<Id> getLocalSymbolIdsForLocationIds(const std::vector<Id>& locationIds) const;
|
||||
virtual bool checkNodeExistsByName(const std::string& serializedName) const;
|
||||
|
||||
virtual std::vector<Id> getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const;
|
||||
virtual Id getTokenIdForFileNode(const FilePath& filePath) const;
|
||||
|
||||
@@ -328,6 +328,203 @@ Id SqliteStorage::addError(const std::string& message, const FilePath& filePath,
|
||||
return m_database.lastRowId();
|
||||
}
|
||||
|
||||
Id SqliteStorage::addNodeBookmark(const NodeBookmark& bookmark)
|
||||
{
|
||||
std::string tokenName = bookmark.getDisplayName();
|
||||
std::string comment = bookmark.getComment();
|
||||
std::string timeStamp = bookmark.getTimeStamp().toString();
|
||||
|
||||
tokenName = utility::replace(tokenName, "'", "''");
|
||||
comment = utility::replace(comment, "'", "''");
|
||||
|
||||
/*tokenName = utility::replace(tokenName, "\\", "/");
|
||||
comment = utility::replace(comment, "\\", "/");*/
|
||||
|
||||
// for backwards compatibility
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS nodeBookmark("
|
||||
"id INTEGER NOT NULL, "
|
||||
"name TEXT, "
|
||||
"comment TEXT, "
|
||||
"timestamp TEXT, "
|
||||
"category INTEGER, "
|
||||
"PRIMARY KEY(id), "
|
||||
"FOREIGN KEY(category) REFERENCES bookmarkCategory(id));"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS nodeBookmarkToken("
|
||||
"id INTEGER NOT NULL, "
|
||||
"bookmarkId INTEGER NOT NULL, "
|
||||
"name TEXT, "
|
||||
"type INTEGER, "
|
||||
"PRIMARY KEY(id), "
|
||||
"FOREIGN KEY(bookmarkId) REFERENCES nodeBookmark(id) ON DELETE CASCADE);"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS bookmarkCategory("
|
||||
"id INTEGER NOT NULL, "
|
||||
"name TEXT, "
|
||||
"PRIMARY KEY(id));"
|
||||
);
|
||||
|
||||
std::string statement = "INSERT INTO nodeBookmark(name, comment, timestamp, category) "
|
||||
"VALUES (?, ?, ?, ?);";
|
||||
|
||||
int categoryId = getOrCreateBookmarkCategoryByName(bookmark.getCategory().getName()).getId();
|
||||
|
||||
CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str());
|
||||
stmt.bind(1, tokenName.c_str());
|
||||
stmt.bind(2, comment.c_str());
|
||||
stmt.bind(3, timeStamp.c_str());
|
||||
stmt.bind(4, categoryId);
|
||||
|
||||
stmt.execDML();
|
||||
|
||||
Id id = m_database.lastRowId();
|
||||
|
||||
for (unsigned int i = 0; i < bookmark.getTokenNames().size(); i++)
|
||||
{
|
||||
std::string name = bookmark.getTokenNames()[i];
|
||||
int type = bookmark.getTokenTypes()[i];
|
||||
|
||||
statement = "INSERT INTO nodeBookmarkToken(bookmarkId, name, type) "
|
||||
"VALUES (" + std::to_string(id) + ", ?, " + std::to_string(type) + ");";
|
||||
|
||||
stmt = m_database.compileStatement(statement.c_str());
|
||||
stmt.bind(1, name.c_str());
|
||||
|
||||
stmt.execDML();
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
Id SqliteStorage::addEdgeBookmark(const EdgeBookmark& bookmark)
|
||||
{
|
||||
std::string tokenName = bookmark.getDisplayName();
|
||||
std::string comment = bookmark.getComment();
|
||||
std::string timeStamp = bookmark.getTimeStamp().toString();
|
||||
|
||||
tokenName = utility::replace(tokenName, "'", "''");
|
||||
comment = utility::replace(comment, "'", "''");
|
||||
|
||||
// for backwards compatibility
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS edgeBookmark("
|
||||
"id INTEGER NOT NULL, "
|
||||
"name TEXT, "
|
||||
"comment TEXT, "
|
||||
"timestamp TEXT, "
|
||||
"category INTEGER, "
|
||||
"PRIMARY KEY(id), "
|
||||
"FOREIGN KEY(category) REFERENCES bookmarkCategory(id));"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS edgeBookmarkToken("
|
||||
"id INTEGER NOT NULL, "
|
||||
"bookmarkId INTEGER NOT NULL, "
|
||||
"name TEXT, "
|
||||
"type INTEGER, "
|
||||
"PRIMARY KEY(id), "
|
||||
"FOREIGN KEY(bookmarkId) REFERENCES edgeBookmark(id) ON DELETE CASCADE);"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS edgeBaseBookmark("
|
||||
"id INTEGER NOT NULL, "
|
||||
"edgeId INTEGER, "
|
||||
"PRIMARY KEY(id), "
|
||||
"FOREIGN KEY(edgeId) REFERENCES edgeBookmark(id) ON DELETE CASCADE);"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS edgeBaseBookmarkToken("
|
||||
"id INTEGER NOT NULL, "
|
||||
"bookmarkId INTEGER NOT NULL, "
|
||||
"name TEXT, "
|
||||
"type INTEGER, "
|
||||
"PRIMARY KEY(id), "
|
||||
"FOREIGN KEY(bookmarkId) REFERENCES edgeBaseBookmark(id) ON DELETE CASCADE);"
|
||||
);
|
||||
|
||||
std::string statement = "INSERT INTO edgeBookmark(name, comment, timestamp, category) "
|
||||
"VALUES (?, ?, ?, ?);";
|
||||
|
||||
int categoryId = getOrCreateBookmarkCategoryByName(bookmark.getCategory().getName()).getId();
|
||||
|
||||
CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str());
|
||||
stmt.bind(1, tokenName.c_str());
|
||||
stmt.bind(2, comment.c_str());
|
||||
stmt.bind(3, timeStamp.c_str());
|
||||
stmt.bind(4, categoryId);
|
||||
|
||||
stmt.execDML();
|
||||
|
||||
Id id = m_database.lastRowId();
|
||||
|
||||
for (unsigned int i = 0; i < bookmark.getEdgeTokenNames().size(); i++)
|
||||
{
|
||||
std::string name = bookmark.getEdgeTokenNames()[i];
|
||||
int type = bookmark.getEdgeTokenTypes()[i];
|
||||
|
||||
statement = "INSERT INTO edgeBookmarkToken(bookmarkId, name, type) "
|
||||
"VALUES (" + std::to_string(id) + ", ?, " + std::to_string(type) + ");";
|
||||
|
||||
stmt = m_database.compileStatement(statement.c_str());
|
||||
stmt.bind(1, name.c_str());
|
||||
|
||||
stmt.execDML();
|
||||
}
|
||||
|
||||
statement = "INSERT INTO edgeBaseBookmark(edgeId) "
|
||||
"VALUES (" + std::to_string(id) + ");";
|
||||
stmt = m_database.compileStatement(statement.c_str());
|
||||
stmt.execDML();
|
||||
Id baseId = m_database.lastRowId();
|
||||
|
||||
for (unsigned int i = 0; i < bookmark.getTokenNames().size(); i++)
|
||||
{
|
||||
std::string name = bookmark.getTokenNames()[i];
|
||||
int type = bookmark.getTokenTypes()[i];
|
||||
|
||||
statement = "INSERT INTO edgeBaseBookmarkToken(bookmarkId, name, type) "
|
||||
"VALUES (" + std::to_string(baseId) + ", ?, " + std::to_string(bookmark.getTokenTypes()[i]) + ");";
|
||||
|
||||
stmt = m_database.compileStatement(statement.c_str());
|
||||
stmt.bind(1, bookmark.getTokenNames()[i].c_str());
|
||||
|
||||
stmt.execDML();
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
Id SqliteStorage::addBookmarkCategory(const std::string& name)
|
||||
{
|
||||
// for backwards compatibility
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS bookmarkCategory("
|
||||
"id INTEGER NOT NULL, "
|
||||
"name TEXT, "
|
||||
"PRIMARY KEY(id));"
|
||||
);
|
||||
|
||||
std::string statement = "INSERT INTO bookmarkCategory(name) "
|
||||
"VALUES (?);";
|
||||
|
||||
CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str());
|
||||
stmt.bind(1, name.c_str());
|
||||
|
||||
stmt.execDML();
|
||||
|
||||
Id id = m_database.lastRowId();
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void SqliteStorage::removeElement(Id id)
|
||||
{
|
||||
std::vector<Id> ids;
|
||||
@@ -509,6 +706,18 @@ bool SqliteStorage::isFile(Id elementId) const
|
||||
return (count > 0);
|
||||
}
|
||||
|
||||
StorageEdge SqliteStorage::getEdgeById(Id edgeId) const
|
||||
{
|
||||
std::vector<StorageEdge> candidates = doGetAll<StorageEdge>("WHERE id = " + std::to_string(edgeId));
|
||||
|
||||
if (candidates.size() > 0)
|
||||
{
|
||||
return candidates[0];
|
||||
}
|
||||
|
||||
return StorageEdge();
|
||||
}
|
||||
|
||||
StorageEdge SqliteStorage::getEdgeBySourceTargetType(Id sourceId, Id targetId, int type) const
|
||||
{
|
||||
return doGetFirst<StorageEdge>("WHERE "
|
||||
@@ -568,6 +777,39 @@ std::vector<StorageEdge> SqliteStorage::getEdgesByTargetsType(const std::vector<
|
||||
return doGetAll<StorageEdge>("WHERE target_node_id IN (" + utility::join(utility::toStrings(targetIds), ',') + ") AND type == " + std::to_string(type));
|
||||
}
|
||||
|
||||
bool SqliteStorage::checkEdgeExists(Id edgeId) const
|
||||
{
|
||||
CppSQLite3Statement stmt = m_database.compileStatement(
|
||||
("SELECT type FROM edge WHERE id == " + std::to_string(edgeId) + ";").c_str()
|
||||
);
|
||||
|
||||
CppSQLite3Query q = executeQuery(stmt);
|
||||
|
||||
if (!q.eof())
|
||||
{
|
||||
const int type = q.getIntField(0, -1);
|
||||
|
||||
if (type != -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
StorageNode SqliteStorage::getNodeById(Id id) const
|
||||
{
|
||||
std::vector<StorageNode> candidates = doGetAll<StorageNode>("WHERE id = " + std::to_string(id));
|
||||
|
||||
if (candidates.size() > 0)
|
||||
{
|
||||
return candidates[0];
|
||||
}
|
||||
|
||||
return StorageNode();
|
||||
}
|
||||
|
||||
StorageNode SqliteStorage::getNodeBySerializedName(const std::string& serializedName) const
|
||||
{
|
||||
CppSQLite3Statement stmt = m_database.compileStatement(
|
||||
@@ -592,6 +834,28 @@ StorageNode SqliteStorage::getNodeBySerializedName(const std::string& serialized
|
||||
return StorageNode();
|
||||
}
|
||||
|
||||
bool SqliteStorage::checkNodeExistsByName(const std::string& serializedName) const
|
||||
{
|
||||
CppSQLite3Statement stmt = m_database.compileStatement(
|
||||
"SELECT id FROM node WHERE serialized_name == ? LIMIT 1;"
|
||||
);
|
||||
|
||||
stmt.bind(1, serializedName.c_str());
|
||||
CppSQLite3Query q = executeQuery(stmt);
|
||||
|
||||
if (!q.eof())
|
||||
{
|
||||
const Id id = q.getIntField(0, 0);
|
||||
|
||||
if (id != -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
StorageLocalSymbol SqliteStorage::getLocalSymbolByName(const std::string& name) const
|
||||
{
|
||||
return doGetFirst<StorageLocalSymbol>("WHERE name == '" + name + "'");
|
||||
@@ -735,6 +999,278 @@ std::vector<StorageCommentLocation> SqliteStorage::getCommentLocationsInFile(con
|
||||
return doGetAll<StorageCommentLocation>("WHERE file_node_id == " + std::to_string(fileNodeId));
|
||||
}
|
||||
|
||||
std::vector<NodeBookmark> SqliteStorage::getAllNodeBookmarks() const
|
||||
{
|
||||
return doGetAll<NodeBookmark>("");
|
||||
}
|
||||
|
||||
NodeBookmark SqliteStorage::getNodeBookmarkById(const Id bookmarkId) const
|
||||
{
|
||||
std::vector<NodeBookmark> candidates = doGetAll<NodeBookmark>("WHERE id = " + std::to_string(bookmarkId));
|
||||
|
||||
if (candidates.size() > 0)
|
||||
{
|
||||
return candidates[0];
|
||||
}
|
||||
|
||||
return NodeBookmark();
|
||||
}
|
||||
|
||||
bool SqliteStorage::checkNodeBookmarkExistsByNames(const std::vector<std::string>& names) const
|
||||
{
|
||||
// bookmarks can only be uniquly identified by their token names.
|
||||
// therefore, a bookmark exists if there is an exactly matching set of 'bookmarkToken's with a common foreign key
|
||||
|
||||
if (names.size() <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::set<int> bookmarkIds;
|
||||
bool insert = true;
|
||||
|
||||
for (unsigned int i = 0; i < names.size(); i++)
|
||||
{
|
||||
CppSQLite3Query q = m_database.execQuery((
|
||||
"SELECT bookmarkId FROM nodeBookmarkToken WHERE name = '" + names[i] +"';"
|
||||
).c_str());
|
||||
|
||||
bool contains = false;
|
||||
|
||||
while (!q.eof())
|
||||
{
|
||||
int id = q.getIntField(0, -1);
|
||||
|
||||
if (insert)
|
||||
{
|
||||
bookmarkIds.insert(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bookmarkIds.find(id) != bookmarkIds.end())
|
||||
{
|
||||
contains = true;
|
||||
}
|
||||
}
|
||||
|
||||
q.nextRow();
|
||||
}
|
||||
|
||||
if ((contains == false && insert == false)
|
||||
|| bookmarkIds.size() <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
insert = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SqliteStorage::removeNodeBookmark(Id id)
|
||||
{
|
||||
executeStatement(
|
||||
"DELETE FROM nodeBookmark WHERE id = (" + std::to_string(id) + ");"
|
||||
);
|
||||
}
|
||||
|
||||
void SqliteStorage::editNodeBookmark(const NodeBookmark& bookmark)
|
||||
{
|
||||
std::string statement = "UPDATE nodeBookmark SET name=?, comment=?, category=? WHERE id=" + std::to_string(bookmark.getId()) + ";";
|
||||
|
||||
BookmarkCategory category = getBookmarkCategoryByName(bookmark.getCategory().getName());
|
||||
if (category.getId() == -1)
|
||||
{
|
||||
category.setId(addBookmarkCategory(bookmark.getCategory().getName()));
|
||||
category.setName(bookmark.getCategory().getName());
|
||||
}
|
||||
|
||||
CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str());
|
||||
stmt.bind(1, bookmark.getDisplayName().c_str());
|
||||
stmt.bind(2, bookmark.getComment().c_str());
|
||||
stmt.bind(3, (int)category.getId());
|
||||
|
||||
stmt.execDML();
|
||||
}
|
||||
|
||||
std::vector<EdgeBookmark> SqliteStorage::getAllEdgeBookmarks() const
|
||||
{
|
||||
return doGetAll<EdgeBookmark>("");
|
||||
}
|
||||
|
||||
EdgeBookmark SqliteStorage::getEdgeBookmarkById(const Id bookmarkId) const
|
||||
{
|
||||
std::vector<EdgeBookmark> candidates = doGetAll<EdgeBookmark>("WHERE id = " + std::to_string(bookmarkId));
|
||||
|
||||
if (candidates.size() > 0)
|
||||
{
|
||||
return candidates[0];
|
||||
}
|
||||
|
||||
return EdgeBookmark();
|
||||
}
|
||||
|
||||
bool SqliteStorage::checkEdgeBookmarkExistsByNames(const std::vector<std::string>& names) const
|
||||
{
|
||||
if (names.size() <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::set<int> bookmarkIds;
|
||||
bool insert = true;
|
||||
|
||||
for (unsigned int i = 0; i < names.size(); i++)
|
||||
{
|
||||
CppSQLite3Query q = m_database.execQuery((
|
||||
"SELECT bookmarkId FROM edgeBookmarkToken WHERE name = '" + names[i] + "';"
|
||||
).c_str());
|
||||
|
||||
bool contains = false;
|
||||
|
||||
while (!q.eof())
|
||||
{
|
||||
int id = q.getIntField(0, -1);
|
||||
|
||||
if (insert)
|
||||
{
|
||||
bookmarkIds.insert(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bookmarkIds.find(id) != bookmarkIds.end())
|
||||
{
|
||||
contains = true;
|
||||
}
|
||||
}
|
||||
|
||||
q.nextRow();
|
||||
}
|
||||
|
||||
if ((contains == false && insert == false)
|
||||
|| bookmarkIds.size() <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
insert = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SqliteStorage::removeEdgeBookmark(Id id)
|
||||
{
|
||||
executeStatement(
|
||||
"DELETE FROM edgeBookmark WHERE id = (" + std::to_string(id) + ");"
|
||||
);
|
||||
}
|
||||
|
||||
void SqliteStorage::editEdgeBookmark(const EdgeBookmark& bookmark)
|
||||
{
|
||||
std::string statement = "UPDATE edgeBookmark SET name=?, comment=?, category=? WHERE id=" + std::to_string(bookmark.getId()) + ";";
|
||||
|
||||
BookmarkCategory category = getBookmarkCategoryByName(bookmark.getCategory().getName());
|
||||
if (category.getId() == -1)
|
||||
{
|
||||
category.setId(addBookmarkCategory(bookmark.getCategory().getName()));
|
||||
category.setName(bookmark.getCategory().getName());
|
||||
}
|
||||
|
||||
CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str());
|
||||
stmt.bind(1, bookmark.getDisplayName().c_str());
|
||||
stmt.bind(2, bookmark.getComment().c_str());
|
||||
stmt.bind(3, (int)category.getId());
|
||||
|
||||
stmt.execDML();
|
||||
}
|
||||
|
||||
std::vector<BookmarkCategory> SqliteStorage::getAllBookmarkCategories() const
|
||||
{
|
||||
return doGetAll<BookmarkCategory>("");
|
||||
}
|
||||
|
||||
BookmarkCategory SqliteStorage::getBookmarkCategoryByName(const std::string& name) const
|
||||
{
|
||||
BookmarkCategory category;
|
||||
category.setName("");
|
||||
category.setId(-1);
|
||||
|
||||
CppSQLite3Query q = m_database.execQuery((
|
||||
"SELECT id FROM bookmarkCategory WHERE name = '" + name + "';"
|
||||
).c_str());
|
||||
|
||||
while (!q.eof())
|
||||
{
|
||||
int id = q.getIntField(0, -1);
|
||||
|
||||
if (id > -1)
|
||||
{
|
||||
category.setName(name);
|
||||
category.setId(id);
|
||||
}
|
||||
|
||||
q.nextRow();
|
||||
}
|
||||
|
||||
return category;
|
||||
}
|
||||
|
||||
BookmarkCategory SqliteStorage::getOrCreateBookmarkCategoryByName(const std::string& name)
|
||||
{
|
||||
if (checkBookmarkCategoryExists(name))
|
||||
{
|
||||
return getBookmarkCategoryByName(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Id id = addBookmarkCategory(name);
|
||||
BookmarkCategory result;
|
||||
result.setName(name);
|
||||
result.setId(id);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
bool SqliteStorage::checkBookmarkCategoryExists(const std::string& name) const
|
||||
{
|
||||
CppSQLite3Query q = m_database.execQuery((
|
||||
"SELECT id FROM bookmarkCategory WHERE name = '" + name + "';"
|
||||
).c_str());
|
||||
|
||||
while (!q.eof())
|
||||
{
|
||||
int id = q.getIntField(0, -1);
|
||||
|
||||
if (id > -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
q.nextRow();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void SqliteStorage::removeBookmarkCategory(Id id)
|
||||
{
|
||||
executeStatement(
|
||||
"DELETE FROM bookmarkCategory WHERE id = (" + std::to_string(id) + ");"
|
||||
);
|
||||
}
|
||||
|
||||
Id SqliteStorage::getTokenIdByName(const std::string& name) const
|
||||
{
|
||||
/*CppSQLite3Query q = m_database.execQuery((
|
||||
"SELECT id FROM bookmark WHERE " + " foo " + ";"
|
||||
).c_str());*/
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int SqliteStorage::getNodeCount() const
|
||||
{
|
||||
return executeScalar("SELECT COUNT(*) FROM node;");
|
||||
@@ -913,10 +1449,81 @@ void SqliteStorage::setupTables()
|
||||
"column_number INTEGER, "
|
||||
"PRIMARY KEY(id));"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS bookmarkCategory("
|
||||
"id INTEGER NOT NULL, "
|
||||
"name TEXT, "
|
||||
"PRIMARY KEY(id));"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS nodeBookmark("
|
||||
"id INTEGER NOT NULL, "
|
||||
"name TEXT, "
|
||||
"comment TEXT, "
|
||||
"timestamp TEXT, "
|
||||
"category INTEGER, "
|
||||
"PRIMARY KEY(id), "
|
||||
"FOREIGN KEY(category) REFERENCES bookmarkCategory(id));"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS edgeBookmark("
|
||||
"id INTEGER NOT NULL, "
|
||||
"name TEXT, "
|
||||
"comment TEXT, "
|
||||
"timestamp TEXT, "
|
||||
"category INTEGER, "
|
||||
"PRIMARY KEY(id), "
|
||||
"FOREIGN KEY(category) REFERENCES bookmarkCategory(id));"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS nodeBookmarkToken("
|
||||
"id INTEGER NOT NULL, "
|
||||
"bookmarkId INTEGER NOT NULL, "
|
||||
"name TEXT, "
|
||||
"type INTEGER, "
|
||||
"PRIMARY KEY(id), "
|
||||
"FOREIGN KEY(bookmarkId) REFERENCES nodeBookmark(id) ON DELETE CASCADE);"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS edgeBookmarkToken("
|
||||
"id INTEGER NOT NULL, "
|
||||
"bookmarkId INTEGER NOT NULL, "
|
||||
"name TEXT, "
|
||||
"type INTEGER, "
|
||||
"PRIMARY KEY(id), "
|
||||
"FOREIGN KEY(bookmarkId) REFERENCES edgeBookmark(id) ON DELETE CASCADE);"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS edgeBaseBookmark("
|
||||
"id INTEGER NOT NULL, "
|
||||
"edgeId INTEGER, "
|
||||
"PRIMARY KEY(id), "
|
||||
"FOREIGN KEY(edgeId) REFERENCES edgeBookmark(id) ON DELETE CASCADE);"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS edgeBaseBookmarkToken("
|
||||
"id INTEGER NOT NULL, "
|
||||
"bookmarkId INTEGER NOT NULL, "
|
||||
"name TEXT, "
|
||||
"type INTEGER, "
|
||||
"PRIMARY KEY(id), "
|
||||
"FOREIGN KEY(bookmarkId) REFERENCES edgeBaseBookmark(id) ON DELETE CASCADE);"
|
||||
);
|
||||
}
|
||||
catch (CppSQLite3Exception& e)
|
||||
{
|
||||
LOG_ERROR(std::to_string(e.errorCode()) + ": " + e.errorMessage());
|
||||
|
||||
throw(std::exception("fail"));
|
||||
|
||||
// todo: cancel project creation and destroy created files, display message
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1318,3 +1925,186 @@ std::vector<StorageError> SqliteStorage::doGetAll<StorageError>(const std::strin
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<NodeBookmark> SqliteStorage::doGetAll<NodeBookmark>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = m_database.execQuery((
|
||||
"SELECT id, name, comment, timestamp, category FROM nodeBookmark " + query + ";"
|
||||
).c_str());
|
||||
|
||||
std::vector<NodeBookmark> bookmarks;
|
||||
bookmarks.clear();
|
||||
|
||||
while (!q.eof())
|
||||
{
|
||||
const int id = q.getIntField(0, -1);
|
||||
const std::string name = q.getStringField(1, "");
|
||||
const std::string comment = q.getStringField(2, "");
|
||||
const std::string timeStamp = q.getStringField(3, "");
|
||||
const int categoryId = q.getIntField(4, -1);
|
||||
|
||||
CppSQLite3Query qSub = m_database.execQuery((
|
||||
"SELECT name, type FROM nodeBookmarkToken WHERE bookmarkId = " + std::to_string(id) + ";"
|
||||
).c_str());
|
||||
|
||||
std::vector<std::string> tokenNames;
|
||||
std::vector<int> tokenTypes;
|
||||
|
||||
while (!qSub.eof())
|
||||
{
|
||||
const std::string tokenName = qSub.getStringField(0, "");
|
||||
const int tokenType = qSub.getIntField(1, -1);
|
||||
tokenNames.push_back(tokenName);
|
||||
tokenTypes.push_back(tokenType);
|
||||
qSub.nextRow();
|
||||
}
|
||||
|
||||
NodeBookmark bookmark(name, std::vector<Id>(), tokenNames, comment, TimePoint(timeStamp));
|
||||
bookmark.setId(id);
|
||||
bookmark.setTokenTypes(tokenTypes);
|
||||
|
||||
qSub = m_database.execQuery((
|
||||
"SELECT id, name FROM bookmarkCategory WHERE id = " + std::to_string(categoryId) + ";"
|
||||
).c_str());
|
||||
|
||||
while (!qSub.eof())
|
||||
{
|
||||
const int categoryId = qSub.getIntField(0, -1);
|
||||
const std::string name = qSub.getStringField(1, "");
|
||||
BookmarkCategory category;
|
||||
category.setId(categoryId);
|
||||
category.setName(name);
|
||||
bookmark.setCategory(category);
|
||||
|
||||
qSub.nextRow();
|
||||
}
|
||||
|
||||
bookmarks.push_back(bookmark);
|
||||
|
||||
q.nextRow();
|
||||
}
|
||||
|
||||
return bookmarks;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<EdgeBookmark> SqliteStorage::doGetAll<EdgeBookmark>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = m_database.execQuery((
|
||||
"SELECT id, name, comment, timestamp, category FROM edgeBookmark " + query + ";"
|
||||
).c_str());
|
||||
|
||||
std::vector<EdgeBookmark> bookmarks;
|
||||
bookmarks.clear();
|
||||
|
||||
while (!q.eof())
|
||||
{
|
||||
const int id = q.getIntField(0, -1);
|
||||
const std::string name = q.getStringField(1, "");
|
||||
const std::string comment = q.getStringField(2, "");
|
||||
const std::string timeStamp = q.getStringField(3, "");
|
||||
const int categoryId = q.getIntField(4, -1);
|
||||
|
||||
CppSQLite3Query qSub = m_database.execQuery((
|
||||
"SELECT name, type FROM edgeBookmarkToken WHERE bookmarkId = " + std::to_string(id) + ";"
|
||||
).c_str());
|
||||
|
||||
|
||||
std::vector<std::string> tokenNames;
|
||||
std::vector<int> tokenTypes;
|
||||
while (!qSub.eof())
|
||||
{
|
||||
const std::string tokenName = qSub.getStringField(0, "");
|
||||
const int tokenType = qSub.getIntField(1, -1);
|
||||
tokenNames.push_back(tokenName);
|
||||
tokenTypes.push_back(tokenType);
|
||||
qSub.nextRow();
|
||||
}
|
||||
|
||||
qSub = m_database.execQuery((
|
||||
"SELECT id FROM edgeBaseBookmark WHERE edgeId = " + std::to_string(id) + ";"
|
||||
).c_str());
|
||||
|
||||
NodeBookmark baseBookmark; // there should only be one base bookmark, if there are more use the last one
|
||||
while (!qSub.eof())
|
||||
{
|
||||
const int baseId = qSub.getIntField(0, -1);
|
||||
|
||||
baseBookmark.setId(baseId);
|
||||
|
||||
CppSQLite3Query qSubSub = m_database.execQuery((
|
||||
"SELECT id, name, type FROM edgeBaseBookmarkToken WHERE bookmarkId = " + std::to_string(baseId) + ";"
|
||||
).c_str());
|
||||
|
||||
std::vector<std::string> baseTokenNames;
|
||||
std::vector<int> baseTokenTypes;
|
||||
while (!qSubSub.eof())
|
||||
{
|
||||
const std::string baseTokenName = qSubSub.getStringField(1, "");
|
||||
const int baseTokenType = qSubSub.getIntField(2, -1);
|
||||
baseTokenNames.push_back(baseTokenName);
|
||||
baseTokenTypes.push_back(baseTokenType);
|
||||
qSubSub.nextRow();
|
||||
}
|
||||
|
||||
baseBookmark.setTokenNames(baseTokenNames);
|
||||
baseBookmark.setTokenTypes(baseTokenTypes);
|
||||
|
||||
qSub.nextRow();
|
||||
}
|
||||
|
||||
EdgeBookmark bookmark(name, std::vector<Id>(), tokenNames, comment, TimePoint(timeStamp));
|
||||
bookmark.setTokenTypes(tokenTypes);
|
||||
bookmark.setBaseBookmark(baseBookmark);
|
||||
bookmark.setId(id);
|
||||
|
||||
qSub = m_database.execQuery((
|
||||
"SELECT id, name FROM bookmarkCategory WHERE id = " + std::to_string(categoryId) + ";"
|
||||
).c_str());
|
||||
|
||||
while (!qSub.eof())
|
||||
{
|
||||
const int categoryId = qSub.getIntField(0, -1);
|
||||
const std::string name = qSub.getStringField(1, "");
|
||||
BookmarkCategory category;
|
||||
category.setId(categoryId);
|
||||
category.setName(name);
|
||||
bookmark.setCategory(category);
|
||||
|
||||
qSub.nextRow();
|
||||
}
|
||||
|
||||
bookmarks.push_back(bookmark);
|
||||
|
||||
q.nextRow();
|
||||
}
|
||||
|
||||
return bookmarks;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<BookmarkCategory> SqliteStorage::doGetAll<BookmarkCategory>(const std::string& query) const
|
||||
{
|
||||
std::vector<BookmarkCategory> categories;
|
||||
|
||||
CppSQLite3Query q = m_database.execQuery((
|
||||
"SELECT id, name FROM bookmarkCategory " + query + ";"
|
||||
).c_str());
|
||||
|
||||
while (!q.eof())
|
||||
{
|
||||
const int id = q.getIntField(0, -1);
|
||||
const std::string name = q.getStringField(1, "");
|
||||
|
||||
BookmarkCategory category;
|
||||
category.setId(id);
|
||||
category.setName(name);
|
||||
|
||||
categories.push_back(category);
|
||||
|
||||
q.nextRow();
|
||||
}
|
||||
|
||||
return categories;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
#include "sqlite/CppSQLite3.h"
|
||||
|
||||
#include "data/bookmark/BookmarkCategory.h"
|
||||
#include "data/bookmark/EdgeBookmark.h"
|
||||
#include "data/bookmark/NodeBookmark.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/TokenLocationCollection.h"
|
||||
#include "data/name/NameHierarchy.h"
|
||||
@@ -66,6 +69,9 @@ public:
|
||||
Id addComponentAccess(Id nodeId, int type);
|
||||
Id addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
|
||||
Id addError(const std::string& message, const FilePath& filePath, uint lineNumber, uint columnNumber, bool fatal, bool indexed);
|
||||
Id addNodeBookmark(const NodeBookmark& bookmark);
|
||||
Id addEdgeBookmark(const EdgeBookmark& bookmark);
|
||||
Id addBookmarkCategory(const std::string& name);
|
||||
|
||||
void removeElement(Id id);
|
||||
void removeElements(const std::vector<Id>& ids);
|
||||
@@ -77,6 +83,7 @@ public:
|
||||
bool isNode(Id elementId) const;
|
||||
bool isFile(Id elementId) const;
|
||||
|
||||
StorageEdge getEdgeById(Id edgeId) const;
|
||||
StorageEdge getEdgeBySourceTargetType(Id sourceId, Id targetId, int type) const;
|
||||
|
||||
std::vector<StorageEdge> getEdgesBySourceId(Id sourceId) const;
|
||||
@@ -91,7 +98,11 @@ public:
|
||||
std::vector<StorageEdge> getEdgesByTargetType(Id targetId, int type) const;
|
||||
std::vector<StorageEdge> getEdgesByTargetsType(const std::vector<Id>& targetIds, int type) const;
|
||||
|
||||
bool checkEdgeExists(Id edgeId) const;
|
||||
|
||||
StorageNode getNodeById(Id id) const;
|
||||
StorageNode getNodeBySerializedName(const std::string& serializedName) const;
|
||||
bool checkNodeExistsByName(const std::string& serializedName) const;
|
||||
|
||||
StorageLocalSymbol getLocalSymbolByName(const std::string& name) const;
|
||||
|
||||
@@ -121,6 +132,26 @@ public:
|
||||
return doGetAll<ResultType>("");
|
||||
}
|
||||
|
||||
std::vector<NodeBookmark> getAllNodeBookmarks() const;
|
||||
NodeBookmark getNodeBookmarkById(const Id bookmarkId) const;
|
||||
bool checkNodeBookmarkExistsByNames(const std::vector<std::string>& names) const;
|
||||
void removeNodeBookmark(Id id);
|
||||
void editNodeBookmark(const NodeBookmark& bookmark);
|
||||
|
||||
std::vector<EdgeBookmark> getAllEdgeBookmarks() const;
|
||||
EdgeBookmark getEdgeBookmarkById(const Id bookmarkId) const;
|
||||
bool checkEdgeBookmarkExistsByNames(const std::vector<std::string>& names) const;
|
||||
void removeEdgeBookmark(Id id);
|
||||
void editEdgeBookmark(const EdgeBookmark& bookmark);
|
||||
|
||||
std::vector<BookmarkCategory> getAllBookmarkCategories() const;
|
||||
BookmarkCategory getBookmarkCategoryByName(const std::string& name) const;
|
||||
BookmarkCategory getOrCreateBookmarkCategoryByName(const std::string& name);
|
||||
bool checkBookmarkCategoryExists(const std::string& name) const;
|
||||
void removeBookmarkCategory(Id id);
|
||||
|
||||
Id getTokenIdByName(const std::string& name) const;
|
||||
|
||||
template <typename ResultType>
|
||||
ResultType getFirstById(const Id id) const
|
||||
{
|
||||
@@ -200,6 +231,8 @@ std::vector<StorageLocalSymbol> SqliteStorage::doGetAll<StorageLocalSymbol>(cons
|
||||
template <>
|
||||
std::vector<StorageSourceLocation> SqliteStorage::doGetAll<StorageSourceLocation>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<NodeBookmark> SqliteStorage::doGetAll<NodeBookmark>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageOccurrence> SqliteStorage::doGetAll<StorageOccurrence>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageComponentAccess> SqliteStorage::doGetAll<StorageComponentAccess>(const std::string& query) const;
|
||||
@@ -207,6 +240,11 @@ template <>
|
||||
std::vector<StorageCommentLocation> SqliteStorage::doGetAll<StorageCommentLocation>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageError> SqliteStorage::doGetAll<StorageError>(const std::string& query) const;
|
||||
|
||||
template <>
|
||||
std::vector<Bookmark> SqliteStorage::doGetAll<Bookmark>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<EdgeBookmark> SqliteStorage::doGetAll<EdgeBookmark>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<BookmarkCategory> SqliteStorage::doGetAll<BookmarkCategory>(const std::string& query) const;
|
||||
|
||||
#endif // SQLITE_STORAGE_H
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include "data/bookmark/Bookmark.h"
|
||||
#include "data/name/NameHierarchy.h"
|
||||
#include "data/StorageTypes.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
#include "utility/file/FileInfo.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
#include "data/bookmark/Bookmark.h"
|
||||
#include "data/bookmark/BookmarkCategory.h"
|
||||
#include "data/bookmark/EdgeBookmark.h"
|
||||
#include "data/bookmark/NodeBookmark.h"
|
||||
#include "data/parser/ParseLocation.h"
|
||||
#include "data/graph/Node.h"
|
||||
#include "data/search/SearchMatch.h"
|
||||
@@ -32,9 +36,13 @@ public:
|
||||
virtual Id getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) const = 0;
|
||||
virtual Id getIdForEdge(
|
||||
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const = 0;
|
||||
virtual StorageEdge getEdgeById(Id edgeId) const = 0;
|
||||
|
||||
virtual bool checkEdgeExists(Id edgeId) const = 0;
|
||||
|
||||
virtual NameHierarchy getNameHierarchyForNodeWithId(Id id) const = 0;
|
||||
virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const = 0;
|
||||
virtual bool checkNodeExistsByName(const std::string& serializedName) const = 0;
|
||||
|
||||
virtual std::shared_ptr<TokenLocationCollection> getFullTextSearchLocations(
|
||||
const std::string& searchTerm, bool caseSensitive) const = 0;
|
||||
@@ -76,6 +84,26 @@ public:
|
||||
|
||||
virtual void setErrorFilter(const ErrorFilter& filter);
|
||||
|
||||
virtual Id addNodeBookmark(const NodeBookmark& bookmark) = 0;
|
||||
virtual Id addEdgeBookmark(const EdgeBookmark& bookmark) = 0;
|
||||
virtual Id addBookmarkCategory(const BookmarkCategory& category) = 0;
|
||||
|
||||
virtual std::vector<NodeBookmark> getAllNodeBookmarks() const = 0;
|
||||
virtual NodeBookmark getNodeBookmarkById(const Id bookmarkId) const = 0;
|
||||
virtual bool checkNodeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const = 0;
|
||||
virtual void removeNodeBookmark(Id id) = 0;
|
||||
virtual void editNodeBookmark(const NodeBookmark& bookmark) = 0;
|
||||
|
||||
virtual std::vector<EdgeBookmark> getAllEdgeBookmarks() const = 0;
|
||||
virtual EdgeBookmark getEdgeBookmarkById(const Id bookmarkId) const = 0;
|
||||
virtual bool checkEdgeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const = 0;
|
||||
virtual void removeEdgeBookmark(Id id) = 0;
|
||||
virtual void editEdgeBookmark(const EdgeBookmark& bookmark) = 0;
|
||||
|
||||
virtual std::vector<BookmarkCategory> getAllBookmarkCategories() const = 0;
|
||||
virtual bool checkBookmarkCategoryExists(const std::string& name) const = 0;
|
||||
virtual void removeBookmarkCategory(Id id) = 0;
|
||||
|
||||
protected:
|
||||
ErrorFilter m_errorFilter;
|
||||
};
|
||||
|
||||
@@ -57,6 +57,24 @@ Id StorageAccessProxy::getIdForEdge(
|
||||
return 0;
|
||||
}
|
||||
|
||||
StorageEdge StorageAccessProxy::getEdgeById(Id edgeId) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getEdgeById(edgeId);
|
||||
}
|
||||
}
|
||||
|
||||
bool StorageAccessProxy::checkEdgeExists(Id edgeId) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->checkEdgeExists(edgeId);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Node::NodeType StorageAccessProxy::getNodeTypeForNodeWithId(Id id) const
|
||||
{
|
||||
if (hasSubject())
|
||||
@@ -66,6 +84,15 @@ Node::NodeType StorageAccessProxy::getNodeTypeForNodeWithId(Id id) const
|
||||
return Node::NODE_NON_INDEXED;
|
||||
}
|
||||
|
||||
bool StorageAccessProxy::checkNodeExistsByName(const std::string& serializedName) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->checkNodeExistsByName(serializedName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
NameHierarchy StorageAccessProxy::getNameHierarchyForNodeWithId(Id id) const
|
||||
{
|
||||
if (hasSubject())
|
||||
@@ -302,6 +329,156 @@ std::shared_ptr<TokenLocationCollection> StorageAccessProxy::getErrorTokenLocati
|
||||
return std::make_shared<TokenLocationCollection>();
|
||||
}
|
||||
|
||||
Id StorageAccessProxy::addNodeBookmark(const NodeBookmark& bookmark)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->addNodeBookmark(bookmark);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
Id StorageAccessProxy::addEdgeBookmark(const EdgeBookmark& bookmark)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->addEdgeBookmark(bookmark);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
Id StorageAccessProxy::addBookmarkCategory(const BookmarkCategory& category)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->addBookmarkCategory(category);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::vector<NodeBookmark> StorageAccessProxy::getAllNodeBookmarks() const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getAllNodeBookmarks();
|
||||
}
|
||||
|
||||
return std::vector<NodeBookmark>();
|
||||
}
|
||||
|
||||
NodeBookmark StorageAccessProxy::getNodeBookmarkById(const Id bookmarkId) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getNodeBookmarkById(bookmarkId);
|
||||
}
|
||||
|
||||
return NodeBookmark();
|
||||
}
|
||||
|
||||
bool StorageAccessProxy::checkNodeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->checkNodeBookmarkExistsByTokens(tokenNames);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void StorageAccessProxy::removeNodeBookmark(Id id)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
m_subject->removeNodeBookmark(id);
|
||||
}
|
||||
}
|
||||
|
||||
void StorageAccessProxy::editNodeBookmark(const NodeBookmark& bookmark)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
m_subject->editNodeBookmark(bookmark);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<EdgeBookmark> StorageAccessProxy::getAllEdgeBookmarks() const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getAllEdgeBookmarks();
|
||||
}
|
||||
|
||||
return std::vector<EdgeBookmark>();
|
||||
}
|
||||
|
||||
EdgeBookmark StorageAccessProxy::getEdgeBookmarkById(const Id bookmarkId) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getEdgeBookmarkById(bookmarkId);
|
||||
}
|
||||
|
||||
return EdgeBookmark();
|
||||
}
|
||||
|
||||
bool StorageAccessProxy::checkEdgeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->checkEdgeBookmarkExistsByTokens(tokenNames);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void StorageAccessProxy::removeEdgeBookmark(Id id)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
m_subject->removeEdgeBookmark(id);
|
||||
}
|
||||
}
|
||||
|
||||
void StorageAccessProxy::editEdgeBookmark(const EdgeBookmark& bookmark)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
m_subject->editEdgeBookmark(bookmark);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<BookmarkCategory> StorageAccessProxy::getAllBookmarkCategories() const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getAllBookmarkCategories();
|
||||
}
|
||||
|
||||
return std::vector<BookmarkCategory>();
|
||||
}
|
||||
|
||||
bool StorageAccessProxy::checkBookmarkCategoryExists(const std::string& name) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->checkBookmarkCategoryExists(name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void StorageAccessProxy::removeBookmarkCategory(Id id)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
m_subject->removeBookmarkCategory(id);
|
||||
}
|
||||
}
|
||||
|
||||
void StorageAccessProxy::setErrorFilter(const ErrorFilter& filter)
|
||||
{
|
||||
StorageAccess::setErrorFilter(filter);
|
||||
|
||||
@@ -21,9 +21,13 @@ public:
|
||||
virtual Id getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) const;
|
||||
virtual Id getIdForEdge(
|
||||
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const;
|
||||
virtual StorageEdge getEdgeById(Id edgeId) const;
|
||||
|
||||
virtual bool checkEdgeExists(Id edgeId) const;
|
||||
|
||||
virtual NameHierarchy getNameHierarchyForNodeWithId(Id id) const;
|
||||
virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const;
|
||||
virtual bool checkNodeExistsByName(const std::string& serializedName) const;
|
||||
|
||||
virtual std::shared_ptr<TokenLocationCollection> getFullTextSearchLocations(
|
||||
const std::string& searchTerm, bool caseSensitive) const;
|
||||
@@ -66,6 +70,26 @@ public:
|
||||
|
||||
virtual std::shared_ptr<TokenLocationCollection> getErrorTokenLocations(std::vector<ErrorInfo>* errors) const;
|
||||
|
||||
virtual Id addNodeBookmark(const NodeBookmark& bookmark);
|
||||
virtual Id addEdgeBookmark(const EdgeBookmark& bookmark);
|
||||
virtual Id addBookmarkCategory(const BookmarkCategory& category);
|
||||
|
||||
virtual std::vector<NodeBookmark> getAllNodeBookmarks() const;
|
||||
virtual NodeBookmark getNodeBookmarkById(const Id bookmarkId) const;
|
||||
virtual bool checkNodeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const;
|
||||
virtual void removeNodeBookmark(Id id);
|
||||
virtual void editNodeBookmark(const NodeBookmark& bookmark);
|
||||
|
||||
virtual std::vector<EdgeBookmark> getAllEdgeBookmarks() const;
|
||||
virtual EdgeBookmark getEdgeBookmarkById(const Id bookmarkId) const;
|
||||
virtual bool checkEdgeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const;
|
||||
virtual void removeEdgeBookmark(Id id);
|
||||
virtual void editEdgeBookmark(const EdgeBookmark& bookmark);
|
||||
|
||||
virtual virtual std::vector<BookmarkCategory> getAllBookmarkCategories() const;
|
||||
virtual bool checkBookmarkCategoryExists(const std::string& name) const;
|
||||
virtual void removeBookmarkCategory(Id id);
|
||||
|
||||
protected:
|
||||
virtual void setErrorFilter(const ErrorFilter& filter);
|
||||
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
#include "Bookmark.h"
|
||||
|
||||
Bookmark::Bookmark()
|
||||
: m_id(-1)
|
||||
, m_tokenTypes()
|
||||
, m_tokenIds()
|
||||
, m_tokenNames()
|
||||
, m_comment("")
|
||||
, m_displayName("")
|
||||
, m_valid(false)
|
||||
, m_timeStamp()
|
||||
, m_category()
|
||||
{
|
||||
}
|
||||
|
||||
Bookmark::Bookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp)
|
||||
: m_id(-1)
|
||||
, m_tokenTypes()
|
||||
, m_tokenIds(tokens)
|
||||
, m_tokenNames(tokenNames)
|
||||
, m_comment(comment)
|
||||
, m_displayName(displayName)
|
||||
, m_valid(false)
|
||||
, m_timeStamp(timeStamp)
|
||||
, m_category()
|
||||
{
|
||||
}
|
||||
|
||||
Bookmark::~Bookmark()
|
||||
{
|
||||
}
|
||||
|
||||
Id Bookmark::getId() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
void Bookmark::setId(const Id id)
|
||||
{
|
||||
m_id = id;
|
||||
}
|
||||
|
||||
std::vector<int> Bookmark::getTokenTypes() const
|
||||
{
|
||||
return m_tokenTypes;
|
||||
}
|
||||
|
||||
void Bookmark::setTokenTypes(const std::vector<int>& types)
|
||||
{
|
||||
m_tokenTypes = types;
|
||||
}
|
||||
|
||||
std::vector<Id> Bookmark::getTokenIds() const
|
||||
{
|
||||
return m_tokenIds;
|
||||
}
|
||||
|
||||
void Bookmark::setTokenIds(const std::vector<Id>& ids)
|
||||
{
|
||||
m_tokenIds = ids;
|
||||
}
|
||||
|
||||
std::vector<std::string> Bookmark::getTokenNames() const
|
||||
{
|
||||
return m_tokenNames;
|
||||
}
|
||||
|
||||
void Bookmark::setTokenNames(const std::vector<std::string>& names)
|
||||
{
|
||||
m_tokenNames = names;
|
||||
}
|
||||
|
||||
std::string Bookmark::getComment() const
|
||||
{
|
||||
return m_comment;
|
||||
}
|
||||
|
||||
void Bookmark::setComment(const std::string& comment)
|
||||
{
|
||||
m_comment = comment;
|
||||
}
|
||||
|
||||
std::string Bookmark::getDisplayName() const
|
||||
{
|
||||
return m_displayName;
|
||||
}
|
||||
|
||||
void Bookmark::setDisplayName(const std::string& name)
|
||||
{
|
||||
m_displayName = name;
|
||||
}
|
||||
|
||||
bool Bookmark::isValid() const
|
||||
{
|
||||
return m_valid;
|
||||
}
|
||||
|
||||
void Bookmark::setValid(const bool valid)
|
||||
{
|
||||
m_valid = valid;
|
||||
}
|
||||
|
||||
TimePoint Bookmark::getTimeStamp() const
|
||||
{
|
||||
return m_timeStamp;
|
||||
}
|
||||
|
||||
BookmarkCategory Bookmark::getCategory() const
|
||||
{
|
||||
return m_category;
|
||||
}
|
||||
|
||||
void Bookmark::setCategory(const BookmarkCategory& category)
|
||||
{
|
||||
m_category = category;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#ifndef BOOKMARK_H
|
||||
#define BOOKMARK_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "utility/TimePoint.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
#include "BookmarkCategory.h"
|
||||
|
||||
class Bookmark
|
||||
{
|
||||
public:
|
||||
Bookmark();
|
||||
Bookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp);
|
||||
virtual ~Bookmark();
|
||||
|
||||
Id getId() const;
|
||||
void setId(const Id id);
|
||||
|
||||
std::vector<int> getTokenTypes() const;
|
||||
void setTokenTypes(const std::vector<int>& types);
|
||||
|
||||
std::vector<Id> getTokenIds() const;
|
||||
void setTokenIds(const std::vector<Id>& ids);
|
||||
|
||||
std::vector<std::string> getTokenNames() const;
|
||||
void setTokenNames(const std::vector<std::string>& names);
|
||||
|
||||
std::string getComment() const;
|
||||
void setComment(const std::string& comment);
|
||||
|
||||
std::string getDisplayName() const;
|
||||
void setDisplayName(const std::string& name);
|
||||
|
||||
bool isValid() const;
|
||||
void setValid(const bool valid);
|
||||
|
||||
TimePoint getTimeStamp() const;
|
||||
|
||||
BookmarkCategory getCategory() const;
|
||||
void setCategory(const BookmarkCategory& category);
|
||||
|
||||
private:
|
||||
Id m_id;
|
||||
std::vector<int> m_tokenTypes;
|
||||
std::vector<Id> m_tokenIds;
|
||||
std::vector<std::string> m_tokenNames;
|
||||
std::string m_comment;
|
||||
std::string m_displayName;
|
||||
|
||||
bool m_valid;
|
||||
|
||||
TimePoint m_timeStamp;
|
||||
|
||||
BookmarkCategory m_category;
|
||||
};
|
||||
|
||||
#endif // BOOKMARK_H
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "BookmarkCategory.h"
|
||||
|
||||
BookmarkCategory::BookmarkCategory()
|
||||
: m_id(-1)
|
||||
, m_name("")
|
||||
{
|
||||
}
|
||||
|
||||
BookmarkCategory::~BookmarkCategory()
|
||||
{
|
||||
}
|
||||
|
||||
Id BookmarkCategory::getId() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
void BookmarkCategory::setId(const Id id)
|
||||
{
|
||||
m_id = id;
|
||||
}
|
||||
|
||||
std::string BookmarkCategory::getName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void BookmarkCategory::setName(const std::string& name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef BOOKMARK_CATEGORY_H
|
||||
#define BOOKMARK_CATEGORY_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "utility/types.h"
|
||||
|
||||
class BookmarkCategory
|
||||
{
|
||||
public:
|
||||
BookmarkCategory();
|
||||
~BookmarkCategory();
|
||||
|
||||
Id getId() const;
|
||||
void setId(const Id id);
|
||||
|
||||
std::string getName() const;
|
||||
void setName(const std::string& name);
|
||||
|
||||
private:
|
||||
Id m_id;
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
#endif // BOOKMARK_CATEGORY_H
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "EdgeBookmark.h"
|
||||
|
||||
EdgeBookmark::EdgeBookmark()
|
||||
: Bookmark()
|
||||
{
|
||||
}
|
||||
|
||||
EdgeBookmark::EdgeBookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp)
|
||||
: Bookmark(displayName, tokens, tokenNames, comment, timeStamp)
|
||||
{
|
||||
}
|
||||
|
||||
EdgeBookmark::~EdgeBookmark()
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<int> EdgeBookmark::getEdgeTokenTypes() const
|
||||
{
|
||||
return m_edgeTokenTypes;
|
||||
}
|
||||
|
||||
void EdgeBookmark::setEdgeTokenTypes(const std::vector<int>& tokenTypes)
|
||||
{
|
||||
m_edgeTokenTypes = tokenTypes;
|
||||
}
|
||||
|
||||
std::vector<Id> EdgeBookmark::getEdgeTokenIds() const
|
||||
{
|
||||
return m_edgeTokenIds;
|
||||
}
|
||||
|
||||
void EdgeBookmark::setEdgeTokenIds(const std::vector<Id>& tokenIds)
|
||||
{
|
||||
m_edgeTokenIds = tokenIds;
|
||||
}
|
||||
|
||||
std::vector<std::string> EdgeBookmark::getEdgeTokenNames() const
|
||||
{
|
||||
return m_edgeTokenNames;
|
||||
}
|
||||
|
||||
void EdgeBookmark::setEdgeTokenNames(const std::vector<std::string>& tokenNames)
|
||||
{
|
||||
m_edgeTokenNames = tokenNames;
|
||||
}
|
||||
|
||||
NodeBookmark EdgeBookmark::getBaseBookmark() const
|
||||
{
|
||||
return m_baseBookmark;
|
||||
}
|
||||
|
||||
void EdgeBookmark::setBaseBookmark(const NodeBookmark& baseBookmark)
|
||||
{
|
||||
m_baseBookmark = baseBookmark;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef EDGE_BOOKMARK_H
|
||||
#define EDGE_BOOKMARK_H
|
||||
|
||||
#include "Bookmark.h"
|
||||
#include "NodeBookmark.h"
|
||||
|
||||
class EdgeBookmark
|
||||
: public Bookmark
|
||||
{
|
||||
public:
|
||||
EdgeBookmark();
|
||||
EdgeBookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp);
|
||||
virtual ~EdgeBookmark();
|
||||
|
||||
std::vector<int> getEdgeTokenTypes() const;
|
||||
void setEdgeTokenTypes(const std::vector<int>& tokenTypes);
|
||||
|
||||
std::vector<Id> getEdgeTokenIds() const;
|
||||
void setEdgeTokenIds(const std::vector<Id>& tokenIds);
|
||||
|
||||
std::vector<std::string> getEdgeTokenNames() const;
|
||||
void setEdgeTokenNames(const std::vector<std::string>& tokenNames);
|
||||
|
||||
NodeBookmark getBaseBookmark() const;
|
||||
void setBaseBookmark(const NodeBookmark& baseBookmark);
|
||||
|
||||
private:
|
||||
std::vector<int> m_edgeTokenTypes;
|
||||
std::vector<Id> m_edgeTokenIds;
|
||||
std::vector<std::string> m_edgeTokenNames;
|
||||
|
||||
NodeBookmark m_baseBookmark;
|
||||
};
|
||||
|
||||
#endif // EDGE_BOOKMARK_H
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "NodeBookmark.h"
|
||||
|
||||
NodeBookmark::NodeBookmark()
|
||||
: Bookmark()
|
||||
{
|
||||
}
|
||||
|
||||
NodeBookmark::NodeBookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp)
|
||||
: Bookmark(displayName, tokens, tokenNames, comment, timeStamp)
|
||||
{
|
||||
}
|
||||
|
||||
NodeBookmark::~NodeBookmark()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef NODE_BOOKMARK_H
|
||||
#define NODE_BOOKMARK_H
|
||||
|
||||
#include "Bookmark.h"
|
||||
|
||||
class NodeBookmark
|
||||
: public Bookmark
|
||||
{
|
||||
public:
|
||||
NodeBookmark();
|
||||
NodeBookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp);
|
||||
virtual ~NodeBookmark();
|
||||
};
|
||||
|
||||
#endif // NODE_BOOKMARK_H
|
||||
@@ -44,7 +44,35 @@ std::string TimePoint::toString() const
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string TimePoint::getDDMMYYYYString() const
|
||||
{
|
||||
std::stringstream stream;
|
||||
boost::posix_time::time_facet* facet = new boost::posix_time::time_facet();
|
||||
facet->format("%d-%m-%Y");
|
||||
stream.imbue(std::locale(std::locale::classic(), facet));
|
||||
stream << m_time;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
size_t TimePoint::deltaMS(const TimePoint& other) const
|
||||
{
|
||||
return (m_time - other.m_time).total_milliseconds();
|
||||
}
|
||||
|
||||
bool TimePoint::isSameDay(const TimePoint& other) const
|
||||
{
|
||||
if (m_time.date().day() == other.m_time.date().day() &&
|
||||
m_time.date().month() == other.m_time.date().month() &&
|
||||
m_time.date().year() == other.m_time.date().year())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t TimePoint::deltaDays(const TimePoint& other) const
|
||||
{
|
||||
boost::gregorian::date_duration deltaDate = m_time.date() - other.m_time.date();
|
||||
return size_t(std::abs(deltaDate.days()));
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||
|
||||
class TimePoint
|
||||
class TimePoint // that name sounds pretty silly, was time stamp not ok?
|
||||
{
|
||||
public:
|
||||
static TimePoint now();
|
||||
@@ -16,6 +16,7 @@ public:
|
||||
bool isValid() const;
|
||||
|
||||
std::string toString() const;
|
||||
std::string getDDMMYYYYString() const;
|
||||
|
||||
inline bool operator==(const TimePoint& rhs){ return m_time == rhs.m_time; }
|
||||
inline bool operator!=(const TimePoint& rhs){ return m_time != rhs.m_time; }
|
||||
@@ -28,6 +29,9 @@ public:
|
||||
|
||||
size_t deltaMS(const TimePoint& other) const;
|
||||
|
||||
bool isSameDay(const TimePoint& other) const;
|
||||
size_t deltaDays(const TimePoint& other) const; // days are counted beginning at 00:00, so a tp of 1.1.2017 23:59 is 1 day ago if it's the 2.1.2017 00:01
|
||||
|
||||
private:
|
||||
boost::posix_time::ptime m_time;
|
||||
};
|
||||
|
||||
@@ -16,8 +16,15 @@ std::shared_ptr<LogManager> LogManager::createInstance()
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
// what is this method for? why would you want to risk returning s_instance without checking whether it is initialized???
|
||||
std::shared_ptr<LogManager> LogManager::getInstance()
|
||||
{
|
||||
// return s_instance; // original implementation
|
||||
|
||||
if (s_instance.use_count() == 0)
|
||||
{
|
||||
s_instance = std::shared_ptr<LogManager>(new LogManager());
|
||||
}
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef MESSAGE_ACTIVATE_BOOKMARK_H
|
||||
#define MESSAGE_ACTIVATE_BOOKMARK_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
|
||||
#include "data/bookmark/Bookmark.h"
|
||||
|
||||
class MessageActivateBookmark
|
||||
: public Message<MessageActivateBookmark>
|
||||
{
|
||||
public:
|
||||
MessageActivateBookmark(const std::shared_ptr<Bookmark>& bookmark)
|
||||
: bookmark(bookmark)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~MessageActivateBookmark()
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageActivateBookmark";
|
||||
}
|
||||
|
||||
const std::shared_ptr<Bookmark> bookmark;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_ACTIVATE_BOOKMARK_H
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef MESSAGE_CREATE_BOOKMARK_H
|
||||
#define MESSAGE_CREATE_BOOKMARK_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
|
||||
class MessageCreateBookmark
|
||||
: public Message<MessageCreateBookmark>
|
||||
{
|
||||
public:
|
||||
MessageCreateBookmark(const std::string& comment, const std::string& displayName, const std::string& categoryName)
|
||||
: comment(comment)
|
||||
, displayName(displayName)
|
||||
, categoryName(categoryName)
|
||||
{
|
||||
}
|
||||
|
||||
~MessageCreateBookmark()
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageCreateBookmark";
|
||||
}
|
||||
|
||||
const std::string comment;
|
||||
const std::string displayName;
|
||||
const std::string categoryName;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_CREATE_BOOKMARK_H
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef MESSAGE_CREATE_BOOKMARK_CATEGORY_H
|
||||
#define MESSAGE_CREATE_BOOKMARK_CATEGORY_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
|
||||
class MessageCreateBookmarkCategory
|
||||
: public Message<MessageCreateBookmarkCategory>
|
||||
{
|
||||
public:
|
||||
MessageCreateBookmarkCategory(const std::string& name)
|
||||
: name(name)
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageCreateBookmarkCategory";
|
||||
}
|
||||
|
||||
const std::string name;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_CREATE_BOOKMARK_CATEGORY_H
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef MESSAGE_DELETE_BOOKMARK_H
|
||||
#define MESSAGE_DELETE_BOOKMARK_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class MessageDeleteBookmark
|
||||
: public Message<MessageDeleteBookmark>
|
||||
{
|
||||
public:
|
||||
MessageDeleteBookmark(const Id bookmarkId, const bool isEdge)
|
||||
: bookmarkId(bookmarkId)
|
||||
, isEdge(isEdge)
|
||||
{
|
||||
}
|
||||
|
||||
~MessageDeleteBookmark()
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageDeleteBookmark";
|
||||
}
|
||||
|
||||
const Id bookmarkId;
|
||||
const bool isEdge;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_DELETE_BOOKMARK_H
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef MESSAGE_DELETE_BOOKMARK_CATEGORY_WITH_BOOKMARKS_H
|
||||
#define MESSAGE_DELETE_BOOKMARK_CATEGORY_WITH_BOOKMARKS_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class MessageDeleteBookmarkCategoryWithBookmarks
|
||||
: public Message<MessageDeleteBookmarkCategoryWithBookmarks>
|
||||
{
|
||||
public:
|
||||
MessageDeleteBookmarkCategoryWithBookmarks(const Id id)
|
||||
: categoryId(id)
|
||||
{
|
||||
}
|
||||
|
||||
~MessageDeleteBookmarkCategoryWithBookmarks()
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageDeleteBookmarkCategoryWithBookmarks";
|
||||
}
|
||||
|
||||
const Id categoryId;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_DELETE_BOOKMARK_CATEGORY_WITH_BOOKMARKS_H
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef MESSAGE_DELETE_BOOKMARK_FOR_ACTIVE_TOKENS
|
||||
#define MESSAGE_DELETE_BOOKMARK_FOR_ACTIVE_TOKENS
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
|
||||
class MessageDeleteBookmarkForActiveTokens
|
||||
: public Message<MessageDeleteBookmarkForActiveTokens>
|
||||
{
|
||||
public:
|
||||
MessageDeleteBookmarkForActiveTokens()
|
||||
{
|
||||
}
|
||||
|
||||
~MessageDeleteBookmarkForActiveTokens()
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageDeleteBookmarkForActiveTokens";
|
||||
}
|
||||
};
|
||||
|
||||
#endif // MESSAGE_DELETE_BOOKMARK_FOR_ACTIVE_TOKENS
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef MESSAGE_DISPLAY_BOOKMARK_CREATOR_H
|
||||
#define MESSAGE_DISPLAY_BOOKMARK_CREATOR_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
|
||||
class MessageDisplayBookmarkCreator
|
||||
: public Message<MessageDisplayBookmarkCreator>
|
||||
{
|
||||
public:
|
||||
MessageDisplayBookmarkCreator()
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageDisplayBookmarkCreator";
|
||||
}
|
||||
};
|
||||
|
||||
#endif // MESSAGE_DISPLAY_BOOKMARK_CREATOR_H
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef MESSAGE_DISPLAY_BOOKMARK_EDITOR_H
|
||||
#define MESSAGE_DISPLAY_BOOKMARK_EDITOR_H
|
||||
|
||||
#include "data/bookmark/Bookmark.h"
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
|
||||
class MessageDisplayBookmarkEditor
|
||||
: public Message<MessageDisplayBookmarkEditor>
|
||||
{
|
||||
public:
|
||||
MessageDisplayBookmarkEditor(std::shared_ptr<Bookmark> bookmark)
|
||||
: bookmark(bookmark)
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageDisplayBookmarkEditor";
|
||||
}
|
||||
|
||||
std::shared_ptr<Bookmark> bookmark;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_DISPLAY_BOOKMARK_EDITOR_H
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef MESSAGE_DISPLAY_BOOKMARKS_H
|
||||
#define MESSAGE_DISPLAY_BOOKMARKS_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
|
||||
class MessageDisplayBookmarks
|
||||
: public Message<MessageDisplayBookmarks>
|
||||
{
|
||||
public:
|
||||
enum BookmarkFilter
|
||||
{
|
||||
UNKNOWN = 0,
|
||||
ALL,
|
||||
NODES,
|
||||
EDGES
|
||||
};
|
||||
|
||||
enum BookmarkOrder
|
||||
{
|
||||
NONE = 0,
|
||||
DATE_ASCENDING,
|
||||
DATE_DESCENDING,
|
||||
NAME_ASCENDING,
|
||||
NAME_DESCENDING
|
||||
};
|
||||
|
||||
MessageDisplayBookmarks(const BookmarkFilter& filter, const BookmarkOrder& order)
|
||||
: filter(filter)
|
||||
, order(order)
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageDisplayBookmarks";
|
||||
}
|
||||
|
||||
const BookmarkFilter filter;
|
||||
const BookmarkOrder order;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_DISPLAY_BOOKMARKS_H
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef MESSAGE_EDIT_BOOKMARK_H
|
||||
#define MESSAGE_EDIT_BOOKMARK_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
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)
|
||||
: bookmarkId(id)
|
||||
, comment(comment)
|
||||
, displayName(displayName)
|
||||
, categoryName(categoryName)
|
||||
, isEdge(isEdge)
|
||||
{
|
||||
}
|
||||
|
||||
~MessageEditBookmark()
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageEditBookmark";
|
||||
}
|
||||
|
||||
const Id bookmarkId;
|
||||
const std::string comment;
|
||||
const std::string displayName;
|
||||
const std::string categoryName;
|
||||
const bool isEdge;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_EDIT_BOOKMARK_H
|
||||
@@ -9,6 +9,7 @@ class MessagePingReceived
|
||||
public:
|
||||
MessagePingReceived()
|
||||
: ideId("")
|
||||
, ideName("")
|
||||
{
|
||||
}
|
||||
|
||||
@@ -18,6 +19,7 @@ public:
|
||||
}
|
||||
|
||||
std::string ideId;
|
||||
std::string ideName;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_PING_RECEIVED_H
|
||||
Reference in New Issue
Block a user