Skip to content

Commit

Permalink
Add posibility clear an image
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipK committed Apr 28, 2022
1 parent 8e9cbd8 commit 3d68192
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/ui/ui_image_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ enum UserAction {
UserSelected(SteamUsersInfo),
ShortcutSelected(ShortcutOwned),
ImageTypeSelected(ImageType),
ImageTypeCleared(ImageType),
ImageSelected(PossibleImage),
GridIdChanged(usize),
BackButton,
Expand Down Expand Up @@ -165,6 +166,10 @@ impl MyEguiApp {
) -> Option<UserAction> {
ui.heading(image_type.name());

if ui.small_button("Clear image?").on_hover_text("Click here to clear the image").clicked(){
return Some(UserAction::ImageTypeCleared(image_type.clone()));
}

match &*state.image_options.borrow() {
FetcStatus::Fetched(images) => {
for image in images {
Expand Down Expand Up @@ -282,9 +287,24 @@ impl MyEguiApp {
UserAction::CorrectGridId => {
self.handle_correct_grid_request();
}
UserAction::ImageTypeCleared(image_type) => {
self.handle_image_type_clear(image_type);
},
};
}

fn handle_image_type_clear(&mut self, image_type: ImageType) {
let data_folder = &self.image_selected_state.steam_user.as_ref().unwrap().steam_user_data_folder;
let file_name = image_type.file_name(self.image_selected_state.selected_shortcut.as_ref().unwrap().app_id);
let path = Path::new(data_folder).join("config").join("grid").join(&file_name);
if path.exists(){
let _ = std::fs::remove_file(&path);
}
let key = path.to_string_lossy().to_string();
self.image_selected_state.image_handles.remove(&key);
self.image_selected_state.image_type_selected = None;
}

fn handle_correct_grid_request(&mut self) {
let app_name = self
.image_selected_state
Expand Down

0 comments on commit 3d68192

Please sign in to comment.