Implement ReplaceSelection output handling.

External 'sort' now works as it should.
This commit is contained in:
con
2010-12-09 15:53:43 +01:00
parent 10b6b2936b
commit a22a30cf60
5 changed files with 50 additions and 6 deletions

View File

@@ -55,6 +55,7 @@
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/uniqueidmanager.h>
#include <coreplugin/externaltool.h>
#include <extensionsystem/pluginmanager.h>
#include <texteditor/texteditoractionhandler.h>
#include <find/searchresultwindow.h>
@@ -178,7 +179,8 @@ void TextEditorPlugin::extensionsInitialized()
addAutoReleasedObject(new FindInCurrentFile(Find::SearchResultWindow::instance()));
connect(Core::VariableManager::instance(), SIGNAL(variableUpdateRequested(QString)),
this, SLOT(updateVariable(QString)));
connect(Core::ExternalToolManager::instance(), SIGNAL(replaceSelectionRequested(QString)),
this, SLOT(updateCurrentSelection(QString)));
}
void TextEditorPlugin::initializeEditor(PlainTextEditor *editor)
@@ -227,4 +229,22 @@ void TextEditorPlugin::updateVariable(const QString &variable)
}
}
void TextEditorPlugin::updateCurrentSelection(const QString &text)
{
Core::IEditor *iface = Core::EditorManager::instance()->currentEditor();
ITextEditable *editor = qobject_cast<ITextEditable *>(iface);
if (editor) {
int pos = editor->position();
int anchor = editor->position(ITextEditor::Anchor);
int selectionLength = anchor-pos;
if (selectionLength < 0)
selectionLength = -selectionLength;
if (selectionLength == 0)
return;
int start = qMin(pos, anchor);
editor->setCurPos(start);
editor->replace(selectionLength, text);
}
}
Q_EXPORT_PLUGIN(TextEditorPlugin)