1
1
use std:: sync:: Arc ;
2
2
3
+ use itertools:: Itertools ;
3
4
use re_build_info:: CrateVersion ;
4
5
use re_data_source:: { DataSource , FileContents } ;
5
6
use re_entity_db:: entity_db:: EntityDb ;
@@ -573,17 +574,33 @@ impl App {
573
574
store_context : Option < & StoreContext < ' _ > > ,
574
575
cmd : UICommand ,
575
576
) {
576
- let active_application_id = store_context
577
- . and_then ( |ctx| {
578
- ctx. hub
579
- . active_app ( )
580
- // Don't redirect data to the welcome screen.
581
- . filter ( |& app_id| app_id != & StoreHub :: welcome_screen_app_id ( ) )
582
- } )
583
- . cloned ( ) ;
577
+ let mut force_store_info = false ;
578
+ let active_application_id = store_context . and_then ( |ctx| {
579
+ ctx. hub
580
+ . active_app ( )
581
+ // Don't redirect data to the welcome screen.
582
+ . filter ( |& app_id| app_id != & StoreHub :: welcome_screen_app_id ( ) )
583
+ . cloned ( )
584
+ } ) ;
584
585
let active_recording_id = store_context
585
- . and_then ( |ctx| ctx. hub . active_recording_id ( ) )
586
- . cloned ( ) ;
586
+ . and_then ( |ctx| ctx. hub . active_recording_id ( ) . cloned ( ) )
587
+ . or_else ( || {
588
+ // When we're on the welcome screen, there is no recording ID to recommend.
589
+ // But we want one, otherwise multiple things being dropped simultaneously on the
590
+ // welcome screen would end up in different recordings!
591
+
592
+ // We're creating a recording just-in-time, directly from the viewer.
593
+ // We need those those store infos or the data will just be silently ignored.
594
+ force_store_info = true ;
595
+
596
+ // NOTE: We don't override blueprints' store IDs anyhow, so it is sound to assume that
597
+ // this can only be a recording.
598
+ Some ( re_log_types:: StoreId :: random ( StoreKind :: Recording ) )
599
+ } ) ;
600
+
601
+ // TODO: we need to detect when drag-n-dropping multiple files at once on a welcome screen
602
+ // and create an appropriate app-id, somehow, otherwise we'll end up creating empty apps
603
+ // and everything will become very messy
587
604
588
605
match cmd {
589
606
UICommand :: SaveRecording => {
@@ -615,6 +632,7 @@ impl App {
615
632
FileSource :: FileDialog {
616
633
recommended_application_id : None ,
617
634
recommended_recording_id : None ,
635
+ force_store_info,
618
636
} ,
619
637
file_path,
620
638
) ) ) ;
@@ -642,12 +660,33 @@ impl App {
642
660
643
661
#[ cfg( not( target_arch = "wasm32" ) ) ]
644
662
UICommand :: Import => {
645
- for file_path in open_file_dialog_native ( ) {
663
+ let file_paths = open_file_dialog_native ( ) ;
664
+
665
+ let active_application_id = active_application_id. clone ( ) . or_else ( || {
666
+ if file_paths. len ( ) > 1 {
667
+ // TODO: come up with a nice compound name
668
+ Some (
669
+ file_paths
670
+ . iter ( )
671
+ . map ( |p| p. to_string_lossy ( ) . to_string ( ) )
672
+ . collect_vec ( )
673
+ . join ( "|" )
674
+ . into ( ) ,
675
+ )
676
+ } else {
677
+ file_paths
678
+ . first ( )
679
+ . map ( |p| p. to_string_lossy ( ) . to_string ( ) . into ( ) )
680
+ }
681
+ } ) ;
682
+
683
+ for file_path in file_paths {
646
684
self . command_sender
647
685
. send_system ( SystemCommand :: LoadDataSource ( DataSource :: FilePath (
648
686
FileSource :: FileDialog {
649
687
recommended_application_id : active_application_id. clone ( ) ,
650
688
recommended_recording_id : active_recording_id. clone ( ) ,
689
+ force_store_info,
651
690
} ,
652
691
file_path,
653
692
) ) ) ;
@@ -661,6 +700,8 @@ impl App {
661
700
let recommended_application_id = active_application_id;
662
701
let recommended_recording_id = active_recording_id;
663
702
703
+ // TODO: how do we even know if we have multiple files?
704
+
664
705
let promise = poll_promise:: Promise :: spawn_local ( async move {
665
706
let file = async_open_rrd_dialog ( ) . await ;
666
707
egui_ctx. request_repaint ( ) ; // Wake ui thread
@@ -1364,17 +1405,32 @@ impl App {
1364
1405
return ;
1365
1406
}
1366
1407
1367
- let active_application_id = store_ctx
1368
- . and_then ( |ctx| {
1369
- ctx. hub
1370
- . active_app ( )
1371
- // Don't redirect data to the welcome screen.
1372
- . filter ( |& app_id| app_id != & StoreHub :: welcome_screen_app_id ( ) )
1373
- } )
1374
- . cloned ( ) ;
1408
+ let mut force_store_info = false ;
1409
+ let active_application_id = store_ctx . and_then ( |ctx| {
1410
+ ctx. hub
1411
+ . active_app ( )
1412
+ // Don't redirect data to the welcome screen.
1413
+ . filter ( |& app_id| app_id != & StoreHub :: welcome_screen_app_id ( ) )
1414
+ . cloned ( )
1415
+ } ) ;
1375
1416
let active_recording_id = store_ctx
1376
- . and_then ( |ctx| ctx. hub . active_recording_id ( ) )
1377
- . cloned ( ) ;
1417
+ . and_then ( |ctx| ctx. hub . active_recording_id ( ) . cloned ( ) )
1418
+ . or_else ( || {
1419
+ // When we're on the welcome screen, there is no recording ID to recommend.
1420
+ // But we want one, otherwise multiple things being dropped simultaneously on the
1421
+ // welcome screen would end up in different recordings!
1422
+
1423
+ // We're creating a recording just-in-time, directly from the viewer.
1424
+ // We need those those store infos or the data will just be silently ignored.
1425
+ force_store_info = true ;
1426
+
1427
+ // NOTE: We don't override blueprints' store IDs anyhow, so it is sound to assume that
1428
+ // this can only be a recording.
1429
+ Some ( re_log_types:: StoreId :: random ( StoreKind :: Recording ) )
1430
+ } ) ;
1431
+
1432
+ // TODO: same shenanigans below -- we need to detect when drag-n-dropping multiple files at
1433
+ // once on a welcome screen and create an appropriate app-id, somehow
1378
1434
1379
1435
for file in dropped_files {
1380
1436
if let Some ( bytes) = file. bytes {
@@ -1384,6 +1440,7 @@ impl App {
1384
1440
FileSource :: DragAndDrop {
1385
1441
recommended_application_id : active_application_id. clone ( ) ,
1386
1442
recommended_recording_id : active_recording_id. clone ( ) ,
1443
+ force_store_info,
1387
1444
} ,
1388
1445
FileContents {
1389
1446
name : file. name . clone ( ) ,
@@ -1400,6 +1457,7 @@ impl App {
1400
1457
FileSource :: DragAndDrop {
1401
1458
recommended_application_id : active_application_id. clone ( ) ,
1402
1459
recommended_recording_id : active_recording_id. clone ( ) ,
1460
+ force_store_info,
1403
1461
} ,
1404
1462
path,
1405
1463
) ) ) ;
0 commit comments