use egui::KeyboardShortcut;
use egui::os::OperatingSystem;
use smallvec::SmallVec;
use super::CommandEnvironment;
pub trait TableCommandSender {
fn send_table_command(&self, command: TableCommand);
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct TableCommand {
pub origin: re_uri::Origin,
pub entry_id: re_log_types::EntryId,
pub kind: TableCommandKind,
}
impl TableCommand {
pub fn text(&self) -> &'static str {
self.kind.text()
}
pub fn tooltip(&self) -> &'static str {
self.kind.tooltip()
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, strum_macros::EnumIter)]
pub enum TableCommandKind {
Refresh,
}
impl TableCommandKind {
pub fn text(self) -> &'static str {
self.text_and_tooltip().0
}
pub fn tooltip(self) -> &'static str {
self.text_and_tooltip().1
}
pub fn text_and_tooltip(self) -> (&'static str, &'static str) {
match self {
Self::Refresh => (
"Refresh table",
"Refresh the contents of the current dataset or table",
),
}
}
pub fn for_environment(self, env: &CommandEnvironment) -> Option<TableCommand> {
let (origin, entry_id) = env.redap_entry.clone()?;
Some(TableCommand {
origin,
entry_id,
kind: self,
})
}
pub fn kb_shortcuts(self, os: OperatingSystem) -> SmallVec<[KeyboardShortcut; 2]> {
match self {
Self::Refresh => super::refresh_shortcuts(os),
}
}
pub fn primary_kb_shortcut(self, os: OperatingSystem) -> Option<KeyboardShortcut> {
self.kb_shortcuts(os).first().copied()
}
pub fn formatted_kb_shortcut(self, egui_ctx: &egui::Context) -> Option<String> {
self.primary_kb_shortcut(egui_ctx.os())
.map(|shortcut| egui_ctx.format_shortcut(&shortcut))
}
}