rustapi/actions/
copy_tile_id.rs1use crate::editor::DOCKMANAGER;
2use crate::prelude::*;
3
4pub struct CopyTileID {
5 id: TheId,
6 nodeui: TheNodeUI,
7}
8
9impl Action for CopyTileID {
10 fn new() -> Self
11 where
12 Self: Sized,
13 {
14 let mut nodeui: TheNodeUI = TheNodeUI::default();
15 let item = TheNodeUIItem::Markdown("desc".into(), fl!("action_copy_tile_id_desc"));
16 nodeui.add_item(item);
17
18 Self {
19 id: TheId::named(&fl!("action_copy_tile_id")),
20 nodeui,
21 }
22 }
23
24 fn id(&self) -> TheId {
25 self.id.clone()
26 }
27
28 fn info(&self) -> String {
29 fl!("action_copy_tile_id_desc")
30 }
31
32 fn role(&self) -> ActionRole {
33 ActionRole::Dock
34 }
35
36 fn accel(&self) -> Option<TheAccelerator> {
37 None
38 }
39
40 fn is_applicable(&self, _map: &Map, _ctx: &mut TheContext, server_ctx: &ServerContext) -> bool {
41 DOCKMANAGER.read().unwrap().dock == "Tiles" && server_ctx.curr_tile_id.is_some()
42 }
43
44 fn apply(
45 &self,
46 _map: &mut Map,
47 _ui: &mut TheUI,
48 ctx: &mut TheContext,
49 server_ctx: &mut ServerContext,
50 ) -> Option<ProjectUndoAtom> {
51 if let Some(tile_id) = server_ctx.curr_tile_id {
52 let txt = format!("\"{tile_id}\"");
53 ctx.ui.clipboard = Some(TheValue::Text(txt.clone()));
54 let mut clipboard = arboard::Clipboard::new().unwrap();
55 clipboard.set_text(txt.clone()).unwrap();
56 }
57
58 None
59 }
60
61 fn params(&self) -> TheNodeUI {
62 self.nodeui.clone()
63 }
64
65 fn handle_event(
66 &mut self,
67 event: &TheEvent,
68 _project: &mut Project,
69 _ui: &mut TheUI,
70 _ctx: &mut TheContext,
71 _server_ctx: &mut ServerContext,
72 ) -> bool {
73 self.nodeui.handle_event(event)
74 }
75}