#include <QtGui/QMenu>
#include <QtGui/QMainWindow>
-using namespace CodePaster;
using namespace Core;
using namespace TextEditor;
+namespace CodePaster {
+
+/*!
+ \class CodePaster::CodePasterService
+ \brief Service registered with PluginManager providing CodePaster
+ post() functionality.
+
+ \sa ExtensionSystem::PluginManager::getObjectByClassName, ExtensionSystem::invoke
+ \sa VCSBase::VCSBaseEditorWidget
+*/
+
+CodePasterService::CodePasterService(QObject *parent) :
+ QObject(parent)
+{
+}
+
+void CodePasterService::postText(const QString &text, const QString &mimeType)
+{
+ QTC_ASSERT(CodepasterPlugin::instance(), return; )
+ CodepasterPlugin::instance()->post(text, mimeType);
+}
+
+void CodePasterService::postCurrentEditor()
+{
+ QTC_ASSERT(CodepasterPlugin::instance(), return; )
+ CodepasterPlugin::instance()->postEditor();
+}
+
+void CodePasterService::postClipboard()
+{
+ QTC_ASSERT(CodepasterPlugin::instance(), return; )
+ CodepasterPlugin::instance()->postClipboard();
+}
+
+// ---------- CodepasterPlugin
+CodepasterPlugin *CodepasterPlugin::m_instance = 0;
+
CodepasterPlugin::CodepasterPlugin() :
m_settings(new Settings),
m_postEditorAction(0), m_postClipboardAction(0), m_fetchAction(0)
{
+ CodepasterPlugin::m_instance = this;
}
CodepasterPlugin::~CodepasterPlugin()
{
qDeleteAll(m_protocols);
+ CodepasterPlugin::m_instance = 0;
}
bool CodepasterPlugin::initialize(const QStringList &arguments, QString *error_message)
connect(m_fetchAction, SIGNAL(triggered()), this, SLOT(fetch()));
cpContainer->addAction(command);
+ addAutoReleasedObject(new CodePasterService);
+
return true;
}
view.setProtocol(m_settings->protocol);
const FileDataList diffChunks = splitDiffToFiles(data.toLatin1());
- if (diffChunks.isEmpty()) {
- view.show(username, QString(), QString(), data);
- } else {
+ const int dialogResult = diffChunks.isEmpty() ?
+ view.show(username, QString(), QString(), data) :
view.show(username, QString(), QString(), diffChunks);
+ // Save new protocol in case user changed it.
+ if (dialogResult == QDialog::Accepted
+ && m_settings->protocol != view.protocol()) {
+ m_settings->protocol = view.protocol();
+ m_settings->toSettings(Core::ICore::instance()->settings());
}
}
if (dialog.exec() != QDialog::Accepted)
return;
+ // Save new protocol in case user changed it.
+ if (m_settings->protocol != dialog.protocol()) {
+ m_settings->protocol = dialog.protocol();
+ m_settings->toSettings(Core::ICore::instance()->settings());
+ }
+
const QString pasteID = dialog.pasteId();
if (pasteID.isEmpty())
return;
editor->setDisplayName(titleDescription);
}
-Q_EXPORT_PLUGIN(CodepasterPlugin)
+CodepasterPlugin *CodepasterPlugin::instance()
+{
+ return m_instance;
+}
+
+} // namespace CodePaster
+
+Q_EXPORT_PLUGIN(CodePaster::CodepasterPlugin)
struct Settings;
class Protocol;
+class CodePasterService : public QObject
+{
+ Q_OBJECT
+public:
+ explicit CodePasterService(QObject *parent = 0);
+
+public slots:
+ void postText(const QString &text, const QString &mimeType);
+ void postCurrentEditor();
+ void postClipboard();
+};
+
class CodepasterPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
virtual void extensionsInitialized();
virtual ShutdownFlag aboutToShutdown();
+ static CodepasterPlugin *instance();
+
public slots:
void postEditor();
void postClipboard();
const QString &content,
bool error);
-private:
void post(QString data, const QString &mimeType);
+private:
+ static CodepasterPlugin *m_instance;
const QSharedPointer<Settings> m_settings;
QAction *m_postEditorAction;
QAction *m_postClipboardAction;
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorconstants.h>
#include <utils/qtcassert.h>
+#include <extensionsystem/invoker.h>
+#include <extensionsystem/pluginmanager.h>
#include <QtCore/QDebug>
#include <QtCore/QFileInfo>
break;
case DiffOutput: {
menu->addSeparator();
+ connect(menu->addAction(tr("Send to CodePaster...")), SIGNAL(triggered()),
+ this, SLOT(slotPaste()));
+ menu->addSeparator();
QAction *revertAction = menu->addAction(tr("Revert Chunk..."));
const DiffChunk chunk = diffChunk(cursorForPosition(e->pos()));
revertAction->setEnabled(canRevertDiffChunk(chunk));
return QStringList();
}
+void VCSBaseEditorWidget::slotPaste()
+{
+ // Retrieve service by soft dependency.
+ QObject *pasteService =
+ ExtensionSystem::PluginManager::instance()
+ ->getObjectByClassName("CodePaster::CodePasterService");
+ if (pasteService) {
+ QMetaObject::invokeMethod(pasteService, "postCurrentEditor");
+ } else {
+ QMessageBox::information(this, tr("Unable to Paste"),
+ tr("Code pasting services are not available."));
+ }
+}
+
bool VCSBaseEditorWidget::isRevertDiffChunkEnabled() const
{
return d->m_revertChunkEnabled;