1use std::num::NonZeroUsize;
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 use_system_window_tabs: bool,
35 pub zoomed_padding: bool,
36 pub window_decorations: settings::WindowDecorations,
37}
38
39#[derive(Copy, Clone, PartialEq, Debug, Default)]
40pub struct ActivePanelModifiers {
41 /// Size of the border surrounding the active pane.
42 /// When set to 0, the active pane doesn't have any border.
43 /// The border is drawn inset.
44 ///
45 /// Default: `0.0`
46 // TODO: make this not an option, it is never None
47 pub border_size: Option<f32>,
48 /// Opacity of inactive panels.
49 /// When set to 1.0, the inactive panes have the same opacity as the active one.
50 /// If set to 0, the inactive panes content will not be visible at all.
51 /// Values are clamped to the [0.0, 1.0] range.
52 ///
53 /// Default: `1.0`
54 // TODO: make this not an option, it is never None
55 pub inactive_opacity: Option<InactiveOpacity>,
56}
57
58#[derive(Deserialize, RegisterSetting)]
59pub struct TabBarSettings {
60 pub show: bool,
61 pub show_nav_history_buttons: bool,
62 pub show_tab_bar_buttons: bool,
63}
64
65impl Settings for WorkspaceSettings {
66 fn from_settings(content: &settings::SettingsContent) -> Self {
67 let workspace = &content.workspace;
68 Self {
69 active_pane_modifiers: ActivePanelModifiers {
70 border_size: Some(
71 workspace
72 .active_pane_modifiers
73 .unwrap()
74 .border_size
75 .unwrap(),
76 ),
77 inactive_opacity: Some(
78 workspace
79 .active_pane_modifiers
80 .unwrap()
81 .inactive_opacity
82 .unwrap(),
83 ),
84 },
85 bottom_dock_layout: workspace.bottom_dock_layout.unwrap(),
86 pane_split_direction_horizontal: workspace.pane_split_direction_horizontal.unwrap(),
87 pane_split_direction_vertical: workspace.pane_split_direction_vertical.unwrap(),
88 centered_layout: workspace.centered_layout.unwrap(),
89 confirm_quit: workspace.confirm_quit.unwrap(),
90 show_call_status_icon: workspace.show_call_status_icon.unwrap(),
91 autosave: workspace.autosave.unwrap(),
92 restore_on_startup: workspace.restore_on_startup.unwrap(),
93 restore_on_file_reopen: workspace.restore_on_file_reopen.unwrap(),
94 drop_target_size: workspace.drop_target_size.unwrap(),
95 use_system_path_prompts: workspace.use_system_path_prompts.unwrap(),
96 use_system_prompts: workspace.use_system_prompts.unwrap(),
97 command_aliases: workspace.command_aliases.clone(),
98 max_tabs: workspace.max_tabs,
99 when_closing_with_no_tabs: workspace.when_closing_with_no_tabs.unwrap(),
100 on_last_window_closed: workspace.on_last_window_closed.unwrap(),
101 text_rendering_mode: workspace.text_rendering_mode.unwrap(),
102 resize_all_panels_in_dock: workspace
103 .resize_all_panels_in_dock
104 .clone()
105 .unwrap()
106 .into_iter()
107 .map(Into::into)
108 .collect(),
109 close_on_file_delete: workspace.close_on_file_delete.unwrap(),
110 use_system_window_tabs: workspace.use_system_window_tabs.unwrap(),
111 zoomed_padding: workspace.zoomed_padding.unwrap(),
112 window_decorations: workspace.window_decorations.unwrap(),
113 }
114 }
115}
116
117impl Settings for TabBarSettings {
118 fn from_settings(content: &settings::SettingsContent) -> Self {
119 let tab_bar = content.tab_bar.clone().unwrap();
120 TabBarSettings {
121 show: tab_bar.show.unwrap(),
122 show_nav_history_buttons: tab_bar.show_nav_history_buttons.unwrap(),
123 show_tab_bar_buttons: tab_bar.show_tab_bar_buttons.unwrap(),
124 }
125 }
126}
127
128#[derive(Deserialize, RegisterSetting)]
129pub struct StatusBarSettings {
130 pub show: bool,
131 pub active_language_button: bool,
132 pub cursor_position_button: bool,
133 pub line_endings_button: bool,
134 pub active_encoding_button: EncodingDisplayOptions,
135}
136
137impl Settings for StatusBarSettings {
138 fn from_settings(content: &settings::SettingsContent) -> Self {
139 let status_bar = content.status_bar.clone().unwrap();
140 StatusBarSettings {
141 show: status_bar.show.unwrap(),
142 active_language_button: status_bar.active_language_button.unwrap(),
143 cursor_position_button: status_bar.cursor_position_button.unwrap(),
144 line_endings_button: status_bar.line_endings_button.unwrap(),
145 active_encoding_button: status_bar.active_encoding_button.unwrap(),
146 }
147 }
148}