Skip to main content

vtcode_tui/core_tui/session/file_palette/
mod.rs

1use std::path::PathBuf;
2
3use crate::ui::FileColorizer;
4
5mod filtering;
6mod navigation;
7mod palette_item;
8mod references;
9
10pub use references::extract_file_reference;
11
12const PAGE_SIZE: usize = 20;
13
14#[derive(Debug, Clone)]
15pub struct FileEntry {
16    pub path: String,
17    #[allow(dead_code)]
18    pub display_name: String,
19    pub relative_path: String,
20    pub is_dir: bool,
21}
22
23pub struct FilePalette {
24    all_files: Vec<FileEntry>,
25    filtered_files: Vec<FileEntry>,
26    selected_index: usize,
27    current_page: usize,
28    filter_query: String,
29    workspace_root: PathBuf,
30    filter_cache: std::collections::HashMap<String, Vec<FileEntry>>,
31    #[allow(dead_code)]
32    file_colorizer: FileColorizer,
33}
34
35impl FilePalette {
36    pub fn new(workspace_root: PathBuf) -> Self {
37        Self {
38            all_files: Vec::new(),
39            filtered_files: Vec::new(),
40            selected_index: 0,
41            current_page: 0,
42            filter_query: String::new(),
43            workspace_root,
44            filter_cache: std::collections::HashMap::new(),
45            file_colorizer: FileColorizer::new(),
46        }
47    }
48
49    /// Reset selection and filter (call when opening file browser)
50    #[allow(dead_code)]
51    pub fn reset(&mut self) {
52        self.selected_index = 0;
53        self.current_page = 0;
54        self.filter_query.clear();
55        self.apply_filter(); // Refresh filtered_files to show all
56    }
57
58    /// Clean up resources to free memory (call when closing file browser)
59    pub fn cleanup(&mut self) {
60        self.filter_cache.clear();
61        self.filtered_files.clear();
62        self.filtered_files.shrink_to_fit();
63    }
64}
65
66#[cfg(test)]
67mod tests;