Add image dimension and file size information (#21675)

Closes https://github.com/zed-industries/zed/issues/21281

@jansol, kindly take a look when you're free.


![image](https://github.com/user-attachments/assets/da9a54fa-6284-4012-a243-7e355a5290d3)

Release Notes:

- Added dimensions and file size information for images.

---------

Co-authored-by: tims <0xtimsb@gmail.com>
Co-authored-by: Marshall Bowers <git@maxdeviant.com>
This commit is contained in:
Caleb! 2025-02-07 01:56:34 +01:00 committed by GitHub
parent a1ed1a00b3
commit d6d0d7d3e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 312 additions and 10 deletions

View file

@ -0,0 +1,42 @@
use gpui::App;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsSources};
/// The settings for the image viewer.
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, Default)]
pub struct ImageViewerSettings {
/// The unit to use for displaying image file sizes.
///
/// Default: "binary"
#[serde(default)]
pub unit: ImageFileSizeUnit,
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "snake_case")]
pub enum ImageFileSizeUnit {
/// Displays file size in binary units (e.g., KiB, MiB).
#[default]
Binary,
/// Displays file size in decimal units (e.g., KB, MB).
Decimal,
}
impl Settings for ImageViewerSettings {
const KEY: Option<&'static str> = Some("image_viewer");
type FileContent = Self;
fn load(
sources: SettingsSources<Self::FileContent>,
_: &mut App,
) -> Result<Self, anyhow::Error> {
SettingsSources::<Self::FileContent>::json_merge_with(
[sources.default]
.into_iter()
.chain(sources.user)
.chain(sources.server),
)
}
}