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

feature: Adds tree view #223

Merged
merged 21 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Now we have sorting in tree mode
  • Loading branch information
ClementTsang committed Sep 6, 2020
commit e44c025f9d63ea6739e190cd6493dc1c07d1724b
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"haase",
"heim",
"hjkl",
"indexmap",
"libc",
"markdownlint",
"memb",
Expand Down
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ctrlc = {version = "3.1", features = ["termination"]}
clap = "2.33"
dirs = "3.0.1"
futures = "0.3.5"
indexmap = "1.6.0"
itertools = "0.9.0"
libc = "0.2"
regex = "1.3"
Expand Down
68 changes: 39 additions & 29 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,24 +266,27 @@ impl App {
.proc_state
.get_mut_widget_state(self.current_widget.widget_id)
{
// Toggles process widget grouping state
proc_widget_state.is_grouped = !(proc_widget_state.is_grouped);
// Do NOT allow when in tree mode!
if !proc_widget_state.is_tree_mode {
// Toggles process widget grouping state
proc_widget_state.is_grouped = !(proc_widget_state.is_grouped);

proc_widget_state
.columns
.column_mapping
.get_mut(&processes::ProcessSorting::State)
.unwrap()
.enabled = !(proc_widget_state.is_grouped);
proc_widget_state
.columns
.column_mapping
.get_mut(&processes::ProcessSorting::State)
.unwrap()
.enabled = !(proc_widget_state.is_grouped);

proc_widget_state
.columns
.toggle(&processes::ProcessSorting::Count);
proc_widget_state
.columns
.toggle(&processes::ProcessSorting::Pid);
proc_widget_state
.columns
.toggle(&processes::ProcessSorting::Count);
proc_widget_state
.columns
.toggle(&processes::ProcessSorting::Pid);

self.proc_state.force_update = Some(self.current_widget.widget_id);
self.proc_state.force_update = Some(self.current_widget.widget_id);
}
}
}
_ => {}
Expand Down Expand Up @@ -372,8 +375,8 @@ impl App {
};

if let Some(proc_widget_state) = self.proc_state.get_mut_widget_state(widget_id) {
proc_widget_state.process_sorting_reverse =
!proc_widget_state.process_sorting_reverse;
proc_widget_state.is_process_sort_descending =
!proc_widget_state.is_process_sort_descending;

self.proc_state.force_update = Some(widget_id);
}
Expand Down Expand Up @@ -478,6 +481,13 @@ impl App {
.get_mut(&(self.current_widget.widget_id))
{
proc_widget_state.is_tree_mode = !proc_widget_state.is_tree_mode;

if proc_widget_state.is_tree_mode {
// We enabled... set PID sort type to descending.
proc_widget_state.process_sorting_type = processes::ProcessSorting::Pid;
proc_widget_state.is_process_sort_descending = false;
}

self.proc_state.force_update = Some(self.current_widget.widget_id);
}
}
Expand Down Expand Up @@ -1068,13 +1078,13 @@ impl App {
{
match proc_widget_state.process_sorting_type {
processes::ProcessSorting::CpuPercent => {
proc_widget_state.process_sorting_reverse =
!proc_widget_state.process_sorting_reverse
proc_widget_state.is_process_sort_descending =
!proc_widget_state.is_process_sort_descending
}
_ => {
proc_widget_state.process_sorting_type =
processes::ProcessSorting::CpuPercent;
proc_widget_state.process_sorting_reverse = true;
proc_widget_state.is_process_sort_descending = true;
}
}
self.proc_state.force_update = Some(self.current_widget.widget_id);
Expand All @@ -1091,13 +1101,13 @@ impl App {
{
match proc_widget_state.process_sorting_type {
processes::ProcessSorting::MemPercent => {
proc_widget_state.process_sorting_reverse =
!proc_widget_state.process_sorting_reverse
proc_widget_state.is_process_sort_descending =
!proc_widget_state.is_process_sort_descending
}
_ => {
proc_widget_state.process_sorting_type =
processes::ProcessSorting::MemPercent;
proc_widget_state.process_sorting_reverse = true;
proc_widget_state.is_process_sort_descending = true;
}
}
self.proc_state.force_update = Some(self.current_widget.widget_id);
Expand All @@ -1115,13 +1125,13 @@ impl App {
if !proc_widget_state.is_grouped {
match proc_widget_state.process_sorting_type {
processes::ProcessSorting::Pid => {
proc_widget_state.process_sorting_reverse =
!proc_widget_state.process_sorting_reverse
proc_widget_state.is_process_sort_descending =
!proc_widget_state.is_process_sort_descending
}
_ => {
proc_widget_state.process_sorting_type =
processes::ProcessSorting::Pid;
proc_widget_state.process_sorting_reverse = false;
proc_widget_state.is_process_sort_descending = false;
}
}
self.proc_state.force_update = Some(self.current_widget.widget_id);
Expand Down Expand Up @@ -1167,8 +1177,8 @@ impl App {
match proc_widget_state.process_sorting_type {
processes::ProcessSorting::ProcessName
| processes::ProcessSorting::Command => {
proc_widget_state.process_sorting_reverse =
!proc_widget_state.process_sorting_reverse
proc_widget_state.is_process_sort_descending =
!proc_widget_state.is_process_sort_descending
}
_ => {
proc_widget_state.process_sorting_type =
Expand All @@ -1177,7 +1187,7 @@ impl App {
} else {
processes::ProcessSorting::ProcessName
};
proc_widget_state.process_sorting_reverse = false;
proc_widget_state.is_process_sort_descending = false;
}
}
self.proc_state.force_update = Some(self.current_widget.widget_id);
Expand Down
8 changes: 4 additions & 4 deletions src/app/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ pub struct ProcWidgetState {
pub is_grouped: bool,
pub scroll_state: AppScrollWidgetState,
pub process_sorting_type: processes::ProcessSorting,
pub process_sorting_reverse: bool,
pub is_process_sort_descending: bool,
pub is_using_command: bool,
pub current_column_index: usize,
pub is_sort_open: bool,
Expand Down Expand Up @@ -391,7 +391,7 @@ impl ProcWidgetState {
is_grouped,
scroll_state: AppScrollWidgetState::default(),
process_sorting_type,
process_sorting_reverse: true,
is_process_sort_descending: true,
is_using_command: false,
current_column_index: 0,
is_sort_open: false,
Expand Down Expand Up @@ -424,7 +424,7 @@ impl ProcWidgetState {
if let Some(new_sort_type) = self.columns.ordered_columns.get(true_index) {
if *new_sort_type == self.process_sorting_type {
// Just reverse the search if we're reselecting!
self.process_sorting_reverse = !(self.process_sorting_reverse);
self.is_process_sort_descending = !(self.is_process_sort_descending);
} else {
self.process_sorting_type = new_sort_type.clone();
match self.process_sorting_type {
Expand All @@ -433,7 +433,7 @@ impl ProcWidgetState {
| ProcessSorting::ProcessName
| ProcessSorting::Command => {
// Also invert anything that uses alphabetical sorting by default.
self.process_sorting_reverse = false;
self.is_process_sort_descending = false;
}
_ => {}
}
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/widgets/process_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl ProcessTableWidget for Painter {

let process_headers = proc_widget_state.columns.get_column_headers(
&proc_widget_state.process_sorting_type,
proc_widget_state.process_sorting_reverse,
proc_widget_state.is_process_sort_descending,
);

let process_headers_lens: Vec<usize> = process_headers
Expand Down
Loading