This PR separates out the associated constant `KEY` from the `Settings` trait into a new trait `SettingsKey`. This allows for the key trait to be derived using attributes to specify the path so that the new `SettingsUi` derive macro can use the same attributes to determine top level settings paths thereby removing the need to duplicate the path in both `Settings::KEY` and `#[settings_ui(path = "...")]` Co-authored-by: Ben Kunkle <ben@zed.dev> Release Notes: - N/A --------- Co-authored-by: Ben Kunkle <ben@zed.dev>
137 lines
3.7 KiB
Rust
137 lines
3.7 KiB
Rust
mod base_keymap_setting;
|
|
mod editable_setting_control;
|
|
mod keymap_file;
|
|
mod settings_file;
|
|
mod settings_json;
|
|
mod settings_store;
|
|
mod settings_ui_core;
|
|
mod vscode_import;
|
|
|
|
use gpui::{App, Global};
|
|
use rust_embed::RustEmbed;
|
|
use std::{borrow::Cow, fmt, str};
|
|
use util::asset_str;
|
|
|
|
pub use base_keymap_setting::*;
|
|
pub use editable_setting_control::*;
|
|
pub use keymap_file::{
|
|
KeyBindingValidator, KeyBindingValidatorRegistration, KeybindSource, KeybindUpdateOperation,
|
|
KeybindUpdateTarget, KeymapFile, KeymapFileLoadResult,
|
|
};
|
|
pub use settings_file::*;
|
|
pub use settings_json::*;
|
|
pub use settings_store::{
|
|
InvalidSettingsError, LocalSettingsKind, Settings, SettingsKey, SettingsLocation,
|
|
SettingsSources, SettingsStore,
|
|
};
|
|
pub use settings_ui_core::*;
|
|
// Re-export the derive macro
|
|
pub use settings_ui_macros::{SettingsKey, SettingsUi};
|
|
pub use vscode_import::{VsCodeSettings, VsCodeSettingsSource};
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct ActiveSettingsProfileName(pub String);
|
|
|
|
impl Global for ActiveSettingsProfileName {}
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, PartialOrd, Ord, serde::Serialize)]
|
|
pub struct WorktreeId(usize);
|
|
|
|
impl From<WorktreeId> for usize {
|
|
fn from(value: WorktreeId) -> Self {
|
|
value.0
|
|
}
|
|
}
|
|
|
|
impl WorktreeId {
|
|
pub fn from_usize(handle_id: usize) -> Self {
|
|
Self(handle_id)
|
|
}
|
|
|
|
pub fn from_proto(id: u64) -> Self {
|
|
Self(id as usize)
|
|
}
|
|
|
|
pub fn to_proto(self) -> u64 {
|
|
self.0 as u64
|
|
}
|
|
|
|
pub fn to_usize(self) -> usize {
|
|
self.0
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for WorktreeId {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
std::fmt::Display::fmt(&self.0, f)
|
|
}
|
|
}
|
|
|
|
#[derive(RustEmbed)]
|
|
#[folder = "../../assets"]
|
|
#[include = "settings/*"]
|
|
#[include = "keymaps/*"]
|
|
#[exclude = "*.DS_Store"]
|
|
pub struct SettingsAssets;
|
|
|
|
pub fn init(cx: &mut App) {
|
|
let mut settings = SettingsStore::new(cx);
|
|
settings
|
|
.set_default_settings(&default_settings(), cx)
|
|
.unwrap();
|
|
cx.set_global(settings);
|
|
BaseKeymap::register(cx);
|
|
SettingsStore::observe_active_settings_profile_name(cx).detach();
|
|
}
|
|
|
|
pub fn default_settings() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>("settings/default.json")
|
|
}
|
|
|
|
#[cfg(target_os = "macos")]
|
|
pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-macos.json";
|
|
|
|
#[cfg(target_os = "windows")]
|
|
pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-windows.json";
|
|
|
|
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
|
|
pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-linux.json";
|
|
|
|
pub fn default_keymap() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>(DEFAULT_KEYMAP_PATH)
|
|
}
|
|
|
|
pub const VIM_KEYMAP_PATH: &str = "keymaps/vim.json";
|
|
|
|
pub fn vim_keymap() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>(VIM_KEYMAP_PATH)
|
|
}
|
|
|
|
pub fn initial_user_settings_content() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>("settings/initial_user_settings.json")
|
|
}
|
|
|
|
pub fn initial_server_settings_content() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>("settings/initial_server_settings.json")
|
|
}
|
|
|
|
pub fn initial_project_settings_content() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>("settings/initial_local_settings.json")
|
|
}
|
|
|
|
pub fn initial_keymap_content() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>("keymaps/initial.json")
|
|
}
|
|
|
|
pub fn initial_tasks_content() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>("settings/initial_tasks.json")
|
|
}
|
|
|
|
pub fn initial_debug_tasks_content() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>("settings/initial_debug_tasks.json")
|
|
}
|
|
|
|
pub fn initial_local_debug_tasks_content() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>("settings/initial_local_debug_tasks.json")
|
|
}
|