diff --git a/src/Tools/tim_tool/src/gui/file_tab/callbacks.rs b/src/Tools/tim_tool/src/gui/file_tab/callbacks.rs index fec59379..ba53b540 100644 --- a/src/Tools/tim_tool/src/gui/file_tab/callbacks.rs +++ b/src/Tools/tim_tool/src/gui/file_tab/callbacks.rs @@ -69,9 +69,11 @@ pub(super) fn on_load_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu } }; - for job in new_project.jobs { - let mut tim_manager = tim_manager.lock().expect("VRAM already locked"); - + let mut tim_manager = tim_manager.lock().expect("VRAM already locked"); + clear_all_vram_images(main_tab, &mut tim_manager); + main_window.invoke_clear_file_tab_current_selected_file(); + + for job in new_project.jobs { let (_, _) = tim_manager.load_unadded_tim(&job.file_path)?; let (pal_width, pal_height) = job.palette_rect.size.into(); @@ -208,6 +210,11 @@ fn add_unadded_tim(main_tab: &mut MainTab, tim_manager: &mut TIMManager, unadded Ok(()) } +fn clear_all_vram_images(main_tab: &mut MainTab, tim_manager: &mut TIMManager) { + tim_manager.clear(); + main_tab.clear(); +} + fn create_project_file_dialog() -> FileDialog { FileDialog::new() .add_filter("TIM project file (.tim_project)", &["tim_project"]) diff --git a/src/Tools/tim_tool/src/gui/main_tab/mod.rs b/src/Tools/tim_tool/src/gui/main_tab/mod.rs index 71ed1135..a4cf8087 100644 --- a/src/Tools/tim_tool/src/gui/main_tab/mod.rs +++ b/src/Tools/tim_tool/src/gui/main_tab/mod.rs @@ -72,6 +72,15 @@ impl MainTab { object } + pub fn clear(&mut self) { + let mut vram_data = self.vram.lock().expect("VRAM already locked"); + let count = vram_data.count; + + for _ in 0..count { + vram_data.pop(); + } + } + pub fn add_new_vram_file(&mut self, file_name: &String, full_image: slint::Image, texture: NewVRAMImageInfo, image_palette: Option) -> usize { let mut vram_data = self.vram.lock().expect("VRAM already locked"); let mut add_new_image = |file_name: &String, full_image: slint::Image, vram_image: NewVRAMImageInfo, palette_count: i32, is_palette: bool| { diff --git a/src/Tools/tim_tool/src/logic/tim_mgr.rs b/src/Tools/tim_tool/src/logic/tim_mgr.rs index 2476c173..930df311 100644 --- a/src/Tools/tim_tool/src/logic/tim_mgr.rs +++ b/src/Tools/tim_tool/src/logic/tim_mgr.rs @@ -13,6 +13,10 @@ impl TIMManager { TIMManager{added_tims: Default::default(), unadded_tim: None} } + pub fn clear(&mut self) { + self.added_tims.clear(); + } + pub fn remove_added_tim(&mut self, range: RangeInclusive) { let idx = *range.start(); for _ in range { diff --git a/src/Tools/tim_tool/ui/app-window.slint b/src/Tools/tim_tool/ui/app-window.slint index a6b27cd9..7ccd88ba 100644 --- a/src/Tools/tim_tool/ui/app-window.slint +++ b/src/Tools/tim_tool/ui/app-window.slint @@ -80,4 +80,8 @@ export component MainWindow inherits Window { public function change_to_main() { tab_widget.current-index = 1; } + + public function clear_file_tab-current_selected_file() { + main_tab.clear_current_selection(); + } } \ No newline at end of file diff --git a/src/Tools/tim_tool/ui/tab/main-tab.slint b/src/Tools/tim_tool/ui/tab/main-tab.slint index 13a22654..6bff7047 100644 --- a/src/Tools/tim_tool/ui/tab/main-tab.slint +++ b/src/Tools/tim_tool/ui/tab/main-tab.slint @@ -179,10 +179,7 @@ export component MainTab inherits Rectangle { text: "Remove file"; clicked => { root.remove_file_clicked(vram_files_list.current_item); - vram_files_list.current-item = -1; - cur_sel_x.text = 0; - cur_sel_y.text = 0; - cur_sel_img.visible = false; + root.clear_current_selection(); } } } @@ -285,4 +282,11 @@ export component MainTab inherits Rectangle { function get_border_width() -> int { return 4; } + + public function clear_current_selection() { + vram_files_list.current-item = -1; + cur_sel_x.text = 0; + cur_sel_y.text = 0; + cur_sel_img.visible = false; + } } \ No newline at end of file