From e03f764e31eb635c4114aef511ef9a986377dd62 Mon Sep 17 00:00:00 2001 From: Sergio Regueira Date: Fri, 4 Aug 2017 12:51:21 +0200 Subject: [PATCH 1/2] Added a new option to extract the identifier (string) from an ObjectId --- src/robomongo/core/domain/Notifier.cpp | 22 ++++++++++++++++++++++ src/robomongo/core/domain/Notifier.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/robomongo/core/domain/Notifier.cpp b/src/robomongo/core/domain/Notifier.cpp index e0ce16801..a500f8a56 100644 --- a/src/robomongo/core/domain/Notifier.cpp +++ b/src/robomongo/core/domain/Notifier.cpp @@ -132,6 +132,9 @@ namespace Robomongo _copyTimestampAction = new QAction("Copy Timestamp from ObjectId", wid); VERIFY(connect(_copyTimestampAction, SIGNAL(triggered()), SLOT(onCopyTimestamp()))); + _copyIdentifierAction = new QAction("Copy Identifier from ObjectId", wid); + VERIFY(connect(_copyIdentifierAction, SIGNAL(triggered()), SLOT(onCopyIdentifier()))); + _copyJsonAction = new QAction("Copy JSON", wid); VERIFY(connect(_copyJsonAction, SIGNAL(triggered()), SLOT(onCopyJson()))); } @@ -476,6 +479,25 @@ namespace Robomongo } } + void Notifier::onCopyIdentifier() + { + QModelIndex selectedInd = _observer->selectedIndex(); + if (!selectedInd.isValid()) + return; + + BsonTreeItem *documentItem = QtUtils::item(selectedInd); + if (!documentItem) + return; + + if (!detail::isObjectIdType(documentItem)) + return; + + QString identifier = documentItem->value().mid(10, 24); + + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(identifier); + } + void Notifier::onCopyJson() { QModelIndex selectedInd = _observer->selectedIndex(); diff --git a/src/robomongo/core/domain/Notifier.h b/src/robomongo/core/domain/Notifier.h index eebbc4833..0f966d149 100644 --- a/src/robomongo/core/domain/Notifier.h +++ b/src/robomongo/core/domain/Notifier.h @@ -56,6 +56,7 @@ namespace Robomongo void onInsertDocument(); void onCopyDocument(); void onCopyTimestamp(); + void onCopyIdentifier(); void onCopyJson(); void handle(InsertDocumentResponse *event); void handle(RemoveDocumentResponse *event); From 7dfed5afd185a818b30ccb03cf729f4e5ff0ddb0 Mon Sep 17 00:00:00 2001 From: Sergio Regueira Date: Fri, 4 Aug 2017 12:51:21 +0200 Subject: [PATCH 2/2] Added a new option to extract the identifier (string) from an ObjectId --- src/robomongo/core/domain/Notifier.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/robomongo/core/domain/Notifier.cpp b/src/robomongo/core/domain/Notifier.cpp index a500f8a56..2e68f5db3 100644 --- a/src/robomongo/core/domain/Notifier.cpp +++ b/src/robomongo/core/domain/Notifier.cpp @@ -171,6 +171,7 @@ namespace Robomongo menu->addAction(_copyValuePathAction); if (onItem && isObjectId) menu->addAction(_copyTimestampAction); + if (onItem && isObjectId) menu->addAction(_copyIdentifierAction); if (onItem && isDocument) menu->addAction(_copyJsonAction); if (onItem && isEditable) menu->addSeparator(); if (onItem && isEditable) menu->addAction(_deleteDocumentAction);