Small TabConfig clean ups

* Rename `config::Tab` to `TabConfig`
* Use the loaded tab config instead of the default (oops)
This commit is contained in:
Josh Megnauth 2024-02-11 01:16:51 -05:00 committed by Jeremy Soller
parent bc5b46d552
commit e697e96afe
4 changed files with 16 additions and 12 deletions

View file

@ -26,7 +26,7 @@ use std::{
}; };
use crate::{ use crate::{
config::{AppTheme, Config, Tab as TabConfig, CONFIG_VERSION}, config::{AppTheme, Config, CONFIG_VERSION},
fl, home_dir, fl, home_dir,
key_bind::{key_binds, KeyBind}, key_bind::{key_binds, KeyBind},
menu, mouse_area, menu, mouse_area,
@ -188,7 +188,7 @@ pub struct App {
impl App { impl App {
fn open_tab(&mut self, location: Location) -> Command<Message> { fn open_tab(&mut self, location: Location) -> Command<Message> {
let tab = Tab::new(location.clone(), TabConfig::default()); let tab = Tab::new(location.clone(), self.config.tab.clone());
let entity = self let entity = self
.tab_model .tab_model
.insert() .insert()
@ -1086,7 +1086,7 @@ pub(crate) mod test_utils {
use log::{debug, trace}; use log::{debug, trace};
use tempfile::{tempdir, TempDir}; use tempfile::{tempdir, TempDir};
use crate::tab::Item; use crate::{config::TabConfig, tab::Item};
use super::*; use super::*;

View file

@ -28,22 +28,26 @@ impl AppTheme {
#[derive(Clone, CosmicConfigEntry, Debug, Deserialize, Eq, PartialEq, Serialize)] #[derive(Clone, CosmicConfigEntry, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Config { pub struct Config {
pub app_theme: AppTheme, pub app_theme: AppTheme,
pub tab: Tab, pub tab: TabConfig,
} }
impl Default for Config { impl Default for Config {
fn default() -> Self { fn default() -> Self {
Self { Self {
app_theme: AppTheme::System, app_theme: AppTheme::System,
tab: Tab::default(), tab: TabConfig::default(),
} }
} }
} }
/// Per tab config /// Global and local [`crate::tab::Tab`] config.
///
/// [`TabConfig`] contains options that are passed to each instance of [`crate::tab::Tab`].
/// These options are set globally through the main config, but each tab may change options
/// locally. Local changes aren't saved to the main config.
#[derive(Clone, Debug, Eq, PartialEq, CosmicConfigEntry, Deserialize, Serialize)] #[derive(Clone, Debug, Eq, PartialEq, CosmicConfigEntry, Deserialize, Serialize)]
pub struct Tab { pub struct TabConfig {
/// Show hidden files /// Show hidden files and folders
pub show_hidden: bool, pub show_hidden: bool,
// TODO: Other possible options // TODO: Other possible options
// pub sort_by: fn(&PathBuf, &PathBuf) -> Ordering, // pub sort_by: fn(&PathBuf, &PathBuf) -> Ordering,
@ -53,7 +57,7 @@ pub struct Tab {
// icon_size_grid: u16, // icon_size_grid: u16,
} }
impl Default for Tab { impl Default for TabConfig {
fn default() -> Self { fn default() -> Self {
Self { show_hidden: false } Self { show_hidden: false }
} }

View file

@ -25,7 +25,7 @@ use std::{
}; };
use crate::{ use crate::{
config::Tab as TabConfig, config::TabConfig,
fl, home_dir, fl, home_dir,
tab::{self, Location, Tab}, tab::{self, Location, Tab},
}; };

View file

@ -23,7 +23,7 @@ use std::{
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use crate::{config::Tab as TabConfig, fl, home_dir, mime_icon::mime_icon}; use crate::{config::TabConfig, fl, home_dir, mime_icon::mime_icon};
const DOUBLE_CLICK_DURATION: Duration = Duration::from_millis(500); const DOUBLE_CLICK_DURATION: Duration = Duration::from_millis(500);
//TODO: configurable //TODO: configurable
@ -1068,7 +1068,7 @@ mod tests {
read_dir_sorted, simple_fs, sort_files, tab_click_new, NAME_LEN, NUM_DIRS, NUM_FILES, read_dir_sorted, simple_fs, sort_files, tab_click_new, NAME_LEN, NUM_DIRS, NUM_FILES,
NUM_HIDDEN, NUM_NESTED, NUM_HIDDEN, NUM_NESTED,
}, },
config::Tab as TabConfig, config::TabConfig,
}; };
// Boilerplate for tab tests. Checks if simulated clicks selected items. // Boilerplate for tab tests. Checks if simulated clicks selected items.