rustapi/actions/
export_vcode.rs1use crate::{editor::DOCKMANAGER, prelude::*};
2
3pub struct ExportVCode {
4 id: TheId,
5 nodeui: TheNodeUI,
6}
7
8impl Action for ExportVCode {
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_export_vcode_desc"));
15 nodeui.add_item(item);
16
17 Self {
18 id: TheId::named(&fl!("action_export_vcode")),
19 nodeui,
20 }
21 }
22
23 fn id(&self) -> TheId {
24 self.id.clone()
25 }
26
27 fn info(&self) -> String {
28 fl!("action_export_vcode_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(
40 &self,
41 _map: &Map,
42 _ctx: &mut TheContext,
43 _server_ctx: &ServerContext,
44 ) -> bool {
45 DOCKMANAGER.read().unwrap().dock == "Visual Code"
46 }
47
48 fn apply_project(
49 &self,
50 _project: &mut Project,
51 _ui: &mut TheUI,
52 ctx: &mut TheContext,
53 _server_ctx: &mut ServerContext,
54 ) {
55 ctx.ui.save_file_requester(
56 TheId::named_with_id("actionExportVisualCode", Uuid::new_v4()),
57 "Export Visual Code".into(),
58 TheFileExtension::new(
59 "Eldiron Visual Code".into(),
60 vec!["eldiron_vcode".to_string()],
61 ),
62 );
63 }
64
65 fn params(&self) -> TheNodeUI {
66 self.nodeui.clone()
67 }
68
69 fn handle_event(
70 &mut self,
71 event: &TheEvent,
72 _project: &mut Project,
73 _ui: &mut TheUI,
74 _ctx: &mut TheContext,
75 _server_ctx: &mut ServerContext,
76 ) -> bool {
77 match event {
78 TheEvent::FileRequesterResult(id, paths) => {
79 if id.name == "actionExportVisualCode" {
80 if let Some(json) = DOCKMANAGER.read().unwrap().export() {
81 for p in paths {
82 let _ = std::fs::write(p.clone(), json.clone());
83 }
84 }
85 }
86 }
87 _ => {}
88 }
89 false
90 }
91}