workspace_settings.rs

  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    pub show_pinned_tabs_in_separate_row: bool,
 64}
 65
 66impl Settings for WorkspaceSettings {
 67    fn from_settings(content: &settings::SettingsContent) -> Self {
 68        let workspace = &content.workspace;
 69        Self {
 70            active_pane_modifiers: ActivePanelModifiers {
 71                border_size: Some(
 72                    workspace
 73                        .active_pane_modifiers
 74                        .unwrap()
 75                        .border_size
 76                        .unwrap(),
 77                ),
 78                inactive_opacity: Some(
 79                    workspace
 80                        .active_pane_modifiers
 81                        .unwrap()
 82                        .inactive_opacity
 83                        .unwrap(),
 84                ),
 85            },
 86            bottom_dock_layout: workspace.bottom_dock_layout.unwrap(),
 87            pane_split_direction_horizontal: workspace.pane_split_direction_horizontal.unwrap(),
 88            pane_split_direction_vertical: workspace.pane_split_direction_vertical.unwrap(),
 89            centered_layout: workspace.centered_layout.unwrap(),
 90            confirm_quit: workspace.confirm_quit.unwrap(),
 91            show_call_status_icon: workspace.show_call_status_icon.unwrap(),
 92            autosave: workspace.autosave.unwrap(),
 93            restore_on_startup: workspace.restore_on_startup.unwrap(),
 94            restore_on_file_reopen: workspace.restore_on_file_reopen.unwrap(),
 95            drop_target_size: workspace.drop_target_size.unwrap(),
 96            use_system_path_prompts: workspace.use_system_path_prompts.unwrap(),
 97            use_system_prompts: workspace.use_system_prompts.unwrap(),
 98            command_aliases: workspace.command_aliases.clone(),
 99            max_tabs: workspace.max_tabs,
100            when_closing_with_no_tabs: workspace.when_closing_with_no_tabs.unwrap(),
101            on_last_window_closed: workspace.on_last_window_closed.unwrap(),
102            text_rendering_mode: workspace.text_rendering_mode.unwrap(),
103            resize_all_panels_in_dock: workspace
104                .resize_all_panels_in_dock
105                .clone()
106                .unwrap()
107                .into_iter()
108                .map(Into::into)
109                .collect(),
110            close_on_file_delete: workspace.close_on_file_delete.unwrap(),
111            use_system_window_tabs: workspace.use_system_window_tabs.unwrap(),
112            zoomed_padding: workspace.zoomed_padding.unwrap(),
113            window_decorations: workspace.window_decorations.unwrap(),
114        }
115    }
116}
117
118impl Settings for TabBarSettings {
119    fn from_settings(content: &settings::SettingsContent) -> Self {
120        let tab_bar = content.tab_bar.clone().unwrap();
121        TabBarSettings {
122            show: tab_bar.show.unwrap(),
123            show_nav_history_buttons: tab_bar.show_nav_history_buttons.unwrap(),
124            show_tab_bar_buttons: tab_bar.show_tab_bar_buttons.unwrap(),
125            show_pinned_tabs_in_separate_row: tab_bar.show_pinned_tabs_in_separate_row.unwrap(),
126        }
127    }
128}
129
130#[derive(Deserialize, RegisterSetting)]
131pub struct StatusBarSettings {
132    pub show: bool,
133    pub active_language_button: bool,
134    pub cursor_position_button: bool,
135    pub line_endings_button: bool,
136    pub active_encoding_button: EncodingDisplayOptions,
137}
138
139impl Settings for StatusBarSettings {
140    fn from_settings(content: &settings::SettingsContent) -> Self {
141        let status_bar = content.status_bar.clone().unwrap();
142        StatusBarSettings {
143            show: status_bar.show.unwrap(),
144            active_language_button: status_bar.active_language_button.unwrap(),
145            cursor_position_button: status_bar.cursor_position_button.unwrap(),
146            line_endings_button: status_bar.line_endings_button.unwrap(),
147            active_encoding_button: status_bar.active_encoding_button.unwrap(),
148        }
149    }
150}