gardesk/garfield / dca8a20

Browse files

tab: add recents view state and show_recents_entries

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
dca8a2067e16635447d3ea97544d7ab9ee8eb36c
Parents
ffeb268
Tree
b62188d

1 changed file

StatusFile+-
M garfield/src/ui/tab.rs 76 7
garfield/src/ui/tab.rsmodified
@@ -1,6 +1,6 @@
11
 //! Tab state for a single directory view.
22
 
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};
44
 use crate::ui::{ColumnClickResult, ColumnView, GridView, IconSize, ListView};
55
 use gartk_core::{Key, Modifiers, Point, Rect};
66
 use gartk_render::Renderer;
@@ -63,6 +63,10 @@ pub struct Tab {
6363
     bounds: Rect,
6464
     /// Active rename operation (if any).
6565
     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>,
6670
 }
6771
 
6872
 impl Tab {
@@ -94,16 +98,22 @@ impl Tab {
9498
             entries,
9599
             bounds,
96100
             renaming: None,
101
+            showing_recents: false,
102
+            recents_entries: Vec::new(),
97103
         }
98104
     }
99105
 
100
-    /// Get the tab title (directory name).
106
+    /// Get the tab title (directory name or "Recents").
101107
     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
+        }
107117
     }
108118
 
109119
     /// Get the current directory path.
@@ -169,12 +179,71 @@ impl Tab {
169179
 
170180
     /// Navigate to a new directory.
171181
     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
+
172186
         if path.is_dir() && path != *self.history.current() {
173187
             self.history.navigate(path.clone());
174188
             self.load_directory(&path);
175189
         }
176190
     }
177191
 
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
+
178247
     /// Go back in history.
179248
     pub fn go_back(&mut self) {
180249
         if let Some(path) = self.history.go_back().cloned() {