image viewer: Allow dropping images on pane (#21803)

Partially addresses #21484


https://github.com/user-attachments/assets/777da5de-15c3-4af3-a597-1835c0155326

Release Notes:

- Support opening images by dropping them onto a pane
This commit is contained in:
Bennet Bo Fenner 2024-12-10 15:01:14 +01:00 committed by GitHub
parent 96499b7b25
commit 58f9301253
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 7 deletions

View file

@ -108,10 +108,11 @@ impl Item for ImageView {
params.text_color()
};
let title = project_path
.path
.file_name()
.unwrap_or_else(|| project_path.path.as_os_str())
let title = self
.image_item
.read(cx)
.file
.file_name(cx)
.to_string_lossy()
.to_string();
Label::new(title)
@ -160,7 +161,7 @@ impl Item for ImageView {
}
fn breadcrumbs_text_for_image(project: &Project, image: &ImageItem, cx: &AppContext) -> String {
let path = image.path();
let path = image.file.file_name(cx);
if project.visible_worktrees(cx).count() <= 1 {
return path.to_string_lossy().to_string();
}

View file

@ -123,9 +123,17 @@ impl ProjectItem for ImageItem {
let path = path.clone();
let project = project.clone();
let ext = path
.path
let worktree_abs_path = project
.read(cx)
.worktree_for_id(path.worktree_id, cx)?
.read(cx)
.abs_path();
// Resolve the file extension from either the worktree path (if it's a single file)
// or from the project path's subpath.
let ext = worktree_abs_path
.extension()
.or_else(|| path.path.extension())
.and_then(OsStr::to_str)
.map(str::to_lowercase)
.unwrap_or_default();