image_viewer: Fix image view tab icon lost (#17063)

Closes #16989 

Release Notes:

- N/A
This commit is contained in:
CharlesChen0823 2024-08-29 16:51:35 +08:00 committed by GitHub
parent 64fa7a5234
commit 804d1997f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View file

@ -16,6 +16,8 @@ doctest = false
anyhow.workspace = true
db.workspace = true
gpui.workspace = true
file_icons.workspace = true
ui.workspace = true
settings.workspace = true
workspace.workspace = true
project.workspace = true

View file

@ -7,11 +7,13 @@ use gpui::{
use persistence::IMAGE_VIEWER;
use ui::prelude::*;
use file_icons::FileIcons;
use project::{Project, ProjectEntryId, ProjectPath};
use settings::Settings;
use std::{ffi::OsStr, path::PathBuf};
use workspace::{
item::{Item, ProjectItem, SerializableItem, TabContentParams},
ItemId, Pane, Workspace, WorkspaceId,
ItemId, ItemSettings, Pane, Workspace, WorkspaceId,
};
const IMAGE_VIEWER_KIND: &str = "ImageView";
@ -85,6 +87,14 @@ impl Item for ImageView {
.into_any_element()
}
fn tab_icon(&self, cx: &WindowContext) -> Option<Icon> {
ItemSettings::get_global(cx)
.file_icons
.then(|| FileIcons::get_icon(self.path.as_path(), cx))
.flatten()
.map(|icon| Icon::from_path(icon))
}
fn clone_on_split(
&self,
_workspace_id: Option<WorkspaceId>,