summaryrefslogtreecommitdiff
path: root/src/plugins/cpaster/cpasterplugin.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2014-11-13 14:44:35 +0100
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2014-11-18 08:44:48 +0100
commit7a69585b0a6695d98446f2e35b9319db4deddb95 (patch)
tree053deb6c0e5b858c5a139ffec79fad916d4587a8 /src/plugins/cpaster/cpasterplugin.cpp
parent2d25e6290a5b0e072a16ab973a17fd79f0eac3a6 (diff)
downloadqt-creator-7a69585b0a6695d98446f2e35b9319db4deddb95.tar.gz
Codepaster: Join actions, always open dialog.
Remove the "Paste from clipboard" action and move the functionality into "Paste Snippet". Introduce a new overload for post() taking a flag mask specifying the sources and use this for the CodePasterService class (used by the diff editor). Task-number: QTCREATORBUG-13401 Change-Id: Iadc3560a8a3bdaa817bc4a86007c2682feeb4b77 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Diffstat (limited to 'src/plugins/cpaster/cpasterplugin.cpp')
-rw-r--r--src/plugins/cpaster/cpasterplugin.cpp47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/plugins/cpaster/cpasterplugin.cpp b/src/plugins/cpaster/cpasterplugin.cpp
index 4941a8240b..e4a34d49fb 100644
--- a/src/plugins/cpaster/cpasterplugin.cpp
+++ b/src/plugins/cpaster/cpasterplugin.cpp
@@ -90,13 +90,13 @@ void CodePasterService::postText(const QString &text, const QString &mimeType)
void CodePasterService::postCurrentEditor()
{
QTC_ASSERT(CodepasterPlugin::instance(), return);
- CodepasterPlugin::instance()->postEditor();
+ CodepasterPlugin::instance()->post(CodepasterPlugin::PasteEditor);
}
void CodePasterService::postClipboard()
{
QTC_ASSERT(CodepasterPlugin::instance(), return);
- CodepasterPlugin::instance()->postClipboard();
+ CodepasterPlugin::instance()->post(CodepasterPlugin::PasteClipboard);
}
// ---------- CodepasterPlugin
@@ -104,7 +104,7 @@ CodepasterPlugin *CodepasterPlugin::m_instance = 0;
CodepasterPlugin::CodepasterPlugin() :
m_settings(new Settings),
- m_postEditorAction(0), m_postClipboardAction(0), m_fetchAction(0)
+ m_postEditorAction(0), m_fetchAction(0)
{
CodepasterPlugin::m_instance = this;
}
@@ -165,12 +165,7 @@ bool CodepasterPlugin::initialize(const QStringList &arguments, QString *errorMe
m_postEditorAction = new QAction(tr("Paste Snippet..."), this);
command = Core::ActionManager::registerAction(m_postEditorAction, "CodePaster.Post", globalcontext);
command->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+C,Meta+P") : tr("Alt+C,Alt+P")));
- connect(m_postEditorAction, SIGNAL(triggered()), this, SLOT(postEditor()));
- cpContainer->addAction(command);
-
- m_postClipboardAction = new QAction(tr("Paste Clipboard..."), this);
- command = Core::ActionManager::registerAction(m_postClipboardAction, "CodePaster.PostClipboard", globalcontext);
- connect(m_postClipboardAction, SIGNAL(triggered()), this, SLOT(postClipboard()));
+ connect(m_postEditorAction, &QAction::triggered, this, &CodepasterPlugin::pasteSnippet);
cpContainer->addAction(command);
m_fetchAction = new QAction(tr("Fetch Snippet..."), this);
@@ -204,13 +199,12 @@ ExtensionSystem::IPlugin::ShutdownFlag CodepasterPlugin::aboutToShutdown()
return SynchronousShutdown;
}
-void CodepasterPlugin::postEditor()
+static inline void textFromCurrentEditor(QString *text, QString *mimeType)
{
IEditor *editor = EditorManager::currentEditor();
if (!editor)
return;
const IDocument *document = editor->document();
- const QString mimeType = document->mimeType();
QString data;
if (const BaseTextEditor *textEditor = qobject_cast<const BaseTextEditor *>(editor))
data = textEditor->selectedText();
@@ -223,15 +217,10 @@ void CodepasterPlugin::postEditor()
data = textV.toString();
}
}
- post(data, mimeType);
-}
-
-void CodepasterPlugin::postClipboard()
-{
- QString subtype = QLatin1String("plain");
- const QString text = qApp->clipboard()->text(subtype, QClipboard::Clipboard);
- if (!text.isEmpty())
- post(text, QString());
+ if (!data.isEmpty()) {
+ *text = data;
+ *mimeType = document->mimeType();
+ }
}
static inline void fixSpecialCharacters(QString &data)
@@ -256,6 +245,19 @@ static inline void fixSpecialCharacters(QString &data)
}
}
+void CodepasterPlugin::post(PasteSources pasteSources)
+{
+ QString data;
+ QString mimeType;
+ if (pasteSources & PasteEditor)
+ textFromCurrentEditor(&data, &mimeType);
+ if (data.isEmpty() && (pasteSources & PasteClipboard)) {
+ QString subType = QStringLiteral("plain");
+ data = qApp->clipboard()->text(subType, QClipboard::Clipboard);
+ }
+ post(data, mimeType);
+}
+
void CodepasterPlugin::post(QString data, const QString &mimeType)
{
fixSpecialCharacters(data);
@@ -289,6 +291,11 @@ void CodepasterPlugin::fetchUrl()
m_urlOpen->fetch(url.toString());
}
+void CodepasterPlugin::pasteSnippet()
+{
+ post(PasteEditor | PasteClipboard);
+}
+
void CodepasterPlugin::fetch()
{
PasteSelectDialog dialog(m_protocols, ICore::dialogParent());