1use std::{num::NonZeroUsize, time::Duration};
2
3use crate::DockPosition;
4use collections::HashMap;
5use serde::Deserialize;
6pub use settings::{
7 AutosaveSetting, BottomDockLayout, EncodingDisplayOptions, InactiveOpacity,
8 PaneSplitDirectionHorizontal, PaneSplitDirectionVertical, RegisterSetting,
9 RestoreOnStartupBehavior, Settings,
10};
11
12#[derive(RegisterSetting)]
13pub struct WorkspaceSettings {
14 pub active_pane_modifiers: ActivePanelModifiers,
15 pub bottom_dock_layout: settings::BottomDockLayout,
16 pub pane_split_direction_horizontal: settings::PaneSplitDirectionHorizontal,
17 pub pane_split_direction_vertical: settings::PaneSplitDirectionVertical,
18 pub centered_layout: settings::CenteredLayoutSettings,
19 pub confirm_quit: bool,
20 pub show_call_status_icon: bool,
21 pub autosave: AutosaveSetting,
22 pub restore_on_startup: settings::RestoreOnStartupBehavior,
23 pub restore_on_file_reopen: bool,
24 pub drop_target_size: f32,
25 pub use_system_path_prompts: bool,
26 pub use_system_prompts: bool,
27 pub command_aliases: HashMap<String, String>,
28 pub max_tabs: Option<NonZeroUsize>,
29 pub when_closing_with_no_tabs: settings::CloseWindowWhenNoItems,
30 pub on_last_window_closed: settings::OnLastWindowClosed,
31 pub text_rendering_mode: settings::TextRenderingMode,
32 pub resize_all_panels_in_dock: Vec<DockPosition>,
33 pub close_on_file_delete: bool,
34 pub close_panel_on_toggle: bool,
35 pub use_system_window_tabs: bool,
36 pub zoomed_padding: bool,
37 pub window_decorations: settings::WindowDecorations,
38 pub focus_follows_mouse: FocusFollowsMouse,
39}
40
41#[derive(Copy, Clone, Deserialize)]
42pub struct FocusFollowsMouse {
43 pub enabled: bool,
44 pub debounce: Duration,
45}
46
47#[derive(Copy, Clone, PartialEq, Debug, Default)]
48pub struct ActivePanelModifiers {
49 /// Size of the border surrounding the active pane.
50 /// When set to 0, the active pane doesn't have any border.
51 /// The border is drawn inset.
52 ///
53 /// Default: `0.0`
54 // TODO: make this not an option, it is never None
55 pub border_size: Option<f32>,
56 /// Opacity of inactive panels.
57 /// When set to 1.0, the inactive panes have the same opacity as the active one.
58 /// If set to 0, the inactive panes content will not be visible at all.
59 /// Values are clamped to the [0.0, 1.0] range.
60 ///
61 /// Default: `1.0`
62 // TODO: make this not an option, it is never None
63 pub inactive_opacity: Option<InactiveOpacity>,
64}
65
66#[derive(Deserialize, RegisterSetting)]
67pub struct TabBarSettings {
68 pub show: bool,
69 pub show_nav_history_buttons: bool,
70 pub show_tab_bar_buttons: bool,
71 pub show_pinned_tabs_in_separate_row: bool,
72}
73
74impl Settings for WorkspaceSettings {
75 fn from_settings(content: &settings::SettingsContent) -> Self {
76 let workspace = &content.workspace;
77 Self {
78 active_pane_modifiers: ActivePanelModifiers {
79 border_size: Some(
80 workspace
81 .active_pane_modifiers
82 .unwrap()
83 .border_size
84 .unwrap(),
85 ),
86 inactive_opacity: Some(
87 workspace
88 .active_pane_modifiers
89 .unwrap()
90 .inactive_opacity
91 .unwrap(),
92 ),
93 },
94 bottom_dock_layout: workspace.bottom_dock_layout.unwrap(),
95 pane_split_direction_horizontal: workspace.pane_split_direction_horizontal.unwrap(),
96 pane_split_direction_vertical: workspace.pane_split_direction_vertical.unwrap(),
97 centered_layout: workspace.centered_layout.unwrap(),
98 confirm_quit: workspace.confirm_quit.unwrap(),
99 show_call_status_icon: workspace.show_call_status_icon.unwrap(),
100 autosave: workspace.autosave.unwrap(),
101 restore_on_startup: workspace.restore_on_startup.unwrap(),
102 restore_on_file_reopen: workspace.restore_on_file_reopen.unwrap(),
103 drop_target_size: workspace.drop_target_size.unwrap(),
104 use_system_path_prompts: workspace.use_system_path_prompts.unwrap(),
105 use_system_prompts: workspace.use_system_prompts.unwrap(),
106 command_aliases: workspace.command_aliases.clone(),
107 max_tabs: workspace.max_tabs,
108 when_closing_with_no_tabs: workspace.when_closing_with_no_tabs.unwrap(),
109 on_last_window_closed: workspace.on_last_window_closed.unwrap(),
110 text_rendering_mode: workspace.text_rendering_mode.unwrap(),
111 resize_all_panels_in_dock: workspace
112 .resize_all_panels_in_dock
113 .clone()
114 .unwrap()
115 .into_iter()
116 .map(Into::into)
117 .collect(),
118 close_on_file_delete: workspace.close_on_file_delete.unwrap(),
119 close_panel_on_toggle: workspace.close_panel_on_toggle.unwrap(),
120 use_system_window_tabs: workspace.use_system_window_tabs.unwrap(),
121 zoomed_padding: workspace.zoomed_padding.unwrap(),
122 window_decorations: workspace.window_decorations.unwrap(),
123 focus_follows_mouse: FocusFollowsMouse {
124 enabled: workspace
125 .focus_follows_mouse
126 .unwrap()
127 .enabled
128 .unwrap_or(false),
129 debounce: Duration::from_millis(
130 workspace
131 .focus_follows_mouse
132 .unwrap()
133 .debounce_ms
134 .unwrap_or(250),
135 ),
136 },
137 }
138 }
139}
140
141impl Settings for TabBarSettings {
142 fn from_settings(content: &settings::SettingsContent) -> Self {
143 let tab_bar = content.tab_bar.clone().unwrap();
144 TabBarSettings {
145 show: tab_bar.show.unwrap(),
146 show_nav_history_buttons: tab_bar.show_nav_history_buttons.unwrap(),
147 show_tab_bar_buttons: tab_bar.show_tab_bar_buttons.unwrap(),
148 show_pinned_tabs_in_separate_row: tab_bar.show_pinned_tabs_in_separate_row.unwrap(),
149 }
150 }
151}
152
153#[derive(Deserialize, RegisterSetting)]
154pub struct StatusBarSettings {
155 pub show: bool,
156 pub show_active_file: bool,
157 pub active_language_button: bool,
158 pub cursor_position_button: bool,
159 pub line_endings_button: bool,
160 pub active_encoding_button: EncodingDisplayOptions,
161}
162
163impl Settings for StatusBarSettings {
164 fn from_settings(content: &settings::SettingsContent) -> Self {
165 let status_bar = content.status_bar.clone().unwrap();
166 StatusBarSettings {
167 show: status_bar.show.unwrap(),
168 show_active_file: status_bar.show_active_file.unwrap(),
169 active_language_button: status_bar.active_language_button.unwrap(),
170 cursor_position_button: status_bar.cursor_position_button.unwrap(),
171 line_endings_button: status_bar.line_endings_button.unwrap(),
172 active_encoding_button: status_bar.active_encoding_button.unwrap(),
173 }
174 }
175}