forked from qt-creator/qt-creator
Allow to set environment for "Open Terminal"
Change-Id: If6e82ef8a7bbbaa947b41e0f6746d2b2aa770c20 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -116,7 +116,8 @@ public:
|
||||
static void setTerminalEmulator(QSettings *, const TerminalCommand &) {}
|
||||
#endif
|
||||
|
||||
static bool startTerminalEmulator(QSettings *settings, const QString &workingDir);
|
||||
static bool startTerminalEmulator(QSettings *settings, const QString &workingDir,
|
||||
const Utils::Environment &env);
|
||||
|
||||
signals:
|
||||
void error(QProcess::ProcessError error);
|
||||
|
||||
@@ -431,10 +431,18 @@ void ConsoleProcess::setTerminalEmulator(QSettings *settings, const TerminalComm
|
||||
}
|
||||
}
|
||||
|
||||
bool ConsoleProcess::startTerminalEmulator(QSettings *settings, const QString &workingDir)
|
||||
bool ConsoleProcess::startTerminalEmulator(QSettings *settings, const QString &workingDir,
|
||||
const Utils::Environment &env)
|
||||
{
|
||||
const TerminalCommand term = terminalEmulator(settings);
|
||||
return QProcess::startDetached(term.command, QtcProcess::splitArgs(term.openArgs), workingDir);
|
||||
|
||||
QProcess process;
|
||||
process.setProgram(term.command);
|
||||
process.setArguments(QtcProcess::splitArgs(term.openArgs));
|
||||
process.setProcessEnvironment(env.toProcessEnvironment());
|
||||
process.setWorkingDirectory(workingDir);
|
||||
|
||||
return process.startDetached();
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <QAbstractEventDispatcher>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cstring>
|
||||
|
||||
namespace Utils {
|
||||
|
||||
@@ -361,7 +362,8 @@ QString ConsoleProcess::createWinCommandline(const QString &program, const QStri
|
||||
return programName;
|
||||
}
|
||||
|
||||
bool ConsoleProcess::startTerminalEmulator(QSettings *, const QString &workingDir)
|
||||
bool ConsoleProcess::startTerminalEmulator(QSettings *, const QString &workingDir,
|
||||
const Utils::Environment &env)
|
||||
{
|
||||
STARTUPINFO si;
|
||||
ZeroMemory(&si, sizeof(si));
|
||||
@@ -375,9 +377,13 @@ bool ConsoleProcess::startTerminalEmulator(QSettings *, const QString &workingDi
|
||||
// cmdLine is assumed to be detached -
|
||||
// https://blogs.msdn.microsoft.com/oldnewthing/20090601-00/?p=18083
|
||||
|
||||
QString totalEnvironment = env.toStringList().join('\0') + '\0';
|
||||
LPVOID envPtr = (env != Utils::Environment::systemEnvironment())
|
||||
? (WCHAR *)(totalEnvironment.utf16()) : nullptr;
|
||||
|
||||
bool success = CreateProcessW(0, (WCHAR *)cmdLine.utf16(),
|
||||
0, 0, FALSE, CREATE_NEW_CONSOLE,
|
||||
0, workingDir.isEmpty() ? 0 : (WCHAR *)workingDir.utf16(),
|
||||
0, 0, FALSE, CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT,
|
||||
envPtr, workingDir.isEmpty() ? 0 : (WCHAR *)workingDir.utf16(),
|
||||
&si, &pinfo);
|
||||
|
||||
if (success) {
|
||||
|
||||
@@ -108,12 +108,17 @@ void FileUtils::showInGraphicalShell(QWidget *parent, const QString &pathIn)
|
||||
}
|
||||
|
||||
void FileUtils::openTerminal(const QString &path)
|
||||
{
|
||||
openTerminal(path, Environment::systemEnvironment());
|
||||
}
|
||||
|
||||
void FileUtils::openTerminal(const QString &path, const Environment &env)
|
||||
{
|
||||
const QFileInfo fileInfo(path);
|
||||
const QString pwd = QDir::toNativeSeparators(fileInfo.isDir() ?
|
||||
fileInfo.absoluteFilePath() :
|
||||
fileInfo.absolutePath());
|
||||
ConsoleProcess::startTerminalEmulator(ICore::settings(), pwd);
|
||||
ConsoleProcess::startTerminalEmulator(ICore::settings(), pwd, env);
|
||||
}
|
||||
|
||||
QString FileUtils::msgFindInDirectory()
|
||||
|
||||
@@ -31,6 +31,8 @@ QT_BEGIN_NAMESPACE
|
||||
class QWidget;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils { class Environment; }
|
||||
|
||||
namespace Core {
|
||||
|
||||
struct CORE_EXPORT FileUtils
|
||||
@@ -38,6 +40,7 @@ struct CORE_EXPORT FileUtils
|
||||
// Helpers for common directory browser options.
|
||||
static void showInGraphicalShell(QWidget *parent, const QString &path);
|
||||
static void openTerminal(const QString &path);
|
||||
static void openTerminal(const QString &path, const Utils::Environment &env);
|
||||
static QString msgFindInDirectory();
|
||||
// Platform-dependent action descriptions
|
||||
static QString msgGraphicalShellAction();
|
||||
|
||||
Reference in New Issue
Block a user