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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "qmakeprojectmanager.h"
#include "qmakeprojectmanagerconstants.h"
#include "qmakeprojectmanagerplugin.h"
#include "qmakenodes.h"
#include "qmakeproject.h"
#include "profileeditor.h"
#include "qmakestep.h"
#include "qmakebuildconfiguration.h"
#include "addlibrarywizard.h"
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projecttree.h>
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <utils/qtcassert.h>
#include <texteditor/texteditor.h>
#include <QDir>
#include <QFileInfo>
#include <QVariant>
using namespace ProjectExplorer;
using namespace TextEditor;
namespace QmakeProjectManager {
QmakeManager::~QmakeManager()
{
}
void QmakeManager::registerProject(QmakeProject *project)
{
m_projects.append(project);
}
void QmakeManager::unregisterProject(QmakeProject *project)
{
m_projects.removeOne(project);
}
void QmakeManager::notifyChanged(const Utils::FileName &name)
{
foreach (QmakeProject *pro, m_projects)
pro->notifyChanged(name);
}
QString QmakeManager::mimeType() const
{
return QLatin1String(QmakeProjectManager::Constants::PROFILE_MIMETYPE);
}
ProjectExplorer::Project *QmakeManager::openProject(const QString &fileName, QString *errorString)
{
if (!QFileInfo(fileName).isFile()) {
if (errorString)
*errorString = tr("Failed opening project \"%1\": Project is not a file")
.arg(fileName);
return 0;
}
return new QmakeProject(this, fileName);
}
ProjectExplorer::Node *QmakeManager::contextNode() const
{
return m_contextNode;
}
void QmakeManager::setContextNode(ProjectExplorer::Node *node)
{
m_contextNode = node;
}
ProjectExplorer::Project *QmakeManager::contextProject() const
{
return m_contextProject;
}
void QmakeManager::setContextProject(ProjectExplorer::Project *project)
{
m_contextProject = project;
}
ProjectExplorer::FileNode *QmakeManager::contextFile() const
{
return m_contextFile;
}
void QmakeManager::setContextFile(ProjectExplorer::FileNode *file)
{
m_contextFile = file;
}
void QmakeManager::addLibrary()
{
if (auto editor = qobject_cast<BaseTextEditor *>(Core::EditorManager::currentEditor()))
addLibrary(editor->document()->filePath().toString(), editor);
}
void QmakeManager::addLibraryContextMenu()
{
Node *node = ProjectTree::currentNode();
if (dynamic_cast<QmakeProFileNode *>(node))
addLibrary(node->path().toString());
}
void QmakeManager::addLibrary(const QString &fileName, BaseTextEditor *editor)
{
Internal::AddLibraryWizard wizard(fileName, Core::ICore::dialogParent());
if (wizard.exec() != QDialog::Accepted)
return;
if (!editor)
editor = qobject_cast<BaseTextEditor *>(Core::EditorManager::openEditor(fileName,
Constants::PROFILE_EDITOR_ID, Core::EditorManager::DoNotMakeVisible));
if (!editor)
return;
const int endOfDoc = editor->position(EndOfDocPosition);
editor->setCursorPosition(endOfDoc);
QString snippet = wizard.snippet();
// add extra \n in case the last line is not empty
int line, column;
editor->convertPosition(endOfDoc, &line, &column);
if (!editor->textAt(endOfDoc - column, column).simplified().isEmpty())
snippet = QLatin1Char('\n') + snippet;
editor->insert(snippet);
}
void QmakeManager::runQMake()
{
runQMake(SessionManager::startupProject(), 0);
}
void QmakeManager::runQMakeContextMenu()
{
runQMake(m_contextProject, m_contextNode);
}
void QmakeManager::runQMake(ProjectExplorer::Project *p, ProjectExplorer::Node *node)
{
if (!ProjectExplorerPlugin::saveModifiedFiles())
return;
QmakeProject *qmakeProject = qobject_cast<QmakeProject *>(p);
QTC_ASSERT(qmakeProject, return);
if (!qmakeProject->activeTarget() ||
!qmakeProject->activeTarget()->activeBuildConfiguration())
return;
QmakeBuildConfiguration *bc = static_cast<QmakeBuildConfiguration *>(qmakeProject->activeTarget()->activeBuildConfiguration());
QMakeStep *qs = bc->qmakeStep();
if (!qs)
return;
//found qmakeStep, now use it
qs->setForced(true);
if (node != 0 && node != qmakeProject->rootProjectNode())
if (QmakeProFileNode *profile = dynamic_cast<QmakeProFileNode *>(node))
bc->setSubNodeBuild(profile);
BuildManager::appendStep(qs, tr("QMake"));
bc->setSubNodeBuild(0);
}
void QmakeManager::buildSubDirContextMenu()
{
handleSubDirContextMenu(BUILD, false);
}
void QmakeManager::cleanSubDirContextMenu()
{
handleSubDirContextMenu(CLEAN, false);
}
void QmakeManager::rebuildSubDirContextMenu()
{
handleSubDirContextMenu(REBUILD, false);
}
void QmakeManager::buildFileContextMenu()
{
handleSubDirContextMenu(BUILD, true);
}
void QmakeManager::buildFile()
{
if (Core::IDocument *currentDocument= Core::EditorManager::currentDocument()) {
const Utils::FileName file = currentDocument->filePath();
Node *n = SessionManager::nodeForFile(file);
FileNode *node = n ? n->asFileNode() : 0;
Project *project = SessionManager::projectForFile(file);
if (project && node)
handleSubDirContextMenu(BUILD, true, project, node->projectNode(), node);
}
}
void QmakeManager::handleSubDirContextMenu(QmakeManager::Action action, bool isFileBuild)
{
handleSubDirContextMenu(action, isFileBuild, m_contextProject, m_contextNode, m_contextFile);
}
void QmakeManager::handleSubDirContextMenu(QmakeManager::Action action, bool isFileBuild,
ProjectExplorer::Project *contextProject,
ProjectExplorer::Node *contextNode,
ProjectExplorer::FileNode *contextFile)
{
QmakeProject *qmakeProject = qobject_cast<QmakeProject *>(contextProject);
QTC_ASSERT(qmakeProject, return);
if (!qmakeProject->activeTarget() ||
!qmakeProject->activeTarget()->activeBuildConfiguration())
return;
if (!contextNode || !contextFile)
isFileBuild = false;
QmakeBuildConfiguration *bc = qobject_cast<QmakeBuildConfiguration *>(qmakeProject->activeTarget()->activeBuildConfiguration());
if (!bc)
return;
if (contextNode) {
if (QmakePriFileNode *prifile = dynamic_cast<QmakePriFileNode *>(contextNode)) {
if (QmakeProFileNode *profile = prifile->proFileNode()) {
if (profile != qmakeProject->rootProjectNode() || isFileBuild)
bc->setSubNodeBuild(profile);
}
}
}
if (isFileBuild)
bc->setFileNodeBuild(contextFile);
if (ProjectExplorerPlugin::saveModifiedFiles()) {
const Core::Id buildStep = ProjectExplorer::Constants::BUILDSTEPS_BUILD;
const Core::Id cleanStep = ProjectExplorer::Constants::BUILDSTEPS_CLEAN;
if (action == BUILD) {
const QString name = ProjectExplorerPlugin::displayNameForStepId(buildStep);
BuildManager::buildList(bc->stepList(buildStep), name);
} else if (action == CLEAN) {
const QString name = ProjectExplorerPlugin::displayNameForStepId(cleanStep);
BuildManager::buildList(bc->stepList(cleanStep), name);
} else if (action == REBUILD) {
QStringList names;
names << ProjectExplorerPlugin::displayNameForStepId(cleanStep)
<< ProjectExplorerPlugin::displayNameForStepId(buildStep);
QList<ProjectExplorer::BuildStepList *> stepLists;
stepLists << bc->stepList(cleanStep) << bc->stepList(buildStep);
BuildManager::buildLists(stepLists, names);
}
}
bc->setSubNodeBuild(0);
bc->setFileNodeBuild(0);
}
} // namespace QmakeProjectManager
|