rustapi/actions/
clear_tile.rs1use crate::prelude::*;
2
3pub struct ClearTile {
4 id: TheId,
5 nodeui: TheNodeUI,
6}
7
8impl Action for ClearTile {
9 fn new() -> Self
10 where
11 Self: Sized,
12 {
13 let mut nodeui: TheNodeUI = TheNodeUI::default();
14 let item = TheNodeUIItem::Markdown("desc".into(), fl!("action_clear_tile_desc"));
15 nodeui.add_item(item);
16
17 Self {
18 id: TheId::named(&fl!("action_clear_tile")),
19 nodeui,
20 }
21 }
22
23 fn id(&self) -> TheId {
24 self.id.clone()
25 }
26
27 fn info(&self) -> String {
28 fl!("action_clear_tile_desc")
29 }
30
31 fn role(&self) -> ActionRole {
32 ActionRole::Dock
33 }
34
35 fn accel(&self) -> Option<TheAccelerator> {
36 None
37 }
38
39 fn is_applicable(&self, map: &Map, _ctx: &mut TheContext, _server_ctx: &ServerContext) -> bool {
40 if map.selected_sectors.is_empty() {
41 return false;
42 }
43 true
48 }
49
50 fn apply(
51 &self,
52 map: &mut Map,
53 _ui: &mut TheUI,
54 _ctx: &mut TheContext,
55 server_ctx: &mut ServerContext,
56 ) -> Option<ProjectUndoAtom> {
57 let mut changed = false;
58 let prev = map.clone();
59
60 for sector_id in &map.selected_sectors.clone() {
61 if let Some(sector) = map.find_sector_mut(*sector_id) {
62 if sector.properties.contains("source") {
63 sector.properties.remove("source");
64 changed = true;
65 }
66 }
67 }
68
69 if changed {
70 Some(ProjectUndoAtom::MapEdit(
71 server_ctx.pc,
72 Box::new(prev),
73 Box::new(map.clone()),
74 ))
75 } else {
76 None
77 }
78 }
79
80 fn params(&self) -> TheNodeUI {
81 self.nodeui.clone()
82 }
83
84 fn handle_event(
85 &mut self,
86 event: &TheEvent,
87 _project: &mut Project,
88 _ui: &mut TheUI,
89 _ctx: &mut TheContext,
90 _server_ctx: &mut ServerContext,
91 ) -> bool {
92 self.nodeui.handle_event(event)
93 }
94}