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