Commit a22a30cf authored by con's avatar con
Browse files

Implement ReplaceSelection output handling.

External 'sort' now works as it should.
parent 10b6b293
......@@ -36,7 +36,7 @@
<displayname xml:lang="de">Selektion Sortieren</displayname>
<category>Text</category>
<category xml:lang="de">Text</category>
<executable output="showinpane" error="ignore">
<executable output="replaceselection" error="ignore">
<path>sort</path>
<input>%{CurrentSelection}</input>
<workingdirectory>%{CurrentPath}</workingdirectory>
......
......@@ -356,6 +356,10 @@ void ExternalToolRunner::started()
void ExternalToolRunner::finished()
{
if (m_tool->outputHandling() == ExternalTool::ReplaceSelection
|| m_tool->errorHandling() == ExternalTool::ReplaceSelection) {
emit ExternalToolManager::instance()->replaceSelectionRequested(m_processOutput);
}
ICore::instance()->messageManager()->printToOutputPane(
tr("'%1' finished").arg(m_resolvedExecutable), false);
// TODO handle the ReplaceSelection and ReloadDocument flags
......@@ -379,6 +383,8 @@ void ExternalToolRunner::readStandardOutput()
// TODO handle the ReplaceSelection flag
if (m_tool->outputHandling() == ExternalTool::ShowInPane) {
ICore::instance()->messageManager()->printToOutputPane(output, true);
} else if (m_tool->outputHandling() == ExternalTool::ReplaceSelection) {
m_processOutput.append(output);
}
}
......@@ -391,14 +397,19 @@ void ExternalToolRunner::readStandardError()
// TODO handle the ReplaceSelection flag
if (m_tool->errorHandling() == ExternalTool::ShowInPane) {
ICore::instance()->messageManager()->printToOutputPane(output, true);
} else if (m_tool->errorHandling() == ExternalTool::ReplaceSelection) {
m_processOutput.append(output);
}
}
// #pragma mark -- ExternalToolManager
ExternalToolManager *ExternalToolManager::m_instance = 0;
ExternalToolManager::ExternalToolManager(Core::ICore *core)
: QObject(core), m_core(core)
{
m_instance = this;
initialize();
}
......
......@@ -31,6 +31,7 @@
#define EXTERNALTOOL_H
#include "icore.h"
#include "core_global.h"
#include <QtCore/QObject>
#include <QtCore/QString>
......@@ -111,27 +112,38 @@ private:
QTextCodec *m_outputCodec;
QTextCodec::ConverterState m_outputCodecState;
QTextCodec::ConverterState m_errorCodecState;
QString m_processOutput;
};
class ExternalToolManager : public QObject
} // Internal
class CORE_EXPORT ExternalToolManager : public QObject
{
Q_OBJECT
public:
static ExternalToolManager *instance() { return m_instance; }
ExternalToolManager(Core::ICore *core);
~ExternalToolManager();
void initialize();
signals:
void replaceSelectionRequested(const QString &text);
private slots:
void menuActivated();
private:
void initialize();
static ExternalToolManager *m_instance;
Core::ICore *m_core;
QMap<QString, ExternalTool *> m_tools;
QMap<QString, Internal::ExternalTool *> m_tools;
// for sending the replaceSelectionRequested signal
friend class Core::Internal::ExternalToolRunner;
};
} // Internal
} // Core
#endif // EXTERNALTOOL_H
......@@ -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)
......@@ -77,6 +77,7 @@ private slots:
void invokeQuickFix();
void updateSearchResultsFont(const TextEditor::FontSettings &);
void updateVariable(const QString &variable);
void updateCurrentSelection(const QString &text);
private:
static TextEditorPlugin *m_instance;
......
Markdown is supported
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