summaryrefslogtreecommitdiff
path: root/src/plugins/diffeditor
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@theqtcompany.com>2015-06-29 14:22:17 +0200
committerEike Ziller <eike.ziller@theqtcompany.com>2015-07-08 07:41:43 +0000
commitce96a8b80ade646b77594deaee893eab6ab92897 (patch)
treed5c2c1085f42d5eab1c765c3c7644f3f4712c5f7 /src/plugins/diffeditor
parent81272a9fdb9a1779352cafba1da401448446d9a1 (diff)
downloadqt-creator-ce96a8b80ade646b77594deaee893eab6ab92897.tar.gz
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>
Diffstat (limited to 'src/plugins/diffeditor')
-rw-r--r--src/plugins/diffeditor/diffeditor.qbs4
-rw-r--r--src/plugins/diffeditor/diffeditor_dependencies.pri2
-rw-r--r--src/plugins/diffeditor/sidebysidediffeditorwidget.cpp45
-rw-r--r--src/plugins/diffeditor/unifieddiffeditorwidget.cpp31
4 files changed, 45 insertions, 37 deletions
diff --git a/src/plugins/diffeditor/diffeditor.qbs b/src/plugins/diffeditor/diffeditor.qbs
index 8a23861f95..d7266c7dfc 100644
--- a/src/plugins/diffeditor/diffeditor.qbs
+++ b/src/plugins/diffeditor/diffeditor.qbs
@@ -9,6 +9,10 @@ QtcPlugin {
Depends { name: "Core" }
Depends { name: "TextEditor" }
+ pluginRecommends: [
+ "CodePaster"
+ ]
+
files: [
"diffeditor.cpp",
"diffeditor.h",
diff --git a/src/plugins/diffeditor/diffeditor_dependencies.pri b/src/plugins/diffeditor/diffeditor_dependencies.pri
index 0458f03fbe..abe8944152 100644
--- a/src/plugins/diffeditor/diffeditor_dependencies.pri
+++ b/src/plugins/diffeditor/diffeditor_dependencies.pri
@@ -5,3 +5,5 @@ QTC_LIB_DEPENDS += \
QTC_PLUGIN_DEPENDS += \
texteditor \
coreplugin
+QTC_PLUGIN_RECOMMENDS += \
+ cpaster
diff --git a/src/plugins/diffeditor/sidebysidediffeditorwidget.cpp b/src/plugins/diffeditor/sidebysidediffeditorwidget.cpp
index ce218a52fb..9a5fc0abc8 100644
--- a/src/plugins/diffeditor/sidebysidediffeditorwidget.cpp
+++ b/src/plugins/diffeditor/sidebysidediffeditorwidget.cpp
@@ -56,8 +56,11 @@
#include <coreplugin/minisplitter.h>
#include <coreplugin/patchtool.h>
+#include <cpaster/codepasterservice.h>
+
#include <extensionsystem/pluginmanager.h>
+#include <utils/qtcassert.h>
#include <utils/tooltip/tooltip.h>
using namespace Core;
@@ -894,11 +897,14 @@ void SideBySideDiffEditorWidget::slotLeftContextMenuRequested(QMenu *menu,
int chunkIndex)
{
menu->addSeparator();
- QAction *sendChunkToCodePasterAction =
- menu->addAction(tr("Send Chunk to CodePaster..."));
- connect(sendChunkToCodePasterAction, &QAction::triggered,
- this, &SideBySideDiffEditorWidget::slotSendChunkToCodePaster);
- menu->addSeparator();
+ if (ExtensionSystem::PluginManager::getObject<CodePaster::Service>()) {
+ // optional code pasting service
+ QAction *sendChunkToCodePasterAction =
+ menu->addAction(tr("Send Chunk to CodePaster..."));
+ connect(sendChunkToCodePasterAction, &QAction::triggered,
+ this, &SideBySideDiffEditorWidget::slotSendChunkToCodePaster);
+ menu->addSeparator();
+ }
QAction *applyAction = menu->addAction(tr("Apply Chunk..."));
connect(applyAction, &QAction::triggered, this, &SideBySideDiffEditorWidget::slotApplyChunk);
applyAction->setEnabled(false);
@@ -929,11 +935,14 @@ void SideBySideDiffEditorWidget::slotRightContextMenuRequested(QMenu *menu,
int chunkIndex)
{
menu->addSeparator();
- QAction *sendChunkToCodePasterAction =
- menu->addAction(tr("Send Chunk to CodePaster..."));
- connect(sendChunkToCodePasterAction, &QAction::triggered,
- this, &SideBySideDiffEditorWidget::slotSendChunkToCodePaster);
- menu->addSeparator();
+ if (ExtensionSystem::PluginManager::getObject<CodePaster::Service>()) {
+ // optional code pasting service
+ QAction *sendChunkToCodePasterAction =
+ menu->addAction(tr("Send Chunk to CodePaster..."));
+ connect(sendChunkToCodePasterAction, &QAction::triggered,
+ this, &SideBySideDiffEditorWidget::slotSendChunkToCodePaster);
+ menu->addSeparator();
+ }
QAction *revertAction = menu->addAction(tr("Revert Chunk..."));
connect(revertAction, &QAction::triggered, this, &SideBySideDiffEditorWidget::slotRevertChunk);
revertAction->setEnabled(false);
@@ -961,21 +970,15 @@ void SideBySideDiffEditorWidget::slotSendChunkToCodePaster()
if (!m_document)
return;
+ // Retrieve service by soft dependency.
+ auto pasteService = ExtensionSystem::PluginManager::getObject<CodePaster::Service>();
+ QTC_ASSERT(pasteService, return);
+
const QString patch = m_document->makePatch(m_contextMenuFileIndex, m_contextMenuChunkIndex, false);
if (patch.isEmpty())
return;
- // Retrieve service by soft dependency.
- QObject *pasteService
- = ExtensionSystem::PluginManager::getObjectByClassName(QLatin1String("CodePaster::CodePasterService"));
- if (pasteService) {
- QMetaObject::invokeMethod(pasteService, "postText",
- Q_ARG(QString, patch),
- Q_ARG(QString, QLatin1String(DiffEditor::Constants::DIFF_EDITOR_MIMETYPE)));
- } else {
- QMessageBox::information(this, tr("Unable to Paste"),
- tr("Code pasting services are not available."));
- }
+ pasteService->postText(patch, QLatin1String(Constants::DIFF_EDITOR_MIMETYPE));
}
void SideBySideDiffEditorWidget::slotApplyChunk()
diff --git a/src/plugins/diffeditor/unifieddiffeditorwidget.cpp b/src/plugins/diffeditor/unifieddiffeditorwidget.cpp
index fbc3a22064..3810a4052c 100644
--- a/src/plugins/diffeditor/unifieddiffeditorwidget.cpp
+++ b/src/plugins/diffeditor/unifieddiffeditorwidget.cpp
@@ -54,8 +54,11 @@
#include <coreplugin/patchtool.h>
#include <coreplugin/editormanager/editormanager.h>
+#include <cpaster/codepasterservice.h>
+
#include <extensionsystem/pluginmanager.h>
+#include <utils/qtcassert.h>
#include <utils/tooltip/tooltip.h>
//static const int FILE_LEVEL = 1;
@@ -189,10 +192,13 @@ void UnifiedDiffEditorWidget::addContextMenuActions(QMenu *menu,
menu->addSeparator();
menu->addSeparator();
- QAction *sendChunkToCodePasterAction =
- menu->addAction(tr("Send Chunk to CodePaster..."));
- connect(sendChunkToCodePasterAction, &QAction::triggered,
- this, &UnifiedDiffEditorWidget::slotSendChunkToCodePaster);
+ if (ExtensionSystem::PluginManager::getObject<CodePaster::Service>()) {
+ // optional code pasting service
+ QAction *sendChunkToCodePasterAction =
+ menu->addAction(tr("Send Chunk to CodePaster..."));
+ connect(sendChunkToCodePasterAction, &QAction::triggered,
+ this, &UnifiedDiffEditorWidget::slotSendChunkToCodePaster);
+ }
QAction *applyAction = menu->addAction(tr("Apply Chunk..."));
connect(applyAction, &QAction::triggered, this, &UnifiedDiffEditorWidget::slotApplyChunk);
QAction *revertAction = menu->addAction(tr("Revert Chunk..."));
@@ -229,23 +235,16 @@ void UnifiedDiffEditorWidget::slotSendChunkToCodePaster()
if (!m_document)
return;
+ // Retrieve service by soft dependency.
+ auto pasteService = ExtensionSystem::PluginManager::getObject<CodePaster::Service>();
+ QTC_ASSERT(pasteService, return);
+
const QString patch = m_document->makePatch(m_contextMenuFileIndex, m_contextMenuChunkIndex, false);
if (patch.isEmpty())
return;
- // Retrieve service by soft dependency.
- QObject *pasteService =
- ExtensionSystem::PluginManager::getObjectByClassName(
- QLatin1String("CodePaster::CodePasterService"));
- if (pasteService) {
- QMetaObject::invokeMethod(pasteService, "postText",
- Q_ARG(QString, patch),
- Q_ARG(QString, QLatin1String(DiffEditor::Constants::DIFF_EDITOR_MIMETYPE)));
- } else {
- QMessageBox::information(this, tr("Unable to Paste"),
- tr("Code pasting services are not available."));
- }
+ pasteService->postText(patch, QLatin1String(Constants::DIFF_EDITOR_MIMETYPE));
}
void UnifiedDiffEditorWidget::slotApplyChunk()