rustapi/actions/
edit_tile_meta.rs1use crate::editor::DOCKMANAGER;
2use crate::prelude::*;
3use rusterix::TileRole;
4
5pub struct EditTileMeta {
6 id: TheId,
7 nodeui: TheNodeUI,
8}
9
10impl Action for EditTileMeta {
11 fn new() -> Self
12 where
13 Self: Sized,
14 {
15 let mut nodeui: TheNodeUI = TheNodeUI::default();
16
17 let mut roles = vec![];
18 for dir in TileRole::iterator() {
19 roles.push(dir.to_string().to_string());
20 }
21 let item = TheNodeUIItem::Selector("actionTileRole".into(), "".into(), "".into(), roles, 1);
22 nodeui.add_item(item);
23
24 let item = TheNodeUIItem::Selector(
25 "actionTileBlocking".into(),
26 "".into(),
27 "".into(),
28 vec!["No".to_string(), "Yes".to_string()],
29 0,
30 );
31 nodeui.add_item(item);
32
33 let item = TheNodeUIItem::Text(
34 "actionTileTags".into(),
35 "".into(),
36 "".into(),
37 "".into(),
38 None,
39 false,
40 );
41 nodeui.add_item(item);
42
43 let item = TheNodeUIItem::Markdown("desc".into(), "".into());
44 nodeui.add_item(item);
45
46 Self {
47 id: TheId::named(&fl!("action_edit_tile")),
48 nodeui,
49 }
50 }
51
52 fn id(&self) -> TheId {
53 self.id.clone()
54 }
55
56 fn info(&self) -> String {
57 fl!("action_edit_tile_desc")
58 }
59
60 fn role(&self) -> ActionRole {
61 ActionRole::Dock
62 }
63
64 fn accel(&self) -> Option<TheAccelerator> {
65 None
66 }
67
68 fn is_applicable(&self, _map: &Map, _ctx: &mut TheContext, server_ctx: &ServerContext) -> bool {
69 DOCKMANAGER.read().unwrap().dock == "Tiles" && server_ctx.curr_tile_id.is_some()
70 }
71
72 fn load_params_project(&mut self, project: &Project, server_ctx: &mut ServerContext) {
73 if let Some(tile_id) = server_ctx.curr_tile_id {
74 if let Some(tile) = project.get_tile(&tile_id) {
75 self.nodeui
76 .set_i32_value("actionTileRole", tile.role as i32);
77 self.nodeui
78 .set_i32_value("actionTileBlocking", if tile.blocking { 1 } else { 0 });
79 self.nodeui
80 .set_text_value("actionTileTags", tile.name.clone());
81 }
82 }
83 }
84
85 fn apply_project(
86 &self,
87 project: &mut Project,
88 _ui: &mut TheUI,
89 _ctx: &mut TheContext,
90 server_ctx: &mut ServerContext,
91 ) {
92 let role = self.nodeui.get_i32_value("actionTileRole").unwrap_or(0);
93 let blocking = self.nodeui.get_i32_value("actionTileBlocking").unwrap_or(0);
94 let name = self
95 .nodeui
96 .get_text_value("actionTileTags")
97 .unwrap_or(String::new());
98
99 if let Some(tile_id) = server_ctx.curr_tile_id {
100 if let Some(tile) = project.get_tile_mut(&tile_id) {
101 tile.role = TileRole::from_index(role as u8);
102 tile.blocking = blocking == 1;
103 tile.name = name;
104 }
105 }
106 }
107
108 fn params(&self) -> TheNodeUI {
109 self.nodeui.clone()
110 }
111
112 fn handle_event(
113 &mut self,
114 event: &TheEvent,
115 _project: &mut Project,
116 _ui: &mut TheUI,
117 _ctx: &mut TheContext,
118 _server_ctx: &mut ServerContext,
119 ) -> bool {
120 self.nodeui.handle_event(event)
121 }
122}