CodePaster: Register type safe service object

Use Q_DECLARE_INTERFACE et al.
This provides a way to have the dependency on code pasting
optional in the using plugins (VCS, diff editor), while
still being able to use a nice API to perform the pasting itself.

Change-Id: Ia61e0066d552e45031f4aa7fd1f6693b68f92384
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
This commit is contained in:
Eike Ziller
2015-06-29 14:22:17 +02:00
parent 81272a9fdb
commit ce96a8b80a
11 changed files with 135 additions and 64 deletions

View File

@@ -40,6 +40,7 @@
#include <coreplugin/vcsmanager.h>
#include <coreplugin/patchtool.h>
#include <coreplugin/editormanager/editormanager.h>
#include <cpaster/codepasterservice.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/editorconfiguration.h>
#include <projectexplorer/projectexplorer.h>
@@ -953,9 +954,12 @@ void VcsBaseEditorWidget::contextMenuEvent(QContextMenuEvent *e)
switch (d->m_parameters->type) {
case LogOutput: // log might have diff
case DiffOutput: {
menu->addSeparator();
connect(menu->addAction(tr("Send to CodePaster...")), &QAction::triggered,
this, &VcsBaseEditorWidget::slotPaste);
if (ExtensionSystem::PluginManager::getObject<CodePaster::Service>()) {
// optional code pasting service
menu->addSeparator();
connect(menu->addAction(tr("Send to CodePaster...")), &QAction::triggered,
this, &VcsBaseEditorWidget::slotPaste);
}
menu->addSeparator();
// Apply/revert diff chunk.
const DiffChunk chunk = diffChunk(cursorForPosition(e->pos()));
@@ -1472,14 +1476,9 @@ QStringList VcsBaseEditorWidget::annotationPreviousVersions(const QString &) con
void VcsBaseEditorWidget::slotPaste()
{
// Retrieve service by soft dependency.
QObject *pasteService =
ExtensionSystem::PluginManager::getObjectByClassName(QLatin1String("CodePaster::CodePasterService"));
if (pasteService) {
QMetaObject::invokeMethod(pasteService, "postCurrentEditor");
} else {
QMessageBox::information(this, tr("Unable to Paste"),
tr("Code pasting services are not available."));
}
auto pasteService = ExtensionSystem::PluginManager::getObject<CodePaster::Service>();
QTC_ASSERT(pasteService, return);
pasteService->postCurrentEditor();
}
void VcsBaseEditorWidget::showProgressIndicator()