forked from qt-creator/qt-creator
ProjectExplorer: Allow to close all files in a project
[ChangeLog] Users can now close all open files of a specific project Fixes: QTCREATORBUG-15593 Change-Id: Icb755511ae682042433030c33671a214c448b8be Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -110,6 +110,7 @@
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/editormanager/documentmodel.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/findplaceholder.h>
|
||||
#include <coreplugin/vcsmanager.h>
|
||||
@@ -360,6 +361,7 @@ public:
|
||||
void handleRenameFile();
|
||||
void handleSetStartupProject();
|
||||
void setStartupProject(ProjectExplorer::Project *project);
|
||||
void closeAllFilesInProject(const Project *project);
|
||||
|
||||
void updateRecentProjectMenu();
|
||||
void clearRecentProjects();
|
||||
@@ -441,6 +443,8 @@ public:
|
||||
QAction *m_openFileAction;
|
||||
QAction *m_projectTreeCollapseAllAction;
|
||||
QAction *m_projectTreeExpandAllAction;
|
||||
Utils::ParameterAction *m_closeProjectFilesActionFileMenu;
|
||||
Utils::ParameterAction *m_closeProjectFilesActionContextMenu;
|
||||
QAction *m_searchOnFileSystem;
|
||||
QAction *m_showInGraphicalShell;
|
||||
QAction *m_openTerminalHere;
|
||||
@@ -933,6 +937,15 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
cmd->setDescription(dd->m_unloadAction->text());
|
||||
mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);
|
||||
|
||||
dd->m_closeProjectFilesActionFileMenu = new Utils::ParameterAction(
|
||||
tr("Close All Files in Project"), tr("Close All Files in Project \"%1\""),
|
||||
Utils::ParameterAction::AlwaysEnabled, this);
|
||||
cmd = ActionManager::registerAction(dd->m_closeProjectFilesActionFileMenu,
|
||||
"ProjectExplorer.CloseProjectFilesFileMenu");
|
||||
cmd->setAttribute(Command::CA_UpdateText);
|
||||
cmd->setDescription(dd->m_closeProjectFilesActionFileMenu->text());
|
||||
mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);
|
||||
|
||||
ActionContainer *munload =
|
||||
ActionManager::createMenu(Constants::M_UNLOADPROJECTS);
|
||||
munload->menu()->setTitle(tr("Close Pro&ject"));
|
||||
@@ -1140,6 +1153,15 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
cmd->setDescription(dd->m_unloadActionContextMenu->text());
|
||||
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST);
|
||||
|
||||
dd->m_closeProjectFilesActionContextMenu = new Utils::ParameterAction(
|
||||
tr("Close All Files"), tr("Close All Files in Project \"%1\""),
|
||||
Utils::ParameterAction::EnabledWithParameter, this);
|
||||
cmd = ActionManager::registerAction(dd->m_closeProjectFilesActionContextMenu,
|
||||
"ProjectExplorer.CloseAllFilesInProjectContextMenu");
|
||||
cmd->setAttribute(Command::CA_UpdateText);
|
||||
cmd->setDescription(dd->m_closeProjectFilesActionContextMenu->text());
|
||||
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST);
|
||||
|
||||
// file properties action
|
||||
dd->m_filePropertiesAction = new QAction(tr("Properties..."), this);
|
||||
cmd = ActionManager::registerAction(dd->m_filePropertiesAction, Constants::FILEPROPERTIES,
|
||||
@@ -1442,6 +1464,10 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
dd, &ProjectExplorerPluginPrivate::handleRenameFile);
|
||||
connect(dd->m_setStartupProjectAction, &QAction::triggered,
|
||||
dd, &ProjectExplorerPluginPrivate::handleSetStartupProject);
|
||||
connect(dd->m_closeProjectFilesActionFileMenu, &QAction::triggered,
|
||||
dd, [] { dd->closeAllFilesInProject(SessionManager::projects().first()); });
|
||||
connect(dd->m_closeProjectFilesActionContextMenu, &QAction::triggered,
|
||||
dd, [] { dd->closeAllFilesInProject(ProjectTree::currentProject()); });
|
||||
connect(dd->m_projectTreeCollapseAllAction, &QAction::triggered,
|
||||
ProjectTree::instance(), &ProjectTree::collapseAll);
|
||||
connect(dd->m_projectTreeExpandAllAction, &QAction::triggered,
|
||||
@@ -1824,6 +1850,26 @@ void ProjectExplorerPluginPrivate::setStartupProject(Project *project)
|
||||
updateActions();
|
||||
}
|
||||
|
||||
void ProjectExplorerPluginPrivate::closeAllFilesInProject(const Project *project)
|
||||
{
|
||||
QTC_ASSERT(project, return);
|
||||
const Utils::FileNameList filesInProject = project->files(Project::AllFiles);
|
||||
QList<IDocument *> openFiles = DocumentModel::openedDocuments();
|
||||
Utils::erase(openFiles, [filesInProject](const IDocument *doc) {
|
||||
return !filesInProject.contains(doc->filePath());
|
||||
});
|
||||
for (const Project * const otherProject : SessionManager::projects()) {
|
||||
if (otherProject == project)
|
||||
continue;
|
||||
const Utils::FileNameList filesInOtherProject
|
||||
= otherProject->files(Project::AllFiles);
|
||||
Utils::erase(openFiles, [filesInOtherProject](const IDocument *doc) {
|
||||
return filesInOtherProject.contains(doc->filePath());
|
||||
});
|
||||
}
|
||||
EditorManager::closeDocuments(openFiles);
|
||||
}
|
||||
|
||||
void ProjectExplorerPluginPrivate::savePersistentSettings()
|
||||
{
|
||||
if (dd->m_shuttingDown)
|
||||
@@ -2332,6 +2378,8 @@ void ProjectExplorerPluginPrivate::updateActions()
|
||||
|
||||
m_unloadAction->setParameter(projectName);
|
||||
m_unloadActionContextMenu->setParameter(projectNameContextMenu);
|
||||
m_closeProjectFilesActionFileMenu->setParameter(projectName);
|
||||
m_closeProjectFilesActionContextMenu->setParameter(projectNameContextMenu);
|
||||
|
||||
// mode bar build action
|
||||
QAction * const buildAction = ActionManager::command(Constants::BUILD)->action();
|
||||
@@ -2390,6 +2438,9 @@ void ProjectExplorerPluginPrivate::updateActions()
|
||||
m_unloadAction->setVisible(SessionManager::projects().size() <= 1);
|
||||
m_unloadAction->setEnabled(SessionManager::projects().size() == 1);
|
||||
m_unloadActionContextMenu->setEnabled(SessionManager::hasProjects());
|
||||
m_closeProjectFilesActionFileMenu->setVisible(SessionManager::projects().size() <= 1);
|
||||
m_closeProjectFilesActionFileMenu->setEnabled(SessionManager::projects().size() == 1);
|
||||
m_closeProjectFilesActionContextMenu->setEnabled(SessionManager::hasProjects());
|
||||
|
||||
ActionContainer *aci =
|
||||
ActionManager::actionContainer(Constants::M_UNLOADPROJECTS);
|
||||
|
Reference in New Issue
Block a user