image_viewer_settings.rs

 1use gpui::App;
 2use schemars::JsonSchema;
 3use serde::{Deserialize, Serialize};
 4use settings::{Settings, SettingsSources};
 5
 6/// The settings for the image viewer.
 7#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, Default)]
 8pub struct ImageViewerSettings {
 9    /// The unit to use for displaying image file sizes.
10    ///
11    /// Default: "binary"
12    #[serde(default)]
13    pub unit: ImageFileSizeUnit,
14}
15
16#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, Default)]
17#[serde(rename_all = "snake_case")]
18pub enum ImageFileSizeUnit {
19    /// Displays file size in binary units (e.g., KiB, MiB).
20    #[default]
21    Binary,
22    /// Displays file size in decimal units (e.g., KB, MB).
23    Decimal,
24}
25
26impl Settings for ImageViewerSettings {
27    const KEY: Option<&'static str> = Some("image_viewer");
28
29    type FileContent = Self;
30
31    fn load(
32        sources: SettingsSources<Self::FileContent>,
33        _: &mut App,
34    ) -> Result<Self, anyhow::Error> {
35        SettingsSources::<Self::FileContent>::json_merge_with(
36            [sources.default]
37                .into_iter()
38                .chain(sources.user)
39                .chain(sources.server),
40        )
41    }
42
43    fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {}
44}