ass_editor/extensions/registry_integration/
integration.rs1use crate::core::{EditorError, Result};
9use crate::extensions::EditorExtension;
10use ass_core::plugin::{ExtensionRegistry, SectionProcessor, TagHandler};
11
12#[cfg(not(feature = "std"))]
13use alloc::{boxed::Box, format, string::String, vec::Vec};
14
15pub struct RegistryIntegration {
17 pub(super) registry: ExtensionRegistry,
19 pub(super) tag_providers: Vec<Box<dyn EditorExtension>>,
21 pub(super) section_providers: Vec<Box<dyn EditorExtension>>,
23}
24
25impl core::fmt::Debug for RegistryIntegration {
26 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
27 f.debug_struct("RegistryIntegration")
28 .field("registry", &self.registry)
29 .field(
30 "tag_providers",
31 &format!("{} providers", self.tag_providers.len()),
32 )
33 .field(
34 "section_providers",
35 &format!("{} providers", self.section_providers.len()),
36 )
37 .finish()
38 }
39}
40
41impl RegistryIntegration {
42 pub fn new() -> Self {
44 Self {
45 registry: ExtensionRegistry::new(),
46 tag_providers: Vec::new(),
47 section_providers: Vec::new(),
48 }
49 }
50
51 pub fn registry(&self) -> &ExtensionRegistry {
53 &self.registry
54 }
55
56 pub fn registry_mut(&mut self) -> &mut ExtensionRegistry {
58 &mut self.registry
59 }
60
61 pub fn register_custom_tag_handler(
63 &mut self,
64 extension_name: String,
65 handler: Box<dyn TagHandler>,
66 ) -> Result<()> {
67 self.registry
68 .register_tag_handler(handler)
69 .map_err(|e| EditorError::ExtensionError {
70 extension: extension_name,
71 message: format!("Failed to register tag handler: {e}"),
72 })
73 }
74
75 pub fn register_custom_section_processor(
77 &mut self,
78 extension_name: String,
79 processor: Box<dyn SectionProcessor>,
80 ) -> Result<()> {
81 self.registry
82 .register_section_processor(processor)
83 .map_err(|e| EditorError::ExtensionError {
84 extension: extension_name,
85 message: format!("Failed to register section processor: {e}"),
86 })
87 }
88}
89
90impl Default for RegistryIntegration {
91 fn default() -> Self {
92 Self::new()
93 }
94}