2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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 Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "projectwindow.h"
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2010-01-21 13:46:19 +01:00
|
|
|
#include "doubletabwidget.h"
|
2014-07-11 16:54:04 +02:00
|
|
|
#include "panelswidget.h"
|
2012-09-03 18:31:44 +02:00
|
|
|
#include "kitmanager.h"
|
2008-12-02 16:19:05 +01:00
|
|
|
#include "project.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "projectexplorer.h"
|
2014-07-14 13:10:50 +02:00
|
|
|
#include "iprojectpanelfactory.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "session.h"
|
2010-12-10 19:02:19 +01:00
|
|
|
#include "target.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
#include <coreplugin/idocument.h>
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2014-06-16 18:25:52 +04:00
|
|
|
#include <utils/algorithm.h>
|
2009-11-30 16:23:28 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QStackedWidget>
|
2014-07-11 16:54:04 +02:00
|
|
|
#include <QVBoxLayout>
|
2009-09-29 18:06:13 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace ProjectExplorer::Internal;
|
2009-08-06 15:31:32 +02:00
|
|
|
///
|
|
|
|
|
// ProjectWindow
|
|
|
|
|
///
|
|
|
|
|
|
2009-06-08 19:13:46 +02:00
|
|
|
ProjectWindow::ProjectWindow(QWidget *parent)
|
2010-01-21 13:46:19 +01:00
|
|
|
: QWidget(parent),
|
2014-07-11 13:08:09 +02:00
|
|
|
m_currentWidget(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-11-25 16:01:46 +01:00
|
|
|
// Setup overall layout:
|
|
|
|
|
QVBoxLayout *viewLayout = new QVBoxLayout(this);
|
|
|
|
|
viewLayout->setMargin(0);
|
|
|
|
|
viewLayout->setSpacing(0);
|
2009-09-17 13:59:10 +02:00
|
|
|
|
2010-01-21 13:46:19 +01:00
|
|
|
m_tabWidget = new DoubleTabWidget(this);
|
|
|
|
|
viewLayout->addWidget(m_tabWidget);
|
2009-10-07 15:46:07 +02:00
|
|
|
|
2009-11-25 16:01:46 +01:00
|
|
|
// Setup our container for the contents:
|
2010-01-21 13:46:19 +01:00
|
|
|
m_centralWidget = new QStackedWidget(this);
|
|
|
|
|
viewLayout->addWidget(m_centralWidget);
|
2009-11-25 16:01:46 +01:00
|
|
|
|
2013-09-05 11:46:07 +02:00
|
|
|
// Connections
|
2010-01-21 13:46:19 +01:00
|
|
|
connect(m_tabWidget, SIGNAL(currentIndexChanged(int,int)),
|
|
|
|
|
this, SLOT(showProperties(int,int)));
|
2009-09-17 13:59:10 +02:00
|
|
|
|
2013-09-05 11:46:07 +02:00
|
|
|
QObject *sessionManager = SessionManager::instance();
|
|
|
|
|
connect(sessionManager, SIGNAL(projectAdded(ProjectExplorer::Project*)),
|
2010-03-11 13:42:41 +01:00
|
|
|
this, SLOT(registerProject(ProjectExplorer::Project*)));
|
2013-09-05 11:46:07 +02:00
|
|
|
connect(sessionManager, SIGNAL(aboutToRemoveProject(ProjectExplorer::Project*)),
|
2010-03-11 13:42:41 +01:00
|
|
|
this, SLOT(deregisterProject(ProjectExplorer::Project*)));
|
2009-11-25 15:18:51 +01:00
|
|
|
|
2013-09-05 11:46:07 +02:00
|
|
|
connect(sessionManager, SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
|
2012-03-05 22:30:59 +01:00
|
|
|
this, SLOT(startupProjectChanged(ProjectExplorer::Project*)));
|
2010-03-24 18:36:06 +01:00
|
|
|
|
2013-09-05 11:46:07 +02:00
|
|
|
connect(sessionManager, SIGNAL(projectDisplayNameChanged(ProjectExplorer::Project*)),
|
2012-04-16 19:18:26 +04:00
|
|
|
this, SLOT(projectUpdated(ProjectExplorer::Project*)));
|
|
|
|
|
|
2009-11-25 15:18:51 +01:00
|
|
|
// Update properties to empty project for now:
|
2010-01-21 13:46:19 +01:00
|
|
|
showProperties(-1, -1);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectWindow::~ProjectWindow()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-28 16:59:03 +02:00
|
|
|
void ProjectWindow::aboutToShutdown()
|
2009-10-07 15:46:07 +02:00
|
|
|
{
|
2012-05-03 16:10:00 +02:00
|
|
|
showProperties(-1, -1); // that's a bit stupid, but otherwise stuff is still
|
|
|
|
|
// connected to the session
|
2013-10-11 16:18:04 +02:00
|
|
|
disconnect(KitManager::instance(), 0, this, 0);
|
2013-09-05 11:46:07 +02:00
|
|
|
disconnect(SessionManager::instance(), 0, this, 0);
|
2009-10-07 15:46:07 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-16 15:12:58 +02:00
|
|
|
void ProjectWindow::removedTarget(Target *)
|
2012-07-12 13:31:35 +02:00
|
|
|
{
|
|
|
|
|
Project *p = qobject_cast<Project *>(sender());
|
|
|
|
|
QTC_ASSERT(p, return);
|
|
|
|
|
if (p->targets().isEmpty())
|
|
|
|
|
projectUpdated(p);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-28 10:15:04 +00:00
|
|
|
void ProjectWindow::projectUpdated(Project *p)
|
|
|
|
|
{
|
|
|
|
|
// Called after a project was configured
|
|
|
|
|
int index = m_tabWidget->currentIndex();
|
2014-07-03 16:36:17 +02:00
|
|
|
if (deregisterProject(p)) // might return false if the project is unloading
|
|
|
|
|
registerProject(p);
|
2011-10-28 10:15:04 +00:00
|
|
|
m_tabWidget->setCurrentIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-11 13:42:41 +01:00
|
|
|
void ProjectWindow::registerProject(ProjectExplorer::Project *project)
|
2009-10-07 15:46:07 +02:00
|
|
|
{
|
2010-03-05 09:36:05 +01:00
|
|
|
if (!project || m_tabIndexToProject.contains(project))
|
2010-02-08 15:50:06 +01:00
|
|
|
return;
|
|
|
|
|
|
2010-03-05 09:36:05 +01:00
|
|
|
// find index to insert:
|
|
|
|
|
int index = -1;
|
|
|
|
|
for (int i = 0; i <= m_tabIndexToProject.count(); ++i) {
|
|
|
|
|
if (i == m_tabIndexToProject.count() ||
|
|
|
|
|
m_tabIndexToProject.at(i)->displayName() > project->displayName()) {
|
|
|
|
|
index = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-21 13:46:19 +01:00
|
|
|
QStringList subtabs;
|
2010-12-10 19:02:19 +01:00
|
|
|
|
2010-03-25 16:16:38 +01:00
|
|
|
// Add the project specific pages
|
2012-06-18 11:34:15 +02:00
|
|
|
QList<IProjectPanelFactory *> factories = ExtensionSystem::PluginManager::getObjects<IProjectPanelFactory>();
|
2014-07-11 13:20:40 +02:00
|
|
|
Utils::sort(factories, &IProjectPanelFactory::prioritySort);
|
2010-03-25 16:16:38 +01:00
|
|
|
foreach (IProjectPanelFactory *panelFactory, factories) {
|
|
|
|
|
if (panelFactory->supports(project))
|
|
|
|
|
subtabs << panelFactory->displayName();
|
2009-10-07 15:46:07 +02:00
|
|
|
}
|
2010-02-08 15:50:06 +01:00
|
|
|
|
2010-01-21 13:46:19 +01:00
|
|
|
m_tabIndexToProject.insert(index, project);
|
2014-05-02 12:22:58 +02:00
|
|
|
m_tabWidget->insertTab(index, project->displayName(), project->projectFilePath().toString(), subtabs);
|
2012-07-12 13:31:35 +02:00
|
|
|
|
|
|
|
|
connect(project, SIGNAL(removedTarget(ProjectExplorer::Target*)),
|
|
|
|
|
this, SLOT(removedTarget(ProjectExplorer::Target*)));
|
2010-01-21 13:46:19 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-03 16:36:17 +02:00
|
|
|
bool ProjectWindow::deregisterProject(ProjectExplorer::Project *project)
|
2010-01-21 13:46:19 +01:00
|
|
|
{
|
|
|
|
|
int index = m_tabIndexToProject.indexOf(project);
|
2010-03-05 09:36:05 +01:00
|
|
|
if (index < 0)
|
2014-07-03 16:36:17 +02:00
|
|
|
return false;
|
2010-03-11 13:42:41 +01:00
|
|
|
|
2010-01-21 13:46:19 +01:00
|
|
|
m_tabIndexToProject.removeAt(index);
|
|
|
|
|
m_tabWidget->removeTab(index);
|
2012-07-12 13:31:35 +02:00
|
|
|
disconnect(project, SIGNAL(removedTarget(ProjectExplorer::Target*)),
|
|
|
|
|
this, SLOT(removedTarget(ProjectExplorer::Target*)));
|
2014-07-03 16:36:17 +02:00
|
|
|
return true;
|
2009-10-07 15:46:07 +02:00
|
|
|
}
|
|
|
|
|
|
2010-03-24 18:36:06 +01:00
|
|
|
void ProjectWindow::startupProjectChanged(ProjectExplorer::Project *p)
|
|
|
|
|
{
|
|
|
|
|
int index = m_tabIndexToProject.indexOf(p);
|
2010-03-26 11:01:47 +01:00
|
|
|
if (index != -1)
|
|
|
|
|
m_tabWidget->setCurrentIndex(index);
|
2010-03-11 13:42:41 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-21 13:46:19 +01:00
|
|
|
void ProjectWindow::showProperties(int index, int subIndex)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-08-26 18:47:32 +02:00
|
|
|
if (index < 0 || index >= m_tabIndexToProject.count()) {
|
|
|
|
|
removeCurrentWidget();
|
2010-01-21 13:46:19 +01:00
|
|
|
return;
|
2010-08-26 18:47:32 +02:00
|
|
|
}
|
2010-02-22 15:47:47 +01:00
|
|
|
|
2010-01-21 13:46:19 +01:00
|
|
|
Project *project = m_tabIndexToProject.at(index);
|
2009-11-04 18:50:37 +01:00
|
|
|
|
2009-11-25 15:18:51 +01:00
|
|
|
// Set up custom panels again:
|
2010-02-08 15:50:06 +01:00
|
|
|
int pos = 0;
|
2014-07-11 11:54:49 +02:00
|
|
|
IProjectPanelFactory *fac = 0;
|
2010-12-10 19:02:19 +01:00
|
|
|
|
2012-08-07 10:05:19 +02:00
|
|
|
QList<IProjectPanelFactory *> factories = ExtensionSystem::PluginManager::getObjects<IProjectPanelFactory>();
|
2014-07-11 13:20:40 +02:00
|
|
|
Utils::sort(factories, &IProjectPanelFactory::prioritySort);
|
2012-08-07 10:05:19 +02:00
|
|
|
foreach (IProjectPanelFactory *panelFactory, factories) {
|
|
|
|
|
if (panelFactory->supports(project)) {
|
|
|
|
|
if (subIndex == pos) {
|
|
|
|
|
fac = panelFactory;
|
|
|
|
|
break;
|
2010-03-25 16:16:38 +01:00
|
|
|
}
|
2012-08-07 10:05:19 +02:00
|
|
|
++pos;
|
2010-03-25 16:16:38 +01:00
|
|
|
}
|
2010-01-21 13:46:19 +01:00
|
|
|
}
|
2010-03-25 16:16:38 +01:00
|
|
|
|
|
|
|
|
if (fac) {
|
|
|
|
|
removeCurrentWidget();
|
|
|
|
|
|
2014-07-11 18:23:30 +02:00
|
|
|
QWidget *widget = fac->createWidget(project);
|
|
|
|
|
Q_ASSERT(widget);
|
2010-03-25 16:16:38 +01:00
|
|
|
|
2014-07-11 18:23:30 +02:00
|
|
|
m_currentWidget = widget;
|
2010-03-25 16:16:38 +01:00
|
|
|
m_centralWidget->addWidget(m_currentWidget);
|
|
|
|
|
m_centralWidget->setCurrentWidget(m_currentWidget);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 11:46:07 +02:00
|
|
|
SessionManager::setStartupProject(project);
|
2010-02-08 15:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectWindow::removeCurrentWidget()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentWidget) {
|
|
|
|
|
m_centralWidget->removeWidget(m_currentWidget);
|
2010-03-25 16:16:38 +01:00
|
|
|
if (m_currentWidget) {
|
2010-02-08 15:50:06 +01:00
|
|
|
delete m_currentWidget;
|
|
|
|
|
m_currentWidget = 0;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|