diff --git a/src/app.rs b/src/app.rs index b52fb3e..d75beb8 100644 --- a/src/app.rs +++ b/src/app.rs @@ -26,7 +26,7 @@ use std::{ }; use crate::{ - config::{AppTheme, Config, CONFIG_VERSION}, + config::{AppTheme, Config, Tab as TabConfig, CONFIG_VERSION}, fl, home_dir, key_bind::{key_binds, KeyBind}, menu, mouse_area, @@ -186,7 +186,7 @@ pub struct App { impl App { fn open_tab(&mut self, location: Location) -> Command { - let tab = Tab::new(location.clone()); + let tab = Tab::new(location.clone(), TabConfig::default()); let entity = self .tab_model .insert() @@ -1237,7 +1237,7 @@ pub(crate) mod test_utils { // New tab with items let location = Location::Path(path.to_owned()); let items = location.scan(); - let mut tab = Tab::new(location); + let mut tab = Tab::new(location, TabConfig::default()); tab.items_opt = Some(items); // Ensure correct number of directories as a sanity check diff --git a/src/config.rs b/src/config.rs index d10b36c..7e751d5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -28,12 +28,33 @@ impl AppTheme { #[derive(Clone, CosmicConfigEntry, Debug, Deserialize, Eq, PartialEq, Serialize)] pub struct Config { pub app_theme: AppTheme, + pub tab: Tab, } impl Default for Config { fn default() -> Self { Self { app_theme: AppTheme::System, + tab: Tab::default(), } } } + +/// Per tab config +#[derive(Clone, Debug, Eq, PartialEq, CosmicConfigEntry, Deserialize, Serialize)] +pub struct Tab { + /// Show hidden files + pub show_hidden: bool, + // TODO: Other possible options + // pub sort_by: fn(&PathBuf, &PathBuf) -> Ordering, + // Icon handle sizes + // icon_size_dialog: u16, + // icon_size_list: u16, + // icon_size_grid: u16, +} + +impl Default for Tab { + fn default() -> Self { + Self { show_hidden: false } + } +} diff --git a/src/dialog.rs b/src/dialog.rs index 6470365..614925b 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -25,6 +25,7 @@ use std::{ }; use crate::{ + config::Tab as TabConfig, fl, home_dir, tab::{self, Location, Tab}, }; @@ -78,7 +79,7 @@ pub struct App { impl App { fn open_tab(&mut self, location: Location) -> Command { - let mut tab = Tab::new(location.clone()); + let mut tab = Tab::new(location.clone(), TabConfig::default()); tab.dialog = true; let entity = self .tab_model diff --git a/src/tab.rs b/src/tab.rs index 84b6357..ca0ae38 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -23,7 +23,7 @@ use std::{ time::{Duration, Instant}, }; -use crate::{fl, home_dir, mime_icon::mime_icon}; +use crate::{config::Tab as TabConfig, fl, home_dir, mime_icon::mime_icon}; const DOUBLE_CLICK_DURATION: Duration = Duration::from_millis(500); //TODO: configurable @@ -524,10 +524,11 @@ pub struct Tab { pub edit_location: Option, pub history_i: usize, pub history: Vec, + pub config: TabConfig, } impl Tab { - pub fn new(location: Location) -> Self { + pub fn new(location: Location, config: TabConfig) -> Self { let history = vec![location.clone()]; Self { location, @@ -538,6 +539,7 @@ impl Tab { edit_location: None, history_i: 0, history, + config, } } @@ -1054,10 +1056,13 @@ mod tests { use test_log::test; use super::{scan_path, Item, Location, Message, Tab}; - use crate::app::test_utils::{ - assert_eq_tab_path, assert_eq_tab_path_contents, empty_fs, eq_path_item, filter_dirs, - read_dir_sorted, simple_fs, sort_files, tab_click_new, NAME_LEN, NUM_DIRS, NUM_FILES, - NUM_HIDDEN, NUM_NESTED, + use crate::{ + app::test_utils::{ + assert_eq_tab_path, assert_eq_tab_path_contents, empty_fs, eq_path_item, filter_dirs, + read_dir_sorted, simple_fs, sort_files, tab_click_new, NAME_LEN, NUM_DIRS, NUM_FILES, + NUM_HIDDEN, NUM_NESTED, + }, + config::Tab as TabConfig, }; // Boilerplate for tab tests. Checks if simulated clicks selected items. @@ -1098,7 +1103,7 @@ mod tests { fn tab_history() -> io::Result<(TempDir, Tab, Vec)> { let fs = simple_fs(NUM_FILES, NUM_NESTED, NUM_DIRS, NUM_NESTED, NAME_LEN)?; let path = fs.path(); - let mut tab = Tab::new(Location::Path(path.into())); + let mut tab = Tab::new(Location::Path(path.into()), TabConfig::default()); // All directories (simple_fs only produces one nested layer) let dirs: Vec = filter_dirs(path)? @@ -1195,7 +1200,7 @@ mod tests { .next() .expect("temp directory should have at least one directory"); - let mut tab = Tab::new(Location::Path(path.to_owned())); + let mut tab = Tab::new(Location::Path(path.to_owned()), TabConfig::default()); debug!( "Emitting Message::Location(Location::Path(\"{}\"))", next_dir.display() @@ -1294,7 +1299,7 @@ mod tests { fn tab_empty_history_does_nothing_on_prev_next() -> io::Result<()> { let fs = simple_fs(0, NUM_NESTED, NUM_DIRS, 0, NAME_LEN)?; let path = fs.path(); - let mut tab = Tab::new(Location::Path(path.into())); + let mut tab = Tab::new(Location::Path(path.into()), TabConfig::default()); // Tab's location shouldn't change if GoPrev or GoNext is triggered debug!("Emitting Message::GoPrevious",); @@ -1316,7 +1321,7 @@ mod tests { .next() .expect("should be at least one directory"); - let mut tab = Tab::new(Location::Path(next_dir.clone())); + let mut tab = Tab::new(Location::Path(next_dir.clone()), TabConfig::default()); // This will eventually yield false once root is hit while next_dir.pop() { debug!("Emitting Message::LocationUp",);