Commit f268d0f8 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

DiffEditor: Make it possible to paste snippets.



Add property "plainText" to DiffEditorDocument which
is queried as last resort by the code paster.

Task-number: QTCREATORBUG-12546
Task-number: QTCREATORBUG-9669
Change-Id: Iea9cd0d296bcc8e8a7300072c1a4a9068c2ab102
Reviewed-by: default avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 9605244f
...@@ -215,8 +215,13 @@ void CodepasterPlugin::postEditor() ...@@ -215,8 +215,13 @@ void CodepasterPlugin::postEditor()
if (const BaseTextEditor *textEditor = qobject_cast<const BaseTextEditor *>(editor)) if (const BaseTextEditor *textEditor = qobject_cast<const BaseTextEditor *>(editor))
data = textEditor->selectedText(); data = textEditor->selectedText();
if (data.isEmpty()) { if (data.isEmpty()) {
if (auto textDocument = qobject_cast<const TextDocument *>(document)) if (auto textDocument = qobject_cast<const TextDocument *>(document)) {
data = textDocument->plainText(); data = textDocument->plainText();
} else {
const QVariant textV = document->property("plainText"); // Diff Editor.
if (textV.type() == QVariant::String)
data = textV.toString();
}
} }
post(data, mimeType); post(data, mimeType);
} }
......
...@@ -155,4 +155,9 @@ QString DiffEditorDocument::suggestedFileName() const ...@@ -155,4 +155,9 @@ QString DiffEditorDocument::suggestedFileName() const
return result + QStringLiteral(".patch"); return result + QStringLiteral(".patch");
} }
QString DiffEditorDocument::plainText() const
{
return m_controller->contents();
}
} // namespace DiffEditor } // namespace DiffEditor
...@@ -42,6 +42,7 @@ class DiffEditorController; ...@@ -42,6 +42,7 @@ class DiffEditorController;
class DIFFEDITOR_EXPORT DiffEditorDocument : public Core::BaseTextDocument class DIFFEDITOR_EXPORT DiffEditorDocument : public Core::BaseTextDocument
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString plainText READ plainText STORED false) // For access by code pasters
public: public:
explicit DiffEditorDocument(); explicit DiffEditorDocument();
virtual ~DiffEditorDocument(); virtual ~DiffEditorDocument();
...@@ -58,6 +59,8 @@ public: ...@@ -58,6 +59,8 @@ public:
bool reload(QString *errorString, ReloadFlag flag, ChangeType type); bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
bool open(QString *errorString, const QString &fileName); bool open(QString *errorString, const QString &fileName);
QString plainText() const;
private: private:
DiffEditorController *m_controller; DiffEditorController *m_controller;
}; };
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment