forked from qt-creator/qt-creator
Terminal: External terminal if blocked by modal
Change-Id: I89ba438c7a9f4d593e849b9b7ca2daf202cca625 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -3,14 +3,11 @@
|
||||
|
||||
#include "terminalhooks.h"
|
||||
|
||||
#include "externalterminalprocessimpl.h"
|
||||
#include "filepath.h"
|
||||
#include "process.h"
|
||||
#include "terminalcommand.h"
|
||||
#include "terminalinterface.h"
|
||||
#include "utilstr.h"
|
||||
|
||||
#include <QMutex>
|
||||
#include <QTemporaryFile>
|
||||
|
||||
namespace Utils::Terminal {
|
||||
|
||||
@@ -31,99 +28,6 @@ FilePath defaultShellForDevice(const FilePath &deviceRoot)
|
||||
return deviceRoot.withNewMappedPath(shell);
|
||||
}
|
||||
|
||||
class ExternalTerminalProcessImpl final : public TerminalInterface
|
||||
{
|
||||
class ProcessStubCreator : public StubCreator
|
||||
{
|
||||
public:
|
||||
ProcessStubCreator(ExternalTerminalProcessImpl *interface)
|
||||
: m_interface(interface)
|
||||
{}
|
||||
|
||||
~ProcessStubCreator() override = default;
|
||||
|
||||
expected_str<qint64> startStubProcess(const ProcessSetupData &setupData) override
|
||||
{
|
||||
const TerminalCommand terminal = TerminalCommand::terminalEmulator();
|
||||
|
||||
if (HostOsInfo::isMacHost() && terminal.command == "Terminal.app") {
|
||||
QTemporaryFile f;
|
||||
f.setAutoRemove(false);
|
||||
f.open();
|
||||
f.setPermissions(QFile::ExeUser | QFile::ReadUser | QFile::WriteUser);
|
||||
f.write("#!/bin/sh\n");
|
||||
f.write(QString("cd %1\n").arg(setupData.m_workingDirectory.nativePath()).toUtf8());
|
||||
f.write("clear\n");
|
||||
f.write(QString("exec '%1' %2\n")
|
||||
.arg(setupData.m_commandLine.executable().nativePath())
|
||||
.arg(setupData.m_commandLine.arguments())
|
||||
.toUtf8());
|
||||
f.close();
|
||||
|
||||
const QString path = f.fileName();
|
||||
const QString exe
|
||||
= QString("tell app \"Terminal\" to do script \"'%1'; rm -f '%1'; exit\"")
|
||||
.arg(path);
|
||||
|
||||
Process process;
|
||||
|
||||
process.setCommand(
|
||||
{"osascript", {"-e", "tell app \"Terminal\" to activate", "-e", exe}});
|
||||
process.runBlocking();
|
||||
|
||||
if (process.exitCode() != 0) {
|
||||
return make_unexpected(Tr::tr("Failed to start terminal process: \"%1\"")
|
||||
.arg(process.errorString()));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool detached = setupData.m_terminalMode == TerminalMode::Detached;
|
||||
|
||||
Process *process = new Process(detached ? nullptr : this);
|
||||
if (detached)
|
||||
QObject::connect(process, &Process::done, process, &Process::deleteLater);
|
||||
|
||||
QObject::connect(process,
|
||||
&Process::done,
|
||||
m_interface,
|
||||
&ExternalTerminalProcessImpl::onStubExited);
|
||||
|
||||
process->setWorkingDirectory(setupData.m_workingDirectory);
|
||||
|
||||
if constexpr (HostOsInfo::isWindowsHost()) {
|
||||
process->setCommand(setupData.m_commandLine);
|
||||
process->setCreateConsoleOnWindows(true);
|
||||
process->setProcessMode(ProcessMode::Writer);
|
||||
} else {
|
||||
QString extraArgsFromOptions = detached ? terminal.openArgs : terminal.executeArgs;
|
||||
CommandLine cmdLine = {terminal.command, {}};
|
||||
if (!extraArgsFromOptions.isEmpty())
|
||||
cmdLine.addArgs(extraArgsFromOptions, CommandLine::Raw);
|
||||
cmdLine.addCommandLineAsArgs(setupData.m_commandLine, CommandLine::Raw);
|
||||
process->setCommand(cmdLine);
|
||||
}
|
||||
|
||||
process->start();
|
||||
process->waitForStarted();
|
||||
if (process->error() != QProcess::UnknownError) {
|
||||
return make_unexpected(
|
||||
Tr::tr("Failed to start terminal process: \"%1\"").arg(process->errorString()));
|
||||
}
|
||||
|
||||
qint64 pid = process->processId();
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
||||
ExternalTerminalProcessImpl *m_interface;
|
||||
};
|
||||
|
||||
public:
|
||||
ExternalTerminalProcessImpl() { setStubCreator(new ProcessStubCreator(this)); }
|
||||
};
|
||||
|
||||
class HooksPrivate
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user