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