rustapi/actions/
toggle_rect_geo.rs1use crate::editor::DOCKMANAGER;
2use crate::prelude::*;
3
4pub struct ToggleRectGeo {
5 id: TheId,
6 nodeui: TheNodeUI,
7}
8
9impl Action for ToggleRectGeo {
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_toggle_rect_geo_desc"));
16 nodeui.add_item(item);
17
18 Self {
19 id: TheId::named(&fl!("action_toggle_rect_geo")),
20 nodeui,
21 }
22 }
23
24 fn id(&self) -> TheId {
25 self.id.clone()
26 }
27
28 fn info(&self) -> String {
29 fl!("action_toggle_rect_geo_desc")
30 }
31
32 fn role(&self) -> ActionRole {
33 ActionRole::Editor
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 server_ctx.editor_view_mode == EditorViewMode::D2
42 && server_ctx.editing_surface.is_none()
43 && DOCKMANAGER.read().unwrap().get_state() != DockManagerState::Editor
44 }
45
46 fn apply(
47 &self,
48 _map: &mut Map,
49 _ui: &mut TheUI,
50 ctx: &mut TheContext,
51 server_ctx: &mut ServerContext,
52 ) -> Option<ProjectUndoAtom> {
53 server_ctx.no_rect_geo_on_map = !server_ctx.no_rect_geo_on_map;
54
55 ctx.ui.send(TheEvent::Custom(
56 TheId::named("Update Client Properties"),
57 TheValue::Empty,
58 ));
59
60 None
61 }
62
63 fn params(&self) -> TheNodeUI {
64 self.nodeui.clone()
65 }
66
67 fn handle_event(
68 &mut self,
69 event: &TheEvent,
70 _project: &mut Project,
71 _ui: &mut TheUI,
72 _ctx: &mut TheContext,
73 _server_ctx: &mut ServerContext,
74 ) -> bool {
75 self.nodeui.handle_event(event)
76 }
77}