Skip to main content

editor/
app.rs

1//! App-owned configuration.
2
3use gpui::App;
4
5/// Configuration carried by the application. Import as `use editor::AppExt as _;`.
6pub trait AppExt {
7    /// Reads editor layout.
8    fn editor_layout(&self) -> crate::Layout;
9
10    /// Reads editor text size.
11    fn editor_text_size(&self) -> crate::TextSize;
12
13    /// Configures editor layout.
14    fn set_editor_layout(&mut self, layout: crate::Layout);
15
16    /// Sets editor zoom steps and limits, not an individual editor’s base size.
17    fn set_editor_text_size(&mut self, text_size: crate::TextSize);
18
19    /// Installs the image store used when pasting pictures.
20    fn set_image_store(&mut self, store: crate::ImageStore);
21
22    /// Returns the installed image store, or the default that keeps nothing.
23    fn image_store(&self) -> crate::ImageStore;
24
25    /// Overrides clipboard paste; returning `None` keeps the default behavior.
26    /// File drops are not passed to this handler.
27    fn set_paste_handler(&mut self, handler: crate::PasteHandler);
28
29    /// Replaces the slash menu's items, which are [`crate::slash_defaults`]
30    /// until this is called.
31    fn set_slash_items(&mut self, items: Vec<crate::SlashItem>);
32
33    /// Replaces the block menu's items, which are
34    /// [`crate::block_menu_defaults`] until this is called.
35    fn set_block_menu_items(&mut self, items: Vec<crate::SlashItem>);
36
37    /// Replaces the glyphs the block and table handles paint, which are
38    /// [`crate::Handles::default`] until this is called.
39    fn set_handles(&mut self, handles: crate::Handles);
40
41    /// Installs what the menu `trigger` opens lists, in editors whose
42    /// [`crate::Chrome::mention`] is on. Replaces the source already installed
43    /// for `trigger`; sources for other characters stay.
44    fn set_mention_source(&mut self, trigger: char, source: crate::MentionSource);
45
46    /// Adjusts every open document by the given points and refreshes windows.
47    fn adjust_editor_text_size(&mut self, points: f32);
48
49    /// Resets the shared adjustment to zero and refreshes windows.
50    fn reset_editor_text_size(&mut self);
51
52    /// Returns the shared adjustment from each document’s base size, in points.
53    fn editor_text_size_adjustment(&self) -> f32;
54}
55
56impl AppExt for App {
57    fn editor_layout(&self) -> crate::Layout {
58        crate::layout::Layout::of(self)
59    }
60
61    fn editor_text_size(&self) -> crate::TextSize {
62        crate::text_size::TextSize::of(self)
63    }
64
65    fn set_editor_layout(&mut self, layout: crate::Layout) {
66        crate::layout::set_layout(self, layout)
67    }
68
69    fn set_editor_text_size(&mut self, text_size: crate::TextSize) {
70        crate::text_size::set_text_size(self, text_size)
71    }
72
73    fn set_image_store(&mut self, store: crate::ImageStore) {
74        crate::editor::image::set_image_store(self, store)
75    }
76
77    fn image_store(&self) -> crate::ImageStore {
78        crate::editor::image::store(self)
79    }
80
81    fn set_paste_handler(&mut self, handler: crate::PasteHandler) {
82        self.set_global(crate::paste::Installed(handler));
83    }
84
85    fn set_mention_source(&mut self, trigger: char, source: crate::MentionSource) {
86        let installed = &mut self.default_global::<crate::mention::Installed>().0;
87        installed.retain(|(installed, _)| *installed != trigger);
88        installed.push((trigger, source));
89    }
90
91    fn set_slash_items(&mut self, items: Vec<crate::SlashItem>) {
92        self.set_global(crate::slash::Installed(items));
93    }
94
95    fn set_block_menu_items(&mut self, items: Vec<crate::SlashItem>) {
96        self.set_global(crate::block_menu::Installed(items));
97    }
98
99    fn set_handles(&mut self, handles: crate::Handles) {
100        self.set_global(crate::handles::Installed(handles));
101    }
102
103    fn adjust_editor_text_size(&mut self, points: f32) {
104        crate::text_size::adjust_text_size(self, points)
105    }
106
107    fn reset_editor_text_size(&mut self) {
108        crate::text_size::reset_text_size(self)
109    }
110
111    fn editor_text_size_adjustment(&self) -> f32 {
112        crate::text_size::text_size_adjustment(self)
113    }
114}