workspace_settings.rs

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