Commit 3d4caa39 authored by Daniel Teske's avatar Daniel Teske

ProjectExplorer: Fix Project::displayName changes

The only project manager that actually sometimes changes the displayname
is the cmake project manager. And that one failed to emit the right
signal. And since the signal was never emitted a few places handled the
signal wrongly.

Change-Id: I4aa75dc3032efe49263143dbadb7585a378b9be9
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 895207be
......@@ -383,6 +383,7 @@ bool CMakeProject::parseCMakeLists()
}
emit displayNameChanged();
emit buildTargetsChanged();
emit fileListChanged();
......
......@@ -122,6 +122,25 @@ int DoubleTabWidget::currentSubIndex() const
return -1;
}
QStringList DoubleTabWidget::subTabs(int index) const
{
if (index >= 0 && index < m_tabs.size())
return m_tabs.at(index).subTabs;
return QStringList();
}
void DoubleTabWidget::setCurrentIndex(int index, int subIndex)
{
Q_ASSERT(index < m_tabs.size());
if (index == m_currentIndex
&& m_tabs.at(m_currentIndex).currentSubTab == subIndex)
return;
m_currentIndex = index;
m_tabs[m_currentIndex].currentSubTab = subIndex;
emit currentIndexChanged(m_currentIndex, m_tabs.at(m_currentIndex).currentSubTab);
update();
}
void DoubleTabWidget::setTitle(const QString &title)
{
m_title = title;
......
......@@ -56,9 +56,12 @@ public:
int currentIndex() const;
void setCurrentIndex(int index);
void setCurrentIndex(int index, int subIndex);
int currentSubIndex() const;
QStringList subTabs(int index) const;
signals:
void currentIndexChanged(int index, int subIndex);
......
......@@ -811,6 +811,14 @@ bool SessionNode::showInSimpleTree() const
return true;
}
void SessionNode::projectDisplayNameChanged(Node *node)
{
foreach (NodesWatcher *watcher, m_watchers)
emit watcher->nodeSortKeyAboutToChange(node);
foreach (NodesWatcher *watcher, m_watchers)
emit watcher->nodeSortKeyChanged();
}
QList<ProjectNode*> SessionNode::projectNodes() const
{
return m_projectNodes;
......
......@@ -301,6 +301,7 @@ public:
bool isEnabled() const { return true; }
bool showInSimpleTree() const;
void projectDisplayNameChanged(Node *node);
protected:
void addProjectNodes(const QList<ProjectNode*> &projectNodes);
void removeProjectNodes(const QList<ProjectNode*> &projectNodes);
......
......@@ -54,6 +54,7 @@ using namespace ProjectExplorer::Internal;
ProjectWindow::ProjectWindow(QWidget *parent)
: QWidget(parent),
m_ignoreChange(false),
m_currentWidget(0)
{
// Setup overall layout:
......@@ -82,7 +83,7 @@ ProjectWindow::ProjectWindow(QWidget *parent)
this, SLOT(startupProjectChanged(ProjectExplorer::Project*)));
connect(sessionManager, SIGNAL(projectDisplayNameChanged(ProjectExplorer::Project*)),
this, SLOT(projectUpdated(ProjectExplorer::Project*)));
this, SLOT(projectDisplayNameChanged(ProjectExplorer::Project*)));
// Update properties to empty project for now:
showProperties(-1, -1);
......@@ -117,31 +118,63 @@ void ProjectWindow::projectUpdated(Project *p)
m_tabWidget->setCurrentIndex(index);
}
void ProjectWindow::registerProject(ProjectExplorer::Project *project)
QStringList ProjectWindow::tabDisplayNamesFor(Project *project)
{
if (!project || m_tabIndexToProject.contains(project))
return;
QList<IProjectPanelFactory *> factories = ExtensionSystem::PluginManager::getObjects<IProjectPanelFactory>();
Utils::sort(factories, &IProjectPanelFactory::prioritySort);
QStringList subTabs;
foreach (IProjectPanelFactory *panelFactory, factories) {
if (panelFactory->supports(project))
subTabs << panelFactory->displayName();
}
return subTabs;
}
// find index to insert:
int index = -1;
int ProjectWindow::insertPosFor(Project *project)
{
int newIndex = -1;
for (int i = 0; i <= m_tabIndexToProject.count(); ++i) {
if (i == m_tabIndexToProject.count() ||
m_tabIndexToProject.at(i)->displayName() > project->displayName()) {
index = i;
newIndex = i;
break;
}
}
return newIndex;
}
QStringList subtabs;
void ProjectWindow::projectDisplayNameChanged(Project *project)
{
int index = m_tabIndexToProject.indexOf(project);
if (index < 0)
return;
// Add the project specific pages
QList<IProjectPanelFactory *> factories = ExtensionSystem::PluginManager::getObjects<IProjectPanelFactory>();
Utils::sort(factories, &IProjectPanelFactory::prioritySort);
foreach (IProjectPanelFactory *panelFactory, factories) {
if (panelFactory->supports(project))
subtabs << panelFactory->displayName();
}
m_ignoreChange = true;
bool isCurrentIndex = m_tabWidget->currentIndex() == index;
int subIndex = m_tabWidget->currentSubIndex();
QStringList subTabs = m_tabWidget->subTabs(index);
m_tabIndexToProject.removeAt(index);
m_tabWidget->removeTab(index);
int newIndex = insertPosFor(project);
m_tabIndexToProject.insert(newIndex, project);
m_tabWidget->insertTab(newIndex, project->displayName(), project->projectFilePath().toString(), subTabs);
if (isCurrentIndex)
m_tabWidget->setCurrentIndex(newIndex, subIndex);
m_ignoreChange = false;
}
void ProjectWindow::registerProject(ProjectExplorer::Project *project)
{
if (!project || m_tabIndexToProject.contains(project))
return;
// find index to insert:
int index = insertPosFor(project);
// Add the project specific pages
QStringList subtabs = tabDisplayNamesFor(project);
m_tabIndexToProject.insert(index, project);
m_tabWidget->insertTab(index, project->displayName(), project->projectFilePath().toString(), subtabs);
......@@ -171,6 +204,9 @@ void ProjectWindow::startupProjectChanged(ProjectExplorer::Project *p)
void ProjectWindow::showProperties(int index, int subIndex)
{
if (m_ignoreChange)
return;
if (index < 0 || index >= m_tabIndexToProject.count()) {
removeCurrentWidget();
return;
......
......@@ -61,6 +61,7 @@ public slots:
void projectUpdated(ProjectExplorer::Project *p);
private slots:
void projectDisplayNameChanged(ProjectExplorer::Project *p);
void showProperties(int index, int subIndex);
void registerProject(ProjectExplorer::Project*);
bool deregisterProject(ProjectExplorer::Project*);
......@@ -69,7 +70,10 @@ private slots:
private:
void removeCurrentWidget();
static QStringList tabDisplayNamesFor(Project *project);
int insertPosFor(Project *project);
bool m_ignoreChange;
DoubleTabWidget *m_tabWidget;
QStackedWidget *m_centralWidget;
QWidget *m_currentWidget;
......
......@@ -992,11 +992,7 @@ void SessionManager::projectDisplayNameChanged()
if (ProjectExplorerPlugin::currentProject() == pro)
currentNode = ProjectExplorerPlugin::instance()->currentNode();
// Fix node sorting
QList<ProjectNode *> nodes;
nodes << pro->rootProjectNode();
d->m_sessionNode->removeProjectNodes(nodes);
d->m_sessionNode->addProjectNodes(nodes);
d->m_sessionNode->projectDisplayNameChanged(pro->rootProjectNode());
if (currentNode)
ProjectExplorerPlugin::instance()->setCurrentNode(currentNode);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment