feat: add setting to enable/disable the "recents" feature
This commit is contained in:
parent
8909689245
commit
5d3d893c9e
5 changed files with 72 additions and 40 deletions
|
|
@ -298,6 +298,7 @@ calculating = Calculating...
|
||||||
## Settings
|
## Settings
|
||||||
settings = Settings
|
settings = Settings
|
||||||
single-click = Single click to open
|
single-click = Single click to open
|
||||||
|
show-recents = Show recents
|
||||||
|
|
||||||
### Appearance
|
### Appearance
|
||||||
appearance = Appearance
|
appearance = Appearance
|
||||||
|
|
|
||||||
88
src/app.rs
88
src/app.rs
|
|
@ -424,6 +424,7 @@ pub enum Message {
|
||||||
SearchClear,
|
SearchClear,
|
||||||
SearchInput(String),
|
SearchInput(String),
|
||||||
SetShowDetails(bool),
|
SetShowDetails(bool),
|
||||||
|
SetShowRecents(bool),
|
||||||
SetTypeToSearch(TypeToSearch),
|
SetTypeToSearch(TypeToSearch),
|
||||||
SystemThemeModeChange,
|
SystemThemeModeChange,
|
||||||
Size(window::Id, Size),
|
Size(window::Id, Size),
|
||||||
|
|
@ -842,12 +843,14 @@ impl App {
|
||||||
for path in paths {
|
for path in paths {
|
||||||
match open::that_detached(&path) {
|
match open::that_detached(&path) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
let _ = recently_used_xbel::update_recently_used(
|
if self.config.show_recents {
|
||||||
&path,
|
let _ = recently_used_xbel::update_recently_used(
|
||||||
Self::APP_ID.to_string(),
|
&path,
|
||||||
"cosmic-files".to_string(),
|
Self::APP_ID.to_string(),
|
||||||
None,
|
"cosmic-files".to_string(),
|
||||||
);
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::warn!("failed to open {}: {}", path.display(), err);
|
log::warn!("failed to open {}: {}", path.display(), err);
|
||||||
|
|
@ -911,13 +914,15 @@ impl App {
|
||||||
for (i, mut command) in commands.into_iter().enumerate() {
|
for (i, mut command) in commands.into_iter().enumerate() {
|
||||||
match spawn_detached(&mut command) {
|
match spawn_detached(&mut command) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
for path in paths {
|
if self.config.show_recents {
|
||||||
let _ = recently_used_xbel::update_recently_used(
|
for path in paths {
|
||||||
&path.into(),
|
let _ = recently_used_xbel::update_recently_used(
|
||||||
Self::APP_ID.to_string(),
|
&path.into(),
|
||||||
"cosmic-files".to_string(),
|
Self::APP_ID.to_string(),
|
||||||
None,
|
"cosmic-files".to_string(),
|
||||||
);
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -1548,11 +1553,13 @@ impl App {
|
||||||
fn update_nav_model(&mut self) {
|
fn update_nav_model(&mut self) {
|
||||||
let mut nav_model = segmented_button::ModelBuilder::default();
|
let mut nav_model = segmented_button::ModelBuilder::default();
|
||||||
|
|
||||||
nav_model = nav_model.insert(|b| {
|
if self.config.show_recents {
|
||||||
b.text(fl!("recents"))
|
nav_model = nav_model.insert(|b| {
|
||||||
.icon(icon::from_name("document-open-recent-symbolic"))
|
b.text(fl!("recents"))
|
||||||
.data(Location::Recents)
|
.icon(icon::from_name("document-open-recent-symbolic"))
|
||||||
});
|
.data(Location::Recents)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
for (favorite_i, favorite) in self.config.favorites.iter().enumerate() {
|
for (favorite_i, favorite) in self.config.favorites.iter().enumerate() {
|
||||||
if let Some(path) = favorite.path_opt() {
|
if let Some(path) = favorite.path_opt() {
|
||||||
|
|
@ -2059,6 +2066,10 @@ impl App {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
.add({
|
||||||
|
widget::settings::item::builder(fl!("show-recents"))
|
||||||
|
.toggler(self.config.show_recents, Message::SetShowRecents)
|
||||||
|
})
|
||||||
.into(),
|
.into(),
|
||||||
])
|
])
|
||||||
.into()
|
.into()
|
||||||
|
|
@ -2961,12 +2972,14 @@ impl Application for App {
|
||||||
{
|
{
|
||||||
match spawn_detached(&mut command) {
|
match spawn_detached(&mut command) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
let _ = recently_used_xbel::update_recently_used(
|
if self.config.show_recents {
|
||||||
&path,
|
let _ = recently_used_xbel::update_recently_used(
|
||||||
Self::APP_ID.to_string(),
|
&path,
|
||||||
"cosmic-files".to_string(),
|
Self::APP_ID.to_string(),
|
||||||
None,
|
"cosmic-files".to_string(),
|
||||||
);
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
|
|
@ -4029,6 +4042,10 @@ impl Application for App {
|
||||||
config_set!(show_details, show_details);
|
config_set!(show_details, show_details);
|
||||||
return self.update_config();
|
return self.update_config();
|
||||||
}
|
}
|
||||||
|
Message::SetShowRecents(show_recents) => {
|
||||||
|
config_set!(show_recents, show_recents);
|
||||||
|
return self.update_config();
|
||||||
|
}
|
||||||
Message::SetTypeToSearch(type_to_search) => {
|
Message::SetTypeToSearch(type_to_search) => {
|
||||||
config_set!(type_to_search, type_to_search);
|
config_set!(type_to_search, type_to_search);
|
||||||
return self.update_config();
|
return self.update_config();
|
||||||
|
|
@ -4831,7 +4848,9 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Message::Recents => {
|
Message::Recents => {
|
||||||
return self.open_tab(Location::Recents, false, None);
|
if self.config.show_recents {
|
||||||
|
return self.open_tab(Location::Recents, false, None);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[cfg(all(feature = "wayland", feature = "desktop-applet"))]
|
#[cfg(all(feature = "wayland", feature = "desktop-applet"))]
|
||||||
Message::OutputEvent(output_event, output) => {
|
Message::OutputEvent(output_event, output) => {
|
||||||
|
|
@ -6346,12 +6365,15 @@ impl Application for App {
|
||||||
std::future::pending().await
|
std::future::pending().await
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
#[cfg(all(
|
];
|
||||||
not(feature = "desktop-applet"),
|
|
||||||
not(target_os = "ios"),
|
#[cfg(all(
|
||||||
not(target_os = "android")
|
not(feature = "desktop-applet"),
|
||||||
))]
|
not(target_os = "ios"),
|
||||||
Subscription::run_with_id(
|
not(target_os = "android")
|
||||||
|
))]
|
||||||
|
if self.config.show_recents {
|
||||||
|
subscriptions.push(Subscription::run_with_id(
|
||||||
TypeId::of::<RecentsWatcherSubscription>(),
|
TypeId::of::<RecentsWatcherSubscription>(),
|
||||||
stream::channel(1, |mut output| async move {
|
stream::channel(1, |mut output| async move {
|
||||||
let Some(recents_path) = recently_used_xbel::dir() else {
|
let Some(recents_path) = recently_used_xbel::dir() else {
|
||||||
|
|
@ -6411,8 +6433,8 @@ impl Application for App {
|
||||||
|
|
||||||
std::future::pending().await
|
std::future::pending().await
|
||||||
}),
|
}),
|
||||||
),
|
));
|
||||||
];
|
}
|
||||||
|
|
||||||
if let Some(scroll_speed) = self.auto_scroll_speed {
|
if let Some(scroll_speed) = self.auto_scroll_speed {
|
||||||
subscriptions.push(
|
subscriptions.push(
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,7 @@ pub struct Config {
|
||||||
pub thumb_cfg: ThumbCfg,
|
pub thumb_cfg: ThumbCfg,
|
||||||
pub favorites: Vec<Favorite>,
|
pub favorites: Vec<Favorite>,
|
||||||
pub show_details: bool,
|
pub show_details: bool,
|
||||||
|
pub show_recents: bool,
|
||||||
pub tab: TabConfig,
|
pub tab: TabConfig,
|
||||||
pub type_to_search: TypeToSearch,
|
pub type_to_search: TypeToSearch,
|
||||||
}
|
}
|
||||||
|
|
@ -229,6 +230,7 @@ impl Default for Config {
|
||||||
Favorite::Videos,
|
Favorite::Videos,
|
||||||
],
|
],
|
||||||
show_details: false,
|
show_details: false,
|
||||||
|
show_recents: true,
|
||||||
tab: TabConfig::default(),
|
tab: TabConfig::default(),
|
||||||
type_to_search: TypeToSearch::Recursive,
|
type_to_search: TypeToSearch::Recursive,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1609,12 +1609,14 @@ impl Application for App {
|
||||||
&& let Some(path) = item.path_opt()
|
&& let Some(path) = item.path_opt()
|
||||||
{
|
{
|
||||||
paths.push(path.clone());
|
paths.push(path.clone());
|
||||||
let _ = update_recently_used(
|
if self.flags.config.show_recents {
|
||||||
path,
|
let _ = update_recently_used(
|
||||||
Self::APP_ID.to_string(),
|
path,
|
||||||
"cosmic-files".to_string(),
|
Self::APP_ID.to_string(),
|
||||||
None,
|
"cosmic-files".to_string(),
|
||||||
);
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,12 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
} else if &arg == "--trash" {
|
} else if &arg == "--trash" {
|
||||||
Location::Trash
|
Location::Trash
|
||||||
} else if &arg == "--recents" {
|
} else if &arg == "--recents" {
|
||||||
Location::Recents
|
if config.show_recents {
|
||||||
|
Location::Recents
|
||||||
|
} else {
|
||||||
|
log::warn!("recents feature is disabled in config");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
} else if &arg == "--network" {
|
} else if &arg == "--network" {
|
||||||
Location::Network("network:///".to_string(), fl!("networks"), None)
|
Location::Network("network:///".to_string(), fl!("networks"), None)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue