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