diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2021-02-19 01:02:21 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-19 01:02:21 -0500 |
commit | e6c9187928d49b796b7d8a2302c057e229d68805 (patch) | |
tree | a938a1ac19cfac23e5a7b4deabf765df2adcf61a | |
parent | e6230ef156efe907f2cf76af4298a7e34df330b4 (diff) |
bug: Fix sorting menu and sort shortcuts not syncing in gui (#417)
Fixes sorting menus and shortcuts not syncing correctly if the sorting window is open.
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | src/app.rs | 89 | ||||
-rw-r--r-- | src/app/states.rs | 4 |
3 files changed, 33 insertions, 62 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index b6a12b28..0030c1a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#416](https://github.com/ClementTsang/bottom/pull/416): Fixes grouped vs ungrouped modes in the processes widget having inconsistent spacing. +- [#417](https://github.com/ClementTsang/bottom/pull/417): Fixes the sort menu and sort shortcuts not syncing up. + ## [0.5.7] - 2021-01-30 ## Bug Fixes @@ -700,8 +700,8 @@ impl App { .widget_states .get_mut(&(self.current_widget.widget_id - 2)) { - self.proc_state.force_update = Some(self.current_widget.widget_id - 2); proc_widget_state.update_sorting_with_columns(); + self.proc_state.force_update = Some(self.current_widget.widget_id - 2); self.toggle_sort(); } } @@ -1473,25 +1473,15 @@ impl App { } 'c' => { if let BottomWidgetType::Proc = self.current_widget.widget_type { - // FIXME: There's a mismatch bug with this and all sorting types when using the keybind vs the sorting menu. - // If the sorting menu is open, it won't update when using this! if let Some(proc_widget_state) = self .proc_state .get_mut_widget_state(self.current_widget.widget_id) { - match proc_widget_state.process_sorting_type { - processes::ProcessSorting::CpuPercent => { - 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.is_process_sort_descending = true; - } - } + proc_widget_state + .columns + .set_to_sorted_index_from_type(&processes::ProcessSorting::CpuPercent); + proc_widget_state.update_sorting_with_columns(); self.proc_state.force_update = Some(self.current_widget.widget_id); - self.skip_to_first(); } } @@ -1502,25 +1492,17 @@ impl App { .proc_state .get_mut_widget_state(self.current_widget.widget_id) { - match proc_widget_state.process_sorting_type { - processes::ProcessSorting::MemPercent - | processes::ProcessSorting::Mem => { - proc_widget_state.is_process_sort_descending = - !proc_widget_state.is_process_sort_descending - } - - _ => { - proc_widget_state.process_sorting_type = if proc_widget_state - .columns - .is_enabled(&processes::ProcessSorting::MemPercent) - { - processes::ProcessSorting::MemPercent - } else { - processes::ProcessSorting::Mem - }; - proc_widget_state.is_process_sort_descending = true; - } - } + proc_widget_state.columns.set_to_sorted_index_from_type( + &(if proc_widget_state + .columns + .is_enabled(&processes::ProcessSorting::MemPercent) + { + processes::ProcessSorting::MemPercent + } else { + processes::ProcessSorting::Mem + }), + ); + proc_widget_state.update_sorting_with_columns(); self.proc_state.force_update = Some(self.current_widget.widget_id); self.skip_to_first(); } @@ -1534,17 +1516,10 @@ impl App { { // Skip if grouped if !proc_widget_state.is_grouped { - match proc_widget_state.process_sorting_type { - processes::ProcessSorting::Pid => { - 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.is_process_sort_descending = false; - } - } + proc_widget_state + .columns + .set_to_sorted_index_from_type(&processes::ProcessSorting::Pid); + proc_widget_state.update_sorting_with_columns(); self.proc_state.force_update = Some(self.current_widget.widget_id); self.skip_to_first(); } @@ -1585,22 +1560,14 @@ impl App { .proc_state .get_mut_widget_state(self.current_widget.widget_id) { - match proc_widget_state.process_sorting_type { - processes::ProcessSorting::ProcessName - | processes::ProcessSorting::Command => { - proc_widget_state.is_process_sort_descending = - !proc_widget_state.is_process_sort_descending - } - _ => { - proc_widget_state.process_sorting_type = - if proc_widget_state.is_using_command { - processes::ProcessSorting::Command - } else { - processes::ProcessSorting::ProcessName - }; - proc_widget_state.is_process_sort_descending = false; - } - } + proc_widget_state.columns.set_to_sorted_index_from_type( + &(if proc_widget_state.is_using_command { + processes::ProcessSorting::Command + } else { + processes::ProcessSorting::ProcessName + }), + ); + proc_widget_state.update_sorting_with_columns(); self.proc_state.force_update = Some(self.current_widget.widget_id); self.skip_to_first(); } diff --git a/src/app/states.rs b/src/app/states.rs index 37fbd8d1..c2853337 100644 --- a/src/app/states.rs +++ b/src/app/states.rs @@ -507,7 +507,9 @@ impl ProcWidgetState { // Also invert anything that uses alphabetical sorting by default. self.is_process_sort_descending = false; } - _ => {} + _ => { + self.is_process_sort_descending = true; + } } } } |