Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve proc tree expand/collapse functionality #1306

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/usage/widgets/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Pressing ++t++ or ++f5++ in the table toggles tree mode in the process widget, d
<img src="../../../assets/screenshots/process/process_tree.webp" alt="A picture of tree mode in a process widget."/>
</figure>

A process in tree mode can also be "collapsed", hiding its children and any descendants, using either the ++minus++ or ++plus++ keys, or double clicking on an entry.
A process in tree mode can also be "collapsed", hiding its children and any descendants, using either the ++minus++ or ++Left++ keys, or clicking on an entry. To expand, use the ++plus++ or ++Right++ keys, or click on the entry again.

Lastly, note that in tree mode, processes cannot be grouped together due to the behaviour of the two modes somewhat clashing.

Expand Down
16 changes: 11 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,9 @@ impl App {
}
}
}
BottomWidgetType::Proc => {
self.toggle_collapsing_process_branch(Some(false));
}
_ => {}
}
} else if self.delete_dialog_state.is_showing_dd {
Expand Down Expand Up @@ -769,6 +772,9 @@ impl App {
}
}
}
BottomWidgetType::Proc => {
self.toggle_collapsing_process_branch(Some(true));
}
_ => {}
}
} else if self.delete_dialog_state.is_showing_dd {
Expand Down Expand Up @@ -2138,7 +2144,7 @@ impl App {
fn on_plus(&mut self) {
if let BottomWidgetType::Proc = self.current_widget.widget_type {
// Toggle collapsing if tree
self.toggle_collapsing_process_branch();
self.toggle_collapsing_process_branch(Some(true));
} else {
self.zoom_in();
}
Expand All @@ -2147,20 +2153,20 @@ impl App {
fn on_minus(&mut self) {
if let BottomWidgetType::Proc = self.current_widget.widget_type {
// Toggle collapsing if tree
self.toggle_collapsing_process_branch();
self.toggle_collapsing_process_branch(Some(false));
} else {
self.zoom_out();
}
}

fn toggle_collapsing_process_branch(&mut self) {
fn toggle_collapsing_process_branch(&mut self, force_expand: Option<bool>) {
if let Some(pws) = self
.states
.proc_state
.widget_states
.get_mut(&self.current_widget.widget_id)
{
pws.toggle_current_tree_branch_entry();
pws.toggle_current_tree_branch_entry(force_expand);
}
}

Expand Down Expand Up @@ -2579,7 +2585,7 @@ impl App {
// the same entry as the already selected one - if it is,
// then we minimize.
if is_tree_mode && change == 0 {
self.toggle_collapsing_process_branch();
self.toggle_collapsing_process_branch(None);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/data_harvester/disks/unix/linux/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl FromStr for Partition {
let mut parts = line.splitn(5, ' ');

let device = match parts.next() {
Some(device) if device == "none" => None,
Some("none") => None,
Some(device) => Some(device.to_string()),
None => {
bail!("missing device");
Expand Down
5 changes: 3 additions & 2 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ pub const CPU_HELP_TEXT: [&str; 2] = [
"Mouse scroll Scrolling over an CPU core/average shows only that entry on the chart",
];

pub const PROCESS_HELP_TEXT: [&str; 15] = [
pub const PROCESS_HELP_TEXT: [&str; 16] = [
"3 - Process widget",
"dd, F9 Kill the selected process",
"c Sort by CPU usage, press again to reverse",
Expand All @@ -341,7 +341,8 @@ pub const PROCESS_HELP_TEXT: [&str; 15] = [
"I Invert current sort",
"% Toggle between values and percentages for memory usage",
"t, F5 Toggle tree mode",
"+, -, click Collapse/expand a branch while in tree mode",
"-, Left, click Collapse a branch while in tree mode",
"+, Right, click Expand a branch while in tree mode",
"click on header Sorts the entries by that column, click again to invert the sort",
];

Expand Down
22 changes: 18 additions & 4 deletions src/widgets/process_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,15 +794,29 @@ impl ProcWidgetState {
}
}

pub fn toggle_current_tree_branch_entry(&mut self) {
/// Change the state of a tree branch:
/// None - toggle the branch between collapsed and expanded
/// Some(true) - expand the branch, or do nothing if it's already expanded
/// Some(false) - collapse the branch, or do nothing if it's already collapsed
pub fn toggle_current_tree_branch_entry(&mut self, force_expand: Option<bool>) {
if let ProcWidgetMode::Tree { collapsed_pids } = &mut self.mode {
if let Some(process) = self.table.current_item() {
let pid = process.pid;

if !collapsed_pids.remove(&pid) {
collapsed_pids.insert(pid);
let refresh = match force_expand {
Some(true) => collapsed_pids.remove(&pid),
Some(false) => collapsed_pids.insert(pid),
None => {
if !collapsed_pids.remove(&pid) {
collapsed_pids.insert(pid);
}
true
}
};

if refresh {
self.force_data_update();
}
self.force_data_update();
}
}
}
Expand Down