forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -90,13 +90,13 @@ void CodePasterService::postText(const QString &text, const QString &mimeType)
|
|||||||
void CodePasterService::postCurrentEditor()
|
void CodePasterService::postCurrentEditor()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(CodepasterPlugin::instance(), return);
|
QTC_ASSERT(CodepasterPlugin::instance(), return);
|
||||||
CodepasterPlugin::instance()->postEditor();
|
CodepasterPlugin::instance()->post(CodepasterPlugin::PasteEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodePasterService::postClipboard()
|
void CodePasterService::postClipboard()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(CodepasterPlugin::instance(), return);
|
QTC_ASSERT(CodepasterPlugin::instance(), return);
|
||||||
CodepasterPlugin::instance()->postClipboard();
|
CodepasterPlugin::instance()->post(CodepasterPlugin::PasteClipboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- CodepasterPlugin
|
// ---------- CodepasterPlugin
|
||||||
@@ -104,7 +104,7 @@ CodepasterPlugin *CodepasterPlugin::m_instance = 0;
|
|||||||
|
|
||||||
CodepasterPlugin::CodepasterPlugin() :
|
CodepasterPlugin::CodepasterPlugin() :
|
||||||
m_settings(new Settings),
|
m_settings(new Settings),
|
||||||
m_postEditorAction(0), m_postClipboardAction(0), m_fetchAction(0)
|
m_postEditorAction(0), m_fetchAction(0)
|
||||||
{
|
{
|
||||||
CodepasterPlugin::m_instance = this;
|
CodepasterPlugin::m_instance = this;
|
||||||
}
|
}
|
||||||
@@ -165,12 +165,7 @@ bool CodepasterPlugin::initialize(const QStringList &arguments, QString *errorMe
|
|||||||
m_postEditorAction = new QAction(tr("Paste Snippet..."), this);
|
m_postEditorAction = new QAction(tr("Paste Snippet..."), this);
|
||||||
command = Core::ActionManager::registerAction(m_postEditorAction, "CodePaster.Post", globalcontext);
|
command = Core::ActionManager::registerAction(m_postEditorAction, "CodePaster.Post", globalcontext);
|
||||||
command->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+C,Meta+P") : tr("Alt+C,Alt+P")));
|
command->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+C,Meta+P") : tr("Alt+C,Alt+P")));
|
||||||
connect(m_postEditorAction, SIGNAL(triggered()), this, SLOT(postEditor()));
|
connect(m_postEditorAction, &QAction::triggered, this, &CodepasterPlugin::pasteSnippet);
|
||||||
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()));
|
|
||||||
cpContainer->addAction(command);
|
cpContainer->addAction(command);
|
||||||
|
|
||||||
m_fetchAction = new QAction(tr("Fetch Snippet..."), this);
|
m_fetchAction = new QAction(tr("Fetch Snippet..."), this);
|
||||||
@@ -204,13 +199,12 @@ ExtensionSystem::IPlugin::ShutdownFlag CodepasterPlugin::aboutToShutdown()
|
|||||||
return SynchronousShutdown;
|
return SynchronousShutdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodepasterPlugin::postEditor()
|
static inline void textFromCurrentEditor(QString *text, QString *mimeType)
|
||||||
{
|
{
|
||||||
IEditor *editor = EditorManager::currentEditor();
|
IEditor *editor = EditorManager::currentEditor();
|
||||||
if (!editor)
|
if (!editor)
|
||||||
return;
|
return;
|
||||||
const IDocument *document = editor->document();
|
const IDocument *document = editor->document();
|
||||||
const QString mimeType = document->mimeType();
|
|
||||||
QString data;
|
QString data;
|
||||||
if (const BaseTextEditor *textEditor = qobject_cast<const BaseTextEditor *>(editor))
|
if (const BaseTextEditor *textEditor = qobject_cast<const BaseTextEditor *>(editor))
|
||||||
data = textEditor->selectedText();
|
data = textEditor->selectedText();
|
||||||
@@ -223,15 +217,10 @@ void CodepasterPlugin::postEditor()
|
|||||||
data = textV.toString();
|
data = textV.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
post(data, mimeType);
|
if (!data.isEmpty()) {
|
||||||
}
|
*text = data;
|
||||||
|
*mimeType = document->mimeType();
|
||||||
void CodepasterPlugin::postClipboard()
|
}
|
||||||
{
|
|
||||||
QString subtype = QLatin1String("plain");
|
|
||||||
const QString text = qApp->clipboard()->text(subtype, QClipboard::Clipboard);
|
|
||||||
if (!text.isEmpty())
|
|
||||||
post(text, QString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void fixSpecialCharacters(QString &data)
|
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)
|
void CodepasterPlugin::post(QString data, const QString &mimeType)
|
||||||
{
|
{
|
||||||
fixSpecialCharacters(data);
|
fixSpecialCharacters(data);
|
||||||
@@ -289,6 +291,11 @@ void CodepasterPlugin::fetchUrl()
|
|||||||
m_urlOpen->fetch(url.toString());
|
m_urlOpen->fetch(url.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CodepasterPlugin::pasteSnippet()
|
||||||
|
{
|
||||||
|
post(PasteEditor | PasteClipboard);
|
||||||
|
}
|
||||||
|
|
||||||
void CodepasterPlugin::fetch()
|
void CodepasterPlugin::fetch()
|
||||||
{
|
{
|
||||||
PasteSelectDialog dialog(m_protocols, ICore::dialogParent());
|
PasteSelectDialog dialog(m_protocols, ICore::dialogParent());
|
||||||
|
@@ -64,6 +64,12 @@ class CodepasterPlugin : public ExtensionSystem::IPlugin
|
|||||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "CodePaster.json")
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "CodePaster.json")
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum PasteSource {
|
||||||
|
PasteEditor = 0x1,
|
||||||
|
PasteClipboard = 0x2
|
||||||
|
};
|
||||||
|
Q_DECLARE_FLAGS(PasteSources, PasteSource)
|
||||||
|
|
||||||
CodepasterPlugin();
|
CodepasterPlugin();
|
||||||
~CodepasterPlugin();
|
~CodepasterPlugin();
|
||||||
|
|
||||||
@@ -74,14 +80,14 @@ public:
|
|||||||
static CodepasterPlugin *instance();
|
static CodepasterPlugin *instance();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void postEditor();
|
void pasteSnippet();
|
||||||
void postClipboard();
|
|
||||||
void fetch();
|
void fetch();
|
||||||
void finishPost(const QString &link);
|
void finishPost(const QString &link);
|
||||||
void finishFetch(const QString &titleDescription,
|
void finishFetch(const QString &titleDescription,
|
||||||
const QString &content,
|
const QString &content,
|
||||||
bool error);
|
bool error);
|
||||||
|
|
||||||
|
void post(PasteSources pasteSources);
|
||||||
void post(QString data, const QString &mimeType);
|
void post(QString data, const QString &mimeType);
|
||||||
void fetchUrl();
|
void fetchUrl();
|
||||||
private:
|
private:
|
||||||
@@ -89,7 +95,6 @@ private:
|
|||||||
static CodepasterPlugin *m_instance;
|
static CodepasterPlugin *m_instance;
|
||||||
const QSharedPointer<Settings> m_settings;
|
const QSharedPointer<Settings> m_settings;
|
||||||
QAction *m_postEditorAction;
|
QAction *m_postEditorAction;
|
||||||
QAction *m_postClipboardAction;
|
|
||||||
QAction *m_fetchAction;
|
QAction *m_fetchAction;
|
||||||
QAction *m_fetchUrlAction;
|
QAction *m_fetchUrlAction;
|
||||||
QList<Protocol*> m_protocols;
|
QList<Protocol*> m_protocols;
|
||||||
@@ -97,6 +102,8 @@ private:
|
|||||||
Protocol *m_urlOpen;
|
Protocol *m_urlOpen;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_OPERATORS_FOR_FLAGS(CodepasterPlugin::PasteSources)
|
||||||
|
|
||||||
} // namespace CodePaster
|
} // namespace CodePaster
|
||||||
|
|
||||||
#endif // CPASTERPLUGIN_H
|
#endif // CPASTERPLUGIN_H
|
||||||
|
Reference in New Issue
Block a user