Commit e97e566e authored by Daniel Teske's avatar Daniel Teske
Browse files

ProjectExplorer: Unload project show all projects



If there are multiple projects, show a menu listing all projects.

Task-number: QTCREATORBUG-12857
Change-Id: Ie96eaec88235dc528170360ea374ac8ebac8db13
Reviewed-by: default avatarAllan Sandfeld Jensen <allan.jensen@digia.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 519aed8f
...@@ -734,6 +734,14 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er ...@@ -734,6 +734,14 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
cmd->setDescription(d->m_unloadAction->text()); cmd->setDescription(d->m_unloadAction->text());
mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT); mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);
ActionContainer *munload =
ActionManager::createMenu(Constants::M_UNLOADPROJECTS);
munload->menu()->setTitle(tr("Close Project"));
munload->setOnAllDisabledBehavior(ActionContainer::Show);
mfile->addMenu(munload, Core::Constants::G_FILE_PROJECT);
connect(mfile->menu(), SIGNAL(aboutToShow()),
this, SLOT(updateUnloadProjectMenu()));
// unload session action // unload session action
d->m_closeAllProjects = new QAction(tr("Close All Projects and Editors"), this); d->m_closeAllProjects = new QAction(tr("Close All Projects and Editors"), this);
cmd = ActionManager::registerAction(d->m_closeAllProjects, Constants::CLEARSESSION, globalcontext); cmd = ActionManager::registerAction(d->m_closeAllProjects, Constants::CLEARSESSION, globalcontext);
...@@ -1209,13 +1217,18 @@ void ProjectExplorerPlugin::unloadProject() ...@@ -1209,13 +1217,18 @@ void ProjectExplorerPlugin::unloadProject()
if (debug) if (debug)
qDebug() << "ProjectExplorerPlugin::unloadProject"; qDebug() << "ProjectExplorerPlugin::unloadProject";
if (BuildManager::isBuilding(d->m_currentProject)) { unloadProject(d->m_currentProject);
}
void ProjectExplorerPlugin::unloadProject(Project *project)
{
if (BuildManager::isBuilding(project)) {
QMessageBox box; QMessageBox box;
QPushButton *closeAnyway = box.addButton(tr("Cancel Build && Unload"), QMessageBox::AcceptRole); QPushButton *closeAnyway = box.addButton(tr("Cancel Build && Unload"), QMessageBox::AcceptRole);
QPushButton *cancelClose = box.addButton(tr("Do Not Unload"), QMessageBox::RejectRole); QPushButton *cancelClose = box.addButton(tr("Do Not Unload"), QMessageBox::RejectRole);
box.setDefaultButton(cancelClose); box.setDefaultButton(cancelClose);
box.setWindowTitle(tr("Unload Project %1?").arg(d->m_currentProject->displayName())); box.setWindowTitle(tr("Unload Project %1?").arg(project->displayName()));
box.setText(tr("The project %1 is currently being built.").arg(d->m_currentProject->displayName())); box.setText(tr("The project %1 is currently being built.").arg(project->displayName()));
box.setInformativeText(tr("Do you want to cancel the build process and unload the project anyway?")); box.setInformativeText(tr("Do you want to cancel the build process and unload the project anyway?"));
box.exec(); box.exec();
if (box.clickedButton() != closeAnyway) if (box.clickedButton() != closeAnyway)
...@@ -1223,7 +1236,7 @@ void ProjectExplorerPlugin::unloadProject() ...@@ -1223,7 +1236,7 @@ void ProjectExplorerPlugin::unloadProject()
BuildManager::cancel(); BuildManager::cancel();
} }
IDocument *document = d->m_currentProject->document(); IDocument *document = project->document();
if (!document || document->filePath().isEmpty()) //nothing to save? if (!document || document->filePath().isEmpty()) //nothing to save?
return; return;
...@@ -1231,12 +1244,8 @@ void ProjectExplorerPlugin::unloadProject() ...@@ -1231,12 +1244,8 @@ void ProjectExplorerPlugin::unloadProject()
if (!DocumentManager::saveModifiedDocumentSilently(document)) if (!DocumentManager::saveModifiedDocumentSilently(document))
return; return;
addToRecentProjects(document->filePath(), d->m_currentProject->displayName()); addToRecentProjects(document->filePath(), project->displayName());
unloadProject(d->m_currentProject);
}
void ProjectExplorerPlugin::unloadProject(Project *project)
{
SessionManager::removeProject(project); SessionManager::removeProject(project);
updateActions(); updateActions();
} }
...@@ -2060,6 +2069,11 @@ void ProjectExplorerPlugin::updateActions() ...@@ -2060,6 +2069,11 @@ void ProjectExplorerPlugin::updateActions()
// Session actions // Session actions
d->m_closeAllProjects->setEnabled(SessionManager::hasProjects()); d->m_closeAllProjects->setEnabled(SessionManager::hasProjects());
d->m_unloadAction->setVisible(SessionManager::projects().size() <= 1);
ActionContainer *aci =
ActionManager::actionContainer(Constants::M_UNLOADPROJECTS);
aci->menu()->menuAction()->setVisible(SessionManager::projects().size() > 1);
d->m_buildSessionAction->setEnabled(buildSessionState.first); d->m_buildSessionAction->setEnabled(buildSessionState.first);
d->m_rebuildSessionAction->setEnabled(buildSessionState.first); d->m_rebuildSessionAction->setEnabled(buildSessionState.first);
...@@ -2721,6 +2735,18 @@ void ProjectExplorerPlugin::addToRecentProjects(const QString &fileName, const Q ...@@ -2721,6 +2735,18 @@ void ProjectExplorerPlugin::addToRecentProjects(const QString &fileName, const Q
emit recentProjectsChanged(); emit recentProjectsChanged();
} }
void ProjectExplorerPlugin::updateUnloadProjectMenu()
{
ActionContainer *aci = ActionManager::actionContainer(Constants::M_UNLOADPROJECTS);
QMenu *menu = aci->menu();
menu->clear();
foreach (Project *project, SessionManager::projects()) {
QAction *action = menu->addAction(tr("Close Project \"%1\"").arg(project->displayName()));
connect(action, &QAction::triggered,
this, [project, this](){ unloadProject(project); } );
}
}
void ProjectExplorerPlugin::updateRecentProjectMenu() void ProjectExplorerPlugin::updateRecentProjectMenu()
{ {
typedef QList<QPair<QString, QString> >::const_iterator StringPairListConstIterator; typedef QList<QPair<QString, QString> >::const_iterator StringPairListConstIterator;
......
...@@ -205,6 +205,7 @@ private slots: ...@@ -205,6 +205,7 @@ private slots:
void updateRecentProjectMenu(); void updateRecentProjectMenu();
void clearRecentProjects(); void clearRecentProjects();
void openRecentProject(); void openRecentProject();
void updateUnloadProjectMenu();
void openTerminalHere(); void openTerminalHere();
void invalidateProject(ProjectExplorer::Project *project); void invalidateProject(ProjectExplorer::Project *project);
......
...@@ -101,6 +101,7 @@ const char LANG_QMLJS[] = "QMLJS"; ...@@ -101,6 +101,7 @@ const char LANG_QMLJS[] = "QMLJS";
// Menus // Menus
const char M_RECENTPROJECTS[] = "ProjectExplorer.Menu.Recent"; const char M_RECENTPROJECTS[] = "ProjectExplorer.Menu.Recent";
const char M_UNLOADPROJECTS[] = "ProjectExplorer.Menu.Unload";
const char M_BUILDPROJECT[] = "ProjectExplorer.Menu.Build"; const char M_BUILDPROJECT[] = "ProjectExplorer.Menu.Build";
const char M_DEBUG[] = "ProjectExplorer.Menu.Debug"; const char M_DEBUG[] = "ProjectExplorer.Menu.Debug";
const char M_DEBUG_STARTDEBUGGING[] = "ProjectExplorer.Menu.Debug.StartDebugging"; const char M_DEBUG_STARTDEBUGGING[] = "ProjectExplorer.Menu.Debug.StartDebugging";
......
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