diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index 93bccdb6538..f06eed2911d 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -383,6 +383,7 @@ bool CMakeProject::parseCMakeLists() } + emit displayNameChanged(); emit buildTargetsChanged(); emit fileListChanged(); diff --git a/src/plugins/projectexplorer/doubletabwidget.cpp b/src/plugins/projectexplorer/doubletabwidget.cpp index 6e3a65b4a0c..51facf8e19c 100644 --- a/src/plugins/projectexplorer/doubletabwidget.cpp +++ b/src/plugins/projectexplorer/doubletabwidget.cpp @@ -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; diff --git a/src/plugins/projectexplorer/doubletabwidget.h b/src/plugins/projectexplorer/doubletabwidget.h index 1c88b8d2551..73f12161e56 100644 --- a/src/plugins/projectexplorer/doubletabwidget.h +++ b/src/plugins/projectexplorer/doubletabwidget.h @@ -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); diff --git a/src/plugins/projectexplorer/projectnodes.cpp b/src/plugins/projectexplorer/projectnodes.cpp index 9cd9dc5e574..c0a8a8e14ec 100644 --- a/src/plugins/projectexplorer/projectnodes.cpp +++ b/src/plugins/projectexplorer/projectnodes.cpp @@ -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 SessionNode::projectNodes() const { return m_projectNodes; diff --git a/src/plugins/projectexplorer/projectnodes.h b/src/plugins/projectexplorer/projectnodes.h index fbf6909b5e1..8212e7134aa 100644 --- a/src/plugins/projectexplorer/projectnodes.h +++ b/src/plugins/projectexplorer/projectnodes.h @@ -301,6 +301,7 @@ public: bool isEnabled() const { return true; } bool showInSimpleTree() const; + void projectDisplayNameChanged(Node *node); protected: void addProjectNodes(const QList &projectNodes); void removeProjectNodes(const QList &projectNodes); diff --git a/src/plugins/projectexplorer/projectwindow.cpp b/src/plugins/projectexplorer/projectwindow.cpp index ad53ba22d2c..1fd136f1960 100644 --- a/src/plugins/projectexplorer/projectwindow.cpp +++ b/src/plugins/projectexplorer/projectwindow.cpp @@ -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); } +QStringList ProjectWindow::tabDisplayNamesFor(Project *project) +{ + QList factories = ExtensionSystem::PluginManager::getObjects(); + Utils::sort(factories, &IProjectPanelFactory::prioritySort); + QStringList subTabs; + foreach (IProjectPanelFactory *panelFactory, factories) { + if (panelFactory->supports(project)) + subTabs << panelFactory->displayName(); + } + return subTabs; +} + +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()) { + newIndex = i; + break; + } + } + return newIndex; +} + +void ProjectWindow::projectDisplayNameChanged(Project *project) +{ + int index = m_tabIndexToProject.indexOf(project); + if (index < 0) + return; + + 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 = -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; - } - } - - QStringList subtabs; + int index = insertPosFor(project); // Add the project specific pages - QList factories = ExtensionSystem::PluginManager::getObjects(); - Utils::sort(factories, &IProjectPanelFactory::prioritySort); - foreach (IProjectPanelFactory *panelFactory, factories) { - if (panelFactory->supports(project)) - subtabs << panelFactory->displayName(); - } - + 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; diff --git a/src/plugins/projectexplorer/projectwindow.h b/src/plugins/projectexplorer/projectwindow.h index 1933a6e4036..f276226ee95 100644 --- a/src/plugins/projectexplorer/projectwindow.h +++ b/src/plugins/projectexplorer/projectwindow.h @@ -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; diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp index 2c18d5e7353..fd7360de426 100644 --- a/src/plugins/projectexplorer/session.cpp +++ b/src/plugins/projectexplorer/session.cpp @@ -992,11 +992,7 @@ void SessionManager::projectDisplayNameChanged() if (ProjectExplorerPlugin::currentProject() == pro) currentNode = ProjectExplorerPlugin::instance()->currentNode(); - // Fix node sorting - QList 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);