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