Add basic ico support (#40822)

Closes https://github.com/zed-industries/zed/discussions/40763

<img width="867" height="1088" alt="Screenshot 2025-10-21 at 23 14 47"
src="https://github.com/user-attachments/assets/d691fb2a-afc6-4445-a335-054ef164e0d3"
/>

Also improves error handling on image open failure:

<img width="864" height="1083" alt="Screenshot 2025-10-21 at 23 14 30"
src="https://github.com/user-attachments/assets/d5388b61-995f-441b-b375-ad5136d1533b"
/>


Release Notes:

- Added basic ico support, improved unsupported image handling
This commit is contained in:
Kirill Bulatov
2025-10-22 12:07:32 +03:00
committed by GitHub
parent 8ceb2f2c61
commit bc0bace81f
13 changed files with 166 additions and 17 deletions
@@ -10,17 +10,17 @@ use zed_actions::workspace::OpenWithSystem;
use crate::Item;
/// A view to display when a certain buffer fails to open.
pub struct InvalidBufferView {
/// A view to display when a certain buffer/image/other item fails to open.
pub struct InvalidItemView {
/// Which path was attempted to open.
pub abs_path: Arc<Path>,
/// An error message, happened when opening the buffer.
/// An error message, happened when opening the item.
pub error: SharedString,
is_local: bool,
focus_handle: FocusHandle,
}
impl InvalidBufferView {
impl InvalidItemView {
pub fn new(
abs_path: &Path,
is_local: bool,
@@ -37,7 +37,7 @@ impl InvalidBufferView {
}
}
impl Item for InvalidBufferView {
impl Item for InvalidItemView {
type Event = ();
fn tab_content_text(&self, mut detail: usize, _: &App) -> SharedString {
@@ -66,15 +66,15 @@ impl Item for InvalidBufferView {
}
}
impl EventEmitter<()> for InvalidBufferView {}
impl EventEmitter<()> for InvalidItemView {}
impl Focusable for InvalidBufferView {
impl Focusable for InvalidItemView {
fn focus_handle(&self, _: &App) -> FocusHandle {
self.focus_handle.clone()
}
}
impl Render for InvalidBufferView {
impl Render for InvalidItemView {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl gpui::IntoElement {
let abs_path = self.abs_path.clone();
v_flex()
@@ -83,7 +83,7 @@ impl Render for InvalidBufferView {
.flex_none()
.justify_center()
.overflow_hidden()
.key_context("InvalidBuffer")
.key_context("InvalidItem")
.child(
h_flex().size_full().justify_center().child(
v_flex()
+2 -2
View File
@@ -1,7 +1,7 @@
use crate::{
CollaboratorId, DelayedDebouncedEditAction, FollowableViewRegistry, ItemNavHistory,
SerializableItemRegistry, ToolbarItemLocation, ViewId, Workspace, WorkspaceId,
invalid_buffer_view::InvalidBufferView,
invalid_item_view::InvalidItemView,
pane::{self, Pane},
persistence::model::ItemId,
searchable::SearchableItemHandle,
@@ -1062,7 +1062,7 @@ pub trait ProjectItem: Item {
_e: &anyhow::Error,
_window: &mut Window,
_cx: &mut App,
) -> Option<InvalidBufferView>
) -> Option<InvalidItemView>
where
Self: Sized,
{
+3 -3
View File
@@ -2,7 +2,7 @@ use crate::{
CloseWindow, NewFile, NewTerminal, OpenInTerminal, OpenOptions, OpenTerminal, OpenVisible,
SplitDirection, ToggleFileFinder, ToggleProjectSymbols, ToggleZoom, Workspace,
WorkspaceItemBuilder,
invalid_buffer_view::InvalidBufferView,
invalid_item_view::InvalidItemView,
item::{
ActivateOnClose, ClosePosition, Item, ItemBufferKind, ItemHandle, ItemSettings,
PreviewTabsSettings, ProjectItemKind, SaveOptions, ShowCloseButton, ShowDiagnostics,
@@ -992,11 +992,11 @@ impl Pane {
let new_item = build_item(self, window, cx);
// A special case that won't ever get a `project_entry_id` but has to be deduplicated nonetheless.
if let Some(invalid_buffer_view) = new_item.downcast::<InvalidBufferView>() {
if let Some(invalid_buffer_view) = new_item.downcast::<InvalidItemView>() {
let mut already_open_view = None;
let mut views_to_close = HashSet::default();
for existing_error_view in self
.items_of_type::<InvalidBufferView>()
.items_of_type::<InvalidItemView>()
.filter(|item| item.read(cx).abs_path == invalid_buffer_view.read(cx).abs_path)
{
if already_open_view.is_none()
+1 -1
View File
@@ -1,6 +1,6 @@
pub mod dock;
pub mod history_manager;
pub mod invalid_buffer_view;
pub mod invalid_item_view;
pub mod item;
mod modal_layer;
pub mod notifications;