default view config

This commit is contained in:
maciekk64 2024-05-29 23:33:12 +02:00 committed by Jeremy Soller
parent 2c5ed02f74
commit a085499c0e
7 changed files with 37 additions and 12 deletions

View file

@ -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

View file

@ -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

View file

@ -317,6 +317,7 @@ pub struct App {
config_handler: Option<cosmic_config::Config>,
config: Config,
app_themes: Vec<String>,
default_view: Vec<String>,
sort_by_names: Vec<String>,
sort_direction: Vec<String>,
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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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<Point>,
pub view: View,
pub dialog: Option<DialogKind>,
pub scroll_opt: Option<AbsoluteOffset>,
pub size_opt: Option<Size>,
@ -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<KeyBind, Action>) -> Element<Message> {
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(),
};