mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-20 15:40:29 +01:00
e10b9b70ef
Closes #13304 Release Notes: - Add global `git status` and `git diff` on/off in one place instead of control everywhere We can first review to ensure this change meets both `Zed` and user requirements, as well as code rules. Currently, we only support user-level settings. We can wait for this PR: https://github.com/zed-industries/zed/pull/43173 to be merged, then modify it to support both user and project levels.
131 lines
4.3 KiB
Rust
131 lines
4.3 KiB
Rust
use editor::EditorSettings;
|
|
use gpui::Pixels;
|
|
use schemars::JsonSchema;
|
|
use serde::{Deserialize, Serialize};
|
|
use settings::{
|
|
DockSide, ProjectPanelEntrySpacing, ProjectPanelSortMode, RegisterSetting, Settings,
|
|
ShowDiagnostics, ShowIndentGuides,
|
|
};
|
|
use ui::{
|
|
px,
|
|
scrollbars::{ScrollbarVisibility, ShowScrollbar},
|
|
};
|
|
|
|
#[derive(Deserialize, Debug, Clone, Copy, PartialEq, RegisterSetting)]
|
|
pub struct ProjectPanelSettings {
|
|
pub button: bool,
|
|
pub hide_gitignore: bool,
|
|
pub default_width: Pixels,
|
|
pub dock: DockSide,
|
|
pub entry_spacing: ProjectPanelEntrySpacing,
|
|
pub file_icons: bool,
|
|
pub folder_icons: bool,
|
|
pub git_status: bool,
|
|
pub indent_size: f32,
|
|
pub indent_guides: IndentGuidesSettings,
|
|
pub sticky_scroll: bool,
|
|
pub auto_reveal_entries: bool,
|
|
pub auto_fold_dirs: bool,
|
|
pub starts_open: bool,
|
|
pub scrollbar: ScrollbarSettings,
|
|
pub show_diagnostics: ShowDiagnostics,
|
|
pub hide_root: bool,
|
|
pub hide_hidden: bool,
|
|
pub drag_and_drop: bool,
|
|
pub auto_open: AutoOpenSettings,
|
|
pub sort_mode: ProjectPanelSortMode,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
|
pub struct IndentGuidesSettings {
|
|
pub show: ShowIndentGuides,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
|
pub struct ScrollbarSettings {
|
|
/// When to show the scrollbar in the project panel.
|
|
///
|
|
/// Default: inherits editor scrollbar settings
|
|
pub show: Option<ShowScrollbar>,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
|
pub struct AutoOpenSettings {
|
|
pub on_create: bool,
|
|
pub on_paste: bool,
|
|
pub on_drop: bool,
|
|
}
|
|
|
|
impl AutoOpenSettings {
|
|
#[inline]
|
|
pub fn should_open_on_create(self) -> bool {
|
|
self.on_create
|
|
}
|
|
|
|
#[inline]
|
|
pub fn should_open_on_paste(self) -> bool {
|
|
self.on_paste
|
|
}
|
|
|
|
#[inline]
|
|
pub fn should_open_on_drop(self) -> bool {
|
|
self.on_drop
|
|
}
|
|
}
|
|
|
|
impl ScrollbarVisibility for ProjectPanelSettings {
|
|
fn visibility(&self, cx: &ui::App) -> ShowScrollbar {
|
|
self.scrollbar
|
|
.show
|
|
.unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show)
|
|
}
|
|
}
|
|
|
|
impl Settings for ProjectPanelSettings {
|
|
fn from_settings(content: &settings::SettingsContent) -> Self {
|
|
let project_panel = content.project_panel.clone().unwrap();
|
|
Self {
|
|
button: project_panel.button.unwrap(),
|
|
hide_gitignore: project_panel.hide_gitignore.unwrap(),
|
|
default_width: px(project_panel.default_width.unwrap()),
|
|
dock: project_panel.dock.unwrap(),
|
|
entry_spacing: project_panel.entry_spacing.unwrap(),
|
|
file_icons: project_panel.file_icons.unwrap(),
|
|
folder_icons: project_panel.folder_icons.unwrap(),
|
|
git_status: project_panel.git_status.unwrap()
|
|
&& content
|
|
.git
|
|
.unwrap()
|
|
.enabled
|
|
.unwrap()
|
|
.is_git_status_enabled(),
|
|
indent_size: project_panel.indent_size.unwrap(),
|
|
indent_guides: IndentGuidesSettings {
|
|
show: project_panel.indent_guides.unwrap().show.unwrap(),
|
|
},
|
|
sticky_scroll: project_panel.sticky_scroll.unwrap(),
|
|
auto_reveal_entries: project_panel.auto_reveal_entries.unwrap(),
|
|
auto_fold_dirs: project_panel.auto_fold_dirs.unwrap(),
|
|
starts_open: project_panel.starts_open.unwrap(),
|
|
scrollbar: ScrollbarSettings {
|
|
show: project_panel.scrollbar.unwrap().show.map(Into::into),
|
|
},
|
|
show_diagnostics: project_panel.show_diagnostics.unwrap(),
|
|
hide_root: project_panel.hide_root.unwrap(),
|
|
hide_hidden: project_panel.hide_hidden.unwrap(),
|
|
drag_and_drop: project_panel.drag_and_drop.unwrap(),
|
|
auto_open: {
|
|
let auto_open = project_panel.auto_open.unwrap();
|
|
AutoOpenSettings {
|
|
on_create: auto_open.on_create.unwrap(),
|
|
on_paste: auto_open.on_paste.unwrap(),
|
|
on_drop: auto_open.on_drop.unwrap(),
|
|
}
|
|
},
|
|
sort_mode: project_panel
|
|
.sort_mode
|
|
.unwrap_or(ProjectPanelSortMode::DirectoriesFirst),
|
|
}
|
|
}
|
|
}
|