workspace_settings.rs

  1use std::num::NonZeroUsize;
  2
  3use crate::DockPosition;
  4use collections::HashMap;
  5use serde::Deserialize;
  6pub use settings::AutosaveSetting;
  7pub use settings::{
  8    BottomDockLayout, PaneSplitDirectionHorizontal, PaneSplitDirectionVertical,
  9    RestoreOnStartupBehavior,
 10};
 11use settings::{InactiveOpacity, Settings};
 12
 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 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}
 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)]
 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        }
110    }
111}
112
113impl Settings for TabBarSettings {
114    fn from_settings(content: &settings::SettingsContent) -> Self {
115        let tab_bar = content.tab_bar.clone().unwrap();
116        TabBarSettings {
117            show: tab_bar.show.unwrap(),
118            show_nav_history_buttons: tab_bar.show_nav_history_buttons.unwrap(),
119            show_tab_bar_buttons: tab_bar.show_tab_bar_buttons.unwrap(),
120        }
121    }
122}
123
124#[derive(Deserialize)]
125pub struct StatusBarSettings {
126    pub show: bool,
127    pub active_language_button: bool,
128    pub cursor_position_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        }
139    }
140}