-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpqt5runconfiguration.cpp
More file actions
160 lines (127 loc) · 5.43 KB
/
Copy pathphpqt5runconfiguration.cpp
File metadata and controls
160 lines (127 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "phpqt5runconfiguration.h"
#include "phpqt5buildconfiguration.h"
#include "phpqt5runconfigurationwidget.h"
#include "phpqt5constants.h"
#include <projectexplorer/runnables.h>
#include <projectexplorer/localenvironmentaspect.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <utils/environment.h>
#include <QDir>
#include <QFileInfo>
#include <QVariantMap>
#include <QMessageBox>
using namespace ProjectExplorer;
using namespace Utils;
namespace PHPQt5 {
PHPQt5RunConfiguration::PHPQt5RunConfiguration(Target *parent, Core::Id id)
: RunConfiguration(parent, id)
, m_buildConfiguration(nullptr)
, m_workingDirectoryAspect(new WorkingDirectoryAspect(this, PHPQt5::Constants::C_PHPQt5RUNCONFIGURATION_WORKINGDIRECTORYASPECT_ID))
, m_argumentAspect(new ArgumentsAspect(this, PHPQt5::Constants::C_PHPQt5RUNCONFIGURATION_ARGUMENTASPECT_ID))
, m_terminalAspect(new TerminalAspect(this, PHPQt5::Constants::C_PHPQt5RUNCONFIGURATION_TERMINALASPECT_ID))
, m_localEnvironmentAspect(new LocalEnvironmentAspect(this, LocalEnvironmentAspect::BaseEnvironmentModifier()))
{
m_terminalAspect->setRunMode(ApplicationLauncher::Gui);
addExtraAspect(m_argumentAspect);
addExtraAspect(m_terminalAspect);
addExtraAspect(m_localEnvironmentAspect);
setDisplayName(tr(Constants::C_PHPQt5RUNCONFIGURATION_DISPLAY));
setDefaultDisplayName(tr(Constants::C_PHPQt5RUNCONFIGURATION_DEFAULT_DISPLAY));
// Connect target signals
connect(this->target(), &Target::activeBuildConfigurationChanged,
this, &PHPQt5RunConfiguration::updateConfiguration);
updateConfiguration();
}
QWidget *PHPQt5RunConfiguration::createConfigurationWidget()
{
return new PHPQt5RunConfigurationWidget(this);
}
Runnable PHPQt5RunConfiguration::runnable() const
{
StandardRunnable result;
result.runMode = m_terminalAspect->runMode();
result.executable = m_executable;
result.commandLineArguments = m_argumentAspect->arguments();
result.workingDirectory = m_workingDirectoryAspect->workingDirectory().toString();
result.environment = m_localEnvironmentAspect->environment();
return result;
}
QVariantMap PHPQt5RunConfiguration::toMap() const
{
auto result = RunConfiguration::toMap();
result[Constants::C_PHPQt5RUNCONFIGURATION_EXECUTABLE_KEY] = m_executable;
return result;
}
bool PHPQt5RunConfiguration::fromMap(const QVariantMap &map)
{
bool result = RunConfiguration::fromMap(map);
if (!result)
return result;
m_executable = map[Constants::C_PHPQt5RUNCONFIGURATION_EXECUTABLE_KEY].toString();
return true;
}
void PHPQt5RunConfiguration::setExecutable(const QString &executable)
{
if (m_executable == executable)
return;
m_executable = executable;
emit executableChanged(executable);
}
void PHPQt5RunConfiguration::setWorkingDirectory(const QString &workingDirectory)
{
m_workingDirectoryAspect->setDefaultWorkingDirectory(FileName::fromString(workingDirectory));
}
void PHPQt5RunConfiguration::updateConfiguration()
{
PHPQt5BuildConfiguration *buildConfiguration = qobject_cast<PHPQt5BuildConfiguration *>(activeBuildConfiguration());
QTC_ASSERT(buildConfiguration, return);
setActiveBuildConfiguration(buildConfiguration);
const QFileInfo outFileInfo = buildConfiguration->outFilePath().toFileInfo();
#ifdef Q_OS_WIN
static const QString execExt = ".exe";
#else
static const QString execExt = "";
#endif
switch (buildConfiguration->buildType()) {
case BuildConfiguration::BuildType::Release: {
const QString execFileName = buildConfiguration->projectFilePath().fileName()
.replace(QRegExp("\\.phpqt5$"), execExt);
setExecutable(QString("%1/%2/%3")
.arg(outFileInfo.absoluteFilePath())
.arg("release")
.arg(execFileName));
} break;
case BuildConfiguration::BuildType::Debug: {
const QString execFileName = buildConfiguration->projectFilePath().fileName()
.replace(QRegExp("\\.phpqt5$"), QString("-debug%1").arg(execExt));
setExecutable(QString("%1/%2/%3")
.arg(outFileInfo.absoluteFilePath())
.arg("release")
.arg(execFileName));
} break;
default: //nothing
break;
}
setWorkingDirectory(outFileInfo.absoluteDir().absolutePath());
}
void PHPQt5RunConfiguration::setActiveBuildConfiguration(PHPQt5BuildConfiguration *activeBuildConfiguration)
{
if (m_buildConfiguration == activeBuildConfiguration)
return;
if (m_buildConfiguration) {
disconnect(m_buildConfiguration, &PHPQt5BuildConfiguration::buildDirectoryChanged,
this, &PHPQt5RunConfiguration::updateConfiguration);
disconnect(m_buildConfiguration, &PHPQt5BuildConfiguration::outFilePathChanged,
this, &PHPQt5RunConfiguration::updateConfiguration);
}
m_buildConfiguration = activeBuildConfiguration;
if (m_buildConfiguration) {
connect(m_buildConfiguration, &PHPQt5BuildConfiguration::buildDirectoryChanged,
this, &PHPQt5RunConfiguration::updateConfiguration);
connect(m_buildConfiguration, &PHPQt5BuildConfiguration::outFilePathChanged,
this, &PHPQt5RunConfiguration::updateConfiguration);
//connect(m_buildConfiguration, &PHPQt5BuildConfiguration::buildTypeChanged,
// this, &PHPQt5RunConfiguration::updateConfiguration);
}
}
}