@@ -38,18 +38,13 @@ use std::{
38
38
time:: Duration ,
39
39
} ;
40
40
41
- use crate :: {
42
- app:: FileOpenContext ,
43
- emulator,
44
- emulator:: Emulator ,
45
- event_loop:: thread_events:: FrontendThreadEvent ,
46
- floppy:: load_floppy:: handle_load_floppy,
47
- } ;
41
+ use crate :: { emulator, emulator:: Emulator , floppy:: load_floppy:: handle_load_floppy} ;
48
42
use display_manager_eframe:: EFrameDisplayManager ;
49
43
50
44
use marty_frontend_common:: {
51
45
constants:: { LONG_NOTIFICATION_TIME , NORMAL_NOTIFICATION_TIME , SHORT_NOTIFICATION_TIME } ,
52
46
floppy_manager:: FloppyError ,
47
+ thread_events:: { FileSelectionContext , FrontendThreadEvent } ,
53
48
types:: floppy:: FloppyImageSource ,
54
49
} ;
55
50
@@ -90,12 +85,6 @@ use std::thread::spawn;
90
85
#[ cfg( target_arch = "wasm32" ) ]
91
86
use crate :: wasm:: worker:: spawn_closure_worker as spawn;
92
87
93
- #[ derive( Clone , Debug ) ]
94
- pub enum FileSelectionContext {
95
- Index ( usize ) ,
96
- Path ( PathBuf ) ,
97
- }
98
-
99
88
//noinspection RsBorrowChecker
100
89
pub fn handle_egui_event ( emu : & mut Emulator , dm : & mut EFrameDisplayManager , gui_event : & GuiEvent ) {
101
90
match gui_event {
@@ -380,41 +369,41 @@ pub fn handle_egui_event(emu: &mut Emulator, dm: &mut EFrameDisplayManager, gui_
380
369
Some ( name) => {
381
370
log:: info!( "Loading cart image: {:?} into slot: {}" , name, slot_select) ;
382
371
383
- // match emu.cart_manager.load_cart_data(*item_idx, &emu.rm).await {
384
- // Ok(cart_image) => match cart_slot.insert_cart(*slot_select, cart_image) {
385
- // Ok(()) => {
386
- // log::info!("Cart image successfully loaded into slot: {}", slot_select);
387
- //
388
- // emu.gui.set_cart_selection(
389
- // *slot_select,
390
- // Some(*item_idx),
391
- // Some(name.clone().into()),
392
- // );
393
- //
394
- // emu.gui
395
- // .toasts()
396
- // .info(format!("Cartridge inserted: {:?}", name.clone()))
397
- // .duration(Some(NORMAL_NOTIFICATION_TIME));
398
- //
399
- // // Inserting a cartridge reboots the machine due to a switch in the cartridge slot.
400
- // reboot = true;
401
- // }
402
- // Err(err) => {
403
- // log::error!("Cart image failed to load into slot {}: {}", slot_select, err);
404
- // emu.gui
405
- // .toasts()
406
- // .error(format!("Cartridge load failed: {}", err))
407
- // .duration(Some(NORMAL_NOTIFICATION_TIME));
408
- // }
409
- // },
410
- // Err(err) => {
411
- // log::error!("Failed to load cart image: {:?} Error: {}", item_idx, err);
412
- // emu.gui
413
- // .toasts()
414
- // .error(format!("Cartridge load failed: {}", err))
415
- // .duration(Some(NORMAL_NOTIFICATION_TIME));
416
- // }
417
- // }
372
+ match emu. cart_manager . load_cart_data ( * item_idx, & mut emu. rm ) {
373
+ Ok ( cart_image) => match cart_slot. insert_cart ( * slot_select, cart_image) {
374
+ Ok ( ( ) ) => {
375
+ log:: info!( "Cart image successfully loaded into slot: {}" , slot_select) ;
376
+
377
+ emu. gui . set_cart_selection (
378
+ * slot_select,
379
+ Some ( * item_idx) ,
380
+ Some ( name. clone ( ) . into ( ) ) ,
381
+ ) ;
382
+
383
+ emu. gui
384
+ . toasts ( )
385
+ . info ( format ! ( "Cartridge inserted: {:?}" , name. clone( ) ) )
386
+ . duration ( Some ( NORMAL_NOTIFICATION_TIME ) ) ;
387
+
388
+ // Inserting a cartridge reboots the machine due to a switch in the cartridge slot.
389
+ reboot = true ;
390
+ }
391
+ Err ( err) => {
392
+ log:: error!( "Cart image failed to load into slot {}: {}" , slot_select, err) ;
393
+ emu. gui
394
+ . toasts ( )
395
+ . error ( format ! ( "Cartridge load failed: {}" , err) )
396
+ . duration ( Some ( NORMAL_NOTIFICATION_TIME ) ) ;
397
+ }
398
+ } ,
399
+ Err ( err) => {
400
+ log:: error!( "Failed to load cart image: {:?} Error: {}" , item_idx, err) ;
401
+ emu. gui
402
+ . toasts ( )
403
+ . error ( format ! ( "Cartridge load failed: {}" , err) )
404
+ . duration ( Some ( NORMAL_NOTIFICATION_TIME ) ) ;
405
+ }
406
+ }
418
407
}
419
408
None => {
420
409
emu. gui
@@ -453,13 +442,66 @@ pub fn handle_egui_event(emu: &mut Emulator, dm: &mut EFrameDisplayManager, gui_
453
442
log:: debug!( "Requesting floppy load dialog for drive: {}" , drive_select) ;
454
443
#[ cfg( target_arch = "wasm32" ) ]
455
444
{
445
+ use marty_frontend_common:: thread_events:: FileOpenContext ;
456
446
let context = FileOpenContext :: FloppyDiskImage {
457
447
drive_select : * drive_select,
458
448
fsc : FileSelectionContext :: Path ( PathBuf :: new ( ) ) ,
459
449
} ;
460
450
file_open:: open_file_dialog ( context, emu. sender . clone ( ) ) ;
461
451
}
462
452
}
453
+ GuiEvent :: RequestSaveFloppyDialog ( drive_select, format) => {
454
+ // User requested a file dialog to load a floppy image into the indicated drive slot.
455
+ log:: debug!(
456
+ "Requesting floppy save dialog for drive: {}, format: {:?}" ,
457
+ drive_select,
458
+ format
459
+ ) ;
460
+ // TODO: Implement save floppy image on web
461
+ // ImageBuilder needs to be able to accept a Writer (`with_writer` perhaps?)
462
+ #[ cfg( target_arch = "wasm32" ) ]
463
+ {
464
+ // if let Some(fdc) = emu.machine.fdc() {
465
+ // let (disk_image_opt, _) = fdc.get_image(*drive_select);
466
+ // if let Some(floppy_image) = disk_image_opt {
467
+ // let mut image = floppy_image.write().unwrap();
468
+ // match fluxfox::ImageWriter::new(&mut image)
469
+ // .with_format(*format)
470
+ // .with_path(filepath.clone())
471
+ // .write()
472
+ // {
473
+ // Ok(_) => {
474
+ // log::info!("Floppy image successfully saved: {:?}", filepath);
475
+ //
476
+ // emu.gui.set_floppy_selection(
477
+ // *drive_select,
478
+ // None,
479
+ // FloppyDriveSelection::Image(filepath.clone()),
480
+ // Some(*format),
481
+ // image.compatible_formats(true),
482
+ // None,
483
+ // );
484
+ //
485
+ // emu.gui
486
+ // .toasts()
487
+ // .info(format!("Floppy saved: {:?}", filepath.file_name().unwrap_or_default()))
488
+ // .duration(Some(NORMAL_NOTIFICATION_TIME));
489
+ // }
490
+ // Err(err) => {
491
+ // log::error!("Floppy image failed to save: {}", err);
492
+ //
493
+ // emu.gui
494
+ // .toasts()
495
+ // .error(format!("Failed to save: {}", err))
496
+ // .duration(Some(NORMAL_NOTIFICATION_TIME));
497
+ // }
498
+ // }
499
+ // }
500
+ // }
501
+
502
+ //file_save::save_file_dialog(context, emu.sender.clone());
503
+ }
504
+ }
463
505
GuiEvent :: LoadQuickFloppy ( drive_select, item_idx) => {
464
506
// User selected a floppy image from the quick access menu.
465
507
log:: debug!( "Load floppy quick image: {:?} into drive: {}" , item_idx, drive_select) ;
0 commit comments