From 7be8dead07b86683a627a1fa2969b3947fc44f1c Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Mon, 22 May 2023 20:23:07 -0700 Subject: [PATCH] Add initial project panel settings --- Cargo.lock | 4 +++ assets/settings/default.json | 4 +++ crates/project_panel/Cargo.toml | 6 ++++ crates/project_panel/src/project_panel.rs | 7 ++++- .../src/project_panel_settings.rs | 29 +++++++++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 crates/project_panel/src/project_panel_settings.rs diff --git a/Cargo.lock b/Cargo.lock index 3ae96f4751..981005f3f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4886,6 +4886,7 @@ dependencies = [ name = "project_panel" version = "0.1.0" dependencies = [ + "anyhow", "client", "context_menu", "drag_and_drop", @@ -4896,6 +4897,9 @@ dependencies = [ "menu", "postage", "project", + "schemars", + "serde", + "serde_derive", "serde_json", "settings", "theme", diff --git a/assets/settings/default.json b/assets/settings/default.json index e4e7a8c522..38d0ce820b 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -70,6 +70,10 @@ // Whether to show git diff indicators in the scrollbar. "git_diff": true }, + "project_panel": { + // Whether to show the git status in the project panel. + "git_status": true + }, // Whether the screen sharing icon is shown in the os status bar. "show_call_status_icon": true, // Whether to use language servers to provide code intelligence. diff --git a/crates/project_panel/Cargo.toml b/crates/project_panel/Cargo.toml index 6fcdf06d2c..01d1be53b9 100644 --- a/crates/project_panel/Cargo.toml +++ b/crates/project_panel/Cargo.toml @@ -21,6 +21,12 @@ util = { path = "../util" } workspace = { path = "../workspace" } postage.workspace = true futures.workspace = true +serde.workspace = true +serde_derive.workspace = true +serde_json.workspace = true +anyhow.workspace = true +schemars.workspace = true + unicase = "2.6" [dev-dependencies] diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index a7895172d5..d4cd007454 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -1,3 +1,5 @@ +mod project_panel_settings; + use context_menu::{ContextMenu, ContextMenuItem}; use drag_and_drop::{DragAndDrop, Draggable}; use editor::{Cancel, Editor}; @@ -20,6 +22,7 @@ use project::{ repository::GitFileStatus, Entry, EntryKind, Project, ProjectEntryId, ProjectPath, Worktree, WorktreeId, }; +use project_panel_settings::ProjectPanelSettings; use std::{ cmp::Ordering, collections::{hash_map, HashMap}, @@ -111,6 +114,7 @@ actions!( ); pub fn init(cx: &mut AppContext) { + settings::register::(cx); cx.add_action(ProjectPanel::expand_selected_entry); cx.add_action(ProjectPanel::collapse_selected_entry); cx.add_action(ProjectPanel::select_prev); @@ -1000,6 +1004,7 @@ impl ProjectPanel { } let end_ix = range.end.min(ix + visible_worktree_entries.len()); + let git_status_setting = settings::get::(cx).git_status; if let Some(worktree) = self.project.read(cx).worktree_for_id(*worktree_id, cx) { let snapshot = worktree.read(cx).snapshot(); let root_name = OsStr::new(snapshot.root_name()); @@ -1013,7 +1018,7 @@ impl ProjectPanel { for (entry, repo) in snapshot.entries_with_repositories(visible_worktree_entries[entry_range].iter()) { - let status = (entry.path.parent().is_some() && !entry.is_ignored) + let status = (git_status_setting && entry.path.parent().is_some() && !entry.is_ignored) .then(|| repo.and_then(|repo| repo.status_for_path(&snapshot, &entry.path))) .flatten(); diff --git a/crates/project_panel/src/project_panel_settings.rs b/crates/project_panel/src/project_panel_settings.rs new file mode 100644 index 0000000000..01a15d089b --- /dev/null +++ b/crates/project_panel/src/project_panel_settings.rs @@ -0,0 +1,29 @@ +use serde_derive::{Deserialize, Serialize}; +use anyhow; +use settings::Setting; +use schemars::JsonSchema; + + +#[derive(Deserialize, Debug)] +pub struct ProjectPanelSettings { + pub git_status: bool, +} + +#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)] +pub struct ProjectPanelSettingsContent { + pub git_status: Option, +} + +impl Setting for ProjectPanelSettings { + const KEY: Option<&'static str> = Some("project_panel"); + + type FileContent = ProjectPanelSettingsContent; + + fn load( + default_value: &Self::FileContent, + user_values: &[&Self::FileContent], + _: &gpui::AppContext, + ) -> anyhow::Result { + Self::load_via_json_merge(default_value, user_values) + } +}