diff --git a/src/robomongo/core/domain/Notifier.cpp b/src/robomongo/core/domain/Notifier.cpp index e0ce16801..2e68f5db3 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()))); } @@ -168,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); @@ -476,6 +480,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);