Add sort by option to config for new tabs
This commit is contained in:
parent
a4b38c4983
commit
e22c74d721
3 changed files with 51 additions and 2 deletions
|
|
@ -64,6 +64,10 @@ settings-tab = Tab
|
|||
settings-show-hidden = Show hidden files
|
||||
icon-size-list = Icon size (list)
|
||||
icon-size-grid = Icon size (grid)
|
||||
sorting-name = Sort by
|
||||
direction = Direction
|
||||
ascending = Ascending
|
||||
descending = Descending
|
||||
|
||||
### Appearance
|
||||
appearance = Appearance
|
||||
|
|
|
|||
26
src/app.rs
26
src/app.rs
|
|
@ -36,7 +36,7 @@ use crate::{
|
|||
menu, mime_app,
|
||||
operation::Operation,
|
||||
spawn_detached::spawn_detached,
|
||||
tab::{self, ItemMetadata, Location, Tab},
|
||||
tab::{self, HeadingOptions, ItemMetadata, Location, Tab},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
@ -228,6 +228,7 @@ pub struct App {
|
|||
config_handler: Option<cosmic_config::Config>,
|
||||
config: Config,
|
||||
app_themes: Vec<String>,
|
||||
sort_by_names: Vec<String>,
|
||||
context_page: ContextPage,
|
||||
dialog_pages: VecDeque<DialogPage>,
|
||||
dialog_text_input: widget::Id,
|
||||
|
|
@ -523,6 +524,28 @@ impl App {
|
|||
.step(25u16),
|
||||
)
|
||||
})
|
||||
.add({
|
||||
let tab_config = self.config.tab;
|
||||
let sort_by_selected = tab_config.sort_name as _;
|
||||
|
||||
widget::settings::item::builder(fl!("sorting-name"))
|
||||
.description(format!("{}", tab_config.sort_name))
|
||||
.control(widget::dropdown(
|
||||
&self.sort_by_names,
|
||||
Some(sort_by_selected),
|
||||
move |index| {
|
||||
Message::TabConfig(TabConfig {
|
||||
sort_name: match index {
|
||||
0 => HeadingOptions::Name,
|
||||
1 => HeadingOptions::Modified,
|
||||
2 => HeadingOptions::Size,
|
||||
_ => HeadingOptions::Name,
|
||||
},
|
||||
..tab_config
|
||||
})
|
||||
},
|
||||
))
|
||||
})
|
||||
.into(),
|
||||
widget::settings::view_section(fl!("settings-tab"))
|
||||
.add({
|
||||
|
|
@ -611,6 +634,7 @@ impl Application for App {
|
|||
config_handler: flags.config_handler,
|
||||
config: flags.config,
|
||||
app_themes,
|
||||
sort_by_names: HeadingOptions::names(),
|
||||
context_page: ContextPage::Settings,
|
||||
dialog_pages: VecDeque::new(),
|
||||
dialog_text_input: widget::Id::unique(),
|
||||
|
|
|
|||
23
src/tab.rs
23
src/tab.rs
|
|
@ -27,6 +27,7 @@ use std::{
|
|||
cell::Cell,
|
||||
cmp::Ordering,
|
||||
collections::HashMap,
|
||||
fmt,
|
||||
fs::{self, Metadata},
|
||||
path::PathBuf,
|
||||
time::{Duration, Instant},
|
||||
|
|
@ -620,11 +621,31 @@ pub enum View {
|
|||
}
|
||||
#[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Ord, Eq, Deserialize, Serialize)]
|
||||
pub enum HeadingOptions {
|
||||
Name,
|
||||
Name = 0,
|
||||
Modified,
|
||||
Size,
|
||||
}
|
||||
|
||||
impl fmt::Display for HeadingOptions {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
HeadingOptions::Name => write!(f, "{}", fl!("name")),
|
||||
HeadingOptions::Modified => write!(f, "{}", fl!("modified")),
|
||||
HeadingOptions::Size => write!(f, "{}", fl!("size")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HeadingOptions {
|
||||
pub fn names() -> Vec<String> {
|
||||
vec![
|
||||
HeadingOptions::Name.to_string(),
|
||||
HeadingOptions::Modified.to_string(),
|
||||
HeadingOptions::Size.to_string(),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Tab {
|
||||
//TODO: make more items private
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue