ProjectExplorer: Allow users to quickly expand the project tree

... by adding an "Expand All" action to accompany the existing "Collapse
All" one.

Fixes: QTCREATORBUG-17243
Change-Id: I84e185562ee4c62ede7d0dc40f0d296020c4f0ea
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2019-01-16 13:12:12 +01:00
parent 0679c2ff25
commit 29e20e369b
5 changed files with 32 additions and 14 deletions

View File

@@ -217,6 +217,7 @@ const char DELETEFILE[] = "ProjectExplorer.DeleteFile";
const char DIFFFILE[] = "ProjectExplorer.DiffFile";
const char SETSTARTUP[] = "ProjectExplorer.SetStartup";
const char PROJECTTREE_COLLAPSE_ALL[] = "ProjectExplorer.CollapseAll";
const char PROJECTTREE_EXPAND_ALL[] = "ProjectExplorer.ExpandAll";
const char SELECTTARGET[] = "ProjectExplorer.SelectTarget";
const char SELECTTARGETQUICK[] = "ProjectExplorer.SelectTargetQuick";
@@ -439,6 +440,7 @@ public:
QAction *m_diffFileAction;
QAction *m_openFileAction;
QAction *m_projectTreeCollapseAllAction;
QAction *m_projectTreeExpandAllAction;
QAction *m_searchOnFileSystem;
QAction *m_showInGraphicalShell;
QAction *m_openTerminalHere;
@@ -1197,21 +1199,22 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
cmd->setDescription(dd->m_setStartupProjectAction->text());
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_FIRST);
// Collapse All.
dd->m_projectTreeCollapseAllAction = new QAction(tr("Collapse All"), this);
cmd = ActionManager::registerAction(dd->m_projectTreeCollapseAllAction, Constants::PROJECTTREE_COLLAPSE_ALL,
projecTreeContext);
// Collapse & Expand.
const Id treeGroup = Constants::G_PROJECT_TREE;
mfileContextMenu->addSeparator(treeGroup);
mfileContextMenu->addAction(cmd, treeGroup);
msubProjectContextMenu->addSeparator(treeGroup);
msubProjectContextMenu->addAction(cmd, treeGroup);
mfolderContextMenu->addSeparator(treeGroup);
mfolderContextMenu->addAction(cmd, treeGroup);
mprojectContextMenu->addSeparator(treeGroup);
mprojectContextMenu->addAction(cmd, treeGroup);
msessionContextMenu->addSeparator(treeGroup);
msessionContextMenu->addAction(cmd, treeGroup);
dd->m_projectTreeCollapseAllAction = new QAction(tr("Collapse All"), this);
Command * const collapseCmd = ActionManager::registerAction(
dd->m_projectTreeCollapseAllAction, Constants::PROJECTTREE_COLLAPSE_ALL,
projecTreeContext);
dd->m_projectTreeExpandAllAction = new QAction(tr("Expand All"), this);
Command * const expandCmd = ActionManager::registerAction(
dd->m_projectTreeExpandAllAction, Constants::PROJECTTREE_EXPAND_ALL,
projecTreeContext);
for (Core::ActionContainer * const ac : {mfileContextMenu, msubProjectContextMenu,
mfolderContextMenu, mprojectContextMenu, msessionContextMenu}) {
ac->addSeparator(treeGroup);
ac->addAction(collapseCmd, treeGroup);
ac->addAction(expandCmd, treeGroup);
}
// target selector
dd->m_projectSelectorAction = new QAction(this);
@@ -1441,6 +1444,8 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
dd, &ProjectExplorerPluginPrivate::handleSetStartupProject);
connect(dd->m_projectTreeCollapseAllAction, &QAction::triggered,
ProjectTree::instance(), &ProjectTree::collapseAll);
connect(dd->m_projectTreeExpandAllAction, &QAction::triggered,
ProjectTree::instance(), &ProjectTree::expandAll);
connect(this, &ProjectExplorerPlugin::updateRunActions,
dd, &ProjectExplorerPluginPrivate::slotUpdateRunActions);

View File

@@ -277,6 +277,12 @@ void ProjectTree::collapseAll()
w->collapseAll();
}
void ProjectTree::expandAll()
{
if (auto w = Utils::findOrDefault(s_instance->m_projectTreeWidgets, &ProjectTree::hasFocus))
w->expandAll();
}
void ProjectTree::updateExternalFileWarning()
{
auto document = qobject_cast<Core::IDocument *>(sender());

View File

@@ -79,6 +79,7 @@ public:
static Node *nodeForFile(const Utils::FileName &fileName);
void collapseAll();
void expandAll();
// for nodes to emit signals, do not call unless you are a node
static void emitSubtreeChanged(FolderNode *node);

View File

@@ -413,6 +413,11 @@ void ProjectTreeWidget::collapseAll()
m_view->collapseAll();
}
void ProjectTreeWidget::expandAll()
{
m_view->expandAll();
}
void ProjectTreeWidget::editCurrentItem()
{
m_delayedRename.clear();

View File

@@ -66,6 +66,7 @@ public:
void toggleAutoSynchronization();
void editCurrentItem();
void collapseAll();
void expandAll();
private:
void setProjectFilter(bool filter);