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