diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 7c05d2add4dc4280aec067243e118ff928f67efa..4e71f4a0635b9bfe6dee149c58b2228b6cbb7ecc 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -84,6 +84,7 @@ #include <coreplugin/vcsmanager.h> #include <welcome/welcomemode.h> #include <extensionsystem/pluginmanager.h> +#include <utils/consoleprocess.h> #include <utils/qtcassert.h> #include <utils/parameteraction.h> #include <utils/unixutils.h> @@ -145,6 +146,7 @@ struct ProjectExplorerPluginPrivate { QAction *m_addExistingFilesAction; QAction *m_openFileAction; QAction *m_showInGraphicalShell; + QAction *m_openTerminalHere; QAction *m_removeFileAction; QAction *m_renameFileAction; @@ -488,11 +490,22 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er #else d->m_showInGraphicalShell = new QAction(tr("Show containing folder..."), this); #endif + +#ifdef Q_OS_WIN + d->m_openTerminalHere = new QAction(tr("Open Command Prompt here..."), this); +#else + d->m_openTerminalHere = new QAction(tr("Open Terminal here..."), this); +#endif cmd = am->registerAction(d->m_showInGraphicalShell, ProjectExplorer::Constants::SHOWINGRAPHICALSHELL, globalcontext); mfilec->addAction(cmd, Constants::G_FILE_OPEN); mfolder->addAction(cmd, Constants::G_FOLDER_FILES); + cmd = am->registerAction(d->m_openTerminalHere, ProjectExplorer::Constants::OPENTERMIANLHERE, + globalcontext); + mfilec->addAction(cmd, Constants::G_FILE_OPEN); + mfolder->addAction(cmd, Constants::G_FOLDER_FILES); + // Open With menu mfilec->addMenu(openWith, ProjectExplorer::Constants::G_FILE_OPEN); @@ -746,6 +759,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er connect(d->m_addExistingFilesAction, SIGNAL(triggered()), this, SLOT(addExistingFiles())); connect(d->m_openFileAction, SIGNAL(triggered()), this, SLOT(openFile())); connect(d->m_showInGraphicalShell, SIGNAL(triggered()), this, SLOT(showInGraphicalShell())); + connect(d->m_openTerminalHere, SIGNAL(triggered()), this, SLOT(openTerminalHere())); connect(d->m_removeFileAction, SIGNAL(triggered()), this, SLOT(removeFile())); connect(d->m_renameFileAction, SIGNAL(triggered()), this, SLOT(renameFile())); @@ -1892,6 +1906,24 @@ void ProjectExplorerPlugin::showInGraphicalShell() #endif } +void ProjectExplorerPlugin::openTerminalHere() +{ +#ifdef Q_OS_WIN + const QString terminalEmulator = QString::fromLocal8Bit(qgetenv("COMSPEC")); + const QStringList args; // none +#else + QStringList args = Utils::ConsoleProcess::terminalEmulator( + Core::ICore::instance()->settings()).split(QLatin1Char(' ')); + const QString terminalEmulator = args.takeFirst(); + const QString shell = QString::fromLocal8Bit(qgetenv("SHELL")); + args.append(shell); +#endif + const QFileInfo fileInfo(d->m_currentNode->path()); + const QString pwd = QDir::toNativeSeparators(fileInfo.path()); + QProcess::startDetached(terminalEmulator, args, pwd); + +} + void ProjectExplorerPlugin::removeFile() { QTC_ASSERT(d->m_currentNode && d->m_currentNode->nodeType() == FileNodeType, return) diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h index 6f194f6335a55c4f3b105dda5846adc49cab49f1..96c3f6fe14830fef5e25bdaad381c4b54d363b99 100644 --- a/src/plugins/projectexplorer/projectexplorer.h +++ b/src/plugins/projectexplorer/projectexplorer.h @@ -194,6 +194,7 @@ private slots: void updateRecentProjectMenu(); void openRecentProject(); + void openTerminalHere(); void invalidateProject(ProjectExplorer::Project *project); diff --git a/src/plugins/projectexplorer/projectexplorerconstants.h b/src/plugins/projectexplorer/projectexplorerconstants.h index ab7258d1a9ae3c1a1d88204a32d24023e7a90986..b3a1b6145fec421c45a6055eda9f24b94bfd060f 100644 --- a/src/plugins/projectexplorer/projectexplorerconstants.h +++ b/src/plugins/projectexplorer/projectexplorerconstants.h @@ -69,6 +69,7 @@ const char * const ADDNEWFILE = "ProjectExplorer.AddNewFile"; const char * const ADDEXISTINGFILES = "ProjectExplorer.AddExistingFiles"; const char * const OPENFILE = "ProjectExplorer.OpenFile"; const char * const SHOWINGRAPHICALSHELL = "ProjectExplorer.ShowInGraphicalShell"; +const char * const OPENTERMIANLHERE = "ProjectExplorer.OpenTerminalHere"; const char * const REMOVEFILE = "ProjectExplorer.RemoveFile"; const char * const RENAMEFILE = "ProjectExplorer.RenameFile";