Add "Open Terminal here"/"Open Command Prompt here" Actions.

Reviewed-By: Friedemann Kleint
This commit is contained in:
Daniel Molkentin
2010-01-04 16:31:28 +01:00
parent 39e4b11277
commit 23fc1afe1f
3 changed files with 34 additions and 0 deletions

View File

@@ -84,6 +84,7 @@
#include <coreplugin/vcsmanager.h> #include <coreplugin/vcsmanager.h>
#include <welcome/welcomemode.h> #include <welcome/welcomemode.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <utils/consoleprocess.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/parameteraction.h> #include <utils/parameteraction.h>
#include <utils/unixutils.h> #include <utils/unixutils.h>
@@ -145,6 +146,7 @@ struct ProjectExplorerPluginPrivate {
QAction *m_addExistingFilesAction; QAction *m_addExistingFilesAction;
QAction *m_openFileAction; QAction *m_openFileAction;
QAction *m_showInGraphicalShell; QAction *m_showInGraphicalShell;
QAction *m_openTerminalHere;
QAction *m_removeFileAction; QAction *m_removeFileAction;
QAction *m_renameFileAction; QAction *m_renameFileAction;
@@ -488,11 +490,22 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
#else #else
d->m_showInGraphicalShell = new QAction(tr("Show containing folder..."), this); d->m_showInGraphicalShell = new QAction(tr("Show containing folder..."), this);
#endif #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, cmd = am->registerAction(d->m_showInGraphicalShell, ProjectExplorer::Constants::SHOWINGRAPHICALSHELL,
globalcontext); globalcontext);
mfilec->addAction(cmd, Constants::G_FILE_OPEN); mfilec->addAction(cmd, Constants::G_FILE_OPEN);
mfolder->addAction(cmd, Constants::G_FOLDER_FILES); 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 // Open With menu
mfilec->addMenu(openWith, ProjectExplorer::Constants::G_FILE_OPEN); 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_addExistingFilesAction, SIGNAL(triggered()), this, SLOT(addExistingFiles()));
connect(d->m_openFileAction, SIGNAL(triggered()), this, SLOT(openFile())); connect(d->m_openFileAction, SIGNAL(triggered()), this, SLOT(openFile()));
connect(d->m_showInGraphicalShell, SIGNAL(triggered()), this, SLOT(showInGraphicalShell())); 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_removeFileAction, SIGNAL(triggered()), this, SLOT(removeFile()));
connect(d->m_renameFileAction, SIGNAL(triggered()), this, SLOT(renameFile())); connect(d->m_renameFileAction, SIGNAL(triggered()), this, SLOT(renameFile()));
@@ -1892,6 +1906,24 @@ void ProjectExplorerPlugin::showInGraphicalShell()
#endif #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() void ProjectExplorerPlugin::removeFile()
{ {
QTC_ASSERT(d->m_currentNode && d->m_currentNode->nodeType() == FileNodeType, return) QTC_ASSERT(d->m_currentNode && d->m_currentNode->nodeType() == FileNodeType, return)

View File

@@ -194,6 +194,7 @@ private slots:
void updateRecentProjectMenu(); void updateRecentProjectMenu();
void openRecentProject(); void openRecentProject();
void openTerminalHere();
void invalidateProject(ProjectExplorer::Project *project); void invalidateProject(ProjectExplorer::Project *project);

View File

@@ -69,6 +69,7 @@ const char * const ADDNEWFILE = "ProjectExplorer.AddNewFile";
const char * const ADDEXISTINGFILES = "ProjectExplorer.AddExistingFiles"; const char * const ADDEXISTINGFILES = "ProjectExplorer.AddExistingFiles";
const char * const OPENFILE = "ProjectExplorer.OpenFile"; const char * const OPENFILE = "ProjectExplorer.OpenFile";
const char * const SHOWINGRAPHICALSHELL = "ProjectExplorer.ShowInGraphicalShell"; const char * const SHOWINGRAPHICALSHELL = "ProjectExplorer.ShowInGraphicalShell";
const char * const OPENTERMIANLHERE = "ProjectExplorer.OpenTerminalHere";
const char * const REMOVEFILE = "ProjectExplorer.RemoveFile"; const char * const REMOVEFILE = "ProjectExplorer.RemoveFile";
const char * const RENAMEFILE = "ProjectExplorer.RenameFile"; const char * const RENAMEFILE = "ProjectExplorer.RenameFile";