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.  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:
parent
a1ed1a00b3
commit
d6d0d7d3e4
10 changed files with 312 additions and 10 deletions
42
crates/image_viewer/src/image_viewer_settings.rs
Normal file
42
crates/image_viewer/src/image_viewer_settings.rs
Normal 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),
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue