1use crate::prelude::*;
2
3pub struct Split {
4 id: TheId,
5 nodeui: TheNodeUI,
6}
7
8impl Action for Split {
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_split_desc"));
16 nodeui.add_item(item);
17
18 Self {
19 id: TheId::named(&fl!("action_split")),
20 nodeui,
21 }
22 }
23
24 fn id(&self) -> TheId {
25 self.id.clone()
26 }
27
28 fn info(&self) -> String {
29 fl!("action_split_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 !map.selected_linedefs.is_empty()
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 let mut changed = false;
52 let prev = map.clone();
53
54 for linedef_id in &map.selected_linedefs.clone() {
55 map.add_midpoint(*linedef_id);
56 changed = true;
57 }
58
59 if changed {
60 Some(ProjectUndoAtom::MapEdit(
61 server_ctx.pc,
62 Box::new(prev),
63 Box::new(map.clone()),
64 ))
65 } else {
66 None
67 }
68 }
69
70 fn params(&self) -> TheNodeUI {
71 self.nodeui.clone()
72 }
73
74 fn handle_event(
75 &mut self,
76 event: &TheEvent,
77 _project: &mut Project,
78 _ui: &mut TheUI,
79 _ctx: &mut TheContext,
80 _server_ctx: &mut ServerContext,
81 ) -> bool {
82 self.nodeui.handle_event(event)
83 }
84}