Merge pull request #165 from joshuamegnauth54/clear-recents

Clear recent media button
This commit is contained in:
Jeremy Soller 2025-10-12 20:25:53 -06:00 committed by GitHub
commit 85695b25ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 42 additions and 3 deletions

View file

@ -26,8 +26,9 @@ light = Light
file = File
open-media = Open media...
open-recent-media = Open recent media
clear-recent = Clear recent list
close-file = Close file
open-media-folder = Open media folder...
open-recent-media-folder = Open recent media folder
close-media-folder = Close media folder
quit = Quit
quit = Quit

View file

@ -158,9 +158,11 @@ fn main() -> Result<(), Box<dyn Error>> {
pub enum Action {
FileClose,
FileOpen,
FileClearRecents,
FileOpenRecent(usize),
FolderClose(usize),
FolderOpen,
FolderClearRecents,
FolderOpenRecent(usize),
Fullscreen,
PlayPause,
@ -176,9 +178,11 @@ impl MenuAction for Action {
match self {
Self::FileClose => Message::FileClose,
Self::FileOpen => Message::FileOpen,
Self::FileClearRecents => Message::FileClearRecents,
Self::FileOpenRecent(index) => Message::FileOpenRecent(*index),
Self::FolderClose(index) => Message::FolderClose(*index),
Self::FolderOpen => Message::FolderOpen,
Self::FolderClearRecents => Message::FolderClearRecents,
Self::FolderOpenRecent(index) => Message::FolderOpenRecent(*index),
Self::Fullscreen => Message::Fullscreen,
Self::PlayPause => Message::PlayPause,
@ -256,10 +260,12 @@ pub enum Message {
FileClose,
FileLoad(url::Url),
FileOpen,
FileClearRecents,
FileOpenRecent(usize),
FolderClose(usize),
FolderLoad(PathBuf),
FolderOpen,
FolderClearRecents,
FolderOpenRecent(usize),
MultipleLoad(Vec<url::Url>),
Fullscreen,
@ -1065,6 +1071,10 @@ impl Application for App {
|x| x,
);
}
Message::FileClearRecents => {
self.flags.config_state.recent_files.clear();
self.save_config_state();
}
Message::FileOpenRecent(index) => {
if let Some(url) = self.flags.config_state.recent_files.get(index) {
return self.update(Message::FileLoad(url.clone()));
@ -1137,6 +1147,10 @@ impl Application for App {
return self.update(Message::FolderLoad(path.clone()));
}
}
Message::FolderClearRecents => {
self.flags.config_state.recent_projects.clear();
self.save_config_state();
}
Message::MultipleLoad(urls) => {
log::trace!("Loading multiple URLs: {urls:?}");
let paths: Vec<_> = urls

View file

@ -31,21 +31,45 @@ pub fn menu_bar<'a>(
}
};
let mut recent_files = Vec::with_capacity(config_state.recent_files.len());
let files_len = if config_state.recent_files.is_empty() {
0
} else {
config_state.recent_files.len() + 2
};
let mut recent_files = Vec::with_capacity(files_len);
for (i, path) in config_state.recent_files.iter().enumerate() {
recent_files.push(menu::Item::Button(
format_url(path),
Action::FileOpenRecent(i),
));
}
if files_len > 0 {
recent_files.push(menu::Item::Divider);
recent_files.push(menu::Item::Button(
fl!("clear-recent"),
Action::FileClearRecents,
));
}
let mut recent_projects = Vec::with_capacity(config_state.recent_projects.len());
let projects_len = if config_state.recent_projects.is_empty() {
0
} else {
config_state.recent_projects.len() + 2
};
let mut recent_projects = Vec::with_capacity(projects_len);
for (i, path) in config_state.recent_projects.iter().enumerate() {
recent_projects.push(menu::Item::Button(
format_path(path),
Action::FolderOpenRecent(i),
));
}
if projects_len > 0 {
recent_projects.push(menu::Item::Divider);
recent_projects.push(menu::Item::Button(
fl!("clear-recent"),
Action::FolderClearRecents,
));
}
let mut close_projects = Vec::with_capacity(projects.len());
for (folder_i, (name, _path)) in projects.iter().enumerate() {