ass_editor/extensions/
command.rs1#[cfg(feature = "std")]
7use std::collections::HashMap;
8
9#[cfg(not(feature = "std"))]
10use alloc::collections::BTreeMap as HashMap;
11
12#[cfg(not(feature = "std"))]
13use alloc::string::{String, ToString};
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub enum ExtensionState {
18 Uninitialized,
20 Initializing,
22 Active,
24 Paused,
26 Error,
28 ShuttingDown,
30 Shutdown,
32}
33
34impl ExtensionState {
35 pub fn is_active(&self) -> bool {
37 matches!(self, Self::Active)
38 }
39
40 pub fn is_usable(&self) -> bool {
42 matches!(self, Self::Active | Self::Paused)
43 }
44
45 pub fn is_error(&self) -> bool {
47 matches!(self, Self::Error)
48 }
49}
50
51#[derive(Debug, Clone)]
53pub struct ExtensionCommand {
54 pub id: String,
56 pub name: String,
58 pub description: String,
60 pub shortcut: Option<String>,
62 pub category: String,
64 pub requires_document: bool,
66}
67
68impl ExtensionCommand {
69 pub fn new(id: String, name: String, description: String) -> Self {
71 Self {
72 id,
73 name,
74 description,
75 shortcut: None,
76 category: "General".to_string(),
77 requires_document: true,
78 }
79 }
80
81 pub fn with_shortcut(mut self, shortcut: String) -> Self {
83 self.shortcut = Some(shortcut);
84 self
85 }
86
87 pub fn with_category(mut self, category: String) -> Self {
89 self.category = category;
90 self
91 }
92
93 pub fn requires_document(mut self, requires: bool) -> Self {
95 self.requires_document = requires;
96 self
97 }
98}
99
100#[derive(Debug, Clone, Copy, PartialEq, Eq)]
102pub enum MessageLevel {
103 Info,
105 Warning,
107 Error,
109 Success,
111}
112
113#[derive(Debug, Clone)]
115pub struct ExtensionResult {
116 pub success: bool,
118 pub message: Option<String>,
120 pub data: HashMap<String, String>,
122}
123
124impl ExtensionResult {
125 pub fn success() -> Self {
127 Self {
128 success: true,
129 message: None,
130 data: HashMap::new(),
131 }
132 }
133
134 pub fn success_with_message(message: String) -> Self {
136 Self {
137 success: true,
138 message: Some(message),
139 data: HashMap::new(),
140 }
141 }
142
143 pub fn failure(message: String) -> Self {
145 Self {
146 success: false,
147 message: Some(message),
148 data: HashMap::new(),
149 }
150 }
151
152 pub fn with_data(mut self, key: String, value: String) -> Self {
154 self.data.insert(key, value);
155 self
156 }
157}