rustapi/actions/
clear_palette.rs1use crate::{
2 editor::{DOCKMANAGER, UNDOMANAGER},
3 prelude::*,
4};
5
6pub struct ClearPalette {
7 id: TheId,
8 nodeui: TheNodeUI,
9}
10
11impl Action for ClearPalette {
12 fn new() -> Self
13 where
14 Self: Sized,
15 {
16 let nodeui: TheNodeUI = TheNodeUI::default();
17
18 Self {
19 id: TheId::named(&fl!("action_clear_palette")),
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_palette_desc")
30 }
31
32 fn role(&self) -> ActionRole {
33 ActionRole::Dock
34 }
35
36 fn accel(&self) -> Option<TheAccelerator> {
37 None
38 }
39
40 fn is_applicable(
41 &self,
42 _map: &Map,
43 _ctx: &mut TheContext,
44 _server_ctx: &ServerContext,
45 ) -> bool {
46 DOCKMANAGER.read().unwrap().dock == "Tiles"
47 }
48
49 fn apply_project(
50 &self,
51 project: &mut Project,
52 ui: &mut TheUI,
53 ctx: &mut TheContext,
54 server_ctx: &mut ServerContext,
55 ) {
56 let prev = project.palette.clone();
57
58 project.palette.clear();
59 apply_palette(ui, ctx, server_ctx, project);
60
61 let undo_atom = ProjectUndoAtom::PaletteEdit(prev, project.palette.clone());
62 UNDOMANAGER.write().unwrap().add_undo(undo_atom, ctx);
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 _ => {}
79 }
80 false
81 }
82}