From a085499c0ec48d4e23930c6d14da39eb98f3f79a Mon Sep 17 00:00:00 2001 From: maciekk64 Date: Wed, 29 May 2024 23:33:12 +0200 Subject: [PATCH] default view config --- i18n/en/cosmic_files.ftl | 1 + i18n/pl/cosmic_files.ftl | 1 + src/app.rs | 21 +++++++++++++++++++++ src/config.rs | 4 ++++ src/dialog.rs | 2 +- src/menu.rs | 4 ++-- src/tab.rs | 16 +++++++--------- 7 files changed, 37 insertions(+), 12 deletions(-) diff --git a/i18n/en/cosmic_files.ftl b/i18n/en/cosmic_files.ftl index c77d924..95e6972 100644 --- a/i18n/en/cosmic_files.ftl +++ b/i18n/en/cosmic_files.ftl @@ -71,6 +71,7 @@ properties = Properties settings = Settings settings-tab = Tab settings-show-hidden = Show hidden files +default-view = Default view icon-size-list = Icon size (list) icon-size-grid = Icon size (grid) sorting-name = Sort by diff --git a/i18n/pl/cosmic_files.ftl b/i18n/pl/cosmic_files.ftl index 429e2a8..0883b83 100644 --- a/i18n/pl/cosmic_files.ftl +++ b/i18n/pl/cosmic_files.ftl @@ -71,6 +71,7 @@ properties = Właściwości settings = Ustawienia settings-tab = Karta settings-show-hidden = Pokaż ukryte pliki +default-view = Domyślny widok icon-size-list = Rozmiar ikon (lista) icon-size-grid = Rozmiar ikon (siatka) sorting-name = Uszereguj według diff --git a/src/app.rs b/src/app.rs index ebb6577..4cf0da1 100644 --- a/src/app.rs +++ b/src/app.rs @@ -317,6 +317,7 @@ pub struct App { config_handler: Option, config: Config, app_themes: Vec, + default_view: Vec, sort_by_names: Vec, sort_direction: Vec, context_page: ContextPage, @@ -695,6 +696,25 @@ impl App { }, )) }) + .add({ + let tab_config = self.config.tab.clone(); + widget::settings::item::builder(fl!("default-view")).control(widget::dropdown( + &self.default_view, + match tab_config.view { + tab::View::Grid => Some(0), + tab::View::List => Some(1), + }, + move |index| { + Message::TabConfig(TabConfig { + view: match index { + 0 => tab::View::Grid, + _ => tab::View::List, + }, + ..tab_config + }) + }, + )) + }) .add({ let tab_config = self.config.tab.clone(); let list: u16 = tab_config.icon_sizes.list.into(); @@ -860,6 +880,7 @@ impl Application for App { config_handler: flags.config_handler, config: flags.config, app_themes, + default_view: vec![fl!("grid-view"), fl!("list-view")], sort_by_names: HeadingOptions::names(), sort_direction: vec![fl!("descending"), fl!("ascending")], context_page: ContextPage::Settings, diff --git a/src/config.rs b/src/config.rs index aa67818..f62f329 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,6 +8,8 @@ use cosmic::{ }; use serde::{Deserialize, Serialize}; +use crate::tab::View; + use super::tab::HeadingOptions; pub const CONFIG_VERSION: u64 = 1; @@ -111,6 +113,7 @@ impl Default for Config { /// locally. Local changes aren't saved to the main config. #[derive(Clone, Copy, Debug, Eq, PartialEq, CosmicConfigEntry, Deserialize, Serialize)] pub struct TabConfig { + pub view: View, /// Show folders before files pub folders_first: bool, /// Show hidden files and folders @@ -125,6 +128,7 @@ pub struct TabConfig { impl Default for TabConfig { fn default() -> Self { Self { + view: View::Grid, folders_first: true, show_hidden: false, sort_name: HeadingOptions::Name, diff --git a/src/dialog.rs b/src/dialog.rs index 11ef413..0e09d9a 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -364,7 +364,7 @@ impl Application for App { let mut tab = Tab::new(location, TabConfig::default()); tab.dialog = Some(flags.kind.clone()); - tab.view = tab::View::List; + tab.config.view = tab::View::List; let mut app = App { core, diff --git a/src/menu.rs b/src/menu.rs index 9088f9a..a1a26ef 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -221,12 +221,12 @@ pub fn menu_bar<'a>( menu::Item::Divider, menu::Item::CheckBox( fl!("grid-view"), - tab_opt.map_or(false, |tab| matches!(tab.view, tab::View::Grid)), + tab_opt.map_or(false, |tab| matches!(tab.config.view, tab::View::Grid)), Action::TabViewGrid, ), menu::Item::CheckBox( fl!("list-view"), - tab_opt.map_or(false, |tab| matches!(tab.view, tab::View::List)), + tab_opt.map_or(false, |tab| matches!(tab.config.view, tab::View::List)), Action::TabViewList, ), menu::Item::Divider, diff --git a/src/tab.rs b/src/tab.rs index 31d9790..fdbbdf0 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -663,7 +663,7 @@ impl Item { } } -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)] pub enum View { Grid, List, @@ -702,7 +702,6 @@ pub struct Tab { //TODO: make more items private pub location: Location, pub context_menu: Option, - pub view: View, pub dialog: Option, pub scroll_opt: Option, pub size_opt: Option, @@ -727,7 +726,6 @@ impl Tab { Self { location, context_menu: None, - view: View::Grid, dialog: None, scroll_opt: None, size_opt: None, @@ -1403,7 +1401,7 @@ impl Tab { Message::ToggleShowHidden => self.config.show_hidden = !self.config.show_hidden, Message::View(view) => { - self.view = view; + self.config.view = view; } Message::ToggleSort(heading_option) => { let heading_sort = if self.config.sort_name == heading_option { @@ -1459,7 +1457,7 @@ impl Tab { self.dnd_hovered = None; } } - Message::ZoomDefault => match self.view { + Message::ZoomDefault => match self.config.view { View::List => self.config.icon_sizes.list = 100.try_into().unwrap(), View::Grid => self.config.icon_sizes.grid = 100.try_into().unwrap(), }, @@ -1477,7 +1475,7 @@ impl Tab { *size = step.try_into().unwrap(); } }; - match self.view { + match self.config.view { View::List => zoom_in(&mut self.config.icon_sizes.list, 100, 500), View::Grid => zoom_in(&mut self.config.icon_sizes.grid, 50, 500), } @@ -1496,7 +1494,7 @@ impl Tab { *size = step.try_into().unwrap(); } }; - match self.view { + match self.config.view { View::List => zoom_out(&mut self.config.icon_sizes.list, 100, 500), View::Grid => zoom_out(&mut self.config.icon_sizes.grid, 50, 500), } @@ -2355,7 +2353,7 @@ impl Tab { pub fn view(&self, key_binds: &HashMap) -> Element { let location_view = self.location_view(); - let (drag_list, mut item_view, can_scroll) = match self.view { + let (drag_list, mut item_view, can_scroll) = match self.config.view { View::Grid => self.grid_view(), View::List => self.list_view(), }; @@ -2511,7 +2509,7 @@ impl Tab { }; //TODO: HACK to ensure positions are up to date since subscription runs before view - match self.view { + match self.config.view { View::Grid => _ = self.grid_view(), View::List => _ = self.list_view(), };