rustapi/actions/
editing_camera.rs1use crate::prelude::*;
2
3pub struct EditingCamera {
4 id: TheId,
5 nodeui: TheNodeUI,
6}
7
8impl Action for EditingCamera {
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_editing_camera_desc"));
15 nodeui.add_item(item);
16
17 Self {
18 id: TheId::named(&fl!("action_editing_camera")),
19 nodeui,
20 }
21 }
22
23 fn id(&self) -> TheId {
24 self.id.clone()
25 }
26
27 fn info(&self) -> String {
28 fl!("action_editing_camera_desc")
29 }
30
31 fn role(&self) -> ActionRole {
32 ActionRole::Camera
33 }
34
35 fn accel(&self) -> Option<TheAccelerator> {
36 Some(TheAccelerator::new(TheAcceleratorKey::CTRLCMD, '2'))
37 }
38
39 fn is_applicable(&self, _map: &Map, _ctx: &mut TheContext, server_ctx: &ServerContext) -> bool {
40 (server_ctx.editor_view_mode != EditorViewMode::D2 || server_ctx.editing_surface.is_some())
41 && server_ctx.get_map_context() == MapContext::Region
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 server_ctx.editing_surface = None;
52 ui.set_widget_value("Editor View Switch", ctx, TheValue::Int(0));
53 ctx.ui.send(TheEvent::IndexChanged(
54 TheId::named("Editor View Switch"),
55 0,
56 ));
57
58 None
59 }
60
61 fn params(&self) -> TheNodeUI {
62 self.nodeui.clone()
63 }
64
65 fn handle_event(
66 &mut self,
67 event: &TheEvent,
68 _project: &mut Project,
69 _ui: &mut TheUI,
70 _ctx: &mut TheContext,
71 _server_ctx: &mut ServerContext,
72 ) -> bool {
73 self.nodeui.handle_event(event)
74 }
75}