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