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