ProjectExplorer: Make RunControl::bringApplicationToForeground virtual

No practical change as the only case that is used so far are local
setups on Mac. It's a conceptual change, though, giving concrete
RunControl implementation the chance to act "sensibly", e.g. by
raising a locally running simulator control in case of remote setups
or such.

Change-Id: I5679428934fe08b8c9756f3906ee3d9073278822
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
hjk
2017-03-01 09:55:32 +01:00
parent 60cc07103a
commit 716f6e7f1c
5 changed files with 21 additions and 14 deletions

View File

@@ -311,7 +311,7 @@ public:
void raiseApplication() void raiseApplication()
{ {
QTC_ASSERT(runControl(), return); QTC_ASSERT(runControl(), return);
runControl()->bringApplicationToForeground(m_inferiorPid.pid()); runControl()->bringApplicationToForeground();
} }
void scheduleResetLocation() void scheduleResetLocation()

View File

@@ -281,8 +281,8 @@ void ApplicationLauncher::processDone(int exitCode, QProcess::ExitStatus status)
void ApplicationLauncher::bringToForeground() void ApplicationLauncher::bringToForeground()
{ {
emit bringToForegroundRequested(applicationPID());
handleProcessStarted(); handleProcessStarted();
emit bringToForegroundRequested();
} }
QString ApplicationLauncher::msgWinCannotRetrieveDebuggingOutput() QString ApplicationLauncher::msgWinCannotRetrieveDebuggingOutput()

View File

@@ -65,7 +65,7 @@ signals:
void appendMessage(const QString &message, Utils::OutputFormat format); void appendMessage(const QString &message, Utils::OutputFormat format);
void processStarted(); void processStarted();
void processExited(int exitCode, QProcess::ExitStatus); void processExited(int exitCode, QProcess::ExitStatus);
void bringToForegroundRequested(qint64 pid); void bringToForegroundRequested();
void error(QProcess::ProcessError error); void error(QProcess::ProcessError error);
private: private:

View File

@@ -538,9 +538,8 @@ public:
bool isRunning = false; bool isRunning = false;
#ifdef Q_OS_OSX #ifdef Q_OS_OSX
//these two are used to bring apps in the foreground on Mac // This is used to bring apps in the foreground on Mac
int foregroundCount; int foregroundCount;
qint64 internalPid;
#endif #endif
}; };
@@ -656,6 +655,13 @@ bool RunControl::canReUseOutputPane(const RunControl *other) const
return d->runnable.canReUseOutputPane(other->d->runnable); return d->runnable.canReUseOutputPane(other->d->runnable);
} }
/*!
A handle to the application process.
This is typically a process id, but should be treated as
opaque handle to the process controled by this \c RunControl.
*/
ProcessHandle RunControl::applicationProcessHandle() const ProcessHandle RunControl::applicationProcessHandle() const
{ {
return d->applicationProcessHandle; return d->applicationProcessHandle;
@@ -729,14 +735,18 @@ bool RunControl::showPromptToStopDialog(const QString &title,
return close; return close;
} }
void RunControl::bringApplicationToForeground(qint64 pid) /*!
Brings the application determined by this RunControl's \c applicationProcessHandle
to the foreground.
The default implementation raises the application on Mac, and does
nothing elsewhere.
*/
void RunControl::bringApplicationToForeground()
{ {
#ifdef Q_OS_OSX #ifdef Q_OS_OSX
d->internalPid = pid;
d->foregroundCount = 0; d->foregroundCount = 0;
bringApplicationToForegroundInternal(); bringApplicationToForegroundInternal();
#else
Q_UNUSED(pid)
#endif #endif
} }
@@ -758,14 +768,13 @@ void RunControl::bringApplicationToForegroundInternal()
{ {
#ifdef Q_OS_OSX #ifdef Q_OS_OSX
ProcessSerialNumber psn; ProcessSerialNumber psn;
GetProcessForPID(d->internalPid, &psn); GetProcessForPID(d->applicationProcessHandle.pid(), &psn);
if (SetFrontProcess(&psn) == procNotFound && d->foregroundCount < 15) { if (SetFrontProcess(&psn) == procNotFound && d->foregroundCount < 15) {
// somehow the mac/carbon api says // somehow the mac/carbon api says
// "-600 no eligible process with specified process id" // "-600 no eligible process with specified process id"
// if we call SetFrontProcess too early // if we call SetFrontProcess too early
++d->foregroundCount; ++d->foregroundCount;
QTimer::singleShot(200, this, &RunControl::bringApplicationToForegroundInternal); QTimer::singleShot(200, this, &RunControl::bringApplicationToForegroundInternal);
return;
} }
#endif #endif
} }

View File

@@ -391,9 +391,7 @@ public:
void setConnection(const Connection &connection); void setConnection(const Connection &connection);
virtual void appendMessage(const QString &msg, Utils::OutputFormat format); virtual void appendMessage(const QString &msg, Utils::OutputFormat format);
virtual void bringApplicationToForeground();
public slots:
void bringApplicationToForeground(qint64 pid);
signals: signals:
void appendMessageRequested(ProjectExplorer::RunControl *runControl, void appendMessageRequested(ProjectExplorer::RunControl *runControl,