1mod base_keymap_setting;
2mod editable_setting_control;
3mod keymap_file;
4mod settings_content;
5mod settings_file;
6mod settings_json;
7mod settings_store;
8mod settings_ui_core;
9mod vscode_import;
10
11use gpui::{App, Global};
12use rust_embed::RustEmbed;
13use std::{borrow::Cow, fmt, str};
14use util::asset_str;
15
16pub use base_keymap_setting::*;
17pub use editable_setting_control::*;
18pub use keymap_file::{
19 KeyBindingValidator, KeyBindingValidatorRegistration, KeybindSource, KeybindUpdateOperation,
20 KeybindUpdateTarget, KeymapFile, KeymapFileLoadResult,
21};
22pub use settings_file::*;
23pub use settings_json::*;
24pub use settings_store::{
25 InvalidSettingsError, LocalSettingsKind, Settings, SettingsKey, SettingsLocation,
26 SettingsSources, SettingsStore,
27};
28pub use settings_ui_core::*;
29// Re-export the derive macro
30pub use settings_ui_macros::{SettingsKey, SettingsUi};
31pub use vscode_import::{VsCodeSettings, VsCodeSettingsSource};
32
33#[derive(Clone, Debug, PartialEq)]
34pub struct ActiveSettingsProfileName(pub String);
35
36impl Global for ActiveSettingsProfileName {}
37
38#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, PartialOrd, Ord, serde::Serialize)]
39pub struct WorktreeId(usize);
40
41impl From<WorktreeId> for usize {
42 fn from(value: WorktreeId) -> Self {
43 value.0
44 }
45}
46
47impl WorktreeId {
48 pub fn from_usize(handle_id: usize) -> Self {
49 Self(handle_id)
50 }
51
52 pub fn from_proto(id: u64) -> Self {
53 Self(id as usize)
54 }
55
56 pub fn to_proto(self) -> u64 {
57 self.0 as u64
58 }
59
60 pub fn to_usize(self) -> usize {
61 self.0
62 }
63}
64
65impl fmt::Display for WorktreeId {
66 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67 std::fmt::Display::fmt(&self.0, f)
68 }
69}
70
71#[derive(RustEmbed)]
72#[folder = "../../assets"]
73#[include = "settings/*"]
74#[include = "keymaps/*"]
75#[exclude = "*.DS_Store"]
76pub struct SettingsAssets;
77
78pub fn init(cx: &mut App) {
79 let mut settings = SettingsStore::new(cx);
80 settings
81 .set_default_settings(&default_settings(), cx)
82 .unwrap();
83 cx.set_global(settings);
84 BaseKeymap::register(cx);
85 SettingsStore::observe_active_settings_profile_name(cx).detach();
86}
87
88pub fn default_settings() -> Cow<'static, str> {
89 asset_str::<SettingsAssets>("settings/default.json")
90}
91
92#[cfg(target_os = "macos")]
93pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-macos.json";
94
95#[cfg(target_os = "windows")]
96pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-windows.json";
97
98#[cfg(not(any(target_os = "macos", target_os = "windows")))]
99pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-linux.json";
100
101pub fn default_keymap() -> Cow<'static, str> {
102 asset_str::<SettingsAssets>(DEFAULT_KEYMAP_PATH)
103}
104
105pub const VIM_KEYMAP_PATH: &str = "keymaps/vim.json";
106
107pub fn vim_keymap() -> Cow<'static, str> {
108 asset_str::<SettingsAssets>(VIM_KEYMAP_PATH)
109}
110
111pub fn initial_user_settings_content() -> Cow<'static, str> {
112 asset_str::<SettingsAssets>("settings/initial_user_settings.json")
113}
114
115pub fn initial_server_settings_content() -> Cow<'static, str> {
116 asset_str::<SettingsAssets>("settings/initial_server_settings.json")
117}
118
119pub fn initial_project_settings_content() -> Cow<'static, str> {
120 asset_str::<SettingsAssets>("settings/initial_local_settings.json")
121}
122
123pub fn initial_keymap_content() -> Cow<'static, str> {
124 asset_str::<SettingsAssets>("keymaps/initial.json")
125}
126
127pub fn initial_tasks_content() -> Cow<'static, str> {
128 asset_str::<SettingsAssets>("settings/initial_tasks.json")
129}
130
131pub fn initial_debug_tasks_content() -> Cow<'static, str> {
132 asset_str::<SettingsAssets>("settings/initial_debug_tasks.json")
133}
134
135pub fn initial_local_debug_tasks_content() -> Cow<'static, str> {
136 asset_str::<SettingsAssets>("settings/initial_local_debug_tasks.json")
137}