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