Struct settings2::SettingsStore
source · pub struct SettingsStore { /* private fields */ }
Expand description
A set of strongly-typed setting values defined via multiple JSON files.
Implementations§
source§impl SettingsStore
impl SettingsStore
sourcepub fn register_setting<T: Settings>(&mut self, cx: &mut AppContext)
pub fn register_setting<T: Settings>(&mut self, cx: &mut AppContext)
Add a new type of setting to the store.
sourcepub fn get<T: Settings>(&self, path: Option<(usize, &Path)>) -> &T
pub fn get<T: Settings>(&self, path: Option<(usize, &Path)>) -> &T
Get the value of a setting.
Panics if the given setting type has not been registered, or if there is no value for this setting.
sourcepub fn override_global<T: Settings>(&mut self, value: T)
pub fn override_global<T: Settings>(&mut self, value: T)
Override the global value for a setting.
The given value will be overwritten if the user settings file changes.
sourcepub fn raw_user_settings(&self) -> &Value
pub fn raw_user_settings(&self) -> &Value
Get the user’s settings as a raw JSON value.
This is only for debugging and reporting. For user-facing functionality, use the typed setting interface.
sourcepub fn new_text_for_update<T: Settings>(
&self,
old_text: String,
update: impl FnOnce(&mut T::FileContent)
) -> String
pub fn new_text_for_update<T: Settings>( &self, old_text: String, update: impl FnOnce(&mut T::FileContent) ) -> String
Update the value of a setting in a JSON file, returning the new text for that JSON file.
sourcepub fn edits_for_update<T: Settings>(
&self,
text: &str,
update: impl FnOnce(&mut T::FileContent)
) -> Vec<(Range<usize>, String)>
pub fn edits_for_update<T: Settings>( &self, text: &str, update: impl FnOnce(&mut T::FileContent) ) -> Vec<(Range<usize>, String)>
Update the value of a setting in a JSON file, returning a list of edits to apply to the JSON file.
sourcepub fn set_json_tab_size_callback<T: Settings>(
&mut self,
get_tab_size: fn(_: &T) -> Option<usize>
)
pub fn set_json_tab_size_callback<T: Settings>( &mut self, get_tab_size: fn(_: &T) -> Option<usize> )
Configure the tab sized when updating JSON files.
sourcepub fn set_default_settings(
&mut self,
default_settings_content: &str,
cx: &mut AppContext
) -> Result<()>
pub fn set_default_settings( &mut self, default_settings_content: &str, cx: &mut AppContext ) -> Result<()>
Set the default settings via a JSON string.
The string should contain a JSON object with a default value for every setting.
sourcepub fn set_user_settings(
&mut self,
user_settings_content: &str,
cx: &mut AppContext
) -> Result<()>
pub fn set_user_settings( &mut self, user_settings_content: &str, cx: &mut AppContext ) -> Result<()>
Set the user settings via a JSON string.
sourcepub fn set_local_settings(
&mut self,
root_id: usize,
path: Arc<Path>,
settings_content: Option<&str>,
cx: &mut AppContext
) -> Result<()>
pub fn set_local_settings( &mut self, root_id: usize, path: Arc<Path>, settings_content: Option<&str>, cx: &mut AppContext ) -> Result<()>
Add or remove a set of local settings via a JSON string.
sourcepub fn clear_local_settings(
&mut self,
root_id: usize,
cx: &mut AppContext
) -> Result<()>
pub fn clear_local_settings( &mut self, root_id: usize, cx: &mut AppContext ) -> Result<()>
Add or remove a set of local settings via a JSON string.