Add group setting titles

Co-authored-by: Ben Kunkle <ben@zed.dev>
This commit is contained in:
Anthony 2025-08-26 13:55:25 -04:00
parent ba9d109289
commit c1631b6e8c
3 changed files with 29 additions and 5 deletions

View file

@ -31,8 +31,9 @@ use util::{
pub type EditorconfigProperties = ec4rs::Properties;
use crate::{
ActiveSettingsProfileName, ParameterizedJsonSchema, SettingsJsonSchemaParams, VsCodeSettings,
WorktreeId, parse_json_with_comments, settings_ui::SettingsUI, update_value_in_json_text,
ActiveSettingsProfileName, ParameterizedJsonSchema, SettingsJsonSchemaParams, SettingsUIItem,
VsCodeSettings, WorktreeId, parse_json_with_comments, settings_ui::SettingsUI,
update_value_in_json_text,
};
/// A value that can be defined as a user setting.
@ -272,6 +273,7 @@ trait AnySettingValue: 'static + Send + Sync {
text: &mut String,
edits: &mut Vec<(Range<usize>, String)>,
);
fn settings_ui_item(&self) -> SettingsUIItem;
}
struct DeserializedSetting(Box<dyn Any>);
@ -604,6 +606,12 @@ impl SettingsStore {
rx
}
pub fn settings_ui_items(&self) -> impl IntoIterator<Item = SettingsUIItem> {
self.setting_values
.values()
.map(|item| item.settings_ui_item())
}
}
impl SettingsStore {
@ -1498,6 +1506,10 @@ impl<T: Settings> AnySettingValue for SettingValue<T> {
edits,
);
}
fn settings_ui_item(&self) -> SettingsUIItem {
T::ui_item()
}
}
#[cfg(test)]

View file

@ -5,7 +5,8 @@ use std::any::TypeId;
use command_palette_hooks::CommandPaletteFilter;
use editor::EditorSettingsControls;
use feature_flags::{FeatureFlag, FeatureFlagViewExt};
use gpui::{App, Entity, EventEmitter, FocusHandle, Focusable, actions};
use gpui::{App, Entity, EventEmitter, FocusHandle, Focusable, ReadGlobal, actions};
use settings::SettingsStore;
use ui::prelude::*;
use workspace::item::{Item, ItemEvent};
use workspace::{Workspace, with_active_or_new_workspace};
@ -72,7 +73,6 @@ pub fn init(cx: &mut App) {
.detach();
})
.detach();
}
pub struct SettingsPage {
@ -121,6 +121,17 @@ impl Render for SettingsPage {
.p_4()
.size_full()
.gap_4()
.children(
SettingsStore::global(cx)
.settings_ui_items()
.into_iter()
.flat_map(|item| match item.item {
settings::SettingsUIItemVariant::Group { path, group } => Some(path),
settings::SettingsUIItemVariant::Item { path, item } => todo!(),
settings::SettingsUIItemVariant::None => None,
})
.map(|group_name| Label::new(group_name).size(LabelSize::Large)),
)
.child(Label::new("Settings").size(LabelSize::Large))
.child(
v_flex().gap_1().child(Label::new("Appearance")).child(

View file

@ -1,9 +1,10 @@
use db::anyhow;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::{SettingsUI, Settings, SettingsSources};
use settings::{Settings, SettingsSources, SettingsUI};
#[derive(Copy, Clone, Deserialize, Debug, SettingsUI)]
#[settings_ui(group = "Title Bar")]
pub struct TitleBarSettings {
pub show_branch_icon: bool,
pub show_onboarding_banner: bool,