forked from qt-creator/qt-creator
FakeVim: Remove QtcProcess use from fakevimhandler.cpp
fakevimhandler.{h,cpp} are meant to be re-usable outside of Qt Creator.
Amends 91605c3.
Change-Id: I569a393d13049ef92ed3ef0c4f69de5232b2fa32
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -36,8 +36,6 @@
|
||||
#include "fakevimactions.h"
|
||||
#include "fakevimtr.h"
|
||||
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QObject>
|
||||
@@ -833,29 +831,6 @@ static void setClipboardData(const QString &content, RangeMode mode,
|
||||
clipboard->setMimeData(data, clipboardMode);
|
||||
}
|
||||
|
||||
static QByteArray toLocalEncoding(const QString &text)
|
||||
{
|
||||
#if defined(Q_OS_WIN)
|
||||
return QString(text).replace("\n", "\r\n").toLocal8Bit();
|
||||
#else
|
||||
return text.toLocal8Bit();
|
||||
#endif
|
||||
}
|
||||
|
||||
static QString getProcessOutput(const QString &command, const QString &input)
|
||||
{
|
||||
Utils::QtcProcess proc;
|
||||
proc.setCommand(Utils::CommandLine::fromUserInput(command));
|
||||
proc.setWriteData(toLocalEncoding(input));
|
||||
proc.start();
|
||||
|
||||
// FIXME: Process should be interruptable by user.
|
||||
// Solution is to create a QObject for each process and emit finished state.
|
||||
proc.waitForFinished();
|
||||
|
||||
return proc.cleanedStdOut();
|
||||
}
|
||||
|
||||
static const QMap<QString, int> &vimKeyNames()
|
||||
{
|
||||
static const QMap<QString, int> k = {
|
||||
@@ -6432,7 +6407,8 @@ bool FakeVimHandler::Private::handleExBangCommand(const ExCommand &cmd) // :!
|
||||
const QString command = QString(cmd.cmd.mid(1) + ' ' + cmd.args).trimmed();
|
||||
const QString input = replaceText ? selectText(cmd.range) : QString();
|
||||
|
||||
const QString result = getProcessOutput(command, input);
|
||||
QString result;
|
||||
q->processOutput(command, input, &result);
|
||||
|
||||
if (replaceText) {
|
||||
setCurrentRange(cmd.range);
|
||||
|
||||
@@ -167,6 +167,7 @@ public:
|
||||
Callback<void()> tabNextRequested;
|
||||
Callback<void(bool insertMode)> modeChanged;
|
||||
Callback<bool()> tabPressedInInsertMode;
|
||||
Callback<void(const QString &, const QString &, QString *)> processOutput;
|
||||
|
||||
public:
|
||||
class Private;
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
#include <utils/layoutbuilder.h>
|
||||
#include <utils/pathchooser.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/stylehelper.h>
|
||||
|
||||
#include <cppeditor/cppeditorconstants.h>
|
||||
@@ -1887,6 +1887,18 @@ void FakeVimPluginPrivate::editorOpened(IEditor *editor)
|
||||
tew->invokeAssist(Completion, &runData->wordProvider);
|
||||
});
|
||||
|
||||
handler->processOutput.set([](const QString &command, const QString &input, QString *output) {
|
||||
QtcProcess proc;
|
||||
proc.setCommand(Utils::CommandLine::fromUserInput(command));
|
||||
proc.setWriteData(input.toLocal8Bit());
|
||||
proc.start();
|
||||
|
||||
// FIXME: Process should be interruptable by user.
|
||||
// Solution is to create a QObject for each process and emit finished state.
|
||||
proc.waitForFinished();
|
||||
*output = proc.cleanedStdOut();
|
||||
});
|
||||
|
||||
connect(ICore::instance(), &ICore::saveSettingsRequested,
|
||||
this, &FakeVimPluginPrivate::writeSettings);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user