settings: Remove auxiliary Content types where possible (#16744)
Release Notes: - N/A
This commit is contained in:
parent
8f28445612
commit
ccf6f27b8f
49 changed files with 843 additions and 696 deletions
|
@ -36,20 +36,49 @@ use util::ResultExt;
|
|||
|
||||
pub const LEADER_UPDATE_THROTTLE: Duration = Duration::from_millis(200);
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(default)]
|
||||
pub struct ItemSettings {
|
||||
/// Whether to show the Git file status on a tab item.
|
||||
pub git_status: bool,
|
||||
/// Position of the close button in a tab.
|
||||
pub close_position: ClosePosition,
|
||||
/// Whether to show the file icon for a tab.
|
||||
pub file_icons: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
impl Default for ItemSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
git_status: false,
|
||||
close_position: ClosePosition::Right,
|
||||
file_icons: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(default)]
|
||||
pub struct PreviewTabsSettings {
|
||||
/// Whether to show opened editors as preview tabs.
|
||||
/// Preview tabs do not stay open, are reused until explicitly set to be kept open opened (via double-click or editing) and show file names in italic.
|
||||
pub enabled: bool,
|
||||
/// Whether to open tabs in preview mode when selected from the file finder.
|
||||
pub enable_preview_from_file_finder: bool,
|
||||
/// Whether a preview tab gets replaced when code navigation is used to navigate away from the tab.
|
||||
pub enable_preview_from_code_navigation: bool,
|
||||
}
|
||||
|
||||
impl Default for PreviewTabsSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: true,
|
||||
enable_preview_from_file_finder: false,
|
||||
enable_preview_from_code_navigation: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ClosePosition {
|
||||
|
@ -67,43 +96,10 @@ impl ClosePosition {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct ItemSettingsContent {
|
||||
/// Whether to show the Git file status on a tab item.
|
||||
///
|
||||
/// Default: false
|
||||
git_status: Option<bool>,
|
||||
/// Position of the close button in a tab.
|
||||
///
|
||||
/// Default: right
|
||||
close_position: Option<ClosePosition>,
|
||||
/// Whether to show the file icon for a tab.
|
||||
///
|
||||
/// Default: false
|
||||
file_icons: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct PreviewTabsSettingsContent {
|
||||
/// Whether to show opened editors as preview tabs.
|
||||
/// Preview tabs do not stay open, are reused until explicitly set to be kept open opened (via double-click or editing) and show file names in italic.
|
||||
///
|
||||
/// Default: true
|
||||
enabled: Option<bool>,
|
||||
/// Whether to open tabs in preview mode when selected from the file finder.
|
||||
///
|
||||
/// Default: false
|
||||
enable_preview_from_file_finder: Option<bool>,
|
||||
/// Whether a preview tab gets replaced when code navigation is used to navigate away from the tab.
|
||||
///
|
||||
/// Default: false
|
||||
enable_preview_from_code_navigation: Option<bool>,
|
||||
}
|
||||
|
||||
impl Settings for ItemSettings {
|
||||
const KEY: Option<&'static str> = Some("tabs");
|
||||
|
||||
type FileContent = ItemSettingsContent;
|
||||
type FileContent = Self;
|
||||
|
||||
fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
|
||||
sources.json_merge()
|
||||
|
@ -113,7 +109,7 @@ impl Settings for ItemSettings {
|
|||
impl Settings for PreviewTabsSettings {
|
||||
const KEY: Option<&'static str> = Some("preview_tabs");
|
||||
|
||||
type FileContent = PreviewTabsSettingsContent;
|
||||
type FileContent = Self;
|
||||
|
||||
fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
|
||||
sources.json_merge()
|
||||
|
|
|
@ -6418,7 +6418,7 @@ mod tests {
|
|||
item.update(cx, |item, cx| {
|
||||
SettingsStore::update_global(cx, |settings, cx| {
|
||||
settings.update_user_settings::<WorkspaceSettings>(cx, |settings| {
|
||||
settings.autosave = Some(AutosaveSetting::OnWindowChange);
|
||||
settings.autosave = AutosaveSetting::OnWindowChange;
|
||||
})
|
||||
});
|
||||
item.is_dirty = true;
|
||||
|
@ -6438,7 +6438,7 @@ mod tests {
|
|||
cx.focus_self();
|
||||
SettingsStore::update_global(cx, |settings, cx| {
|
||||
settings.update_user_settings::<WorkspaceSettings>(cx, |settings| {
|
||||
settings.autosave = Some(AutosaveSetting::OnFocusChange);
|
||||
settings.autosave = AutosaveSetting::OnFocusChange;
|
||||
})
|
||||
});
|
||||
item.is_dirty = true;
|
||||
|
@ -6461,7 +6461,7 @@ mod tests {
|
|||
item.update(cx, |item, cx| {
|
||||
SettingsStore::update_global(cx, |settings, cx| {
|
||||
settings.update_user_settings::<WorkspaceSettings>(cx, |settings| {
|
||||
settings.autosave = Some(AutosaveSetting::AfterDelay { milliseconds: 500 });
|
||||
settings.autosave = AutosaveSetting::AfterDelay { milliseconds: 500 };
|
||||
})
|
||||
});
|
||||
item.is_dirty = true;
|
||||
|
@ -6480,7 +6480,7 @@ mod tests {
|
|||
item.update(cx, |item, cx| {
|
||||
SettingsStore::update_global(cx, |settings, cx| {
|
||||
settings.update_user_settings::<WorkspaceSettings>(cx, |settings| {
|
||||
settings.autosave = Some(AutosaveSetting::OnFocusChange);
|
||||
settings.autosave = AutosaveSetting::OnFocusChange;
|
||||
})
|
||||
});
|
||||
item.is_dirty = true;
|
||||
|
|
|
@ -5,22 +5,58 @@ use schemars::JsonSchema;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use settings::{Settings, SettingsSources};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(default)]
|
||||
pub struct WorkspaceSettings {
|
||||
/// Scale by which to zoom the active pane.
|
||||
/// When set to 1.0, the active pane has the same size as others,
|
||||
/// but when set to a larger value, the active pane takes up more space.
|
||||
pub active_pane_magnification: f32,
|
||||
/// Direction to split horizontally.
|
||||
pub pane_split_direction_horizontal: PaneSplitDirectionHorizontal,
|
||||
/// Direction to split vertically.
|
||||
pub pane_split_direction_vertical: PaneSplitDirectionVertical,
|
||||
/// Centered layout related settings.
|
||||
pub centered_layout: CenteredLayoutSettings,
|
||||
/// Whether or not to prompt the user to confirm before closing the application.
|
||||
pub confirm_quit: bool,
|
||||
/// Whether or not to show the call status icon in the status bar.
|
||||
pub show_call_status_icon: bool,
|
||||
/// When to automatically save edited buffers.
|
||||
pub autosave: AutosaveSetting,
|
||||
/// Controls previous session restoration in freshly launched Zed instance.
|
||||
pub restore_on_startup: RestoreOnStartupBehavior,
|
||||
/// The size of the workspace split drop targets on the outer edges.
|
||||
/// Given as a fraction that will be multiplied by the smaller dimension of the workspace.
|
||||
pub drop_target_size: f32,
|
||||
/// Whether to close the window when using 'close active item' on a workspace with no tabs
|
||||
pub when_closing_with_no_tabs: CloseWindowWhenNoItems,
|
||||
/// Whether to use the system provided dialogs for Open and Save As.
|
||||
/// When set to false, Zed will use the built-in keyboard-first pickers.
|
||||
pub use_system_path_prompts: bool,
|
||||
/// Aliases for the command palette. When you type a key in this map,
|
||||
/// it will be assumed to equal the value.
|
||||
pub command_aliases: HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl Default for WorkspaceSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
active_pane_magnification: 1.0,
|
||||
pane_split_direction_horizontal: PaneSplitDirectionHorizontal::Up,
|
||||
pane_split_direction_vertical: PaneSplitDirectionVertical::Left,
|
||||
centered_layout: CenteredLayoutSettings::default(),
|
||||
confirm_quit: false,
|
||||
show_call_status_icon: true,
|
||||
autosave: AutosaveSetting::Off,
|
||||
restore_on_startup: RestoreOnStartupBehavior::default(),
|
||||
drop_target_size: 0.2,
|
||||
when_closing_with_no_tabs: CloseWindowWhenNoItems::default(),
|
||||
use_system_path_prompts: true,
|
||||
command_aliases: HashMap::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum CloseWindowWhenNoItems {
|
||||
|
@ -55,77 +91,22 @@ pub enum RestoreOnStartupBehavior {
|
|||
LastSession,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct WorkspaceSettingsContent {
|
||||
/// Scale by which to zoom the active pane.
|
||||
/// When set to 1.0, the active pane has the same size as others,
|
||||
/// but when set to a larger value, the active pane takes up more space.
|
||||
///
|
||||
/// Default: `1.0`
|
||||
pub active_pane_magnification: Option<f32>,
|
||||
// Direction to split horizontally.
|
||||
//
|
||||
// Default: "up"
|
||||
pub pane_split_direction_horizontal: Option<PaneSplitDirectionHorizontal>,
|
||||
// Direction to split vertically.
|
||||
//
|
||||
// Default: "left"
|
||||
pub pane_split_direction_vertical: Option<PaneSplitDirectionVertical>,
|
||||
// Centered layout related settings.
|
||||
pub centered_layout: Option<CenteredLayoutSettings>,
|
||||
/// Whether or not to prompt the user to confirm before closing the application.
|
||||
///
|
||||
/// Default: false
|
||||
pub confirm_quit: Option<bool>,
|
||||
/// Whether or not to show the call status icon in the status bar.
|
||||
///
|
||||
/// Default: true
|
||||
pub show_call_status_icon: Option<bool>,
|
||||
/// When to automatically save edited buffers.
|
||||
///
|
||||
/// Default: off
|
||||
pub autosave: Option<AutosaveSetting>,
|
||||
/// Controls previous session restoration in freshly launched Zed instance.
|
||||
/// Values: none, last_workspace, last_session
|
||||
/// Default: last_session
|
||||
pub restore_on_startup: Option<RestoreOnStartupBehavior>,
|
||||
/// The size of the workspace split drop targets on the outer edges.
|
||||
/// Given as a fraction that will be multiplied by the smaller dimension of the workspace.
|
||||
///
|
||||
/// Default: `0.2` (20% of the smaller dimension of the workspace)
|
||||
pub drop_target_size: Option<f32>,
|
||||
/// Whether to close the window when using 'close active item' on a workspace with no tabs
|
||||
///
|
||||
/// Default: auto ("on" on macOS, "off" otherwise)
|
||||
pub when_closing_with_no_tabs: Option<CloseWindowWhenNoItems>,
|
||||
/// Whether to use the system provided dialogs for Open and Save As.
|
||||
/// When set to false, Zed will use the built-in keyboard-first pickers.
|
||||
///
|
||||
/// Default: true
|
||||
pub use_system_path_prompts: Option<bool>,
|
||||
/// Aliases for the command palette. When you type a key in this map,
|
||||
/// it will be assumed to equal the value.
|
||||
///
|
||||
/// Default: true
|
||||
pub command_aliases: Option<HashMap<String, String>>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(default)]
|
||||
pub struct TabBarSettings {
|
||||
/// Whether or not to show the tab bar in the editor.
|
||||
pub show: bool,
|
||||
/// Whether or not to show the navigation history buttons in the tab bar.
|
||||
pub show_nav_history_buttons: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct TabBarSettingsContent {
|
||||
/// Whether or not to show the tab bar in the editor.
|
||||
///
|
||||
/// Default: true
|
||||
pub show: Option<bool>,
|
||||
/// Whether or not to show the navigation history buttons in the tab bar.
|
||||
///
|
||||
/// Default: true
|
||||
pub show_nav_history_buttons: Option<bool>,
|
||||
impl Default for TabBarSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
show_nav_history_buttons: true,
|
||||
show: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||
|
@ -163,17 +144,26 @@ pub struct CenteredLayoutSettings {
|
|||
///
|
||||
/// Default: 0.2
|
||||
pub left_padding: Option<f32>,
|
||||
// The relative width of the right padding of the central pane from the
|
||||
// workspace when the centered layout is used.
|
||||
/// The relative width of the right padding of the central pane from the
|
||||
/// workspace when the centered layout is used.
|
||||
///
|
||||
/// Default: 0.2
|
||||
pub right_padding: Option<f32>,
|
||||
}
|
||||
|
||||
impl Default for CenteredLayoutSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
left_padding: Some(0.2),
|
||||
right_padding: Some(0.2),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Settings for WorkspaceSettings {
|
||||
const KEY: Option<&'static str> = None;
|
||||
|
||||
type FileContent = WorkspaceSettingsContent;
|
||||
type FileContent = Self;
|
||||
|
||||
fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
|
||||
sources.json_merge()
|
||||
|
@ -183,7 +173,7 @@ impl Settings for WorkspaceSettings {
|
|||
impl Settings for TabBarSettings {
|
||||
const KEY: Option<&'static str> = Some("tab_bar");
|
||||
|
||||
type FileContent = TabBarSettingsContent;
|
||||
type FileContent = Self;
|
||||
|
||||
fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
|
||||
sources.json_merge()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue