diff options
author | ClementTsang <cjhtsang@uwaterloo.ca> | 2021-09-05 19:02:50 -0400 |
---|---|---|
committer | ClementTsang <cjhtsang@uwaterloo.ca> | 2021-09-05 19:09:11 -0400 |
commit | 18af6b01bf9c19a67deece57212b4c366d65ca16 (patch) | |
tree | 03dfebac676cb74bbb61c1e0e4ae47ed9397c8d7 /src/app.rs | |
parent | fa00dec1460b8bc6b0c43a01c1e240536575ea5a (diff) |
refactor: delete a bunch of old unused code
Diffstat (limited to 'src/app.rs')
-rw-r--r-- | src/app.rs | 513 |
1 files changed, 2 insertions, 511 deletions
@@ -2300,87 +2300,7 @@ impl AppState { } } - pub fn skip_to_last(&mut self) { - // if !self.ignore_normal_keybinds() { - // match self.current_widget.widget_type { - // BottomWidgetType::Proc => { - // if let Some(proc_widget_state) = self - // .proc_state - // .get_mut_widget_state(self.current_widget.widget_id) - // { - // if let Some(finalized_process_data) = self - // .canvas_data - // .finalized_process_data_map - // .get(&self.current_widget.widget_id) - // { - // if !self.canvas_data.finalized_process_data_map.is_empty() { - // proc_widget_state.scroll_state.current_scroll_position = - // finalized_process_data.len() - 1; - // proc_widget_state.scroll_state.scroll_direction = - // ScrollDirection::Down; - // } - // } - // } - // } - // BottomWidgetType::ProcSort => { - // if let Some(proc_widget_state) = self - // .proc_state - // .get_mut_widget_state(self.current_widget.widget_id - 2) - // { - // proc_widget_state.columns.current_scroll_position = - // proc_widget_state.columns.get_enabled_columns_len() - 1; - // proc_widget_state.columns.scroll_direction = ScrollDirection::Down; - // } - // } - // BottomWidgetType::Temp => { - // if let Some(temp_widget_state) = self - // .temp_state - // .get_mut_widget_state(self.current_widget.widget_id) - // { - // if !self.canvas_data.temp_sensor_data.is_empty() { - // temp_widget_state.scroll_state.current_scroll_position = - // self.canvas_data.temp_sensor_data.len() - 1; - // temp_widget_state.scroll_state.scroll_direction = ScrollDirection::Down; - // } - // } - // } - // BottomWidgetType::Disk => { - // if let Some(disk_widget_state) = self - // .disk_state - // .get_mut_widget_state(self.current_widget.widget_id) - // { - // if !self.canvas_data.disk_data.is_empty() { - // disk_widget_state.scroll_state.current_scroll_position = - // self.canvas_data.disk_data.len() - 1; - // disk_widget_state.scroll_state.scroll_direction = ScrollDirection::Down; - // } - // } - // } - // BottomWidgetType::CpuLegend => { - // if let Some(cpu_widget_state) = self - // .cpu_state - // .get_mut_widget_state(self.current_widget.widget_id - 1) - // { - // let cap = self.canvas_data.cpu_data.len(); - // if cap > 0 { - // cpu_widget_state.scroll_state.current_scroll_position = cap - 1; - // cpu_widget_state.scroll_state.scroll_direction = ScrollDirection::Down; - // } - // } - // } - // _ => {} - // } - // self.reset_multi_tap_keys(); - // } else if self.help_dialog_state.is_showing_help { - // self.help_dialog_state.scroll_state.current_scroll_index = self - // .help_dialog_state - // .scroll_state - // .max_scroll_index - // .saturating_sub(1); - // } else if self.delete_dialog_state.is_showing_dd { - // self.delete_dialog_state.selected_signal = KillSignal::Kill(MAX_SIGNAL); - // } - } + pub fn skip_to_last(&mut self) {} pub fn decrement_position_count(&mut self) { if !self.ignore_normal_keybinds() { @@ -2461,35 +2381,6 @@ impl AppState { /// Returns the new position. fn increment_process_position(&mut self, _num_to_change_by: i64) -> Option<usize> { - // if let Some(proc_widget_state) = self - // .proc_state - // .get_mut_widget_state(self.current_widget.widget_id) - // { - // let current_posn = proc_widget_state.scroll_state.current_scroll_position; - // if let Some(finalized_process_data) = self - // .canvas_data - // .finalized_process_data_map - // .get(&self.current_widget.widget_id) - // { - // if current_posn as i64 + num_to_change_by >= 0 - // && current_posn as i64 + num_to_change_by < finalized_process_data.len() as i64 - // { - // proc_widget_state.scroll_state.current_scroll_position = - // (current_posn as i64 + num_to_change_by) as usize; - // } else { - // return None; - // } - // } - - // if num_to_change_by < 0 { - // proc_widget_state.scroll_state.scroll_direction = ScrollDirection::Up; - // } else { - // proc_widget_state.scroll_state.scroll_direction = ScrollDirection::Down; - // } - - // return Some(proc_widget_state.scroll_state.current_scroll_position); - // } - None } @@ -2563,40 +2454,6 @@ impl AppState { } } - pub fn handle_scroll_up(&mut self) { - if self.delete_dialog_state.is_showing_dd { - #[cfg(target_family = "unix")] - { - self.on_up_key(); - return; - } - } - if self.help_dialog_state.is_showing_help { - self.help_scroll_up(); - } else if self.current_widget.widget_type.is_widget_graph() { - self.zoom_in(); - } else if self.current_widget.widget_type.is_widget_table() { - self.decrement_position_count(); - } - } - - pub fn handle_scroll_down(&mut self) { - if self.delete_dialog_state.is_showing_dd { - #[cfg(target_family = "unix")] - { - self.on_down_key(); - return; - } - } - if self.help_dialog_state.is_showing_help { - self.help_scroll_down(); - } else if self.current_widget.widget_type.is_widget_graph() { - self.zoom_out(); - } else if self.current_widget.widget_type.is_widget_table() { - self.increment_position_count(); - } - } - fn on_plus(&mut self) { if let BottomWidgetType::Proc = self.current_widget.widget_type { // Toggle collapsing if tree @@ -2615,34 +2472,7 @@ impl AppState { } } - fn toggle_collapsing_process_branch(&mut self) { - // if let Some(proc_widget_state) = self - // .proc_state - // .widget_states - // .get_mut(&self.current_widget.widget_id) - // { - // let current_posn = proc_widget_state.scroll_state.current_scroll_position; - - // if let Some(displayed_process_list) = self - // .canvas_data - // .finalized_process_data_map - // .get(&self.current_widget.widget_id) - // { - // if let Some(corresponding_process) = displayed_process_list.get(current_posn) { - // let corresponding_pid = corresponding_process.pid; - - // if let Some(process_data) = self - // .canvas_data - // .single_process_data - // .get_mut(&corresponding_pid) - // { - // process_data.is_collapsed_entry = !process_data.is_collapsed_entry; - // self.proc_state.force_update = Some(self.current_widget.widget_id); - // } - // } - // } - // } - } + fn toggle_collapsing_process_branch(&mut self) {} fn zoom_out(&mut self) { match self.current_widget.widget_type { @@ -2856,343 +2686,4 @@ impl AppState { _ => {} } } - - /// Moves the mouse to the widget that was clicked on, then propagates the click down to be - /// handled by the widget specifically. - pub fn on_left_mouse_up(&mut self, x: u16, y: u16) { - // Pretty dead simple - iterate through the widget map and go to the widget where the click - // is within. - - // TODO: [REFACTOR] might want to refactor this, it's really ugly. - // TODO: [REFACTOR] Might wanna refactor ALL state things in general, currently everything - // is grouped up as an app state. We should separate stuff like event state and gui state and etc. - - // TODO: [MOUSE] double click functionality...? We would do this above all other actions and SC if needed. - - // Short circuit if we're in basic table... we might have to handle the basic table arrow - // case here... - - if let Some(bt) = &mut self.basic_table_widget_state { - if let ( - Some((left_tlc_x, left_tlc_y)), - Some((left_brc_x, left_brc_y)), - Some((right_tlc_x, right_tlc_y)), - Some((right_brc_x, right_brc_y)), - ) = (bt.left_tlc, bt.left_brc, bt.right_tlc, bt.right_brc) - { - if (x >= left_tlc_x && y >= left_tlc_y) && (x < left_brc_x && y < left_brc_y) { - // Case for the left "button" in the simple arrow. - if let Some(new_widget) = - self.widget_map.get(&(bt.currently_displayed_widget_id)) - { - // We have to move to the current table widget first... - self.current_widget = new_widget.clone(); - - if let BottomWidgetType::Proc = &new_widget.widget_type { - if let Some(proc_widget_state) = - self.proc_state.get_widget_state(new_widget.widget_id) - { - if proc_widget_state.is_sort_open { - self.move_widget_selection(&WidgetDirection::Left); - } - } - } - self.move_widget_selection(&WidgetDirection::Left); - return; - } - } else if (x >= right_tlc_x && y >= right_tlc_y) - && (x < right_brc_x && y < right_brc_y) - { - // Case for the right "button" in the simple arrow. - if let Some(new_widget) = - self.widget_map.get(&(bt.currently_displayed_widget_id)) - { - // We have to move to the current table widget first... - self.current_widget = new_widget.clone(); - - if let BottomWidgetType::ProcSort = &new_widget.widget_type { - if let Some(proc_widget_state) = - self.proc_state.get_widget_state(new_widget.widget_id - 2) - { - if proc_widget_state.is_sort_open { - self.move_widget_selection(&WidgetDirection::Right); - } - } - } - } - self.move_widget_selection(&WidgetDirection::Right); - // Bit extra logic to ensure you always land on a proc widget, not the sort - if let BottomWidgetType::ProcSort = &self.current_widget.widget_type { - self.move_widget_selection(&WidgetDirection::Right); - } - return; - } - } - } - - // Second short circuit --- are we in the dd dialog state? If so, only check yes/no/signals - // and bail after. - if self.is_in_dialog() { - match self.delete_dialog_state.button_positions.iter().find( - |(tl_x, tl_y, br_x, br_y, _idx)| { - (x >= *tl_x && y >= *tl_y) && (x <= *br_x && y <= *br_y) - }, - ) { - Some((_, _, _, _, 0)) => { - self.delete_dialog_state.selected_signal = KillSignal::Cancel - } - Some((_, _, _, _, idx)) => { - if *idx > 31 { - self.delete_dialog_state.selected_signal = KillSignal::Kill(*idx + 2) - } else { - self.delete_dialog_state.selected_signal = KillSignal::Kill(*idx) - } - } - _ => {} - } - return; - } - - let mut failed_to_get = true; - // TODO: [MOUSE] We could use a better data structure for this? Currently it's a blind - // traversal through a hashmap, using a 2d binary tree of sorts would be better. - // See: https://docs.rs/kdtree/0.6.0/kdtree/ - for (new_widget_id, widget) in &self.widget_map { - if let (Some((tlc_x, tlc_y)), Some((brc_x, brc_y))) = - (widget.top_left_corner, widget.bottom_right_corner) - { - if (x >= tlc_x && y >= tlc_y) && (x < brc_x && y < brc_y) { - if let Some(new_widget) = self.widget_map.get(new_widget_id) { - self.current_widget = new_widget.clone(); - - match &self.current_widget.widget_type { - BottomWidgetType::Temp - | BottomWidgetType::Proc - | BottomWidgetType::ProcSort - | BottomWidgetType::Disk - | BottomWidgetType::Battery => { - if let Some(basic_table_widget_state) = - &mut self.basic_table_widget_state - { - basic_table_widget_state.currently_displayed_widget_id = - self.current_widget.widget_id; - basic_table_widget_state.currently_displayed_widget_type = - self.current_widget.widget_type.clone(); - } - } - _ => {} - } - - failed_to_get = false; - break; - } - } - } - } - - if failed_to_get { - return; - } - - // Now handle click propagation down to widget. - if let (Some((_tlc_x, tlc_y)), Some((_brc_x, brc_y))) = ( - &self.current_widget.top_left_corner, - &self.current_widget.bottom_right_corner, - ) { - let border_offset = if self.is_drawing_border() { 1 } else { 0 }; - - // This check ensures the click isn't actually just clicking on the bottom border. - if y < (brc_y - border_offset) { - match &self.current_widget.widget_type { - BottomWidgetType::Proc - | BottomWidgetType::ProcSort - | BottomWidgetType::CpuLegend - | BottomWidgetType::Temp - | BottomWidgetType::Disk => { - // Get our index... - let clicked_entry = y - *tlc_y; - // + 1 so we start at 0. - let header_gap_offset = 1 + if self.is_drawing_gap(&self.current_widget) { - self.app_config_fields.table_gap - } else { - 0 - }; - let offset = border_offset + header_gap_offset; - if clicked_entry >= offset { - let offset_clicked_entry = clicked_entry - offset; - match &self.current_widget.widget_type { - BottomWidgetType::Proc => { - if let Some(proc_widget_state) = self - .proc_state - .get_widget_state(self.current_widget.widget_id) - { - if let Some(visual_index) = - proc_widget_state.scroll_state.table_state.selected() - { - // If in tree mode, also check to see if this click is on - // the same entry as the already selected one - if it is, - // then we minimize. - - let previous_scroll_position = proc_widget_state - .scroll_state - .current_scroll_position; - let is_tree_mode = proc_widget_state.is_tree_mode; - - let new_position = self.increment_process_position( - offset_clicked_entry as i64 - visual_index as i64, - ); - - if is_tree_mode { - if let Some(new_position) = new_position { - if previous_scroll_position == new_position { - self.toggle_collapsing_process_branch(); - } - } - } - } - } - } - BottomWidgetType::ProcSort => { - // TODO: This should sort if you double click! - if let Some(proc_widget_state) = self - .proc_state - .get_widget_state(self.current_widget.widget_id - 2) - { - if let Some(visual_index) = - proc_widget_state.columns.column_state.selected() - { - self.increment_process_sort_position( - offset_clicked_entry as i64 - visual_index as i64, - ); - } - } - } - BottomWidgetType::CpuLegend => { - if let Some(cpu_widget_state) = self - .cpu_state - .get_widget_state(self.current_widget.widget_id - 1) - { - if let Some(visual_index) = - cpu_widget_state.scroll_state.table_state.selected() - { - self.increment_cpu_legend_position( - offset_clicked_entry as i64 - visual_index as i64, - ); - } - } - } - BottomWidgetType::Temp => { - if let Some(temp_widget_state) = self - .temp_state - .get_widget_state(self.current_widget.widget_id) - { - if let Some(visual_index) = - temp_widget_state.scroll_state.table_state.selected() - { - self.increment_temp_position( - offset_clicked_entry as i64 - visual_index as i64, - ); - } - } - } - BottomWidgetType::Disk => { - if let Some(disk_widget_state) = self - .disk_state - .get_widget_state(self.current_widget.widget_id) - { - if let Some(visual_index) = - disk_widget_state.scroll_state.table_state.selected() - { - self.increment_disk_position( - offset_clicked_entry as i64 - visual_index as i64, - ); - } - } - } - _ => {} - } - } else { - // We might have clicked on a header! Check if we only exceeded the table + border offset, and - // it's implied we exceeded the gap offset. - if clicked_entry == border_offset { - #[allow(clippy::single_match)] - match &self.current_widget.widget_type { - BottomWidgetType::Proc => { - if let Some(proc_widget_state) = self - .proc_state - .get_mut_widget_state(self.current_widget.widget_id) - { - // Let's now check if it's a column header. - if let (Some(y_loc), Some(x_locs)) = ( - &proc_widget_state.columns.column_header_y_loc, - &proc_widget_state.columns.column_header_x_locs, - ) { - // debug!("x, y: {}, {}", x, y); - // debug!("y_loc: {}", y_loc); - // debug!("x_locs: {:?}", x_locs); - - if y == *y_loc { - for (itx, (x_left, x_right)) in - x_locs.iter().enumerate() - { - if x >= *x_left && x <= *x_right { - // Found our column! - proc_widget_state - .columns - .set_to_sorted_index_from_visual_index( - itx, - ); - proc_widget_state - .update_sorting_with_columns(); - self.proc_state.force_update = - Some(self.current_widget.widget_id); - break; - } - } - } - } - } - } - _ => {} - } - } - } - } - BottomWidgetType::Battery => { - if let Some(battery_widget_state) = self - .battery_state - .get_mut_widget_state(self.current_widget.widget_id) - { - if let Some(tab_spacing) = &battery_widget_state.tab_click_locs { - for (itx, ((tlc_x, tlc_y), (brc_x, brc_y))) in - tab_spacing.iter().enumerate() - { - if (x >= *tlc_x && y >= *tlc_y) && (x <= *brc_x && y <= *brc_y) - { - battery_widget_state.currently_selected_battery_index = itx; - break; - } - } - } - } - } - _ => {} - } - } - } - } - - fn is_drawing_border(&self) -> bool { - self.is_expanded || !self.app_config_fields.use_basic_mode - } - - fn is_drawing_gap(&self, widget: &BottomWidget) -> bool { - if let (Some((_tlc_x, tlc_y)), Some((_brc_x, brc_y))) = - (widget.top_left_corner, widget.bottom_right_corner) - { - brc_y - tlc_y >= constants::TABLE_GAP_HEIGHT_LIMIT - } else { - self.app_config_fields.table_gap == 0 - } - } } |