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
|
settings-show-hidden = Show hidden files
|
||||||
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
|
||||||
|
direction = Direction
|
||||||
|
ascending = Ascending
|
||||||
|
descending = Descending
|
||||||
|
|
||||||
### Appearance
|
### Appearance
|
||||||
appearance = Appearance
|
appearance = Appearance
|
||||||
|
|
|
||||||
26
src/app.rs
26
src/app.rs
|
|
@ -36,7 +36,7 @@ use crate::{
|
||||||
menu, mime_app,
|
menu, mime_app,
|
||||||
operation::Operation,
|
operation::Operation,
|
||||||
spawn_detached::spawn_detached,
|
spawn_detached::spawn_detached,
|
||||||
tab::{self, ItemMetadata, Location, Tab},
|
tab::{self, HeadingOptions, ItemMetadata, Location, Tab},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
@ -228,6 +228,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>,
|
||||||
|
sort_by_names: Vec<String>,
|
||||||
context_page: ContextPage,
|
context_page: ContextPage,
|
||||||
dialog_pages: VecDeque<DialogPage>,
|
dialog_pages: VecDeque<DialogPage>,
|
||||||
dialog_text_input: widget::Id,
|
dialog_text_input: widget::Id,
|
||||||
|
|
@ -523,6 +524,28 @@ impl App {
|
||||||
.step(25u16),
|
.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(),
|
.into(),
|
||||||
widget::settings::view_section(fl!("settings-tab"))
|
widget::settings::view_section(fl!("settings-tab"))
|
||||||
.add({
|
.add({
|
||||||
|
|
@ -611,6 +634,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,
|
||||||
|
sort_by_names: HeadingOptions::names(),
|
||||||
context_page: ContextPage::Settings,
|
context_page: ContextPage::Settings,
|
||||||
dialog_pages: VecDeque::new(),
|
dialog_pages: VecDeque::new(),
|
||||||
dialog_text_input: widget::Id::unique(),
|
dialog_text_input: widget::Id::unique(),
|
||||||
|
|
|
||||||
23
src/tab.rs
23
src/tab.rs
|
|
@ -27,6 +27,7 @@ use std::{
|
||||||
cell::Cell,
|
cell::Cell,
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
|
fmt,
|
||||||
fs::{self, Metadata},
|
fs::{self, Metadata},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
|
|
@ -620,11 +621,31 @@ pub enum View {
|
||||||
}
|
}
|
||||||
#[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Ord, Eq, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Ord, Eq, Deserialize, Serialize)]
|
||||||
pub enum HeadingOptions {
|
pub enum HeadingOptions {
|
||||||
Name,
|
Name = 0,
|
||||||
Modified,
|
Modified,
|
||||||
Size,
|
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)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Tab {
|
pub struct Tab {
|
||||||
//TODO: make more items private
|
//TODO: make more items private
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue