@@ -1,6 +1,6 @@ |
| 1 | 1 | //! Tab state for a single directory view. |
| 2 | 2 | |
| 3 | | -use crate::core::{read_directory, rename_path, sort_entries, FileEntry, History, SortDirection, SortOrder}; |
| 3 | +use crate::core::{read_directory, rename_path, sort_entries, EntryType, FileEntry, History, recents::RecentEntry, SortDirection, SortOrder}; |
| 4 | 4 | use crate::ui::{ColumnClickResult, ColumnView, GridView, IconSize, ListView}; |
| 5 | 5 | use gartk_core::{Key, Modifiers, Point, Rect}; |
| 6 | 6 | use gartk_render::Renderer; |
@@ -63,6 +63,10 @@ pub struct Tab { |
| 63 | 63 | bounds: Rect, |
| 64 | 64 | /// Active rename operation (if any). |
| 65 | 65 | renaming: Option<RenameState>, |
| 66 | + /// Whether currently showing the recents view. |
| 67 | + showing_recents: bool, |
| 68 | + /// Cached entries for the recents view. |
| 69 | + recents_entries: Vec<FileEntry>, |
| 66 | 70 | } |
| 67 | 71 | |
| 68 | 72 | impl Tab { |
@@ -94,16 +98,22 @@ impl Tab { |
| 94 | 98 | entries, |
| 95 | 99 | bounds, |
| 96 | 100 | renaming: None, |
| 101 | + showing_recents: false, |
| 102 | + recents_entries: Vec::new(), |
| 97 | 103 | } |
| 98 | 104 | } |
| 99 | 105 | |
| 100 | | - /// Get the tab title (directory name). |
| 106 | + /// Get the tab title (directory name or "Recents"). |
| 101 | 107 | pub fn title(&self) -> String { |
| 102 | | - self.history |
| 103 | | - .current() |
| 104 | | - .file_name() |
| 105 | | - .map(|n| n.to_string_lossy().to_string()) |
| 106 | | - .unwrap_or_else(|| "/".to_string()) |
| 108 | + if self.showing_recents { |
| 109 | + "Recents".to_string() |
| 110 | + } else { |
| 111 | + self.history |
| 112 | + .current() |
| 113 | + .file_name() |
| 114 | + .map(|n| n.to_string_lossy().to_string()) |
| 115 | + .unwrap_or_else(|| "/".to_string()) |
| 116 | + } |
| 107 | 117 | } |
| 108 | 118 | |
| 109 | 119 | /// Get the current directory path. |
@@ -169,12 +179,71 @@ impl Tab { |
| 169 | 179 | |
| 170 | 180 | /// Navigate to a new directory. |
| 171 | 181 | pub fn navigate_to(&mut self, path: PathBuf) { |
| 182 | + // Exit recents view when navigating to a directory |
| 183 | + self.showing_recents = false; |
| 184 | + self.recents_entries.clear(); |
| 185 | + |
| 172 | 186 | if path.is_dir() && path != *self.history.current() { |
| 173 | 187 | self.history.navigate(path.clone()); |
| 174 | 188 | self.load_directory(&path); |
| 175 | 189 | } |
| 176 | 190 | } |
| 177 | 191 | |
| 192 | + /// Check if currently showing the recents view. |
| 193 | + pub fn is_showing_recents(&self) -> bool { |
| 194 | + self.showing_recents |
| 195 | + } |
| 196 | + |
| 197 | + /// Show the recents view with entries from the RecentsManager. |
| 198 | + pub fn show_recents_entries(&mut self, recents: &[RecentEntry]) { |
| 199 | + use std::time::SystemTime; |
| 200 | + |
| 201 | + self.showing_recents = true; |
| 202 | + self.recents_entries.clear(); |
| 203 | + |
| 204 | + // Convert RecentEntry items to FileEntry for display |
| 205 | + for recent in recents { |
| 206 | + // Get file metadata for size and modified time |
| 207 | + let (size, modified) = if let Ok(meta) = std::fs::metadata(&recent.path) { |
| 208 | + (meta.len(), meta.modified().unwrap_or(SystemTime::UNIX_EPOCH)) |
| 209 | + } else { |
| 210 | + (0, recent.modified) |
| 211 | + }; |
| 212 | + |
| 213 | + let entry_type = if recent.is_directory() { |
| 214 | + EntryType::Directory |
| 215 | + } else { |
| 216 | + EntryType::File |
| 217 | + }; |
| 218 | + |
| 219 | + let name = recent.file_name().unwrap_or("").to_string(); |
| 220 | + |
| 221 | + self.recents_entries.push(FileEntry { |
| 222 | + name, |
| 223 | + path: recent.path.clone(), |
| 224 | + entry_type, |
| 225 | + size, |
| 226 | + modified: Some(modified), |
| 227 | + hidden: false, |
| 228 | + is_symlink: false, |
| 229 | + symlink_target: None, |
| 230 | + }); |
| 231 | + } |
| 232 | + |
| 233 | + // Update the list view to show recents |
| 234 | + self.list_view.set_entries(self.recents_entries.clone()); |
| 235 | + self.grid_view.set_entries(self.recents_entries.clone()); |
| 236 | + } |
| 237 | + |
| 238 | + /// Exit the recents view and return to showing the current directory. |
| 239 | + pub fn exit_recents(&mut self) { |
| 240 | + self.showing_recents = false; |
| 241 | + self.recents_entries.clear(); |
| 242 | + // Reload the current directory |
| 243 | + let path = self.history.current().clone(); |
| 244 | + self.load_directory(&path); |
| 245 | + } |
| 246 | + |
| 178 | 247 | /// Go back in history. |
| 179 | 248 | pub fn go_back(&mut self) { |
| 180 | 249 | if let Some(path) = self.history.go_back().cloned() { |