Files · Items: one icon map, file icon, file row and file grid
The crate had two maps from a file's name to its icon, in chat and in the file tree, and they disagreed. One map now lives in primitives, over the Lucide file-* icons, and chat, agent, the file tree and the directory listing use it. FileIcon draws it for a file or a folder. FileItem is a file's row, a ListItem with its size and when it changed. FileList is the directory listing. FileGrid lays tiles in the order given, with a cursor seeded from the owner's pick: arrows by tile and by row, Home, End, Enter and a double press to open. The count of what fits a width has one home, layout's columns_for, and fit builds on it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9872adc5e9
commit
ebad5328ed
36 files changed
+1024
-77
No files matched your search
@@ -0,0 +1,55 @@
|
||||
use gpui::{App, IntoElement, RenderOnce, Window};
|
||||
|
||||
use crate::{
|
||||
lists::DirEntry,
|
||||
primitives::{Icon, IconName, file_icon},
|
||||
theme::{ActiveTheme, IconSize},
|
||||
};
|
||||
|
||||
/// A file's icon by its name's extension, or a folder's, open or shut.
|
||||
#[derive(IntoElement)]
|
||||
pub struct FileIcon {
|
||||
icon: IconName,
|
||||
size: IconSize,
|
||||
}
|
||||
|
||||
impl FileIcon {
|
||||
pub fn file(name: impl AsRef<str>) -> Self {
|
||||
Self {
|
||||
icon: file_icon(name.as_ref()),
|
||||
size: IconSize::Md,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn folder(open: bool) -> Self {
|
||||
Self {
|
||||
icon: if open {
|
||||
IconName::FolderOpen
|
||||
} else {
|
||||
IconName::Folder
|
||||
},
|
||||
size: IconSize::Md,
|
||||
}
|
||||
}
|
||||
|
||||
/// The icon for a listing's entry: a shut folder, or the file's by its name.
|
||||
pub fn entry(entry: &DirEntry) -> Self {
|
||||
match entry.is_folder() {
|
||||
true => Self::folder(false),
|
||||
false => Self::file(entry.name()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn size(mut self, size: IconSize) -> Self {
|
||||
self.size = size;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for FileIcon {
|
||||
fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
Icon::new(self.icon)
|
||||
.size(self.size)
|
||||
.color(cx.theme().colors.fg_muted)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user