Skip to content

Commit 9241d7d

Browse files
committed
implement Import support
1 parent 64a27ee commit 9241d7d

File tree

3 files changed

+84
-7
lines changed

3 files changed

+84
-7
lines changed

crates/viewer/re_ui/src/command.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub trait UICommandSender {
1414
pub enum UICommand {
1515
// Listed in the order they show up in the command palette by default!
1616
Open,
17+
Import,
1718
SaveRecording,
1819
SaveRecordingSelection,
1920
SaveBlueprint,
@@ -111,7 +112,8 @@ impl UICommand {
111112

112113
Self::SaveBlueprint => ("Save blueprint…", "Save the current viewer setup as a Rerun blueprint file (.rbl)"),
113114

114-
Self::Open => ("Open…", "Open any supported files (.rrd, images, meshes, …)"),
115+
Self::Open => ("Open…", "Open any supported files (.rrd, images, meshes, …) in a new recording"),
116+
Self::Import => ("Import…", "Import any supported files (.rrd, images, meshes, …) in the current recording"),
115117

116118
Self::CloseCurrentRecording => (
117119
"Close current recording",
@@ -271,6 +273,10 @@ impl UICommand {
271273
KeyboardShortcut::new(Modifiers::COMMAND, key)
272274
}
273275

276+
fn cmd_shift(key: Key) -> KeyboardShortcut {
277+
KeyboardShortcut::new(Modifiers::COMMAND.plus(Modifiers::SHIFT), key)
278+
}
279+
274280
fn cmd_alt(key: Key) -> KeyboardShortcut {
275281
KeyboardShortcut::new(Modifiers::COMMAND.plus(Modifiers::ALT), key)
276282
}
@@ -284,6 +290,7 @@ impl UICommand {
284290
Self::SaveRecordingSelection => Some(cmd_alt(Key::S)),
285291
Self::SaveBlueprint => None,
286292
Self::Open => Some(cmd(Key::O)),
293+
Self::Import => Some(cmd_shift(Key::O)),
287294
Self::CloseCurrentRecording => None,
288295
Self::CloseAllRecordings => None,
289296

crates/viewer/re_viewer/src/app.rs

+75-6
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ const MIN_ZOOM_FACTOR: f32 = 0.2;
146146
#[cfg(not(target_arch = "wasm32"))]
147147
const MAX_ZOOM_FACTOR: f32 = 5.0;
148148

149+
#[cfg(target_arch = "wasm32")]
150+
struct PendingFilePromise {
151+
recommended_application_id: Option<ApplicationId>,
152+
recommended_recording_id: Option<re_log_types::StoreId>,
153+
promise: poll_promise::Promise<Vec<re_data_source::FileContents>>,
154+
}
155+
149156
/// The Rerun Viewer as an [`eframe`] application.
150157
pub struct App {
151158
build_info: re_build_info::BuildInfo,
@@ -169,7 +176,7 @@ pub struct App {
169176
rx: ReceiveSet<LogMsg>,
170177

171178
#[cfg(target_arch = "wasm32")]
172-
open_files_promise: Option<poll_promise::Promise<Vec<re_data_source::FileContents>>>,
179+
open_files_promise: Option<PendingFilePromise>,
173180

174181
/// What is serialized
175182
pub(crate) state: AppState,
@@ -564,6 +571,18 @@ impl App {
564571
store_context: Option<&StoreContext<'_>>,
565572
cmd: UICommand,
566573
) {
574+
let active_application_id = store_context
575+
.and_then(|ctx| {
576+
ctx.hub
577+
.active_app()
578+
// Don't redirect data to the welcome screen.
579+
.filter(|&app_id| app_id != &StoreHub::welcome_screen_app_id())
580+
})
581+
.cloned();
582+
let active_recording_id = store_context
583+
.and_then(|ctx| ctx.hub.active_recording_id())
584+
.cloned();
585+
567586
match cmd {
568587
UICommand::SaveRecording => {
569588
if let Err(err) = save_recording(self, store_context, None) {
@@ -602,12 +621,57 @@ impl App {
602621
#[cfg(target_arch = "wasm32")]
603622
UICommand::Open => {
604623
let egui_ctx = egui_ctx.clone();
605-
self.open_files_promise = Some(poll_promise::Promise::spawn_local(async move {
624+
625+
// Open: we want to try and load into a new dedicated recording.
626+
let recommended_application_id = None;
627+
let recommended_recording_id = None;
628+
let promise = poll_promise::Promise::spawn_local(async move {
606629
let file = async_open_rrd_dialog().await;
607630
egui_ctx.request_repaint(); // Wake ui thread
608631
file
609-
}));
632+
});
633+
634+
self.open_files_promise = Some(PendingFilePromise {
635+
recommended_application_id,
636+
recommended_recording_id,
637+
promise,
638+
});
610639
}
640+
641+
#[cfg(not(target_arch = "wasm32"))]
642+
UICommand::Import => {
643+
for file_path in open_file_dialog_native() {
644+
self.command_sender
645+
.send_system(SystemCommand::LoadDataSource(DataSource::FilePath(
646+
FileSource::FileDialog {
647+
recommended_application_id: active_application_id.clone(),
648+
recommended_recording_id: active_recording_id.clone(),
649+
},
650+
file_path,
651+
)));
652+
}
653+
}
654+
#[cfg(target_arch = "wasm32")]
655+
UICommand::Import => {
656+
let egui_ctx = egui_ctx.clone();
657+
658+
// Import: we want to try and load into the current recording.
659+
let recommended_application_id = active_application_id;
660+
let recommended_recording_id = active_recording_id;
661+
662+
let promise = poll_promise::Promise::spawn_local(async move {
663+
let file = async_open_rrd_dialog().await;
664+
egui_ctx.request_repaint(); // Wake ui thread
665+
file
666+
});
667+
668+
self.open_files_promise = Some(PendingFilePromise {
669+
recommended_application_id,
670+
recommended_recording_id,
671+
promise,
672+
});
673+
}
674+
611675
UICommand::CloseCurrentRecording => {
612676
let cur_rec = store_context.map(|ctx| ctx.recording.store_id());
613677
if let Some(cur_rec) = cur_rec {
@@ -1586,14 +1650,19 @@ impl eframe::App for App {
15861650
}
15871651

15881652
#[cfg(target_arch = "wasm32")]
1589-
if let Some(promise) = &self.open_files_promise {
1653+
if let Some(PendingFilePromise {
1654+
recommended_application_id,
1655+
recommended_recording_id,
1656+
promise,
1657+
}) = &self.open_files_promise
1658+
{
15901659
if let Some(files) = promise.ready() {
15911660
for file in files {
15921661
self.command_sender
15931662
.send_system(SystemCommand::LoadDataSource(DataSource::FileContents(
15941663
FileSource::FileDialog {
1595-
recommended_application_id: None,
1596-
recommended_recording_id: None,
1664+
recommended_application_id: recommended_application_id.clone(),
1665+
recommended_recording_id: recommended_recording_id.clone(),
15971666
},
15981667
file.clone(),
15991668
)));

crates/viewer/re_viewer/src/ui/rerun_menu.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl App {
3737
ui.add_space(SPACING);
3838

3939
UICommand::Open.menu_button_ui(ui, &self.command_sender);
40+
UICommand::Import.menu_button_ui(ui, &self.command_sender);
4041

4142
self.save_buttons_ui(ui, _store_context);
4243

0 commit comments

Comments
 (0)