use re_viewer_context::{
Item, ScreenshotTarget, SystemCommand, SystemCommandSender as _, ViewId, ViewRectPublisher,
};
use crate::{ContextMenuAction, ContextMenuContext};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ScreenshotAction {
CopyScreenshot,
SaveScreenshot,
}
impl ContextMenuAction for ScreenshotAction {
fn supports_multi_selection(&self, _ctx: &ContextMenuContext<'_>) -> bool {
match self {
Self::CopyScreenshot => false,
Self::SaveScreenshot => true,
}
}
fn supports_item(&self, ctx: &ContextMenuContext<'_>, item: &Item) -> bool {
if *self == Self::CopyScreenshot && ctx.viewer_context.is_safari_browser() {
re_log::debug_once!("Copying screenshots not supported on Safari");
return false;
}
let Item::View(view_id) = item else {
return false;
};
ctx.egui_context().memory_mut(|mem| {
mem.caches
.cache::<ViewRectPublisher>()
.get(view_id)
.is_some()
})
}
fn label(&self, _ctx: &ContextMenuContext<'_>) -> String {
match self {
Self::CopyScreenshot => "Copy screenshot".to_owned(),
Self::SaveScreenshot => "Save screenshot…".to_owned(),
}
}
fn process_view(&self, ctx: &ContextMenuContext<'_>, view_id: &ViewId) {
let target = match self {
Self::CopyScreenshot => ScreenshotTarget::CopyToClipboard,
Self::SaveScreenshot => ScreenshotTarget::SaveToPathFromFileDialog,
};
ctx.viewer_context
.command_sender()
.send_system(SystemCommand::SaveScreenshot {
target,
view_id: Some(*view_id),
});
}
}