Refactor text retrieval of the code paster plugin.

Try to obtain text via ITextEditorDocument.

Task-number: QTCREATORBUG-9669
Change-Id: Ie3816d84ea715691256f757fdd9a7b666fb6c27c
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Friedemann Kleint
2014-07-02 15:00:00 +02:00
parent 65c9092495
commit b435f7bfe8

View File

@@ -205,15 +205,17 @@ ExtensionSystem::IPlugin::ShutdownFlag CodepasterPlugin::aboutToShutdown()
void CodepasterPlugin::postEditor()
{
IEditor *editor = EditorManager::currentEditor();
if (!editor)
return;
const IDocument *document = editor->document();
const QString mimeType = document->mimeType();
QString data;
QString mimeType;
if (IEditor *editor = EditorManager::currentEditor()) {
if (ITextEditor *textEditor = qobject_cast<ITextEditor *>(editor)) {
data = textEditor->selectedText();
if (data.isEmpty())
data = textEditor->textDocument()->plainText();
mimeType = textEditor->document()->mimeType();
}
if (const ITextEditor *textEditor = qobject_cast<const ITextEditor *>(editor))
data = textEditor->selectedText();
if (data.isEmpty()) {
if (const ITextEditorDocument *textDocument = qobject_cast<const ITextEditorDocument *>(document))
data = textDocument->plainText();
}
post(data, mimeType);
}