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