file manager
git clone https://git.lucas.co/cce-files.git
src/pages/preview.rs (1.9K)
1 use std::path::PathBuf;
2
3 use crate::preview_pane::PreviewPane;
4
5 // ── Data ────────────────────────────────────────────────────────────
6
7 #[derive(Debug, Clone)]
8 pub enum PreviewMessage {
9 SetPath { path: PathBuf },
10 Clear,
11 /// `generation` is the request's (`FsRequest::ReadPreview`); the app
12 /// drops any but the newest before it gets here.
13 PreviewLoaded { path: PathBuf, generation: u64, data: crate::services::fs::PreviewData },
14 }
15
16 // ── Update ──────────────────────────────────────────────────────────
17
18 pub fn update(state: &mut PreviewPane, msg: PreviewMessage) {
19 match msg {
20 PreviewMessage::Clear => {
21 // Free the texture BEFORE the wholesale replace — a plain
22 // Default::default() swap would leak the uploaded id.
23 state.set_image(None);
24 *state = PreviewPane::default();
25 }
26 PreviewMessage::SetPath { path: _ } => {
27 // Deprecated direct SetPath, as we now load previews via the FsService.
28 }
29 PreviewMessage::PreviewLoaded { path, data, .. } => {
30 state.path_display = path.to_string_lossy().to_string();
31 state.path = Some(path);
32 state.name = data.name;
33 state.is_dir = data.is_dir;
34 state.size = data.size;
35 state.permissions = data.permissions;
36 state.modified = data.modified;
37 state.file_type = data.file_type;
38 state.target = data.target;
39 state.content_preview = data.content_preview;
40 state.set_image(data.image_preview.map(|img| (img.pixels, img.width, img.height)));
41 state.reset_scroll();
42 }
43 }
44 }