Add icon sizes to settings page
This commit is contained in:
parent
1f613860e4
commit
162616f687
3 changed files with 63 additions and 21 deletions
|
|
@ -35,6 +35,9 @@ settings = Settings
|
||||||
settings-tab = Tab
|
settings-tab = Tab
|
||||||
settings-hidden = Hidden files
|
settings-hidden = Hidden files
|
||||||
settings-show-hidden = Show hidden files
|
settings-show-hidden = Show hidden files
|
||||||
|
icon-size-list = Icon size (list)
|
||||||
|
icon-size-grid = Icon size (grid)
|
||||||
|
icon-zoom = Zoom
|
||||||
|
|
||||||
### Appearance
|
### Appearance
|
||||||
appearance = Appearance
|
appearance = Appearance
|
||||||
|
|
|
||||||
77
src/app.rs
77
src/app.rs
|
|
@ -26,7 +26,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{AppTheme, Config, TabConfig, CONFIG_VERSION},
|
config::{AppTheme, Config, IconSizes, TabConfig, CONFIG_VERSION},
|
||||||
fl, home_dir,
|
fl, home_dir,
|
||||||
key_bind::{key_binds, KeyBind},
|
key_bind::{key_binds, KeyBind},
|
||||||
menu, mouse_area,
|
menu, mouse_area,
|
||||||
|
|
@ -222,9 +222,7 @@ impl App {
|
||||||
let icon_sizes = self.config.tab.icon_sizes;
|
let icon_sizes = self.config.tab.icon_sizes;
|
||||||
Command::perform(
|
Command::perform(
|
||||||
async move {
|
async move {
|
||||||
match tokio::task::spawn_blocking(move || location.scan(icon_sizes))
|
match tokio::task::spawn_blocking(move || location.scan(icon_sizes)).await {
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(items) => message::app(Message::TabRescan(entity, items)),
|
Ok(items) => message::app(Message::TabRescan(entity, items)),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::warn!("failed to rescan: {}", err);
|
log::warn!("failed to rescan: {}", err);
|
||||||
|
|
@ -375,6 +373,8 @@ impl App {
|
||||||
AppTheme::System => 0,
|
AppTheme::System => 0,
|
||||||
};
|
};
|
||||||
let hidden_selected = self.config.tab.show_hidden;
|
let hidden_selected = self.config.tab.show_hidden;
|
||||||
|
// TODO: Should dialog be updated here too?
|
||||||
|
let IconSizes { list, grid, .. } = self.config.tab.icon_sizes;
|
||||||
widget::settings::view_column(vec![
|
widget::settings::view_column(vec![
|
||||||
widget::settings::view_section(fl!("appearance"))
|
widget::settings::view_section(fl!("appearance"))
|
||||||
.add(
|
.add(
|
||||||
|
|
@ -390,6 +390,40 @@ impl App {
|
||||||
},
|
},
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
|
.add(
|
||||||
|
widget::settings::item::builder(fl!("icon-size-list")).control(
|
||||||
|
widget::text_input(fl!("icon-zoom"), list.to_string()).on_input(|s| {
|
||||||
|
s.parse()
|
||||||
|
.map(|list_next| {
|
||||||
|
Message::TabConfig(TabConfig {
|
||||||
|
icon_sizes: IconSizes {
|
||||||
|
list: list_next,
|
||||||
|
..self.config.tab.icon_sizes
|
||||||
|
},
|
||||||
|
..self.config.tab
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|_| Message::TabConfig(self.config.tab))
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.add(
|
||||||
|
widget::settings::item::builder(fl!("icon-size-grid")).control(
|
||||||
|
widget::text_input(fl!("icon-zoom"), grid.to_string()).on_input(|s| {
|
||||||
|
s.parse()
|
||||||
|
.map(|grid_next| {
|
||||||
|
Message::TabConfig(TabConfig {
|
||||||
|
icon_sizes: IconSizes {
|
||||||
|
grid: grid_next,
|
||||||
|
..self.config.tab.icon_sizes
|
||||||
|
},
|
||||||
|
..self.config.tab
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|_| Message::TabConfig(self.config.tab))
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
.into(),
|
.into(),
|
||||||
widget::settings::view_section(fl!("settings-tab"))
|
widget::settings::view_section(fl!("settings-tab"))
|
||||||
.add(
|
.add(
|
||||||
|
|
@ -778,21 +812,23 @@ impl Application for App {
|
||||||
return Command::batch([self.update_title(), self.update_watcher()]);
|
return Command::batch([self.update_title(), self.update_watcher()]);
|
||||||
}
|
}
|
||||||
Message::TabConfig(config) => {
|
Message::TabConfig(config) => {
|
||||||
// Tabs are collected first to placate the borrowck
|
if config != self.config.tab {
|
||||||
let tabs: Vec<_> = self.tab_model.iter().collect();
|
// Tabs are collected first to placate the borrowck
|
||||||
// Update main conf and each tab with the new config
|
let tabs: Vec<_> = self.tab_model.iter().collect();
|
||||||
let commands: Vec<_> = std::iter::once(self.update_config())
|
// Update main conf and each tab with the new config
|
||||||
.chain(tabs.into_iter().map(|entity| {
|
let commands: Vec<_> = std::iter::once(self.update_config())
|
||||||
let config = config.clone();
|
.chain(tabs.into_iter().map(|entity| {
|
||||||
self.update(Message::TabMessage(
|
let config = config.clone();
|
||||||
Some(entity),
|
self.update(Message::TabMessage(
|
||||||
tab::Message::Config(config),
|
Some(entity),
|
||||||
))
|
tab::Message::Config(config),
|
||||||
}))
|
))
|
||||||
.collect();
|
}))
|
||||||
|
.collect();
|
||||||
|
|
||||||
config_set!(tab, config);
|
config_set!(tab, config);
|
||||||
return Command::batch(commands);
|
return Command::batch(commands);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Message::TabContextAction(entity, action) => {
|
Message::TabContextAction(entity, action) => {
|
||||||
match self.tab_model.data_mut::<Tab>(entity) {
|
match self.tab_model.data_mut::<Tab>(entity) {
|
||||||
|
|
@ -1126,7 +1162,10 @@ pub(crate) mod test_utils {
|
||||||
use log::{debug, trace};
|
use log::{debug, trace};
|
||||||
use tempfile::{tempdir, TempDir};
|
use tempfile::{tempdir, TempDir};
|
||||||
|
|
||||||
use crate::{config::{TabConfig, IconSizes}, tab::Item};
|
use crate::{
|
||||||
|
config::{IconSizes, TabConfig},
|
||||||
|
tab::Item,
|
||||||
|
};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,13 +54,13 @@ impl Default for Config {
|
||||||
/// [`TabConfig`] contains options that are passed to each instance of [`crate::tab::Tab`].
|
/// [`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
|
/// 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.
|
/// locally. Local changes aren't saved to the main config.
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, CosmicConfigEntry, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, CosmicConfigEntry, Deserialize, Serialize)]
|
||||||
pub struct TabConfig {
|
pub struct TabConfig {
|
||||||
/// Show hidden files and folders
|
/// 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,
|
||||||
// Icon handle zoom percents
|
// Icon zoom
|
||||||
pub icon_sizes: IconSizes,
|
pub icon_sizes: IconSizes,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue