From da97d2625aeb9cad57657ed9cc076b558f30921d Mon Sep 17 00:00:00 2001 From: Denis Lisov Date: Fri, 20 May 2022 23:57:36 +0300 Subject: [PATCH 1/2] ProcessList_collapseAllBranches: actually build tree As the loop checks `tree_depth`, a tree build is needed to ensure they're filled in correctly. Note that this breaks the display list sort order in case it's non-tree-based (either startup in flat mode, or `*` hotkey in flat mode), so the display list will need to be sorted again. --- ProcessList.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ProcessList.c b/ProcessList.c index f71619f6..2fad32b7 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -353,7 +353,10 @@ void ProcessList_expandTree(ProcessList* this) { } } +// Called on collapse-all toggle and on startup, possibly in non-tree mode void ProcessList_collapseAllBranches(ProcessList* this) { + ProcessList_buildTree(this); // Update `tree_depth` fields of the processes + this->needsSort = true; // ProcessList is sorted by parent now, force new sort int size = Vector_size(this->processes); for (int i = 0; i < size; i++) { Process* process = (Process*) Vector_get(this->processes, i); From 17e28d5264c34075bdd4b5ebf2b7c0efb892ce2f Mon Sep 17 00:00:00 2001 From: Denis Lisov Date: Sat, 21 May 2022 00:06:36 +0300 Subject: [PATCH 2/2] actionExpandOrCollapseAllBranches: NOP in flat mode This shortcut does not have any visible effect in flat mode, so disable it completely to avoid possible confusion. --- Action.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Action.c b/Action.c index cb132b4a..9e3b94b3 100644 --- a/Action.c +++ b/Action.c @@ -242,6 +242,9 @@ static Htop_Reaction actionToggleTreeView(State* st) { static Htop_Reaction actionExpandOrCollapseAllBranches(State* st) { ScreenSettings* ss = st->settings->ss; + if (!ss->treeView) { + return HTOP_OK; + } ss->allBranchesCollapsed = !ss->allBranchesCollapsed; if (ss->allBranchesCollapsed) ProcessList_collapseAllBranches(st->pl);