1mod editable_setting_control;
2mod json_schema;
3mod keymap_file;
4mod settings_file;
5mod settings_store;
6
7use gpui::AppContext;
8use rust_embed::RustEmbed;
9use std::{borrow::Cow, fmt, str};
10use util::asset_str;
11
12pub use editable_setting_control::*;
13pub use json_schema::*;
14pub use keymap_file::KeymapFile;
15pub use settings_file::*;
16pub use settings_store::{
17 InvalidSettingsError, Settings, SettingsLocation, SettingsSources, SettingsStore,
18};
19
20#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, PartialOrd, Ord)]
21pub struct WorktreeId(usize);
22
23impl From<WorktreeId> for usize {
24 fn from(value: WorktreeId) -> Self {
25 value.0
26 }
27}
28
29impl WorktreeId {
30 pub fn from_usize(handle_id: usize) -> Self {
31 Self(handle_id)
32 }
33
34 pub fn from_proto(id: u64) -> Self {
35 Self(id as usize)
36 }
37
38 pub fn to_proto(&self) -> u64 {
39 self.0 as u64
40 }
41
42 pub fn to_usize(&self) -> usize {
43 self.0
44 }
45}
46
47impl fmt::Display for WorktreeId {
48 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49 std::fmt::Display::fmt(&self.0, f)
50 }
51}
52
53#[derive(RustEmbed)]
54#[folder = "../../assets"]
55#[include = "settings/*"]
56#[include = "keymaps/*"]
57#[exclude = "*.DS_Store"]
58pub struct SettingsAssets;
59
60pub fn init(cx: &mut AppContext) {
61 let mut settings = SettingsStore::new(cx);
62 settings
63 .set_default_settings(&default_settings(), cx)
64 .unwrap();
65 cx.set_global(settings);
66}
67
68pub fn default_settings() -> Cow<'static, str> {
69 asset_str::<SettingsAssets>("settings/default.json")
70}
71
72#[cfg(target_os = "macos")]
73pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-macos.json";
74
75#[cfg(not(target_os = "macos"))]
76pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-linux.json";
77
78pub fn default_keymap() -> Cow<'static, str> {
79 asset_str::<SettingsAssets>(DEFAULT_KEYMAP_PATH)
80}
81
82pub fn vim_keymap() -> Cow<'static, str> {
83 asset_str::<SettingsAssets>("keymaps/vim.json")
84}
85
86pub fn initial_user_settings_content() -> Cow<'static, str> {
87 asset_str::<SettingsAssets>("settings/initial_user_settings.json")
88}
89
90pub fn initial_local_settings_content() -> Cow<'static, str> {
91 asset_str::<SettingsAssets>("settings/initial_local_settings.json")
92}
93
94pub fn initial_keymap_content() -> Cow<'static, str> {
95 asset_str::<SettingsAssets>("keymaps/initial.json")
96}
97
98pub fn initial_tasks_content() -> Cow<'static, str> {
99 asset_str::<SettingsAssets>("settings/initial_tasks.json")
100}