use std::fmt::Display;
#[derive(Clone, Debug, PartialEq)]
pub enum ColumnLocator {
Table(String),
Expression(String),
NewExpression,
}
impl ColumnLocator {
pub fn name(&self) -> Option<&String> {
match self {
Self::Table(s) | Self::Expression(s) => Some(s),
Self::NewExpression => None,
}
}
#[inline(always)]
pub fn is_saved_expr(&self) -> bool {
matches!(self, ColumnLocator::Expression(_))
}
#[inline(always)]
pub fn is_expr(&self) -> bool {
matches!(
self,
ColumnLocator::Expression(_) | ColumnLocator::NewExpression
)
}
#[inline(always)]
pub fn is_new_expr(&self) -> bool {
matches!(self, ColumnLocator::NewExpression)
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq)]
pub enum ColumnSettingsTab {
#[default]
Attributes,
Style,
}
impl Display for ColumnSettingsTab {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("{self:?}"))
}
}
#[derive(Clone, Default, Debug, PartialEq)]
pub struct OpenColumnSettings {
pub locator: Option<ColumnLocator>,
pub tab: Option<ColumnSettingsTab>,
}
impl OpenColumnSettings {
pub fn name(&self) -> Option<String> {
self.locator
.as_ref()
.and_then(|l| l.name())
.map(|s| s.to_owned())
}
}
pub trait ColumnTab: PartialEq + Display + Clone + Default + 'static {}
impl ColumnTab for String {}
impl ColumnTab for &'static str {}
impl ColumnTab for ColumnSettingsTab {}