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: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Daniel Teske
2014-07-14 17:39:46 +02:00
parent 895207be18
commit 3d4caa3908
8 changed files with 91 additions and 23 deletions

View File

@@ -383,6 +383,7 @@ bool CMakeProject::parseCMakeLists()
}
emit displayNameChanged();
emit buildTargetsChanged();
emit fileListChanged();

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);

View File

@@ -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<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;
}
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<IProjectPanelFactory *> factories = ExtensionSystem::PluginManager::getObjects<IProjectPanelFactory>();
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;

View File

@@ -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;

View File

@@ -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);