-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add context menu action to copy entity paths to clipboard (#9137)
Co-authored-by: Antoine Beyeler <[email protected]>
- Loading branch information
Showing
3 changed files
with
65 additions
and
8 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
crates/viewer/re_context_menu/src/actions/copy_entity_path.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use itertools::Itertools; | ||
use re_viewer_context::Item; | ||
|
||
use crate::{ContextMenuAction, ContextMenuContext}; | ||
|
||
pub struct CopyEntityPathToClipboard; | ||
|
||
impl ContextMenuAction for CopyEntityPathToClipboard { | ||
fn supports_multi_selection(&self, _ctx: &ContextMenuContext<'_>) -> bool { | ||
true | ||
} | ||
|
||
fn supports_item(&self, _ctx: &ContextMenuContext<'_>, item: &Item) -> bool { | ||
match item { | ||
Item::AppId(_) | ||
| Item::DataSource(_) | ||
| Item::StoreId(_) | ||
| Item::Container(_) | ||
| Item::View(_) => false, | ||
Item::DataResult(..) | Item::InstancePath(_) | Item::ComponentPath(_) => true, | ||
} | ||
} | ||
|
||
fn label(&self, ctx: &ContextMenuContext<'_>) -> String { | ||
if ctx.selection.len() == 1 { | ||
"Copy entity path".to_owned() | ||
} else { | ||
"Copy entity paths".to_owned() | ||
} | ||
} | ||
|
||
fn process_selection(&self, ctx: &ContextMenuContext<'_>) { | ||
let clipboard_text = ctx | ||
.selection | ||
.iter() | ||
.filter_map(|(item, _)| match item { | ||
Item::AppId(_) | ||
| Item::DataSource(_) | ||
| Item::StoreId(_) | ||
| Item::Container(_) | ||
| Item::View(_) => None, | ||
Item::DataResult(_, instance_path) | Item::InstancePath(instance_path) => { | ||
Some(instance_path.entity_path.clone()) | ||
} | ||
Item::ComponentPath(component_path) => Some(component_path.entity_path.clone()), | ||
}) | ||
.map(|entity_path| entity_path.to_string()) | ||
.join("\n"); | ||
|
||
re_log::info!("Copied entity paths to clipboard:\n{}", &clipboard_text); | ||
ctx.viewer_context.egui_ctx().copy_text(clipboard_text); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
pub(super) mod add_container; | ||
pub(super) mod add_entities_to_new_view; | ||
pub(super) mod add_view; | ||
pub(super) mod clone_view; | ||
pub(super) mod collapse_expand_all; | ||
pub(super) mod move_contents_to_new_container; | ||
pub(super) mod remove; | ||
pub(super) mod show_hide; | ||
pub mod add_container; | ||
pub mod add_entities_to_new_view; | ||
pub mod add_view; | ||
pub mod clone_view; | ||
pub mod collapse_expand_all; | ||
pub mod move_contents_to_new_container; | ||
pub mod remove; | ||
pub mod show_hide; | ||
|
||
mod copy_entity_path; | ||
mod screenshot_action; | ||
|
||
pub use copy_entity_path::CopyEntityPathToClipboard; | ||
pub use screenshot_action::ScreenshotAction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters