default view config
This commit is contained in:
parent
2c5ed02f74
commit
a085499c0e
7 changed files with 37 additions and 12 deletions
|
|
@ -71,6 +71,7 @@ properties = Properties
|
||||||
settings = Settings
|
settings = Settings
|
||||||
settings-tab = Tab
|
settings-tab = Tab
|
||||||
settings-show-hidden = Show hidden files
|
settings-show-hidden = Show hidden files
|
||||||
|
default-view = Default view
|
||||||
icon-size-list = Icon size (list)
|
icon-size-list = Icon size (list)
|
||||||
icon-size-grid = Icon size (grid)
|
icon-size-grid = Icon size (grid)
|
||||||
sorting-name = Sort by
|
sorting-name = Sort by
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ properties = Właściwości
|
||||||
settings = Ustawienia
|
settings = Ustawienia
|
||||||
settings-tab = Karta
|
settings-tab = Karta
|
||||||
settings-show-hidden = Pokaż ukryte pliki
|
settings-show-hidden = Pokaż ukryte pliki
|
||||||
|
default-view = Domyślny widok
|
||||||
icon-size-list = Rozmiar ikon (lista)
|
icon-size-list = Rozmiar ikon (lista)
|
||||||
icon-size-grid = Rozmiar ikon (siatka)
|
icon-size-grid = Rozmiar ikon (siatka)
|
||||||
sorting-name = Uszereguj według
|
sorting-name = Uszereguj według
|
||||||
|
|
|
||||||
21
src/app.rs
21
src/app.rs
|
|
@ -317,6 +317,7 @@ pub struct App {
|
||||||
config_handler: Option<cosmic_config::Config>,
|
config_handler: Option<cosmic_config::Config>,
|
||||||
config: Config,
|
config: Config,
|
||||||
app_themes: Vec<String>,
|
app_themes: Vec<String>,
|
||||||
|
default_view: Vec<String>,
|
||||||
sort_by_names: Vec<String>,
|
sort_by_names: Vec<String>,
|
||||||
sort_direction: Vec<String>,
|
sort_direction: Vec<String>,
|
||||||
context_page: ContextPage,
|
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({
|
.add({
|
||||||
let tab_config = self.config.tab.clone();
|
let tab_config = self.config.tab.clone();
|
||||||
let list: u16 = tab_config.icon_sizes.list.into();
|
let list: u16 = tab_config.icon_sizes.list.into();
|
||||||
|
|
@ -860,6 +880,7 @@ impl Application for App {
|
||||||
config_handler: flags.config_handler,
|
config_handler: flags.config_handler,
|
||||||
config: flags.config,
|
config: flags.config,
|
||||||
app_themes,
|
app_themes,
|
||||||
|
default_view: vec![fl!("grid-view"), fl!("list-view")],
|
||||||
sort_by_names: HeadingOptions::names(),
|
sort_by_names: HeadingOptions::names(),
|
||||||
sort_direction: vec![fl!("descending"), fl!("ascending")],
|
sort_direction: vec![fl!("descending"), fl!("ascending")],
|
||||||
context_page: ContextPage::Settings,
|
context_page: ContextPage::Settings,
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ use cosmic::{
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::tab::View;
|
||||||
|
|
||||||
use super::tab::HeadingOptions;
|
use super::tab::HeadingOptions;
|
||||||
|
|
||||||
pub const CONFIG_VERSION: u64 = 1;
|
pub const CONFIG_VERSION: u64 = 1;
|
||||||
|
|
@ -111,6 +113,7 @@ impl Default for Config {
|
||||||
/// locally. Local changes aren't saved to the main config.
|
/// locally. Local changes aren't saved to the main config.
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, CosmicConfigEntry, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, CosmicConfigEntry, Deserialize, Serialize)]
|
||||||
pub struct TabConfig {
|
pub struct TabConfig {
|
||||||
|
pub view: View,
|
||||||
/// Show folders before files
|
/// Show folders before files
|
||||||
pub folders_first: bool,
|
pub folders_first: bool,
|
||||||
/// Show hidden files and folders
|
/// Show hidden files and folders
|
||||||
|
|
@ -125,6 +128,7 @@ pub struct TabConfig {
|
||||||
impl Default for TabConfig {
|
impl Default for TabConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
view: View::Grid,
|
||||||
folders_first: true,
|
folders_first: true,
|
||||||
show_hidden: false,
|
show_hidden: false,
|
||||||
sort_name: HeadingOptions::Name,
|
sort_name: HeadingOptions::Name,
|
||||||
|
|
|
||||||
|
|
@ -364,7 +364,7 @@ impl Application for App {
|
||||||
|
|
||||||
let mut tab = Tab::new(location, TabConfig::default());
|
let mut tab = Tab::new(location, TabConfig::default());
|
||||||
tab.dialog = Some(flags.kind.clone());
|
tab.dialog = Some(flags.kind.clone());
|
||||||
tab.view = tab::View::List;
|
tab.config.view = tab::View::List;
|
||||||
|
|
||||||
let mut app = App {
|
let mut app = App {
|
||||||
core,
|
core,
|
||||||
|
|
|
||||||
|
|
@ -221,12 +221,12 @@ pub fn menu_bar<'a>(
|
||||||
menu::Item::Divider,
|
menu::Item::Divider,
|
||||||
menu::Item::CheckBox(
|
menu::Item::CheckBox(
|
||||||
fl!("grid-view"),
|
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,
|
Action::TabViewGrid,
|
||||||
),
|
),
|
||||||
menu::Item::CheckBox(
|
menu::Item::CheckBox(
|
||||||
fl!("list-view"),
|
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,
|
Action::TabViewList,
|
||||||
),
|
),
|
||||||
menu::Item::Divider,
|
menu::Item::Divider,
|
||||||
|
|
|
||||||
16
src/tab.rs
16
src/tab.rs
|
|
@ -663,7 +663,7 @@ impl Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
pub enum View {
|
pub enum View {
|
||||||
Grid,
|
Grid,
|
||||||
List,
|
List,
|
||||||
|
|
@ -702,7 +702,6 @@ pub struct Tab {
|
||||||
//TODO: make more items private
|
//TODO: make more items private
|
||||||
pub location: Location,
|
pub location: Location,
|
||||||
pub context_menu: Option<Point>,
|
pub context_menu: Option<Point>,
|
||||||
pub view: View,
|
|
||||||
pub dialog: Option<DialogKind>,
|
pub dialog: Option<DialogKind>,
|
||||||
pub scroll_opt: Option<AbsoluteOffset>,
|
pub scroll_opt: Option<AbsoluteOffset>,
|
||||||
pub size_opt: Option<Size>,
|
pub size_opt: Option<Size>,
|
||||||
|
|
@ -727,7 +726,6 @@ impl Tab {
|
||||||
Self {
|
Self {
|
||||||
location,
|
location,
|
||||||
context_menu: None,
|
context_menu: None,
|
||||||
view: View::Grid,
|
|
||||||
dialog: None,
|
dialog: None,
|
||||||
scroll_opt: None,
|
scroll_opt: None,
|
||||||
size_opt: None,
|
size_opt: None,
|
||||||
|
|
@ -1403,7 +1401,7 @@ impl Tab {
|
||||||
Message::ToggleShowHidden => self.config.show_hidden = !self.config.show_hidden,
|
Message::ToggleShowHidden => self.config.show_hidden = !self.config.show_hidden,
|
||||||
|
|
||||||
Message::View(view) => {
|
Message::View(view) => {
|
||||||
self.view = view;
|
self.config.view = view;
|
||||||
}
|
}
|
||||||
Message::ToggleSort(heading_option) => {
|
Message::ToggleSort(heading_option) => {
|
||||||
let heading_sort = if self.config.sort_name == heading_option {
|
let heading_sort = if self.config.sort_name == heading_option {
|
||||||
|
|
@ -1459,7 +1457,7 @@ impl Tab {
|
||||||
self.dnd_hovered = None;
|
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::List => self.config.icon_sizes.list = 100.try_into().unwrap(),
|
||||||
View::Grid => self.config.icon_sizes.grid = 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();
|
*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::List => zoom_in(&mut self.config.icon_sizes.list, 100, 500),
|
||||||
View::Grid => zoom_in(&mut self.config.icon_sizes.grid, 50, 500),
|
View::Grid => zoom_in(&mut self.config.icon_sizes.grid, 50, 500),
|
||||||
}
|
}
|
||||||
|
|
@ -1496,7 +1494,7 @@ impl Tab {
|
||||||
*size = step.try_into().unwrap();
|
*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::List => zoom_out(&mut self.config.icon_sizes.list, 100, 500),
|
||||||
View::Grid => zoom_out(&mut self.config.icon_sizes.grid, 50, 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> {
|
pub fn view(&self, key_binds: &HashMap<KeyBind, Action>) -> Element<Message> {
|
||||||
let location_view = self.location_view();
|
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::Grid => self.grid_view(),
|
||||||
View::List => self.list_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
|
//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::Grid => _ = self.grid_view(),
|
||||||
View::List => _ = self.list_view(),
|
View::List => _ = self.list_view(),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue