settings_ui: Collect all settings files (#38816)

Closes #ISSUE

Updates the settings editor to collect all known settings files from the
settings store, in order to show them in the UI. Additionally adds a
fake worktree instantiation in the settings UI example binary in order
to have more than one file available when testing.

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Ben Kunkle
2025-09-24 21:16:06 +00:00
committed by GitHub
parent ed7bd5a8ed
commit 523c042930
8 changed files with 157 additions and 19 deletions
+38 -13
View File
@@ -200,7 +200,7 @@ struct SettingItem {
}
#[allow(unused)]
#[derive(Clone)]
#[derive(Clone, PartialEq)]
enum SettingsFile {
User, // Uses all settings.
Local((WorktreeId, Arc<Path>)), // Has a special name, and special set of settings
@@ -216,11 +216,11 @@ impl SettingsFile {
}
}
fn name(&self) -> String {
fn name(&self) -> SharedString {
match self {
SettingsFile::User => "User".to_string(),
SettingsFile::Local((_, path)) => format!("Local ({})", path.display()),
SettingsFile::Server(file) => format!("Server ({})", file),
SettingsFile::User => SharedString::new_static("User"),
SettingsFile::Local((_, path)) => format!("Local ({})", path.display()).into(),
SettingsFile::Server(file) => format!("Server ({})", file).into(),
}
}
}
@@ -234,22 +234,18 @@ impl SettingsWindow {
editor
});
let mut this = Self {
files: vec![
SettingsFile::User,
SettingsFile::Local((
WorktreeId::from_usize(0),
Arc::from(Path::new("/my-project/")),
)),
],
files: vec![],
current_file: current_file,
pages: vec![],
current_page: 0,
search,
};
cx.observe_global_in::<SettingsStore>(window, move |_, _, cx| {
cx.observe_global_in::<SettingsStore>(window, move |this, _, cx| {
this.fetch_files(cx);
cx.notify();
})
.detach();
this.fetch_files(cx);
this.build_ui();
this
@@ -259,7 +255,36 @@ impl SettingsWindow {
self.pages = self.current_file.pages();
}
fn fetch_files(&mut self, cx: &mut App) {
let settings_store = cx.global::<SettingsStore>();
let mut ui_files = vec![];
let all_files = settings_store.get_all_files();
for file in all_files {
let settings_ui_file = match file {
settings::SettingsFile::User => SettingsFile::User,
settings::SettingsFile::Global => continue,
settings::SettingsFile::Extension => continue,
settings::SettingsFile::Server => SettingsFile::Server("todo: server name"),
settings::SettingsFile::Default => continue,
settings::SettingsFile::Local(location) => SettingsFile::Local(location),
};
ui_files.push(settings_ui_file);
}
ui_files.reverse();
if !ui_files.contains(&self.current_file) {
self.change_file(0);
}
self.files = ui_files;
}
fn change_file(&mut self, ix: usize) {
if ix >= self.files.len() {
self.current_file = SettingsFile::User;
return;
}
if self.files[ix] == self.current_file {
return;
}
self.current_file = self.files[ix].clone();
self.build_ui();
}