Commit 4012b759 authored by Daniel Teske's avatar Daniel Teske

Fix handling of current node if project tree view is hidden

I'm not 100% sure that this fixes the crash from QTCREATORBUG-12876.
But it's clearly wrong to only check for removed nodes in the project
tree widget and thus only if a tree widget is shown.

Task-number: QTCREATORBUG-12876
Change-Id: Iaaafcef0fe408e8bc2f4d2b61133f4419a612d57
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 00477182
......@@ -446,6 +446,14 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
connect(sessionManager, SIGNAL(sessionLoaded(QString)),
this, SLOT(updateWelcomePage()));
NodesWatcher *watcher = new NodesWatcher(this);
SessionManager::sessionNode()->registerWatcher(watcher);
connect(watcher, &NodesWatcher::foldersAboutToBeRemoved,
this, &ProjectExplorerPlugin::foldersAboutToBeRemoved);
connect(watcher, &NodesWatcher::filesAboutToBeRemoved,
this, &ProjectExplorerPlugin::filesAboutToBeRemoved);
addAutoReleasedObject(new CustomWizardMetaFactory<CustomProjectWizard>(Core::IWizardFactory::ProjectWizard));
addAutoReleasedObject(new CustomWizardMetaFactory<CustomWizard>(Core::IWizardFactory::FileWizard));
addAutoReleasedObject(new CustomWizardMetaFactory<CustomWizard>(Core::IWizardFactory::ClassWizard));
......@@ -2889,6 +2897,32 @@ void ProjectExplorerPlugin::invalidateProject(Project *project)
updateActions();
}
void ProjectExplorerPlugin::foldersAboutToBeRemoved(FolderNode *, const QList<FolderNode*> &list)
{
Node *n = ProjectExplorerPlugin::currentNode();
while (n) {
if (FolderNode *fn = qobject_cast<FolderNode *>(n)) {
if (list.contains(fn)) {
ProjectNode *pn = n->projectNode();
// Make sure the node we are switching too isn't going to be removed also
while (list.contains(pn))
pn = pn->parentFolderNode()->projectNode();
ProjectExplorerPlugin::setCurrentNode(pn);
break;
}
}
n = n->parentFolderNode();
}
}
void ProjectExplorerPlugin::filesAboutToBeRemoved(FolderNode *, const QList<FileNode*> &list)
{
if (FileNode *fileNode = qobject_cast<FileNode *>(ProjectExplorerPlugin::currentNode())) {
if (list.contains(fileNode))
ProjectExplorerPlugin::setCurrentNode(fileNode->projectNode());
}
}
void ProjectExplorerPluginPrivate::updateContextMenuActions()
{
m_addExistingFilesAction->setEnabled(false);
......
......@@ -54,6 +54,7 @@ class IRunControlFactory;
class Project;
class Node;
class FolderNode;
class FileNode;
namespace Internal { class ProjectExplorerSettings; }
......@@ -201,7 +202,10 @@ private slots:
void updateUnloadProjectMenu();
void openTerminalHere();
// for keeping current node / current project up to date
void invalidateProject(ProjectExplorer::Project *project);
void foldersAboutToBeRemoved(FolderNode *, const QList<FolderNode*> &);
void filesAboutToBeRemoved(FolderNode *, const QList<FileNode*> &);
void setCurrentFile(const QString &filePath);
......
......@@ -121,13 +121,6 @@ ProjectTreeWidget::ProjectTreeWidget(QWidget *parent)
Project *pro = SessionManager::startupProject();
if (pro)
m_model->setStartupProject(pro->rootProjectNode());
NodesWatcher *watcher = new NodesWatcher(this);
SessionManager::sessionNode()->registerWatcher(watcher);
connect(watcher, SIGNAL(foldersAboutToBeRemoved(FolderNode*,QList<FolderNode*>)),
this, SLOT(foldersAboutToBeRemoved(FolderNode*,QList<FolderNode*>)));
connect(watcher, SIGNAL(filesAboutToBeRemoved(FolderNode*,QList<FileNode*>)),
this, SLOT(filesAboutToBeRemoved(FolderNode*,QList<FileNode*>)));
m_view = new ProjectTreeView;
m_view->setModel(m_model);
......@@ -279,32 +272,6 @@ void ProjectTreeWidget::recursiveSaveExpandData(const QModelIndex &index, QStrin
}
}
void ProjectTreeWidget::foldersAboutToBeRemoved(FolderNode *, const QList<FolderNode*> &list)
{
Node *n = ProjectExplorerPlugin::currentNode();
while (n) {
if (FolderNode *fn = qobject_cast<FolderNode *>(n)) {
if (list.contains(fn)) {
ProjectNode *pn = n->projectNode();
// Make sure the node we are switching too isn't going to be removed also
while (list.contains(pn))
pn = pn->parentFolderNode()->projectNode();
ProjectExplorerPlugin::setCurrentNode(pn);
break;
}
}
n = n->parentFolderNode();
}
}
void ProjectTreeWidget::filesAboutToBeRemoved(FolderNode *, const QList<FileNode*> &list)
{
if (FileNode *fileNode = qobject_cast<FileNode *>(ProjectExplorerPlugin::currentNode())) {
if (list.contains(fileNode))
ProjectExplorerPlugin::setCurrentNode(fileNode->projectNode());
}
}
QToolButton *ProjectTreeWidget::toggleSync()
{
return m_toggleSync;
......
......@@ -80,9 +80,6 @@ private slots:
void startupProjectChanged(ProjectExplorer::Project *project);
void initView();
void foldersAboutToBeRemoved(FolderNode *, const QList<FolderNode*> &);
void filesAboutToBeRemoved(FolderNode *, const QList<FileNode*> &);
void loadExpandData();
void saveExpandData();
void disableAutoExpand();
......
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