use super::ResourceTab;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DrillItem {
pub kind: String,
pub name: String,
pub detail: String
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DrillView {
pub title: String,
pub items: Vec<DrillItem>,
pub selected: usize
}
impl super::App {
#[must_use]
pub fn can_drill(&self) -> bool {
matches!(self.active_tab, ResourceTab::Projects) && self.selected_resource().is_some()
}
pub fn request_drill(&mut self) {
if self.can_drill()
&& let Some((id, name)) = self.selected_resource()
&& let Ok(id) = id.parse::<i32>()
{
self.drill_request = Some((self.active_tab, id, name));
}
}
#[must_use]
pub const fn take_drill_request(&mut self) -> Option<(ResourceTab, i32, String)> {
self.drill_request.take()
}
pub fn open_drill(&mut self, view: DrillView) {
self.drill = Some(view);
}
pub fn close_drill(&mut self) {
self.drill = None;
}
#[must_use]
pub const fn drill_open(&self) -> bool {
self.drill.is_some()
}
#[must_use]
pub const fn drill_view(&self) -> Option<&DrillView> {
self.drill.as_ref()
}
pub const fn drill_next(&mut self) {
if let Some(view) = self.drill.as_mut()
&& view.selected + 1 < view.items.len()
{
view.selected += 1;
}
}
pub const fn drill_previous(&mut self) {
if let Some(view) = self.drill.as_mut() {
view.selected = view.selected.saturating_sub(1);
}
}
}